- // Create the main frame window
- MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "wxTreeCtrl Test", 50, 50, 450, 340);
-
- // This reduces flicker effects - even better would be to define OnEraseBackground
- // to do nothing. When the tree control's scrollbars are show or hidden, the
- // frame is sent a background erase event.
- frame->SetBackgroundColour(wxColour(255, 255, 255));
-
- // Give it an icon
- frame->SetIcon(wxICON(mondrian));
-
- // Make an image list containing small icons
- m_imageListNormal = new wxImageList(16, 16, TRUE);
-
- m_imageListNormal->Add(wxICON(icon1));
- m_imageListNormal->Add(wxICON(icon2));
-
- // Make a menubar
- wxMenu *file_menu = new wxMenu;
-
- file_menu->Append(TREE_ABOUT, "&About");
- file_menu->Append(TREE_QUIT, "E&xit");
- wxMenuBar *menu_bar = new wxMenuBar;
- menu_bar->Append(file_menu, "&File");
- frame->SetMenuBar(menu_bar);
-
- // Make a panel with a message
- frame->m_treeCtrl = new MyTreeCtrl(frame, TREE_CTRL, wxPoint(0, 0), wxSize(400, 200),
- wxTR_HAS_BUTTONS|wxSUNKEN_BORDER);
- frame->m_logWindow = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxSize(400, 200),
- wxTE_MULTILINE|wxSUNKEN_BORDER);
-
- wxLayoutConstraints *c = new wxLayoutConstraints;
- c->top.SameAs (frame, wxTop);
- c->left.SameAs (frame, wxLeft);
- c->right.SameAs (frame, wxRight);
- c->height.PercentOf (frame, wxHeight, 66);
- frame->m_treeCtrl->SetConstraints(c);
-
- c = new wxLayoutConstraints;
- c->top.Below (frame->m_treeCtrl);
- c->left.SameAs (frame, wxLeft);
- c->right.SameAs (frame, wxRight);
- c->bottom.SameAs (frame, wxBottom);
- frame->m_logWindow->SetConstraints(c);
- frame->SetAutoLayout(TRUE);
-
- frame->m_treeCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
-
- wxTreeItemId rootId = frame->m_treeCtrl->AddRoot("Root", 0);
-
- char buf[20];
- int i;
- wxString str;
-
- for ( i = 0; i < 10; i++)
- {
- sprintf(buf, "Folder child %d", i);
- str = buf;
- wxTreeItemId id = frame->m_treeCtrl->AppendItem(rootId, str, 0);
- int j;
- for ( j = 0; j < 5; j++)
+ // Create the main frame window
+ MyFrame *frame = new MyFrame(wxT("wxTreeCtrl Test"), 50, 50, 450, 600);
+
+ // Show the frame
+ frame->Show(true);
+ SetTopWindow(frame);
+
+ return true;
+}
+
+
+// My frame constructor
+MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
+ : wxFrame((wxFrame *)NULL, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)),
+ m_treeCtrl(NULL)
+#if wxUSE_LOG
+ , m_textCtrl(NULL)
+#endif // wxUSE_LOG
+{
+ // This reduces flicker effects - even better would be to define
+ // OnEraseBackground to do nothing. When the tree control's scrollbars are
+ // show or hidden, the frame is sent a background erase event.
+ SetBackgroundColour(wxColour(255, 255, 255));
+
+ // Give it an icon
+ SetIcon(wxICON(sample));
+
+#if wxUSE_MENUS
+ // Make a menubar
+ wxMenu *file_menu = new wxMenu,
+ *style_menu = new wxMenu,
+ *tree_menu = new wxMenu,
+ *item_menu = new wxMenu;
+
+ file_menu->Append(TreeTest_About, wxT("&About..."));
+ file_menu->AppendSeparator();
+ file_menu->Append(TreeTest_Quit, wxT("E&xit\tAlt-X"));
+
+ style_menu->AppendCheckItem(TreeTest_TogButtons, wxT("Toggle &normal buttons"));
+ style_menu->AppendCheckItem(TreeTest_TogTwist, wxT("Toggle &twister buttons"));
+ style_menu->AppendCheckItem(TreeTest_ToggleButtons, wxT("Toggle image &buttons"));
+ style_menu->AppendSeparator();
+ style_menu->AppendCheckItem(TreeTest_TogLines, wxT("Toggle &connecting lines"));
+ style_menu->AppendCheckItem(TreeTest_TogRootLines, wxT("Toggle &lines at root"));
+ style_menu->AppendCheckItem(TreeTest_TogHideRoot, wxT("Toggle &hidden root"));
+ style_menu->AppendCheckItem(TreeTest_TogBorder, wxT("Toggle &item border"));
+ style_menu->AppendCheckItem(TreeTest_TogFullHighlight, wxT("Toggle &full row highlight"));
+ style_menu->AppendCheckItem(TreeTest_TogEdit, wxT("Toggle &edit mode"));
+#ifndef NO_MULTIPLE_SELECTION
+ style_menu->AppendCheckItem(TreeTest_ToggleSel, wxT("Toggle &selection mode"));
+#endif // NO_MULTIPLE_SELECTION
+ style_menu->AppendCheckItem(TreeTest_ToggleImages, wxT("Toggle show ima&ges"));
+ style_menu->Append(TreeTest_SetImageSize, wxT("Set image si&ze..."));
+ style_menu->AppendSeparator();
+ style_menu->Append(TreeTest_SetFgColour, wxT("Set &foreground colour..."));
+ style_menu->Append(TreeTest_SetBgColour, wxT("Set &background colour..."));
+ style_menu->AppendSeparator();
+ style_menu->Append(TreeTest_ResetStyle, wxT("&Reset to default\tF10"));
+
+ tree_menu->Append(TreeTest_Recreate, wxT("&Recreate the tree"));
+ tree_menu->Append(TreeTest_CollapseAndReset, wxT("C&ollapse and reset"));
+ tree_menu->AppendSeparator();
+ tree_menu->Append(TreeTest_AddItem, wxT("Append a &new item"));
+ tree_menu->Append(TreeTest_InsertItem, wxT("&Insert a new item"));
+ tree_menu->Append(TreeTest_Delete, wxT("&Delete this item"));
+ tree_menu->Append(TreeTest_DeleteChildren, wxT("Delete &children"));
+ tree_menu->Append(TreeTest_DeleteAll, wxT("Delete &all items"));
+ tree_menu->Append(TreeTest_SelectRoot, wxT("Select root item"));
+ tree_menu->AppendSeparator();
+ tree_menu->Append(TreeTest_Count, wxT("Count children of current item"));
+ tree_menu->Append(TreeTest_CountRec, wxT("Recursively count children of current item"));
+ tree_menu->AppendSeparator();
+ tree_menu->Append(TreeTest_Sort, wxT("Sort children of current item"));
+ 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->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"));
+ tree_menu->AppendSeparator();
+ tree_menu->Append(TreeTest_IncSpacing, wxT("Add 5 points to spacing\tCtrl-I"));
+ tree_menu->Append(TreeTest_DecSpacing, wxT("Reduce spacing by 5 points\tCtrl-R"));
+
+ item_menu->Append(TreeTest_Dump, wxT("&Dump item children"));
+ item_menu->Append(TreeTest_Rename, wxT("&Rename item..."));
+
+ item_menu->AppendSeparator();
+ item_menu->Append(TreeTest_SetBold, wxT("Make item &bold"));
+ item_menu->Append(TreeTest_ClearBold, wxT("Make item ¬ bold"));
+ item_menu->AppendSeparator();
+ item_menu->Append(TreeTest_ToggleIcon, wxT("Toggle the item's &icon"));
+
+#ifndef NO_MULTIPLE_SELECTION
+ item_menu->AppendSeparator();
+ item_menu->Append(TreeTest_DumpSelected, wxT("Dump selected items\tAlt-D"));
+ item_menu->Append(TreeTest_Select, wxT("Select current item\tAlt-S"));
+ item_menu->Append(TreeTest_Unselect, wxT("Unselect everything\tAlt-U"));
+#endif // NO_MULTIPLE_SELECTION
+
+ wxMenuBar *menu_bar = new wxMenuBar;
+ menu_bar->Append(file_menu, wxT("&File"));
+ menu_bar->Append(style_menu, wxT("&Style"));
+ menu_bar->Append(tree_menu, wxT("&Tree"));
+ menu_bar->Append(item_menu, wxT("&Item"));
+ SetMenuBar(menu_bar);
+#endif // wxUSE_MENUS
+
+ m_panel = new wxPanel(this);
+
+#if wxUSE_LOG
+ // create the controls
+ m_textCtrl = new wxTextCtrl(m_panel, wxID_ANY, wxT(""),
+ wxDefaultPosition, wxDefaultSize,
+ wxTE_MULTILINE | wxSUNKEN_BORDER);
+#endif // wxUSE_LOG
+
+ CreateTreeWithDefStyle();
+
+ menu_bar->Check(TreeTest_ToggleImages, true);
+
+#if wxUSE_STATUSBAR
+ // create a status bar
+ CreateStatusBar(2);
+#endif // wxUSE_STATUSBAR
+
+#if wxUSE_LOG
+#ifdef __WXMOTIF__
+ // For some reason, we get a memcpy crash in wxLogStream::DoLogStream
+ // on gcc/wxMotif, if we use wxLogTextCtl. Maybe it's just gcc?
+ delete wxLog::SetActiveTarget(new wxLogStderr);
+#else
+ // set our text control as the log target
+ wxLogTextCtrl *logWindow = new wxLogTextCtrl(m_textCtrl);
+ delete wxLog::SetActiveTarget(logWindow);
+#endif
+#endif // wxUSE_LOG
+}
+
+MyFrame::~MyFrame()
+{
+#if wxUSE_LOG
+ delete wxLog::SetActiveTarget(NULL);
+#endif // wxUSE_LOG
+}
+
+void MyFrame::CreateTreeWithDefStyle()
+{
+ long style = wxTR_DEFAULT_STYLE |
+#ifndef NO_VARIABLE_HEIGHT
+ wxTR_HAS_VARIABLE_ROW_HEIGHT |
+#endif
+ wxTR_EDIT_LABELS;
+
+ CreateTree(style | wxSUNKEN_BORDER);
+
+ // as we don't know what wxTR_DEFAULT_STYLE could contain, test for
+ // everything
+ wxMenuBar *mbar = GetMenuBar();
+ mbar->Check(TreeTest_TogButtons, (style & wxTR_HAS_BUTTONS) != 0);
+ mbar->Check(TreeTest_TogButtons, (style & wxTR_TWIST_BUTTONS) != 0);
+ mbar->Check(TreeTest_TogLines, (style & wxTR_NO_LINES) == 0);
+ mbar->Check(TreeTest_TogRootLines, (style & wxTR_LINES_AT_ROOT) != 0);
+ mbar->Check(TreeTest_TogHideRoot, (style & wxTR_HIDE_ROOT) != 0);
+ mbar->Check(TreeTest_TogEdit, (style & wxTR_EDIT_LABELS) != 0);
+ mbar->Check(TreeTest_TogBorder, (style & wxTR_ROW_LINES) != 0);
+ mbar->Check(TreeTest_TogFullHighlight, (style & wxTR_FULL_ROW_HIGHLIGHT) != 0);
+}
+
+void MyFrame::CreateTree(long style)
+{
+ m_treeCtrl = new MyTreeCtrl(m_panel, TreeTest_Ctrl,
+ wxDefaultPosition, wxDefaultSize,
+ style);
+ Resize();
+}
+
+void MyFrame::TogStyle(int id, long flag)
+{
+ long style = m_treeCtrl->GetWindowStyle() ^ flag;
+
+ // most treectrl styles can't be changed on the fly using the native
+ // control and the tree must be recreated
+#ifndef __WXMSW__
+ m_treeCtrl->SetWindowStyle(style);
+#else // MSW
+ delete m_treeCtrl;
+ CreateTree(style);
+#endif // !MSW/MSW
+
+ GetMenuBar()->Check(id, (style & flag) != 0);
+}
+
+void MyFrame::OnIdle(wxIdleEvent& event)
+{
+#if wxUSE_STATUSBAR
+ if ( m_treeCtrl )