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
;
47 //-----------------------------------------------------------------------------
48 // wxTreeListColumnAttrs
49 //-----------------------------------------------------------------------------
51 enum wxTreeListColumnAlign
{
58 class GIZMODLLEXPORT wxTreeListColumnInfo
: public wxObject
{
60 enum { DEFAULT_COL_WIDTH
= 100 };
62 wxTreeListColumnInfo(const wxString
&text
= wxT(""),
64 size_t width
= DEFAULT_COL_WIDTH
,
66 wxTreeListColumnAlign alignment
= wxTL_ALIGN_LEFT
)
69 m_selected_image
= -1;
73 m_alignment
= alignment
;
76 wxTreeListColumnInfo(const wxTreeListColumnInfo
& other
)
78 m_image
= other
.m_image
;
79 m_selected_image
= other
.m_selected_image
;
80 m_text
= other
.m_text
;
81 m_width
= other
.m_width
;
82 m_shown
= other
.m_shown
;
83 m_alignment
= other
.m_alignment
;
86 ~wxTreeListColumnInfo() {}
89 bool GetShown() const { return m_shown
; }
90 wxTreeListColumnAlign
GetAlignment() const { return m_alignment
; }
91 wxString
GetText() const { return m_text
; }
92 int GetImage() const { return m_image
; }
93 int GetSelectedImage() const { return m_selected_image
; }
94 size_t GetWidth() const { return m_width
; }
97 wxTreeListColumnInfo
& SetShown(bool shown
)
98 { m_shown
= shown
; return *this; }
100 wxTreeListColumnInfo
& SetAlignment(wxTreeListColumnAlign alignment
)
101 { m_alignment
= alignment
; return *this; }
103 wxTreeListColumnInfo
& SetText(const wxString
& text
)
104 { m_text
= text
; return *this; }
106 wxTreeListColumnInfo
& SetImage(int image
)
107 { m_image
= image
; return *this; }
109 wxTreeListColumnInfo
& SetSelectedImage(int image
)
110 { m_selected_image
= image
; return *this; }
112 wxTreeListColumnInfo
& SetWidth(size_t with
)
113 { m_width
= with
; return *this; }
117 wxTreeListColumnAlign m_alignment
;
120 int m_selected_image
;
124 //----------------------------------------------------------------------------
125 // wxTreeListCtrl - the multicolumn tree control
126 //----------------------------------------------------------------------------
128 // flags for FindItem
129 const int wxTL_SEARCH_VISIBLE
= 0x0000;
130 const int wxTL_SEARCH_LEVEL
= 0x0001;
131 const int wxTL_SEARCH_FULL
= 0x0002;
132 const int wxTL_SEARCH_PARTIAL
= 0x0010;
133 const int wxTL_SEARCH_NOCASE
= 0x0020;
135 // additional flag for HitTest
136 const int wxTREE_HITTEST_ONITEMCOLUMN
= 0x2000;
137 extern GIZMODLLEXPORT
const wxChar
* wxTreeListCtrlNameStr
;
140 class GIZMODLLEXPORT wxTreeListCtrl
: public wxControl
147 wxTreeListCtrl(wxWindow
*parent
, wxWindowID id
= -1,
148 const wxPoint
& pos
= wxDefaultPosition
,
149 const wxSize
& size
= wxDefaultSize
,
150 long style
= wxTR_DEFAULT_STYLE
,
151 const wxValidator
&validator
= wxDefaultValidator
,
152 const wxString
& name
= wxTreeListCtrlNameStr
)
153 : m_header_win(0), m_main_win(0)
155 Create(parent
, id
, pos
, size
, style
, validator
, name
);
158 virtual ~wxTreeListCtrl() {}
160 bool Create(wxWindow
*parent
, wxWindowID id
= -1,
161 const wxPoint
& pos
= wxDefaultPosition
,
162 const wxSize
& size
= wxDefaultSize
,
163 long style
= wxTR_DEFAULT_STYLE
,
164 const wxValidator
&validator
= wxDefaultValidator
,
165 const wxString
& name
= wxTreeListCtrlNameStr
);
167 void Refresh(bool erase
=TRUE
, const wxRect
* rect
=NULL
);
172 // get the total number of items in the control
173 size_t GetCount() const;
175 // indent is the number of pixels the children are indented relative to
176 // the parents position. SetIndent() also redraws the control
178 unsigned int GetIndent() const;
179 void SetIndent(unsigned int indent
);
181 // line spacing is the space above and below the text on each line
182 unsigned int GetLineSpacing() const;
183 void SetLineSpacing(unsigned int spacing
);
185 // image list: these functions allow to associate an image list with
186 // the control and retrieve it. Note that when assigned with
187 // SetImageList, the control does _not_ delete
188 // the associated image list when it's deleted in order to allow image
189 // lists to be shared between different controls. If you use
190 // AssignImageList, the control _does_ delete the image list.
192 // The normal image list is for the icons which correspond to the
193 // normal tree item state (whether it is selected or not).
194 // Additionally, the application might choose to show a state icon
195 // which corresponds to an app-defined item state (for example,
196 // checked/unchecked) which are taken from the state image list.
197 wxImageList
*GetImageList() const;
198 wxImageList
*GetStateImageList() const;
199 wxImageList
*GetButtonsImageList() const;
201 void SetImageList(wxImageList
*imageList
);
202 void SetStateImageList(wxImageList
*imageList
);
203 void SetButtonsImageList(wxImageList
*imageList
);
204 void AssignImageList(wxImageList
*imageList
);
205 void AssignStateImageList(wxImageList
*imageList
);
206 void AssignButtonsImageList(wxImageList
*imageList
);
209 // Functions to work with tree list ctrl columns
212 void AddColumn(const wxString
& text
)
213 { AddColumn(wxTreeListColumnInfo(text
)); }
214 void AddColumn(const wxString
& text
,
216 wxTreeListColumnAlign alignment
= wxTL_ALIGN_LEFT
)
217 { AddColumn(wxTreeListColumnInfo(text
,
222 void AddColumn(const wxTreeListColumnInfo
& col
);
224 // inserts a column before the given one
225 void InsertColumn(size_t before
, const wxString
& text
)
226 { InsertColumn(before
, wxTreeListColumnInfo(text
)); }
227 void InsertColumn(size_t before
, const wxTreeListColumnInfo
& col
);
229 // deletes the given column - does not delete the corresponding column
231 void RemoveColumn(size_t column
);
233 // returns the number of columns in the ctrl
234 size_t GetColumnCount() const;
236 void SetColumnWidth(size_t column
, size_t width
);
237 int GetColumnWidth(size_t column
) const;
239 // tells which column is the "main" one, i.e. the "threaded" one
240 void SetMainColumn(size_t column
);
241 size_t GetMainColumn() const;
243 void SetColumnText(size_t column
, const wxString
& text
);
244 wxString
GetColumnText(size_t column
) const;
246 void SetColumn(size_t column
, const wxTreeListColumnInfo
& info
);
247 wxTreeListColumnInfo
& GetColumn(size_t column
);
248 const wxTreeListColumnInfo
& GetColumn(size_t column
) const;
250 // other column-related methods
251 void SetColumnAlignment(size_t column
, wxTreeListColumnAlign align
);
252 wxTreeListColumnAlign
GetColumnAlignment(size_t column
) const;
254 void SetColumnImage(size_t column
, int image
);
255 int GetColumnImage(size_t column
) const;
257 void ShowColumn(size_t column
, bool shown
);
258 bool IsColumnShown(size_t column
) const;
260 // Functions to work with tree list ctrl items.
265 // retrieve item's label (of the main column)
266 wxString
GetItemText(const wxTreeItemId
& item
) const
267 { return GetItemText(item
, GetMainColumn()); }
268 // retrieves item's label of the given column
269 wxString
GetItemText(const wxTreeItemId
& item
, size_t column
) const;
271 // get one of the images associated with the item (normal by default)
272 int GetItemImage(const wxTreeItemId
& item
,
273 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
274 { return GetItemImage(item
, GetMainColumn(), which
); }
275 int GetItemImage(const wxTreeItemId
& item
, size_t column
,
276 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const;
278 // get the data associated with the item
279 wxTreeItemData
*GetItemData(const wxTreeItemId
& item
) const;
281 bool GetItemBold(const wxTreeItemId
& item
) const;
282 wxColour
GetItemTextColour(const wxTreeItemId
& item
) const;
283 wxColour
GetItemBackgroundColour(const wxTreeItemId
& item
) const;
284 wxFont
GetItemFont(const wxTreeItemId
& item
) const;
290 void SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
291 { SetItemText(item
, GetMainColumn(), text
); }
292 void SetItemText(const wxTreeItemId
& item
, size_t column
,
293 const wxString
& text
);
295 // get one of the images associated with the item (normal by default)
296 void SetItemImage(const wxTreeItemId
& item
, int image
,
297 wxTreeItemIcon which
= wxTreeItemIcon_Normal
)
298 { SetItemImage(item
, GetMainColumn(), image
, which
); }
299 // the which parameter is ignored for all columns but the main one
300 void SetItemImage(const wxTreeItemId
& item
, size_t column
, int image
,
301 wxTreeItemIcon which
= wxTreeItemIcon_Normal
);
303 // associate some data with the item
304 void SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
);
306 // force appearance of [+] button near the item. This is useful to
307 // allow the user to expand the items which don't have any children now
308 // - but instead add them only when needed, thus minimizing memory
309 // usage and loading time.
310 void SetItemHasChildren(const wxTreeItemId
& item
, bool has
= TRUE
);
312 // the item will be shown in bold
313 void SetItemBold(const wxTreeItemId
& item
, bool bold
= TRUE
);
315 // set the item's text colour
316 void SetItemTextColour(const wxTreeItemId
& item
, const wxColour
& colour
);
318 // set the item's background colour
319 void SetItemBackgroundColour(const wxTreeItemId
& item
, const wxColour
& colour
);
321 // set the item's font (should be of the same height for all items)
322 void SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
);
324 // set the window font
325 virtual bool SetFont( const wxFont
&font
);
328 void SetWindowStyle(const long styles
);
329 long GetWindowStyle() const;
330 long GetWindowStyleFlag() const { return GetWindowStyle(); }
332 // item status inquiries
333 // ---------------------
335 // is the item visible (it might be outside the view or not expanded)?
336 bool IsVisible(const wxTreeItemId
& item
) const;
337 // does the item has any children?
338 bool HasChildren(const wxTreeItemId
& item
) const
339 { return ItemHasChildren(item
); }
340 bool ItemHasChildren(const wxTreeItemId
& item
) const;
341 // is the item expanded (only makes sense if HasChildren())?
342 bool IsExpanded(const wxTreeItemId
& item
) const;
343 // is this item currently selected (the same as has focus)?
344 bool IsSelected(const wxTreeItemId
& item
) const;
345 // is item text in bold font?
346 bool IsBold(const wxTreeItemId
& item
) const;
347 // does the layout include space for a button?
349 // number of children
350 // ------------------
352 // if 'recursively' is FALSE, only immediate children count, otherwise
353 // the returned number is the number of all items in this branch
354 size_t GetChildrenCount(const wxTreeItemId
& item
, bool recursively
= TRUE
);
359 // wxTreeItemId.IsOk() will return FALSE if there is no such item
361 // get the root tree item
362 wxTreeItemId
GetRootItem() const;
364 // get the item currently selected (may return NULL if no selection)
365 wxTreeItemId
GetSelection() const;
367 // get the items currently selected, return the number of such item
368 size_t GetSelections(wxArrayTreeItemIds
&) const;
370 // get the parent of this item (may return NULL if root)
371 wxTreeItemId
GetItemParent(const wxTreeItemId
& item
) const;
373 // for this enumeration function you must pass in a "cookie" parameter
374 // which is opaque for the application but is necessary for the library
375 // to make these functions reentrant (i.e. allow more than one
376 // enumeration on one and the same object simultaneously). Of course,
377 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
380 // get the first child of this item
381 #if !wxCHECK_VERSION(2, 5, 0)
382 wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const;
384 wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const;
386 // get the next child
387 #if !wxCHECK_VERSION(2, 5, 0)
388 wxTreeItemId
GetNextChild(const wxTreeItemId
& item
, long& cookie
) const;
390 wxTreeItemId
GetNextChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const;
392 // get the prev child
393 #if !wxCHECK_VERSION(2, 5, 0)
394 wxTreeItemId
GetPrevChild(const wxTreeItemId
& item
, long& cookie
) const;
396 wxTreeItemId
GetPrevChild(const wxTreeItemId
& item
, wxTreeItemIdValue
& cookie
) const;
398 // get the last child of this item - this method doesn't use cookies
399 wxTreeItemId
GetLastChild(const wxTreeItemId
& item
) const;
401 // get the next sibling of this item
402 wxTreeItemId
GetNextSibling(const wxTreeItemId
& item
) const;
403 // get the previous sibling
404 wxTreeItemId
GetPrevSibling(const wxTreeItemId
& item
) const;
406 // get first visible item
407 wxTreeItemId
GetFirstVisibleItem() const;
408 // get the next visible item: item must be visible itself!
409 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
410 wxTreeItemId
GetNextVisible(const wxTreeItemId
& item
) const;
411 // get the previous visible item: item must be visible itself!
412 wxTreeItemId
GetPrevVisible(const wxTreeItemId
& item
) const;
414 // Only for internal use right now, but should probably be public
415 wxTreeItemId
GetNext(const wxTreeItemId
& item
) const;
420 // add the root node to the tree
421 wxTreeItemId
AddRoot(const wxString
& text
,
422 int image
= -1, int selectedImage
= -1,
423 wxTreeItemData
*data
= NULL
);
425 // insert a new item in as the first child of the parent
426 wxTreeItemId
PrependItem(const wxTreeItemId
& parent
,
427 const wxString
& text
,
428 int image
= -1, int selectedImage
= -1,
429 wxTreeItemData
*data
= NULL
);
431 // insert a new item after a given one
432 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
433 const wxTreeItemId
& idPrevious
,
434 const wxString
& text
,
435 int image
= -1, int selectedImage
= -1,
436 wxTreeItemData
*data
= NULL
);
438 // insert a new item before the one with the given index
439 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
441 const wxString
& text
,
442 int image
= -1, int selectedImage
= -1,
443 wxTreeItemData
*data
= NULL
);
445 // insert a new item in as the last child of the parent
446 wxTreeItemId
AppendItem(const wxTreeItemId
& parent
,
447 const wxString
& text
,
448 int image
= -1, int selectedImage
= -1,
449 wxTreeItemData
*data
= NULL
);
451 // delete this item and associated data if any
452 void Delete(const wxTreeItemId
& item
);
453 // delete all children (but don't delete the item itself)
454 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
455 void DeleteChildren(const wxTreeItemId
& item
);
456 // delete all items from the tree
457 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
458 void DeleteAllItems();
461 void Expand(const wxTreeItemId
& item
);
462 // expand this item and all subitems recursively
463 void ExpandAll(const wxTreeItemId
& item
);
464 // collapse the item without removing its children
465 void Collapse(const wxTreeItemId
& item
);
466 // collapse the item and remove all children
467 void CollapseAndReset(const wxTreeItemId
& item
);
468 // toggles the current state
469 void Toggle(const wxTreeItemId
& item
);
471 // remove the selection from currently selected item (if any)
475 void SelectItem(const wxTreeItemId
& item
, bool unselect_others
=TRUE
,
476 bool extended_select
=FALSE
);
477 void SelectAll(bool extended_select
=FALSE
);
478 // make sure this item is visible (expanding the parent item and/or
479 // scrolling to this item if necessary)
480 void EnsureVisible(const wxTreeItemId
& item
);
481 // scroll to this item (but don't expand its parent)
482 void ScrollTo(const wxTreeItemId
& item
);
483 //void AdjustMyScrollbars();
485 // The first function is more portable (because easier to implement
486 // on other platforms), but the second one returns some extra info.
487 wxTreeItemId
HitTest(const wxPoint
& point
)
488 { int dummy
; return HitTest(point
, dummy
); }
489 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
)
490 { int col
; return HitTest(point
, flags
, col
); }
491 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
, int& column
);
493 // get the bounding rectangle of the item (or of its label only)
494 bool GetBoundingRect(const wxTreeItemId
& item
,
496 bool textOnly
= FALSE
) const;
498 // Start editing the item label: this (temporarily) replaces the item
499 // with a one line edit control. The item will be selected if it hadn't
501 void EditLabel( const wxTreeItemId
& item
) { Edit( item
); }
502 void Edit( const wxTreeItemId
& item
);
505 // this function is called to compare 2 items and should return -1, 0
506 // or +1 if the first item is less than, equal to or greater than the
507 // second one. The base class version performs alphabetic comparaison
508 // of item labels (GetText)
509 virtual int OnCompareItems(const wxTreeItemId
& item1
,
510 const wxTreeItemId
& item2
);
511 // sort the children of this item using OnCompareItems
513 // NB: this function is not reentrant and not MT-safe (FIXME)!
514 void SortChildren(const wxTreeItemId
& item
);
517 wxTreeItemId
FindItem (const wxTreeItemId
& item
, const wxString
& str
, int flags
= 0);
519 // overridden base class virtuals
520 virtual bool SetBackgroundColour(const wxColour
& colour
);
521 virtual bool SetForegroundColour(const wxColour
& colour
);
524 wxTreeListHeaderWindow
* GetHeaderWindow() const
525 { return m_header_win
; }
527 wxTreeListMainWindow
* GetMainWindow() const
528 { return m_main_win
; }
531 // header window, responsible for column visualization and manipulation
532 wxTreeListHeaderWindow
* m_header_win
;
533 // main window, the "true" tree ctrl
534 wxTreeListMainWindow
* m_main_win
;
536 // // the common part of all ctors
539 void OnSize(wxSizeEvent
& event
);
545 DECLARE_EVENT_TABLE()
546 DECLARE_DYNAMIC_CLASS(wxTreeListCtrl
)
549 #endif // TREELISTCTRL_H