1 /////////////////////////////////////////////////////////////////////////////
2 // Name: treelistctrl.h
3 // Purpose: wxTreeListCtrl class
4 // Author: Robert Roebling
5 // Modified by: Alberto Griggio, 2002
8 // Copyright: (c) Robert Roebling, Julian Smart, Alberto Griggio,
9 // Vadim Zeitlin, Otto Wyss
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
14 #ifndef TREELISTCTRL_H
15 #define TREELISTCTRL_H
17 #if defined(__GNUG__) && !defined(__APPLE__)
18 #pragma interface "treelistctrl.h"
21 #include <wx/treectrl.h>
22 #include <wx/control.h>
24 #include <wx/listctrl.h> // for wxListEvent
27 #define GIZMODLLEXPORT WXDLLEXPORT
29 #define GIZMODLLEXPORT
33 class GIZMODLLEXPORT wxTreeListItem
;
34 class GIZMODLLEXPORT wxTreeListHeaderWindow
;
35 class GIZMODLLEXPORT wxTreeListMainWindow
;
38 // Using this typedef removes an ambiguity when calling Remove()
40 #if !wxCHECK_VERSION(2, 5, 0)
41 typedef long wxTreeItemIdValue
;
43 typedef void *wxTreeItemIdValue
;
48 #define wxTR_DONT_ADJUST_MAC 0x0100 // Don't adjust the style for the Mac
50 //-----------------------------------------------------------------------------
51 // wxTreeListColumnAttrs
52 //-----------------------------------------------------------------------------
54 enum wxTreeListColumnAlign
{
61 class GIZMODLLEXPORT wxTreeListColumnInfo
: public wxObject
{
63 enum { DEFAULT_COL_WIDTH
= 100 };
65 wxTreeListColumnInfo(const wxString
&text
= wxT(""),
67 size_t width
= DEFAULT_COL_WIDTH
,
69 wxTreeListColumnAlign alignment
= wxTL_ALIGN_LEFT
)
72 m_selected_image
= -1;
76 m_alignment
= alignment
;
79 wxTreeListColumnInfo(const wxTreeListColumnInfo
& other
)
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
;
89 ~wxTreeListColumnInfo() {}
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
; }
100 wxTreeListColumnInfo
& SetShown(bool shown
)
101 { m_shown
= shown
; return *this; }
103 wxTreeListColumnInfo
& SetAlignment(wxTreeListColumnAlign alignment
)
104 { m_alignment
= alignment
; return *this; }
106 wxTreeListColumnInfo
& SetText(const wxString
& text
)
107 { m_text
= text
; return *this; }
109 wxTreeListColumnInfo
& SetImage(int image
)
110 { m_image
= image
; return *this; }
112 wxTreeListColumnInfo
& SetSelectedImage(int image
)
113 { m_selected_image
= image
; return *this; }
115 wxTreeListColumnInfo
& SetWidth(size_t with
)
116 { m_width
= with
; return *this; }
120 wxTreeListColumnAlign m_alignment
;
123 int m_selected_image
;
127 //----------------------------------------------------------------------------
128 // wxTreeListCtrl - the multicolumn tree control
129 //----------------------------------------------------------------------------
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;
138 // additional flag for HitTest
139 const int wxTREE_HITTEST_ONITEMCOLUMN
= 0x2000;
140 extern GIZMODLLEXPORT
const wxChar
* wxTreeListCtrlNameStr
;
143 class GIZMODLLEXPORT wxTreeListCtrl
: public wxControl
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)
158 Create(parent
, id
, pos
, size
, style
, validator
, name
);
161 virtual ~wxTreeListCtrl() {}
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
);
170 void Refresh(bool erase
=TRUE
, const wxRect
* rect
=NULL
);
175 // get the total number of items in the control
176 size_t GetCount() const;
178 // indent is the number of pixels the children are indented relative to
179 // the parents position. SetIndent() also redraws the control
181 unsigned int GetIndent() const;
182 void SetIndent(unsigned int indent
);
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
);
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.
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;
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
);
212 // Functions to work with tree list ctrl columns
215 void AddColumn(const wxString
& text
)
216 { AddColumn(wxTreeListColumnInfo(text
)); }
217 void AddColumn(const wxString
& text
,
219 wxTreeListColumnAlign alignment
= wxTL_ALIGN_LEFT
)
220 { AddColumn(wxTreeListColumnInfo(text
,
225 void AddColumn(const wxTreeListColumnInfo
& col
);
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
);
232 // deletes the given column - does not delete the corresponding column
234 void RemoveColumn(size_t column
);
236 // returns the number of columns in the ctrl
237 size_t GetColumnCount() const;
239 void SetColumnWidth(size_t column
, size_t width
);
240 int GetColumnWidth(size_t column
) const;
242 // tells which column is the "main" one, i.e. the "threaded" one
243 void SetMainColumn(size_t column
);
244 size_t GetMainColumn() const;
246 void SetColumnText(size_t column
, const wxString
& text
);
247 wxString
GetColumnText(size_t column
) const;
249 void SetColumn(size_t column
, const wxTreeListColumnInfo
& info
);
250 wxTreeListColumnInfo
& GetColumn(size_t column
);
251 const wxTreeListColumnInfo
& GetColumn(size_t column
) const;
253 // other column-related methods
254 void SetColumnAlignment(size_t column
, wxTreeListColumnAlign align
);
255 wxTreeListColumnAlign
GetColumnAlignment(size_t column
) const;
257 void SetColumnImage(size_t column
, int image
);
258 int GetColumnImage(size_t column
) const;
260 void ShowColumn(size_t column
, bool shown
);
261 bool IsColumnShown(size_t column
) const;
263 // Functions to work with tree list ctrl items.
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;
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;
281 // get the data associated with the item
282 wxTreeItemData
*GetItemData(const wxTreeItemId
& item
) const;
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;
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
);
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
);
306 // associate some data with the item
307 void SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
);
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
);
315 // the item will be shown in bold
316 void SetItemBold(const wxTreeItemId
& item
, bool bold
= TRUE
);
318 // set the item's text colour
319 void SetItemTextColour(const wxTreeItemId
& item
, const wxColour
& colour
);
321 // set the item's background colour
322 void SetItemBackgroundColour(const wxTreeItemId
& item
, const wxColour
& colour
);
324 // set the item's font (should be of the same height for all items)
325 void SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
);
327 // set the window font
328 virtual bool SetFont( const wxFont
&font
);
331 void SetWindowStyle(const long styles
);
332 long GetWindowStyle() const;
333 long GetWindowStyleFlag() const { return GetWindowStyle(); }
335 // item status inquiries
336 // ---------------------
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?
352 // number of children
353 // ------------------
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
);
362 // wxTreeItemId.IsOk() will return FALSE if there is no such item
364 // get the root tree item
365 wxTreeItemId
GetRootItem() const;
367 // get the item currently selected (may return NULL if no selection)
368 wxTreeItemId
GetSelection() const;
370 // get the items currently selected, return the number of such item
371 size_t GetSelections(wxArrayTreeItemIds
&) const;
373 // get the parent of this item (may return NULL if root)
374 wxTreeItemId
GetItemParent(const wxTreeItemId
& item
) const;
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
383 // get the first child of this item
384 #if !wxCHECK_VERSION(2, 5, 0)
385 wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const;
387 wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const;
389 // get the next child
390 #if !wxCHECK_VERSION(2, 5, 0)
391 wxTreeItemId
GetNextChild(const wxTreeItemId
& item
, long& cookie
) const;
393 wxTreeItemId
GetNextChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const;
395 // get the prev child
396 #if !wxCHECK_VERSION(2, 5, 0)
397 wxTreeItemId
GetPrevChild(const wxTreeItemId
& item
, long& cookie
) const;
399 wxTreeItemId
GetPrevChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const;
401 // get the last child of this item - this method doesn't use cookies
402 wxTreeItemId
GetLastChild(const wxTreeItemId
& item
) const;
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;
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;
417 // Only for internal use right now, but should probably be public
418 wxTreeItemId
GetNext(const wxTreeItemId
& item
) const;
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
);
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
);
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
);
441 // insert a new item before the one with the given index
442 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
444 const wxString
& text
,
445 int image
= -1, int selectedImage
= -1,
446 wxTreeItemData
*data
= NULL
);
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
);
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();
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
);
474 // remove the selection from currently selected item (if any)
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();
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
);
496 // get the bounding rectangle of the item (or of its label only)
497 bool GetBoundingRect(const wxTreeItemId
& item
,
499 bool textOnly
= FALSE
) const;
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
504 void EditLabel( const wxTreeItemId
& item
) { Edit( item
); }
505 void Edit( const wxTreeItemId
& item
);
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
516 // NB: this function is not reentrant and not MT-safe (FIXME)!
517 void SortChildren(const wxTreeItemId
& item
);
520 wxTreeItemId
FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags
= 0);
522 // overridden base class virtuals
523 virtual bool SetBackgroundColour(const wxColour
& colour
);
524 virtual bool SetForegroundColour(const wxColour
& colour
);
527 wxTreeListHeaderWindow
* GetHeaderWindow() const
528 { return m_header_win
; }
530 wxTreeListMainWindow
* GetMainWindow() const
531 { return m_main_win
; }
533 virtual wxSize
DoGetBestSize() const;
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
;
541 // // the common part of all ctors
544 void OnSize(wxSizeEvent
& event
);
550 DECLARE_EVENT_TABLE()
551 DECLARE_DYNAMIC_CLASS(wxTreeListCtrl
)
554 #endif // TREELISTCTRL_H