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
This commit is contained in:
@@ -33,13 +33,15 @@
|
|||||||
|
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
|
||||||
//#define NO_VARIABLE_HEIGHT
|
|
||||||
//#define NO_MULTIPLE_SELECTION
|
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
// comment out this line to test multiple selection even under MSW (where
|
// this is not supported at all under MSW
|
||||||
// it looks ugly - but works)
|
#define NO_VARIABLE_HEIGHT
|
||||||
|
|
||||||
#define NO_MULTIPLE_SELECTION
|
#define NO_MULTIPLE_SELECTION
|
||||||
|
|
||||||
|
// this is supported (so the next line may be uncommented) but not very
|
||||||
|
// well :-(
|
||||||
|
#undef NO_MULTIPLE_SELECTION
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "treetest.h"
|
#include "treetest.h"
|
||||||
@@ -64,6 +66,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
|
EVT_SIZE(MyFrame::OnSize)
|
||||||
|
|
||||||
EVT_MENU(TreeTest_Quit, MyFrame::OnQuit)
|
EVT_MENU(TreeTest_Quit, MyFrame::OnQuit)
|
||||||
EVT_MENU(TreeTest_About, MyFrame::OnAbout)
|
EVT_MENU(TreeTest_About, MyFrame::OnAbout)
|
||||||
EVT_MENU(TreeTest_Dump, MyFrame::OnDump)
|
EVT_MENU(TreeTest_Dump, MyFrame::OnDump)
|
||||||
@@ -71,6 +75,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_MENU(TreeTest_DumpSelected, MyFrame::OnDumpSelected)
|
EVT_MENU(TreeTest_DumpSelected, MyFrame::OnDumpSelected)
|
||||||
EVT_MENU(TreeTest_Select, MyFrame::OnSelect)
|
EVT_MENU(TreeTest_Select, MyFrame::OnSelect)
|
||||||
EVT_MENU(TreeTest_Unselect, MyFrame::OnUnselect)
|
EVT_MENU(TreeTest_Unselect, MyFrame::OnUnselect)
|
||||||
|
EVT_MENU(TreeTest_ToggleSel, MyFrame::OnToggleSel)
|
||||||
#endif // NO_MULTIPLE_SELECTION
|
#endif // NO_MULTIPLE_SELECTION
|
||||||
EVT_MENU(TreeTest_Rename, MyFrame::OnRename)
|
EVT_MENU(TreeTest_Rename, MyFrame::OnRename)
|
||||||
EVT_MENU(TreeTest_Count, MyFrame::OnCount)
|
EVT_MENU(TreeTest_Count, MyFrame::OnCount)
|
||||||
@@ -133,7 +138,8 @@ bool MyApp::OnInit()
|
|||||||
|
|
||||||
// My frame constructor
|
// My frame constructor
|
||||||
MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
|
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
|
// This reduces flicker effects - even better would be to define
|
||||||
// OnEraseBackground to do nothing. When the tree control's scrollbars are
|
// 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->AppendSeparator();
|
||||||
file_menu->Append(TreeTest_Quit, "E&xit\tAlt-X");
|
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_Recreate, "&Recreate the tree");
|
||||||
tree_menu->Append(TreeTest_CollapseAndReset, "C&ollapse and reset");
|
tree_menu->Append(TreeTest_CollapseAndReset, "C&ollapse and reset");
|
||||||
tree_menu->AppendSeparator();
|
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_DumpSelected, "Dump selected items\tAlt-D");
|
||||||
item_menu->Append(TreeTest_Select, "Select current item\tAlt-S");
|
item_menu->Append(TreeTest_Select, "Select current item\tAlt-S");
|
||||||
item_menu->Append(TreeTest_Unselect, "Unselect everything\tAlt-U");
|
item_menu->Append(TreeTest_Unselect, "Unselect everything\tAlt-U");
|
||||||
#endif
|
#endif // NO_MULTIPLE_SELECTION
|
||||||
|
|
||||||
wxMenuBar *menu_bar = new wxMenuBar;
|
wxMenuBar *menu_bar = new wxMenuBar;
|
||||||
menu_bar->Append(file_menu, "&File");
|
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,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
wxTR_HAS_BUTTONS |
|
wxTR_HAS_BUTTONS |
|
||||||
wxTR_EDIT_LABELS |
|
wxTR_EDIT_LABELS |
|
||||||
#ifndef NO_MULTIPLE_SELECTION
|
|
||||||
wxTR_MULTIPLE |
|
|
||||||
#endif
|
|
||||||
#ifndef NO_VARIABLE_HEIGHT
|
#ifndef NO_VARIABLE_HEIGHT
|
||||||
wxTR_HAS_VARIABLE_ROW_HEIGHT |
|
wxTR_HAS_VARIABLE_ROW_HEIGHT |
|
||||||
#endif
|
#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));
|
m_treeCtrl->SetBackgroundColour(wxColour(204, 205, 79));
|
||||||
|
|
||||||
wxTextCtrl *textCtrl = new wxTextCtrl(this, -1, "",
|
m_textCtrl = new wxTextCtrl(this, -1, "",
|
||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
wxTE_MULTILINE | wxSUNKEN_BORDER);
|
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
|
// create a status bar with 3 panes
|
||||||
CreateStatusBar(3);
|
CreateStatusBar(3);
|
||||||
SetStatusText("", 0);
|
SetStatusText("", 0);
|
||||||
@@ -240,7 +231,7 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
|
|||||||
delete wxLog::SetActiveTarget(new wxLogStderr);
|
delete wxLog::SetActiveTarget(new wxLogStderr);
|
||||||
#else
|
#else
|
||||||
// set our text control as the log target
|
// set our text control as the log target
|
||||||
wxLogTextCtrl *logWindow = new wxLogTextCtrl(textCtrl);
|
wxLogTextCtrl *logWindow = new wxLogTextCtrl(m_textCtrl);
|
||||||
delete wxLog::SetActiveTarget(logWindow);
|
delete wxLog::SetActiveTarget(logWindow);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -250,6 +241,22 @@ MyFrame::~MyFrame()
|
|||||||
delete wxLog::SetActiveTarget(NULL);
|
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))
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
Close(TRUE);
|
Close(TRUE);
|
||||||
@@ -326,6 +333,22 @@ void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
#ifndef NO_MULTIPLE_SELECTION
|
#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))
|
void MyFrame::OnDumpSelected(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxArrayTreeItemIds array;
|
wxArrayTreeItemIds array;
|
||||||
|
@@ -120,6 +120,7 @@ public:
|
|||||||
void OnDumpSelected(wxCommandEvent& event);
|
void OnDumpSelected(wxCommandEvent& event);
|
||||||
void OnSelect(wxCommandEvent& event);
|
void OnSelect(wxCommandEvent& event);
|
||||||
void OnUnselect(wxCommandEvent& event);
|
void OnUnselect(wxCommandEvent& event);
|
||||||
|
void OnToggleSel(wxCommandEvent& event);
|
||||||
#endif // NO_MULTIPLE_SELECTION
|
#endif // NO_MULTIPLE_SELECTION
|
||||||
void OnDelete(wxCommandEvent& event);
|
void OnDelete(wxCommandEvent& event);
|
||||||
void OnDeleteChildren(wxCommandEvent& event);
|
void OnDeleteChildren(wxCommandEvent& event);
|
||||||
@@ -150,10 +151,15 @@ public:
|
|||||||
|
|
||||||
void OnToggleIcon(wxCommandEvent& event);
|
void OnToggleIcon(wxCommandEvent& event);
|
||||||
|
|
||||||
|
void OnSize(wxSizeEvent& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DoSort(bool reverse = FALSE);
|
void DoSort(bool reverse = FALSE);
|
||||||
|
|
||||||
|
void Resize(const wxSize& size);
|
||||||
|
|
||||||
MyTreeCtrl *m_treeCtrl;
|
MyTreeCtrl *m_treeCtrl;
|
||||||
|
wxTextCtrl *m_textCtrl;
|
||||||
|
|
||||||
void DoSetBold(bool bold = TRUE);
|
void DoSetBold(bool bold = TRUE);
|
||||||
|
|
||||||
@@ -178,6 +184,7 @@ enum
|
|||||||
TreeTest_DeleteChildren,
|
TreeTest_DeleteChildren,
|
||||||
TreeTest_DeleteAll,
|
TreeTest_DeleteAll,
|
||||||
TreeTest_Recreate,
|
TreeTest_Recreate,
|
||||||
|
TreeTest_ToggleSel,
|
||||||
TreeTest_CollapseAndReset,
|
TreeTest_CollapseAndReset,
|
||||||
TreeTest_EnsureVisible,
|
TreeTest_EnsureVisible,
|
||||||
TreeTest_AddItem,
|
TreeTest_AddItem,
|
||||||
|
Reference in New Issue
Block a user