]> git.saurik.com Git - wxWidgets.git/blob - include/wx/palmos/treectrl.h
German translation mostly uptodate now.
[wxWidgets.git] / include / wx / palmos / treectrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/palmos/treectrl.h
3 // Purpose: wxTreeCtrl class
4 // Author: William Osborne
5 // Modified by:
6 // Created: 10/13/04
7 // RCS-ID: $Id:
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_TREECTRL_H_
13 #define _WX_TREECTRL_H_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma interface "treectrl.h"
21 #endif
22
23 #if wxUSE_TREECTRL
24
25 #include "wx/textctrl.h"
26 #include "wx/dynarray.h"
27 #include "wx/treebase.h"
28 #include "wx/hashmap.h"
29
30 #ifdef __GNUWIN32__
31 // Cygwin windows.h defines these identifiers
32 #undef GetFirstChild
33 #undef GetNextSibling
34 #endif // Cygwin
35
36 // fwd decl
37 class WXDLLEXPORT wxImageList;
38 class WXDLLEXPORT wxDragImage;
39 struct WXDLLEXPORT wxTreeViewItem;
40
41 // NB: all the following flags are for compatbility only and will be removed in the
42 // next versions
43
44 // flags for deprecated `Expand(int action)'
45 enum
46 {
47 wxTREE_EXPAND_EXPAND,
48 wxTREE_EXPAND_COLLAPSE,
49 wxTREE_EXPAND_COLLAPSE_RESET,
50 wxTREE_EXPAND_TOGGLE
51 };
52
53 // flags for deprecated InsertItem() variant (their values are the same as of
54 // TVI_FIRST and TVI_LAST)
55 #define wxTREE_INSERT_FIRST 0xFFFF0001
56 #define wxTREE_INSERT_LAST 0xFFFF0002
57
58 // hash storing attributes for our items
59 WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP(wxTreeItemAttr *, wxMapTreeAttr);
60
61 // ----------------------------------------------------------------------------
62 // wxTreeCtrl
63 // ----------------------------------------------------------------------------
64
65 class WXDLLEXPORT wxTreeCtrl : public wxControl
66 {
67 public:
68 // creation
69 // --------
70 wxTreeCtrl() { Init(); }
71
72 wxTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY,
73 const wxPoint& pos = wxDefaultPosition,
74 const wxSize& size = wxDefaultSize,
75 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
76 const wxValidator& validator = wxDefaultValidator,
77 const wxString& name = wxTreeCtrlNameStr)
78 {
79 Create(parent, id, pos, size, style, validator, name);
80 }
81
82 virtual ~wxTreeCtrl();
83
84 bool Create(wxWindow *parent, wxWindowID id = wxID_ANY,
85 const wxPoint& pos = wxDefaultPosition,
86 const wxSize& size = wxDefaultSize,
87 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
88 const wxValidator& validator = wxDefaultValidator,
89 const wxString& name = wxTreeCtrlNameStr);
90
91 // accessors
92 // ---------
93
94 // get the total number of items in the control
95 size_t GetCount() const;
96
97 // indent is the number of pixels the children are indented relative to
98 // the parents position. SetIndent() also redraws the control
99 // immediately.
100 unsigned int GetIndent() const;
101 void SetIndent(unsigned int indent);
102
103 // spacing is the number of pixels between the start and the Text
104 unsigned int GetSpacing() const { return 18; } // return wxGTK default
105 void SetSpacing(unsigned int WXUNUSED(spacing)) { }
106
107 // image list: these functions allow to associate an image list with
108 // the control and retrieve it. Note that the control does _not_ delete
109 // the associated image list when it's deleted in order to allow image
110 // lists to be shared between different controls.
111 //
112 // The normal image list is for the icons which correspond to the
113 // normal tree item state (whether it is selected or not).
114 // Additionally, the application might choose to show a state icon
115 // which corresponds to an app-defined item state (for example,
116 // checked/unchecked) which are taken from the state image list.
117 wxImageList *GetImageList() const;
118 wxImageList *GetStateImageList() const;
119
120 void SetImageList(wxImageList *imageList);
121 void SetStateImageList(wxImageList *imageList);
122 void AssignImageList(wxImageList *imageList);
123 void AssignStateImageList(wxImageList *imageList);
124
125 // Functions to work with tree ctrl items. Unfortunately, they can _not_ be
126 // member functions of wxTreeItem because they must know the tree the item
127 // belongs to for Windows implementation and storing the pointer to
128 // wxTreeCtrl in each wxTreeItem is just too much waste.
129
130 // accessors
131 // ---------
132
133 // retrieve items label
134 wxString GetItemText(const wxTreeItemId& item) const;
135 // get one of the images associated with the item (normal by default)
136 int GetItemImage(const wxTreeItemId& item,
137 wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
138 // get the data associated with the item
139 wxTreeItemData *GetItemData(const wxTreeItemId& item) const;
140
141 // get the item's text colour
142 wxColour GetItemTextColour(const wxTreeItemId& item) const;
143
144 // get the item's background colour
145 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
146
147 // get the item's font
148 wxFont GetItemFont(const wxTreeItemId& item) const;
149
150 // modifiers
151 // ---------
152
153 // set items label
154 void SetItemText(const wxTreeItemId& item, const wxString& text);
155 // get one of the images associated with the item (normal by default)
156 void SetItemImage(const wxTreeItemId& item, int image,
157 wxTreeItemIcon which = wxTreeItemIcon_Normal);
158 // associate some data with the item
159 void SetItemData(const wxTreeItemId& item, wxTreeItemData *data);
160
161 // force appearance of [+] button near the item. This is useful to
162 // allow the user to expand the items which don't have any children now
163 // - but instead add them only when needed, thus minimizing memory
164 // usage and loading time.
165 void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
166
167 // the item will be shown in bold
168 void SetItemBold(const wxTreeItemId& item, bool bold = true);
169
170 // the item will be shown with a drop highlight
171 void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = true);
172
173 // set the items text colour
174 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
175
176 // set the items background colour
177 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
178
179 // set the items font (should be of the same height for all items)
180 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
181
182 // item status inquiries
183 // ---------------------
184
185 // is the item visible (it might be outside the view or not expanded)?
186 bool IsVisible(const wxTreeItemId& item) const;
187 // does the item has any children?
188 bool ItemHasChildren(const wxTreeItemId& item) const;
189 // is the item expanded (only makes sense if HasChildren())?
190 bool IsExpanded(const wxTreeItemId& item) const;
191 // is this item currently selected (the same as has focus)?
192 bool IsSelected(const wxTreeItemId& item) const;
193 // is item text in bold font?
194 bool IsBold(const wxTreeItemId& item) const;
195
196 // number of children
197 // ------------------
198
199 // if 'recursively' is false, only immediate children count, otherwise
200 // the returned number is the number of all items in this branch
201 size_t GetChildrenCount(const wxTreeItemId& item,
202 bool recursively = true) const;
203
204 // navigation
205 // ----------
206
207 // wxTreeItemId.IsOk() will return false if there is no such item
208
209 // get the root tree item
210 wxTreeItemId GetRootItem() const;
211
212 // get the item currently selected (may return NULL if no selection)
213 wxTreeItemId GetSelection() const;
214
215 // get the items currently selected, return the number of such item
216 //
217 // NB: this operation is expensive and can take a long time for a
218 // control with a lot of items (~ O(number of items)).
219 size_t GetSelections(wxArrayTreeItemIds& selections) const;
220
221 // get the parent of this item (may return NULL if root)
222 wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
223
224 #if WXWIN_COMPATIBILITY_2_2
225 // deprecated: Use GetItemParent instead.
226 wxTreeItemId GetParent(const wxTreeItemId& item) const
227 { return GetItemParent( item ); }
228
229 // Expose the base class method hidden by the one above.
230 wxWindow *GetParent() const { return wxControl::GetParent(); }
231 #endif // WXWIN_COMPATIBILITY_2_2
232
233 // for this enumeration function you must pass in a "cookie" parameter
234 // which is opaque for the application but is necessary for the library
235 // to make these functions reentrant (i.e. allow more than one
236 // enumeration on one and the same object simultaneously). Of course,
237 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
238 // the same!
239
240 // get the first child of this item
241 wxTreeItemId GetFirstChild(const wxTreeItemId& item,
242 wxTreeItemIdValue& cookie) const;
243 // get the next child
244 wxTreeItemId GetNextChild(const wxTreeItemId& item,
245 wxTreeItemIdValue& cookie) const;
246 // get the last child of this item - this method doesn't use cookies
247 wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
248
249 // get the next sibling of this item
250 wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
251 // get the previous sibling
252 wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
253
254 // get first visible item
255 wxTreeItemId GetFirstVisibleItem() const;
256 // get the next visible item: item must be visible itself!
257 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
258 wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
259 // get the previous visible item: item must be visible itself!
260 wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
261
262 // operations
263 // ----------
264
265 // add the root node to the tree
266 wxTreeItemId AddRoot(const wxString& text,
267 int image = -1, int selectedImage = -1,
268 wxTreeItemData *data = NULL);
269
270 // insert a new item in as the first child of the parent
271 wxTreeItemId PrependItem(const wxTreeItemId& parent,
272 const wxString& text,
273 int image = -1, int selectedImage = -1,
274 wxTreeItemData *data = NULL);
275
276 // insert a new item after a given one
277 wxTreeItemId InsertItem(const wxTreeItemId& parent,
278 const wxTreeItemId& idPrevious,
279 const wxString& text,
280 int image = -1, int selectedImage = -1,
281 wxTreeItemData *data = NULL);
282
283 // insert a new item before the one with the given index
284 wxTreeItemId InsertItem(const wxTreeItemId& parent,
285 size_t index,
286 const wxString& text,
287 int image = -1, int selectedImage = -1,
288 wxTreeItemData *data = NULL);
289
290 // insert a new item in as the last child of the parent
291 wxTreeItemId AppendItem(const wxTreeItemId& parent,
292 const wxString& text,
293 int image = -1, int selectedImage = -1,
294 wxTreeItemData *data = NULL);
295
296 // delete this item and associated data if any
297 void Delete(const wxTreeItemId& item);
298 // delete all children (but don't delete the item itself)
299 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
300 void DeleteChildren(const wxTreeItemId& item);
301 // delete all items from the tree
302 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
303 void DeleteAllItems();
304
305 // expand this item
306 void Expand(const wxTreeItemId& item);
307 // collapse the item without removing its children
308 void Collapse(const wxTreeItemId& item);
309 // collapse the item and remove all children
310 void CollapseAndReset(const wxTreeItemId& item);
311 // toggles the current state
312 void Toggle(const wxTreeItemId& item);
313
314 // remove the selection from currently selected item (if any)
315 void Unselect();
316 // unselect all items (only makes sense for multiple selection control)
317 void UnselectAll();
318 // select this item
319 void SelectItem(const wxTreeItemId& item, bool select = true);
320 // unselect this item
321 void UnselectItem(const wxTreeItemId& item);
322 // toggle item selection
323 void ToggleItemSelection(const wxTreeItemId& item);
324
325 // make sure this item is visible (expanding the parent item and/or
326 // scrolling to this item if necessary)
327 void EnsureVisible(const wxTreeItemId& item);
328 // scroll to this item (but don't expand its parent)
329 void ScrollTo(const wxTreeItemId& item);
330
331 // start editing the item label: this (temporarily) replaces the item
332 // with a one line edit control. The item will be selected if it hadn't
333 // been before. textCtrlClass parameter allows you to create an edit
334 // control of arbitrary user-defined class deriving from wxTextCtrl.
335 wxTextCtrl* EditLabel(const wxTreeItemId& item,
336 wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
337 // returns the same pointer as StartEdit() if the item is being edited,
338 // NULL otherwise (it's assumed that no more than one item may be
339 // edited simultaneously)
340 wxTextCtrl* GetEditControl() const;
341 // end editing and accept or discard the changes to item label
342 void EndEditLabel(const wxTreeItemId& item, bool discardChanges = false);
343
344 // sorting
345 // this function is called to compare 2 items and should return -1, 0
346 // or +1 if the first item is less than, equal to or greater than the
347 // second one. The base class version performs alphabetic comparaison
348 // of item labels (GetText)
349 virtual int OnCompareItems(const wxTreeItemId& item1,
350 const wxTreeItemId& item2);
351 // sort the children of this item using OnCompareItems
352 //
353 // NB: this function is not reentrant and not MT-safe (FIXME)!
354 void SortChildren(const wxTreeItemId& item);
355
356 // helpers
357 // -------
358
359 // determine to which item (if any) belongs the given point (the
360 // coordinates specified are relative to the client area of tree ctrl)
361 // and fill the flags parameter with a bitmask of wxTREE_HITTEST_xxx
362 // constants.
363 //
364 // The first function is more portable (because easier to implement
365 // on other platforms), but the second one returns some extra info.
366 wxTreeItemId HitTest(const wxPoint& point)
367 { int dummy; return HitTest(point, dummy); }
368 wxTreeItemId HitTest(const wxPoint& point, int& flags);
369
370 // get the bounding rectangle of the item (or of its label only)
371 bool GetBoundingRect(const wxTreeItemId& item,
372 wxRect& rect,
373 bool textOnly = false) const;
374
375 // deprecated
376 // ----------
377
378 #if WXWIN_COMPATIBILITY_2_4
379 // these methods are deprecated and will be removed in future versions of
380 // wxWidgets, they're here for compatibility only, don't use them in new
381 // code (the comments indicate why these methods are now useless and how to
382 // replace them)
383
384 // use Expand, Collapse, CollapseAndReset or Toggle
385 wxDEPRECATED( void ExpandItem(const wxTreeItemId& item, int action) );
386
387 // use AddRoot, PrependItem or AppendItem
388 wxDEPRECATED( wxTreeItemId InsertItem(const wxTreeItemId& parent,
389 const wxString& text,
390 int image = -1, int selImage = -1,
391 long insertAfter = wxTREE_INSERT_LAST) );
392
393 // use Set/GetImageList and Set/GetStateImageList
394 wxImageList *GetImageList(int) const { return GetImageList(); }
395 void SetImageList(wxImageList *imageList, int) { SetImageList(imageList); }
396
397 // use Set/GetItemImage directly
398 int GetItemSelectedImage(const wxTreeItemId& item) const
399 { return GetItemImage(item, wxTreeItemIcon_Selected); }
400 void SetItemSelectedImage(const wxTreeItemId& item, int image)
401 { SetItemImage(item, image, wxTreeItemIcon_Selected); }
402
403 // use the versions taking wxTreeItemIdValue cookies
404 wxDEPRECATED( wxTreeItemId GetFirstChild(const wxTreeItemId& item,
405 long& cookie) const );
406 wxDEPRECATED( wxTreeItemId GetNextChild(const wxTreeItemId& item,
407 long& cookie) const );
408 #endif // WXWIN_COMPATIBILITY_2_4
409
410
411 // implementation
412 // --------------
413
414 virtual bool ShouldInheritColours() const { return false; }
415
416 virtual wxVisualAttributes GetDefaultAttributes() const
417 {
418 return GetClassDefaultAttributes(GetWindowVariant());
419 }
420
421 static wxVisualAttributes
422 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
423
424 // override some base class virtuals
425 virtual bool SetBackgroundColour(const wxColour &colour);
426 virtual bool SetForegroundColour(const wxColour &colour);
427
428 // get/set the check state for the item (only for wxTR_MULTIPLE)
429 bool IsItemChecked(const wxTreeItemId& item) const;
430 void SetItemCheck(const wxTreeItemId& item, bool check = true);
431
432 // set/get the item state.image (state == -1 means cycle to the next one)
433 void SetState(const wxTreeItemId& node, int state);
434 int GetState(const wxTreeItemId& node);
435
436 protected:
437 // SetImageList helper
438 void SetAnyImageList(wxImageList *imageList, int which);
439
440 // refresh a single item
441 void RefreshItem(const wxTreeItemId& item);
442
443 wxTextCtrl *m_textCtrl; // used while editing the item label
444 wxImageList *m_imageListNormal, // images for tree elements
445 *m_imageListState; // special images for app defined states
446 bool m_ownsImageListNormal, m_ownsImageListState;
447
448 private:
449 // the common part of all ctors
450 void Init();
451
452 // helper functions
453 inline bool DoGetItem(wxTreeViewItem *tvItem) const;
454 inline void DoSetItem(wxTreeViewItem *tvItem);
455
456 inline void DoExpand(const wxTreeItemId& item, int flag);
457
458 wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
459 wxTreeItemId hInsertAfter,
460 const wxString& text,
461 int image, int selectedImage,
462 wxTreeItemData *data);
463
464 int DoGetItemImageFromData(const wxTreeItemId& item,
465 wxTreeItemIcon which) const;
466 void DoSetItemImageFromData(const wxTreeItemId& item,
467 int image,
468 wxTreeItemIcon which) const;
469 void DoSetItemImages(const wxTreeItemId& item, int image, int imageSel);
470
471 void DeleteTextCtrl();
472
473 // support for additional item images which we implement using
474 // wxTreeItemIndirectData technique - see the comments in msw/treectrl.cpp
475 void SetIndirectItemData(const wxTreeItemId& item,
476 class wxTreeItemIndirectData *data);
477 bool HasIndirectData(const wxTreeItemId& item) const;
478 bool IsDataIndirect(wxTreeItemData *data) const
479 { return data && data->GetId().m_pItem == 0; }
480
481 // the hash storing the items attributes (indexed by item ids)
482 wxMapTreeAttr m_attrs;
483
484 // true if the hash above is not empty
485 bool m_hasAnyAttr;
486
487 // used for dragging
488 wxDragImage *m_dragImage;
489
490 // Virtual root item, if wxTR_HIDE_ROOT is set.
491 void* m_pVirtualRoot;
492
493 // the starting item for selection with Shift
494 wxTreeItemId m_htSelStart;
495
496 friend class wxTreeItemIndirectData;
497 friend class wxTreeSortHelper;
498
499 DECLARE_DYNAMIC_CLASS(wxTreeCtrl)
500 DECLARE_NO_COPY_CLASS(wxTreeCtrl)
501 };
502
503 #endif // wxUSE_TREECTRL
504
505 #endif
506 // _WX_TREECTRL_H_