1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/mac/classic/treectrl.h
3 // Purpose: wxTreeCtrl class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_TREECTRL_H_
13 #define _WX_TREECTRL_H_
15 #include "wx/control.h"
17 #include "wx/imaglist.h"
19 #define wxTREE_MASK_HANDLE 0x0001
20 #define wxTREE_MASK_STATE 0x0002
21 #define wxTREE_MASK_TEXT 0x0004
22 #define wxTREE_MASK_IMAGE 0x0008
23 #define wxTREE_MASK_SELECTED_IMAGE 0x0010
24 #define wxTREE_MASK_CHILDREN 0x0020
25 #define wxTREE_MASK_DATA 0x0040
27 #define wxTREE_STATE_BOLD 0x0001
28 #define wxTREE_STATE_DROPHILITED 0x0002
29 #define wxTREE_STATE_EXPANDED 0x0004
30 #define wxTREE_STATE_EXPANDEDONCE 0x0008
31 #define wxTREE_STATE_FOCUSED 0x0010
32 #define wxTREE_STATE_SELECTED 0x0020
33 #define wxTREE_STATE_CUT 0x0040
35 #define wxTREE_HITTEST_ABOVE 0x0001 // Above the client area.
36 #define wxTREE_HITTEST_BELOW 0x0002 // Below the client area.
37 #define wxTREE_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
38 #define wxTREE_HITTEST_ONITEMBUTTON 0x0010 // On the button associated with an item.
39 #define wxTREE_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
40 #define wxTREE_HITTEST_ONITEMINDENT 0x0040 // In the indentation associated with an item.
41 #define wxTREE_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
42 #define wxTREE_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
43 #define wxTREE_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
44 #define wxTREE_HITTEST_TOLEFT 0x0400 // To the right of the client area.
45 #define wxTREE_HITTEST_TORIGHT 0x0800 // To the left of the client area.
47 #define wxTREE_HITTEST_ONITEM (wxTREE_HITTEST_ONITEMICON | wxTREE_HITTEST_ONITEMLABEL | wxTREE_HITTEST_ONITEMSTATEICON)
49 // Flags for GetNextItem
51 wxTREE_NEXT_CARET
, // Retrieves the currently selected item.
52 wxTREE_NEXT_CHILD
, // Retrieves the first child item. The hItem parameter must be NULL.
53 wxTREE_NEXT_DROPHILITE
, // Retrieves the item that is the target of a drag-and-drop operation.
54 wxTREE_NEXT_FIRSTVISIBLE
, // Retrieves the first visible item.
55 wxTREE_NEXT_NEXT
, // Retrieves the next sibling item.
56 wxTREE_NEXT_NEXTVISIBLE
, // Retrieves the next visible item that follows the specified item.
57 wxTREE_NEXT_PARENT
, // Retrieves the parent of the specified item.
58 wxTREE_NEXT_PREVIOUS
, // Retrieves the previous sibling item.
59 wxTREE_NEXT_PREVIOUSVISIBLE
, // Retrieves the first visible item that precedes the specified item.
60 wxTREE_NEXT_ROOT
// Retrieves the first child item of the root item of which the specified item is a part.
63 // Flags for InsertItem
65 wxTREE_INSERT_LAST
= -1,
66 wxTREE_INSERT_FIRST
= -2,
67 wxTREE_INSERT_SORT
= -3
70 class WXDLLEXPORT wxTreeItem
: public wxObject
72 DECLARE_DYNAMIC_CLASS(wxTreeItem
)
87 inline long GetMask() const { return m_mask
; }
88 inline long GetItemId() const { return m_itemId
; }
89 inline long GetState() const { return m_state
; }
90 inline long GetStateMask() const { return m_stateMask
; }
91 inline wxString
GetText() const { return m_text
; }
92 inline int GetImage() const { return m_image
; }
93 inline int GetSelectedImage() const { return m_selectedImage
; }
94 inline int GetChildren() const { return m_children
; }
95 inline long GetData() const { return m_data
; }
97 inline void SetMask(long mask
) { m_mask
= mask
; }
98 inline void SetItemId(long id
) { m_itemId
= m_itemId
= id
; }
99 inline void SetState(long state
) { m_state
= state
; }
100 inline void SetStateMask(long stateMask
) { m_stateMask
= stateMask
; }
101 inline void GetText(const wxString
& text
) { m_text
= text
; }
102 inline void SetImage(int image
) { m_image
= image
; }
103 inline void GetSelectedImage(int selImage
) { m_selectedImage
= selImage
; }
104 inline void SetChildren(int children
) { m_children
= children
; }
105 inline void SetData(long data
) { m_data
= data
; }
108 class WXDLLEXPORT wxTreeCtrl
: public wxControl
119 inline wxTreeCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
120 const wxPoint
& pos
= wxDefaultPosition
,
121 const wxSize
& size
= wxDefaultSize
,
122 long style
= wxTR_HAS_BUTTONS
|wxTR_LINES_AT_ROOT
,
123 const wxValidator
& validator
= wxDefaultValidator
,
124 const wxString
& name
= "wxTreeCtrl")
126 Create(parent
, id
, pos
, size
, style
, validator
, name
);
130 bool Create(wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
131 const wxPoint
& pos
= wxDefaultPosition
,
132 const wxSize
& size
= wxDefaultSize
,
133 long style
= wxTR_HAS_BUTTONS
|wxTR_LINES_AT_ROOT
,
134 const wxValidator
& validator
= wxDefaultValidator
,
135 const wxString
& name
= "wxTreeCtrl");
140 size_t GetCount() const;
143 int GetIndent() const;
144 void SetIndent(int indent
);
146 wxImageList
*GetImageList(int which
= wxIMAGE_LIST_NORMAL
) const;
147 void SetImageList(wxImageList
*imageList
, int which
= wxIMAGE_LIST_NORMAL
);
149 // navigation inside the tree
150 long GetNextItem(long item
, int code
) const;
151 bool ItemHasChildren(long item
) const;
152 long GetChild(long item
) const;
153 long GetItemParent(long item
) const;
154 long GetFirstVisibleItem() const;
155 long GetNextVisibleItem(long item
) const;
156 long GetSelection() const;
157 long GetRootItem() const;
159 // generic function for (g|s)etting item attributes
160 bool GetItem(wxTreeItem
& info
) const;
161 bool SetItem(wxTreeItem
& info
);
163 int GetItemState(long item
, long stateMask
) const;
164 bool SetItemState(long item
, long state
, long stateMask
);
166 bool SetItemImage(long item
, int image
, int selImage
);
168 wxString
GetItemText(long item
) const;
169 void SetItemText(long item
, const wxString
& str
);
170 // custom data associated with the item
171 long GetItemData(long item
) const;
172 bool SetItemData(long item
, long data
);
173 // convenience function
174 bool IsItemExpanded(long item
)
176 return (GetItemState(item
, wxTREE_STATE_EXPANDED
) &
177 wxTREE_STATE_EXPANDED
) != 0;
181 bool GetItemRect(long item
, wxRect
& rect
, bool textOnly
= false) const;
183 wxTextCtrl
* GetEditControl() const;
187 // adding/deleting items
188 bool DeleteItem(long item
);
189 long InsertItem(long parent
, wxTreeItem
& info
,
190 long insertAfter
= wxTREE_INSERT_LAST
);
191 // If image > -1 and selImage == -1, the same image is used for
192 // both selected and unselected items.
193 long InsertItem(long parent
, const wxString
& label
,
194 int image
= -1, int selImage
= -1,
195 long insertAfter
= wxTREE_INSERT_LAST
);
197 // changing item state
198 bool ExpandItem(long item
) { return ExpandItem(item
, wxTREE_EXPAND_EXPAND
); }
199 bool CollapseItem(long item
) { return ExpandItem(item
, wxTREE_EXPAND_COLLAPSE
); }
200 bool ToggleItem(long item
) { return ExpandItem(item
, wxTREE_EXPAND_TOGGLE
); }
201 // common interface for {Expand|Collapse|Toggle}Item
202 bool ExpandItem(long item
, int action
);
205 bool SelectItem(long item
);
206 bool ScrollTo(long item
);
207 bool DeleteAllItems();
209 // Edit the label (tree must have the focus)
210 wxTextCtrl
* EditLabel(long item
, wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
212 // End label editing, optionally cancelling the edit
213 bool EndEditLabel(bool cancel
);
215 long HitTest(const wxPoint
& point
, int& flags
);
216 // wxImageList *CreateDragImage(long item);
217 bool SortChildren(long item
);
218 bool EnsureVisible(long item
);
220 void Command(wxCommandEvent
& event
) { ProcessCommand(event
); };
223 wxTextCtrl
* m_textCtrl
;
224 wxImageList
* m_imageListNormal
;
225 wxImageList
* m_imageListState
;
227 DECLARE_DYNAMIC_CLASS(wxTreeCtrl
)
231 wxEVT_COMMAND_TREE_BEGIN_DRAG,
232 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
233 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
234 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
235 wxEVT_COMMAND_TREE_DELETE_ITEM,
236 wxEVT_COMMAND_TREE_GET_INFO,
237 wxEVT_COMMAND_TREE_SET_INFO,
238 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
239 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
240 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
241 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
242 wxEVT_COMMAND_TREE_SEL_CHANGED,
243 wxEVT_COMMAND_TREE_SEL_CHANGING,
244 wxEVT_COMMAND_TREE_KEY_DOWN
247 class WXDLLEXPORT wxTreeEvent
: public wxCommandEvent
249 DECLARE_DYNAMIC_CLASS(wxTreeEvent
)
252 wxTreeEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
259 inline long GetOldItem() const { return m_oldItem
; }
260 inline wxTreeItem
& GetItem() const { return (wxTreeItem
&) m_item
; }
261 inline wxPoint
GetPoint() const { return m_pointDrag
; }
262 inline int GetCode() const { return m_code
; }
265 typedef void (wxEvtHandler::*wxTreeEventFunction
)(wxTreeEvent
&);
267 #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
268 #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
269 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
270 #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
271 #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
272 #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
273 #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
274 #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
275 #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
276 #define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
277 #define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
278 #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
279 #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
280 #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },