added state image support (patch 530155)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21864 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -294,6 +294,7 @@ BEGIN_DECLARE_EVENT_TYPES()
|
|||||||
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, 615)
|
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, 615)
|
||||||
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, 616)
|
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, 616)
|
||||||
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_END_DRAG, 617)
|
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_END_DRAG, 617)
|
||||||
|
DECLARE_EVENT_TYPE(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, 618)
|
||||||
END_DECLARE_EVENT_TYPES()
|
END_DECLARE_EVENT_TYPES()
|
||||||
|
|
||||||
// GetItem() returns the item being dragged, GetPoint() the mouse coords
|
// GetItem() returns the item being dragged, GetPoint() the mouse coords
|
||||||
@@ -346,6 +347,9 @@ END_DECLARE_EVENT_TYPES()
|
|||||||
#define EVT_TREE_ITEM_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
|
#define EVT_TREE_ITEM_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
|
||||||
#define EVT_TREE_ITEM_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
|
#define EVT_TREE_ITEM_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
|
||||||
|
|
||||||
|
// GetItem() returns the item whose state image was clicked on
|
||||||
|
#define EVT_TREE_STATE_IMAGE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL ),
|
||||||
|
|
||||||
#endif // wxUSE_TREECTRL
|
#endif // wxUSE_TREECTRL
|
||||||
|
|
||||||
#endif // _WX_TREEBASE_H_
|
#endif // _WX_TREEBASE_H_
|
||||||
|
@@ -131,9 +131,9 @@ BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl)
|
|||||||
EVT_TREE_ITEM_EXPANDING(TreeTest_Ctrl, MyTreeCtrl::OnItemExpanding)
|
EVT_TREE_ITEM_EXPANDING(TreeTest_Ctrl, MyTreeCtrl::OnItemExpanding)
|
||||||
EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsed)
|
EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsed)
|
||||||
EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsing)
|
EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsing)
|
||||||
EVT_TREE_ITEM_RIGHT_CLICK(TreeTest_Ctrl, MyTreeCtrl::OnItemRightClick)
|
//EVT_TREE_ITEM_RIGHT_CLICK(TreeTest_Ctrl, MyTreeCtrl::OnItemRightClick)
|
||||||
|
|
||||||
EVT_RIGHT_UP(MyTreeCtrl::OnRMouseUp)
|
EVT_CONTEXT_MENU(MyTreeCtrl::OnContextMenu)
|
||||||
EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, MyTreeCtrl::OnSelChanged)
|
EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, MyTreeCtrl::OnSelChanged)
|
||||||
EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, MyTreeCtrl::OnSelChanging)
|
EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, MyTreeCtrl::OnSelChanging)
|
||||||
EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown)
|
EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown)
|
||||||
@@ -1102,10 +1102,35 @@ void MyTreeCtrl::OnItemRightClick(wxTreeEvent& event)
|
|||||||
ShowMenu(event.GetItem(), event.GetPoint());
|
ShowMenu(event.GetItem(), event.GetPoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyTreeCtrl::OnRMouseUp(wxMouseEvent& event)
|
void MyTreeCtrl::OnContextMenu(wxContextMenuEvent& event)
|
||||||
{
|
{
|
||||||
wxPoint pt = event.GetPosition();
|
wxPoint pt = event.GetPosition();
|
||||||
ShowMenu(HitTest(pt), pt);
|
wxTreeItemId item = GetSelection();
|
||||||
|
wxLogMessage("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)
|
||||||
|
{
|
||||||
|
//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); //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);
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowMenu(item, pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt)
|
void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt)
|
||||||
|
@@ -73,7 +73,7 @@ public:
|
|||||||
void OnBeginLabelEdit(wxTreeEvent& event);
|
void OnBeginLabelEdit(wxTreeEvent& event);
|
||||||
void OnEndLabelEdit(wxTreeEvent& event);
|
void OnEndLabelEdit(wxTreeEvent& event);
|
||||||
void OnDeleteItem(wxTreeEvent& event);
|
void OnDeleteItem(wxTreeEvent& event);
|
||||||
void OnRMouseUp(wxMouseEvent& event);
|
void OnContextMenu(wxContextMenuEvent& event);
|
||||||
void OnGetInfo(wxTreeEvent& event);
|
void OnGetInfo(wxTreeEvent& event);
|
||||||
void OnTreeRMouseClick(wxTreeEvent& event);
|
void OnTreeRMouseClick(wxTreeEvent& event);
|
||||||
void OnItemRightClick(wxTreeEvent& event);
|
void OnItemRightClick(wxTreeEvent& event);
|
||||||
|
@@ -61,6 +61,7 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_ACTIVATED)
|
|||||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK)
|
DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK)
|
||||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK)
|
DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK)
|
||||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_END_DRAG)
|
DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_END_DRAG)
|
||||||
|
DEFINE_EVENT_TYPE(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK)
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Tree event
|
// Tree event
|
||||||
|
Reference in New Issue
Block a user