]> git.saurik.com Git - wxWidgets.git/blame - wxPython/contrib/gizmos/wxCode/include/wx/treelistctrl.h
reSWIGged
[wxWidgets.git] / wxPython / contrib / gizmos / wxCode / include / wx / treelistctrl.h
CommitLineData
28eab81f
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: treelistctrl.h
1fded56b
RD
3// Purpose: wxTreeListCtrl class
4// Author: Robert Roebling
5// Modified by: Alberto Griggio, 2002
6// Created: 01/02/97
7// RCS-ID: $Id$
28eab81f
RD
8// Copyright: (c) Robert Roebling, Julian Smart, Alberto Griggio,
9// Vadim Zeitlin, Otto Wyss
1fded56b
RD
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
33class GIZMODLLEXPORT wxTreeListItem;
34class GIZMODLLEXPORT wxTreeListHeaderWindow;
35class GIZMODLLEXPORT wxTreeListMainWindow;
36
28eab81f
RD
37
38// Using this typedef removes an ambiguity when calling Remove()
39#ifdef __WXMSW__
40#if !wxCHECK_VERSION(2, 5, 0)
41typedef long wxTreeItemIdValue;
42#else
43typedef void *wxTreeItemIdValue;
44#endif
45#endif
46
1fded56b
RD
47//-----------------------------------------------------------------------------
48// wxTreeListColumnAttrs
49//-----------------------------------------------------------------------------
50
51enum wxTreeListColumnAlign {
52 wxTL_ALIGN_LEFT,
53 wxTL_ALIGN_RIGHT,
54 wxTL_ALIGN_CENTER
55};
56
57
58class GIZMODLLEXPORT wxTreeListColumnInfo: public wxObject {
59public:
60 enum { DEFAULT_COL_WIDTH = 100 };
61
28eab81f 62 wxTreeListColumnInfo(const wxString &text = wxT(""),
1fded56b
RD
63 int image = -1,
64 size_t width = DEFAULT_COL_WIDTH,
28eab81f 65 bool shown = true,
1fded56b
RD
66 wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT)
67 {
68 m_image = image;
69 m_selected_image = -1;
70 m_text = text;
71 m_width = width;
28eab81f 72 m_shown = shown;
1fded56b
RD
73 m_alignment = alignment;
74 }
75
76 wxTreeListColumnInfo(const wxTreeListColumnInfo& other)
77 {
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;
28eab81f 82 m_shown = other.m_shown;
1fded56b
RD
83 m_alignment = other.m_alignment;
84 }
85
86 ~wxTreeListColumnInfo() {}
87
88 // getters
28eab81f 89 bool GetShown() const { return m_shown; }
1fded56b
RD
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; }
95
96 // setters
28eab81f
RD
97 wxTreeListColumnInfo& SetShown(bool shown)
98 { m_shown = shown; return *this; }
99
1fded56b
RD
100 wxTreeListColumnInfo& SetAlignment(wxTreeListColumnAlign alignment)
101 { m_alignment = alignment; return *this; }
102
103 wxTreeListColumnInfo& SetText(const wxString& text)
104 { m_text = text; return *this; }
105
106 wxTreeListColumnInfo& SetImage(int image)
107 { m_image = image; return *this; }
108
109 wxTreeListColumnInfo& SetSelectedImage(int image)
110 { m_selected_image = image; return *this; }
111
112 wxTreeListColumnInfo& SetWidth(size_t with)
113 { m_width = with; return *this; }
114
115private:
28eab81f 116 bool m_shown;
1fded56b
RD
117 wxTreeListColumnAlign m_alignment;
118 wxString m_text;
119 int m_image;
120 int m_selected_image;
121 size_t m_width;
122};
123
124//----------------------------------------------------------------------------
125// wxTreeListCtrl - the multicolumn tree control
126//----------------------------------------------------------------------------
127
28eab81f
RD
128// flags for FindItem
129const int wxTL_SEARCH_VISIBLE = 0x0000;
130const int wxTL_SEARCH_LEVEL = 0x0001;
131const int wxTL_SEARCH_FULL = 0x0002;
132const int wxTL_SEARCH_PARTIAL = 0x0010;
133const int wxTL_SEARCH_NOCASE = 0x0020;
134
1fded56b
RD
135// additional flag for HitTest
136const int wxTREE_HITTEST_ONITEMCOLUMN = 0x2000;
137extern GIZMODLLEXPORT const wxChar* wxTreeListCtrlNameStr;
138
139
140class GIZMODLLEXPORT wxTreeListCtrl : public wxControl
141{
142public:
143 // creation
144 // --------
145 wxTreeListCtrl() {}
146
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)
154 {
155 Create(parent, id, pos, size, style, validator, name);
156 }
157
158 virtual ~wxTreeListCtrl() {}
159
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 );
166
167 void Refresh(bool erase=TRUE, const wxRect* rect=NULL);
168 void SetFocus();
169 // accessors
170 // ---------
171
28eab81f 172 // get the total number of items in the control
1fded56b
RD
173 size_t GetCount() const;
174
28eab81f
RD
175 // indent is the number of pixels the children are indented relative to
176 // the parents position. SetIndent() also redraws the control
177 // immediately.
1fded56b
RD
178 unsigned int GetIndent() const;
179 void SetIndent(unsigned int indent);
180
1fded56b
RD
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);
184
28eab81f
RD
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.
191 //
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.
1fded56b
RD
197 wxImageList *GetImageList() const;
198 wxImageList *GetStateImageList() const;
199 wxImageList *GetButtonsImageList() const;
200
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);
207
208
209 // Functions to work with tree list ctrl columns
210
211 // adds a column
212 void AddColumn(const wxString& text)
28eab81f
RD
213 { AddColumn(wxTreeListColumnInfo(text)); }
214 void AddColumn(const wxString& text,
215 size_t width,
216 wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT)
217 { AddColumn(wxTreeListColumnInfo(text,
218 -1,
219 width,
220 true,
221 alignment)); }
1fded56b
RD
222 void AddColumn(const wxTreeListColumnInfo& col);
223
224 // inserts a column before the given one
225 void InsertColumn(size_t before, const wxString& text)
28eab81f 226 { InsertColumn(before, wxTreeListColumnInfo(text)); }
1fded56b
RD
227 void InsertColumn(size_t before, const wxTreeListColumnInfo& col);
228
229 // deletes the given column - does not delete the corresponding column
230 // of each item
231 void RemoveColumn(size_t column);
232
233 // returns the number of columns in the ctrl
234 size_t GetColumnCount() const;
235
236 void SetColumnWidth(size_t column, size_t width);
237 int GetColumnWidth(size_t column) const;
238
239 // tells which column is the "main" one, i.e. the "threaded" one
240 void SetMainColumn(size_t column);
241 size_t GetMainColumn() const;
242
243 void SetColumnText(size_t column, const wxString& text);
244 wxString GetColumnText(size_t column) const;
245
246 void SetColumn(size_t column, const wxTreeListColumnInfo& info);
247 wxTreeListColumnInfo& GetColumn(size_t column);
248 const wxTreeListColumnInfo& GetColumn(size_t column) const;
249
250 // other column-related methods
251 void SetColumnAlignment(size_t column, wxTreeListColumnAlign align);
252 wxTreeListColumnAlign GetColumnAlignment(size_t column) const;
253
254 void SetColumnImage(size_t column, int image);
255 int GetColumnImage(size_t column) const;
256
28eab81f
RD
257 void ShowColumn(size_t column, bool shown);
258 bool IsColumnShown(size_t column) const;
259
1fded56b
RD
260 // Functions to work with tree list ctrl items.
261
262 // accessors
263 // ---------
264
28eab81f 265 // retrieve item's label (of the main column)
1fded56b 266 wxString GetItemText(const wxTreeItemId& item) const
28eab81f 267 { return GetItemText(item, GetMainColumn()); }
1fded56b
RD
268 // retrieves item's label of the given column
269 wxString GetItemText(const wxTreeItemId& item, size_t column) const;
270
28eab81f 271 // get one of the images associated with the item (normal by default)
1fded56b
RD
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;
277
28eab81f 278 // get the data associated with the item
1fded56b
RD
279 wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
280
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;
285
286 // modifiers
287 // ---------
288
28eab81f 289 // set item's label
1fded56b
RD
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);
294
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);
302
28eab81f 303 // associate some data with the item
1fded56b
RD
304 void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
305
28eab81f
RD
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.
1fded56b
RD
310 void SetItemHasChildren(const wxTreeItemId& item, bool has = TRUE);
311
28eab81f 312 // the item will be shown in bold
1fded56b
RD
313 void SetItemBold(const wxTreeItemId& item, bool bold = TRUE);
314
28eab81f
RD
315 // set the item's text colour
316 void SetItemTextColour(const wxTreeItemId& item, const wxColour& colour);
1fded56b 317
28eab81f
RD
318 // set the item's background colour
319 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& colour);
1fded56b 320
28eab81f 321 // set the item's font (should be of the same height for all items)
1fded56b
RD
322 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
323
28eab81f 324 // set the window font
1fded56b
RD
325 virtual bool SetFont( const wxFont &font );
326
28eab81f 327 // set the styles.
1fded56b
RD
328 void SetWindowStyle(const long styles);
329 long GetWindowStyle() const;
330 long GetWindowStyleFlag() const { return GetWindowStyle(); }
331
332 // item status inquiries
333 // ---------------------
334
28eab81f 335 // is the item visible (it might be outside the view or not expanded)?
1fded56b 336 bool IsVisible(const wxTreeItemId& item) const;
28eab81f 337 // does the item has any children?
1fded56b
RD
338 bool HasChildren(const wxTreeItemId& item) const
339 { return ItemHasChildren(item); }
340 bool ItemHasChildren(const wxTreeItemId& item) const;
28eab81f 341 // is the item expanded (only makes sense if HasChildren())?
1fded56b 342 bool IsExpanded(const wxTreeItemId& item) const;
28eab81f 343 // is this item currently selected (the same as has focus)?
1fded56b 344 bool IsSelected(const wxTreeItemId& item) const;
28eab81f 345 // is item text in bold font?
1fded56b 346 bool IsBold(const wxTreeItemId& item) const;
28eab81f 347 // does the layout include space for a button?
1fded56b
RD
348
349 // number of children
350 // ------------------
351
28eab81f
RD
352 // if 'recursively' is FALSE, only immediate children count, otherwise
353 // the returned number is the number of all items in this branch
1fded56b
RD
354 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
355
356 // navigation
357 // ----------
358
359 // wxTreeItemId.IsOk() will return FALSE if there is no such item
360
28eab81f 361 // get the root tree item
1fded56b
RD
362 wxTreeItemId GetRootItem() const;
363
28eab81f 364 // get the item currently selected (may return NULL if no selection)
1fded56b
RD
365 wxTreeItemId GetSelection() const;
366
28eab81f 367 // get the items currently selected, return the number of such item
1fded56b
RD
368 size_t GetSelections(wxArrayTreeItemIds&) const;
369
28eab81f
RD
370 // get the parent of this item (may return NULL if root)
371 wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
1fded56b 372
28eab81f
RD
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
378 // the same!
1fded56b 379
28eab81f
RD
380 // get the first child of this item
381#if !wxCHECK_VERSION(2, 5, 0)
1fded56b 382 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const;
28eab81f
RD
383#else
384 wxTreeItemId GetFirstChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const;
385#endif
386 // get the next child
387#if !wxCHECK_VERSION(2, 5, 0)
1fded56b 388 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const;
28eab81f
RD
389#else
390 wxTreeItemId GetNextChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const;
391#endif
392 // get the prev child
393#if !wxCHECK_VERSION(2, 5, 0)
394 wxTreeItemId GetPrevChild(const wxTreeItemId& item, long& cookie) const;
395#else
396 wxTreeItemId GetPrevChild(const wxTreeItemId& item, wxTreeItemIdValue& cookie) const;
397#endif
398 // get the last child of this item - this method doesn't use cookies
1fded56b
RD
399 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
400
28eab81f 401 // get the next sibling of this item
1fded56b 402 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
28eab81f 403 // get the previous sibling
1fded56b
RD
404 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
405
28eab81f 406 // get first visible item
1fded56b 407 wxTreeItemId GetFirstVisibleItem() const;
28eab81f
RD
408 // get the next visible item: item must be visible itself!
409 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
1fded56b 410 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
28eab81f 411 // get the previous visible item: item must be visible itself!
1fded56b
RD
412 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
413
28eab81f 414 // Only for internal use right now, but should probably be public
1fded56b
RD
415 wxTreeItemId GetNext(const wxTreeItemId& item) const;
416
417 // operations
418 // ----------
419
28eab81f 420 // add the root node to the tree
1fded56b
RD
421 wxTreeItemId AddRoot(const wxString& text,
422 int image = -1, int selectedImage = -1,
423 wxTreeItemData *data = NULL);
424
28eab81f 425 // insert a new item in as the first child of the parent
1fded56b
RD
426 wxTreeItemId PrependItem(const wxTreeItemId& parent,
427 const wxString& text,
428 int image = -1, int selectedImage = -1,
429 wxTreeItemData *data = NULL);
430
28eab81f 431 // insert a new item after a given one
1fded56b
RD
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);
437
28eab81f 438 // insert a new item before the one with the given index
1fded56b
RD
439 wxTreeItemId InsertItem(const wxTreeItemId& parent,
440 size_t index,
441 const wxString& text,
442 int image = -1, int selectedImage = -1,
443 wxTreeItemData *data = NULL);
444
28eab81f 445 // insert a new item in as the last child of the parent
1fded56b
RD
446 wxTreeItemId AppendItem(const wxTreeItemId& parent,
447 const wxString& text,
448 int image = -1, int selectedImage = -1,
449 wxTreeItemData *data = NULL);
450
28eab81f 451 // delete this item and associated data if any
1fded56b 452 void Delete(const wxTreeItemId& item);
28eab81f
RD
453 // delete all children (but don't delete the item itself)
454 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
1fded56b 455 void DeleteChildren(const wxTreeItemId& item);
28eab81f
RD
456 // delete all items from the tree
457 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
1fded56b
RD
458 void DeleteAllItems();
459
28eab81f 460 // expand this item
1fded56b 461 void Expand(const wxTreeItemId& item);
28eab81f 462 // expand this item and all subitems recursively
1fded56b 463 void ExpandAll(const wxTreeItemId& item);
28eab81f 464 // collapse the item without removing its children
1fded56b 465 void Collapse(const wxTreeItemId& item);
28eab81f 466 // collapse the item and remove all children
1fded56b 467 void CollapseAndReset(const wxTreeItemId& item);
28eab81f 468 // toggles the current state
1fded56b
RD
469 void Toggle(const wxTreeItemId& item);
470
28eab81f 471 // remove the selection from currently selected item (if any)
1fded56b
RD
472 void Unselect();
473 void UnselectAll();
28eab81f 474 // select this item
1fded56b
RD
475 void SelectItem(const wxTreeItemId& item, bool unselect_others=TRUE,
476 bool extended_select=FALSE);
28eab81f
RD
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)
1fded56b 480 void EnsureVisible(const wxTreeItemId& item);
28eab81f 481 // scroll to this item (but don't expand its parent)
1fded56b
RD
482 void ScrollTo(const wxTreeItemId& item);
483 //void AdjustMyScrollbars();
484
28eab81f
RD
485 // The first function is more portable (because easier to implement
486 // on other platforms), but the second one returns some extra info.
1fded56b
RD
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);
492
28eab81f 493 // get the bounding rectangle of the item (or of its label only)
1fded56b
RD
494 bool GetBoundingRect(const wxTreeItemId& item,
495 wxRect& rect,
496 bool textOnly = FALSE) const;
497
28eab81f
RD
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
500 // been before.
1fded56b
RD
501 void EditLabel( const wxTreeItemId& item ) { Edit( item ); }
502 void Edit( const wxTreeItemId& item );
503
504 // sorting
28eab81f
RD
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)
1fded56b
RD
509 virtual int OnCompareItems(const wxTreeItemId& item1,
510 const wxTreeItemId& item2);
28eab81f
RD
511 // sort the children of this item using OnCompareItems
512 //
513 // NB: this function is not reentrant and not MT-safe (FIXME)!
1fded56b
RD
514 void SortChildren(const wxTreeItemId& item);
515
28eab81f
RD
516 // searching
517 wxTreeItemId FindItem (const wxTreeItemId& item, const wxString& str, int flags = 0);
1fded56b
RD
518
519 // overridden base class virtuals
520 virtual bool SetBackgroundColour(const wxColour& colour);
521 virtual bool SetForegroundColour(const wxColour& colour);
522
523
524 wxTreeListHeaderWindow* GetHeaderWindow() const
525 { return m_header_win; }
526
527 wxTreeListMainWindow* GetMainWindow() const
528 { return m_main_win; }
529
1fded56b
RD
530protected:
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;
535
28eab81f
RD
536// // the common part of all ctors
537// void Init();
1fded56b
RD
538
539 void OnSize(wxSizeEvent& event);
540
541
542private:
28eab81f
RD
543 size_t fill_column;
544
1fded56b
RD
545 DECLARE_EVENT_TABLE()
546 DECLARE_DYNAMIC_CLASS(wxTreeListCtrl)
547};
548
549#endif // TREELISTCTRL_H
550