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