X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5888ef1e7dc9f70e074bbfe9eabed332b3db6870..abceee76ea4d642ccfd3cf91cc139a3fe2b471b7:/samples/treectrl/treetest.cpp diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 135b59b7ed..5d371764f4 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -34,12 +34,15 @@ #include "math.h" #ifdef __WXMSW__ - // comment out this line to test multiple selection even under MSW (where - // it looks ugly - but works) + // this is not supported at all under MSW + #define NO_VARIABLE_HEIGHT + #define NO_MULTIPLE_SELECTION -#endif -#define NO_VARIABLE_HEIGHT + // this is supported (so the next line may be uncommented) but not very + // well :-( + #undef NO_MULTIPLE_SELECTION +#endif #include "treetest.h" @@ -63,6 +66,8 @@ } BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_SIZE(MyFrame::OnSize) + EVT_MENU(TreeTest_Quit, MyFrame::OnQuit) EVT_MENU(TreeTest_About, MyFrame::OnAbout) EVT_MENU(TreeTest_Dump, MyFrame::OnDump) @@ -70,6 +75,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(TreeTest_DumpSelected, MyFrame::OnDumpSelected) EVT_MENU(TreeTest_Select, MyFrame::OnSelect) EVT_MENU(TreeTest_Unselect, MyFrame::OnUnselect) + EVT_MENU(TreeTest_ToggleSel, MyFrame::OnToggleSel) #endif // NO_MULTIPLE_SELECTION EVT_MENU(TreeTest_Rename, MyFrame::OnRename) EVT_MENU(TreeTest_Count, MyFrame::OnCount) @@ -132,7 +138,8 @@ bool MyApp::OnInit() // My frame constructor MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) - : wxFrame((wxFrame *)NULL, -1, title, wxPoint(x, y), wxSize(w, h)) + : wxFrame((wxFrame *)NULL, -1, title, wxPoint(x, y), wxSize(w, h)), + m_treeCtrl(NULL), m_textCtrl(NULL) { // This reduces flicker effects - even better would be to define // OnEraseBackground to do nothing. When the tree control's scrollbars are @@ -149,8 +156,11 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) file_menu->Append(TreeTest_About, "&About..."); file_menu->AppendSeparator(); - file_menu->Append(TreeTest_Quit, "E&xit"); + file_menu->Append(TreeTest_Quit, "E&xit\tAlt-X"); +#ifndef NO_MULTIPLE_SELECTION + tree_menu->Append(TreeTest_ToggleSel, "&Toggle selection mode"); +#endif // NO_MULTIPLE_SELECTION tree_menu->Append(TreeTest_Recreate, "&Recreate the tree"); tree_menu->Append(TreeTest_CollapseAndReset, "C&ollapse and reset"); tree_menu->AppendSeparator(); @@ -188,7 +198,7 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) item_menu->Append(TreeTest_DumpSelected, "Dump selected items\tAlt-D"); item_menu->Append(TreeTest_Select, "Select current item\tAlt-S"); item_menu->Append(TreeTest_Unselect, "Unselect everything\tAlt-U"); -#endif +#endif // NO_MULTIPLE_SELECTION wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append(file_menu, "&File"); @@ -200,9 +210,6 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS | -#ifndef NO_MULTIPLE_SELECTION - wxTR_MULTIPLE | -#endif #ifndef NO_VARIABLE_HEIGHT wxTR_HAS_VARIABLE_ROW_HEIGHT | #endif @@ -210,25 +217,10 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) m_treeCtrl->SetBackgroundColour(wxColour(204, 205, 79)); - wxTextCtrl *textCtrl = new wxTextCtrl(this, -1, "", + m_textCtrl = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxSUNKEN_BORDER); - wxLayoutConstraints *c = new wxLayoutConstraints; - c->top.SameAs(this, wxTop); - c->left.SameAs(this, wxLeft); - c->right.SameAs(this, wxRight); - c->height.PercentOf(this, wxHeight, 66); - m_treeCtrl->SetConstraints(c); - - c = new wxLayoutConstraints; - c->top.Below(m_treeCtrl); - c->left.SameAs(this, wxLeft); - c->right.SameAs(this, wxRight); - c->bottom.SameAs(this, wxBottom); - textCtrl->SetConstraints(c); - SetAutoLayout(TRUE); - // create a status bar with 3 panes CreateStatusBar(3); SetStatusText("", 0); @@ -239,7 +231,7 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) delete wxLog::SetActiveTarget(new wxLogStderr); #else // set our text control as the log target - wxLogTextCtrl *logWindow = new wxLogTextCtrl(textCtrl); + wxLogTextCtrl *logWindow = new wxLogTextCtrl(m_textCtrl); delete wxLog::SetActiveTarget(logWindow); #endif } @@ -249,6 +241,22 @@ MyFrame::~MyFrame() delete wxLog::SetActiveTarget(NULL); } +void MyFrame::OnSize(wxSizeEvent& event) +{ + if ( m_treeCtrl && m_textCtrl ) + { + Resize(GetClientSize()); + } + + event.Skip(); +} + +void MyFrame::Resize(const wxSize& size) +{ + m_treeCtrl->SetSize(0, 0, size.x, 2*size.y/3); + m_textCtrl->SetSize(0, 2*size.y/3, size.x, size.y/3); +} + void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(TRUE); @@ -325,6 +333,22 @@ void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event)) #ifndef NO_MULTIPLE_SELECTION +void MyFrame::OnToggleSel(wxCommandEvent& WXUNUSED(event)) +{ + long style = m_treeCtrl->GetWindowStyle(); + if ( style & wxTR_MULTIPLE ) + style &= ~wxTR_MULTIPLE; + else + style |= wxTR_MULTIPLE; + + delete m_treeCtrl; + + m_treeCtrl = new MyTreeCtrl(this, TreeTest_Ctrl, + wxDefaultPosition, wxDefaultSize, + style); + Resize(GetClientSize()); +} + void MyFrame::OnDumpSelected(wxCommandEvent& WXUNUSED(event)) { wxArrayTreeItemIds array; @@ -622,9 +646,10 @@ void MyTreeCtrl::DoToggleIcon(const wxTreeItemId& item) // avoid repetition #define TREE_EVENT_HANDLER(name) \ -void MyTreeCtrl::name(wxTreeEvent& WXUNUSED(event)) \ +void MyTreeCtrl::name(wxTreeEvent& event) \ { \ wxLogMessage(#name); \ + event.Skip(); \ } TREE_EVENT_HANDLER(OnBeginRDrag) @@ -636,6 +661,7 @@ TREE_EVENT_HANDLER(OnItemExpanding) TREE_EVENT_HANDLER(OnItemCollapsed) TREE_EVENT_HANDLER(OnSelChanged) TREE_EVENT_HANDLER(OnSelChanging) +TREE_EVENT_HANDLER(OnTreeKeyDown) #undef TREE_EVENT_HANDLER @@ -661,7 +687,7 @@ void MyTreeCtrl::OnEndDrag(wxTreeEvent& event) { wxTreeItemId itemSrc = m_draggedItem, itemDst = event.GetItem(); - m_draggedItem = 0; + m_draggedItem = (wxTreeItemId)0l; // where to copy the item? if ( itemDst.IsOk() && !ItemHasChildren(itemDst) ) @@ -688,7 +714,7 @@ void MyTreeCtrl::OnEndDrag(wxTreeEvent& event) // // Finally, we only copy one item here but we might copy the entire tree if // we were dragging a folder. - AppendItem(itemDst, text); + AppendItem(itemDst, text, TreeCtrlIcon_File); } void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent& event) @@ -732,11 +758,6 @@ void MyTreeCtrl::OnItemCollapsing(wxTreeEvent& event) } } -void MyTreeCtrl::OnTreeKeyDown(wxTreeEvent&WXUNUSED(event)) -{ - wxLogMessage("OnTreeKeyDown"); -} - void MyTreeCtrl::OnItemActivated(wxTreeEvent&WXUNUSED(event)) { // show some info about this item