]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/gizmos/wxCode/include/wx/treelistctrl.h
Fixed HitTest for columns > 1
[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 // wxTreeListColumnAttrs
49 //-----------------------------------------------------------------------------
50
51 enum wxTreeListColumnAlign {
52 wxTL_ALIGN_LEFT,
53 wxTL_ALIGN_RIGHT,
54 wxTL_ALIGN_CENTER
55 };
56
57
58 class GIZMODLLEXPORT wxTreeListColumnInfo: public wxObject {
59 public:
60 enum { DEFAULT_COL_WIDTH = 100 };
61
62 wxTreeListColumnInfo(const wxString &text = wxT(""),
63 int image = -1,
64 size_t width = DEFAULT_COL_WIDTH,
65 bool shown = true,
66 wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT)
67 {
68 m_image = image;
69 m_selected_image = -1;
70 m_text = text;
71 m_width = width;
72 m_shown = shown;
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;
82 m_shown = other.m_shown;
83 m_alignment = other.m_alignment;
84 }
85
86 ~wxTreeListColumnInfo() {}
87
88 // getters
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; }
95
96 // setters
97 wxTreeListColumnInfo& SetShown(bool shown)
98 { m_shown = shown; return *this; }
99
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
115 private:
116 bool m_shown;
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
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;
134
135 // additional flag for HitTest
136 const int wxTREE_HITTEST_ONITEMCOLUMN = 0x2000;
137 extern GIZMODLLEXPORT const wxChar* wxTreeListCtrlNameStr;
138
139
140 class GIZMODLLEXPORT wxTreeListCtrl : public wxControl
141 {
142 public:
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
172 // get the total number of items in the control
173 size_t GetCount() const;
174
175 // indent is the number of pixels the children are indented relative to
176 // the parents position. SetIndent() also redraws the control
177 // immediately.
178 unsigned int GetIndent() const;
179 void SetIndent(unsigned int indent);
180
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
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.
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)
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)); }
222 void AddColumn(const wxTreeListColumnInfo& col);
223
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);
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
257 void ShowColumn(size_t column, bool shown);
258 bool IsColumnShown(size_t column) const;
259
260 // Functions to work with tree list ctrl items.
261
262 // accessors
263 // ---------
264
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;
270
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;
277
278 // get the data associated with the item
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
289 // set item's label
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
303 // associate some data with the item
304 void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
305
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);
311
312 // the item will be shown in bold
313 void SetItemBold(const wxTreeItemId& item, bool bold = TRUE);
314
315 // set the item's text colour
316 void SetItemTextColour(const wxTreeItemId& item, const wxColour& colour);
317
318 // set the item's background colour
319 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& colour);
320
321 // set the item's font (should be of the same height for all items)
322 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
323
324 // set the window font
325 virtual bool SetFont( const wxFont &font );
326
327 // set the styles.
328 void SetWindowStyle(const long styles);
329 long GetWindowStyle() const;
330 long GetWindowStyleFlag() const { return GetWindowStyle(); }
331
332 // item status inquiries
333 // ---------------------
334
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?
348
349 // number of children
350 // ------------------
351
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);
355
356 // navigation
357 // ----------
358
359 // wxTreeItemId.IsOk() will return FALSE if there is no such item
360
361 // get the root tree item
362 wxTreeItemId GetRootItem() const;
363
364 // get the item currently selected (may return NULL if no selection)
365 wxTreeItemId GetSelection() const;
366
367 // get the items currently selected, return the number of such item
368 size_t GetSelections(wxArrayTreeItemIds&) const;
369
370 // get the parent of this item (may return NULL if root)
371 wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
372
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!
379
380 // get the first child of this item
381 #if !wxCHECK_VERSION(2, 5, 0)
382 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const;
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)
388 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const;
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
399 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
400
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;
405
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;
413
414 // Only for internal use right now, but should probably be public
415 wxTreeItemId GetNext(const wxTreeItemId& item) const;
416
417 // operations
418 // ----------
419
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);
424
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);
430
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);
437
438 // insert a new item before the one with the given index
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
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);
450
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();
459
460 // expand this item
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);
470
471 // remove the selection from currently selected item (if any)
472 void Unselect();
473 void UnselectAll();
474 // select this item
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();
484
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);
492
493 // get the bounding rectangle of the item (or of its label only)
494 bool GetBoundingRect(const wxTreeItemId& item,
495 wxRect& rect,
496 bool textOnly = FALSE) const;
497
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.
501 void EditLabel( const wxTreeItemId& item ) { Edit( item ); }
502 void Edit( const wxTreeItemId& item );
503
504 // sorting
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
512 //
513 // NB: this function is not reentrant and not MT-safe (FIXME)!
514 void SortChildren(const wxTreeItemId& item);
515
516 // searching
517 wxTreeItemId FindItem (const wxTreeItemId& item, const wxString& str, int flags = 0);
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
530 protected:
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
536 // // the common part of all ctors
537 // void Init();
538
539 void OnSize(wxSizeEvent& event);
540
541
542 private:
543 size_t fill_column;
544
545 DECLARE_EVENT_TABLE()
546 DECLARE_DYNAMIC_CLASS(wxTreeListCtrl)
547 };
548
549 #endif // TREELISTCTRL_H
550