summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-03-28 14:14:31 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-03-28 14:14:31 +0300
commit3986f667cb0f3fffeaee637dcee097b582e240ca (patch)
tree5d764d800adad5a18cda818bd14599b1538e765a
parent4e37d6e13611fb0a27aa35f0c06f221a37cf56f1 (diff)
CCtrlTreeView: OnBeginDrag / OnEndDrag callbacks became boolean
-rw-r--r--include/m_gui.h2
-rw-r--r--include/m_system.h26
-rw-r--r--src/mir_app/src/menu_options.cpp6
-rw-r--r--src/mir_core/src/Windows/CCtrlTreeView.cpp22
4 files changed, 42 insertions, 14 deletions
diff --git a/include/m_gui.h b/include/m_gui.h
index 17b544ef61..0d13d5974a 100644
--- a/include/m_gui.h
+++ b/include/m_gui.h
@@ -1306,6 +1306,7 @@ public:
NMTVGETINFOTIP *nmtvit;
NMTVCUSTOMDRAW *nmcd;
HTREEITEM hItem; // for OnItemChanged
+ TVHITTESTINFO *ntvhi; // for OnEndDrag
};
};
@@ -1314,6 +1315,7 @@ public:
CCallback<TEventInfo> OnBeginRDrag;
CCallback<TEventInfo> OnCustomDraw;
CCallback<TEventInfo> OnDeleteItem;
+ CCallback<TEventInfo> OnEndDrag;
CCallback<TEventInfo> OnEndLabelEdit;
CCallback<TEventInfo> OnGetDispInfo;
CCallback<TEventInfo> OnGetInfoTip;
diff --git a/include/m_system.h b/include/m_system.h
index 2d36a47bcd..f5003a2585 100644
--- a/include/m_system.h
+++ b/include/m_system.h
@@ -604,19 +604,29 @@ class CCallbackImp
};
typedef void (CDummy:: *TFnCallback)(void *argument);
+ typedef bool (CDummy:: *TFnBCallback)(void *argument);
CDummy *m_object;
- TFnCallback m_func;
+ union {
+ TFnCallback m_func;
+ TFnBCallback m_bfunc;
+ };
protected:
template<typename TClass, typename TArgument>
__inline CCallbackImp(TClass *object, void (TClass:: *func)(TArgument *argument)) :
m_object((CDummy *)object),
m_func((TFnCallback)func)
- {
- }
+ {}
+
+ template<typename TClass, typename TArgument>
+ __inline CCallbackImp(TClass *object, bool (TClass:: *func)(TArgument *argument)) :
+ m_object((CDummy *)object),
+ m_bfunc((TFnBCallback)func)
+ {}
__inline void Invoke(void *argument) const { if (m_func && m_object) (m_object->*m_func)(argument); }
+ __inline bool BInvoke(void *argument) const { return (m_bfunc && m_object) ? (m_object->*m_bfunc)(argument) : true; }
public:
__inline CCallbackImp() : m_object(nullptr), m_func(nullptr) {}
@@ -641,9 +651,13 @@ public:
template<typename TClass>
__inline CCallback(TClass *object, void (TClass:: *func)(TArgument *argument)) : CCallbackImp(object, func) {}
+ template<typename TClass>
+ __inline CCallback(TClass *object, bool (TClass:: *func)(TArgument *argument)) : CCallbackImp(object, func) {}
+
__inline CCallback &operator=(const CCallbackImp &x) { CSuper::operator =(x); return *this; }
__inline void operator()(TArgument *argument) const { Invoke((void *)argument); }
+ __inline bool Check(TArgument *argument) const { return BInvoke((void *)argument); }
};
template<typename TClass, typename TArgument>
@@ -652,6 +666,12 @@ __inline CCallback<TArgument> Callback(TClass *object, void (TClass:: *func)(TAr
return CCallback<TArgument>(object, func);
}
+template<typename TClass, typename TArgument>
+__inline CCallback<TArgument> Callback(TClass *object, bool (TClass:: *func)(TArgument *argument))
+{
+ return CCallback<TArgument>(object, func);
+}
+
///////////////////////////////////////////////////////////////////////////////
// http support
diff --git a/src/mir_app/src/menu_options.cpp b/src/mir_app/src/menu_options.cpp
index c2dfae7c87..3c6ce3cf55 100644
--- a/src/mir_app/src/menu_options.cpp
+++ b/src/mir_app/src/menu_options.cpp
@@ -572,12 +572,14 @@ public:
m_customName.Enable(true);
}
- void onMenuItemBeginDrag(CCtrlTreeView::TEventInfo *evt)
+ bool onMenuItemBeginDrag(CCtrlTreeView::TEventInfo *evt)
{
MenuItemOptData *p = (MenuItemOptData*)evt->nmtv->itemNew.lParam;
if (p->pimi != nullptr)
if (p->pimi->mi.flags & CMIF_UNMOVABLE)
- evt->nmhdr->code = 0; // reject an attempt to change item's position
+ return false; // reject an attempt to change item's position
+
+ return true;
}
};
diff --git a/src/mir_core/src/Windows/CCtrlTreeView.cpp b/src/mir_core/src/Windows/CCtrlTreeView.cpp
index 92ad166f91..4f4aeabf2f 100644
--- a/src/mir_core/src/Windows/CCtrlTreeView.cpp
+++ b/src/mir_core/src/Windows/CCtrlTreeView.cpp
@@ -161,12 +161,16 @@ LRESULT CCtrlTreeView::CustomWndProc(UINT msg, WPARAM wParam, LPARAM lParam)
m_bDragging = false;
ReleaseCapture();
- hti.pt.x = (short)LOWORD(lParam);
- hti.pt.y = (short)HIWORD(lParam) - GetItemHeight() / 2;
+ hti.pt.x = GET_X_LPARAM(lParam);
+ hti.pt.y = GET_Y_LPARAM(lParam) - GetItemHeight() / 2;
HitTest(&hti);
if (m_hDragItem == hti.hItem)
break;
+ TEventInfo evt = { this, (LPNMHDR)&hti};
+ if (!OnEndDrag.Check(&evt))
+ break;
+
if (hti.flags & TVHT_ABOVE)
hti.hItem = TVI_FIRST;
else if (hti.flags & TVHT_BELOW)
@@ -288,14 +292,14 @@ BOOL CCtrlTreeView::OnNotify(int, NMHDR *pnmh)
case TVN_SINGLEEXPAND: OnSingleExpand(&evt); return TRUE;
case TVN_BEGINDRAG:
- OnBeginDrag(&evt);
-
// user-defined can clear the event code to disable dragging
- if (m_bDndEnabled && pnmh->code) {
- ::SetCapture(m_hwnd);
- m_bDragging = true;
- m_hDragItem = evt.nmtv->itemNew.hItem;
- SelectItem(m_hDragItem);
+ if (m_bDndEnabled) {
+ if (OnBeginDrag.Check(&evt)) {
+ ::SetCapture(m_hwnd);
+ m_bDragging = true;
+ m_hDragItem = evt.nmtv->itemNew.hItem;
+ SelectItem(m_hDragItem);
+ }
}
return TRUE;