1998-05-22 15:57:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: treetest.h
|
|
|
|
// Purpose: wxTreeCtrl sample
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart and Markus Holzem
|
1998-10-28 16:32:29 -05:00
|
|
|
// Licence: wxWindows license
|
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:
|
1999-04-12 07:48:06 -04:00
|
|
|
bool OnInit();
|
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);
|
|
|
|
const char *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);
|
|
|
|
void OnBeginLabelEdit(wxTreeEvent& event);
|
|
|
|
void OnEndLabelEdit(wxTreeEvent& event);
|
|
|
|
void OnDeleteItem(wxTreeEvent& event);
|
|
|
|
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);
|
|
|
|
void OnRMouseDClick(wxMouseEvent& event);
|
|
|
|
|
|
|
|
void GetItemsRecursively(const wxTreeItemId& idParent, long cookie);
|
|
|
|
|
|
|
|
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); }
|
1999-04-12 07:48:06 -04:00
|
|
|
void DoEnsureVisible() { EnsureVisible(m_lastItem); }
|
1998-12-18 10:37:19 -05:00
|
|
|
|
1999-07-30 18:45:55 -04:00
|
|
|
void DoToggleIcon(const wxTreeItemId& item);
|
|
|
|
|
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
|
|
|
|
return GetParent(item) == GetRootItem() && !GetPrevSibling(item);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
wxImageList *m_imageListNormal;
|
|
|
|
bool m_reverseSort; // flag for OnCompareItems
|
|
|
|
wxTreeItemId m_lastItem; // for OnEnsureVisible()
|
|
|
|
|
|
|
|
// 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
|
|
|
|
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);
|
|
|
|
#endif // NO_MULTIPLE_SELECTION
|
1999-04-12 07:48:06 -04:00
|
|
|
void OnDelete(wxCommandEvent& event);
|
|
|
|
void OnDeleteChildren(wxCommandEvent& event);
|
|
|
|
void OnDeleteAll(wxCommandEvent& event);
|
|
|
|
void OnRecreate(wxCommandEvent& event);
|
|
|
|
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-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-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);
|
|
|
|
|
1998-10-26 12:11:33 -05:00
|
|
|
private:
|
1999-04-12 07:48:06 -04:00
|
|
|
void DoSort(bool reverse = FALSE);
|
1998-12-18 10:37:19 -05:00
|
|
|
|
1999-04-12 07:48:06 -04:00
|
|
|
MyTreeCtrl *m_treeCtrl;
|
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,
|
|
|
|
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,
|
|
|
|
TreeTest_Bold,
|
|
|
|
TreeTest_UnBold,
|
|
|
|
TreeTest_Rename,
|
|
|
|
TreeTest_Delete,
|
|
|
|
TreeTest_DeleteChildren,
|
|
|
|
TreeTest_DeleteAll,
|
|
|
|
TreeTest_Recreate,
|
|
|
|
TreeTest_CollapseAndReset,
|
|
|
|
TreeTest_EnsureVisible,
|
|
|
|
TreeTest_AddItem,
|
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
|
|
|
};
|