1 #ifndef _WX_TREECTRL_H_BASE_
2 #define _WX_TREECTRL_H_BASE_
4 // ----------------------------------------------------------------------------
6 // ----------------------------------------------------------------------------
8 #include "wx/control.h"
11 // ----------------------------------------------------------------------------
13 // ----------------------------------------------------------------------------
15 // enum for different images associated with a treectrl item
18 wxTreeItemIcon_Normal
, // not selected, not expanded
19 wxTreeItemIcon_Selected
, // selected, not expanded
20 wxTreeItemIcon_Expanded
, // not selected, expanded
21 wxTreeItemIcon_SelectedExpanded
, // selected, expanded
26 // values for the `flags' parameter of wxTreeCtrl::HitTest() which determine
27 // where exactly the specified point is situated:
29 static const int wxTREE_HITTEST_ABOVE
= 0x0001;
30 static const int wxTREE_HITTEST_BELOW
= 0x0002;
31 static const int wxTREE_HITTEST_NOWHERE
= 0x0004;
32 // on the button associated with an item.
33 static const int wxTREE_HITTEST_ONITEMBUTTON
= 0x0008;
34 // on the bitmap associated with an item.
35 static const int wxTREE_HITTEST_ONITEMICON
= 0x0010;
36 // on the indent associated with an item.
37 static const int wxTREE_HITTEST_ONITEMINDENT
= 0x0020;
38 // on the label (string) associated with an item.
39 static const int wxTREE_HITTEST_ONITEMLABEL
= 0x0040;
40 // on the right of the label associated with an item.
41 static const int wxTREE_HITTEST_ONITEMRIGHT
= 0x0080;
42 // on the label (string) associated with an item.
43 static const int wxTREE_HITTEST_ONITEMSTATEICON
= 0x0100;
44 // on the left of the wxTreeCtrl.
45 static const int wxTREE_HITTEST_TOLEFT
= 0x0200;
46 // on the right of the wxTreeCtrl.
47 static const int wxTREE_HITTEST_TORIGHT
= 0x0400;
48 // on the upper part (first half) of the item.
49 static const int wxTREE_HITTEST_ONITEMUPPERPART
= 0x0800;
50 // on the lower part (second half) of the item.
51 static const int wxTREE_HITTEST_ONITEMLOWERPART
= 0x1000;
53 // anywhere on the item
54 static const int wxTREE_HITTEST_ONITEM
= wxTREE_HITTEST_ONITEMICON
|
55 wxTREE_HITTEST_ONITEMLABEL
;
57 // tree ctrl default name
58 WXDLLEXPORT_DATA(extern const char*) wxTreeCtrlNameStr
;
60 // ----------------------------------------------------------------------------
61 // wxTreeItemAttr: a structure containing the visual attributes of an item
62 // ----------------------------------------------------------------------------
64 class WXDLLEXPORT wxTreeItemAttr
69 wxTreeItemAttr(const wxColour
& colText
,
70 const wxColour
& colBack
,
72 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
75 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
76 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
77 void SetFont(const wxFont
& font
) { m_font
= font
; }
80 bool HasTextColour() const { return m_colText
.Ok(); }
81 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
82 bool HasFont() const { return m_font
.Ok(); }
84 const wxColour
& GetTextColour() const { return m_colText
; }
85 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
86 const wxFont
& GetFont() const { return m_font
; }
94 // ----------------------------------------------------------------------------
95 // include the platform-dependent wxTreeCtrl class
96 // ----------------------------------------------------------------------------
98 #if defined(__WXMSW__)
100 #include "wx/generic/treectrl.h"
102 #include "wx/msw/treectrl.h"
104 #elif defined(__WXMOTIF__)
105 #include "wx/generic/treectrl.h"
106 #elif defined(__WXGTK__)
107 #include "wx/generic/treectrl.h"
108 #elif defined(__WXQT__)
109 #include "wx/qt/treectrl.h"
110 #elif defined(__WXMAC__)
111 #include "wx/generic/treectrl.h"
112 #elif defined(__WXPM__)
113 #include "wx/generic/treectrl.h"
114 #elif defined(__WXSTUBS__)
115 #include "wx/generic/treectrl.h"
118 // ----------------------------------------------------------------------------
119 // wxTreeEvent is a special class for all events associated with tree controls
121 // NB: note that not all accessors make sense for all events, see the event
122 // descriptions below
123 // ----------------------------------------------------------------------------
125 class WXDLLEXPORT wxTreeEvent
: public wxNotifyEvent
127 friend class WXDLLEXPORT wxTreeCtrl
;
130 wxTreeEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
133 // get the item on which the operation was performed or the newly
134 // selected item for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events
135 wxTreeItemId
GetItem() const { return m_item
; }
137 // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously
139 wxTreeItemId
GetOldItem() const { return m_itemOld
; }
141 // the point where the mouse was when the drag operation started (for
142 // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only)
143 wxPoint
GetPoint() const { return m_pointDrag
; }
145 // keyboard code (for wxEVT_COMMAND_TREE_KEY_DOWN only)
146 int GetCode() const { return m_code
; }
148 // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
149 const wxString
& GetLabel() const { return m_label
; }
152 // TODO we could save some space by using union here
159 DECLARE_DYNAMIC_CLASS(wxTreeEvent
)
162 typedef void (wxEvtHandler::*wxTreeEventFunction
)(wxTreeEvent
&);
164 // ----------------------------------------------------------------------------
165 // macros for handling tree control events
166 // ----------------------------------------------------------------------------
168 // GetItem() returns the item being dragged, GetPoint() the mouse coords
169 #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
170 #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
172 // GetItem() returns the itme whose label is being edited, GetLabel() returns
173 // the current item label for BEGIN and the would be new one for END.
175 // Vetoing BEGIN event means that label editing won't happen at all,
176 // vetoing END means that the new value is discarded and the old one kept
177 #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
178 #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
180 // provide/update information about GetItem() item
181 #define EVT_TREE_GET_INFO(id, fn) { wxEVT_COMMAND_TREE_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
182 #define EVT_TREE_SET_INFO(id, fn) { wxEVT_COMMAND_TREE_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
184 // GetItem() is the item being expanded/collapsed, the "ING" versions can use
185 #define EVT_TREE_ITEM_EXPANDED(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
186 #define EVT_TREE_ITEM_EXPANDING(id, fn) { wxEVT_COMMAND_TREE_ITEM_EXPANDING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
187 #define EVT_TREE_ITEM_COLLAPSED(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
188 #define EVT_TREE_ITEM_COLLAPSING(id, fn) { wxEVT_COMMAND_TREE_ITEM_COLLAPSING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
190 // GetOldItem() is the item which had the selection previously, GetItem() is
191 // the item which acquires selection
192 #define EVT_TREE_SEL_CHANGED(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
193 #define EVT_TREE_SEL_CHANGING(id, fn) { wxEVT_COMMAND_TREE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
195 // GetCode() returns the key code
196 // NB: this is the only message for which GetItem() is invalid (you may get the
197 // item from GetSelection())
198 #define EVT_TREE_KEY_DOWN(id, fn) { wxEVT_COMMAND_TREE_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
200 // GetItem() returns the item being deleted, the associated data (if any) will
201 // be deleted just after the return of this event handler (if any)
202 #define EVT_TREE_DELETE_ITEM(id, fn) { wxEVT_COMMAND_TREE_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL },
204 // GetItem() returns the item that was activated (double click, enter, space)
205 #define EVT_TREE_ITEM_ACTIVATED(id, fn) { wxEVT_COMMAND_TREE_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
207 // GetItem() returns the item that was clicked on
208 #define EVT_TREE_ITEM_RIGHT_CLICK(id, fn) { wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
209 #define EVT_TREE_ITEM_MIDDLE_CLICK(id, fn) { wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, NULL },
212 // _WX_TREECTRL_H_BASE_