X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b6885972eeaa04d4362950e0863e5e07da2770fd..cc3977bf132d40cb66c6b488890ef67a396d4a0a:/src/msw/treectrl.cpp diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index b0de8d30c9..6cb53d2876 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -1966,23 +1966,25 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select) // leave itemNew invalid } - // in spite of the docs (MSDN Jan 99 edition), we don't seem to receive - // the notification from the control (i.e. TVN_SELCHANG{ED|ING}), so - // send them ourselves - + // Recent versions of comctl32.dll send TVN_SELCHANG{ED,ING} events + // when we call TreeView_SelectItem() but apparently some old ones did + // not so send the events ourselves and ignore those generated by + // TreeView_SelectItem() if m_changingSelection is set. wxTreeEvent changingEvent(wxEVT_COMMAND_TREE_SEL_CHANGING, this, itemNew); changingEvent.SetOldItem(itemOld); if ( IsTreeEventAllowed(changingEvent) ) { + TempSetter set(m_changingSelection); + if ( !TreeView_SelectItem(GetHwnd(), HITEM(itemNew)) ) { wxLogLastError(wxT("TreeView_SelectItem")); } else // ok { - SetFocusedItem(item); + ::SetFocus(GetHwnd(), HITEM(item)); wxTreeEvent changedEvent(wxEVT_COMMAND_TREE_SEL_CHANGED, this, itemNew); @@ -2727,13 +2729,16 @@ wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) } // create the event - wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_MENU, this, item); + if ( item.IsOk() ) + { + wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_MENU, this, item); - event.m_pointDrag = pt; + event.m_pointDrag = pt; - if ( HandleTreeEvent(event) ) - processed = true; - //else: continue with generating wxEVT_CONTEXT_MENU in base class code + if ( HandleTreeEvent(event) ) + processed = true; + //else: continue with generating wxEVT_CONTEXT_MENU in base class code + } } else if ( (nMsg >= WM_MOUSEFIRST) && (nMsg <= WM_MOUSELAST) ) { @@ -3469,7 +3474,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // we have to handle both messages: case TVN_SELCHANGEDA: case TVN_SELCHANGEDW: - if ( !HasFlag(wxTR_MULTIPLE) || !m_changingSelection ) + if ( !m_changingSelection ) { eventType = wxEVT_COMMAND_TREE_SEL_CHANGED; } @@ -3477,7 +3482,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) case TVN_SELCHANGINGA: case TVN_SELCHANGINGW: - if ( !HasFlag(wxTR_MULTIPLE) || !m_changingSelection ) + if ( !m_changingSelection ) { if ( eventType == wxEVT_NULL ) eventType = wxEVT_COMMAND_TREE_SEL_CHANGING; @@ -3509,7 +3514,8 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // // to avoid such surprises, we force the generation of focus events // now, before we generate the selection change ones - SetFocus(); + if ( !m_changingSelection ) + SetFocus(); break; // instead of explicitly checking for _WIN32_IE, check if the