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:
|
2001-08-18 09:09:26 -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
|
|
|
};
|
|
|
|
|
|
|
|
MyTreeCtrl() { }
|
|
|
|
MyTreeCtrl(wxWindow *parent, const wxWindowID id,
|
|
|
|
const wxPoint& pos, const wxSize& size,
|
|
|
|
long style);
|
|
|
|
virtual ~MyTreeCtrl();
|
|
|
|
|
|
|
|
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);
|
1999-04-12 07:48:06 -04:00
|
|
|
void OnGetInfo(wxTreeEvent& event);
|
2001-05-26 22:16:09 -04:00
|
|
|
void OnTreeRMouseClick(wxTreeEvent& event);
|
|
|
|
void OnItemRightClick(wxTreeEvent& event);
|
1999-04-12 07:48:06 -04:00
|
|
|
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);
|
|
|
|
void OnRMouseDClick(wxMouseEvent& event);
|
|
|
|
|
|
|
|
void GetItemsRecursively(const wxTreeItemId& idParent, long cookie);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
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);
|
|
|
|
|
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
|
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);
|
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);
|
|
|
|
|
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
|
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);
|
|
|
|
void OnSetImageSize(wxCommandEvent& event);
|
1999-04-12 07:48:06 -04:00
|
|
|
void OnCollapseAndReset(wxCommandEvent& event);
|
1998-11-29 19:08:57 -05:00
|
|
|
|
1999-04-12 07:48:06 -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);
|
|
|
|
void OnSort(wxCommandEvent& event) { DoSort(); }
|
|
|
|
void OnSortRev(wxCommandEvent& event) { DoSort(TRUE); }
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
|
1999-04-12 07:48:06 -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
|
|
|
|
1999-04-12 07:48:06 -04:00
|
|
|
MyTreeCtrl *m_treeCtrl;
|
2000-02-22 19:30:59 -05:00
|
|
|
wxTextCtrl *m_textCtrl;
|
1998-05-22 15:57:05 -04:00
|
|
|
|
1999-04-12 07:48:06 -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
|
|
|
|
{
|
1999-04-12 07:48:06 -04:00
|
|
|
TreeTest_Quit,
|
|
|
|
TreeTest_About,
|
2001-08-18 09:09:26 -04:00
|
|
|
TreeTest_TogButtons,
|
|
|
|
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,
|
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,
|
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,
|
|
|
|
TreeTest_Ctrl = 1000
|
1999-03-23 08:50:29 -05:00
|
|
|
};
|