#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"
}
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)
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)
// 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
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();
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");
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
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);
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
}
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);
#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;
// 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)
TREE_EVENT_HANDLER(OnItemCollapsed)
TREE_EVENT_HANDLER(OnSelChanged)
TREE_EVENT_HANDLER(OnSelChanging)
+TREE_EVENT_HANDLER(OnTreeKeyDown)
#undef TREE_EVENT_HANDLER
{
wxTreeItemId itemSrc = m_draggedItem,
itemDst = event.GetItem();
- m_draggedItem = 0;
+ m_draggedItem = (wxTreeItemId)0l;
// where to copy the item?
if ( itemDst.IsOk() && !ItemHasChildren(itemDst) )
//
// 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)
}
}
-void MyTreeCtrl::OnTreeKeyDown(wxTreeEvent&WXUNUSED(event))
-{
- wxLogMessage("OnTreeKeyDown");
-}
-
void MyTreeCtrl::OnItemActivated(wxTreeEvent&WXUNUSED(event))
{
// show some info about this item