]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/treectlg.h
activating DrawRectangle optimization
[wxWidgets.git] / include / wx / generic / treectlg.h
CommitLineData
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
b5dbe15d 24class WXDLLIMPEXP_FWD_CORE wxGenericTreeItem;
c801d85f 25
b5dbe15d 26class WXDLLIMPEXP_FWD_CORE wxTreeItemData;
e179bd65 27
b5dbe15d
VS
28class WXDLLIMPEXP_FWD_CORE wxTreeRenameTimer;
29class WXDLLIMPEXP_FWD_CORE wxTreeFindTimer;
30class WXDLLIMPEXP_FWD_CORE wxTreeTextCtrl;
31class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
74bedbeb 32
f135ff73 33// -----------------------------------------------------------------------------
484523cf 34// wxGenericTreeCtrl - the tree control
f135ff73 35// -----------------------------------------------------------------------------
c801d85f 36
53a2db12 37class WXDLLIMPEXP_CORE wxGenericTreeCtrl : public wxTreeCtrlBase,
8cee4a30 38 public wxScrollHelper
c801d85f 39{
a32dd690 40public:
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
8cee4a30
VZ
68 // implement base class pure virtuals
69 // ----------------------------------
f135ff73 70
027d45e8 71 virtual unsigned int GetCount() const;
e3d64157 72
8cee4a30
VZ
73 virtual unsigned int GetIndent() const { return m_indent; }
74 virtual void SetIndent(unsigned int indent);
f135ff73 75
f135ff73 76
8cee4a30
VZ
77 virtual void SetImageList(wxImageList *imageList);
78 virtual void SetStateImageList(wxImageList *imageList);
79
80 virtual wxString GetItemText(const wxTreeItemId& item) const;
a78955e3 81 virtual int GetItemImage(const wxTreeItemId& item,
74b31181 82 wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
8cee4a30
VZ
83 virtual wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
84 virtual wxColour GetItemTextColour(const wxTreeItemId& item) const;
85 virtual wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
86 virtual wxFont GetItemFont(const wxTreeItemId& item) const;
87
88 virtual void SetItemText(const wxTreeItemId& item, const wxString& text);
89 virtual void SetItemImage(const wxTreeItemId& item,
90 int image,
91 wxTreeItemIcon which = wxTreeItemIcon_Normal);
92 virtual void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
93
94 virtual void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
95 virtual void SetItemBold(const wxTreeItemId& item, bool bold = true);
96 virtual void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = true);
97 virtual void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
98 virtual void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
99 virtual void SetItemFont(const wxTreeItemId& item, const wxFont& font);
100
101 virtual bool IsVisible(const wxTreeItemId& item) const;
102 virtual bool ItemHasChildren(const wxTreeItemId& item) const;
103 virtual bool IsExpanded(const wxTreeItemId& item) const;
104 virtual bool IsSelected(const wxTreeItemId& item) const;
105 virtual bool IsBold(const wxTreeItemId& item) const;
106
107 virtual size_t GetChildrenCount(const wxTreeItemId& item,
108 bool recursively = true) const;
2b5f62a0 109
8cee4a30
VZ
110 // navigation
111 // ----------
2b5f62a0 112
8cee4a30 113 virtual wxTreeItemId GetRootItem() const { return m_anchor; }
d1f7240a
VZ
114 virtual wxTreeItemId GetSelection() const
115 {
116 wxASSERT_MSG( !HasFlag(wxTR_MULTIPLE),
117 wxT("must use GetSelections() with this control") );
118
119 return m_current;
120 }
8cee4a30 121 virtual size_t GetSelections(wxArrayTreeItemIds&) const;
febebac1 122 virtual wxTreeItemId GetFocusedItem() const { return m_current; }
2b5f62a0 123
5708ae18
VZ
124 virtual void ClearFocusedItem();
125 virtual void SetFocusedItem(const wxTreeItemId& item);
126
8cee4a30
VZ
127 virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
128 virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
129 wxTreeItemIdValue& cookie) const;
130 virtual wxTreeItemId GetNextChild(const wxTreeItemId& item,
131 wxTreeItemIdValue& cookie) const;
132 virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
133 virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
134 virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
f135ff73 135
8cee4a30
VZ
136 virtual wxTreeItemId GetFirstVisibleItem() const;
137 virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
138 virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
f135ff73 139
f135ff73 140
8cee4a30
VZ
141 // operations
142 // ----------
ef44a621 143
8cee4a30
VZ
144 virtual wxTreeItemId AddRoot(const wxString& text,
145 int image = -1, int selectedImage = -1,
146 wxTreeItemData *data = NULL);
9fce43b7 147
8cee4a30
VZ
148 virtual void Delete(const wxTreeItemId& item);
149 virtual void DeleteChildren(const wxTreeItemId& item);
150 virtual void DeleteAllItems();
9ec64fa7 151
8cee4a30
VZ
152 virtual void Expand(const wxTreeItemId& item);
153 virtual void Collapse(const wxTreeItemId& item);
154 virtual void CollapseAndReset(const wxTreeItemId& item);
155 virtual void Toggle(const wxTreeItemId& item);
9ec64fa7 156
8cee4a30
VZ
157 virtual void Unselect();
158 virtual void UnselectAll();
159 virtual void SelectItem(const wxTreeItemId& item, bool select = true);
5cb3a695 160 virtual void SelectChildren(const wxTreeItemId& parent);
9ec64fa7 161
8cee4a30
VZ
162 virtual void EnsureVisible(const wxTreeItemId& item);
163 virtual void ScrollTo(const wxTreeItemId& item);
3da2715f 164
8cee4a30 165 virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
b19b28c8 166 wxClassInfo* textCtrlClass = wxCLASSINFO(wxTextCtrl));
8cee4a30
VZ
167 virtual wxTextCtrl *GetEditControl() const;
168 virtual void EndEditLabel(const wxTreeItemId& item,
169 bool discardChanges = false);
4832f7c0 170
27bc9194
VZ
171 virtual void EnableBellOnNoMatch(bool on = true);
172
8cee4a30 173 virtual void SortChildren(const wxTreeItemId& item);
f135ff73 174
8cee4a30
VZ
175 // items geometry
176 // --------------
f135ff73 177
8cee4a30
VZ
178 virtual bool GetBoundingRect(const wxTreeItemId& item,
179 wxRect& rect,
180 bool textOnly = false) const;
f135ff73 181
f135ff73 182
8cee4a30
VZ
183 // this version specific methods
184 // -----------------------------
88ac883a 185
8cee4a30
VZ
186 wxImageList *GetButtonsImageList() const { return m_imageListButtons; }
187 void SetButtonsImageList(wxImageList *imageList);
188 void AssignButtonsImageList(wxImageList *imageList);
99006e44 189
8cee4a30
VZ
190 void SetDropEffectAboveItem( bool above = false ) { m_dropEffectAboveItem = above; }
191 bool GetDropEffectAboveItem() const { return m_dropEffectAboveItem; }
f135ff73 192
1ed01484 193 wxTreeItemId GetNext(const wxTreeItemId& item) const;
1ed01484 194
8cee4a30
VZ
195#if WXWIN_COMPATIBILITY_2_6
196 // use EditLabel() instead
197 void Edit( const wxTreeItemId& item ) { EditLabel(item); }
198#endif // WXWIN_COMPATIBILITY_2_6
f135ff73 199
3dbeaa52 200 // implementation only from now on
74b31181 201
7009f411
VZ
202 // overridden base class virtuals
203 virtual bool SetBackgroundColour(const wxColour& colour);
204 virtual bool SetForegroundColour(const wxColour& colour);
205
3e6e5147 206 virtual void Refresh(bool eraseBackground = true, const wxRect *rect = NULL);
ca65c044 207
8cee4a30
VZ
208 virtual bool SetFont( const wxFont &font );
209 virtual void SetWindowStyle(const long styles);
210
a43a4f9d 211 // callbacks
3db7be80
RR
212 void OnPaint( wxPaintEvent &event );
213 void OnSetFocus( wxFocusEvent &event );
214 void OnKillFocus( wxFocusEvent &event );
2a4a928d 215 void OnKeyDown( wxKeyEvent &event );
f135ff73 216 void OnChar( wxKeyEvent &event );
3db7be80 217 void OnMouse( wxMouseEvent &event );
73bb6776 218 void OnGetToolTip( wxTreeEvent &event );
ccdbdc89 219 void OnSize( wxSizeEvent &event );
5180055b 220 void OnInternalIdle( );
f135ff73 221
35d4c967
RD
222 virtual wxVisualAttributes GetDefaultAttributes() const
223 {
224 return GetClassDefaultAttributes(GetWindowVariant());
225 }
226
227 static wxVisualAttributes
228 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
ca65c044 229
3dbeaa52 230 // implementation helpers
8cee4a30
VZ
231 void AdjustMyScrollbars();
232
233 WX_FORWARD_TO_SCROLL_HELPER()
234
f135ff73 235protected:
91b8de8d 236 friend class wxGenericTreeItem;
e179bd65 237 friend class wxTreeRenameTimer;
cb59313c 238 friend class wxTreeFindTimer;
e179bd65 239 friend class wxTreeTextCtrl;
91b8de8d 240
eff869aa
RR
241 wxFont m_normalFont;
242 wxFont m_boldFont;
243
f135ff73 244 wxGenericTreeItem *m_anchor;
cb59313c 245 wxGenericTreeItem *m_current,
3e3a7b97
JS
246 *m_key_current,
247 // A hint to select a parent item after deleting a child
248 *m_select_me;
618a5e38 249 unsigned short m_indent;
f135ff73
VZ
250 int m_lineHeight;
251 wxPen m_dottedPen;
b771aa29
VZ
252 wxBrush *m_hilightBrush,
253 *m_hilightUnfocusedBrush;
618a5e38
RR
254 bool m_hasFocus;
255 bool m_dirty;
8cee4a30 256 bool m_ownsImageListButtons;
618a5e38 257 bool m_isDragging; // true between BEGIN/END drag events
618a5e38 258 bool m_lastOnSame; // last click on the same item as prev
8cee4a30 259 wxImageList *m_imageListButtons;
3dbeaa52 260
bbe0af5b 261 int m_dragCount;
fd9811b1 262 wxPoint m_dragStart;
3dbeaa52 263 wxGenericTreeItem *m_dropTarget;
943d28e4
VZ
264 wxCursor m_oldCursor; // cursor is changed while dragging
265 wxGenericTreeItem *m_oldSelection;
f8b043e7 266 wxGenericTreeItem *m_underMouse; // for visual effects
03647350 267
c0d2308b 268 enum { NoEffect, BorderEffect, AboveEffect, BelowEffect } m_dndEffect;
03647350
VZ
269 wxGenericTreeItem *m_dndEffectItem;
270
fbb12260 271 wxTreeTextCtrl *m_textCtrl;
03647350 272
3dbeaa52 273
e179bd65 274 wxTimer *m_renameTimer;
cb59313c 275
cb59313c
VZ
276 // incremental search data
277 wxString m_findPrefix;
278 wxTimer *m_findTimer;
27bc9194
VZ
279 // This flag is set to 0 if the bell is disabled, 1 if it is enabled and -1
280 // if it is globally enabled but has been temporarily disabled because we
281 // had already beeped for this particular search.
282 int m_findBell;
a6fb8636 283
e3d64157 284 bool m_dropEffectAboveItem;
f135ff73
VZ
285
286 // the common part of all ctors
287 void Init();
288
03647350 289 // overridden wxWindow methods
17808a75
VZ
290 virtual void DoThaw();
291
f135ff73 292 // misc helpers
cb59313c
VZ
293 void SendDeleteEvent(wxGenericTreeItem *itemBeingDeleted);
294
295 void DrawBorder(const wxTreeItemId& item);
296 void DrawLine(const wxTreeItemId& item, bool below);
297 void DrawDropEffect(wxGenericTreeItem *item);
298
78f12104 299 void DoSelectItem(const wxTreeItemId& id,
ca65c044
WS
300 bool unselect_others = true,
301 bool extended_select = false);
78f12104 302
03966fcb
RR
303 virtual int DoGetItemState(const wxTreeItemId& item) const;
304 virtual void DoSetItemState(const wxTreeItemId& item, int state);
305
8cee4a30
VZ
306 virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
307 size_t previous,
308 const wxString& text,
309 int image,
310 int selectedImage,
311 wxTreeItemData *data);
312 virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent,
313 const wxTreeItemId& idPrevious,
314 const wxString& text,
315 int image = -1, int selImage = -1,
316 wxTreeItemData *data = NULL);
be0e5d69 317 virtual wxTreeItemId DoTreeHitTest(const wxPoint& point, int& flags) const;
cb59313c 318
fbb12260
JS
319 // called by wxTextTreeCtrl when it marks itself for deletion
320 void ResetTextControl();
321
cb59313c
VZ
322 // find the first item starting with the given prefix after the given item
323 wxTreeItemId FindItem(const wxTreeItemId& id, const wxString& prefix) const;
324
8fcf6e32 325 bool HasButtons() const { return HasFlag(wxTR_HAS_BUTTONS); }
f135ff73 326
618a5e38 327 void CalculateLineHeight();
91b8de8d 328 int GetLineHeight(wxGenericTreeItem *item) const;
ef44a621
VZ
329 void PaintLevel( wxGenericTreeItem *item, wxDC& dc, int level, int &y );
330 void PaintItem( wxGenericTreeItem *item, wxDC& dc);
f135ff73
VZ
331
332 void CalculateLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y );
333 void CalculatePositions();
334
335 void RefreshSubtree( wxGenericTreeItem *item );
336 void RefreshLine( wxGenericTreeItem *item );
9dfbf520 337
b771aa29
VZ
338 // redraw all selected items
339 void RefreshSelected();
340
341 // RefreshSelected() recursive helper
342 void RefreshSelectedUnder(wxGenericTreeItem *item);
343
e179bd65 344 void OnRenameTimer();
edb8f298 345 bool OnRenameAccept(wxGenericTreeItem *item, const wxString& value);
dd23c25c 346 void OnRenameCancelled(wxGenericTreeItem *item);
43fa96a8 347
91b8de8d 348 void FillArray(wxGenericTreeItem*, wxArrayTreeItemIds&) const;
88ac883a
VZ
349 void SelectItemRange( wxGenericTreeItem *item1, wxGenericTreeItem *item2 );
350 bool TagAllChildrenUntilLast(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select);
351 bool TagNextChildren(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select);
352 void UnselectAllChildren( wxGenericTreeItem *item );
0cf3b542 353 void ChildrenClosing(wxGenericTreeItem* item);
88ac883a 354
27f8357f
VZ
355 void DoDirtyProcessing();
356
54a4121a
VZ
357 virtual wxSize DoGetBestSize() const;
358
a32dd690 359private:
27bc9194
VZ
360 // Reset the state of the last find (i.e. keyboard incremental search)
361 // operation.
362 void ResetFindState();
363
f135ff73 364 DECLARE_EVENT_TABLE()
484523cf 365 DECLARE_DYNAMIC_CLASS(wxGenericTreeCtrl)
c0c133e1 366 wxDECLARE_NO_COPY_CLASS(wxGenericTreeCtrl);
c801d85f
KB
367};
368
3a5bcc4d 369#if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
233058c7
JS
370/*
371 * wxTreeCtrl has to be a real class or we have problems with
372 * the run-time information.
373 */
374
53a2db12 375class WXDLLIMPEXP_CORE wxTreeCtrl: public wxGenericTreeCtrl
233058c7 376{
233058c7
JS
377 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
378
618a5e38 379public:
233058c7
JS
380 wxTreeCtrl() {}
381
ca65c044 382 wxTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY,
233058c7
JS
383 const wxPoint& pos = wxDefaultPosition,
384 const wxSize& size = wxDefaultSize,
618a5e38 385 long style = wxTR_DEFAULT_STYLE,
233058c7
JS
386 const wxValidator &validator = wxDefaultValidator,
387 const wxString& name = wxTreeCtrlNameStr)
618a5e38 388 : wxGenericTreeCtrl(parent, id, pos, size, style, validator, name)
233058c7 389 {
233058c7 390 }
233058c7 391};
3a5bcc4d 392#endif // !__WXMSW__ || __WXUNIVERSAL__
233058c7 393
1e6feb95
VZ
394#endif // wxUSE_TREECTRL
395
f135ff73 396#endif // _GENERIC_TREECTRL_H_