X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b9a7d4cc2f5f55df3d83f7cf2160cf9a509a4f2..afd0f084f419d769dba772863472a3f388fd6ab1:/src/msw/treectrl.cpp diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 4e277888cf..52c7d9f768 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "treectrl.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -32,6 +28,11 @@ #include "wx/msw/private.h" +// include "properly" +#include "wx/msw/wrapcctl.h" + +#include "wx/msw/missing.h" + // Set this to 1 to be _absolutely_ sure that repainting will work for all // comctl32.dll versions #define wxUSE_COMCTL32_SAFELY 0 @@ -41,20 +42,14 @@ #include "wx/dynarray.h" #include "wx/imaglist.h" #include "wx/settings.h" -#include "wx/msw/treectrl.h" +#include "wx/treectrl.h" #include "wx/msw/dragimag.h" -// include "properly" -#include "wx/msw/wrapcctl.h" - // macros to hide the cast ugliness // -------------------------------- -// ptr is the real item id, i.e. wxTreeItemId::m_pItem -#define HITEM_PTR(ptr) (HTREEITEM)(ptr) - -// item here is a wxTreeItemId -#define HITEM(item) HITEM_PTR((item).m_pItem) +// get HTREEITEM from wxTreeItemId +#define HITEM(item) ((HTREEITEM)(((item).m_pItem))) // the native control doesn't support multiple selections under MSW and we // have 2 ways to emulate them: either using TVS_CHECKBOXES style and let @@ -316,6 +311,11 @@ public: m_tree = tree; } + // give it a virtual dtor: not really needed as the class is never used + // polymorphically and not even allocated on heap at all, but this is safer + // (in case it ever is) and silences the compiler warnings for now + virtual ~wxTreeTraversal() { } + // do traverse the tree: visit all items (recursively by default) under the // given one; return true if all items were traversed or false if the // traversal was aborted because OnVisit returned false @@ -346,7 +346,8 @@ public: { m_selections.Empty(); - DoTraverse(tree->GetRootItem()); + if (tree->GetCount() > 0) + DoTraverse(tree->GetRootItem()); } virtual bool OnVisit(const wxTreeItemId& item) @@ -610,9 +611,6 @@ bool wxTreeTraversal::Traverse(const wxTreeItemId& root, bool recursively) void wxTreeCtrl::Init() { - m_imageListNormal = NULL; - m_imageListState = NULL; - m_ownsImageListNormal = m_ownsImageListState = false; m_textCtrl = NULL; m_hasAnyAttr = false; m_dragImage = NULL; @@ -677,7 +675,7 @@ bool wxTreeCtrl::Create(wxWindow *parent, wstyle |= TVS_CHECKBOXES; #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE -#ifndef __WXWINCE__ +#if !defined(__WXWINCE__) && defined(TVS_INFOTIP) // Need so that TVN_GETINFOTIP messages will be sent wstyle |= TVS_INFOTIP; #endif @@ -776,9 +774,6 @@ wxTreeCtrl::~wxTreeCtrl() // delete user data to prevent memory leaks // also deletes hidden root node storage. DeleteAllItems(); - - if (m_ownsImageListNormal) delete m_imageListNormal; - if (m_ownsImageListState) delete m_imageListState; } // ---------------------------------------------------------------------------- @@ -822,9 +817,9 @@ void wxTreeCtrl::DoSetItem(wxTreeViewItem* tvItem) } } -size_t wxTreeCtrl::GetCount() const +unsigned int wxTreeCtrl::GetCount() const { - return (size_t)TreeView_GetCount(GetHwnd()); + return (unsigned int)TreeView_GetCount(GetHwnd()); } unsigned int wxTreeCtrl::GetIndent() const @@ -837,22 +832,12 @@ void wxTreeCtrl::SetIndent(unsigned int indent) TreeView_SetIndent(GetHwnd(), indent); } -wxImageList *wxTreeCtrl::GetImageList() const -{ - return m_imageListNormal; -} - -wxImageList *wxTreeCtrl::GetStateImageList() const -{ - return m_imageListState; -} - void wxTreeCtrl::SetAnyImageList(wxImageList *imageList, int which) { // no error return - TreeView_SetImageList(GetHwnd(), - imageList ? imageList->GetHIMAGELIST() : 0, - which); + (void) TreeView_SetImageList(GetHwnd(), + imageList ? imageList->GetHIMAGELIST() : 0, + which); } void wxTreeCtrl::SetImageList(wxImageList *imageList) @@ -871,18 +856,6 @@ void wxTreeCtrl::SetStateImageList(wxImageList *imageList) m_ownsImageListState = false; } -void wxTreeCtrl::AssignImageList(wxImageList *imageList) -{ - SetImageList(imageList); - m_ownsImageListNormal = true; -} - -void wxTreeCtrl::AssignStateImageList(wxImageList *imageList) -{ - SetStateImageList(imageList); - m_ownsImageListState = true; -} - size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId& item, bool recursively) const { @@ -1633,11 +1606,11 @@ size_t wxTreeCtrl::GetSelections(wxArrayTreeItemIds& selections) const // Usual operations // ---------------------------------------------------------------------------- -wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent, - wxTreeItemId hInsertAfter, - const wxString& text, - int image, int selectedImage, - wxTreeItemData *data) +wxTreeItemId wxTreeCtrl::DoInsertAfter(const wxTreeItemId& parent, + const wxTreeItemId& hInsertAfter, + const wxString& text, + int image, int selectedImage, + wxTreeItemData *data) { wxCHECK_MSG( parent.IsOk() || !TreeView_GetRoot(GetHwnd()), wxTreeItemId(), @@ -1710,20 +1683,6 @@ wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent, // for compatibility only #if WXWIN_COMPATIBILITY_2_4 -wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent, - const wxString& text, - int image, int selImage, - long insertAfter) -{ - return DoInsertItem(parent, wxTreeItemId((void *)insertAfter), text, - image, selImage, NULL); -} - -wxImageList *wxTreeCtrl::GetImageList(int) const -{ - return GetImageList(); -} - void wxTreeCtrl::SetImageList(wxImageList *imageList, int) { SetImageList(imageList); @@ -1754,59 +1713,40 @@ wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text, return TVI_ROOT; } - return DoInsertItem(wxTreeItemId(), wxTreeItemId(), - text, image, selectedImage, data); -} - -wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent, - const wxString& text, - int image, int selectedImage, - wxTreeItemData *data) -{ - return DoInsertItem(parent, TVI_FIRST, - text, image, selectedImage, data); + return DoInsertAfter(wxTreeItemId(), wxTreeItemId(), + text, image, selectedImage, data); } -wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent, - const wxTreeItemId& idPrevious, - const wxString& text, - int image, int selectedImage, - wxTreeItemData *data) -{ - return DoInsertItem(parent, idPrevious, text, image, selectedImage, data); -} - -wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent, - size_t index, - const wxString& text, - int image, int selectedImage, - wxTreeItemData *data) +wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent, + size_t index, + const wxString& text, + int image, int selectedImage, + wxTreeItemData *data) { - // find the item from index - wxTreeItemIdValue cookie; - wxTreeItemId idPrev, idCur = GetFirstChild(parent, cookie); - while ( index != 0 && idCur.IsOk() ) + wxTreeItemId idPrev; + if ( index == (size_t)-1 ) { - index--; - - idPrev = idCur; - idCur = GetNextChild(parent, cookie); + // special value: append to the end + idPrev = TVI_LAST; } + else // find the item from index + { + wxTreeItemIdValue cookie; + wxTreeItemId idCur = GetFirstChild(parent, cookie); + while ( index != 0 && idCur.IsOk() ) + { + index--; - // assert, not check: if the index is invalid, we will append the item - // to the end - wxASSERT_MSG( index == 0, _T("bad index in wxTreeCtrl::InsertItem") ); + idPrev = idCur; + idCur = GetNextChild(parent, cookie); + } - return DoInsertItem(parent, idPrev, text, image, selectedImage, data); -} + // assert, not check: if the index is invalid, we will append the item + // to the end + wxASSERT_MSG( index == 0, _T("bad index in wxTreeCtrl::InsertItem") ); + } -wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent, - const wxString& text, - int image, int selectedImage, - wxTreeItemData *data) -{ - return DoInsertItem(parent, TVI_LAST, - text, image, selectedImage, data); + return DoInsertAfter(parent, idPrev, text, image, selectedImage, data); } void wxTreeCtrl::Delete(const wxTreeItemId& item) @@ -1834,7 +1774,7 @@ void wxTreeCtrl::DeleteChildren(const wxTreeItemId& item) size_t nCount = children.Count(); for ( size_t n = 0; n < nCount; n++ ) { - if ( !TreeView_DeleteItem(GetHwnd(), HITEM_PTR(children[n])) ) + if ( !TreeView_DeleteItem(GetHwnd(), HITEM(children[n])) ) { wxLogLastError(wxT("TreeView_DeleteItem")); } @@ -1868,7 +1808,7 @@ void wxTreeCtrl::DoExpand(const wxTreeItemId& item, int flag) // A hidden root can be neither expanded nor collapsed. wxCHECK_RET( !(m_windowStyle & wxTR_HIDE_ROOT) || (HITEM(item) != TVI_ROOT), - wxT("Can't expand/collapse hidden root node!") ) + wxT("Can't expand/collapse hidden root node!") ); // TreeView_Expand doesn't send TVN_ITEMEXPAND(ING) messages, so we must // emulate them. This behaviour has changed slightly with comctl32.dll @@ -1946,11 +1886,13 @@ void wxTreeCtrl::UnselectAll() for ( size_t n = 0; n < count; n++ ) { #if wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE - SetItemCheck(HITEM_PTR(selections[n]), false); + SetItemCheck(HITEM(selections[n]), false); #else // !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE - ::UnselectItem(GetHwnd(), HITEM_PTR(selections[n])); + ::UnselectItem(GetHwnd(), HITEM(selections[n])); #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE/!wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE } + + m_htSelStart.Unset(); } else { @@ -2000,16 +1942,6 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select) } } -void wxTreeCtrl::UnselectItem(const wxTreeItemId& item) -{ - SelectItem(item, false); -} - -void wxTreeCtrl::ToggleItemSelection(const wxTreeItemId& item) -{ - SelectItem(item, !IsSelected(item)); -} - void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item) { // no error return @@ -2082,13 +2014,13 @@ void wxTreeCtrl::DoEndEditLabel(bool discardChanges) DeleteTextCtrl(); } -wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& flags) +wxTreeItemId wxTreeCtrl::DoTreeHitTest(const wxPoint& point, int& flags) { TV_HITTESTINFO hitTestInfo; hitTestInfo.pt.x = (int)point.x; hitTestInfo.pt.y = (int)point.y; - TreeView_HitTest(GetHwnd(), &hitTestInfo); + (void) TreeView_HitTest(GetHwnd(), &hitTestInfo); flags = 0; @@ -2176,12 +2108,6 @@ int CALLBACK wxTreeSortHelper::Compare(LPARAM pItem1, GetIdFromData(tree, pItem2)); } -int wxTreeCtrl::OnCompareItems(const wxTreeItemId& item1, - const wxTreeItemId& item2) -{ - return wxStrcmp(GetItemText(item1), GetItemText(item2)); -} - void wxTreeCtrl::SortChildren(const wxTreeItemId& item) { wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); @@ -2241,17 +2167,42 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara WXLRESULT rc = 0; bool isMultiple = HasFlag(wxTR_MULTIPLE); -#ifdef WM_CONTEXTMENU + // This message is sent after a right-click, or when the "menu" key is pressed if ( nMsg == WM_CONTEXTMENU ) { + int x = GET_X_LPARAM(lParam), + y = GET_Y_LPARAM(lParam); + // Convert the screen point to a client point + wxPoint MenuPoint = ScreenToClient(wxPoint(x, y)); + wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_MENU, GetId() ); - event.m_item = GetSelection(); + + // can't use GetSelection() here as it would assert in multiselect mode + event.m_item = wxTreeItemId(TreeView_GetSelection(GetHwnd())); event.SetEventObject( this ); + + // Get the bounding rectangle for the item, including the non-text areas + wxRect ItemRect; + GetBoundingRect(event.m_item, ItemRect, false); + // If the point is inside the bounding rectangle, use it as the click position. + // This should be the case for WM_CONTEXTMENU as the result of a right-click + if (ItemRect.Inside(MenuPoint)) + { + event.m_pointDrag = MenuPoint; + } + // Use the Explorer standard of putting the menu at the left edge of the text, + // in the vertical middle of the text. Should be the case for the "menu" key + else + { + // Use the bounding rectangle of only the text part + GetBoundingRect(event.m_item, ItemRect, true); + event.m_pointDrag = wxPoint(ItemRect.GetX(), ItemRect.GetY() + ItemRect.GetHeight() / 2); + } + if ( GetEventHandler()->ProcessEvent(event) ) processed = true; //else: continue with generating wxEVT_CONTEXT_MENU in base class code } -#endif // WM_CONTEXTMENU else if ( (nMsg >= WM_MOUSEFIRST) && (nMsg <= WM_MOUSELAST) ) { // we only process mouse messages here and these parameters have the @@ -2260,6 +2211,12 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara y = GET_Y_LPARAM(lParam); HTREEITEM htItem = GetItemFromPoint(GetHwnd(), x, y); + TV_HITTESTINFO tvht; + tvht.pt.x = x; + tvht.pt.y = y; + + (void) TreeView_HitTest(GetHwnd(), &tvht); + switch ( nMsg ) { case WM_RBUTTONDOWN: @@ -2275,19 +2232,15 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara // newly selected item ::SelectItem(GetHwnd(), htItem); ::SetFocus(GetHwnd(), htItem); - - // default WM_RBUTTONUP handler enters modal loop inside - // DefWindowProc() waiting for WM_RBUTTONDOWN and then sends - // the resulting WM_CONTEXTMENU to the parent window, not us, - // which completely breaks everything so simply don't let it - // see this message at all - processed = true; break; #if !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE case WM_LBUTTONDOWN: - if ( htItem && isMultiple ) + if ( htItem && isMultiple && (tvht.flags & TVHT_ONITEM) != 0 ) { + m_htClickedItem = (WXHTREEITEM) htItem; + m_ptClick = wxPoint(x, y); + if ( wParam & MK_CONTROL ) { SetFocus(); @@ -2313,8 +2266,11 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara m_htSelStart = TreeView_GetSelection(GetHwnd()); } - SelectRange(GetHwnd(), HITEM(m_htSelStart), htItem, + if ( m_htSelStart ) + SelectRange(GetHwnd(), HITEM(m_htSelStart), htItem, !(wParam & MK_CONTROL)); + else + ::SelectItem(GetHwnd(), htItem); ::SetFocus(GetHwnd(), htItem); @@ -2325,22 +2281,20 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara // avoid doing anything if we click on the only // currently selected item + SetFocus(); + wxArrayTreeItemIds selections; size_t count = GetSelections(selections); if ( count == 0 || count > 1 || - HITEM_PTR(selections[0]) != htItem ) + HITEM(selections[0]) != htItem ) { // clear the previously selected items, if the // user clicked outside of the present selection. // otherwise, perform the deselection on mouse-up. // this allows multiple drag and drop to work. - if (IsItemSelected(GetHwnd(), htItem)) - { - ::SetFocus(GetHwnd(), htItem); - } - else + if (!IsItemSelected(GetHwnd(), htItem)) { UnselectAll(); @@ -2352,6 +2306,8 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara TreeView_SelectItem(GetHwnd(), 0); ::SelectItem(GetHwnd(), htItem); } + ::SetFocus(GetHwnd(), htItem); + processed = true; } // reset on any click without Shift @@ -2362,6 +2318,45 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE case WM_MOUSEMOVE: +#ifndef __WXWINCE__ + if ( m_htClickedItem ) + { + int cx = abs(m_ptClick.x - x); + int cy = abs(m_ptClick.y - y); + + if ( cx > GetSystemMetrics( SM_CXDRAG ) || cy > GetSystemMetrics( SM_CYDRAG ) ) + { + HWND pWnd = ::GetParent( GetHwnd() ); + if ( pWnd ) + { + NM_TREEVIEW tv; + + tv.hdr.hwndFrom = GetHwnd(); + tv.hdr.idFrom = ::GetWindowLong( GetHwnd(), GWL_ID ); + tv.hdr.code = TVN_BEGINDRAG; + + tv.itemNew.hItem = HITEM(m_htClickedItem); + + TVITEM tviAux; + ZeroMemory(&tviAux, sizeof(tviAux)); + tviAux.hItem = HITEM(m_htClickedItem); + tviAux.mask = TVIF_STATE | TVIF_PARAM; + tviAux.stateMask = 0xffffffff; + TreeView_GetItem( GetHwnd(), &tviAux ); + + tv.itemNew.state = tviAux.state; + tv.itemNew.lParam = tviAux.lParam; + + tv.ptDrag.x = x; + tv.ptDrag.y = y; + + ::SendMessage( pWnd, WM_NOTIFY, tv.hdr.idFrom, (LPARAM)&tv ); + } + m_htClickedItem.Unset(); + } + } +#endif // __WXWINCE__ + if ( m_dragImage ) { m_dragImage->Move(wxPoint(x, y)); @@ -2390,7 +2385,10 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara { UnselectAll(); TreeView_SelectItem(GetHwnd(), htItem); + ::SelectItem(GetHwnd(), htItem); + ::SetFocus(GetHwnd(), htItem); } + m_htClickedItem.Unset(); } // fall through @@ -2431,7 +2429,7 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara { // TreeView_GetItemRect() will return false if item is not visible, // which may happen perfectly well - if ( TreeView_GetItemRect(GetHwnd(), HITEM_PTR(selections[n]), + if ( TreeView_GetItemRect(GetHwnd(), HITEM(selections[n]), &rect, TRUE) ) { ::InvalidateRect(GetHwnd(), &rect, FALSE); @@ -2443,79 +2441,82 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara bool bCtrl = wxIsCtrlDown(), bShift = wxIsShiftDown(); - // we handle.arrows and space, but not page up/down and home/end: the - // latter should be easy, but not the former - HTREEITEM htSel = (HTREEITEM)TreeView_GetSelection(GetHwnd()); - if ( !m_htSelStart ) - { - m_htSelStart = htSel; - } - - if ( wParam == VK_SPACE ) + switch ( wParam ) { - if ( bCtrl ) - { - ::ToggleItemSelection(GetHwnd(), htSel); - } - else - { - UnselectAll(); - - ::SelectItem(GetHwnd(), htSel); - } + case VK_SPACE: + if ( bCtrl ) + { + ::ToggleItemSelection(GetHwnd(), htSel); + } + else + { + UnselectAll(); - processed = true; - } - else if ( wParam == VK_UP || wParam == VK_DOWN ) - { - if ( !bCtrl && !bShift ) - { - // no modifiers, just clear selection and then let the default - // processing to take place - UnselectAll(); - } - else if ( htSel ) - { - (void)wxControl::MSWWindowProc(nMsg, wParam, lParam); + ::SelectItem(GetHwnd(), htSel); + } - HTREEITEM htNext = (HTREEITEM)(wParam == VK_UP - ? TreeView_GetPrevVisible(GetHwnd(), htSel) - : TreeView_GetNextVisible(GetHwnd(), htSel)); + processed = true; + break; - if ( !htNext ) + case VK_UP: + case VK_DOWN: + if ( !bCtrl && !bShift ) { - // at the top/bottom - htNext = htSel; + // no modifiers, just clear selection and then let the default + // processing to take place + UnselectAll(); } - - if ( bShift ) + else if ( htSel ) { - SelectRange(GetHwnd(), HITEM(m_htSelStart), htNext); + (void)wxControl::MSWWindowProc(nMsg, wParam, lParam); + + HTREEITEM htNext = (HTREEITEM) + TreeView_GetNextItem + ( + GetHwnd(), + htSel, + wParam == VK_UP ? TVGN_PREVIOUSVISIBLE + : TVGN_NEXTVISIBLE + ); + + if ( !htNext ) + { + // at the top/bottom + htNext = htSel; + } + + if ( bShift ) + { + if ( !m_htSelStart ) + m_htSelStart = htSel; + + SelectRange(GetHwnd(), HITEM(m_htSelStart), htNext); + } + else // bCtrl + { + // without changing selection + ::SetFocus(GetHwnd(), htNext); + } + + processed = true; } - else // bCtrl + break; + + case VK_HOME: + case VK_END: + case VK_PRIOR: + case VK_NEXT: + // TODO: handle Shift/Ctrl with these keys + if ( !bCtrl && !bShift ) { - // without changing selection - ::SetFocus(GetHwnd(), htNext); - } + UnselectAll(); - processed = true; - } + m_htSelStart.Unset(); + } } } #endif // !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE - else if ( nMsg == WM_CHAR ) - { - // don't let the control process Space and Return keys because it - // doesn't do anything useful with them anyhow but always beeps - // annoyingly when it receives them and there is no way to turn it off - // simply if you just process TREEITEM_ACTIVATED event to which Space - // and Enter presses are mapped in your code - if ( wParam == VK_SPACE || wParam == VK_RETURN ) - { - processed = true; - } - } else if ( nMsg == WM_COMMAND ) { // if we receive a EN_KILLFOCUS command from the in-place edit control @@ -2541,6 +2542,46 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara return rc; } +WXLRESULT +wxTreeCtrl::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) +{ + // default WM_RBUTTONDOWN handler enters modal loop inside DefWindowProc() + // waiting for WM_RBUTTONUP and then sends the resulting WM_CONTEXTMENU to + // the parent window, not us, which completely breaks everything so simply + // don't let it see this message at all + if ( nMsg == WM_RBUTTONDOWN ) + return 0; + + // but because of the above we don't get NM_RCLICK which is normally + // generated by tree window proc when the modal loop mentioned above ends + // because the mouse is released -- synthesize it ourselves instead + if ( nMsg == WM_RBUTTONUP ) + { + NMHDR hdr; + hdr.hwndFrom = GetHwnd(); + hdr.idFrom = GetId(); + hdr.code = NM_RCLICK; + + WXLPARAM rc; + MSWOnNotify(GetId(), (LPARAM)&hdr, &rc); + + // continue as usual + } + + if ( nMsg == WM_CHAR ) + { + // also don't let the control process Space and Return keys because it + // doesn't do anything useful with them anyhow but always beeps + // annoyingly when it receives them and there is no way to turn it off + // simply if you just process TREEITEM_ACTIVATED event to which Space + // and Enter presses are mapped in your code + if ( wParam == VK_SPACE || wParam == VK_RETURN ) + return 0; + } + + return wxControl::MSWDefWindowProc(nMsg, wParam, lParam); +} + // process WM_NOTIFY Windows message bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) { @@ -2577,6 +2618,10 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) eventType = wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT; TV_DISPINFO *info = (TV_DISPINFO *)lParam; + // although the user event handler may still veto it, it is + // important to set it now so that calls to SetItemText() from + // the event handler would change the text controls contents + m_idEdited = event.m_item = info->item.hItem; event.m_label = info->item.pszText; event.m_editCancelled = false; @@ -2625,6 +2670,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) break; } +#ifdef TVN_GETINFOTIP case TVN_GETINFOTIP: { eventType = wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP; @@ -2635,6 +2681,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) break; } +#endif #endif case TVN_GETDISPINFO: @@ -2691,12 +2738,12 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // fabricate the lParam and wParam parameters sufficiently // similar to the ones from a "real" WM_KEYDOWN so that // CreateKeyEvent() works correctly - WXLPARAM lParam = - (::GetKeyState(VK_MENU) < 0 ? KF_ALTDOWN : 0) << 16; + const bool isAltDown = ::GetKeyState(VK_MENU) < 0; + WXLPARAM lParam = (isAltDown ? KF_ALTDOWN : 0) << 16; WXWPARAM wParam = info->wVKey; - int keyCode = wxCharCodeMSWToWX(info->wVKey); + int keyCode = wxCharCodeMSWToWX(wParam); if ( !keyCode ) { // wxCharCodeMSWToWX() returns 0 to indicate that this is a @@ -2710,7 +2757,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) wParam); // a separate event for Space/Return - if ( !wxIsCtrlDown() && !wxIsShiftDown() && + if ( !wxIsCtrlDown() && !wxIsShiftDown() && !isAltDown && ((info->wVKey == VK_SPACE) || (info->wVKey == VK_RETURN)) ) { wxTreeEvent event2(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, @@ -2942,8 +2989,9 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) case TVN_BEGINLABELEDIT: // return true to cancel label editing *result = !event.IsAllowed(); + // set ES_WANTRETURN ( like we do in BeginLabelEdit ) - if(event.IsAllowed()) + if ( event.IsAllowed() ) { HWND hText = TreeView_GetEditControl(GetHwnd()); if(hText != NULL) @@ -2968,6 +3016,10 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) | wxTE_PROCESS_ENTER); } } + else // we had set m_idEdited before + { + m_idEdited.Unset(); + } break; case TVN_ENDLABELEDIT: @@ -2984,6 +3036,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) break; #ifndef __WXWINCE__ +#ifdef TVN_GETINFOTIP case TVN_GETINFOTIP: { // If the user permitted a tooltip change, change it @@ -2993,6 +3046,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) } } break; +#endif #endif case TVN_SELCHANGING: @@ -3097,14 +3151,4 @@ int wxTreeCtrl::GetState(const wxTreeItemId& node) return STATEIMAGEMASKTOINDEX(tvi.state); } -#if WXWIN_COMPATIBILITY_2_2 - -wxTreeItemId wxTreeCtrl::GetParent(const wxTreeItemId& item) const -{ - return GetItemParent( item ); -} - -#endif // WXWIN_COMPATIBILITY_2_2 - #endif // wxUSE_TREECTRL -