1998-05-22 19:57:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2002-03-12 12:22:02 +00:00
|
|
|
// Name: treetest.cpp
|
1998-05-22 19:57:05 +00:00
|
|
|
// Purpose: wxTreeCtrl sample
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
2003-03-17 11:55:54 +00:00
|
|
|
// Copyright: (c) Julian Smart
|
1998-10-24 23:53:20 +00:00
|
|
|
// Licence: wxWindows license
|
1998-05-22 19:57:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
2006-07-25 06:43:18 +00:00
|
|
|
#pragma hdrstop
|
1998-05-22 19:57:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
2006-07-25 06:43:18 +00:00
|
|
|
#include "wx/wx.h"
|
|
|
|
#include "wx/log.h"
|
1998-05-22 19:57:05 +00:00
|
|
|
#endif
|
|
|
|
|
2002-03-16 13:49:40 +00:00
|
|
|
#include "wx/colordlg.h"
|
2004-02-29 15:21:11 +00:00
|
|
|
#include "wx/numdlg.h"
|
1998-10-24 23:53:20 +00:00
|
|
|
|
1999-06-13 15:24:01 +00:00
|
|
|
#include "wx/image.h"
|
1998-10-24 23:53:20 +00:00
|
|
|
#include "wx/imaglist.h"
|
1998-05-22 19:57:05 +00:00
|
|
|
#include "wx/treectrl.h"
|
2004-12-14 20:52:13 +00:00
|
|
|
#include "wx/math.h"
|
1999-05-03 23:11:53 +00:00
|
|
|
|
2000-03-03 10:31:34 +00:00
|
|
|
#ifdef __WIN32__
|
|
|
|
// this is not supported by native control
|
2000-02-23 00:30:59 +00:00
|
|
|
#define NO_VARIABLE_HEIGHT
|
1999-09-29 22:47:56 +00:00
|
|
|
#endif
|
1999-06-13 15:24:01 +00:00
|
|
|
|
2002-03-12 12:22:02 +00:00
|
|
|
#include "treetest.h"
|
1999-07-30 22:45:55 +00:00
|
|
|
|
2002-06-14 10:05:01 +00:00
|
|
|
#include "icon1.xpm"
|
|
|
|
#include "icon2.xpm"
|
|
|
|
#include "icon3.xpm"
|
|
|
|
#include "icon4.xpm"
|
|
|
|
#include "icon5.xpm"
|
2003-12-11 11:25:46 +00:00
|
|
|
|
2006-07-25 06:43:18 +00:00
|
|
|
#ifndef __WXMSW__
|
|
|
|
#include "../sample.xpm"
|
2003-12-11 11:25:46 +00:00
|
|
|
#endif
|
2002-06-14 10:05:01 +00:00
|
|
|
|
1998-12-18 15:37:19 +00:00
|
|
|
// verify that the item is ok and insult the user if it is not
|
2001-09-21 20:21:44 +00:00
|
|
|
#define CHECK_ITEM( item ) if ( !item.IsOk() ) { \
|
|
|
|
wxMessageBox(wxT("Please select some item first!"), \
|
|
|
|
wxT("Tree sample error"), \
|
|
|
|
wxOK | wxICON_EXCLAMATION, \
|
|
|
|
this); \
|
|
|
|
return; \
|
1999-04-12 11:48:06 +00:00
|
|
|
}
|
|
|
|
|
2002-02-20 17:41:39 +00:00
|
|
|
#define MENU_LINK(name) EVT_MENU(TreeTest_##name, MyFrame::On##name)
|
|
|
|
|
1998-05-22 19:57:05 +00:00
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2003-09-21 19:40:35 +00:00
|
|
|
EVT_IDLE(MyFrame::OnIdle)
|
2000-02-23 00:30:59 +00:00
|
|
|
EVT_SIZE(MyFrame::OnSize)
|
|
|
|
|
2001-08-18 13:09:26 +00:00
|
|
|
MENU_LINK(Quit)
|
|
|
|
MENU_LINK(About)
|
2002-03-16 15:10:43 +00:00
|
|
|
|
2001-08-18 13:09:26 +00:00
|
|
|
MENU_LINK(TogButtons)
|
|
|
|
MENU_LINK(TogTwist)
|
|
|
|
MENU_LINK(TogLines)
|
|
|
|
MENU_LINK(TogEdit)
|
|
|
|
MENU_LINK(TogHideRoot)
|
|
|
|
MENU_LINK(TogRootLines)
|
|
|
|
MENU_LINK(TogBorder)
|
2001-12-17 00:30:43 +00:00
|
|
|
MENU_LINK(TogFullHighlight)
|
2002-02-20 17:41:39 +00:00
|
|
|
MENU_LINK(SetFgColour)
|
|
|
|
MENU_LINK(SetBgColour)
|
2002-03-16 15:10:43 +00:00
|
|
|
MENU_LINK(ResetStyle)
|
|
|
|
|
2001-08-18 13:09:26 +00:00
|
|
|
MENU_LINK(Dump)
|
1999-07-30 22:45:55 +00:00
|
|
|
#ifndef NO_MULTIPLE_SELECTION
|
2001-08-18 13:09:26 +00:00
|
|
|
MENU_LINK(DumpSelected)
|
|
|
|
MENU_LINK(Select)
|
|
|
|
MENU_LINK(Unselect)
|
|
|
|
MENU_LINK(ToggleSel)
|
1999-07-30 22:45:55 +00:00
|
|
|
#endif // NO_MULTIPLE_SELECTION
|
2001-08-18 13:09:26 +00:00
|
|
|
MENU_LINK(Rename)
|
|
|
|
MENU_LINK(Count)
|
|
|
|
MENU_LINK(CountRec)
|
|
|
|
MENU_LINK(Sort)
|
|
|
|
MENU_LINK(SortRev)
|
|
|
|
MENU_LINK(SetBold)
|
|
|
|
MENU_LINK(ClearBold)
|
|
|
|
MENU_LINK(Delete)
|
|
|
|
MENU_LINK(DeleteChildren)
|
|
|
|
MENU_LINK(DeleteAll)
|
|
|
|
MENU_LINK(Recreate)
|
|
|
|
MENU_LINK(ToggleImages)
|
|
|
|
MENU_LINK(ToggleButtons)
|
|
|
|
MENU_LINK(SetImageSize)
|
|
|
|
MENU_LINK(CollapseAndReset)
|
|
|
|
MENU_LINK(EnsureVisible)
|
|
|
|
MENU_LINK(AddItem)
|
|
|
|
MENU_LINK(InsertItem)
|
|
|
|
MENU_LINK(IncIndent)
|
|
|
|
MENU_LINK(DecIndent)
|
|
|
|
MENU_LINK(IncSpacing)
|
|
|
|
MENU_LINK(DecSpacing)
|
|
|
|
MENU_LINK(ToggleIcon)
|
2004-02-12 16:35:36 +00:00
|
|
|
MENU_LINK(SelectRoot)
|
2001-08-18 13:09:26 +00:00
|
|
|
#undef MENU_LINK
|
|
|
|
|
1998-05-22 19:57:05 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2000-08-04 13:59:45 +00:00
|
|
|
#if USE_GENERIC_TREECTRL
|
|
|
|
BEGIN_EVENT_TABLE(MyTreeCtrl, wxGenericTreeCtrl)
|
|
|
|
#else
|
1998-05-22 19:57:05 +00:00
|
|
|
BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl)
|
2000-08-04 13:59:45 +00:00
|
|
|
#endif
|
1999-04-12 11:48:06 +00:00
|
|
|
EVT_TREE_BEGIN_DRAG(TreeTest_Ctrl, MyTreeCtrl::OnBeginDrag)
|
|
|
|
EVT_TREE_BEGIN_RDRAG(TreeTest_Ctrl, MyTreeCtrl::OnBeginRDrag)
|
2000-02-15 23:57:33 +00:00
|
|
|
EVT_TREE_END_DRAG(TreeTest_Ctrl, MyTreeCtrl::OnEndDrag)
|
1999-04-12 11:48:06 +00:00
|
|
|
EVT_TREE_BEGIN_LABEL_EDIT(TreeTest_Ctrl, MyTreeCtrl::OnBeginLabelEdit)
|
|
|
|
EVT_TREE_END_LABEL_EDIT(TreeTest_Ctrl, MyTreeCtrl::OnEndLabelEdit)
|
|
|
|
EVT_TREE_DELETE_ITEM(TreeTest_Ctrl, MyTreeCtrl::OnDeleteItem)
|
1999-09-29 22:47:56 +00:00
|
|
|
#if 0 // there are so many of those that logging them causes flicker
|
1999-04-12 11:48:06 +00:00
|
|
|
EVT_TREE_GET_INFO(TreeTest_Ctrl, MyTreeCtrl::OnGetInfo)
|
1999-09-29 22:47:56 +00:00
|
|
|
#endif
|
1999-04-12 11:48:06 +00:00
|
|
|
EVT_TREE_SET_INFO(TreeTest_Ctrl, MyTreeCtrl::OnSetInfo)
|
|
|
|
EVT_TREE_ITEM_EXPANDED(TreeTest_Ctrl, MyTreeCtrl::OnItemExpanded)
|
|
|
|
EVT_TREE_ITEM_EXPANDING(TreeTest_Ctrl, MyTreeCtrl::OnItemExpanding)
|
|
|
|
EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsed)
|
|
|
|
EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsing)
|
2001-05-27 02:16:09 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, MyTreeCtrl::OnSelChanged)
|
|
|
|
EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, MyTreeCtrl::OnSelChanging)
|
|
|
|
EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown)
|
|
|
|
EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl, MyTreeCtrl::OnItemActivated)
|
2005-04-05 23:03:32 +00:00
|
|
|
|
2005-04-06 22:32:24 +00:00
|
|
|
// so many differents ways to handle right mouse button clicks...
|
|
|
|
EVT_CONTEXT_MENU(MyTreeCtrl::OnContextMenu)
|
2005-05-21 03:03:40 +00:00
|
|
|
// EVT_TREE_ITEM_MENU is the preferred event for creating context menus
|
|
|
|
// on a tree control, because it includes the point of the click or item,
|
|
|
|
// meaning that no additional placement calculations are required.
|
2005-04-06 22:32:24 +00:00
|
|
|
EVT_TREE_ITEM_MENU(TreeTest_Ctrl, MyTreeCtrl::OnItemMenu)
|
|
|
|
EVT_TREE_ITEM_RIGHT_CLICK(TreeTest_Ctrl, MyTreeCtrl::OnItemRClick)
|
|
|
|
|
2005-04-05 23:03:32 +00:00
|
|
|
EVT_RIGHT_DOWN(MyTreeCtrl::OnRMouseDown)
|
|
|
|
EVT_RIGHT_UP(MyTreeCtrl::OnRMouseUp)
|
1999-04-12 11:48:06 +00:00
|
|
|
EVT_RIGHT_DCLICK(MyTreeCtrl::OnRMouseDClick)
|
1998-05-22 19:57:05 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
1998-09-29 20:02:53 +00:00
|
|
|
bool MyApp::OnInit()
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
// Create the main frame window
|
2001-09-21 20:21:44 +00:00
|
|
|
MyFrame *frame = new MyFrame(wxT("wxTreeCtrl Test"), 50, 50, 450, 600);
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
// Show the frame
|
2004-05-20 17:23:15 +00:00
|
|
|
frame->Show(true);
|
1999-04-12 11:48:06 +00:00
|
|
|
SetTopWindow(frame);
|
1998-05-22 19:57:05 +00:00
|
|
|
|
2004-05-20 17:23:15 +00:00
|
|
|
return true;
|
1998-10-24 23:53:20 +00:00
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
|
|
|
|
|
1998-10-24 23:53:20 +00:00
|
|
|
// My frame constructor
|
|
|
|
MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
|
2004-05-20 17:23:15 +00:00
|
|
|
: wxFrame((wxFrame *)NULL, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)),
|
2004-07-21 10:29:21 +00:00
|
|
|
m_treeCtrl(NULL)
|
|
|
|
#if wxUSE_LOG
|
|
|
|
, m_textCtrl(NULL)
|
|
|
|
#endif // wxUSE_LOG
|
1998-10-24 23:53:20 +00:00
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
// 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
|
2006-07-25 06:43:18 +00:00
|
|
|
SetIcon(wxICON(sample));
|
1999-04-12 11:48:06 +00:00
|
|
|
|
2001-07-04 16:17:14 +00:00
|
|
|
#if wxUSE_MENUS
|
1999-04-12 11:48:06 +00:00
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu,
|
2001-08-18 13:09:26 +00:00
|
|
|
*style_menu = new wxMenu,
|
1999-04-12 11:48:06 +00:00
|
|
|
*tree_menu = new wxMenu,
|
|
|
|
*item_menu = new wxMenu;
|
|
|
|
|
2001-09-21 20:21:44 +00:00
|
|
|
file_menu->Append(TreeTest_About, wxT("&About..."));
|
1999-04-12 11:48:06 +00:00
|
|
|
file_menu->AppendSeparator();
|
2001-09-21 20:21:44 +00:00
|
|
|
file_menu->Append(TreeTest_Quit, wxT("E&xit\tAlt-X"));
|
1999-04-12 11:48:06 +00:00
|
|
|
|
2004-06-13 00:02:35 +00:00
|
|
|
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"));
|
2001-08-18 13:09:26 +00:00
|
|
|
style_menu->AppendSeparator();
|
2004-06-13 00:02:35 +00:00
|
|
|
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"));
|
2000-02-23 00:30:59 +00:00
|
|
|
#ifndef NO_MULTIPLE_SELECTION
|
2004-06-13 00:02:35 +00:00
|
|
|
style_menu->AppendCheckItem(TreeTest_ToggleSel, wxT("Toggle &selection mode"));
|
2000-02-23 00:30:59 +00:00
|
|
|
#endif // NO_MULTIPLE_SELECTION
|
2004-06-13 00:02:35 +00:00
|
|
|
style_menu->AppendCheckItem(TreeTest_ToggleImages, wxT("Toggle show ima&ges"));
|
2001-09-21 20:21:44 +00:00
|
|
|
style_menu->Append(TreeTest_SetImageSize, wxT("Set image si&ze..."));
|
2002-02-20 17:41:39 +00:00
|
|
|
style_menu->AppendSeparator();
|
|
|
|
style_menu->Append(TreeTest_SetFgColour, wxT("Set &foreground colour..."));
|
|
|
|
style_menu->Append(TreeTest_SetBgColour, wxT("Set &background colour..."));
|
2002-03-16 15:10:43 +00:00
|
|
|
style_menu->AppendSeparator();
|
|
|
|
style_menu->Append(TreeTest_ResetStyle, wxT("&Reset to default\tF10"));
|
2001-08-18 13:09:26 +00:00
|
|
|
|
2002-12-08 13:21:33 +00:00
|
|
|
tree_menu->Append(TreeTest_Recreate, wxT("&Recreate the tree"));
|
|
|
|
tree_menu->Append(TreeTest_CollapseAndReset, wxT("C&ollapse and reset"));
|
1999-04-12 11:48:06 +00:00
|
|
|
tree_menu->AppendSeparator();
|
2002-12-08 13:21:33 +00:00
|
|
|
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"));
|
2004-02-12 16:35:36 +00:00
|
|
|
tree_menu->Append(TreeTest_SelectRoot, wxT("Select root item"));
|
1999-04-12 11:48:06 +00:00
|
|
|
tree_menu->AppendSeparator();
|
2002-12-08 13:21:33 +00:00
|
|
|
tree_menu->Append(TreeTest_Count, wxT("Count children of current item"));
|
|
|
|
tree_menu->Append(TreeTest_CountRec, wxT("Recursively count children of current item"));
|
1999-10-02 19:43:56 +00:00
|
|
|
tree_menu->AppendSeparator();
|
2002-12-08 13:21:33 +00:00
|
|
|
tree_menu->Append(TreeTest_Sort, wxT("Sort children of current item"));
|
|
|
|
tree_menu->Append(TreeTest_SortRev, wxT("Sort in reversed order"));
|
1999-04-12 11:48:06 +00:00
|
|
|
tree_menu->AppendSeparator();
|
2002-12-08 13:21:33 +00:00
|
|
|
tree_menu->Append(TreeTest_EnsureVisible, wxT("Make the last item &visible"));
|
1999-05-03 23:11:53 +00:00
|
|
|
tree_menu->AppendSeparator();
|
2002-12-08 13:21:33 +00:00
|
|
|
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"));
|
1999-05-03 23:11:53 +00:00
|
|
|
tree_menu->AppendSeparator();
|
2002-12-08 13:21:33 +00:00
|
|
|
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"));
|
1999-04-12 11:48:06 +00:00
|
|
|
|
2002-12-08 13:21:33 +00:00
|
|
|
item_menu->Append(TreeTest_Dump, wxT("&Dump item children"));
|
|
|
|
item_menu->Append(TreeTest_Rename, wxT("&Rename item..."));
|
1999-06-13 15:24:01 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
item_menu->AppendSeparator();
|
2002-12-08 13:21:33 +00:00
|
|
|
item_menu->Append(TreeTest_SetBold, wxT("Make item &bold"));
|
|
|
|
item_menu->Append(TreeTest_ClearBold, wxT("Make item ¬ bold"));
|
1999-07-30 22:45:55 +00:00
|
|
|
item_menu->AppendSeparator();
|
2002-12-08 13:21:33 +00:00
|
|
|
item_menu->Append(TreeTest_ToggleIcon, wxT("Toggle the item's &icon"));
|
1999-07-30 22:45:55 +00:00
|
|
|
|
|
|
|
#ifndef NO_MULTIPLE_SELECTION
|
|
|
|
item_menu->AppendSeparator();
|
2002-12-08 13:21:33 +00:00
|
|
|
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"));
|
2000-02-23 00:30:59 +00:00
|
|
|
#endif // NO_MULTIPLE_SELECTION
|
1999-04-12 11:48:06 +00:00
|
|
|
|
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
2002-12-08 13:21:33 +00:00
|
|
|
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"));
|
1999-04-12 11:48:06 +00:00
|
|
|
SetMenuBar(menu_bar);
|
2001-07-04 16:17:14 +00:00
|
|
|
#endif // wxUSE_MENUS
|
2000-03-03 10:31:34 +00:00
|
|
|
|
2006-08-03 23:43:35 +00:00
|
|
|
m_panel = new wxPanel(this);
|
|
|
|
|
2004-07-21 10:29:21 +00:00
|
|
|
#if wxUSE_LOG
|
2002-03-16 15:10:43 +00:00
|
|
|
// create the controls
|
2006-08-03 23:43:35 +00:00
|
|
|
m_textCtrl = new wxTextCtrl(m_panel, wxID_ANY, wxT(""),
|
1999-04-12 11:48:06 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_MULTILINE | wxSUNKEN_BORDER);
|
2004-07-21 10:29:21 +00:00
|
|
|
#endif // wxUSE_LOG
|
1999-04-12 11:48:06 +00:00
|
|
|
|
2002-03-16 15:10:43 +00:00
|
|
|
CreateTreeWithDefStyle();
|
|
|
|
|
2004-05-20 17:23:15 +00:00
|
|
|
menu_bar->Check(TreeTest_ToggleImages, true);
|
2002-03-16 15:10:43 +00:00
|
|
|
|
2003-09-21 19:40:35 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
// create a status bar
|
|
|
|
CreateStatusBar(2);
|
|
|
|
#endif // wxUSE_STATUSBAR
|
1998-10-24 23:53:20 +00:00
|
|
|
|
2004-07-21 10:29:21 +00:00
|
|
|
#if wxUSE_LOG
|
1998-12-04 10:30:39 +00:00
|
|
|
#ifdef __WXMOTIF__
|
1999-04-12 11:48:06 +00:00
|
|
|
// 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);
|
1998-12-04 10:30:39 +00:00
|
|
|
#else
|
1999-04-12 11:48:06 +00:00
|
|
|
// set our text control as the log target
|
2000-02-23 00:30:59 +00:00
|
|
|
wxLogTextCtrl *logWindow = new wxLogTextCtrl(m_textCtrl);
|
1999-04-12 11:48:06 +00:00
|
|
|
delete wxLog::SetActiveTarget(logWindow);
|
1998-12-04 10:30:39 +00:00
|
|
|
#endif
|
2004-07-21 10:29:21 +00:00
|
|
|
#endif // wxUSE_LOG
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-09-29 20:02:53 +00:00
|
|
|
MyFrame::~MyFrame()
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2004-07-21 10:29:21 +00:00
|
|
|
#if wxUSE_LOG
|
1999-04-12 11:48:06 +00:00
|
|
|
delete wxLog::SetActiveTarget(NULL);
|
2004-07-21 10:29:21 +00:00
|
|
|
#endif // wxUSE_LOG
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2002-03-16 15:10:43 +00:00
|
|
|
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)
|
|
|
|
{
|
2006-08-03 23:43:35 +00:00
|
|
|
m_treeCtrl = new MyTreeCtrl(m_panel, TreeTest_Ctrl,
|
2002-03-16 15:10:43 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
style);
|
|
|
|
Resize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::TogStyle(int id, long flag)
|
2001-08-18 13:09:26 +00:00
|
|
|
{
|
2002-03-16 15:10:43 +00:00
|
|
|
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);
|
2001-08-18 13:09:26 +00:00
|
|
|
}
|
|
|
|
|
2003-09-21 19:40:35 +00:00
|
|
|
void MyFrame::OnIdle(wxIdleEvent& event)
|
|
|
|
{
|
|
|
|
#if wxUSE_STATUSBAR
|
2003-10-24 20:08:12 +00:00
|
|
|
if ( m_treeCtrl )
|
|
|
|
{
|
|
|
|
wxTreeItemId idRoot = m_treeCtrl->GetRootItem();
|
|
|
|
|
|
|
|
SetStatusText(wxString::Format
|
|
|
|
(
|
|
|
|
_T("Root/last item is %svisible/%svisible"),
|
|
|
|
m_treeCtrl->IsVisible(idRoot) ? _T("") : _T("not "),
|
|
|
|
m_treeCtrl->IsVisible(m_treeCtrl->GetLastChild(idRoot))
|
|
|
|
? _T("") : _T("not ")
|
|
|
|
), 1);
|
|
|
|
}
|
2003-09-21 19:40:35 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2000-02-23 00:30:59 +00:00
|
|
|
void MyFrame::OnSize(wxSizeEvent& event)
|
|
|
|
{
|
2004-10-06 20:54:57 +00:00
|
|
|
if ( m_treeCtrl
|
2004-07-21 10:29:21 +00:00
|
|
|
#if wxUSE_LOG
|
2004-10-06 20:54:57 +00:00
|
|
|
&& m_textCtrl
|
2004-07-21 10:29:21 +00:00
|
|
|
#endif // wxUSE_LOG
|
|
|
|
)
|
2000-02-23 00:30:59 +00:00
|
|
|
{
|
2002-03-16 15:10:43 +00:00
|
|
|
Resize();
|
2000-02-23 00:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2002-03-16 15:10:43 +00:00
|
|
|
void MyFrame::Resize()
|
2000-02-23 00:30:59 +00:00
|
|
|
{
|
2002-03-16 15:10:43 +00:00
|
|
|
wxSize size = GetClientSize();
|
2004-07-21 10:29:21 +00:00
|
|
|
m_treeCtrl->SetSize(0, 0, size.x, size.y
|
|
|
|
#if !wxUSE_LOG
|
|
|
|
);
|
|
|
|
#else
|
|
|
|
*2/3);
|
2000-02-23 00:30:59 +00:00
|
|
|
m_textCtrl->SetSize(0, 2*size.y/3, size.x, size.y/3);
|
2004-07-21 10:29:21 +00:00
|
|
|
#endif
|
2000-02-23 00:30:59 +00:00
|
|
|
}
|
|
|
|
|
1998-10-24 23:53:20 +00:00
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2004-05-20 17:23:15 +00:00
|
|
|
Close(true);
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-10-24 23:53:20 +00:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2002-12-08 13:21:33 +00:00
|
|
|
wxMessageBox(wxT("Tree test sample\n")
|
|
|
|
wxT("(c) Julian Smart 1997, Vadim Zeitlin 1998"),
|
|
|
|
wxT("About tree test"),
|
1999-04-12 11:48:06 +00:00
|
|
|
wxOK | wxICON_INFORMATION, this);
|
1998-12-18 15:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
wxTreeItemId item = m_treeCtrl->GetSelection();
|
1998-12-18 15:37:19 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
CHECK_ITEM( item );
|
1998-12-18 15:37:19 +00:00
|
|
|
|
1999-07-23 23:41:45 +00:00
|
|
|
// old code - now we edit in place
|
|
|
|
#if 0
|
1999-04-12 11:48:06 +00:00
|
|
|
static wxString s_text;
|
2002-12-08 13:21:33 +00:00
|
|
|
s_text = wxGetTextFromUser(wxT("New name: "), wxT("Tree sample question"),
|
1999-04-12 11:48:06 +00:00
|
|
|
s_text, this);
|
2004-12-14 20:52:13 +00:00
|
|
|
if ( !s_text.empty() )
|
1999-04-12 11:48:06 +00:00
|
|
|
{
|
|
|
|
m_treeCtrl->SetItemText(item, s_text);
|
|
|
|
}
|
1999-07-23 23:41:45 +00:00
|
|
|
#endif // 0
|
|
|
|
|
|
|
|
// TODO demonstrate creating a custom edit control...
|
|
|
|
(void)m_treeCtrl->EditLabel(item);
|
1998-12-18 15:37:19 +00:00
|
|
|
}
|
|
|
|
|
1999-10-02 19:43:56 +00:00
|
|
|
void MyFrame::OnCount(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxTreeItemId item = m_treeCtrl->GetSelection();
|
|
|
|
|
|
|
|
CHECK_ITEM( item );
|
|
|
|
|
2004-05-20 17:23:15 +00:00
|
|
|
int i = m_treeCtrl->GetChildrenCount( item, false );
|
1999-12-29 10:29:26 +00:00
|
|
|
|
1999-10-10 19:56:38 +00:00
|
|
|
wxLogMessage(wxT("%d children"), i);
|
1999-10-02 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnCountRec(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxTreeItemId item = m_treeCtrl->GetSelection();
|
|
|
|
|
|
|
|
CHECK_ITEM( item );
|
|
|
|
|
|
|
|
int i = m_treeCtrl->GetChildrenCount( item );
|
1999-12-29 10:29:26 +00:00
|
|
|
|
1999-10-10 19:56:38 +00:00
|
|
|
wxLogMessage(wxT("%d children"), i);
|
1999-10-02 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
1998-12-18 15:37:19 +00:00
|
|
|
void MyFrame::DoSort(bool reverse)
|
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
wxTreeItemId item = m_treeCtrl->GetSelection();
|
1998-12-18 15:37:19 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
CHECK_ITEM( item );
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
m_treeCtrl->DoSortChildren(item, reverse);
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-11-13 20:47:22 +00:00
|
|
|
void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
wxTreeItemId root = m_treeCtrl->GetSelection();
|
1998-12-18 15:37:19 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
CHECK_ITEM( root );
|
1998-12-18 15:37:19 +00:00
|
|
|
|
2003-07-20 14:01:00 +00:00
|
|
|
m_treeCtrl->GetItemsRecursively(root);
|
1998-11-13 20:47:22 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:45:55 +00:00
|
|
|
#ifndef NO_MULTIPLE_SELECTION
|
|
|
|
|
2002-03-16 15:10:43 +00:00
|
|
|
void MyFrame::OnToggleSel(wxCommandEvent& event)
|
2000-02-23 00:30:59 +00:00
|
|
|
{
|
2002-03-16 15:10:43 +00:00
|
|
|
TogStyle(event.GetId(), wxTR_MULTIPLE);
|
2000-02-23 00:30:59 +00:00
|
|
|
}
|
|
|
|
|
1999-06-13 15:24:01 +00:00
|
|
|
void MyFrame::OnDumpSelected(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
1999-07-30 22:45:55 +00:00
|
|
|
wxArrayTreeItemIds array;
|
1999-06-13 15:24:01 +00:00
|
|
|
|
1999-07-30 22:45:55 +00:00
|
|
|
size_t count = m_treeCtrl->GetSelections(array);
|
2006-10-02 05:36:31 +00:00
|
|
|
wxLogMessage(wxT("%u items selected"), unsigned(count));
|
1999-06-13 15:24:01 +00:00
|
|
|
|
1999-07-30 22:45:55 +00:00
|
|
|
for ( size_t n = 0; n < count; n++ )
|
|
|
|
{
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogMessage(wxT("\t%s"), m_treeCtrl->GetItemText(array.Item(n)).c_str());
|
1999-07-30 22:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-11 12:52:20 +00:00
|
|
|
void MyFrame::OnSelect(wxCommandEvent& WXUNUSED(event))
|
1999-07-30 22:45:55 +00:00
|
|
|
{
|
|
|
|
m_treeCtrl->SelectItem(m_treeCtrl->GetSelection());
|
|
|
|
}
|
|
|
|
|
2004-02-12 16:35:36 +00:00
|
|
|
void MyFrame::OnSelectRoot(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_treeCtrl->SelectItem(m_treeCtrl->GetRootItem());
|
|
|
|
}
|
|
|
|
|
2003-09-11 12:52:20 +00:00
|
|
|
void MyFrame::OnUnselect(wxCommandEvent& WXUNUSED(event))
|
1999-07-30 22:45:55 +00:00
|
|
|
{
|
|
|
|
m_treeCtrl->UnselectAll();
|
1999-06-13 15:24:01 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:45:55 +00:00
|
|
|
#endif // NO_MULTIPLE_SELECTION
|
|
|
|
|
1998-11-30 00:08:57 +00:00
|
|
|
void MyFrame::DoSetBold(bool bold)
|
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
wxTreeItemId item = m_treeCtrl->GetSelection();
|
1998-12-18 15:37:19 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
CHECK_ITEM( item );
|
1998-12-18 15:37:19 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
m_treeCtrl->SetItemBold(item, bold);
|
1998-11-30 00:08:57 +00:00
|
|
|
}
|
|
|
|
|
1998-11-26 19:10:01 +00:00
|
|
|
void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
wxTreeItemId item = m_treeCtrl->GetSelection();
|
1998-12-18 15:37:19 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
CHECK_ITEM( item );
|
1998-12-18 15:37:19 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
m_treeCtrl->Delete(item);
|
1998-11-26 19:10:01 +00:00
|
|
|
}
|
|
|
|
|
1998-12-17 18:41:00 +00:00
|
|
|
void MyFrame::OnDeleteChildren(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
wxTreeItemId item = m_treeCtrl->GetSelection();
|
1998-12-18 15:37:19 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
CHECK_ITEM( item );
|
1998-12-18 15:37:19 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
m_treeCtrl->DeleteChildren(item);
|
1998-12-17 18:41:00 +00:00
|
|
|
}
|
|
|
|
|
1998-11-26 19:10:01 +00:00
|
|
|
void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
m_treeCtrl->DeleteAllItems();
|
1998-11-26 19:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnRecreate(wxCommandEvent& event)
|
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
OnDeleteAll(event);
|
2001-08-18 13:09:26 +00:00
|
|
|
m_treeCtrl->AddTestItemsToTree(5, 2);
|
1998-11-26 19:10:01 +00:00
|
|
|
}
|
|
|
|
|
2003-09-11 12:52:20 +00:00
|
|
|
void MyFrame::OnSetImageSize(wxCommandEvent& WXUNUSED(event))
|
2000-03-03 10:31:34 +00:00
|
|
|
{
|
2002-12-08 13:21:33 +00:00
|
|
|
int size = wxGetNumberFromUser(wxT("Enter the size for the images to use"),
|
|
|
|
wxT("Size: "),
|
|
|
|
wxT("TreeCtrl sample"),
|
2001-08-18 13:09:26 +00:00
|
|
|
m_treeCtrl->ImageSize());
|
2000-03-03 10:31:34 +00:00
|
|
|
if ( size == -1 )
|
|
|
|
return;
|
|
|
|
|
2001-08-18 13:09:26 +00:00
|
|
|
m_treeCtrl->CreateImageList(size);
|
2004-05-20 17:23:15 +00:00
|
|
|
wxGetApp().SetShowImages(true);
|
2000-03-03 10:31:34 +00:00
|
|
|
}
|
|
|
|
|
2003-09-11 12:52:20 +00:00
|
|
|
void MyFrame::OnToggleImages(wxCommandEvent& WXUNUSED(event))
|
2000-03-03 10:31:34 +00:00
|
|
|
{
|
2000-07-15 19:51:35 +00:00
|
|
|
if ( wxGetApp().ShowImages() )
|
|
|
|
{
|
|
|
|
m_treeCtrl->CreateImageList(-1);
|
2004-05-20 17:23:15 +00:00
|
|
|
wxGetApp().SetShowImages(false);
|
2000-07-15 19:51:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-18 13:09:26 +00:00
|
|
|
m_treeCtrl->CreateImageList(0);
|
2004-05-20 17:23:15 +00:00
|
|
|
wxGetApp().SetShowImages(true);
|
2000-07-15 19:51:35 +00:00
|
|
|
}
|
2001-08-18 13:09:26 +00:00
|
|
|
}
|
2000-03-03 10:31:34 +00:00
|
|
|
|
2003-09-11 12:52:20 +00:00
|
|
|
void MyFrame::OnToggleButtons(wxCommandEvent& WXUNUSED(event))
|
2001-08-18 13:09:26 +00:00
|
|
|
{
|
2001-08-22 22:13:06 +00:00
|
|
|
#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
|
2001-08-18 13:09:26 +00:00
|
|
|
if ( wxGetApp().ShowButtons() )
|
|
|
|
{
|
|
|
|
m_treeCtrl->CreateButtonsImageList(-1);
|
2004-05-20 17:23:15 +00:00
|
|
|
wxGetApp().SetShowButtons(false);
|
2001-08-18 13:09:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_treeCtrl->CreateButtonsImageList(15);
|
2004-05-20 17:23:15 +00:00
|
|
|
wxGetApp().SetShowButtons(true);
|
2001-08-18 13:09:26 +00:00
|
|
|
}
|
2001-08-22 22:13:06 +00:00
|
|
|
#endif
|
2000-03-03 10:31:34 +00:00
|
|
|
}
|
|
|
|
|
2003-09-11 12:52:20 +00:00
|
|
|
void MyFrame::OnCollapseAndReset(wxCommandEvent& WXUNUSED(event))
|
1999-03-24 21:56:08 +00:00
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
m_treeCtrl->CollapseAndReset(m_treeCtrl->GetRootItem());
|
1999-03-24 21:56:08 +00:00
|
|
|
}
|
|
|
|
|
2003-09-11 12:52:20 +00:00
|
|
|
void MyFrame::OnEnsureVisible(wxCommandEvent& WXUNUSED(event))
|
1999-03-23 13:50:29 +00:00
|
|
|
{
|
|
|
|
m_treeCtrl->DoEnsureVisible();
|
|
|
|
}
|
|
|
|
|
1999-12-29 10:29:26 +00:00
|
|
|
void MyFrame::OnInsertItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2000-03-03 10:31:34 +00:00
|
|
|
int image = wxGetApp().ShowImages() ? MyTreeCtrl::TreeCtrlIcon_File : -1;
|
2002-12-08 13:21:33 +00:00
|
|
|
m_treeCtrl->InsertItem(m_treeCtrl->GetRootItem(), image, wxT("2nd item"));
|
1999-12-29 10:29:26 +00:00
|
|
|
}
|
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
void MyFrame::OnAddItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
static int s_num = 0;
|
|
|
|
|
|
|
|
wxString text;
|
2001-09-21 20:21:44 +00:00
|
|
|
text.Printf(wxT("Item #%d"), ++s_num);
|
1999-04-12 11:48:06 +00:00
|
|
|
|
|
|
|
m_treeCtrl->AppendItem(m_treeCtrl->GetRootItem(),
|
1999-07-19 14:41:30 +00:00
|
|
|
text /*,
|
|
|
|
MyTreeCtrl::TreeCtrlIcon_File */ );
|
1999-04-12 11:48:06 +00:00
|
|
|
}
|
|
|
|
|
1999-05-03 23:11:53 +00:00
|
|
|
void MyFrame::OnIncIndent(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
unsigned int indent = m_treeCtrl->GetIndent();
|
|
|
|
if (indent < 100)
|
|
|
|
m_treeCtrl->SetIndent( indent+5 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnDecIndent(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
unsigned int indent = m_treeCtrl->GetIndent();
|
|
|
|
if (indent > 10)
|
|
|
|
m_treeCtrl->SetIndent( indent-5 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnIncSpacing(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
unsigned int indent = m_treeCtrl->GetSpacing();
|
|
|
|
if (indent < 100)
|
|
|
|
m_treeCtrl->SetSpacing( indent+5 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnDecSpacing(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
unsigned int indent = m_treeCtrl->GetSpacing();
|
|
|
|
if (indent > 10)
|
|
|
|
m_treeCtrl->SetSpacing( indent-5 );
|
|
|
|
}
|
|
|
|
|
1999-07-30 22:45:55 +00:00
|
|
|
void MyFrame::OnToggleIcon(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxTreeItemId item = m_treeCtrl->GetSelection();
|
|
|
|
|
|
|
|
CHECK_ITEM( item );
|
|
|
|
|
|
|
|
m_treeCtrl->DoToggleIcon(item);
|
|
|
|
}
|
|
|
|
|
2002-02-20 17:41:39 +00:00
|
|
|
void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxColour col = wxGetColourFromUser(this, m_treeCtrl->GetForegroundColour());
|
|
|
|
if ( col.Ok() )
|
|
|
|
m_treeCtrl->SetForegroundColour(col);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnSetBgColour(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxColour col = wxGetColourFromUser(this, m_treeCtrl->GetBackgroundColour());
|
|
|
|
if ( col.Ok() )
|
|
|
|
m_treeCtrl->SetBackgroundColour(col);
|
|
|
|
}
|
|
|
|
|
1998-10-24 23:53:20 +00:00
|
|
|
// MyTreeCtrl implementation
|
2000-08-04 13:59:45 +00:00
|
|
|
#if USE_GENERIC_TREECTRL
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(MyTreeCtrl, wxGenericTreeCtrl)
|
|
|
|
#else
|
1998-12-20 00:34:52 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS(MyTreeCtrl, wxTreeCtrl)
|
2000-08-04 13:59:45 +00:00
|
|
|
#endif
|
1998-12-20 00:34:52 +00:00
|
|
|
|
1998-10-24 23:53:20 +00:00
|
|
|
MyTreeCtrl::MyTreeCtrl(wxWindow *parent, const wxWindowID id,
|
|
|
|
const wxPoint& pos, const wxSize& size,
|
|
|
|
long style)
|
|
|
|
: wxTreeCtrl(parent, id, pos, size, style)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2004-05-20 17:23:15 +00:00
|
|
|
m_reverseSort = false;
|
1999-06-13 15:24:01 +00:00
|
|
|
|
2000-03-03 10:31:34 +00:00
|
|
|
CreateImageList();
|
1999-06-13 15:24:01 +00:00
|
|
|
|
2000-03-03 10:31:34 +00:00
|
|
|
// Add some items to the tree
|
2001-08-18 13:09:26 +00:00
|
|
|
AddTestItemsToTree(5, 2);
|
2000-03-03 10:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyTreeCtrl::CreateImageList(int size)
|
|
|
|
{
|
|
|
|
if ( size == -1 )
|
|
|
|
{
|
2001-08-18 13:09:26 +00:00
|
|
|
SetImageList(NULL);
|
|
|
|
return;
|
2000-03-03 10:31:34 +00:00
|
|
|
}
|
2001-08-18 13:09:26 +00:00
|
|
|
if ( size == 0 )
|
|
|
|
size = m_imageSize;
|
2000-07-15 19:51:35 +00:00
|
|
|
else
|
2001-08-18 13:09:26 +00:00
|
|
|
m_imageSize = size;
|
|
|
|
|
|
|
|
// Make an image list containing small icons
|
2004-05-20 17:23:15 +00:00
|
|
|
wxImageList *images = new wxImageList(size, size, true);
|
1998-12-18 15:37:19 +00:00
|
|
|
|
2001-08-18 13:09:26 +00:00
|
|
|
// should correspond to TreeCtrlIcon_xxx enum
|
|
|
|
wxBusyCursor wait;
|
|
|
|
wxIcon icons[5];
|
2002-06-14 10:05:01 +00:00
|
|
|
icons[0] = wxIcon(icon1_xpm);
|
|
|
|
icons[1] = wxIcon(icon2_xpm);
|
|
|
|
icons[2] = wxIcon(icon3_xpm);
|
|
|
|
icons[3] = wxIcon(icon4_xpm);
|
|
|
|
icons[4] = wxIcon(icon5_xpm);
|
2001-08-18 13:09:26 +00:00
|
|
|
|
|
|
|
int sizeOrig = icons[0].GetWidth();
|
|
|
|
for ( size_t i = 0; i < WXSIZEOF(icons); i++ )
|
|
|
|
{
|
|
|
|
if ( size == sizeOrig )
|
2000-03-03 10:31:34 +00:00
|
|
|
{
|
2001-08-18 13:09:26 +00:00
|
|
|
images->Add(icons[i]);
|
2000-03-03 10:31:34 +00:00
|
|
|
}
|
2001-08-18 13:09:26 +00:00
|
|
|
else
|
|
|
|
{
|
2002-04-08 14:12:56 +00:00
|
|
|
images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
|
2001-08-18 13:09:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AssignImageList(images);
|
|
|
|
}
|
|
|
|
|
2003-09-11 12:52:20 +00:00
|
|
|
#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
|
2001-08-18 13:09:26 +00:00
|
|
|
void MyTreeCtrl::CreateButtonsImageList(int size)
|
|
|
|
{
|
|
|
|
if ( size == -1 )
|
|
|
|
{
|
|
|
|
SetButtonsImageList(NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make an image list containing small icons
|
2004-05-20 17:23:15 +00:00
|
|
|
wxImageList *images = new wxImageList(size, size, true);
|
2001-08-18 13:09:26 +00:00
|
|
|
|
|
|
|
// should correspond to TreeCtrlIcon_xxx enum
|
|
|
|
wxBusyCursor wait;
|
|
|
|
wxIcon icons[4];
|
2002-06-14 10:05:01 +00:00
|
|
|
icons[0] = wxIcon(icon3_xpm); // closed
|
|
|
|
icons[1] = wxIcon(icon3_xpm); // closed, selected
|
|
|
|
icons[2] = wxIcon(icon5_xpm); // open
|
|
|
|
icons[3] = wxIcon(icon5_xpm); // open, selected
|
2001-08-18 13:09:26 +00:00
|
|
|
|
|
|
|
for ( size_t i = 0; i < WXSIZEOF(icons); i++ )
|
|
|
|
{
|
|
|
|
int sizeOrig = icons[i].GetWidth();
|
|
|
|
if ( size == sizeOrig )
|
|
|
|
{
|
|
|
|
images->Add(icons[i]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-04-02 14:40:35 +00:00
|
|
|
images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
|
2001-08-18 13:09:26 +00:00
|
|
|
}
|
2000-03-03 10:31:34 +00:00
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
|
2001-08-18 13:09:26 +00:00
|
|
|
AssignButtonsImageList(images);
|
2003-09-11 12:52:20 +00:00
|
|
|
#else
|
|
|
|
void MyTreeCtrl::CreateButtonsImageList(int WXUNUSED(size))
|
|
|
|
{
|
2001-08-22 22:13:06 +00:00
|
|
|
#endif
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-12-18 15:37:19 +00:00
|
|
|
int MyTreeCtrl::OnCompareItems(const wxTreeItemId& item1,
|
|
|
|
const wxTreeItemId& item2)
|
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
if ( m_reverseSort )
|
|
|
|
{
|
|
|
|
// just exchange 1st and 2nd items
|
|
|
|
return wxTreeCtrl::OnCompareItems(item2, item1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return wxTreeCtrl::OnCompareItems(item1, item2);
|
|
|
|
}
|
1998-12-18 15:37:19 +00:00
|
|
|
}
|
|
|
|
|
1998-10-24 23:53:20 +00:00
|
|
|
void MyTreeCtrl::AddItemsRecursively(const wxTreeItemId& idParent,
|
|
|
|
size_t numChildren,
|
1998-11-13 20:47:22 +00:00
|
|
|
size_t depth,
|
|
|
|
size_t folder)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1999-03-23 13:50:29 +00:00
|
|
|
if ( depth > 0 )
|
1998-10-24 23:53:20 +00:00
|
|
|
{
|
1999-09-29 22:47:56 +00:00
|
|
|
bool hasChildren = depth > 1;
|
|
|
|
|
1999-03-23 13:50:29 +00:00
|
|
|
wxString str;
|
|
|
|
for ( size_t n = 0; n < numChildren; n++ )
|
|
|
|
{
|
|
|
|
// at depth 1 elements won't have any more children
|
1999-09-29 22:47:56 +00:00
|
|
|
if ( hasChildren )
|
2006-10-02 05:36:31 +00:00
|
|
|
str.Printf(wxT("%s child %u"), wxT("Folder"), unsigned(n + 1));
|
1999-09-29 22:47:56 +00:00
|
|
|
else
|
2006-10-02 05:36:31 +00:00
|
|
|
str.Printf(wxT("%s child %u.%u"), wxT("File"), unsigned(folder), unsigned(n + 1));
|
1999-03-23 13:50:29 +00:00
|
|
|
|
1999-09-29 22:47:56 +00:00
|
|
|
// here we pass to AppendItem() normal and selected item images (we
|
|
|
|
// suppose that selected image follows the normal one in the enum)
|
2000-03-03 10:31:34 +00:00
|
|
|
int image, imageSel;
|
|
|
|
if ( wxGetApp().ShowImages() )
|
|
|
|
{
|
|
|
|
image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder;
|
|
|
|
imageSel = image + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
image = imageSel = -1;
|
|
|
|
}
|
|
|
|
wxTreeItemId id = AppendItem(idParent, str, image, imageSel,
|
1999-03-23 13:50:29 +00:00
|
|
|
new MyTreeItemData(str));
|
|
|
|
|
1999-09-29 22:47:56 +00:00
|
|
|
// and now we also set the expanded one (only for the folders)
|
2000-03-03 10:31:34 +00:00
|
|
|
if ( hasChildren && wxGetApp().ShowImages() )
|
1999-09-29 22:47:56 +00:00
|
|
|
{
|
|
|
|
SetItemImage(id, TreeCtrlIcon_FolderOpened,
|
|
|
|
wxTreeItemIcon_Expanded);
|
|
|
|
}
|
|
|
|
|
1999-03-23 13:50:29 +00:00
|
|
|
// remember the last child for OnEnsureVisible()
|
1999-09-29 22:47:56 +00:00
|
|
|
if ( !hasChildren && n == numChildren - 1 )
|
1999-03-23 13:50:29 +00:00
|
|
|
{
|
|
|
|
m_lastItem = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddItemsRecursively(id, numChildren, depth - 1, n + 1);
|
|
|
|
}
|
1998-10-24 23:53:20 +00:00
|
|
|
}
|
1999-03-23 13:50:29 +00:00
|
|
|
//else: done!
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-10-24 23:53:20 +00:00
|
|
|
void MyTreeCtrl::AddTestItemsToTree(size_t numChildren,
|
|
|
|
size_t depth)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2000-03-03 10:31:34 +00:00
|
|
|
int image = wxGetApp().ShowImages() ? MyTreeCtrl::TreeCtrlIcon_Folder : -1;
|
2002-12-08 13:21:33 +00:00
|
|
|
wxTreeItemId rootId = AddRoot(wxT("Root"),
|
2000-03-03 10:31:34 +00:00
|
|
|
image, image,
|
2002-12-08 13:21:33 +00:00
|
|
|
new MyTreeItemData(wxT("Root item")));
|
2000-03-03 10:31:34 +00:00
|
|
|
if ( image != -1 )
|
|
|
|
{
|
|
|
|
SetItemImage(rootId, TreeCtrlIcon_FolderOpened, wxTreeItemIcon_Expanded);
|
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
AddItemsRecursively(rootId, numChildren, depth, 0);
|
1999-12-06 13:18:14 +00:00
|
|
|
|
|
|
|
// set some colours/fonts for testing
|
|
|
|
SetItemFont(rootId, *wxITALIC_FONT);
|
|
|
|
|
2003-07-20 14:01:00 +00:00
|
|
|
wxTreeItemIdValue cookie;
|
1999-12-06 13:18:14 +00:00
|
|
|
wxTreeItemId id = GetFirstChild(rootId, cookie);
|
|
|
|
SetItemTextColour(id, *wxBLUE);
|
|
|
|
|
|
|
|
id = GetNextChild(rootId, cookie);
|
|
|
|
id = GetNextChild(rootId, cookie);
|
|
|
|
SetItemTextColour(id, *wxRED);
|
|
|
|
SetItemBackgroundColour(id, *wxLIGHT_GREY);
|
1998-11-13 20:47:22 +00:00
|
|
|
}
|
|
|
|
|
2003-07-20 14:01:00 +00:00
|
|
|
void MyTreeCtrl::GetItemsRecursively(const wxTreeItemId& idParent,
|
|
|
|
wxTreeItemIdValue cookie)
|
1998-11-13 20:47:22 +00:00
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
wxTreeItemId id;
|
1998-11-13 20:47:22 +00:00
|
|
|
|
2003-07-20 14:01:00 +00:00
|
|
|
if ( !cookie )
|
1999-04-12 11:48:06 +00:00
|
|
|
id = GetFirstChild(idParent, cookie);
|
|
|
|
else
|
|
|
|
id = GetNextChild(idParent, cookie);
|
1998-11-13 20:47:22 +00:00
|
|
|
|
2003-07-20 14:01:00 +00:00
|
|
|
if ( !id.IsOk() )
|
1999-04-12 11:48:06 +00:00
|
|
|
return;
|
1998-11-13 20:47:22 +00:00
|
|
|
|
1999-07-30 22:45:55 +00:00
|
|
|
wxString text = GetItemText(id);
|
1999-04-12 11:48:06 +00:00
|
|
|
wxLogMessage(text);
|
1998-11-13 20:47:22 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
if (ItemHasChildren(id))
|
2003-07-20 14:01:00 +00:00
|
|
|
GetItemsRecursively(id);
|
1998-11-13 20:47:22 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
GetItemsRecursively(idParent, cookie);
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:45:55 +00:00
|
|
|
void MyTreeCtrl::DoToggleIcon(const wxTreeItemId& item)
|
|
|
|
{
|
2006-07-10 22:27:36 +00:00
|
|
|
int image = (GetItemImage(item) == TreeCtrlIcon_Folder)
|
|
|
|
? TreeCtrlIcon_File
|
|
|
|
: TreeCtrlIcon_Folder;
|
|
|
|
SetItemImage(item, image, wxTreeItemIcon_Normal);
|
|
|
|
|
|
|
|
image = (GetItemImage(item) == TreeCtrlIcon_FolderSelected)
|
|
|
|
? TreeCtrlIcon_FileSelected
|
|
|
|
: TreeCtrlIcon_FolderSelected;
|
|
|
|
SetItemImage(item, image, wxTreeItemIcon_Selected);
|
1999-07-30 22:45:55 +00:00
|
|
|
}
|
|
|
|
|
2006-09-24 15:24:19 +00:00
|
|
|
void MyTreeCtrl::LogEvent(const wxChar *name, const wxTreeEvent& event)
|
|
|
|
{
|
|
|
|
wxTreeItemId item = event.GetItem();
|
|
|
|
wxString text;
|
|
|
|
if ( item.IsOk() )
|
|
|
|
text << _T('"') << GetItemText(item).c_str() << _T('"');
|
|
|
|
else
|
|
|
|
text = _T("invalid item");
|
|
|
|
wxLogMessage(wxT("%s(%s)"), name, text.c_str());
|
|
|
|
}
|
1998-11-13 20:47:22 +00:00
|
|
|
|
1998-10-24 23:53:20 +00:00
|
|
|
// avoid repetition
|
2001-09-21 20:21:44 +00:00
|
|
|
#define TREE_EVENT_HANDLER(name) \
|
|
|
|
void MyTreeCtrl::name(wxTreeEvent& event) \
|
|
|
|
{ \
|
2006-09-24 15:24:19 +00:00
|
|
|
LogEvent(_T(#name), event); \
|
2003-05-01 15:38:55 +00:00
|
|
|
SetLastItem(wxTreeItemId()); \
|
2001-09-21 20:21:44 +00:00
|
|
|
event.Skip(); \
|
1999-04-12 11:48:06 +00:00
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1998-10-24 23:53:20 +00:00
|
|
|
TREE_EVENT_HANDLER(OnBeginRDrag)
|
|
|
|
TREE_EVENT_HANDLER(OnDeleteItem)
|
|
|
|
TREE_EVENT_HANDLER(OnGetInfo)
|
|
|
|
TREE_EVENT_HANDLER(OnSetInfo)
|
|
|
|
TREE_EVENT_HANDLER(OnItemExpanded)
|
|
|
|
TREE_EVENT_HANDLER(OnItemExpanding)
|
|
|
|
TREE_EVENT_HANDLER(OnItemCollapsed)
|
|
|
|
TREE_EVENT_HANDLER(OnSelChanged)
|
|
|
|
TREE_EVENT_HANDLER(OnSelChanging)
|
|
|
|
|
|
|
|
#undef TREE_EVENT_HANDLER
|
|
|
|
|
2002-07-21 14:29:13 +00:00
|
|
|
void LogKeyEvent(const wxChar *name, const wxKeyEvent& event)
|
|
|
|
{
|
|
|
|
wxString key;
|
2004-11-06 07:09:35 +00:00
|
|
|
long keycode = event.GetKeyCode();
|
2002-07-21 14:29:13 +00:00
|
|
|
{
|
2004-11-06 07:09:35 +00:00
|
|
|
switch ( keycode )
|
2002-07-21 14:29:13 +00:00
|
|
|
{
|
2004-11-06 07:09:35 +00:00
|
|
|
case WXK_BACK: key = wxT("BACK"); break;
|
|
|
|
case WXK_TAB: key = wxT("TAB"); break;
|
|
|
|
case WXK_RETURN: key = wxT("RETURN"); break;
|
|
|
|
case WXK_ESCAPE: key = wxT("ESCAPE"); break;
|
|
|
|
case WXK_SPACE: key = wxT("SPACE"); break;
|
|
|
|
case WXK_DELETE: key = wxT("DELETE"); break;
|
|
|
|
case WXK_START: key = wxT("START"); break;
|
|
|
|
case WXK_LBUTTON: key = wxT("LBUTTON"); break;
|
|
|
|
case WXK_RBUTTON: key = wxT("RBUTTON"); break;
|
|
|
|
case WXK_CANCEL: key = wxT("CANCEL"); break;
|
|
|
|
case WXK_MBUTTON: key = wxT("MBUTTON"); break;
|
|
|
|
case WXK_CLEAR: key = wxT("CLEAR"); break;
|
|
|
|
case WXK_SHIFT: key = wxT("SHIFT"); break;
|
|
|
|
case WXK_ALT: key = wxT("ALT"); break;
|
|
|
|
case WXK_CONTROL: key = wxT("CONTROL"); break;
|
|
|
|
case WXK_MENU: key = wxT("MENU"); break;
|
|
|
|
case WXK_PAUSE: key = wxT("PAUSE"); break;
|
|
|
|
case WXK_CAPITAL: key = wxT("CAPITAL"); break;
|
|
|
|
case WXK_END: key = wxT("END"); break;
|
|
|
|
case WXK_HOME: key = wxT("HOME"); break;
|
|
|
|
case WXK_LEFT: key = wxT("LEFT"); break;
|
|
|
|
case WXK_UP: key = wxT("UP"); break;
|
|
|
|
case WXK_RIGHT: key = wxT("RIGHT"); break;
|
|
|
|
case WXK_DOWN: key = wxT("DOWN"); break;
|
|
|
|
case WXK_SELECT: key = wxT("SELECT"); break;
|
|
|
|
case WXK_PRINT: key = wxT("PRINT"); break;
|
|
|
|
case WXK_EXECUTE: key = wxT("EXECUTE"); break;
|
|
|
|
case WXK_SNAPSHOT: key = wxT("SNAPSHOT"); break;
|
|
|
|
case WXK_INSERT: key = wxT("INSERT"); break;
|
|
|
|
case WXK_HELP: key = wxT("HELP"); break;
|
|
|
|
case WXK_NUMPAD0: key = wxT("NUMPAD0"); break;
|
|
|
|
case WXK_NUMPAD1: key = wxT("NUMPAD1"); break;
|
|
|
|
case WXK_NUMPAD2: key = wxT("NUMPAD2"); break;
|
|
|
|
case WXK_NUMPAD3: key = wxT("NUMPAD3"); break;
|
|
|
|
case WXK_NUMPAD4: key = wxT("NUMPAD4"); break;
|
|
|
|
case WXK_NUMPAD5: key = wxT("NUMPAD5"); break;
|
|
|
|
case WXK_NUMPAD6: key = wxT("NUMPAD6"); break;
|
|
|
|
case WXK_NUMPAD7: key = wxT("NUMPAD7"); break;
|
|
|
|
case WXK_NUMPAD8: key = wxT("NUMPAD8"); break;
|
|
|
|
case WXK_NUMPAD9: key = wxT("NUMPAD9"); break;
|
|
|
|
case WXK_MULTIPLY: key = wxT("MULTIPLY"); break;
|
|
|
|
case WXK_ADD: key = wxT("ADD"); break;
|
|
|
|
case WXK_SEPARATOR: key = wxT("SEPARATOR"); break;
|
|
|
|
case WXK_SUBTRACT: key = wxT("SUBTRACT"); break;
|
|
|
|
case WXK_DECIMAL: key = wxT("DECIMAL"); break;
|
|
|
|
case WXK_DIVIDE: key = wxT("DIVIDE"); break;
|
|
|
|
case WXK_F1: key = wxT("F1"); break;
|
|
|
|
case WXK_F2: key = wxT("F2"); break;
|
|
|
|
case WXK_F3: key = wxT("F3"); break;
|
|
|
|
case WXK_F4: key = wxT("F4"); break;
|
|
|
|
case WXK_F5: key = wxT("F5"); break;
|
|
|
|
case WXK_F6: key = wxT("F6"); break;
|
|
|
|
case WXK_F7: key = wxT("F7"); break;
|
|
|
|
case WXK_F8: key = wxT("F8"); break;
|
|
|
|
case WXK_F9: key = wxT("F9"); break;
|
|
|
|
case WXK_F10: key = wxT("F10"); break;
|
|
|
|
case WXK_F11: key = wxT("F11"); break;
|
|
|
|
case WXK_F12: key = wxT("F12"); break;
|
|
|
|
case WXK_F13: key = wxT("F13"); break;
|
|
|
|
case WXK_F14: key = wxT("F14"); break;
|
|
|
|
case WXK_F15: key = wxT("F15"); break;
|
|
|
|
case WXK_F16: key = wxT("F16"); break;
|
|
|
|
case WXK_F17: key = wxT("F17"); break;
|
|
|
|
case WXK_F18: key = wxT("F18"); break;
|
|
|
|
case WXK_F19: key = wxT("F19"); break;
|
|
|
|
case WXK_F20: key = wxT("F20"); break;
|
|
|
|
case WXK_F21: key = wxT("F21"); break;
|
|
|
|
case WXK_F22: key = wxT("F22"); break;
|
|
|
|
case WXK_F23: key = wxT("F23"); break;
|
|
|
|
case WXK_F24: key = wxT("F24"); break;
|
|
|
|
case WXK_NUMLOCK: key = wxT("NUMLOCK"); break;
|
|
|
|
case WXK_SCROLL: key = wxT("SCROLL"); break;
|
|
|
|
case WXK_PAGEUP: key = wxT("PAGEUP"); break;
|
|
|
|
case WXK_PAGEDOWN: key = wxT("PAGEDOWN"); break;
|
|
|
|
case WXK_NUMPAD_SPACE: key = wxT("NUMPAD_SPACE"); break;
|
|
|
|
case WXK_NUMPAD_TAB: key = wxT("NUMPAD_TAB"); break;
|
|
|
|
case WXK_NUMPAD_ENTER: key = wxT("NUMPAD_ENTER"); break;
|
|
|
|
case WXK_NUMPAD_F1: key = wxT("NUMPAD_F1"); break;
|
|
|
|
case WXK_NUMPAD_F2: key = wxT("NUMPAD_F2"); break;
|
|
|
|
case WXK_NUMPAD_F3: key = wxT("NUMPAD_F3"); break;
|
|
|
|
case WXK_NUMPAD_F4: key = wxT("NUMPAD_F4"); break;
|
|
|
|
case WXK_NUMPAD_HOME: key = wxT("NUMPAD_HOME"); break;
|
|
|
|
case WXK_NUMPAD_LEFT: key = wxT("NUMPAD_LEFT"); break;
|
|
|
|
case WXK_NUMPAD_UP: key = wxT("NUMPAD_UP"); break;
|
|
|
|
case WXK_NUMPAD_RIGHT: key = wxT("NUMPAD_RIGHT"); break;
|
|
|
|
case WXK_NUMPAD_DOWN: key = wxT("NUMPAD_DOWN"); break;
|
|
|
|
case WXK_NUMPAD_PAGEUP: key = wxT("NUMPAD_PAGEUP"); break;
|
|
|
|
case WXK_NUMPAD_PAGEDOWN: key = wxT("NUMPAD_PAGEDOWN"); break;
|
|
|
|
case WXK_NUMPAD_END: key = wxT("NUMPAD_END"); break;
|
|
|
|
case WXK_NUMPAD_BEGIN: key = wxT("NUMPAD_BEGIN"); break;
|
|
|
|
case WXK_NUMPAD_INSERT: key = wxT("NUMPAD_INSERT"); break;
|
|
|
|
case WXK_NUMPAD_DELETE: key = wxT("NUMPAD_DELETE"); break;
|
|
|
|
case WXK_NUMPAD_EQUAL: key = wxT("NUMPAD_EQUAL"); break;
|
|
|
|
case WXK_NUMPAD_MULTIPLY: key = wxT("NUMPAD_MULTIPLY"); break;
|
|
|
|
case WXK_NUMPAD_ADD: key = wxT("NUMPAD_ADD"); break;
|
|
|
|
case WXK_NUMPAD_SEPARATOR: key = wxT("NUMPAD_SEPARATOR"); break;
|
|
|
|
case WXK_NUMPAD_SUBTRACT: key = wxT("NUMPAD_SUBTRACT"); break;
|
|
|
|
case WXK_NUMPAD_DECIMAL: key = wxT("NUMPAD_DECIMAL"); break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2005-03-18 15:03:14 +00:00
|
|
|
if ( keycode < 128 && wxIsprint((int)keycode) )
|
2004-11-06 07:09:35 +00:00
|
|
|
key.Printf(wxT("'%c'"), (char)keycode);
|
|
|
|
else if ( keycode > 0 && keycode < 27 )
|
|
|
|
key.Printf(_("Ctrl-%c"), wxT('A') + keycode - 1);
|
|
|
|
else
|
|
|
|
key.Printf(wxT("unknown (%ld)"), keycode);
|
|
|
|
}
|
2002-07-21 14:29:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-08 13:21:33 +00:00
|
|
|
wxLogMessage( wxT("%s event: %s (flags = %c%c%c%c)"),
|
2002-07-21 14:29:13 +00:00
|
|
|
name,
|
|
|
|
key.c_str(),
|
2002-12-08 13:21:33 +00:00
|
|
|
event.ControlDown() ? wxT('C') : wxT('-'),
|
|
|
|
event.AltDown() ? wxT('A') : wxT('-'),
|
|
|
|
event.ShiftDown() ? wxT('S') : wxT('-'),
|
|
|
|
event.MetaDown() ? wxT('M') : wxT('-'));
|
2002-07-21 14:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyTreeCtrl::OnTreeKeyDown(wxTreeEvent& event)
|
|
|
|
{
|
2002-12-08 13:21:33 +00:00
|
|
|
LogKeyEvent(wxT("Tree key down "), event.GetKeyEvent());
|
2002-07-21 14:29:13 +00:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2000-02-15 23:57:33 +00:00
|
|
|
void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
|
|
|
|
{
|
|
|
|
// need to explicitly allow drag
|
|
|
|
if ( event.GetItem() != GetRootItem() )
|
|
|
|
{
|
|
|
|
m_draggedItem = event.GetItem();
|
|
|
|
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogMessage(wxT("OnBeginDrag: started dragging %s"),
|
2000-02-15 23:57:33 +00:00
|
|
|
GetItemText(m_draggedItem).c_str());
|
|
|
|
|
|
|
|
event.Allow();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogMessage(wxT("OnBeginDrag: this item can't be dragged."));
|
2000-02-15 23:57:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyTreeCtrl::OnEndDrag(wxTreeEvent& event)
|
|
|
|
{
|
|
|
|
wxTreeItemId itemSrc = m_draggedItem,
|
|
|
|
itemDst = event.GetItem();
|
2000-02-16 20:07:51 +00:00
|
|
|
m_draggedItem = (wxTreeItemId)0l;
|
2000-02-15 23:57:33 +00:00
|
|
|
|
|
|
|
// where to copy the item?
|
|
|
|
if ( itemDst.IsOk() && !ItemHasChildren(itemDst) )
|
|
|
|
{
|
|
|
|
// copy to the parent then
|
2002-12-29 07:48:21 +00:00
|
|
|
itemDst = GetItemParent(itemDst);
|
2000-02-15 23:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !itemDst.IsOk() )
|
|
|
|
{
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogMessage(wxT("OnEndDrag: can't drop here."));
|
2000-02-15 23:57:33 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString text = GetItemText(itemSrc);
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogMessage(wxT("OnEndDrag: '%s' copied to '%s'."),
|
2000-02-15 23:57:33 +00:00
|
|
|
text.c_str(), GetItemText(itemDst).c_str());
|
|
|
|
|
|
|
|
// just do append here - we could also insert it just before/after the item
|
|
|
|
// on which it was dropped, but this requires slightly more work... we also
|
|
|
|
// completely ignore the client data and icon of the old item but could
|
|
|
|
// copy them as well.
|
|
|
|
//
|
|
|
|
// Finally, we only copy one item here but we might copy the entire tree if
|
|
|
|
// we were dragging a folder.
|
2000-03-03 10:31:34 +00:00
|
|
|
int image = wxGetApp().ShowImages() ? TreeCtrlIcon_File : -1;
|
|
|
|
AppendItem(itemDst, text, image);
|
2000-02-15 23:57:33 +00:00
|
|
|
}
|
|
|
|
|
1999-07-23 23:41:45 +00:00
|
|
|
void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent& event)
|
|
|
|
{
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogMessage(wxT("OnBeginLabelEdit"));
|
1999-07-23 23:41:45 +00:00
|
|
|
|
2001-08-18 13:09:26 +00:00
|
|
|
// for testing, prevent this item's label editing
|
1999-07-23 23:41:45 +00:00
|
|
|
wxTreeItemId itemId = event.GetItem();
|
|
|
|
if ( IsTestItem(itemId) )
|
|
|
|
{
|
2001-09-21 20:21:44 +00:00
|
|
|
wxMessageBox(wxT("You can't edit this item."));
|
1999-07-23 23:41:45 +00:00
|
|
|
|
|
|
|
event.Veto();
|
|
|
|
}
|
2005-04-03 00:27:52 +00:00
|
|
|
else if ( itemId == GetRootItem() )
|
|
|
|
{
|
|
|
|
// test that it is possible to change the text of the item being edited
|
|
|
|
SetItemText(itemId, _T("Editing root item"));
|
|
|
|
}
|
1999-07-23 23:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyTreeCtrl::OnEndLabelEdit(wxTreeEvent& event)
|
|
|
|
{
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogMessage(wxT("OnEndLabelEdit"));
|
1999-07-23 23:41:45 +00:00
|
|
|
|
|
|
|
// don't allow anything except letters in the labels
|
|
|
|
if ( !event.GetLabel().IsWord() )
|
|
|
|
{
|
2002-07-08 16:35:52 +00:00
|
|
|
wxMessageBox(wxT("The new label should be a single word."));
|
1999-07-23 23:41:45 +00:00
|
|
|
|
|
|
|
event.Veto();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-24 23:53:20 +00:00
|
|
|
void MyTreeCtrl::OnItemCollapsing(wxTreeEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogMessage(wxT("OnItemCollapsing"));
|
1998-10-26 17:11:33 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
// for testing, prevent the user from collapsing the first child folder
|
|
|
|
wxTreeItemId itemId = event.GetItem();
|
1999-07-23 23:41:45 +00:00
|
|
|
if ( IsTestItem(itemId) )
|
1999-04-12 11:48:06 +00:00
|
|
|
{
|
2001-09-21 20:21:44 +00:00
|
|
|
wxMessageBox(wxT("You can't collapse this item."));
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
event.Veto();
|
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2000-02-29 01:49:05 +00:00
|
|
|
void MyTreeCtrl::OnItemActivated(wxTreeEvent& event)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
1999-04-12 11:48:06 +00:00
|
|
|
// show some info about this item
|
2000-02-29 01:49:05 +00:00
|
|
|
wxTreeItemId itemId = event.GetItem();
|
1999-04-12 11:48:06 +00:00
|
|
|
MyTreeItemData *item = (MyTreeItemData *)GetItemData(itemId);
|
1998-05-22 19:57:05 +00:00
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
if ( item != NULL )
|
|
|
|
{
|
|
|
|
item->ShowInfo(this);
|
|
|
|
}
|
1998-05-22 19:57:05 +00:00
|
|
|
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogMessage(wxT("OnItemActivated"));
|
1999-04-12 11:48:06 +00:00
|
|
|
}
|
|
|
|
|
2005-03-18 15:13:41 +00:00
|
|
|
void MyTreeCtrl::OnItemMenu(wxTreeEvent& event)
|
|
|
|
{
|
|
|
|
wxTreeItemId itemId = event.GetItem();
|
|
|
|
MyTreeItemData *item = itemId.IsOk() ? (MyTreeItemData *)GetItemData(itemId)
|
|
|
|
: NULL;
|
|
|
|
|
|
|
|
wxLogMessage(wxT("OnItemMenu for item \"%s\""), item ? item->GetDesc()
|
|
|
|
: _T(""));
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2003-07-10 12:46:48 +00:00
|
|
|
void MyTreeCtrl::OnContextMenu(wxContextMenuEvent& event)
|
2001-05-27 02:16:09 +00:00
|
|
|
{
|
|
|
|
wxPoint pt = event.GetPosition();
|
2005-04-06 22:32:24 +00:00
|
|
|
wxTreeItemId item;
|
2003-07-23 19:04:42 +00:00
|
|
|
wxLogMessage(wxT("OnContextMenu at screen coords (%i, %i)"), pt.x, pt.y);
|
2003-07-10 12:46:48 +00:00
|
|
|
|
2005-03-18 15:13:41 +00:00
|
|
|
// check if event was generated by keyboard (MSW-specific?)
|
|
|
|
if ( pt.x == -1 && pt.y == -1 ) //(this is how MSW indicates it)
|
2003-07-10 12:46:48 +00:00
|
|
|
{
|
2006-10-22 22:33:25 +00:00
|
|
|
if ( !HasFlag(wxTR_MULTIPLE) )
|
|
|
|
item = GetSelection();
|
|
|
|
|
2005-03-18 15:13:41 +00:00
|
|
|
// attempt to guess where to show the menu
|
|
|
|
if ( item.IsOk() )
|
2004-10-06 20:54:57 +00:00
|
|
|
{
|
2005-03-18 15:13:41 +00:00
|
|
|
// if an item was clicked, show menu to the right of it
|
2003-07-10 12:46:48 +00:00
|
|
|
wxRect rect;
|
2005-03-18 15:13:41 +00:00
|
|
|
GetBoundingRect(item, rect, true /* only the label */);
|
2003-07-10 12:46:48 +00:00
|
|
|
pt = wxPoint(rect.GetRight(), rect.GetTop());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pt = wxPoint(0, 0);
|
|
|
|
}
|
|
|
|
}
|
2005-03-18 15:13:41 +00:00
|
|
|
else // event was generated by mouse, use supplied coords
|
2003-07-10 12:46:48 +00:00
|
|
|
{
|
|
|
|
pt = ScreenToClient(pt);
|
2006-10-22 22:33:25 +00:00
|
|
|
item = HitTest(pt);
|
2003-07-10 12:46:48 +00:00
|
|
|
}
|
2004-10-06 20:54:57 +00:00
|
|
|
|
2003-07-10 12:46:48 +00:00
|
|
|
ShowMenu(item, pt);
|
2001-05-27 02:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt)
|
|
|
|
{
|
|
|
|
wxString title;
|
|
|
|
if ( id.IsOk() )
|
|
|
|
{
|
2002-12-08 13:21:33 +00:00
|
|
|
title << wxT("Menu for ") << GetItemText(id);
|
2001-05-27 02:16:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-12-08 13:21:33 +00:00
|
|
|
title = wxT("Menu for no particular item");
|
2001-05-27 02:16:09 +00:00
|
|
|
}
|
|
|
|
|
2001-07-04 16:17:14 +00:00
|
|
|
#if wxUSE_MENUS
|
2001-05-27 02:16:09 +00:00
|
|
|
wxMenu menu(title);
|
2002-12-08 13:21:33 +00:00
|
|
|
menu.Append(TreeTest_About, wxT("&About..."));
|
|
|
|
menu.Append(TreeTest_Dump, wxT("&Dump"));
|
2001-05-27 02:16:09 +00:00
|
|
|
|
|
|
|
PopupMenu(&menu, pt);
|
2001-07-04 16:17:14 +00:00
|
|
|
#endif // wxUSE_MENUS
|
2001-05-27 02:16:09 +00:00
|
|
|
}
|
|
|
|
|
2005-04-06 22:32:24 +00:00
|
|
|
void MyTreeCtrl::OnItemRClick(wxTreeEvent& event)
|
|
|
|
{
|
|
|
|
wxTreeItemId itemId = event.GetItem();
|
|
|
|
MyTreeItemData *item = itemId.IsOk() ? (MyTreeItemData *)GetItemData(itemId)
|
|
|
|
: NULL;
|
|
|
|
|
|
|
|
wxLogMessage(wxT("Item \"%s\" right clicked"), item ? item->GetDesc()
|
|
|
|
: _T(""));
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2005-04-05 23:03:32 +00:00
|
|
|
void MyTreeCtrl::OnRMouseDown(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
wxLogMessage(wxT("Right mouse button down"));
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyTreeCtrl::OnRMouseUp(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
wxLogMessage(wxT("Right mouse button up"));
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
1999-04-12 11:48:06 +00:00
|
|
|
void MyTreeCtrl::OnRMouseDClick(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
wxTreeItemId id = HitTest(event.GetPosition());
|
|
|
|
if ( !id )
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogMessage(wxT("No item under mouse"));
|
1999-04-12 11:48:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
MyTreeItemData *item = (MyTreeItemData *)GetItemData(id);
|
|
|
|
if ( item )
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogMessage(wxT("Item '%s' under mouse"), item->GetDesc());
|
1999-04-12 11:48:06 +00:00
|
|
|
}
|
2005-04-05 23:03:32 +00:00
|
|
|
|
|
|
|
event.Skip();
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2001-09-21 20:21:44 +00:00
|
|
|
static inline const wxChar *Bool2String(bool b)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-09-21 20:21:44 +00:00
|
|
|
return b ? wxT("") : wxT("not ");
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
1998-12-08 10:44:46 +00:00
|
|
|
void MyTreeItemData::ShowInfo(wxTreeCtrl *tree)
|
1998-05-22 19:57:05 +00:00
|
|
|
{
|
2001-09-21 20:21:44 +00:00
|
|
|
wxLogMessage(wxT("Item '%s': %sselected, %sexpanded, %sbold,\n")
|
|
|
|
wxT("%u children (%u immediately under this item)."),
|
1999-04-12 11:48:06 +00:00
|
|
|
m_desc.c_str(),
|
|
|
|
Bool2String(tree->IsSelected(GetId())),
|
|
|
|
Bool2String(tree->IsExpanded(GetId())),
|
|
|
|
Bool2String(tree->IsBold(GetId())),
|
2006-10-02 05:36:31 +00:00
|
|
|
unsigned(tree->GetChildrenCount(GetId())),
|
|
|
|
unsigned(tree->GetChildrenCount(GetId(), false)));
|
1998-05-22 19:57:05 +00:00
|
|
|
}
|