#include "../sample.xpm"
#endif
+static const int NUM_CHILDREN_PER_LEVEL = 5;
+static const int NUM_LEVELS = 2;
+
// verify that the item is ok and insult the user if it is not
#define CHECK_ITEM( item ) if ( !item.IsOk() ) { \
wxMessageBox(wxT("Please select some item first!"), \
MENU_LINK(SetImageSize)
MENU_LINK(CollapseAndReset)
MENU_LINK(EnsureVisible)
+ MENU_LINK(SetFocus)
MENU_LINK(AddItem)
MENU_LINK(InsertItem)
MENU_LINK(IncIndent)
tree_menu->Append(TreeTest_SortRev, wxT("Sort in reversed order"));
tree_menu->AppendSeparator();
tree_menu->Append(TreeTest_EnsureVisible, wxT("Make the last item &visible"));
+ tree_menu->Append(TreeTest_SetFocus, wxT("Set &focus to the tree"));
tree_menu->AppendSeparator();
tree_menu->Append(TreeTest_IncIndent, wxT("Add 5 points to indentation\tAlt-I"));
tree_menu->Append(TreeTest_DecIndent, wxT("Reduce indentation by 5 points\tAlt-R"));
void MyFrame::OnRecreate(wxCommandEvent& event)
{
OnDeleteAll(event);
- m_treeCtrl->AddTestItemsToTree(5, 2);
+ m_treeCtrl->AddTestItemsToTree(NUM_CHILDREN_PER_LEVEL, NUM_LEVELS);
}
void MyFrame::OnSetImageSize(wxCommandEvent& WXUNUSED(event))
m_treeCtrl->DoEnsureVisible();
}
+void MyFrame::OnSetFocus(wxCommandEvent& WXUNUSED(event))
+{
+ m_treeCtrl->SetFocus();
+}
+
void MyFrame::OnInsertItem(wxCommandEvent& WXUNUSED(event))
{
int image = wxGetApp().ShowImages() ? MyTreeCtrl::TreeCtrlIcon_File : -1;
CreateStateImageList();
// Add some items to the tree
- AddTestItemsToTree(5, 2);
+ AddTestItemsToTree(NUM_CHILDREN_PER_LEVEL, NUM_LEVELS);
}
void MyTreeCtrl::CreateImageList(int size)
SetItemTextColour(id, *wxBLUE);
id = GetNextChild(rootId, cookie);
- id = GetNextChild(rootId, cookie);
- SetItemTextColour(id, *wxRED);
- SetItemBackgroundColour(id, *wxLIGHT_GREY);
+ if ( id )
+ id = GetNextChild(rootId, cookie);
+ if ( id )
+ {
+ SetItemTextColour(id, *wxRED);
+ SetItemBackgroundColour(id, *wxLIGHT_GREY);
+ }
}
void MyTreeCtrl::GetItemsRecursively(const wxTreeItemId& idParent,
wxPoint pt = event.GetPosition();
wxLogMessage(wxT("OnContextMenu at screen coords (%i, %i)"), pt.x, pt.y);
+
+ event.Skip();
}
void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt)