return correct item and position from wxTreeEvent::GetItem/Point() (patch 1622166)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44118 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-01-07 15:43:22 +00:00
parent 0d93bb5039
commit 8f6dc819f8
2 changed files with 45 additions and 50 deletions

View File

@@ -1084,8 +1084,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 +1199,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);
}
void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt)