X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e525c4ff96ae2a26543480a9894d873b2fa20755..b928bd059f8fba7e4601f4786d5b9c0ec8d47196:/samples/treectrl/treetest.cpp diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 31666e9df6..ab2c64abeb 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -154,6 +154,9 @@ IMPLEMENT_APP(MyApp) bool MyApp::OnInit() { + if ( !wxApp::OnInit() ) + return false; + // Create the main frame window MyFrame *frame = new MyFrame(wxT("wxTreeCtrl Test"), 50, 50, 450, 600); @@ -1084,8 +1087,12 @@ void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event) { m_draggedItem = event.GetItem(); - wxLogMessage(wxT("OnBeginDrag: started dragging %s"), - GetItemText(m_draggedItem).c_str()); + wxPoint clientpt = event.GetPoint(); + wxPoint screenpt = ClientToScreen(clientpt); + + wxLogMessage(wxT("OnBeginDrag: started dragging %s at screen coords (%i,%i)"), + GetItemText(m_draggedItem).c_str(), + screenpt.x, screenpt.y); event.Allow(); } @@ -1195,45 +1202,21 @@ void MyTreeCtrl::OnItemMenu(wxTreeEvent& event) wxTreeItemId itemId = event.GetItem(); MyTreeItemData *item = itemId.IsOk() ? (MyTreeItemData *)GetItemData(itemId) : NULL; + wxPoint clientpt = event.GetPoint(); + wxPoint screenpt = ClientToScreen(clientpt); - wxLogMessage(wxT("OnItemMenu for item \"%s\""), item ? item->GetDesc() - : _T("")); + wxLogMessage(wxT("OnItemMenu for item \"%s\" at screen coords (%i, %i)"), + item ? item->GetDesc() : _T(""), screenpt.x, screenpt.y); + ShowMenu(itemId, clientpt); event.Skip(); } void MyTreeCtrl::OnContextMenu(wxContextMenuEvent& event) { wxPoint pt = event.GetPosition(); - wxTreeItemId item; - wxLogMessage(wxT("OnContextMenu at screen coords (%i, %i)"), pt.x, pt.y); - - // check if event was generated by keyboard (MSW-specific?) - if ( pt.x == -1 && pt.y == -1 ) //(this is how MSW indicates it) - { - if ( !HasFlag(wxTR_MULTIPLE) ) - item = GetSelection(); - // attempt to guess where to show the menu - if ( item.IsOk() ) - { - // if an item was clicked, show menu to the right of it - wxRect rect; - GetBoundingRect(item, rect, true /* only the label */); - pt = wxPoint(rect.GetRight(), rect.GetTop()); - } - else - { - pt = wxPoint(0, 0); - } - } - else // event was generated by mouse, use supplied coords - { - pt = ScreenToClient(pt); - item = HitTest(pt); - } - - ShowMenu(item, pt); + wxLogMessage(wxT("OnContextMenu at screen coords (%i, %i)"), pt.x, pt.y); } void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt)