1 // -*- C++ -*- //////////////////////////////////////////////////////////////
2 // Name: treelistctrl.h (derived by wx/treectrlg.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
;
37 //-----------------------------------------------------------------------------
38 // wxTreeListColumnAttrs
39 //-----------------------------------------------------------------------------
41 enum wxTreeListColumnAlign
{
48 class GIZMODLLEXPORT wxTreeListColumnInfo
: public wxObject
{
50 enum { DEFAULT_COL_WIDTH
= 100 };
52 wxTreeListColumnInfo(const wxString
&text
= wxT(""),
54 size_t width
= DEFAULT_COL_WIDTH
,
56 wxTreeListColumnAlign alignment
= wxTL_ALIGN_LEFT
)
59 m_selected_image
= -1;
63 m_alignment
= alignment
;
66 wxTreeListColumnInfo(const wxTreeListColumnInfo
& other
)
68 m_image
= other
.m_image
;
69 m_selected_image
= other
.m_selected_image
;
70 m_text
= other
.m_text
;
71 m_width
= other
.m_width
;
72 m_shown
= other
.m_shown
;
73 m_alignment
= other
.m_alignment
;
76 ~wxTreeListColumnInfo() {}
79 bool GetShown() const { return m_shown
; }
80 wxTreeListColumnAlign
GetAlignment() const { return m_alignment
; }
81 wxString
GetText() const { return m_text
; }
82 int GetImage() const { return m_image
; }
83 int GetSelectedImage() const { return m_selected_image
; }
84 size_t GetWidth() const { return m_width
; }
87 wxTreeListColumnInfo
& SetShown(bool shown
)
88 { m_shown
= shown
; return *this; }
90 wxTreeListColumnInfo
& SetAlignment(wxTreeListColumnAlign alignment
)
91 { m_alignment
= alignment
; return *this; }
93 wxTreeListColumnInfo
& SetText(const wxString
& text
)
94 { m_text
= text
; return *this; }
96 wxTreeListColumnInfo
& SetImage(int image
)
97 { m_image
= image
; return *this; }
99 wxTreeListColumnInfo
& SetSelectedImage(int image
)
100 { m_selected_image
= image
; return *this; }
102 wxTreeListColumnInfo
& SetWidth(size_t with
)
103 { m_width
= with
; return *this; }
107 wxTreeListColumnAlign m_alignment
;
110 int m_selected_image
;
114 //----------------------------------------------------------------------------
115 // wxTreeListCtrl - the multicolumn tree control
116 //----------------------------------------------------------------------------
118 // additional flag for HitTest
119 const int wxTREE_HITTEST_ONITEMCOLUMN
= 0x2000;
120 extern GIZMODLLEXPORT
const wxChar
* wxTreeListCtrlNameStr
;
123 class GIZMODLLEXPORT wxTreeListCtrl
: public wxControl
130 wxTreeListCtrl(wxWindow
*parent
, wxWindowID id
= -1,
131 const wxPoint
& pos
= wxDefaultPosition
,
132 const wxSize
& size
= wxDefaultSize
,
133 long style
= wxTR_DEFAULT_STYLE
,
134 const wxValidator
&validator
= wxDefaultValidator
,
135 const wxString
& name
= wxTreeListCtrlNameStr
)
136 : m_header_win(0), m_main_win(0)
138 Create(parent
, id
, pos
, size
, style
, validator
, name
);
141 virtual ~wxTreeListCtrl() {}
143 bool Create(wxWindow
*parent
, wxWindowID id
= -1,
144 const wxPoint
& pos
= wxDefaultPosition
,
145 const wxSize
& size
= wxDefaultSize
,
146 long style
= wxTR_DEFAULT_STYLE
,
147 const wxValidator
&validator
= wxDefaultValidator
,
148 const wxString
& name
= wxTreeListCtrlNameStr
);
150 void Refresh(bool erase
=TRUE
, const wxRect
* rect
=NULL
);
155 // get the total number of items in the control
156 size_t GetCount() const;
158 // indent is the number of pixels the children are indented relative to
159 // the parents position. SetIndent() also redraws the control
161 unsigned int GetIndent() const;
162 void SetIndent(unsigned int indent
);
164 // line spacing is the space above and below the text on each line
165 unsigned int GetLineSpacing() const;
166 void SetLineSpacing(unsigned int spacing
);
168 // image list: these functions allow to associate an image list with
169 // the control and retrieve it. Note that when assigned with
170 // SetImageList, the control does _not_ delete
171 // the associated image list when it's deleted in order to allow image
172 // lists to be shared between different controls. If you use
173 // AssignImageList, the control _does_ delete the image list.
175 // The normal image list is for the icons which correspond to the
176 // normal tree item state (whether it is selected or not).
177 // Additionally, the application might choose to show a state icon
178 // which corresponds to an app-defined item state (for example,
179 // checked/unchecked) which are taken from the state image list.
180 wxImageList
*GetImageList() const;
181 wxImageList
*GetStateImageList() const;
182 wxImageList
*GetButtonsImageList() const;
184 void SetImageList(wxImageList
*imageList
);
185 void SetStateImageList(wxImageList
*imageList
);
186 void SetButtonsImageList(wxImageList
*imageList
);
187 void AssignImageList(wxImageList
*imageList
);
188 void AssignStateImageList(wxImageList
*imageList
);
189 void AssignButtonsImageList(wxImageList
*imageList
);
192 // Functions to work with tree list ctrl columns
195 void AddColumn(const wxString
& text
)
196 { AddColumn(wxTreeListColumnInfo(text
)); }
197 void AddColumn(const wxString
& text
,
199 wxTreeListColumnAlign alignment
= wxTL_ALIGN_LEFT
)
200 { AddColumn(wxTreeListColumnInfo(text
,
205 void AddColumn(const wxTreeListColumnInfo
& col
);
207 // inserts a column before the given one
208 void InsertColumn(size_t before
, const wxString
& text
)
209 { InsertColumn(before
, wxTreeListColumnInfo(text
)); }
210 void InsertColumn(size_t before
, const wxTreeListColumnInfo
& col
);
212 // deletes the given column - does not delete the corresponding column
214 void RemoveColumn(size_t column
);
216 // returns the number of columns in the ctrl
217 size_t GetColumnCount() const;
219 void SetColumnWidth(size_t column
, size_t width
);
220 int GetColumnWidth(size_t column
) const;
222 // tells which column is the "main" one, i.e. the "threaded" one
223 void SetMainColumn(size_t column
);
224 size_t GetMainColumn() const;
226 void SetColumnText(size_t column
, const wxString
& text
);
227 wxString
GetColumnText(size_t column
) const;
229 void SetColumn(size_t column
, const wxTreeListColumnInfo
& info
);
230 wxTreeListColumnInfo
& GetColumn(size_t column
);
231 const wxTreeListColumnInfo
& GetColumn(size_t column
) const;
233 // other column-related methods
234 void SetColumnAlignment(size_t column
, wxTreeListColumnAlign align
);
235 wxTreeListColumnAlign
GetColumnAlignment(size_t column
) const;
237 void SetColumnImage(size_t column
, int image
);
238 int GetColumnImage(size_t column
) const;
240 void ShowColumn(size_t column
, bool shown
);
241 bool IsColumnShown(size_t column
) const;
243 // Functions to work with tree list ctrl items.
248 // retrieve item's label (of the main column)
249 wxString
GetItemText(const wxTreeItemId
& item
) const
250 { return GetItemText(item
, GetMainColumn()); }
251 // retrieves item's label of the given column
252 wxString
GetItemText(const wxTreeItemId
& item
, size_t column
) const;
254 // get one of the images associated with the item (normal by default)
255 int GetItemImage(const wxTreeItemId
& item
,
256 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
257 { return GetItemImage(item
, GetMainColumn(), which
); }
258 int GetItemImage(const wxTreeItemId
& item
, size_t column
,
259 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const;
261 // get the data associated with the item
262 wxTreeItemData
*GetItemData(const wxTreeItemId
& item
) const;
264 bool GetItemBold(const wxTreeItemId
& item
) const;
265 wxColour
GetItemTextColour(const wxTreeItemId
& item
) const;
266 wxColour
GetItemBackgroundColour(const wxTreeItemId
& item
) const;
267 wxFont
GetItemFont(const wxTreeItemId
& item
) const;
273 void SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
274 { SetItemText(item
, GetMainColumn(), text
); }
275 void SetItemText(const wxTreeItemId
& item
, size_t column
,
276 const wxString
& text
);
278 // get one of the images associated with the item (normal by default)
279 void SetItemImage(const wxTreeItemId
& item
, int image
,
280 wxTreeItemIcon which
= wxTreeItemIcon_Normal
)
281 { SetItemImage(item
, GetMainColumn(), image
, which
); }
282 // the which parameter is ignored for all columns but the main one
283 void SetItemImage(const wxTreeItemId
& item
, size_t column
, int image
,
284 wxTreeItemIcon which
= wxTreeItemIcon_Normal
);
286 // associate some data with the item
287 void SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
);
289 // force appearance of [+] button near the item. This is useful to
290 // allow the user to expand the items which don't have any children now
291 // - but instead add them only when needed, thus minimizing memory
292 // usage and loading time.
293 void SetItemHasChildren(const wxTreeItemId
& item
, bool has
= TRUE
);
295 // the item will be shown in bold
296 void SetItemBold(const wxTreeItemId
& item
, bool bold
= TRUE
);
298 // set the item's text colour
299 void SetItemTextColour(const wxTreeItemId
& item
, const wxColour
& colour
);
301 // set the item's background colour
302 void SetItemBackgroundColour(const wxTreeItemId
& item
, const wxColour
& colour
);
304 // set the item's font (should be of the same height for all items)
305 void SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
);
307 // set the window font
308 virtual bool SetFont( const wxFont
&font
);
311 void SetWindowStyle(const long styles
);
312 long GetWindowStyle() const;
313 long GetWindowStyleFlag() const { return GetWindowStyle(); }
315 // item status inquiries
316 // ---------------------
318 // is the item visible (it might be outside the view or not expanded)?
319 bool IsVisible(const wxTreeItemId
& item
) const;
320 // does the item has any children?
321 bool HasChildren(const wxTreeItemId
& item
) const
322 { return ItemHasChildren(item
); }
323 bool ItemHasChildren(const wxTreeItemId
& item
) const;
324 // is the item expanded (only makes sense if HasChildren())?
325 bool IsExpanded(const wxTreeItemId
& item
) const;
326 // is this item currently selected (the same as has focus)?
327 bool IsSelected(const wxTreeItemId
& item
) const;
328 // is item text in bold font?
329 bool IsBold(const wxTreeItemId
& item
) const;
330 // does the layout include space for a button?
332 // number of children
333 // ------------------
335 // if 'recursively' is FALSE, only immediate children count, otherwise
336 // the returned number is the number of all items in this branch
337 size_t GetChildrenCount(const wxTreeItemId
& item
, bool recursively
= TRUE
);
342 // wxTreeItemId.IsOk() will return FALSE if there is no such item
344 // get the root tree item
345 wxTreeItemId
GetRootItem() const;
347 // get the item currently selected (may return NULL if no selection)
348 wxTreeItemId
GetSelection() const;
350 // get the items currently selected, return the number of such item
351 size_t GetSelections(wxArrayTreeItemIds
&) const;
353 // get the parent of this item (may return NULL if root)
354 wxTreeItemId
GetItemParent(const wxTreeItemId
& item
) const;
356 // for this enumeration function you must pass in a "cookie" parameter
357 // which is opaque for the application but is necessary for the library
358 // to make these functions reentrant (i.e. allow more than one
359 // enumeration on one and the same object simultaneously). Of course,
360 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
363 // get the first child of this item
364 wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const;
365 // get the next child
366 wxTreeItemId
GetNextChild(const wxTreeItemId
& item
, long& cookie
) const;
367 // get the last child of this item - this method doesn't use cookies
368 wxTreeItemId
GetLastChild(const wxTreeItemId
& item
) const;
370 // get the next sibling of this item
371 wxTreeItemId
GetNextSibling(const wxTreeItemId
& item
) const;
372 // get the previous sibling
373 wxTreeItemId
GetPrevSibling(const wxTreeItemId
& item
) const;
375 // get first visible item
376 wxTreeItemId
GetFirstVisibleItem() const;
377 // get the next visible item: item must be visible itself!
378 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
379 wxTreeItemId
GetNextVisible(const wxTreeItemId
& item
) const;
380 // get the previous visible item: item must be visible itself!
381 wxTreeItemId
GetPrevVisible(const wxTreeItemId
& item
) const;
383 // Only for internal use right now, but should probably be public
384 wxTreeItemId
GetNext(const wxTreeItemId
& item
) const;
389 // add the root node to the tree
390 wxTreeItemId
AddRoot(const wxString
& text
,
391 int image
= -1, int selectedImage
= -1,
392 wxTreeItemData
*data
= NULL
);
394 // insert a new item in as the first child of the parent
395 wxTreeItemId
PrependItem(const wxTreeItemId
& parent
,
396 const wxString
& text
,
397 int image
= -1, int selectedImage
= -1,
398 wxTreeItemData
*data
= NULL
);
400 // insert a new item after a given one
401 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
402 const wxTreeItemId
& idPrevious
,
403 const wxString
& text
,
404 int image
= -1, int selectedImage
= -1,
405 wxTreeItemData
*data
= NULL
);
407 // insert a new item before the one with the given index
408 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
410 const wxString
& text
,
411 int image
= -1, int selectedImage
= -1,
412 wxTreeItemData
*data
= NULL
);
414 // insert a new item in as the last child of the parent
415 wxTreeItemId
AppendItem(const wxTreeItemId
& parent
,
416 const wxString
& text
,
417 int image
= -1, int selectedImage
= -1,
418 wxTreeItemData
*data
= NULL
);
420 // delete this item and associated data if any
421 void Delete(const wxTreeItemId
& item
);
422 // delete all children (but don't delete the item itself)
423 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
424 void DeleteChildren(const wxTreeItemId
& item
);
425 // delete all items from the tree
426 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
427 void DeleteAllItems();
430 void Expand(const wxTreeItemId
& item
);
431 // expand this item and all subitems recursively
432 void ExpandAll(const wxTreeItemId
& item
);
433 // collapse the item without removing its children
434 void Collapse(const wxTreeItemId
& item
);
435 // collapse the item and remove all children
436 void CollapseAndReset(const wxTreeItemId
& item
);
437 // toggles the current state
438 void Toggle(const wxTreeItemId
& item
);
440 // remove the selection from currently selected item (if any)
444 void SelectItem(const wxTreeItemId
& item
, bool unselect_others
=TRUE
,
445 bool extended_select
=FALSE
);
446 void SelectAll(bool extended_select
=FALSE
);
447 // make sure this item is visible (expanding the parent item and/or
448 // scrolling to this item if necessary)
449 void EnsureVisible(const wxTreeItemId
& item
);
450 // scroll to this item (but don't expand its parent)
451 void ScrollTo(const wxTreeItemId
& item
);
452 //void AdjustMyScrollbars();
454 // The first function is more portable (because easier to implement
455 // on other platforms), but the second one returns some extra info.
456 wxTreeItemId
HitTest(const wxPoint
& point
)
457 { int dummy
; return HitTest(point
, dummy
); }
458 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
)
459 { int col
; return HitTest(point
, flags
, col
); }
460 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
, int& column
);
462 // get the bounding rectangle of the item (or of its label only)
463 bool GetBoundingRect(const wxTreeItemId
& item
,
465 bool textOnly
= FALSE
) const;
467 // Start editing the item label: this (temporarily) replaces the item
468 // with a one line edit control. The item will be selected if it hadn't
470 void EditLabel( const wxTreeItemId
& item
) { Edit( item
); }
471 void Edit( const wxTreeItemId
& item
);
474 // this function is called to compare 2 items and should return -1, 0
475 // or +1 if the first item is less than, equal to or greater than the
476 // second one. The base class version performs alphabetic comparaison
477 // of item labels (GetText)
478 virtual int OnCompareItems(const wxTreeItemId
& item1
,
479 const wxTreeItemId
& item2
);
480 // sort the children of this item using OnCompareItems
482 // NB: this function is not reentrant and not MT-safe (FIXME)!
483 void SortChildren(const wxTreeItemId
& item
);
485 // overridden base class virtuals
486 virtual bool SetBackgroundColour(const wxColour
& colour
);
487 virtual bool SetForegroundColour(const wxColour
& colour
);
490 wxTreeListHeaderWindow
* GetHeaderWindow() const
491 { return m_header_win
; }
493 wxTreeListMainWindow
* GetMainWindow() const
494 { return m_main_win
; }
497 // header window, responsible for column visualization and manipulation
498 wxTreeListHeaderWindow
* m_header_win
;
499 // main window, the "true" tree ctrl
500 wxTreeListMainWindow
* m_main_win
;
502 // // the common part of all ctors
505 void OnSize(wxSizeEvent
& event
);
511 DECLARE_EVENT_TABLE()
512 DECLARE_DYNAMIC_CLASS(wxTreeListCtrl
)
515 #endif // TREELISTCTRL_H