]>
Commit | Line | Data |
---|---|---|
f135ff73 | 1 | ///////////////////////////////////////////////////////////////////////////// |
cb59313c | 2 | // Name: wx/generic/treectlg.h |
f135ff73 VZ |
3 | // Purpose: wxTreeCtrl class |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1997,1998 Robert Roebling | |
65571936 | 9 | // Licence: wxWindows licence |
f135ff73 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _GENERIC_TREECTRL_H_ | |
13 | #define _GENERIC_TREECTRL_H_ | |
c801d85f | 14 | |
1e6feb95 VZ |
15 | #if wxUSE_TREECTRL |
16 | ||
c801d85f | 17 | #include "wx/scrolwin.h" |
ac57418f | 18 | #include "wx/pen.h" |
91b8de8d | 19 | |
f135ff73 VZ |
20 | // ----------------------------------------------------------------------------- |
21 | // forward declaration | |
22 | // ----------------------------------------------------------------------------- | |
c801d85f | 23 | |
e179bd65 | 24 | class WXDLLEXPORT wxGenericTreeItem; |
c801d85f | 25 | |
e179bd65 RR |
26 | class WXDLLEXPORT wxTreeItemData; |
27 | ||
28 | class WXDLLEXPORT wxTreeRenameTimer; | |
cb59313c | 29 | class WXDLLEXPORT wxTreeFindTimer; |
e179bd65 | 30 | class WXDLLEXPORT wxTreeTextCtrl; |
fbb12260 | 31 | class WXDLLEXPORT wxTextCtrl; |
74bedbeb | 32 | |
f135ff73 | 33 | // ----------------------------------------------------------------------------- |
484523cf | 34 | // wxGenericTreeCtrl - the tree control |
f135ff73 | 35 | // ----------------------------------------------------------------------------- |
c801d85f | 36 | |
8cee4a30 VZ |
37 | class WXDLLEXPORT wxGenericTreeCtrl : public wxTreeCtrlBase, |
38 | public wxScrollHelper | |
c801d85f | 39 | { |
a32dd690 | 40 | public: |
f135ff73 VZ |
41 | // creation |
42 | // -------- | |
8cee4a30 VZ |
43 | |
44 | wxGenericTreeCtrl() : wxTreeCtrlBase(), wxScrollHelper(this) { Init(); } | |
f135ff73 | 45 | |
ca65c044 | 46 | wxGenericTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, |
f135ff73 VZ |
47 | const wxPoint& pos = wxDefaultPosition, |
48 | const wxSize& size = wxDefaultSize, | |
618a5e38 | 49 | long style = wxTR_DEFAULT_STYLE, |
bfc6fde4 | 50 | const wxValidator &validator = wxDefaultValidator, |
62448488 | 51 | const wxString& name = wxTreeCtrlNameStr) |
8cee4a30 VZ |
52 | : wxTreeCtrlBase(), |
53 | wxScrollHelper(this) | |
f135ff73 | 54 | { |
57591e0e | 55 | Init(); |
4f22cf8d | 56 | Create(parent, id, pos, size, style, validator, name); |
f135ff73 VZ |
57 | } |
58 | ||
484523cf | 59 | virtual ~wxGenericTreeCtrl(); |
f135ff73 | 60 | |
ca65c044 | 61 | bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, |
f135ff73 VZ |
62 | const wxPoint& pos = wxDefaultPosition, |
63 | const wxSize& size = wxDefaultSize, | |
618a5e38 | 64 | long style = wxTR_DEFAULT_STYLE, |
bfc6fde4 | 65 | const wxValidator &validator = wxDefaultValidator, |
62448488 | 66 | const wxString& name = wxTreeCtrlNameStr); |
f135ff73 | 67 | |
f135ff73 | 68 | |
8cee4a30 VZ |
69 | // implement base class pure virtuals |
70 | // ---------------------------------- | |
f135ff73 | 71 | |
027d45e8 | 72 | virtual unsigned int GetCount() const; |
e3d64157 | 73 | |
8cee4a30 VZ |
74 | virtual unsigned int GetIndent() const { return m_indent; } |
75 | virtual void SetIndent(unsigned int indent); | |
f135ff73 | 76 | |
f135ff73 | 77 | |
8cee4a30 VZ |
78 | virtual void SetImageList(wxImageList *imageList); |
79 | virtual void SetStateImageList(wxImageList *imageList); | |
80 | ||
81 | virtual wxString GetItemText(const wxTreeItemId& item) const; | |
a78955e3 | 82 | virtual int GetItemImage(const wxTreeItemId& item, |
74b31181 | 83 | wxTreeItemIcon which = wxTreeItemIcon_Normal) const; |
8cee4a30 VZ |
84 | virtual wxTreeItemData *GetItemData(const wxTreeItemId& item) const; |
85 | virtual wxColour GetItemTextColour(const wxTreeItemId& item) const; | |
86 | virtual wxColour GetItemBackgroundColour(const wxTreeItemId& item) const; | |
87 | virtual wxFont GetItemFont(const wxTreeItemId& item) const; | |
88 | ||
89 | virtual void SetItemText(const wxTreeItemId& item, const wxString& text); | |
90 | virtual void SetItemImage(const wxTreeItemId& item, | |
91 | int image, | |
92 | wxTreeItemIcon which = wxTreeItemIcon_Normal); | |
93 | virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData *data); | |
94 | ||
95 | virtual void SetItemHasChildren(const wxTreeItemId& item, bool has = true); | |
96 | virtual void SetItemBold(const wxTreeItemId& item, bool bold = true); | |
97 | virtual void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = true); | |
98 | virtual void SetItemTextColour(const wxTreeItemId& item, const wxColour& col); | |
99 | virtual void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col); | |
100 | virtual void SetItemFont(const wxTreeItemId& item, const wxFont& font); | |
101 | ||
102 | virtual bool IsVisible(const wxTreeItemId& item) const; | |
103 | virtual bool ItemHasChildren(const wxTreeItemId& item) const; | |
104 | virtual bool IsExpanded(const wxTreeItemId& item) const; | |
105 | virtual bool IsSelected(const wxTreeItemId& item) const; | |
106 | virtual bool IsBold(const wxTreeItemId& item) const; | |
107 | ||
108 | virtual size_t GetChildrenCount(const wxTreeItemId& item, | |
109 | bool recursively = true) const; | |
2b5f62a0 | 110 | |
8cee4a30 VZ |
111 | // navigation |
112 | // ---------- | |
2b5f62a0 | 113 | |
8cee4a30 VZ |
114 | virtual wxTreeItemId GetRootItem() const { return m_anchor; } |
115 | virtual wxTreeItemId GetSelection() const { return m_current; } | |
116 | virtual size_t GetSelections(wxArrayTreeItemIds&) const; | |
2b5f62a0 | 117 | |
8cee4a30 VZ |
118 | virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const; |
119 | virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item, | |
120 | wxTreeItemIdValue& cookie) const; | |
121 | virtual wxTreeItemId GetNextChild(const wxTreeItemId& item, | |
122 | wxTreeItemIdValue& cookie) const; | |
123 | virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const; | |
124 | virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; | |
125 | virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const; | |
f135ff73 | 126 | |
8cee4a30 VZ |
127 | virtual wxTreeItemId GetFirstVisibleItem() const; |
128 | virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const; | |
129 | virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const; | |
f135ff73 | 130 | |
f135ff73 | 131 | |
8cee4a30 VZ |
132 | // operations |
133 | // ---------- | |
ef44a621 | 134 | |
8cee4a30 VZ |
135 | virtual wxTreeItemId AddRoot(const wxString& text, |
136 | int image = -1, int selectedImage = -1, | |
137 | wxTreeItemData *data = NULL); | |
9fce43b7 | 138 | |
8cee4a30 VZ |
139 | virtual void Delete(const wxTreeItemId& item); |
140 | virtual void DeleteChildren(const wxTreeItemId& item); | |
141 | virtual void DeleteAllItems(); | |
9ec64fa7 | 142 | |
8cee4a30 VZ |
143 | virtual void Expand(const wxTreeItemId& item); |
144 | virtual void Collapse(const wxTreeItemId& item); | |
145 | virtual void CollapseAndReset(const wxTreeItemId& item); | |
146 | virtual void Toggle(const wxTreeItemId& item); | |
9ec64fa7 | 147 | |
8cee4a30 VZ |
148 | virtual void Unselect(); |
149 | virtual void UnselectAll(); | |
150 | virtual void SelectItem(const wxTreeItemId& item, bool select = true); | |
9ec64fa7 | 151 | |
8cee4a30 VZ |
152 | virtual void EnsureVisible(const wxTreeItemId& item); |
153 | virtual void ScrollTo(const wxTreeItemId& item); | |
3da2715f | 154 | |
8cee4a30 VZ |
155 | virtual wxTextCtrl *EditLabel(const wxTreeItemId& item, |
156 | wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl)); | |
157 | virtual wxTextCtrl *GetEditControl() const; | |
158 | virtual void EndEditLabel(const wxTreeItemId& item, | |
159 | bool discardChanges = false); | |
4832f7c0 | 160 | |
8cee4a30 | 161 | virtual void SortChildren(const wxTreeItemId& item); |
f135ff73 | 162 | |
8cee4a30 VZ |
163 | // items geometry |
164 | // -------------- | |
f135ff73 | 165 | |
8cee4a30 VZ |
166 | virtual bool GetBoundingRect(const wxTreeItemId& item, |
167 | wxRect& rect, | |
168 | bool textOnly = false) const; | |
f135ff73 | 169 | |
f135ff73 | 170 | |
8cee4a30 VZ |
171 | // this version specific methods |
172 | // ----------------------------- | |
88ac883a | 173 | |
8cee4a30 VZ |
174 | wxImageList *GetButtonsImageList() const { return m_imageListButtons; } |
175 | void SetButtonsImageList(wxImageList *imageList); | |
176 | void AssignButtonsImageList(wxImageList *imageList); | |
99006e44 | 177 | |
8cee4a30 VZ |
178 | void SetDropEffectAboveItem( bool above = false ) { m_dropEffectAboveItem = above; } |
179 | bool GetDropEffectAboveItem() const { return m_dropEffectAboveItem; } | |
f135ff73 | 180 | |
1ed01484 | 181 | wxTreeItemId GetNext(const wxTreeItemId& item) const; |
1ed01484 | 182 | |
f6bcfd97 | 183 | void ExpandAll(const wxTreeItemId& item); |
78f12104 | 184 | |
8cee4a30 VZ |
185 | #if WXWIN_COMPATIBILITY_2_6 |
186 | // use EditLabel() instead | |
187 | void Edit( const wxTreeItemId& item ) { EditLabel(item); } | |
188 | #endif // WXWIN_COMPATIBILITY_2_6 | |
f135ff73 | 189 | |
ee4b2721 | 190 | #if WXWIN_COMPATIBILITY_2_4 |
74b31181 | 191 | // deprecated functions: use Set/GetItemImage directly |
a6fb8636 WS |
192 | wxDEPRECATED( int GetItemSelectedImage(const wxTreeItemId& item) const ); |
193 | wxDEPRECATED( void SetItemSelectedImage(const wxTreeItemId& item, int image) ); | |
74b31181 | 194 | |
2d75caaa VZ |
195 | // use the versions taking wxTreeItemIdValue cookies (note that |
196 | // GetNextChild() is not inside wxDEPRECATED on purpose, as otherwise we | |
197 | // get twice as many warnings without any added benefit: it is always used | |
198 | // with GetFirstChild() anyhow) | |
ee4b2721 VZ |
199 | wxDEPRECATED( wxTreeItemId GetFirstChild(const wxTreeItemId& item, |
200 | long& cookie) const ); | |
2d75caaa VZ |
201 | wxTreeItemId GetNextChild(const wxTreeItemId& item, |
202 | long& cookie) const; | |
ee4b2721 VZ |
203 | #endif // WXWIN_COMPATIBILITY_2_4 |
204 | ||
3dbeaa52 | 205 | // implementation only from now on |
74b31181 | 206 | |
7009f411 VZ |
207 | // overridden base class virtuals |
208 | virtual bool SetBackgroundColour(const wxColour& colour); | |
209 | virtual bool SetForegroundColour(const wxColour& colour); | |
210 | ||
e1983ab5 VZ |
211 | virtual void Freeze(); |
212 | virtual void Thaw(); | |
ca65c044 | 213 | |
8cee4a30 VZ |
214 | virtual bool SetFont( const wxFont &font ); |
215 | virtual void SetWindowStyle(const long styles); | |
216 | ||
a43a4f9d | 217 | // callbacks |
3db7be80 RR |
218 | void OnPaint( wxPaintEvent &event ); |
219 | void OnSetFocus( wxFocusEvent &event ); | |
220 | void OnKillFocus( wxFocusEvent &event ); | |
f135ff73 | 221 | void OnChar( wxKeyEvent &event ); |
3db7be80 | 222 | void OnMouse( wxMouseEvent &event ); |
73bb6776 | 223 | void OnGetToolTip( wxTreeEvent &event ); |
5180055b | 224 | void OnInternalIdle( ); |
f135ff73 | 225 | |
35d4c967 RD |
226 | virtual wxVisualAttributes GetDefaultAttributes() const |
227 | { | |
228 | return GetClassDefaultAttributes(GetWindowVariant()); | |
229 | } | |
230 | ||
231 | static wxVisualAttributes | |
232 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
ca65c044 | 233 | |
3dbeaa52 | 234 | // implementation helpers |
8cee4a30 VZ |
235 | void AdjustMyScrollbars(); |
236 | ||
237 | WX_FORWARD_TO_SCROLL_HELPER() | |
238 | ||
f135ff73 | 239 | protected: |
91b8de8d | 240 | friend class wxGenericTreeItem; |
e179bd65 | 241 | friend class wxTreeRenameTimer; |
cb59313c | 242 | friend class wxTreeFindTimer; |
e179bd65 | 243 | friend class wxTreeTextCtrl; |
91b8de8d | 244 | |
eff869aa RR |
245 | wxFont m_normalFont; |
246 | wxFont m_boldFont; | |
247 | ||
f135ff73 | 248 | wxGenericTreeItem *m_anchor; |
cb59313c | 249 | wxGenericTreeItem *m_current, |
3e3a7b97 JS |
250 | *m_key_current, |
251 | // A hint to select a parent item after deleting a child | |
252 | *m_select_me; | |
618a5e38 | 253 | unsigned short m_indent; |
f135ff73 VZ |
254 | int m_lineHeight; |
255 | wxPen m_dottedPen; | |
b771aa29 VZ |
256 | wxBrush *m_hilightBrush, |
257 | *m_hilightUnfocusedBrush; | |
618a5e38 RR |
258 | bool m_hasFocus; |
259 | bool m_dirty; | |
8cee4a30 | 260 | bool m_ownsImageListButtons; |
618a5e38 | 261 | bool m_isDragging; // true between BEGIN/END drag events |
618a5e38 | 262 | bool m_lastOnSame; // last click on the same item as prev |
8cee4a30 | 263 | wxImageList *m_imageListButtons; |
3dbeaa52 | 264 | |
ca65c044 | 265 | int m_freezeCount; |
bbe0af5b | 266 | int m_dragCount; |
fd9811b1 | 267 | wxPoint m_dragStart; |
3dbeaa52 | 268 | wxGenericTreeItem *m_dropTarget; |
943d28e4 VZ |
269 | wxCursor m_oldCursor; // cursor is changed while dragging |
270 | wxGenericTreeItem *m_oldSelection; | |
f8b043e7 | 271 | wxGenericTreeItem *m_underMouse; // for visual effects |
fbb12260 | 272 | wxTreeTextCtrl *m_textCtrl; |
3dbeaa52 | 273 | |
e179bd65 | 274 | wxTimer *m_renameTimer; |
cb59313c | 275 | |
cb59313c VZ |
276 | // incremental search data |
277 | wxString m_findPrefix; | |
278 | wxTimer *m_findTimer; | |
a6fb8636 | 279 | |
e3d64157 | 280 | bool m_dropEffectAboveItem; |
f135ff73 VZ |
281 | |
282 | // the common part of all ctors | |
283 | void Init(); | |
284 | ||
285 | // misc helpers | |
cb59313c VZ |
286 | void SendDeleteEvent(wxGenericTreeItem *itemBeingDeleted); |
287 | ||
288 | void DrawBorder(const wxTreeItemId& item); | |
289 | void DrawLine(const wxTreeItemId& item, bool below); | |
290 | void DrawDropEffect(wxGenericTreeItem *item); | |
291 | ||
78f12104 | 292 | void DoSelectItem(const wxTreeItemId& id, |
ca65c044 WS |
293 | bool unselect_others = true, |
294 | bool extended_select = false); | |
78f12104 | 295 | |
8cee4a30 VZ |
296 | virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent, |
297 | size_t previous, | |
298 | const wxString& text, | |
299 | int image, | |
300 | int selectedImage, | |
301 | wxTreeItemData *data); | |
302 | virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent, | |
303 | const wxTreeItemId& idPrevious, | |
304 | const wxString& text, | |
305 | int image = -1, int selImage = -1, | |
306 | wxTreeItemData *data = NULL); | |
22574b4a | 307 | virtual wxTreeItemId DoTreeHitTest(const wxPoint& point, int& flags); |
cb59313c | 308 | |
fbb12260 JS |
309 | // called by wxTextTreeCtrl when it marks itself for deletion |
310 | void ResetTextControl(); | |
311 | ||
cb59313c VZ |
312 | // find the first item starting with the given prefix after the given item |
313 | wxTreeItemId FindItem(const wxTreeItemId& id, const wxString& prefix) const; | |
314 | ||
8fcf6e32 | 315 | bool HasButtons() const { return HasFlag(wxTR_HAS_BUTTONS); } |
f135ff73 | 316 | |
618a5e38 | 317 | void CalculateLineHeight(); |
91b8de8d | 318 | int GetLineHeight(wxGenericTreeItem *item) const; |
ef44a621 VZ |
319 | void PaintLevel( wxGenericTreeItem *item, wxDC& dc, int level, int &y ); |
320 | void PaintItem( wxGenericTreeItem *item, wxDC& dc); | |
f135ff73 VZ |
321 | |
322 | void CalculateLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y ); | |
323 | void CalculatePositions(); | |
91b8de8d | 324 | void CalculateSize( wxGenericTreeItem *item, wxDC &dc ); |
f135ff73 VZ |
325 | |
326 | void RefreshSubtree( wxGenericTreeItem *item ); | |
327 | void RefreshLine( wxGenericTreeItem *item ); | |
9dfbf520 | 328 | |
b771aa29 VZ |
329 | // redraw all selected items |
330 | void RefreshSelected(); | |
331 | ||
332 | // RefreshSelected() recursive helper | |
333 | void RefreshSelectedUnder(wxGenericTreeItem *item); | |
334 | ||
e179bd65 | 335 | void OnRenameTimer(); |
edb8f298 | 336 | bool OnRenameAccept(wxGenericTreeItem *item, const wxString& value); |
dd23c25c | 337 | void OnRenameCancelled(wxGenericTreeItem *item); |
43fa96a8 | 338 | |
91b8de8d | 339 | void FillArray(wxGenericTreeItem*, wxArrayTreeItemIds&) const; |
88ac883a VZ |
340 | void SelectItemRange( wxGenericTreeItem *item1, wxGenericTreeItem *item2 ); |
341 | bool TagAllChildrenUntilLast(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select); | |
342 | bool TagNextChildren(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select); | |
343 | void UnselectAllChildren( wxGenericTreeItem *item ); | |
0cf3b542 | 344 | void ChildrenClosing(wxGenericTreeItem* item); |
88ac883a | 345 | |
a32dd690 | 346 | private: |
f135ff73 | 347 | DECLARE_EVENT_TABLE() |
484523cf | 348 | DECLARE_DYNAMIC_CLASS(wxGenericTreeCtrl) |
22f3361e | 349 | DECLARE_NO_COPY_CLASS(wxGenericTreeCtrl) |
c801d85f KB |
350 | }; |
351 | ||
3a5bcc4d | 352 | #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__) |
233058c7 JS |
353 | /* |
354 | * wxTreeCtrl has to be a real class or we have problems with | |
355 | * the run-time information. | |
356 | */ | |
357 | ||
358 | class WXDLLEXPORT wxTreeCtrl: public wxGenericTreeCtrl | |
359 | { | |
233058c7 JS |
360 | DECLARE_DYNAMIC_CLASS(wxTreeCtrl) |
361 | ||
618a5e38 | 362 | public: |
233058c7 JS |
363 | wxTreeCtrl() {} |
364 | ||
ca65c044 | 365 | wxTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, |
233058c7 JS |
366 | const wxPoint& pos = wxDefaultPosition, |
367 | const wxSize& size = wxDefaultSize, | |
618a5e38 | 368 | long style = wxTR_DEFAULT_STYLE, |
233058c7 JS |
369 | const wxValidator &validator = wxDefaultValidator, |
370 | const wxString& name = wxTreeCtrlNameStr) | |
618a5e38 | 371 | : wxGenericTreeCtrl(parent, id, pos, size, style, validator, name) |
233058c7 | 372 | { |
233058c7 | 373 | } |
233058c7 | 374 | }; |
3a5bcc4d | 375 | #endif // !__WXMSW__ || __WXUNIVERSAL__ |
233058c7 | 376 | |
1e6feb95 VZ |
377 | #endif // wxUSE_TREECTRL |
378 | ||
f135ff73 VZ |
379 | #endif // _GENERIC_TREECTRL_H_ |
380 |