]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/treectlg.h
rename gsockmsw files to sockmsw
[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
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 114 virtual wxTreeItemId GetRootItem() const { return m_anchor; }
d1f7240a
VZ
115 virtual wxTreeItemId GetSelection() const
116 {
117 wxASSERT_MSG( !HasFlag(wxTR_MULTIPLE),
118 wxT("must use GetSelections() with this control") );
119
120 return m_current;
121 }
8cee4a30 122 virtual size_t GetSelections(wxArrayTreeItemIds&) const;
2b5f62a0 123
8cee4a30
VZ
124 virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
125 virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
126 wxTreeItemIdValue& cookie) const;
127 virtual wxTreeItemId GetNextChild(const wxTreeItemId& item,
128 wxTreeItemIdValue& cookie) const;
129 virtual wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
130 virtual wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
131 virtual wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
f135ff73 132
8cee4a30
VZ
133 virtual wxTreeItemId GetFirstVisibleItem() const;
134 virtual wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
135 virtual wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
f135ff73 136
f135ff73 137
8cee4a30
VZ
138 // operations
139 // ----------
ef44a621 140
8cee4a30
VZ
141 virtual wxTreeItemId AddRoot(const wxString& text,
142 int image = -1, int selectedImage = -1,
143 wxTreeItemData *data = NULL);
9fce43b7 144
8cee4a30
VZ
145 virtual void Delete(const wxTreeItemId& item);
146 virtual void DeleteChildren(const wxTreeItemId& item);
147 virtual void DeleteAllItems();
9ec64fa7 148
8cee4a30
VZ
149 virtual void Expand(const wxTreeItemId& item);
150 virtual void Collapse(const wxTreeItemId& item);
151 virtual void CollapseAndReset(const wxTreeItemId& item);
152 virtual void Toggle(const wxTreeItemId& item);
9ec64fa7 153
8cee4a30
VZ
154 virtual void Unselect();
155 virtual void UnselectAll();
156 virtual void SelectItem(const wxTreeItemId& item, bool select = true);
9ec64fa7 157
8cee4a30
VZ
158 virtual void EnsureVisible(const wxTreeItemId& item);
159 virtual void ScrollTo(const wxTreeItemId& item);
3da2715f 160
8cee4a30
VZ
161 virtual wxTextCtrl *EditLabel(const wxTreeItemId& item,
162 wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
163 virtual wxTextCtrl *GetEditControl() const;
164 virtual void EndEditLabel(const wxTreeItemId& item,
165 bool discardChanges = false);
4832f7c0 166
8cee4a30 167 virtual void SortChildren(const wxTreeItemId& item);
f135ff73 168
8cee4a30
VZ
169 // items geometry
170 // --------------
f135ff73 171
8cee4a30
VZ
172 virtual bool GetBoundingRect(const wxTreeItemId& item,
173 wxRect& rect,
174 bool textOnly = false) const;
f135ff73 175
f135ff73 176
8cee4a30
VZ
177 // this version specific methods
178 // -----------------------------
88ac883a 179
8cee4a30
VZ
180 wxImageList *GetButtonsImageList() const { return m_imageListButtons; }
181 void SetButtonsImageList(wxImageList *imageList);
182 void AssignButtonsImageList(wxImageList *imageList);
99006e44 183
8cee4a30
VZ
184 void SetDropEffectAboveItem( bool above = false ) { m_dropEffectAboveItem = above; }
185 bool GetDropEffectAboveItem() const { return m_dropEffectAboveItem; }
f135ff73 186
1ed01484 187 wxTreeItemId GetNext(const wxTreeItemId& item) const;
1ed01484 188
8cee4a30
VZ
189#if WXWIN_COMPATIBILITY_2_6
190 // use EditLabel() instead
191 void Edit( const wxTreeItemId& item ) { EditLabel(item); }
192#endif // WXWIN_COMPATIBILITY_2_6
f135ff73 193
3dbeaa52 194 // implementation only from now on
74b31181 195
7009f411
VZ
196 // overridden base class virtuals
197 virtual bool SetBackgroundColour(const wxColour& colour);
198 virtual bool SetForegroundColour(const wxColour& colour);
199
3e6e5147 200 virtual void Refresh(bool eraseBackground = true, const wxRect *rect = NULL);
ca65c044 201
8cee4a30
VZ
202 virtual bool SetFont( const wxFont &font );
203 virtual void SetWindowStyle(const long styles);
204
a43a4f9d 205 // callbacks
3db7be80
RR
206 void OnPaint( wxPaintEvent &event );
207 void OnSetFocus( wxFocusEvent &event );
208 void OnKillFocus( wxFocusEvent &event );
f135ff73 209 void OnChar( wxKeyEvent &event );
3db7be80 210 void OnMouse( wxMouseEvent &event );
73bb6776 211 void OnGetToolTip( wxTreeEvent &event );
ccdbdc89 212 void OnSize( wxSizeEvent &event );
5180055b 213 void OnInternalIdle( );
f135ff73 214
35d4c967
RD
215 virtual wxVisualAttributes GetDefaultAttributes() const
216 {
217 return GetClassDefaultAttributes(GetWindowVariant());
218 }
219
220 static wxVisualAttributes
221 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
ca65c044 222
3dbeaa52 223 // implementation helpers
8cee4a30
VZ
224 void AdjustMyScrollbars();
225
226 WX_FORWARD_TO_SCROLL_HELPER()
227
f135ff73 228protected:
91b8de8d 229 friend class wxGenericTreeItem;
e179bd65 230 friend class wxTreeRenameTimer;
cb59313c 231 friend class wxTreeFindTimer;
e179bd65 232 friend class wxTreeTextCtrl;
91b8de8d 233
eff869aa
RR
234 wxFont m_normalFont;
235 wxFont m_boldFont;
236
f135ff73 237 wxGenericTreeItem *m_anchor;
cb59313c 238 wxGenericTreeItem *m_current,
3e3a7b97
JS
239 *m_key_current,
240 // A hint to select a parent item after deleting a child
241 *m_select_me;
618a5e38 242 unsigned short m_indent;
f135ff73
VZ
243 int m_lineHeight;
244 wxPen m_dottedPen;
b771aa29
VZ
245 wxBrush *m_hilightBrush,
246 *m_hilightUnfocusedBrush;
618a5e38
RR
247 bool m_hasFocus;
248 bool m_dirty;
8cee4a30 249 bool m_ownsImageListButtons;
618a5e38 250 bool m_isDragging; // true between BEGIN/END drag events
618a5e38 251 bool m_lastOnSame; // last click on the same item as prev
8cee4a30 252 wxImageList *m_imageListButtons;
3dbeaa52 253
bbe0af5b 254 int m_dragCount;
fd9811b1 255 wxPoint m_dragStart;
3dbeaa52 256 wxGenericTreeItem *m_dropTarget;
943d28e4
VZ
257 wxCursor m_oldCursor; // cursor is changed while dragging
258 wxGenericTreeItem *m_oldSelection;
f8b043e7 259 wxGenericTreeItem *m_underMouse; // for visual effects
fbb12260 260 wxTreeTextCtrl *m_textCtrl;
3dbeaa52 261
e179bd65 262 wxTimer *m_renameTimer;
cb59313c 263
cb59313c
VZ
264 // incremental search data
265 wxString m_findPrefix;
266 wxTimer *m_findTimer;
a6fb8636 267
e3d64157 268 bool m_dropEffectAboveItem;
f135ff73
VZ
269
270 // the common part of all ctors
271 void Init();
272
17808a75
VZ
273 // overridden wxWindow methods
274 virtual void DoThaw();
275
f135ff73 276 // misc helpers
cb59313c
VZ
277 void SendDeleteEvent(wxGenericTreeItem *itemBeingDeleted);
278
279 void DrawBorder(const wxTreeItemId& item);
280 void DrawLine(const wxTreeItemId& item, bool below);
281 void DrawDropEffect(wxGenericTreeItem *item);
282
78f12104 283 void DoSelectItem(const wxTreeItemId& id,
ca65c044
WS
284 bool unselect_others = true,
285 bool extended_select = false);
78f12104 286
03966fcb
RR
287 virtual int DoGetItemState(const wxTreeItemId& item) const;
288 virtual void DoSetItemState(const wxTreeItemId& item, int state);
289
8cee4a30
VZ
290 virtual wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
291 size_t previous,
292 const wxString& text,
293 int image,
294 int selectedImage,
295 wxTreeItemData *data);
296 virtual wxTreeItemId DoInsertAfter(const wxTreeItemId& parent,
297 const wxTreeItemId& idPrevious,
298 const wxString& text,
299 int image = -1, int selImage = -1,
300 wxTreeItemData *data = NULL);
be0e5d69 301 virtual wxTreeItemId DoTreeHitTest(const wxPoint& point, int& flags) const;
cb59313c 302
fbb12260
JS
303 // called by wxTextTreeCtrl when it marks itself for deletion
304 void ResetTextControl();
305
cb59313c
VZ
306 // find the first item starting with the given prefix after the given item
307 wxTreeItemId FindItem(const wxTreeItemId& id, const wxString& prefix) const;
308
8fcf6e32 309 bool HasButtons() const { return HasFlag(wxTR_HAS_BUTTONS); }
f135ff73 310
618a5e38 311 void CalculateLineHeight();
91b8de8d 312 int GetLineHeight(wxGenericTreeItem *item) const;
ef44a621
VZ
313 void PaintLevel( wxGenericTreeItem *item, wxDC& dc, int level, int &y );
314 void PaintItem( wxGenericTreeItem *item, wxDC& dc);
f135ff73
VZ
315
316 void CalculateLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y );
317 void CalculatePositions();
318
319 void RefreshSubtree( wxGenericTreeItem *item );
320 void RefreshLine( wxGenericTreeItem *item );
9dfbf520 321
b771aa29
VZ
322 // redraw all selected items
323 void RefreshSelected();
324
325 // RefreshSelected() recursive helper
326 void RefreshSelectedUnder(wxGenericTreeItem *item);
327
e179bd65 328 void OnRenameTimer();
edb8f298 329 bool OnRenameAccept(wxGenericTreeItem *item, const wxString& value);
dd23c25c 330 void OnRenameCancelled(wxGenericTreeItem *item);
43fa96a8 331
91b8de8d 332 void FillArray(wxGenericTreeItem*, wxArrayTreeItemIds&) const;
88ac883a
VZ
333 void SelectItemRange( wxGenericTreeItem *item1, wxGenericTreeItem *item2 );
334 bool TagAllChildrenUntilLast(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select);
335 bool TagNextChildren(wxGenericTreeItem *crt_item, wxGenericTreeItem *last_item, bool select);
336 void UnselectAllChildren( wxGenericTreeItem *item );
0cf3b542 337 void ChildrenClosing(wxGenericTreeItem* item);
88ac883a 338
27f8357f
VZ
339 void DoDirtyProcessing();
340
54a4121a
VZ
341 virtual wxSize DoGetBestSize() const;
342
a32dd690 343private:
f135ff73 344 DECLARE_EVENT_TABLE()
484523cf 345 DECLARE_DYNAMIC_CLASS(wxGenericTreeCtrl)
22f3361e 346 DECLARE_NO_COPY_CLASS(wxGenericTreeCtrl)
c801d85f
KB
347};
348
3a5bcc4d 349#if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
233058c7
JS
350/*
351 * wxTreeCtrl has to be a real class or we have problems with
352 * the run-time information.
353 */
354
53a2db12 355class WXDLLIMPEXP_CORE wxTreeCtrl: public wxGenericTreeCtrl
233058c7 356{
233058c7
JS
357 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
358
618a5e38 359public:
233058c7
JS
360 wxTreeCtrl() {}
361
ca65c044 362 wxTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY,
233058c7
JS
363 const wxPoint& pos = wxDefaultPosition,
364 const wxSize& size = wxDefaultSize,
618a5e38 365 long style = wxTR_DEFAULT_STYLE,
233058c7
JS
366 const wxValidator &validator = wxDefaultValidator,
367 const wxString& name = wxTreeCtrlNameStr)
618a5e38 368 : wxGenericTreeCtrl(parent, id, pos, size, style, validator, name)
233058c7 369 {
233058c7 370 }
233058c7 371};
3a5bcc4d 372#endif // !__WXMSW__ || __WXUNIVERSAL__
233058c7 373
1e6feb95
VZ
374#endif // wxUSE_TREECTRL
375
f135ff73 376#endif // _GENERIC_TREECTRL_H_