diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index fa35d9f639..f22c467189 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -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(); } diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index b0de8d30c9..971470d442 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -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) ) {