]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/treectrl/treectrl.cpp
added missing methods/removed duplicated base methods
[wxWidgets.git] / samples / treectrl / treectrl.cpp
index e04b74f31442af5cf4c64b19aff9d451bd2fc63b..749bc0d3c9251a9daa3f8e62275b9e95607a533d 100644 (file)
@@ -117,6 +117,9 @@ BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl)
     EVT_TREE_ITEM_EXPANDING(TreeTest_Ctrl, MyTreeCtrl::OnItemExpanding)
     EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsed)
     EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsing)
     EVT_TREE_ITEM_EXPANDING(TreeTest_Ctrl, MyTreeCtrl::OnItemExpanding)
     EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsed)
     EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsing)
+    EVT_TREE_ITEM_RIGHT_CLICK(TreeTest_Ctrl, MyTreeCtrl::OnItemRightClick)
+
+    EVT_RIGHT_UP(MyTreeCtrl::OnRMouseUp)
     EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, MyTreeCtrl::OnSelChanged)
     EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, MyTreeCtrl::OnSelChanging)
     EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown)
     EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, MyTreeCtrl::OnSelChanged)
     EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, MyTreeCtrl::OnSelChanging)
     EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown)
@@ -152,6 +155,7 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
     // Give it an icon
     SetIcon(wxICON(mondrian));
 
     // Give it an icon
     SetIcon(wxICON(mondrian));
 
+#if wxUSE_MENUS
     // Make a menubar
     wxMenu *file_menu = new wxMenu,
            *tree_menu = new wxMenu,
     // Make a menubar
     wxMenu *file_menu = new wxMenu,
            *tree_menu = new wxMenu,
@@ -212,17 +216,18 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
     SetMenuBar(menu_bar);
 
     menu_bar->Check(TreeTest_ToggleImages, TRUE);
     SetMenuBar(menu_bar);
 
     menu_bar->Check(TreeTest_ToggleImages, TRUE);
+#endif // wxUSE_MENUS
 
     m_treeCtrl = new MyTreeCtrl(this, TreeTest_Ctrl,
                                 wxDefaultPosition, wxDefaultSize,
 
     m_treeCtrl = new MyTreeCtrl(this, TreeTest_Ctrl,
                                 wxDefaultPosition, wxDefaultSize,
-                                wxTR_HAS_BUTTONS | // wxTR_NO_LINES |
+                                wxTR_MAC_BUTTONS | wxTR_NO_LINES |
                                 wxTR_EDIT_LABELS |
 #ifndef NO_VARIABLE_HEIGHT
                                 wxTR_HAS_VARIABLE_ROW_HEIGHT |
 #endif
                                 wxSUNKEN_BORDER);
 
                                 wxTR_EDIT_LABELS |
 #ifndef NO_VARIABLE_HEIGHT
                                 wxTR_HAS_VARIABLE_ROW_HEIGHT |
 #endif
                                 wxSUNKEN_BORDER);
 
-    m_treeCtrl->SetBackgroundColour(wxColour(204, 205, 79));
+//    m_treeCtrl->SetBackgroundColour( *wxLIGHT_GREY );
 
     m_textCtrl = new wxTextCtrl(this, -1, "",
                                 wxDefaultPosition, wxDefaultSize,
 
     m_textCtrl = new wxTextCtrl(this, -1, "",
                                 wxDefaultPosition, wxDefaultSize,
@@ -841,6 +846,38 @@ void MyTreeCtrl::OnItemActivated(wxTreeEvent& event)
     wxLogMessage("OnItemActivated");
 }
 
     wxLogMessage("OnItemActivated");
 }
 
+void MyTreeCtrl::OnItemRightClick(wxTreeEvent& event)
+{
+    ShowMenu(event.GetItem(), event.GetPoint());
+}
+
+void MyTreeCtrl::OnRMouseUp(wxMouseEvent& event)
+{
+    wxPoint pt = event.GetPosition();
+    ShowMenu(HitTest(pt), pt);
+}
+
+void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt)
+{
+    wxString title;
+    if ( id.IsOk() )
+    {
+        title << _T("Menu for ") << GetItemText(id);
+    }
+    else
+    {
+        title = _T("Menu for no particular item");
+    }
+
+#if wxUSE_MENUS
+    wxMenu menu(title);
+    menu.Append(TreeTest_About, _T("&About..."));
+    menu.Append(TreeTest_Dump, _T("&Dump"));
+
+    PopupMenu(&menu, pt);
+#endif // wxUSE_MENUS
+}
+
 void MyTreeCtrl::OnRMouseDClick(wxMouseEvent& event)
 {
     wxTreeItemId id = HitTest(event.GetPosition());
 void MyTreeCtrl::OnRMouseDClick(wxMouseEvent& event)
 {
     wxTreeItemId id = HitTest(event.GetPosition());