X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/978f38c238bb83dbb5a73104e4e6870d984dd058..d427503c3696486ef84cd0e5081884ccd8d6b434:/src/msw/treectrl.cpp diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 577946bc0b..e61d985c06 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -27,8 +27,19 @@ #pragma hdrstop #endif +#include "wx/window.h" +#include "wx/msw/private.h" + #ifndef WX_PRECOMP - #include "wx/wx.h" + #include "wx/settings.h" +#endif + +// Mingw32 is a bit mental even though this is done in winundef +#ifdef GetFirstChild +#undef GetFirstChild +#endif +#ifdef GetNextSibling +#undef GetNextSibling #endif #if defined(__WIN95__) @@ -38,28 +49,14 @@ #include "wx/imaglist.h" #include "wx/msw/treectrl.h" -#include "wx/msw/private.h" +#ifdef __GNUWIN32__ +#include "wx/msw/gnuwin32/extra.h" +#endif #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) #include #endif -#ifdef GetFirstChild -#undef GetFirstChild -#endif - -#ifdef GetNextChild -#undef GetNextChild -#endif - -#ifdef GetNextSibling -#undef GetNextSibling -#endif - -#ifdef GetClassInfo -#undef GetClassInfo -#endif - // Bug in headers, sometimes #ifndef TVIS_FOCUSED #define TVIS_FOCUSED 0x0001 @@ -136,7 +133,8 @@ bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, m_windowId = (id == -1) ? NewControlId() : id; - DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | TVS_HASLINES; + DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | TVS_HASLINES | TVS_SHOWSELALWAYS ; + bool want3D; WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; @@ -372,6 +370,13 @@ void wxTreeCtrl::SetItemBold(const wxTreeItemId& item, bool bold) DoSetItem(&tvItem); } +void wxTreeCtrl::SetItemDropHighlight(const wxTreeItemId& item, bool highlight) +{ + wxTreeViewItem tvItem(item, TVIF_STATE, TVIS_DROPHILITED); + tvItem.state = highlight ? TVIS_DROPHILITED : 0; + DoSetItem(&tvItem); +} + // ---------------------------------------------------------------------------- // Item status // ---------------------------------------------------------------------------- @@ -463,11 +468,11 @@ wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const long cookie; wxTreeItemId childLast, - child = GetFirstChild(last, cookie); + child = GetFirstChild(item, cookie); while ( child.IsOk() ) { childLast = child; - child = GetNextChild(last, cookie); + child = GetNextChild(item, cookie); } return childLast; @@ -517,6 +522,13 @@ wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent, TV_INSERTSTRUCT tvIns; tvIns.hParent = (HTREEITEM) (WXHTREEITEM)parent; tvIns.hInsertAfter = (HTREEITEM) (WXHTREEITEM) hInsertAfter; + + // This is how we insert the item as the first child: supply a NULL hInsertAfter + if (tvIns.hInsertAfter == (HTREEITEM) 0) + { + tvIns.hInsertAfter = TVI_FIRST; + } + UINT mask = 0; if ( !text.IsEmpty() ) { @@ -652,8 +664,10 @@ void wxTreeCtrl::DeleteAllItems() void wxTreeCtrl::DoExpand(const wxTreeItemId& item, int flag) { - wxASSERT_MSG( flag == TVE_COLLAPSE || flag == TVE_COLLAPSERESET || - flag == TVE_EXPAND || flag == TVE_TOGGLE, + wxASSERT_MSG( flag == TVE_COLLAPSE || + flag == (TVE_COLLAPSE | TVE_COLLAPSERESET) || + flag == TVE_EXPAND || + flag == TVE_TOGGLE, "Unknown flag in wxTreeCtrl::DoExpand" ); // TreeView_Expand doesn't send TVN_ITEMEXPAND(ING) messages, so we must @@ -693,7 +707,7 @@ void wxTreeCtrl::Collapse(const wxTreeItemId& item) void wxTreeCtrl::CollapseAndReset(const wxTreeItemId& item) { - DoExpand(item, TVE_COLLAPSERESET); + DoExpand(item, TVE_COLLAPSE | TVE_COLLAPSERESET); } void wxTreeCtrl::Toggle(const wxTreeItemId& item) @@ -806,13 +820,36 @@ wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& flags) return wxTreeItemId((WXHTREEITEM) hitTestInfo.hItem); } +bool wxTreeCtrl::GetBoundingRect(const wxTreeItemId& item, + wxRect& rect, + bool textOnly) const +{ + RECT rc; + if ( TreeView_GetItemRect(wxhWnd, (HTREEITEM)(WXHTREEITEM)item, + &rc, textOnly) ) + { + rect = wxRect(wxPoint(rc.left, rc.top), wxPoint(rc.right, rc.bottom)); + + return TRUE; + } + else + { + // couldn't retrieve rect: for example, item isn't visible + return FALSE; + } +} + // ---------------------------------------------------------------------------- // sorting stuff // ---------------------------------------------------------------------------- + static int CALLBACK TreeView_CompareCallback(wxTreeItemData *pItem1, wxTreeItemData *pItem2, wxTreeCtrl *tree) { + wxCHECK_MSG( pItem1 && pItem2, 0, + _T("sorting tree without data doesn't make sense") ); + return tree->OnCompareItems(pItem1->GetId(), pItem2->GetId()); } @@ -870,7 +907,7 @@ bool wxTreeCtrl::MSWCommand(WXUINT cmd, WXWORD id) } // process WM_NOTIFY Windows message -bool wxTreeCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result) +bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) { wxTreeEvent event(wxEVT_NULL, m_windowId); wxEventType eventType = wxEVT_NULL; @@ -1006,7 +1043,7 @@ bool wxTreeCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result) } default: - return wxControl::MSWNotify(wParam, lParam, result); + return wxControl::MSWOnNotify(idCtrl, lParam, result); } event.SetEventObject(this); @@ -1023,6 +1060,7 @@ bool wxTreeCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result) NM_TREEVIEW* tv = (NM_TREEVIEW *)lParam; wxTreeItemData *data = (wxTreeItemData *)tv->itemOld.lParam; delete data; // may be NULL, ok + processed = TRUE; // Make sure we don't get called twice } *result = !event.IsAllowed();