Don't send wxEVT_COMMAND_TREE_ITEM_MENU event without valid item in wxMSW.

The generic wxTreeCtrl version only sends this event when the mouse is right
clicked on a valid item so do the same in wxMSW version too for consistency.

This is also consistent with wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK event and
avoids strange problems with unexpected wxEVT_COMMAND_TREE_ITEM_MENU events
generated on right double click.

Finally, replace the checks for item validity in the event handler in the
sample with asserts which should loudly complain if it happens to be invalid.

Closes #11226.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65903 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2010-10-24 22:40:52 +00:00
parent 0bb84570ce
commit 22993989b4
2 changed files with 16 additions and 12 deletions

View File

@ -1571,13 +1571,14 @@ void MyTreeCtrl::OnItemStateClick(wxTreeEvent& event)
void MyTreeCtrl::OnItemMenu(wxTreeEvent& event)
{
wxTreeItemId itemId = event.GetItem();
MyTreeItemData *item = itemId.IsOk() ? (MyTreeItemData *)GetItemData(itemId)
: NULL;
wxCHECK_RET( itemId.IsOk(), "should have a valid item" );
MyTreeItemData *item = (MyTreeItemData *)GetItemData(itemId);
wxPoint clientpt = event.GetPoint();
wxPoint screenpt = ClientToScreen(clientpt);
wxLogMessage(wxT("OnItemMenu for item \"%s\" at screen coords (%i, %i)"),
item ? item->GetDesc() : wxT(""), screenpt.x, screenpt.y);
item->GetDesc(), screenpt.x, screenpt.y);
ShowMenu(itemId, clientpt);
event.Skip();
@ -1618,11 +1619,11 @@ void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt)
void MyTreeCtrl::OnItemRClick(wxTreeEvent& event)
{
wxTreeItemId itemId = event.GetItem();
MyTreeItemData *item = itemId.IsOk() ? (MyTreeItemData *)GetItemData(itemId)
: NULL;
wxCHECK_RET( itemId.IsOk(), "should have a valid item" );
wxLogMessage(wxT("Item \"%s\" right clicked"), item ? item->GetDesc()
: wxT(""));
MyTreeItemData *item = (MyTreeItemData *)GetItemData(itemId);
wxLogMessage(wxT("Item \"%s\" right clicked"), item->GetDesc());
event.Skip();
}

View File

@ -2727,13 +2727,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) )
{