EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsing)
EVT_CONTEXT_MENU(MyTreeCtrl::OnContextMenu)
+ EVT_TREE_ITEM_MENU(TreeTest_Ctrl, MyTreeCtrl::OnItemMenu)
+
EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, MyTreeCtrl::OnSelChanged)
EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, MyTreeCtrl::OnSelChanging)
EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown)
default:
{
- if ( wxIsprint((int)keycode) )
+ if ( keycode < 128 && wxIsprint((int)keycode) )
key.Printf(wxT("'%c'"), (char)keycode);
else if ( keycode > 0 && keycode < 27 )
key.Printf(_("Ctrl-%c"), wxT('A') + keycode - 1);
wxLogMessage(wxT("OnItemActivated"));
}
+void MyTreeCtrl::OnItemMenu(wxTreeEvent& event)
+{
+ wxTreeItemId itemId = event.GetItem();
+ MyTreeItemData *item = itemId.IsOk() ? (MyTreeItemData *)GetItemData(itemId)
+ : NULL;
+
+ wxLogMessage(wxT("OnItemMenu for item \"%s\""), item ? item->GetDesc()
+ : _T(""));
+
+ event.Skip();
+}
+
void MyTreeCtrl::OnContextMenu(wxContextMenuEvent& event)
{
wxPoint pt = event.GetPosition();
wxTreeItemId item = GetSelection();
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)
+ // check if event was generated by keyboard (MSW-specific?)
+ if ( pt.x == -1 && pt.y == -1 ) //(this is how MSW indicates it)
{
- //attempt to guess where to show the menu
- if (item.IsOk())
+ // attempt to guess where to show the menu
+ if ( item.IsOk() )
{
- //if an item was clicked, show menu to the right of it
+ // if an item was clicked, show menu to the right of it
wxRect rect;
- GetBoundingRect(item, rect, true); //true = only the label
+ GetBoundingRect(item, rect, true /* only the label */);
pt = wxPoint(rect.GetRight(), rect.GetTop());
}
else
pt = wxPoint(0, 0);
}
}
- else
+ else // event was generated by mouse, use supplied coords
{
- //event was generated by mouse, use supplied coords
pt = ScreenToClient(pt);
}