From 7cc8c9884d8cc35cce8394a23e2b7dd2c069e246 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 23 Feb 2000 00:30:59 +0000 Subject: [PATCH] multiple/single sel mode can now be toggled from menu git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6227 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/treectrl/treetest.cpp | 77 +++++++++++++++++++++++------------ samples/treectrl/treetest.h | 7 ++++ 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 37c93a6e67..5d371764f4 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -33,13 +33,15 @@ #include "math.h" -//#define NO_VARIABLE_HEIGHT -//#define NO_MULTIPLE_SELECTION - #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 + + // this is supported (so the next line may be uncommented) but not very + // well :-( + #undef NO_MULTIPLE_SELECTION #endif #include "treetest.h" @@ -64,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) @@ -71,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) @@ -133,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 @@ -152,6 +158,9 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) file_menu->AppendSeparator(); 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(); @@ -189,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"); @@ -201,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 @@ -211,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); @@ -240,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 } @@ -250,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); @@ -326,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; diff --git a/samples/treectrl/treetest.h b/samples/treectrl/treetest.h index 7ae426cbf4..18c8b9a65d 100644 --- a/samples/treectrl/treetest.h +++ b/samples/treectrl/treetest.h @@ -120,6 +120,7 @@ public: void OnDumpSelected(wxCommandEvent& event); void OnSelect(wxCommandEvent& event); void OnUnselect(wxCommandEvent& event); + void OnToggleSel(wxCommandEvent& event); #endif // NO_MULTIPLE_SELECTION void OnDelete(wxCommandEvent& event); void OnDeleteChildren(wxCommandEvent& event); @@ -150,10 +151,15 @@ public: void OnToggleIcon(wxCommandEvent& event); + void OnSize(wxSizeEvent& event); + private: void DoSort(bool reverse = FALSE); + void Resize(const wxSize& size); + MyTreeCtrl *m_treeCtrl; + wxTextCtrl *m_textCtrl; void DoSetBold(bool bold = TRUE); @@ -178,6 +184,7 @@ enum TreeTest_DeleteChildren, TreeTest_DeleteAll, TreeTest_Recreate, + TreeTest_ToggleSel, TreeTest_CollapseAndReset, TreeTest_EnsureVisible, TreeTest_AddItem, -- 2.45.2