X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce3ed50dbe32d118321082db84c3a9abb047d5b7..efeb036598df39027d57d3dd9ea6fafc1232eadb:/src/msw/treectrl.cpp diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index f33b099016..07ff06e610 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -40,24 +40,12 @@ #include "wx/msw/private.h" -#ifndef __GNUWIN32__ - #include -#endif - -#ifdef GetFirstChild -#undef GetFirstChild -#endif - -#ifdef GetNextChild -#undef GetNextChild +#ifdef __GNUWIN32__ +#include "wx/msw/gnuwin32/extra.h" #endif -#ifdef GetNextSibling -#undef GetNextSibling -#endif - -#ifdef GetClassInfo -#undef GetClassInfo +#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) + #include #endif // Bug in headers, sometimes @@ -136,7 +124,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 +361,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 // ---------------------------------------------------------------------------- @@ -457,6 +453,22 @@ wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& WXUNUSED(item), return l; } +wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const +{ + // can this be done more efficiently? + long cookie; + + wxTreeItemId childLast, + child = GetFirstChild(item, cookie); + while ( child.IsOk() ) + { + childLast = child; + child = GetNextChild(item, cookie); + } + + return childLast; +} + wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const { return wxTreeItemId((WXHTREEITEM) TreeView_GetNextSibling(wxhWnd, (HTREEITEM) (WXHTREEITEM) item)); @@ -501,6 +513,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() ) { @@ -636,8 +655,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 @@ -677,7 +698,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) @@ -790,13 +811,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()); } @@ -854,7 +898,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; @@ -990,7 +1034,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); @@ -1007,6 +1051,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();