1998-05-22 15:57:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2000-03-14 13:37:46 -05:00
|
|
|
// Name: treectrl.h
|
1998-05-22 15:57:05 -04:00
|
|
|
// Purpose: wxTreeCtrl sample
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
2003-03-17 06:55:54 -05:00
|
|
|
// Copyright: (c) Julian Smart
|
1998-10-28 16:32:29 -05:00
|
|
|
// Licence: wxWindows license
|
1998-05-22 15:57:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2000-08-04 09:59:45 -04:00
|
|
|
#define USE_GENERIC_TREECTRL 0
|
|
|
|
|
|
|
|
#if USE_GENERIC_TREECTRL
|
|
|
|
#include "wx/generic/treectlg.h"
|
|
|
|
#ifndef wxTreeCtrl
|
|
|
|
#define wxTreeCtrl wxGenericTreeCtrl
|
|
|
|
#define sm_classwxTreeCtrl sm_classwxGenericTreeCtrl
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
1998-05-22 15:57:05 -04:00
|
|
|
// Define a new application type
|
1998-10-28 16:32:29 -05:00
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
2004-05-20 13:23:15 -04:00
|
|
|
MyApp() { m_showImages = true; m_showButtons = false; }
|
2000-03-03 05:31:34 -05:00
|
|
|
|
1999-04-12 07:48:06 -04:00
|
|
|
bool OnInit();
|
2000-03-03 05:31:34 -05:00
|
|
|
|
|
|
|
void SetShowImages(bool show) { m_showImages = show; }
|
|
|
|
bool ShowImages() const { return m_showImages; }
|
|
|
|
|
2001-08-18 09:09:26 -04:00
|
|
|
void SetShowButtons(bool show) { m_showButtons = show; }
|
|
|
|
bool ShowButtons() const { return m_showButtons; }
|
|
|
|
|
2000-03-03 05:31:34 -05:00
|
|
|
private:
|
2001-08-18 09:09:26 -04:00
|
|
|
bool m_showImages, m_showButtons;
|
1998-10-28 16:32:29 -05:00
|
|
|
};
|
1998-05-22 15:57:05 -04:00
|
|
|
|
1998-10-28 16:32:29 -05:00
|
|
|
class MyTreeItemData : public wxTreeItemData
|
|
|
|
{
|
|
|
|
public:
|
1999-04-12 07:48:06 -04:00
|
|
|
MyTreeItemData(const wxString& desc) : m_desc(desc) { }
|
1998-10-28 16:32:29 -05:00
|
|
|
|
1999-04-12 07:48:06 -04:00
|
|
|
void ShowInfo(wxTreeCtrl *tree);
|
2001-09-21 16:21:44 -04:00
|
|
|
const wxChar *GetDesc() const { return m_desc.c_str(); }
|
1998-10-28 16:32:29 -05:00
|
|
|
|
|
|
|
private:
|
1999-04-12 07:48:06 -04:00
|
|
|
wxString m_desc;
|
1998-05-22 15:57:05 -04:00
|
|
|
};
|
|
|
|
|
1998-10-28 16:32:29 -05:00
|
|
|
class MyTreeCtrl : public wxTreeCtrl
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
|
|
|
public:
|
1999-04-12 07:48:06 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
TreeCtrlIcon_File,
|
1999-09-29 18:47:56 -04:00
|
|
|
TreeCtrlIcon_FileSelected,
|
|
|
|
TreeCtrlIcon_Folder,
|
|
|
|
TreeCtrlIcon_FolderSelected,
|
|
|
|
TreeCtrlIcon_FolderOpened
|
1999-04-12 07:48:06 -04:00
|
|
|
};
|
|
|
|
|
2007-04-07 15:59:51 -04:00
|
|
|
MyTreeCtrl() { m_alternateImages = false; }
|
1999-04-12 07:48:06 -04:00
|
|
|
MyTreeCtrl(wxWindow *parent, const wxWindowID id,
|
|
|
|
const wxPoint& pos, const wxSize& size,
|
|
|
|
long style);
|
2004-10-06 16:54:57 -04:00
|
|
|
virtual ~MyTreeCtrl(){};
|
1999-04-12 07:48:06 -04:00
|
|
|
|
|
|
|
void OnBeginDrag(wxTreeEvent& event);
|
|
|
|
void OnBeginRDrag(wxTreeEvent& event);
|
2000-02-15 18:57:33 -05:00
|
|
|
void OnEndDrag(wxTreeEvent& event);
|
1999-04-12 07:48:06 -04:00
|
|
|
void OnBeginLabelEdit(wxTreeEvent& event);
|
|
|
|
void OnEndLabelEdit(wxTreeEvent& event);
|
|
|
|
void OnDeleteItem(wxTreeEvent& event);
|
2003-07-10 08:46:48 -04:00
|
|
|
void OnContextMenu(wxContextMenuEvent& event);
|
2005-03-18 10:13:41 -05:00
|
|
|
void OnItemMenu(wxTreeEvent& event);
|
1999-04-12 07:48:06 -04:00
|
|
|
void OnGetInfo(wxTreeEvent& event);
|
|
|
|
void OnSetInfo(wxTreeEvent& event);
|
|
|
|
void OnItemExpanded(wxTreeEvent& event);
|
|
|
|
void OnItemExpanding(wxTreeEvent& event);
|
|
|
|
void OnItemCollapsed(wxTreeEvent& event);
|
|
|
|
void OnItemCollapsing(wxTreeEvent& event);
|
|
|
|
void OnSelChanged(wxTreeEvent& event);
|
|
|
|
void OnSelChanging(wxTreeEvent& event);
|
|
|
|
void OnTreeKeyDown(wxTreeEvent& event);
|
|
|
|
void OnItemActivated(wxTreeEvent& event);
|
2005-04-09 07:04:00 -04:00
|
|
|
void OnItemRClick(wxTreeEvent& event);
|
2005-04-05 19:03:32 -04:00
|
|
|
|
|
|
|
void OnRMouseDown(wxMouseEvent& event);
|
|
|
|
void OnRMouseUp(wxMouseEvent& event);
|
1999-04-12 07:48:06 -04:00
|
|
|
void OnRMouseDClick(wxMouseEvent& event);
|
|
|
|
|
2003-07-20 10:01:00 -04:00
|
|
|
void GetItemsRecursively(const wxTreeItemId& idParent,
|
|
|
|
wxTreeItemIdValue cookie = 0);
|
1999-04-12 07:48:06 -04:00
|
|
|
|
2000-03-09 20:17:08 -05:00
|
|
|
void CreateImageList(int size = 16);
|
2001-08-18 09:09:26 -04:00
|
|
|
void CreateButtonsImageList(int size = 11);
|
2000-03-03 05:31:34 -05:00
|
|
|
|
1999-04-12 07:48:06 -04:00
|
|
|
void AddTestItemsToTree(size_t numChildren, size_t depth);
|
|
|
|
|
2004-05-20 13:23:15 -04:00
|
|
|
void DoSortChildren(const wxTreeItemId& item, bool reverse = false)
|
1999-07-30 18:45:55 -04:00
|
|
|
{ m_reverseSort = reverse; wxTreeCtrl::SortChildren(item); }
|
2003-05-01 11:38:55 -04:00
|
|
|
void DoEnsureVisible() { if (m_lastItem.IsOk()) EnsureVisible(m_lastItem); }
|
1998-12-18 10:37:19 -05:00
|
|
|
|
1999-07-30 18:45:55 -04:00
|
|
|
void DoToggleIcon(const wxTreeItemId& item);
|
|
|
|
|
2001-05-26 22:16:09 -04:00
|
|
|
void ShowMenu(wxTreeItemId id, const wxPoint& pt);
|
|
|
|
|
2001-08-18 09:09:26 -04:00
|
|
|
int ImageSize(void) const { return m_imageSize; }
|
|
|
|
|
2003-05-01 11:38:55 -04:00
|
|
|
void SetLastItem(wxTreeItemId id) { m_lastItem = id; }
|
|
|
|
|
2007-04-07 15:59:51 -04:00
|
|
|
void SetAlternateImages(bool show) { m_alternateImages = show; }
|
|
|
|
bool AlternateImages() const { return m_alternateImages; }
|
|
|
|
|
1998-12-18 10:37:19 -05:00
|
|
|
protected:
|
1999-04-12 07:48:06 -04:00
|
|
|
virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);
|
1998-12-18 10:37:19 -05:00
|
|
|
|
1999-07-23 19:41:45 -04:00
|
|
|
// is this the test item which we use in several event handlers?
|
|
|
|
bool IsTestItem(const wxTreeItemId& item)
|
|
|
|
{
|
|
|
|
// the test item is the first child folder
|
2002-12-29 02:48:21 -05:00
|
|
|
return GetItemParent(item) == GetRootItem() && !GetPrevSibling(item);
|
1999-07-23 19:41:45 -04:00
|
|
|
}
|
|
|
|
|
1998-10-28 16:32:29 -05:00
|
|
|
private:
|
1999-04-12 07:48:06 -04:00
|
|
|
void AddItemsRecursively(const wxTreeItemId& idParent,
|
|
|
|
size_t nChildren,
|
|
|
|
size_t depth,
|
|
|
|
size_t folder);
|
|
|
|
|
2006-09-24 11:24:19 -04:00
|
|
|
void LogEvent(const wxChar *name, const wxTreeEvent& event);
|
|
|
|
|
2001-08-18 09:09:26 -04:00
|
|
|
int m_imageSize; // current size of images
|
2000-02-15 18:57:33 -05:00
|
|
|
bool m_reverseSort; // flag for OnCompareItems
|
|
|
|
wxTreeItemId m_lastItem, // for OnEnsureVisible()
|
|
|
|
m_draggedItem; // item being dragged right now
|
2007-04-07 15:59:51 -04:00
|
|
|
bool m_alternateImages;
|
1999-04-12 07:48:06 -04:00
|
|
|
|
|
|
|
// NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS()
|
|
|
|
// if you want your overloaded OnCompareItems() to be called.
|
|
|
|
// OTOH, if you don't want it you may omit the next line - this will
|
|
|
|
// make default (alphabetical) sorting much faster under wxMSW.
|
|
|
|
DECLARE_DYNAMIC_CLASS(MyTreeCtrl)
|
|
|
|
DECLARE_EVENT_TABLE()
|
1998-05-22 15:57:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Define a new frame type
|
|
|
|
class MyFrame: public wxFrame
|
1998-10-25 12:04:49 -05:00
|
|
|
{
|
|
|
|
public:
|
1999-04-12 07:48:06 -04:00
|
|
|
// ctor and dtor
|
|
|
|
MyFrame(const wxString& title, int x, int y, int w, int h);
|
|
|
|
virtual ~MyFrame();
|
1998-10-26 12:11:33 -05:00
|
|
|
|
1999-04-12 07:48:06 -04:00
|
|
|
// menu callbacks
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
2007-04-10 19:48:51 -04:00
|
|
|
void OnClearLog(wxCommandEvent& event);
|
1998-10-26 12:11:33 -05:00
|
|
|
|
2002-03-16 10:10:43 -05:00
|
|
|
void OnTogButtons(wxCommandEvent& event)
|
|
|
|
{ TogStyle(event.GetId(), wxTR_HAS_BUTTONS); }
|
|
|
|
void OnTogTwist(wxCommandEvent& event)
|
|
|
|
{ TogStyle(event.GetId(), wxTR_TWIST_BUTTONS); }
|
|
|
|
void OnTogLines(wxCommandEvent& event)
|
|
|
|
{ TogStyle(event.GetId(), wxTR_NO_LINES); }
|
|
|
|
void OnTogEdit(wxCommandEvent& event)
|
|
|
|
{ TogStyle(event.GetId(), wxTR_EDIT_LABELS); }
|
|
|
|
void OnTogHideRoot(wxCommandEvent& event)
|
|
|
|
{ TogStyle(event.GetId(), wxTR_HIDE_ROOT); }
|
|
|
|
void OnTogRootLines(wxCommandEvent& event)
|
|
|
|
{ TogStyle(event.GetId(), wxTR_LINES_AT_ROOT); }
|
|
|
|
void OnTogBorder(wxCommandEvent& event)
|
|
|
|
{ TogStyle(event.GetId(), wxTR_ROW_LINES); }
|
|
|
|
void OnTogFullHighlight(wxCommandEvent& event)
|
|
|
|
{ TogStyle(event.GetId(), wxTR_FULL_ROW_HIGHLIGHT); }
|
|
|
|
|
|
|
|
void OnResetStyle(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{ CreateTreeWithDefStyle(); }
|
2001-08-18 09:09:26 -04:00
|
|
|
|
2002-02-20 12:41:39 -05:00
|
|
|
void OnSetFgColour(wxCommandEvent& event);
|
|
|
|
void OnSetBgColour(wxCommandEvent& event);
|
|
|
|
|
2006-11-04 06:26:51 -05:00
|
|
|
void OnHighlight(wxCommandEvent& event);
|
1999-04-12 07:48:06 -04:00
|
|
|
void OnDump(wxCommandEvent& event);
|
1999-07-30 18:45:55 -04:00
|
|
|
#ifndef NO_MULTIPLE_SELECTION
|
1999-06-13 11:24:01 -04:00
|
|
|
void OnDumpSelected(wxCommandEvent& event);
|
1999-07-30 18:45:55 -04:00
|
|
|
void OnSelect(wxCommandEvent& event);
|
|
|
|
void OnUnselect(wxCommandEvent& event);
|
2000-02-22 19:30:59 -05:00
|
|
|
void OnToggleSel(wxCommandEvent& event);
|
1999-07-30 18:45:55 -04:00
|
|
|
#endif // NO_MULTIPLE_SELECTION
|
2004-02-12 11:35:36 -05:00
|
|
|
void OnSelectRoot(wxCommandEvent& event);
|
1999-04-12 07:48:06 -04:00
|
|
|
void OnDelete(wxCommandEvent& event);
|
|
|
|
void OnDeleteChildren(wxCommandEvent& event);
|
|
|
|
void OnDeleteAll(wxCommandEvent& event);
|
2000-03-03 05:31:34 -05:00
|
|
|
|
1999-04-12 07:48:06 -04:00
|
|
|
void OnRecreate(wxCommandEvent& event);
|
2001-08-18 09:09:26 -04:00
|
|
|
void OnToggleButtons(wxCommandEvent& event);
|
2000-03-03 05:31:34 -05:00
|
|
|
void OnToggleImages(wxCommandEvent& event);
|
2007-04-07 15:59:51 -04:00
|
|
|
void OnToggleAlternateImages(wxCommandEvent& event);
|
2000-03-03 05:31:34 -05:00
|
|
|
void OnSetImageSize(wxCommandEvent& event);
|
1999-04-12 07:48:06 -04:00
|
|
|
void OnCollapseAndReset(wxCommandEvent& event);
|
1998-11-29 19:08:57 -05:00
|
|
|
|
2004-05-20 13:23:15 -04:00
|
|
|
void OnSetBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(true); }
|
|
|
|
void OnClearBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(false); }
|
1999-03-23 08:50:29 -05:00
|
|
|
|
1999-04-12 07:48:06 -04:00
|
|
|
void OnEnsureVisible(wxCommandEvent& event);
|
|
|
|
|
1999-10-02 15:43:56 -04:00
|
|
|
void OnCount(wxCommandEvent& event);
|
|
|
|
void OnCountRec(wxCommandEvent& event);
|
1999-12-29 05:29:26 -05:00
|
|
|
|
1999-04-12 07:48:06 -04:00
|
|
|
void OnRename(wxCommandEvent& event);
|
2003-09-24 11:01:08 -04:00
|
|
|
void OnSort(wxCommandEvent& WXUNUSED(event)) { DoSort(); }
|
2004-05-20 13:23:15 -04:00
|
|
|
void OnSortRev(wxCommandEvent& WXUNUSED(event)) { DoSort(true); }
|
1999-04-12 07:48:06 -04:00
|
|
|
|
|
|
|
void OnAddItem(wxCommandEvent& event);
|
1999-12-29 05:29:26 -05:00
|
|
|
void OnInsertItem(wxCommandEvent& event);
|
1999-07-30 18:45:55 -04:00
|
|
|
|
1999-05-03 19:11:53 -04:00
|
|
|
void OnIncIndent(wxCommandEvent& event);
|
|
|
|
void OnDecIndent(wxCommandEvent& event);
|
|
|
|
|
|
|
|
void OnIncSpacing(wxCommandEvent& event);
|
|
|
|
void OnDecSpacing(wxCommandEvent& event);
|
1998-12-18 10:37:19 -05:00
|
|
|
|
1999-07-30 18:45:55 -04:00
|
|
|
void OnToggleIcon(wxCommandEvent& event);
|
|
|
|
|
2003-09-21 15:40:35 -04:00
|
|
|
void OnIdle(wxIdleEvent& event);
|
2000-02-22 19:30:59 -05:00
|
|
|
void OnSize(wxSizeEvent& event);
|
|
|
|
|
1998-10-26 12:11:33 -05:00
|
|
|
private:
|
2002-03-16 10:10:43 -05:00
|
|
|
void TogStyle(int id, long flag);
|
2001-08-18 09:09:26 -04:00
|
|
|
|
2004-05-20 13:23:15 -04:00
|
|
|
void DoSort(bool reverse = false);
|
1998-12-18 10:37:19 -05:00
|
|
|
|
2002-03-16 10:10:43 -05:00
|
|
|
void Resize();
|
|
|
|
|
|
|
|
void CreateTreeWithDefStyle();
|
|
|
|
void CreateTree(long style);
|
2000-02-22 19:30:59 -05:00
|
|
|
|
2006-08-03 19:43:35 -04:00
|
|
|
wxPanel *m_panel;
|
1999-04-12 07:48:06 -04:00
|
|
|
MyTreeCtrl *m_treeCtrl;
|
2004-07-21 06:29:21 -04:00
|
|
|
#if wxUSE_LOG
|
2000-02-22 19:30:59 -05:00
|
|
|
wxTextCtrl *m_textCtrl;
|
2004-07-21 06:29:21 -04:00
|
|
|
#endif // wxUSE_LOG
|
1998-05-22 15:57:05 -04:00
|
|
|
|
2004-05-20 13:23:15 -04:00
|
|
|
void DoSetBold(bool bold = true);
|
1998-11-29 19:08:57 -05:00
|
|
|
|
1999-04-12 07:48:06 -04:00
|
|
|
DECLARE_EVENT_TABLE()
|
1998-10-28 16:32:29 -05:00
|
|
|
};
|
1998-05-22 15:57:05 -04:00
|
|
|
|
1998-10-28 16:32:29 -05:00
|
|
|
// menu and control ids
|
|
|
|
enum
|
|
|
|
{
|
2005-03-15 06:29:14 -05:00
|
|
|
TreeTest_Quit = wxID_EXIT,
|
|
|
|
TreeTest_About = wxID_ABOUT,
|
2007-04-10 19:48:51 -04:00
|
|
|
TreeTest_ClearLog = wxID_CLEAR,
|
2005-03-15 06:29:14 -05:00
|
|
|
TreeTest_TogButtons = wxID_HIGHEST,
|
2001-08-18 09:09:26 -04:00
|
|
|
TreeTest_TogTwist,
|
|
|
|
TreeTest_TogLines,
|
|
|
|
TreeTest_TogEdit,
|
|
|
|
TreeTest_TogHideRoot,
|
|
|
|
TreeTest_TogRootLines,
|
|
|
|
TreeTest_TogBorder,
|
2001-12-16 19:30:43 -05:00
|
|
|
TreeTest_TogFullHighlight,
|
2002-02-20 12:41:39 -05:00
|
|
|
TreeTest_SetFgColour,
|
|
|
|
TreeTest_SetBgColour,
|
2002-03-16 10:10:43 -05:00
|
|
|
TreeTest_ResetStyle,
|
2006-11-04 06:26:51 -05:00
|
|
|
TreeTest_Highlight,
|
1999-04-12 07:48:06 -04:00
|
|
|
TreeTest_Dump,
|
1999-07-30 18:45:55 -04:00
|
|
|
TreeTest_DumpSelected,
|
1999-10-02 15:43:56 -04:00
|
|
|
TreeTest_Count,
|
|
|
|
TreeTest_CountRec,
|
1999-04-12 07:48:06 -04:00
|
|
|
TreeTest_Sort,
|
|
|
|
TreeTest_SortRev,
|
2001-08-18 09:09:26 -04:00
|
|
|
TreeTest_SetBold,
|
|
|
|
TreeTest_ClearBold,
|
1999-04-12 07:48:06 -04:00
|
|
|
TreeTest_Rename,
|
|
|
|
TreeTest_Delete,
|
|
|
|
TreeTest_DeleteChildren,
|
|
|
|
TreeTest_DeleteAll,
|
|
|
|
TreeTest_Recreate,
|
2000-03-03 05:31:34 -05:00
|
|
|
TreeTest_ToggleImages,
|
2007-04-07 15:59:51 -04:00
|
|
|
TreeTest_ToggleAlternateImages,
|
2001-08-18 09:09:26 -04:00
|
|
|
TreeTest_ToggleButtons,
|
2000-03-03 05:31:34 -05:00
|
|
|
TreeTest_SetImageSize,
|
2000-02-22 19:30:59 -05:00
|
|
|
TreeTest_ToggleSel,
|
1999-04-12 07:48:06 -04:00
|
|
|
TreeTest_CollapseAndReset,
|
|
|
|
TreeTest_EnsureVisible,
|
|
|
|
TreeTest_AddItem,
|
1999-12-29 05:29:26 -05:00
|
|
|
TreeTest_InsertItem,
|
1999-05-03 19:11:53 -04:00
|
|
|
TreeTest_IncIndent,
|
|
|
|
TreeTest_DecIndent,
|
|
|
|
TreeTest_IncSpacing,
|
|
|
|
TreeTest_DecSpacing,
|
1999-07-30 18:45:55 -04:00
|
|
|
TreeTest_ToggleIcon,
|
|
|
|
TreeTest_Select,
|
|
|
|
TreeTest_Unselect,
|
2004-02-12 11:35:36 -05:00
|
|
|
TreeTest_SelectRoot,
|
1999-07-30 18:45:55 -04:00
|
|
|
TreeTest_Ctrl = 1000
|
1999-03-23 08:50:29 -05:00
|
|
|
};
|