1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTreeCtrl class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "treectrl.h"
19 #include "wx/control.h"
21 #include "wx/imaglist.h"
23 // WXDLLEXPORT_DATA(extern const char*) wxTreeNameStr;
25 #define wxTREE_MASK_HANDLE 0x0001
26 #define wxTREE_MASK_STATE 0x0002
27 #define wxTREE_MASK_TEXT 0x0004
28 #define wxTREE_MASK_IMAGE 0x0008
29 #define wxTREE_MASK_SELECTED_IMAGE 0x0010
30 #define wxTREE_MASK_CHILDREN 0x0020
31 #define wxTREE_MASK_DATA 0x0040
33 #define wxTREE_STATE_BOLD 0x0001
34 #define wxTREE_STATE_DROPHILITED 0x0002
35 #define wxTREE_STATE_EXPANDED 0x0004
36 #define wxTREE_STATE_EXPANDEDONCE 0x0008
37 #define wxTREE_STATE_FOCUSED 0x0010
38 #define wxTREE_STATE_SELECTED 0x0020
39 #define wxTREE_STATE_CUT 0x0040
41 #define wxTREE_HITTEST_ABOVE 0x0001 // Above the client area.
42 #define wxTREE_HITTEST_BELOW 0x0002 // Below the client area.
43 #define wxTREE_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
44 #define wxTREE_HITTEST_ONITEMBUTTON 0x0010 // On the button associated with an item.
45 #define wxTREE_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
46 #define wxTREE_HITTEST_ONITEMINDENT 0x0040 // In the indentation associated with an item.
47 #define wxTREE_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
48 #define wxTREE_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
49 #define wxTREE_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
50 #define wxTREE_HITTEST_TOLEFT 0x0400 // To the right of the client area.
51 #define wxTREE_HITTEST_TORIGHT 0x0800 // To the left of the client area.
53 #define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON)
55 // Flags for GetNextItem
57 wxTREE_NEXT_CARET
, // Retrieves the currently selected item.
58 wxTREE_NEXT_CHILD
, // Retrieves the first child item. The hItem parameter must be NULL.
59 wxTREE_NEXT_DROPHILITE
, // Retrieves the item that is the target of a drag-and-drop operation.
60 wxTREE_NEXT_FIRSTVISIBLE
, // Retrieves the first visible item.
61 wxTREE_NEXT_NEXT
, // Retrieves the next sibling item.
62 wxTREE_NEXT_NEXTVISIBLE
, // Retrieves the next visible item that follows the specified item.
63 wxTREE_NEXT_PARENT
, // Retrieves the parent of the specified item.
64 wxTREE_NEXT_PREVIOUS
, // Retrieves the previous sibling item.
65 wxTREE_NEXT_PREVIOUSVISIBLE
, // Retrieves the first visible item that precedes the specified item.
66 wxTREE_NEXT_ROOT
// Retrieves the first child item of the root item of which the specified item is a part.
69 // Flags for ExpandItem
72 wxTREE_EXPAND_COLLAPSE
,
73 wxTREE_EXPAND_COLLAPSE_RESET
,
77 // Flags for InsertItem
79 wxTREE_INSERT_LAST
= -1,
80 wxTREE_INSERT_FIRST
= -2,
81 wxTREE_INSERT_SORT
= -3
84 class WXDLLEXPORT wxTreeItem
: public wxObject
86 DECLARE_DYNAMIC_CLASS(wxTreeItem
)
101 class WXDLLEXPORT wxTreeCtrl
: public wxControl
103 DECLARE_DYNAMIC_CLASS(wxTreeCtrl
)
111 inline wxTreeCtrl(wxWindow
*parent
, const wxWindowID id
= -1,
112 const wxPoint
& pos
= wxDefaultPosition
,
113 const wxSize
& size
= wxDefaultSize
,
114 const long style
= wxTR_HAS_BUTTONS
,
115 const wxValidator
& validator
= wxDefaultValidator
,
116 const wxString
& name
= "wxTreeCtrl")
118 Create(parent
, id
, pos
, size
, style
, validator
, name
);
122 bool Create(wxWindow
*parent
, const wxWindowID id
= -1,
123 const wxPoint
& pos
= wxDefaultPosition
,
124 const wxSize
& size
= wxDefaultSize
,
125 const long style
= wxTR_HAS_BUTTONS
,
126 const wxValidator
& validator
= wxDefaultValidator
,
127 const wxString
& name
= "wxTreeCtrl");
130 int GetCount(void) const ;
131 int GetIndent(void) const ;
132 void SetIndent(int indent
) ;
133 wxImageList
*GetImageList(const int which
= wxIMAGE_LIST_NORMAL
) const ;
134 void SetImageList(wxImageList
*imageList
, const int which
= wxIMAGE_LIST_NORMAL
) ;
135 long GetNextItem(const long item
, int code
) const ;
136 bool ItemHasChildren(const long item
) const ;
137 long GetChild(const long item
) const ;
138 long GetParent(const long item
) const ;
139 long GetFirstVisibleItem(void) const ;
140 long GetNextVisibleItem(const long item
) const ;
141 long GetSelection(void) const ;
142 long GetRootItem(void) const ;
143 bool GetItem(wxTreeItem
& info
) const ;
144 bool SetItem(wxTreeItem
& info
) ;
145 int GetItemState(const long item
, const long stateMask
) const ;
146 bool SetItemState(const long item
, const long state
, const long stateMask
) ;
147 bool SetItemImage(const long item
, const int image
, const int selImage
) ;
148 wxString
GetItemText(const long item
) const ;
149 void SetItemText(const long item
, const wxString
& str
) ;
150 long GetItemData(const long item
) const ;
151 bool SetItemData(const long item
, long data
) ;
152 bool GetItemRect(const long item
, wxRectangle
& rect
, bool textOnly
= FALSE
) const;
153 wxTextCtrl
& GetEditControl(void) const;
156 bool DeleteItem(const long item
);
157 bool ExpandItem(const long item
, const int action
);
158 long InsertItem(const long parent
, wxTreeItem
& info
, const long insertAfter
= wxTREE_INSERT_LAST
);
160 // If image > -1 and selImage == -1, the same image is used for
161 // both selected and unselected items.
162 long InsertItem(const long parent
, const wxString
& label
, const int image
= -1, const int selImage
= -1, const long insertAfter
= wxTREE_INSERT_LAST
);
163 bool SelectItem(const long item
);
164 bool ScrollTo(const long item
);
165 bool DeleteAllItems(void) ;
166 wxTextCtrl
& Edit(const long item
) ;
167 long HitTest(const wxPoint
& point
, int& flags
);
168 // wxImageList *CreateDragImage(const long item) ;
169 bool SortChildren(const long item
) ;
170 bool EnsureVisible(const long item
) ;
172 void Command(wxCommandEvent
& event
) { ProcessCommand(event
); };
175 bool MSWCommand(const WXUINT param
, const WXWORD id
);
176 bool MSWNotify(const WXWPARAM wParam
, const WXLPARAM lParam
);
179 wxTextCtrl m_textCtrl
;
180 wxImageList
*m_imageListNormal
;
181 wxImageList
*m_imageListState
;
185 wxEVT_COMMAND_TREE_BEGIN_DRAG,
186 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
187 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
188 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
189 wxEVT_COMMAND_TREE_DELETE_ITEM,
190 wxEVT_COMMAND_TREE_GET_INFO,
191 wxEVT_COMMAND_TREE_SET_INFO,
192 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
193 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
194 wxEVT_COMMAND_TREE_SEL_CHANGED,
195 wxEVT_COMMAND_TREE_SEL_CHANGING,
196 wxEVT_COMMAND_TREE_KEY_DOWN
199 class WXDLLEXPORT wxTreeEvent
: public wxCommandEvent
201 DECLARE_DYNAMIC_CLASS(wxTreeEvent
)
204 wxTreeEvent(WXTYPE commandType
= 0, int id
= 0);
212 typedef void (wxEvtHandler::*wxTreeEventFunction
)(wxTreeEvent
&);
214 #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
215 #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
216 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
217 #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
218 #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
219 #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
220 #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
221 #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
222 #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
223 #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
224 #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
225 #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },