]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/gizmos/wxCode/include/wx/treelistctrl.h
Some change notes
[wxWidgets.git] / wxPython / contrib / gizmos / wxCode / include / wx / treelistctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: treelistctrl.h
3 // Purpose: wxTreeListCtrl class
4 // Author: Robert Roebling
5 // Modified by: Alberto Griggio, 2002
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling, Julian Smart, Alberto Griggio,
9 // Vadim Zeitlin, Otto Wyss
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13
14 #ifndef TREELISTCTRL_H
15 #define TREELISTCTRL_H
16
17 #if defined(__GNUG__) && !defined(__APPLE__)
18 #pragma interface "treelistctrl.h"
19 #endif
20
21 #include <wx/treectrl.h>
22 #include <wx/control.h>
23 #include <wx/pen.h>
24 #include <wx/listctrl.h> // for wxListEvent
25
26 #ifdef GIZMOISDLL
27 #define GIZMODLLEXPORT WXDLLEXPORT
28 #else
29 #define GIZMODLLEXPORT
30 #endif
31
32
33 class GIZMODLLEXPORT wxTreeListItem;
34 class GIZMODLLEXPORT wxTreeListHeaderWindow;
35 class GIZMODLLEXPORT wxTreeListMainWindow;
36
37
38 // Using this typedef removes an ambiguity when calling Remove()
39 #ifdef __WXMSW__
40 #if !wxCHECK_VERSION(2, 5, 0)
41 typedef long wxTreeItemIdValue;
42 #else
43 typedef void *wxTreeItemIdValue;
44 #endif
45 #endif
46
47
48 #define wxTR_DONT_ADJUST_MAC 0x0100 // Don't adjust the style for the Mac
49
50 //-----------------------------------------------------------------------------
51 // wxTreeListColumnAttrs
52 //-----------------------------------------------------------------------------
53
54 enum wxTreeListColumnAlign {
55 wxTL_ALIGN_LEFT,
56 wxTL_ALIGN_RIGHT,
57 wxTL_ALIGN_CENTER
58 };
59
60
61 class GIZMODLLEXPORT wxTreeListColumnInfo: public wxObject {
62 public:
63 enum { DEFAULT_COL_WIDTH = 100 };
64
65 wxTreeListColumnInfo(const wxString &text = wxT(""),
66 int image = -1,
67 size_t width = DEFAULT_COL_WIDTH,
68 bool shown = true,
69 wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT)
70 {
71 m_image = image;
72 m_selected_image = -1;
73 m_text = text;
74 m_width = width;
75 m_shown = shown;
76 m_alignment = alignment;
77 }
78
79 wxTreeListColumnInfo(const wxTreeListColumnInfo& other)
80 {
81 m_image = other.m_image;
82 m_selected_image = other.m_selected_image;
83 m_text = other.m_text;
84 m_width = other.m_width;
85 m_shown = other.m_shown;
86 m_alignment = other.m_alignment;
87 }
88
89 ~wxTreeListColumnInfo() {}
90
91 // getters
92 bool GetShown() const { return m_shown; }
93 wxTreeListColumnAlign GetAlignment() const { return m_alignment; }
94 wxString GetText() const { return m_text; }
95 int GetImage() const { return m_image; }
96 int GetSelectedImage() const { return m_selected_image; }
97 size_t GetWidth() const { return m_width; }
98
99 // setters
100 wxTreeListColumnInfo& SetShown(bool shown)
101 { m_shown = shown; return *this; }
102
103 wxTreeListColumnInfo& SetAlignment(wxTreeListColumnAlign alignment)
104 { m_alignment = alignment; return *this; }
105
106 wxTreeListColumnInfo& SetText(const wxString& text)
107 { m_text = text; return *this; }
108
109 wxTreeListColumnInfo& SetImage(int image)
110 { m_image = image; return *this; }
111
112 wxTreeListColumnInfo& SetSelectedImage(int image)
113 { m_selected_image = image; return *this; }
114
115 wxTreeListColumnInfo& SetWidth(size_t with)
116 { m_width = with; return *this; }
117
118 private:
119 bool m_shown;
120 wxTreeListColumnAlign m_alignment;
121 wxString m_text;
122 int m_image;
123 int m_selected_image;
124 size_t m_width;
125 };
126
127 //----------------------------------------------------------------------------
128 // wxTreeListCtrl - the multicolumn tree control
129 //----------------------------------------------------------------------------
130
131 // flags for FindItem
132 const int wxTL_SEARCH_VISIBLE = 0x0000;
133 const int wxTL_SEARCH_LEVEL = 0x0001;
134 const int wxTL_SEARCH_FULL = 0x0002;
135 const int wxTL_SEARCH_PARTIAL = 0x0010;
136 const int wxTL_SEARCH_NOCASE = 0x0020;
137
138 // additional flag for HitTest
139 const int wxTREE_HITTEST_ONITEMCOLUMN = 0x2000;
140 extern GIZMODLLEXPORT const wxChar* wxTreeListCtrlNameStr;
141
142
143 class GIZMODLLEXPORT wxTreeListCtrl : public wxControl
144 {
145 public:
146 // creation
147 // --------
148 wxTreeListCtrl() {}
149
150 wxTreeListCtrl(wxWindow *parent, wxWindowID id = -1,
151 const wxPoint& pos = wxDefaultPosition,
152 const wxSize& size = wxDefaultSize,
153 long style = wxTR_DEFAULT_STYLE,
154 const wxValidator &validator = wxDefaultValidator,
155 const wxString& name = wxTreeListCtrlNameStr )
156 : m_header_win(0), m_main_win(0)
157 {
158 Create(parent, id, pos, size, style, validator, name);
159 }
160
161 virtual ~wxTreeListCtrl() {}
162
163 bool Create(wxWindow *parent, wxWindowID id = -1,
164 const wxPoint& pos = wxDefaultPosition,
165 const wxSize& size = wxDefaultSize,
166 long style = wxTR_DEFAULT_STYLE,
167 const wxValidator &validator = wxDefaultValidator,
168 const wxString& name = wxTreeListCtrlNameStr );
169
170 void Refresh(bool erase=TRUE, const wxRect* rect=NULL);
171 void SetFocus();
172 // accessors
173 // ---------
174
175 // get the total number of items in the control
176 size_t GetCount() const;
177
178 // indent is the number of pixels the children are indented relative to
179 // the parents position. SetIndent() also redraws the control
180 // immediately.
181 unsigned int GetIndent() const;
182 void SetIndent(unsigned int indent);
183
184 // line spacing is the space above and below the text on each line
185 unsigned int GetLineSpacing() const;
186 void SetLineSpacing(unsigned int spacing);
187
188 // image list: these functions allow to associate an image list with
189 // the control and retrieve it. Note that when assigned with
190 // SetImageList, the control does _not_ delete
191 // the associated image list when it's deleted in order to allow image
192 // lists to be shared between different controls. If you use
193 // AssignImageList, the control _does_ delete the image list.
194 //
195 // The normal image list is for the icons which correspond to the
196 // normal tree item state (whether it is selected or not).
197 // Additionally, the application might choose to show a state icon
198 // which corresponds to an app-defined item state (for example,
199 // checked/unchecked) which are taken from the state image list.
200 wxImageList *GetImageList() const;
201 wxImageList *GetStateImageList() const;
202 wxImageList *GetButtonsImageList() const;
203
204 void SetImageList(wxImageList *imageList);
205 void SetStateImageList(wxImageList *imageList);
206 void SetButtonsImageList(wxImageList *imageList);
207 void AssignImageList(wxImageList *imageList);
208 void AssignStateImageList(wxImageList *imageList);
209 void AssignButtonsImageList(wxImageList *imageList);
210
211
212 // Functions to work with tree list ctrl columns
213
214 // adds a column
215 void AddColumn(const wxString& text)
216 { AddColumn(wxTreeListColumnInfo(text)); }
217 void AddColumn(const wxString& text,
218 size_t width,
219 wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT)
220 { AddColumn(wxTreeListColumnInfo(text,
221 -1,
222 width,
223 true,
224 alignment)); }
225 void AddColumn(const wxTreeListColumnInfo& col);
226
227 // inserts a column before the given one
228 void InsertColumn(size_t before, const wxString& text)
229 { InsertColumn(before, wxTreeListColumnInfo(text)); }
230 void InsertColumn(size_t before, const wxTreeListColumnInfo& col);
231
232 // deletes the given column - does not delete the corresponding column
233 // of each item
234 void RemoveColumn(size_t column);
235
236 // returns the number of columns in the ctrl
237 size_t GetColumnCount() const;
238
239 void SetColumnWidth(size_t column, size_t width);
240 int GetColumnWidth(size_t column) const;
241
242 // tells which column is the "main" one, i.e. the "threaded" one
243 void SetMainColumn(size_t column);
244 size_t GetMainColumn() const;
245
246 void SetColumnText(size_t column, const wxString& text);
247 wxString GetColumnText(size_t column) const;
248
249 void SetColumn(size_t column, const wxTreeListColumnInfo& info);
250 wxTreeListColumnInfo& GetColumn(size_t column);
251 const wxTreeListColumnInfo& GetColumn(size_t column) const;
252
253 // other column-related methods
254 void SetColumnAlignment(size_t column, wxTreeListColumnAlign align);
255 wxTreeListColumnAlign GetColumnAlignment(size_t column) const;
256
257 void SetColumnImage(size_t column, int image);
258 int GetColumnImage(size_t column) const;
259
260 void ShowColumn(size_t column, bool shown);
261 bool IsColumnShown(size_t column) const;
262
263 // Functions to work with tree list ctrl items.
264
265 // accessors
266 // ---------
267
268 // retrieve item's label (of the main column)
269 wxString GetItemText(const wxTreeItemId& item) const
270 { return GetItemText(item, GetMainColumn()); }
271 // retrieves item's label of the given column
272 wxString GetItemText(const wxTreeItemId& item, size_t column) const;
273
274 // get one of the images associated with the item (normal by default)
275 int GetItemImage(const wxTreeItemId& item,
276 wxTreeItemIcon which = wxTreeItemIcon_Normal) const
277 { return GetItemImage(item, GetMainColumn(), which); }
278 int GetItemImage(const wxTreeItemId& item, size_t column,
279 wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
280
281 // get the data associated with the item
282 wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
283
284 bool GetItemBold(const wxTreeItemId& item) const;
285 wxColour GetItemTextColour(const wxTreeItemId& item) const;
286 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
287 wxFont GetItemFont(const wxTreeItemId& item) const;
288
289 // modifiers
290 // ---------
291
292 // set item's label
293 void SetItemText(const wxTreeItemId& item, const wxString& text)
294 { SetItemText(item, GetMainColumn(), text); }
295 void SetItemText(const wxTreeItemId& item, size_t column,
296 const wxString& text);
297
298 // get one of the images associated with the item (normal by default)
299 void SetItemImage(const wxTreeItemId& item, int image,
300 wxTreeItemIcon which = wxTreeItemIcon_Normal)
301 { SetItemImage(item, GetMainColumn(), image, which); }
302 // the which parameter is ignored for all columns but the main one
303 void SetItemImage(const wxTreeItemId& item, size_t column, int image,
304 wxTreeItemIcon which = wxTreeItemIcon_Normal);
305
306 // associate some data with the item
307 void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
308
309 // force appearance of [+] button near the item. This is useful to
310 // allow the user to expand the items which don't have any children now
311 // - but instead add them only when needed, thus minimizing memory
312 // usage and loading time.
313 void SetItemHasChildren(const wxTreeItemId& item, bool has = TRUE);
314
315 // the item will be shown in bold
316 void SetItemBold(const wxTreeItemId& item, bool bold = TRUE);
317
318 // set the item's text colour
319 void SetItemTextColour(const wxTreeItemId& item, const wxColour& colour);
320
321 // set the item's background colour
322 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& colour);
323
324 // set the item's font (should be of the same height for all items)
325 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
326
327 // set the window font
328 virtual bool SetFont( const wxFont &font );
329
330 // set the styles.
331 void SetWindowStyle(const long styles);
332 long GetWindowStyle() const;
333 long GetWindowStyleFlag() const { return GetWindowStyle(); }
334
335 // item status inquiries
336 // ---------------------
337
338 // is the item visible (it might be outside the view or not expanded)?
339 bool IsVisible(const wxTreeItemId& item) const;
340 // does the item has any children?
341 bool HasChildren(const wxTreeItemId& item) const
342 { return ItemHasChildren(item); }
343 bool ItemHasChildren(const wxTreeItemId& item) const;
344 // is the item expanded (only makes sense if HasChildren())?
345 bool IsExpanded(const wxTreeItemId& item) const;
346 // is this item currently selected (the same as has focus)?
347 bool IsSelected(const wxTreeItemId& item) const;
348 // is item text in bold font?
349 bool IsBold(const wxTreeItemId& item) const;
350 // does the layout include space for a button?
351
352 // number of children
353 // ------------------
354
355 // if 'recursively' is FALSE, only immediate children count, otherwise
356 // the returned number is the number of all items in this branch
357 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
358
359 // navigation
360 // ----------
361
362 // wxTreeItemId.IsOk() will return FALSE if there is no such item
363
364 // get the root tree item
365 wxTreeItemId GetRootItem() const;
366
367 // get the item currently selected (may return NULL if no selection)
368 wxTreeItemId GetSelection() const;
369
370 // get the items currently selected, return the number of such item
371 size_t GetSelections(wxArrayTreeItemIds&) const;
372
373 // get the parent of this item (may return NULL if root)
374 wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
375
376 // for this enumeration function you must pass in a "cookie" parameter
377 // which is opaque for the application but is necessary for the library
378 // to make these functions reentrant (i.e. allow more than one
379 // enumeration on one and the same object simultaneously). Of course,
380 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
381 // the same!
382
383 // get the first child of this item
384 #if !wxCHECK_VERSION(2, 5, 0)
385 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const;
386 #else
387 wxTreeItemId GetFirstChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const;
388 #endif
389 // get the next child
390 #if !wxCHECK_VERSION(2, 5, 0)
391 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const;
392 #else
393 wxTreeItemId GetNextChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const;
394 #endif
395 // get the prev child
396 #if !wxCHECK_VERSION(2, 5, 0)
397 wxTreeItemId GetPrevChild(const wxTreeItemId& item, long& cookie) const;
398 #else
399 wxTreeItemId GetPrevChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const;
400 #endif
401 // get the last child of this item - this method doesn't use cookies
402 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
403
404 // get the next sibling of this item
405 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
406 // get the previous sibling
407 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
408
409 // get first visible item
410 wxTreeItemId GetFirstVisibleItem() const;
411 // get the next visible item: item must be visible itself!
412 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
413 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
414 // get the previous visible item: item must be visible itself!
415 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
416
417 // Only for internal use right now, but should probably be public
418 wxTreeItemId GetNext(const wxTreeItemId& item) const;
419
420 // operations
421 // ----------
422
423 // add the root node to the tree
424 wxTreeItemId AddRoot(const wxString& text,
425 int image = -1, int selectedImage = -1,
426 wxTreeItemData *data = NULL);
427
428 // insert a new item in as the first child of the parent
429 wxTreeItemId PrependItem(const wxTreeItemId& parent,
430 const wxString& text,
431 int image = -1, int selectedImage = -1,
432 wxTreeItemData *data = NULL);
433
434 // insert a new item after a given one
435 wxTreeItemId InsertItem(const wxTreeItemId& parent,
436 const wxTreeItemId& idPrevious,
437 const wxString& text,
438 int image = -1, int selectedImage = -1,
439 wxTreeItemData *data = NULL);
440
441 // insert a new item before the one with the given index
442 wxTreeItemId InsertItem(const wxTreeItemId& parent,
443 size_t index,
444 const wxString& text,
445 int image = -1, int selectedImage = -1,
446 wxTreeItemData *data = NULL);
447
448 // insert a new item in as the last child of the parent
449 wxTreeItemId AppendItem(const wxTreeItemId& parent,
450 const wxString& text,
451 int image = -1, int selectedImage = -1,
452 wxTreeItemData *data = NULL);
453
454 // delete this item and associated data if any
455 void Delete(const wxTreeItemId& item);
456 // delete all children (but don't delete the item itself)
457 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
458 void DeleteChildren(const wxTreeItemId& item);
459 // delete all items from the tree
460 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
461 void DeleteAllItems();
462
463 // expand this item
464 void Expand(const wxTreeItemId& item);
465 // expand this item and all subitems recursively
466 void ExpandAll(const wxTreeItemId& item);
467 // collapse the item without removing its children
468 void Collapse(const wxTreeItemId& item);
469 // collapse the item and remove all children
470 void CollapseAndReset(const wxTreeItemId& item);
471 // toggles the current state
472 void Toggle(const wxTreeItemId& item);
473
474 // remove the selection from currently selected item (if any)
475 void Unselect();
476 void UnselectAll();
477 // select this item
478 void SelectItem(const wxTreeItemId& item, bool unselect_others=TRUE,
479 bool extended_select=FALSE);
480 void SelectAll(bool extended_select=FALSE);
481 // make sure this item is visible (expanding the parent item and/or
482 // scrolling to this item if necessary)
483 void EnsureVisible(const wxTreeItemId& item);
484 // scroll to this item (but don't expand its parent)
485 void ScrollTo(const wxTreeItemId& item);
486 //void AdjustMyScrollbars();
487
488 // The first function is more portable (because easier to implement
489 // on other platforms), but the second one returns some extra info.
490 wxTreeItemId HitTest(const wxPoint& point)
491 { int dummy; return HitTest(point, dummy); }
492 wxTreeItemId HitTest(const wxPoint& point, int& flags)
493 { int col; return HitTest(point, flags, col); }
494 wxTreeItemId HitTest(const wxPoint& point, int& flags, int& column);
495
496 // get the bounding rectangle of the item (or of its label only)
497 bool GetBoundingRect(const wxTreeItemId& item,
498 wxRect& rect,
499 bool textOnly = FALSE) const;
500
501 // Start editing the item label: this (temporarily) replaces the item
502 // with a one line edit control. The item will be selected if it hadn't
503 // been before.
504 void EditLabel( const wxTreeItemId& item ) { Edit( item ); }
505 void Edit( const wxTreeItemId& item );
506
507 // sorting
508 // this function is called to compare 2 items and should return -1, 0
509 // or +1 if the first item is less than, equal to or greater than the
510 // second one. The base class version performs alphabetic comparaison
511 // of item labels (GetText)
512 virtual int OnCompareItems(const wxTreeItemId& item1,
513 const wxTreeItemId& item2);
514 // sort the children of this item using OnCompareItems
515 //
516 // NB: this function is not reentrant and not MT-safe (FIXME)!
517 void SortChildren(const wxTreeItemId& item);
518
519 // searching
520 wxTreeItemId FindItem (const wxTreeItemId& item, const wxString& str, int flags = 0);
521
522 // overridden base class virtuals
523 virtual bool SetBackgroundColour(const wxColour& colour);
524 virtual bool SetForegroundColour(const wxColour& colour);
525
526
527 wxTreeListHeaderWindow* GetHeaderWindow() const
528 { return m_header_win; }
529
530 wxTreeListMainWindow* GetMainWindow() const
531 { return m_main_win; }
532
533 virtual wxSize DoGetBestSize() const;
534
535 protected:
536 // header window, responsible for column visualization and manipulation
537 wxTreeListHeaderWindow* m_header_win;
538 // main window, the "true" tree ctrl
539 wxTreeListMainWindow* m_main_win;
540
541 // // the common part of all ctors
542 // void Init();
543
544 void OnSize(wxSizeEvent& event);
545
546
547 private:
548 size_t fill_column;
549
550 DECLARE_EVENT_TABLE()
551 DECLARE_DYNAMIC_CLASS(wxTreeListCtrl)
552 };
553
554 #endif // TREELISTCTRL_H
555