From 3986f667cb0f3fffeaee637dcee097b582e240ca Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 28 Mar 2023 14:14:31 +0300 Subject: CCtrlTreeView: OnBeginDrag / OnEndDrag callbacks became boolean --- include/m_gui.h | 2 ++ include/m_system.h | 26 +++++++++++++++++++++++--- src/mir_app/src/menu_options.cpp | 6 ++++-- src/mir_core/src/Windows/CCtrlTreeView.cpp | 22 +++++++++++++--------- 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 OnBeginRDrag; CCallback OnCustomDraw; CCallback OnDeleteItem; + CCallback OnEndDrag; CCallback OnEndLabelEdit; CCallback OnGetDispInfo; CCallback 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 __inline CCallbackImp(TClass *object, void (TClass:: *func)(TArgument *argument)) : m_object((CDummy *)object), m_func((TFnCallback)func) - { - } + {} + + template + __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 __inline CCallback(TClass *object, void (TClass:: *func)(TArgument *argument)) : CCallbackImp(object, func) {} + template + __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 @@ -652,6 +666,12 @@ __inline CCallback Callback(TClass *object, void (TClass:: *func)(TAr return CCallback(object, func); } +template +__inline CCallback Callback(TClass *object, bool (TClass:: *func)(TArgument *argument)) +{ + return CCallback(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; -- cgit v1.2.3