bool MyApp::OnInit()
{
+ if ( !wxApp::OnInit() )
+ return false;
+
// Create the main frame window
MyFrame *frame = new MyFrame(wxT("wxTreeCtrl Test"), 50, 50, 450, 600);
{
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();
}
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)