X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/06e38c8e2e9738fe65ccc21349b7328cac5df2de..44c4a3348693414bace13852e50d926c1aa9f08b:/src/msw/treectrl.cpp diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 69cfdaf31c..7fcab3a9a8 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -54,7 +54,7 @@ #undef GetNextSibling #endif -#include "wx/treectrl.h" +#include "wx/msw/treectrl.h" // Bug in headers, sometimes #ifndef TVIS_FOCUSED @@ -319,14 +319,7 @@ wxTreeItemData *wxTreeCtrl::GetItemData(const wxTreeItemId& item) const return NULL; } - wxTreeItemData *data = (wxTreeItemData *)tvItem.lParam; - if ( data != NULL ) - { - // the data object should know about its id - data->m_itemId = item; - } - - return data; + return (wxTreeItemData *)tvItem.lParam; } void wxTreeCtrl::SetItemData(const wxTreeItemId& item, wxTreeItemData *data) @@ -336,16 +329,29 @@ void wxTreeCtrl::SetItemData(const wxTreeItemId& item, wxTreeItemData *data) DoSetItem(&tvItem); } +void wxTreeCtrl::SetItemHasChildren(const wxTreeItemId& item, bool has) +{ + wxTreeViewItem tvItem(item, TVIF_CHILDREN); + tvItem.cChildren = (int)has; + DoSetItem(&tvItem); +} + +void wxTreeCtrl::SetItemBold(const wxTreeItemId& item, bool bold) +{ + wxTreeViewItem tvItem(item, TVIF_STATE, TVIS_BOLD); + tvItem.state = bold ? TVIS_BOLD : 0; + DoSetItem(&tvItem); +} + // ---------------------------------------------------------------------------- // Item status // ---------------------------------------------------------------------------- bool wxTreeCtrl::IsVisible(const wxTreeItemId& item) const { + // Bug in Gnu-Win32 headers, so don't use the macro TreeView_GetItemRect RECT rect; -// return (TreeView_GetItemRect(wxhWnd, (HTREEITEM) (WXHTREEITEM)item, &rect, FALSE) != 0); - // Bug in Gnu-Win32 headers, so don't use the macro. - return (SendMessage((wxhWnd), TVM_GETITEMRECT, (WPARAM) FALSE, (LPARAM) & rect) != 0); + return SendMessage(wxhWnd, TVM_GETITEMRECT, FALSE, (LPARAM)&rect) != 0; } @@ -376,18 +382,26 @@ bool wxTreeCtrl::IsSelected(const wxTreeItemId& item) const return (tvItem.state & TVIS_SELECTED) != 0; } +bool wxTreeCtrl::IsBold(const wxTreeItemId& item) const +{ + wxTreeViewItem tvItem(item, TVIF_STATE, TVIS_BOLD); + DoGetItem(&tvItem); + + return (tvItem.state & TVIS_BOLD) != 0; +} + // ---------------------------------------------------------------------------- // navigation // ---------------------------------------------------------------------------- wxTreeItemId wxTreeCtrl::GetRootItem() const { - return wxTreeItemId(TreeView_GetRoot(wxhWnd)); + return wxTreeItemId((WXHTREEITEM) TreeView_GetRoot(wxhWnd)); } wxTreeItemId wxTreeCtrl::GetSelection() const { - return wxTreeItemId(TreeView_GetSelection(wxhWnd)); + return wxTreeItemId((WXHTREEITEM) TreeView_GetSelection(wxhWnd)); } wxTreeItemId wxTreeCtrl::GetParent(const wxTreeItemId& item) const @@ -407,23 +421,25 @@ wxTreeItemId wxTreeCtrl::GetFirstChild(const wxTreeItemId& item, wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& WXUNUSED(item), long& _cookie) const { - return wxTreeItemId(TreeView_GetNextSibling(wxhWnd, - (HTREEITEM) (WXHTREEITEM)_cookie)); + wxTreeItemId l=wxTreeItemId((WXHTREEITEM) TreeView_GetNextSibling(wxhWnd, + (HTREEITEM) (WXHTREEITEM)_cookie)); + _cookie=(long)l; + return l; } wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const { - return wxTreeItemId(TreeView_GetNextSibling(wxhWnd, (HTREEITEM) (WXHTREEITEM) item)); + return wxTreeItemId((WXHTREEITEM) TreeView_GetNextSibling(wxhWnd, (HTREEITEM) (WXHTREEITEM) item)); } wxTreeItemId wxTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const { - return wxTreeItemId(TreeView_GetPrevSibling(wxhWnd, (HTREEITEM) (WXHTREEITEM) item)); + return wxTreeItemId((WXHTREEITEM) TreeView_GetPrevSibling(wxhWnd, (HTREEITEM) (WXHTREEITEM) item)); } wxTreeItemId wxTreeCtrl::GetFirstVisibleItem() const { - return wxTreeItemId(TreeView_GetFirstVisible(wxhWnd)); + return wxTreeItemId((WXHTREEITEM) TreeView_GetFirstVisible(wxhWnd)); } wxTreeItemId wxTreeCtrl::GetNextVisible(const wxTreeItemId& item) const @@ -431,7 +447,7 @@ wxTreeItemId wxTreeCtrl::GetNextVisible(const wxTreeItemId& item) const wxASSERT_MSG( IsVisible(item), "The item you call GetNextVisible() " "for must be visible itself!"); - return wxTreeItemId(TreeView_GetNextVisible(wxhWnd, (HTREEITEM) (WXHTREEITEM) item)); + return wxTreeItemId((WXHTREEITEM) TreeView_GetNextVisible(wxhWnd, (HTREEITEM) (WXHTREEITEM) item)); } wxTreeItemId wxTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const @@ -439,7 +455,7 @@ wxTreeItemId wxTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const wxASSERT_MSG( IsVisible(item), "The item you call GetPrevVisible() " "for must be visible itself!"); - return wxTreeItemId(TreeView_GetPrevVisible(wxhWnd, (HTREEITEM) (WXHTREEITEM) item)); + return wxTreeItemId((WXHTREEITEM) TreeView_GetPrevVisible(wxhWnd, (HTREEITEM) (WXHTREEITEM) item)); } // ---------------------------------------------------------------------------- @@ -466,6 +482,12 @@ wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent, { mask |= TVIF_IMAGE; tvIns.item.iImage = image; + + if ( selectedImage == -1 ) + { + // take the same image for selected icon if not specified + selectedImage = image; + } } if ( selectedImage != -1 ) @@ -488,6 +510,12 @@ wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent, wxLogLastError("TreeView_InsertItem"); } + if ( data != NULL ) + { + // associate the application tree item with Win32 tree item handle + data->SetId((WXHTREEITEM)id); + } + return wxTreeItemId((WXHTREEITEM)id); } @@ -538,9 +566,6 @@ wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent, void wxTreeCtrl::Delete(const wxTreeItemId& item) { - wxTreeItemData *data = GetItemData(item); - delete data; // may be NULL, ok - if ( !TreeView_DeleteItem(wxhWnd, (HTREEITEM)(WXHTREEITEM)item) ) { wxLogLastError("TreeView_DeleteItem"); @@ -606,6 +631,11 @@ void wxTreeCtrl::Toggle(const wxTreeItemId& item) DoExpand(item, TVE_TOGGLE); } +void wxTreeCtrl::ExpandItem(const wxTreeItemId& item, int action) +{ + DoExpand(item, action); +} + void wxTreeCtrl::Unselect() { SelectItem(wxTreeItemId((WXHTREEITEM) 0)); @@ -720,6 +750,12 @@ void wxTreeCtrl::SortChildren(const wxTreeItemId& item, } } +// TODO +size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId& item, bool recursively) +{ + return 0; +} + // ---------------------------------------------------------------------------- // implementation // ---------------------------------------------------------------------------- @@ -749,7 +785,7 @@ bool wxTreeCtrl::MSWCommand(WXUINT cmd, WXWORD id) } // process WM_NOTIFY Windows message -bool wxTreeCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam) +bool wxTreeCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result) { wxTreeEvent event(wxEVT_NULL, m_windowId); wxEventType eventType = wxEVT_NULL; @@ -875,46 +911,38 @@ bool wxTreeCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam) } default: - return wxControl::MSWNotify(wParam, lParam); + return wxControl::MSWNotify(wParam, lParam, result); } event.SetEventObject(this); event.SetEventType(eventType); - bool rc = GetEventHandler()->ProcessEvent(event); + bool processed = GetEventHandler()->ProcessEvent(event); // post processing - switch ( hdr->code ) + if ( hdr->code == TVN_DELETEITEM ) { // NB: we might process this message using wxWindows event tables, but // due to overhead of wxWin event system we prefer to do it here // (otherwise deleting a tree with many items is just too slow) - case TVN_DELETEITEM: - { - NM_TREEVIEW* tv = (NM_TREEVIEW *)lParam; - wxTreeItemData *data = (wxTreeItemData *)tv->itemOld.lParam; - delete data; // may be NULL, ok - } - break; - - case TVN_ITEMEXPANDING: - // if user called Veto(), don't allow expansion/collapse by - // returning TRUE from here - rc = event.m_code != 0; - break; + NM_TREEVIEW* tv = (NM_TREEVIEW *)lParam; + wxTreeItemData *data = (wxTreeItemData *)tv->itemOld.lParam; + delete data; // may be NULL, ok } - return rc; + *result = !event.IsAllowed(); + + return processed; } // ---------------------------------------------------------------------------- // Tree event // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxCommandEvent) +IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxNotifyEvent) wxTreeEvent::wxTreeEvent(wxEventType commandType, int id) - : wxCommandEvent(commandType, id) + : wxNotifyEvent(commandType, id) { m_code = 0; m_itemOld = 0;