1 /////////////////////////////////////////////////////////////////////////////
2 // Name: treelistctrl.cpp (derived by treectlg.h)
3 // Purpose: multi column tree control implementation
4 // Author: Robert Roebling
6 // Modified: Alberto Griggio, 2002
7 // 22/10/98 - almost total rewrite, simpler interface (VZ)
9 // Copyright: (c) Robert Roebling, Julian Smart, Alberto Griggio,
10 // Vadim Zeitlin, Otto Wyss
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 // ===========================================================================
16 // ===========================================================================
18 // ---------------------------------------------------------------------------
20 // ---------------------------------------------------------------------------
22 #if defined(__GNUG__) && !defined(__APPLE__)
23 #pragma implementation "treelistctrl.h"
26 // For compilers that support precompilation, includes "wx.h".
27 #include "wx/wxprec.h"
34 #include <wx/treebase.h>
36 #include <wx/textctrl.h>
37 #include <wx/imaglist.h>
38 #include <wx/settings.h>
39 #include <wx/dcclient.h>
40 #include <wx/dcscreen.h>
41 #include <wx/scrolwin.h>
43 #include "wx/gizmos/treelistctrl.h"
47 #include <wx/gtk/win_gtk.h>
50 // ---------------------------------------------------------------------------
52 // ---------------------------------------------------------------------------
56 WX_DEFINE_ARRAY(wxTreeListItem
*, wxArrayTreeListItems
);
58 #include <wx/dynarray.h>
59 WX_DECLARE_OBJARRAY(wxTreeListColumnInfo
, wxArrayTreeListColumnInfo
);
60 #include <wx/arrimpl.cpp>
61 WX_DEFINE_OBJARRAY(wxArrayTreeListColumnInfo
);
63 #if !wxCHECK_VERSION(2, 3, 3)
64 WX_DEFINE_ARRAY(short, wxArrayShort
);
68 // --------------------------------------------------------------------------
70 // --------------------------------------------------------------------------
72 static const int NO_IMAGE
= -1;
74 const int LINEHEIGHT
= 10;
75 const int PIXELS_PER_UNIT
= 10;
76 const int LINEATROOT
= 5;
78 const int MININDENT
= 10;
79 const int BTNWIDTH
= 11;
80 const int BTNHEIGHT
= 11;
82 const wxChar
* wxTreeListCtrlNameStr
= wxT("treelistctrl");
84 static wxTreeListColumnInfo wxInvalidTreeListColumnInfo
;
87 // ---------------------------------------------------------------------------
89 // ---------------------------------------------------------------------------
90 //-----------------------------------------------------------------------------
91 // wxTreeListHeaderWindow (internal)
92 //-----------------------------------------------------------------------------
94 class wxTreeListHeaderWindow
: public wxWindow
97 wxTreeListMainWindow
*m_owner
;
98 wxCursor
*m_currentCursor
;
99 wxCursor
*m_resizeCursor
;
102 // column being resized
105 // divider line position in logical (unscrolled) coords
108 // minimal position beyond which the divider line can't be dragged in
112 wxArrayTreeListColumnInfo m_columns
;
114 // total width of the columns
115 int m_total_col_width
;
119 wxTreeListHeaderWindow();
121 wxTreeListHeaderWindow( wxWindow
*win
,
123 wxTreeListMainWindow
*owner
,
124 const wxPoint
&pos
= wxDefaultPosition
,
125 const wxSize
&size
= wxDefaultSize
,
127 const wxString
&name
= wxT("wxtreelistctrlcolumntitles") );
129 virtual ~wxTreeListHeaderWindow();
131 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
133 void AdjustDC(wxDC
& dc
);
135 void OnPaint( wxPaintEvent
&event
);
136 void OnMouse( wxMouseEvent
&event
);
137 void OnSetFocus( wxFocusEvent
&event
);
140 // columns manipulation
142 size_t GetColumnCount() const { return m_columns
.GetCount(); }
144 void AddColumn(const wxTreeListColumnInfo
& col
);
146 void InsertColumn(size_t before
, const wxTreeListColumnInfo
& col
);
148 void RemoveColumn(size_t column
);
150 void SetColumn(size_t column
, const wxTreeListColumnInfo
& info
);
151 const wxTreeListColumnInfo
& GetColumn(size_t column
) const
153 wxCHECK_MSG(column
< GetColumnCount(), wxInvalidTreeListColumnInfo
, wxT("Invalid column"));
154 return m_columns
[column
];
156 wxTreeListColumnInfo
& GetColumn(size_t column
)
158 wxCHECK_MSG(column
< GetColumnCount(), wxInvalidTreeListColumnInfo
, wxT("Invalid column"));
159 return m_columns
[column
];
162 void SetColumnWidth(size_t column
, size_t width
);
164 void SetColumnText(size_t column
, const wxString
& text
)
166 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
167 m_columns
[column
].SetText(text
);
170 void SetColumnShown(size_t column
, bool shown
)
172 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
173 m_columns
[column
].SetShown(shown
);
176 wxString
GetColumnText(size_t column
) const
178 wxCHECK_MSG(column
< GetColumnCount(), wxEmptyString
, wxT("Invalid column"));
179 return m_columns
[column
].GetText();
182 int GetColumnWidth(size_t column
) const
184 wxCHECK_MSG(column
< GetColumnCount(), -1, wxT("Invalid column"));
185 return m_columns
[column
].GetWidth();
188 int GetWidth() const { return m_total_col_width
; }
190 int GetColumnShown(size_t column
) const
192 wxCHECK_MSG(column
< GetColumnCount(), -1, wxT("Invalid column"));
193 return m_columns
[column
].GetShown();
200 // common part of all ctors
203 void SendListEvent(wxEventType type
, wxPoint pos
);
205 DECLARE_DYNAMIC_CLASS(wxTreeListHeaderWindow
)
206 DECLARE_EVENT_TABLE()
210 // this is the "true" control
211 class wxTreeListMainWindow
: public wxScrolledWindow
216 wxTreeListMainWindow() { Init(); }
218 wxTreeListMainWindow(wxTreeListCtrl
*parent
, wxWindowID id
= -1,
219 const wxPoint
& pos
= wxDefaultPosition
,
220 const wxSize
& size
= wxDefaultSize
,
221 long style
= wxTR_DEFAULT_STYLE
,
222 const wxValidator
&validator
= wxDefaultValidator
,
223 const wxString
& name
= wxT("wxtreelistmainwindow"))
226 Create(parent
, id
, pos
, size
, style
, validator
, name
);
229 virtual ~wxTreeListMainWindow();
231 bool Create(wxTreeListCtrl
*parent
, wxWindowID id
= -1,
232 const wxPoint
& pos
= wxDefaultPosition
,
233 const wxSize
& size
= wxDefaultSize
,
234 long style
= wxTR_DEFAULT_STYLE
,
235 const wxValidator
&validator
= wxDefaultValidator
,
236 const wxString
& name
= wxT("wxtreelistctrl"));
241 // get the total number of items in the control
242 size_t GetCount() const;
244 // indent is the number of pixels the children are indented relative to
245 // the parents position. SetIndent() also redraws the control
247 unsigned int GetIndent() const { return m_indent
; }
248 void SetIndent(unsigned int indent
);
250 // see wxTreeListCtrl for the meaning
251 unsigned int GetLineSpacing() const { return m_linespacing
; }
252 void SetLineSpacing(unsigned int spacing
);
254 // image list: these functions allow to associate an image list with
255 // the control and retrieve it. Note that when assigned with
256 // SetImageList, the control does _not_ delete
257 // the associated image list when it's deleted in order to allow image
258 // lists to be shared between different controls. If you use
259 // AssignImageList, the control _does_ delete the image list.
261 // The normal image list is for the icons which correspond to the
262 // normal tree item state (whether it is selected or not).
263 // Additionally, the application might choose to show a state icon
264 // which corresponds to an app-defined item state (for example,
265 // checked/unchecked) which are taken from the state image list.
266 wxImageList
*GetImageList() const;
267 wxImageList
*GetStateImageList() const;
268 wxImageList
*GetButtonsImageList() const;
270 void SetImageList(wxImageList
*imageList
);
271 void SetStateImageList(wxImageList
*imageList
);
272 void SetButtonsImageList(wxImageList
*imageList
);
273 void AssignImageList(wxImageList
*imageList
);
274 void AssignStateImageList(wxImageList
*imageList
);
275 void AssignButtonsImageList(wxImageList
*imageList
);
277 // Functions to work with tree ctrl items.
282 // retrieve item's label
283 wxString
GetItemText(const wxTreeItemId
& item
) const
284 { return GetItemText(item
, GetMainColumn()); }
285 // get one of the images associated with the item (normal by default)
286 int GetItemImage(const wxTreeItemId
& item
,
287 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
288 { return GetItemImage(item
, GetMainColumn(), which
); }
290 // get the data associated with the item
291 wxTreeItemData
*GetItemData(const wxTreeItemId
& item
) const;
293 bool GetItemBold(const wxTreeItemId
& item
) const;
294 wxColour
GetItemTextColour(const wxTreeItemId
& item
) const;
295 wxColour
GetItemBackgroundColour(const wxTreeItemId
& item
) const;
296 wxFont
GetItemFont(const wxTreeItemId
& item
) const;
302 void SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
303 { SetItemText(item
, GetMainColumn(), text
); }
305 // get one of the images associated with the item (normal by default)
306 void SetItemImage(const wxTreeItemId
& item
, int image
,
307 wxTreeItemIcon which
= wxTreeItemIcon_Normal
)
308 { SetItemImage(item
, GetMainColumn(), image
, which
); }
310 // associate some data with the item
311 void SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
);
313 // force appearance of [+] button near the item. This is useful to
314 // allow the user to expand the items which don't have any children now
315 // - but instead add them only when needed, thus minimizing memory
316 // usage and loading time.
317 void SetItemHasChildren(const wxTreeItemId
& item
, bool has
= TRUE
);
319 // the item will be shown in bold
320 void SetItemBold(const wxTreeItemId
& item
, bool bold
= TRUE
);
322 // set the item's text colour
323 void SetItemTextColour(const wxTreeItemId
& item
, const wxColour
& colour
);
325 // set the item's background colour
326 void SetItemBackgroundColour(const wxTreeItemId
& item
, const wxColour
& colour
);
328 // set the item's font (should be of the same height for all items)
329 void SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
);
331 // set the window font
332 virtual bool SetFont( const wxFont
&font
);
334 // set the styles. No need to specify a GetWindowStyle here since
335 // the base wxWindow member function will do it for us
336 void SetWindowStyle(const long styles
);
338 // item status inquiries
339 // ---------------------
341 // is the item visible (it might be outside the view or not expanded)?
342 bool IsVisible(const wxTreeItemId
& item
) const;
343 // does the item has any children?
344 bool HasChildren(const wxTreeItemId
& item
) const
345 { return ItemHasChildren(item
); }
346 bool ItemHasChildren(const wxTreeItemId
& item
) const;
347 // is the item expanded (only makes sense if HasChildren())?
348 bool IsExpanded(const wxTreeItemId
& item
) const;
349 // is this item currently selected (the same as has focus)?
350 bool IsSelected(const wxTreeItemId
& item
) const;
351 // is item text in bold font?
352 bool IsBold(const wxTreeItemId
& item
) const;
353 // does the layout include space for a button?
355 // number of children
356 // ------------------
358 // if 'recursively' is FALSE, only immediate children count, otherwise
359 // the returned number is the number of all items in this branch
360 size_t GetChildrenCount(const wxTreeItemId
& item
, bool recursively
= TRUE
);
365 // wxTreeItemId.IsOk() will return FALSE if there is no such item
367 // get the root tree item
368 wxTreeItemId
GetRootItem() const { return m_anchor
; }
370 // get the item currently selected (may return NULL if no selection)
371 wxTreeItemId
GetSelection() const { return m_current
; }
373 // get the items currently selected, return the number of such item
374 size_t GetSelections(wxArrayTreeItemIds
&) const;
376 // get the parent of this item (may return NULL if root)
377 wxTreeItemId
GetItemParent(const wxTreeItemId
& item
) const;
379 // for this enumeration function you must pass in a "cookie" parameter
380 // which is opaque for the application but is necessary for the library
381 // to make these functions reentrant (i.e. allow more than one
382 // enumeration on one and the same object simultaneously). Of course,
383 // the "cookie" passed to GetFirstChild() and GetNextChild() should be
386 // get the first child of this item
387 wxTreeItemId
GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const;
388 // get the next child
389 wxTreeItemId
GetNextChild(const wxTreeItemId
& item
, long& cookie
) const;
390 // get the last child of this item - this method doesn't use cookies
391 wxTreeItemId
GetLastChild(const wxTreeItemId
& item
) const;
393 // get the next sibling of this item
394 wxTreeItemId
GetNextSibling(const wxTreeItemId
& item
) const;
395 // get the previous sibling
396 wxTreeItemId
GetPrevSibling(const wxTreeItemId
& item
) const;
398 // get first visible item
399 wxTreeItemId
GetFirstVisibleItem() const;
400 // get the next visible item: item must be visible itself!
401 // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
402 wxTreeItemId
GetNextVisible(const wxTreeItemId
& item
) const;
403 // get the previous visible item: item must be visible itself!
404 wxTreeItemId
GetPrevVisible(const wxTreeItemId
& item
) const;
406 // Only for internal use right now, but should probably be public
407 wxTreeItemId
GetNext(const wxTreeItemId
& item
) const;
412 // add the root node to the tree
413 wxTreeItemId
AddRoot(const wxString
& text
,
414 int image
= -1, int selectedImage
= -1,
415 wxTreeItemData
*data
= NULL
);
417 // insert a new item in as the first child of the parent
418 wxTreeItemId
PrependItem(const wxTreeItemId
& parent
,
419 const wxString
& text
,
420 int image
= -1, int selectedImage
= -1,
421 wxTreeItemData
*data
= NULL
);
423 // insert a new item after a given one
424 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
425 const wxTreeItemId
& idPrevious
,
426 const wxString
& text
,
427 int image
= -1, int selectedImage
= -1,
428 wxTreeItemData
*data
= NULL
);
430 // insert a new item before the one with the given index
431 wxTreeItemId
InsertItem(const wxTreeItemId
& parent
,
433 const wxString
& text
,
434 int image
= -1, int selectedImage
= -1,
435 wxTreeItemData
*data
= NULL
);
437 // insert a new item in as the last child of the parent
438 wxTreeItemId
AppendItem(const wxTreeItemId
& parent
,
439 const wxString
& text
,
440 int image
= -1, int selectedImage
= -1,
441 wxTreeItemData
*data
= NULL
);
443 // delete this item and associated data if any
444 void Delete(const wxTreeItemId
& item
);
445 // delete all children (but don't delete the item itself)
446 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
447 void DeleteChildren(const wxTreeItemId
& item
);
448 // delete all items from the tree
449 // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
450 void DeleteAllItems();
453 void Expand(const wxTreeItemId
& item
);
454 // expand this item and all subitems recursively
455 void ExpandAll(const wxTreeItemId
& item
);
456 // collapse the item without removing its children
457 void Collapse(const wxTreeItemId
& item
);
458 // collapse the item and remove all children
459 void CollapseAndReset(const wxTreeItemId
& item
);
460 // toggles the current state
461 void Toggle(const wxTreeItemId
& item
);
463 // remove the selection from currently selected item (if any)
467 void SelectItem(const wxTreeItemId
& item
, bool unselect_others
=TRUE
,
468 bool extended_select
=FALSE
);
469 void SelectAll(bool extended_select
=FALSE
);
470 // make sure this item is visible (expanding the parent item and/or
471 // scrolling to this item if necessary)
472 void EnsureVisible(const wxTreeItemId
& item
);
473 // scroll to this item (but don't expand its parent)
474 void ScrollTo(const wxTreeItemId
& item
);
475 void AdjustMyScrollbars();
477 // The first function is more portable (because easier to implement
478 // on other platforms), but the second one returns some extra info.
479 wxTreeItemId
HitTest(const wxPoint
& point
)
480 { int dummy
; return HitTest(point
, dummy
); }
481 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
)
482 { int col
; return HitTest(point
, flags
, col
); }
484 wxTreeItemId
HitTest(const wxPoint
& point
, int& flags
, int& column
);
487 // get the bounding rectangle of the item (or of its label only)
488 bool GetBoundingRect(const wxTreeItemId
& item
,
490 bool textOnly
= FALSE
) const;
492 // Start editing the item label: this (temporarily) replaces the item
493 // with a one line edit control. The item will be selected if it hadn't
495 void EditLabel( const wxTreeItemId
& item
) { Edit( item
); }
496 void Edit( const wxTreeItemId
& item
);
499 // this function is called to compare 2 items and should return -1, 0
500 // or +1 if the first item is less than, equal to or greater than the
501 // second one. The base class version performs alphabetic comparaison
502 // of item labels (GetText)
503 virtual int OnCompareItems(const wxTreeItemId
& item1
,
504 const wxTreeItemId
& item2
);
505 // sort the children of this item using OnCompareItems
507 // NB: this function is not reentrant and not MT-safe (FIXME)!
508 void SortChildren(const wxTreeItemId
& item
);
510 // deprecated functions: use Set/GetItemImage directly
511 // get the selected item image
512 int GetItemSelectedImage(const wxTreeItemId
& item
) const
513 { return GetItemImage(item
, wxTreeItemIcon_Selected
); }
514 // set the selected item image
515 void SetItemSelectedImage(const wxTreeItemId
& item
, int image
)
516 { SetItemImage(item
, image
, wxTreeItemIcon_Selected
); }
518 // implementation only from now on
520 // overridden base class virtuals
521 virtual bool SetBackgroundColour(const wxColour
& colour
);
522 virtual bool SetForegroundColour(const wxColour
& colour
);
525 void OnPaint( wxPaintEvent
&event
);
526 void OnSetFocus( wxFocusEvent
&event
);
527 void OnKillFocus( wxFocusEvent
&event
);
528 void OnChar( wxKeyEvent
&event
);
529 void OnMouse( wxMouseEvent
&event
);
530 void OnIdle( wxIdleEvent
&event
);
531 void OnSize(wxSizeEvent
& event
); // ALB
532 void OnScroll(wxScrollWinEvent
& event
); // ALB
534 // implementation helpers
535 void SendDeleteEvent(wxTreeListItem
*itemBeingDeleted
);
537 void DrawBorder(const wxTreeItemId
& item
);
538 void DrawLine(const wxTreeItemId
& item
, bool below
);
540 size_t GetColumnCount() const
541 { return m_owner
->GetHeaderWindow()->GetColumnCount(); }
543 void SetMainColumn(size_t column
)
545 if(column
< GetColumnCount())
546 m_main_column
= column
;
548 size_t GetMainColumn() const { return m_main_column
; }
550 void SetItemText(const wxTreeItemId
& item
, size_t column
,
551 const wxString
& text
);
552 wxString
GetItemText(const wxTreeItemId
& item
, size_t column
) const;
554 void SetItemImage(const wxTreeItemId
& item
, size_t column
, int image
,
555 wxTreeItemIcon which
= wxTreeItemIcon_Normal
);
556 int GetItemImage(const wxTreeItemId
& item
, size_t column
,
557 wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const;
559 wxTreeListCtrl
* m_owner
; // ALB
561 size_t m_main_column
; // ALB
563 friend class wxTreeListItem
;
564 friend class wxTreeListRenameTimer
;
565 friend class wxTreeListTextCtrl
;
570 wxTreeListItem
*m_anchor
;
571 wxTreeListItem
*m_current
, *m_key_current
, *m_currentEdit
;
572 int m_btnWidth
, m_btnWidth2
;
573 int m_btnHeight
, m_btnHeight2
;
574 int m_imgWidth
, m_imgWidth2
;
575 int m_imgHeight
, m_imgHeight2
;
576 unsigned short m_indent
;
578 unsigned short m_linespacing
;
580 wxBrush
*m_hilightBrush
,
581 *m_hilightUnfocusedBrush
;
586 bool m_ownsImageListNormal
,
587 m_ownsImageListState
,
588 m_ownsImageListButtons
;
589 bool m_isDragging
; // true between BEGIN/END drag events
591 bool m_lastOnSame
; // last click on the same item as prev
592 wxImageList
*m_imageListNormal
,
598 wxTreeListItem
*m_dropTarget
;
599 wxCursor m_oldCursor
; // cursor is changed while dragging
600 wxTreeListItem
*m_oldSelection
;
602 wxTimer
*m_renameTimer
;
603 wxString m_renameRes
;
605 // the common part of all ctors
609 wxTreeItemId
DoInsertItem(const wxTreeItemId
& parent
,
611 const wxString
& text
,
612 int image
, int selectedImage
,
613 wxTreeItemData
*data
);
614 bool HasButtons(void) const
615 { return (m_imageListButtons
!= NULL
) ||
616 HasFlag (wxTR_TWIST_BUTTONS
|wxTR_HAS_BUTTONS
); }
619 void CalculateLineHeight();
620 int GetLineHeight(wxTreeListItem
*item
) const;
621 void PaintLevel( wxTreeListItem
*item
, wxDC
& dc
, int level
, int &y
,
623 void PaintItem( wxTreeListItem
*item
, wxDC
& dc
);
625 void CalculateLevel( wxTreeListItem
*item
, wxDC
&dc
, int level
, int &y
,
627 void CalculatePositions();
628 void CalculateSize( wxTreeListItem
*item
, wxDC
&dc
);
630 void RefreshSubtree( wxTreeListItem
*item
);
631 void RefreshLine( wxTreeListItem
*item
);
633 // redraw all selected items
634 void RefreshSelected();
636 // RefreshSelected() recursive helper
637 void RefreshSelectedUnder(wxTreeListItem
*item
);
639 void OnRenameTimer();
640 void OnRenameAccept();
642 void FillArray(wxTreeListItem
*, wxArrayTreeItemIds
&) const;
643 void SelectItemRange( wxTreeListItem
*item1
, wxTreeListItem
*item2
);
644 bool TagAllChildrenUntilLast(wxTreeListItem
*crt_item
,
645 wxTreeListItem
*last_item
, bool select
);
646 bool TagNextChildren(wxTreeListItem
*crt_item
, wxTreeListItem
*last_item
,
648 void UnselectAllChildren( wxTreeListItem
*item
);
650 void DrawDropEffect(wxTreeListItem
*item
);
653 DECLARE_EVENT_TABLE()
654 DECLARE_DYNAMIC_CLASS(wxTreeListMainWindow
)
658 // timer used for enabling in-place edit
659 class wxTreeListRenameTimer
: public wxTimer
662 wxTreeListRenameTimer( wxTreeListMainWindow
*owner
);
667 wxTreeListMainWindow
*m_owner
;
670 // control used for in-place edit
671 class wxTreeListTextCtrl
: public wxTextCtrl
674 wxTreeListTextCtrl( wxWindow
*parent
,
678 wxTreeListMainWindow
*owner
,
679 const wxString
&value
= wxEmptyString
,
680 const wxPoint
&pos
= wxDefaultPosition
,
681 const wxSize
&size
= wxDefaultSize
,
682 int style
= wxSIMPLE_BORDER
,
683 const wxValidator
& validator
= wxDefaultValidator
,
684 const wxString
&name
= wxTextCtrlNameStr
);
686 void OnChar( wxKeyEvent
&event
);
687 void OnKeyUp( wxKeyEvent
&event
);
688 void OnKillFocus( wxFocusEvent
&event
);
693 wxTreeListMainWindow
*m_owner
;
694 wxString m_startValue
;
697 DECLARE_EVENT_TABLE()
705 wxTreeListItem() { m_data
= NULL
; }
706 wxTreeListItem( wxTreeListMainWindow
*owner
,
707 wxTreeListItem
*parent
,
708 const wxArrayString
& text
,
711 wxTreeItemData
*data
);
716 wxArrayTreeListItems
& GetChildren() { return m_children
; }
718 const wxString
GetText() const
720 if(m_text
.GetCount() > 0) return m_text
[0];
721 return wxEmptyString
;
723 const wxString
GetText(size_t col
) const
725 if(m_text
.GetCount() > col
) return m_text
[col
];
726 return wxEmptyString
;
728 int GetImage(wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
729 { return m_images
[which
]; }
730 int GetImage(size_t col
, wxTreeItemIcon which
=wxTreeItemIcon_Normal
) const
732 if(col
== m_owner
->GetMainColumn()) return m_images
[which
];
733 if(col
< m_col_images
.GetCount()) return m_col_images
[col
];
736 wxTreeItemData
*GetData() const { return m_data
; }
738 // returns the current image for the item (depending on its
739 // selected/expanded/whatever state)
740 int GetCurrentImage() const;
742 void SetText( const wxString
&text
);
743 void SetText(size_t col
, const wxString
& text
) // ALB
745 if(col
< m_text
.GetCount())
747 else if(col
< m_owner
->GetColumnCount()) {
748 int howmany
= m_owner
->GetColumnCount();
749 for(int i
= m_text
.GetCount(); i
< howmany
; ++i
)
750 m_text
.Add(wxEmptyString
);
754 void SetImage(int image
, wxTreeItemIcon which
) { m_images
[which
] = image
; }
755 void SetImage(size_t col
, int image
, wxTreeItemIcon which
)
757 if(col
== m_owner
->GetMainColumn()) m_images
[which
] = image
;
758 else if(col
< m_col_images
.GetCount())
759 m_col_images
[col
] = image
;
760 else if(col
< m_owner
->GetColumnCount()) {
761 int howmany
= m_owner
->GetColumnCount();
762 for(int i
= m_col_images
.GetCount(); i
< howmany
; ++i
)
763 m_col_images
.Add(NO_IMAGE
);
764 m_col_images
[col
] = image
;
768 void SetData(wxTreeItemData
*data
) { m_data
= data
; }
770 void SetHasPlus(bool has
= TRUE
) { m_hasPlus
= has
; }
772 void SetBold(bool bold
) { m_isBold
= bold
; }
774 int GetX() const { return m_x
; }
775 int GetY() const { return m_y
; }
777 void SetX(int x
) { m_x
= x
; }
778 void SetY(int y
) { m_y
= y
; }
780 int GetHeight() const { return m_height
; }
781 int GetWidth() const { return m_width
; }
783 void SetHeight(int h
) { m_height
= h
; }
784 void SetWidth(int w
) { m_width
= w
; }
786 wxTreeListItem
*GetItemParent() const { return m_parent
; }
789 // deletes all children notifying the treectrl about it if !NULL
791 void DeleteChildren(wxTreeListMainWindow
*tree
= NULL
);
793 // get count of all children (and grand children if 'recursively')
794 size_t GetChildrenCount(bool recursively
= TRUE
) const;
796 void Insert(wxTreeListItem
*child
, size_t index
)
797 { m_children
.Insert(child
, index
); }
799 void GetSize( int &x
, int &y
, const wxTreeListMainWindow
* );
801 // return the item at given position (or NULL if no item), onButton is
802 // TRUE if the point belongs to the item's button, otherwise it lies
803 // on the button's label
804 wxTreeListItem
*HitTest( const wxPoint
& point
,
805 const wxTreeListMainWindow
*,
808 wxTreeListItem
*HitTest( const wxPoint
& point
,
809 const wxTreeListMainWindow
*,
810 int &flags
, int& column
/*ALB*/,
813 void Expand() { m_isCollapsed
= FALSE
; }
814 void Collapse() { m_isCollapsed
= TRUE
; }
816 void SetHilight( bool set
= TRUE
) { m_hasHilight
= set
; }
819 bool HasChildren() const { return !m_children
.IsEmpty(); }
820 bool IsSelected() const { return m_hasHilight
!= 0; }
821 bool IsExpanded() const { return !m_isCollapsed
; }
822 bool HasPlus() const { return m_hasPlus
|| HasChildren(); }
823 bool IsBold() const { return m_isBold
!= 0; }
826 // get them - may be NULL
827 wxTreeItemAttr
*GetAttributes() const { return m_attr
; }
828 // get them ensuring that the pointer is not NULL
829 wxTreeItemAttr
& Attr()
833 m_attr
= new wxTreeItemAttr
;
839 void SetAttributes(wxTreeItemAttr
*attr
)
841 if ( m_ownsAttr
) delete m_attr
;
845 // set them and delete when done
846 void AssignAttributes(wxTreeItemAttr
*attr
)
853 wxTreeListMainWindow
*m_owner
; // control the item belongs to
855 // since there can be very many of these, we save size by chosing
856 // the smallest representation for the elements and by ordering
857 // the members to avoid padding.
858 wxArrayString m_text
; // labels to be rendered for item
860 wxTreeItemData
*m_data
; // user-provided data
862 wxArrayTreeListItems m_children
; // list of children
863 wxTreeListItem
*m_parent
; // parent of this item
865 wxTreeItemAttr
*m_attr
; // attributes???
867 // tree ctrl images for the normal, selected, expanded and
868 // expanded+selected states
869 short m_images
[wxTreeItemIcon_Max
];
870 wxArrayShort m_col_images
; // images for the various columns (!= main)
872 wxCoord m_x
; // (virtual) offset from top
873 wxCoord m_y
; // (virtual) offset from left
874 short m_width
; // width of this item
875 unsigned char m_height
; // height of this item
877 // use bitfields to save size
878 int m_isCollapsed
:1;
879 int m_hasHilight
:1; // same as focused
880 int m_hasPlus
:1; // used for item which doesn't have
881 // children but has a [+] button
882 int m_isBold
:1; // render the label in bold font
883 int m_ownsAttr
:1; // delete attribute when done
886 // ===========================================================================
888 // ===========================================================================
890 // ----------------------------------------------------------------------------
892 // ----------------------------------------------------------------------------
894 // translate the key or mouse event flags to the type of selection we're
896 static void EventFlagsToSelType(long style
,
900 bool &extended_select
,
901 bool &unselect_others
)
903 is_multiple
= (style
& wxTR_MULTIPLE
) != 0;
904 extended_select
= shiftDown
&& is_multiple
;
905 unselect_others
= !(extended_select
|| (ctrlDown
&& is_multiple
));
908 // ---------------------------------------------------------------------------
909 // wxTreeListRenameTimer (internal)
910 // ---------------------------------------------------------------------------
912 wxTreeListRenameTimer::wxTreeListRenameTimer( wxTreeListMainWindow
*owner
)
917 void wxTreeListRenameTimer::Notify()
919 m_owner
->OnRenameTimer();
922 //-----------------------------------------------------------------------------
923 // wxTreeListTextCtrl (internal)
924 //-----------------------------------------------------------------------------
926 BEGIN_EVENT_TABLE(wxTreeListTextCtrl
,wxTextCtrl
)
927 EVT_CHAR (wxTreeListTextCtrl::OnChar
)
928 EVT_KEY_UP (wxTreeListTextCtrl::OnKeyUp
)
929 EVT_KILL_FOCUS (wxTreeListTextCtrl::OnKillFocus
)
932 wxTreeListTextCtrl::wxTreeListTextCtrl( wxWindow
*parent
,
936 wxTreeListMainWindow
*owner
,
937 const wxString
&value
,
941 const wxValidator
& validator
,
942 const wxString
&name
)
943 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
949 (*m_res
) = wxEmptyString
;
950 m_startValue
= value
;
954 void wxTreeListTextCtrl::OnChar( wxKeyEvent
&event
)
956 if (event
.m_keyCode
== WXK_RETURN
)
959 (*m_res
) = GetValue();
961 if ((*m_res
) != m_startValue
)
962 m_owner
->OnRenameAccept();
964 if (!wxPendingDelete
.Member(this))
965 wxPendingDelete
.Append(this);
968 m_owner
->SetFocus(); // This doesn't work. TODO.
972 if (event
.m_keyCode
== WXK_ESCAPE
)
975 (*m_res
) = wxEmptyString
;
977 if (!wxPendingDelete
.Member(this))
978 wxPendingDelete
.Append(this);
981 m_owner
->SetFocus(); // This doesn't work. TODO.
988 void wxTreeListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
996 // auto-grow the textctrl:
997 wxSize parentSize
= m_owner
->GetSize();
998 wxPoint myPos
= GetPosition();
999 wxSize mySize
= GetSize();
1001 GetTextExtent(GetValue() + _T("M"), &sx
, &sy
);
1002 if (myPos
.x
+ sx
> parentSize
.x
) sx
= parentSize
.x
- myPos
.x
;
1003 if (mySize
.x
> sx
) sx
= mySize
.x
;
1009 void wxTreeListTextCtrl::OnKillFocus( wxFocusEvent
&event
)
1017 if (!wxPendingDelete
.Member(this))
1018 wxPendingDelete
.Append(this);
1021 (*m_res
) = GetValue();
1023 if ((*m_res
) != m_startValue
)
1024 m_owner
->OnRenameAccept();
1027 //-----------------------------------------------------------------------------
1028 // wxTreeListHeaderWindow
1029 //-----------------------------------------------------------------------------
1031 IMPLEMENT_DYNAMIC_CLASS(wxTreeListHeaderWindow
,wxWindow
);
1033 BEGIN_EVENT_TABLE(wxTreeListHeaderWindow
,wxWindow
)
1034 EVT_PAINT (wxTreeListHeaderWindow::OnPaint
)
1035 EVT_MOUSE_EVENTS (wxTreeListHeaderWindow::OnMouse
)
1036 EVT_SET_FOCUS (wxTreeListHeaderWindow::OnSetFocus
)
1039 void wxTreeListHeaderWindow::Init()
1041 m_currentCursor
= (wxCursor
*) NULL
;
1042 m_isDragging
= FALSE
;
1044 m_total_col_width
= 0;
1047 wxTreeListHeaderWindow::wxTreeListHeaderWindow()
1051 m_owner
= (wxTreeListMainWindow
*) NULL
;
1052 m_resizeCursor
= (wxCursor
*) NULL
;
1055 wxTreeListHeaderWindow::wxTreeListHeaderWindow( wxWindow
*win
,
1057 wxTreeListMainWindow
*owner
,
1061 const wxString
&name
)
1062 : wxWindow( win
, id
, pos
, size
, style
, name
)
1067 m_resizeCursor
= new wxCursor(wxCURSOR_SIZEWE
);
1069 SetBackgroundColour(wxSystemSettings::GetSystemColour(
1070 wxSYS_COLOUR_BTNFACE
));
1073 wxTreeListHeaderWindow::~wxTreeListHeaderWindow()
1075 delete m_resizeCursor
;
1078 void wxTreeListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1081 GtkStateType state
= m_parent
->IsEnabled() ? GTK_STATE_NORMAL
1082 : GTK_STATE_INSENSITIVE
;
1084 x
= dc
->XLOG2DEV( x
);
1086 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
,
1087 state
, GTK_SHADOW_OUT
,
1088 (GdkRectangle
*) NULL
, m_wxwindow
, "button",
1089 x
-1, y
-1, w
+2, h
+2);
1090 #elif defined( __WXMAC__ )
1091 const int m_corner
= 1;
1093 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1095 dc
->SetPen( wxPen(wxSystemSettings::GetSystemColour(
1096 wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
));
1097 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1098 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1100 wxPen
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID
);
1103 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1104 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1106 dc
->SetPen( *wxWHITE_PEN
);
1107 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1108 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1109 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1110 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1112 const int m_corner
= 1;
1114 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1116 dc
->SetPen( *wxBLACK_PEN
);
1117 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1118 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1120 wxPen
pen(wxSystemSettings::GetSystemColour(
1121 wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1124 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1125 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1127 dc
->SetPen( *wxWHITE_PEN
);
1128 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1129 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1130 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1131 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1135 // shift the DC origin to match the position of the main window horz
1136 // scrollbar: this allows us to always use logical coords
1137 void wxTreeListHeaderWindow::AdjustDC(wxDC
& dc
)
1140 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1143 m_owner
->GetViewStart( &x
, NULL
);
1145 // account for the horz scrollbar offset
1146 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1149 void wxTreeListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1151 static const int HEADER_OFFSET_X
= 1, HEADER_OFFSET_Y
= 1;
1153 wxClientDC
dc( this );
1155 wxPaintDC
dc( this );
1163 dc
.SetFont( GetFont() );
1165 // width and height of the entire header window
1167 GetClientSize( &w
, &h
);
1168 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1170 dc
.SetBackgroundMode(wxTRANSPARENT
);
1172 // do *not* use the listctrl colour for headers - one day we will have a
1173 // function to set it separately
1174 //dc.SetTextForeground( *wxBLACK );
1175 dc
.SetTextForeground(wxSystemSettings::
1176 GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1178 int x
= HEADER_OFFSET_X
;
1180 int numColumns
= GetColumnCount();
1181 for ( int i
= 0; i
< numColumns
&& x
< w
; i
++ )
1183 if (!GetColumnShown (i
)) continue;
1185 wxTreeListColumnInfo
& column
= GetColumn(i
);
1186 int wCol
= column
.GetWidth();
1188 // the width of the rect to draw: make it smaller to fit entirely
1189 // inside the column rect
1192 dc
.SetPen( *wxWHITE_PEN
);
1194 DoDrawRect( &dc
, x
, HEADER_OFFSET_Y
, cw
, h
-2 );
1196 // if we have an image, draw it on the right of the label
1197 int image
= column
.GetImage(); //item.m_image;
1198 int ix
= -2, iy
= 0;
1199 wxImageList
* imageList
= m_owner
->GetImageList();
1202 imageList
->GetSize(image
, ix
, iy
);
1204 //else: ignore the column image
1207 // extra margins around the text label
1208 static const int EXTRA_WIDTH
= 3;
1209 static const int EXTRA_HEIGHT
= 4;
1213 int image_offset
= cw
- ix
- 1;
1215 switch(column
.GetAlignment()) {
1216 case wxTL_ALIGN_LEFT
:
1217 text_x
+= EXTRA_WIDTH
;
1220 case wxTL_ALIGN_RIGHT
:
1221 dc
.GetTextExtent(column
.GetText(), &text_width
, NULL
);
1222 text_x
+= cw
- text_width
- EXTRA_WIDTH
;
1225 case wxTL_ALIGN_CENTER
:
1226 dc
.GetTextExtent(column
.GetText(), &text_width
, NULL
);
1227 text_x
+= (cw
- text_width
)/2 + ix
+ 2;
1228 image_offset
= (cw
- text_width
- ix
- 2)/2;
1233 if(image
!= -1 && imageList
) {
1234 imageList
->Draw(image
, dc
, x
+ image_offset
/*cw - ix - 1*/,
1235 HEADER_OFFSET_Y
+ (h
- 4 - iy
)/2,
1236 wxIMAGELIST_DRAW_TRANSPARENT
);
1239 // draw the text clipping it so that it doesn't overwrite the column
1241 wxDCClipper
clipper(dc
, x
, HEADER_OFFSET_Y
, cw
, h
- 4 );
1243 dc
.DrawText( column
.GetText(),
1244 text_x
, HEADER_OFFSET_Y
+ EXTRA_HEIGHT
);
1249 int more_w
= m_owner
->GetSize().x
- x
;
1252 DoDrawRect( &dc
, x
, HEADER_OFFSET_Y
, more_w
, h
-2 );
1259 void wxTreeListHeaderWindow::DrawCurrent()
1261 int x1
= m_currentX
;
1263 ClientToScreen( &x1
, &y1
);
1265 int x2
= m_currentX
-1;
1270 m_owner
->GetClientSize( NULL
, &y2
);
1271 m_owner
->ClientToScreen( &x2
, &y2
);
1274 dc
.SetLogicalFunction( wxINVERT
);
1275 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1276 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1280 dc
.DrawLine( x1
, y1
, x2
, y2
);
1282 dc
.SetLogicalFunction( wxCOPY
);
1284 dc
.SetPen( wxNullPen
);
1285 dc
.SetBrush( wxNullBrush
);
1288 void wxTreeListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1290 // we want to work with logical coords
1292 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1293 int y
= event
.GetY();
1297 SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING
,
1298 event
.GetPosition());
1300 // we don't draw the line beyond our window, but we allow dragging it
1303 GetClientSize( &w
, NULL
);
1304 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1307 // erase the line if it was drawn
1308 if ( m_currentX
< w
)
1311 if (event
.ButtonUp())
1314 m_isDragging
= FALSE
;
1316 SetColumnWidth( m_column
, m_currentX
- m_minX
);
1318 SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG
,
1319 event
.GetPosition());
1326 m_currentX
= m_minX
+ 7;
1328 // draw in the new location
1329 if ( m_currentX
< w
)
1333 else // not dragging
1336 bool hit_border
= FALSE
;
1338 // end of the current column
1341 // find the column where this event occured
1342 int countCol
= GetColumnCount();
1343 for (int col
= 0; col
< countCol
; col
++)
1345 if (!GetColumnShown (col
)) continue;
1346 xpos
+= GetColumnWidth (col
);
1349 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1351 // near the column border
1358 // inside the column
1365 if (event
.LeftDown() || event
.RightUp())
1367 if (hit_border
&& event
.LeftDown())
1369 m_isDragging
= TRUE
;
1373 SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
,
1374 event
.GetPosition());
1376 else // click on a column
1378 SendListEvent( event
.LeftDown()
1379 ? wxEVT_COMMAND_LIST_COL_CLICK
1380 : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
,
1381 event
.GetPosition());
1384 else if (event
.Moving())
1389 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1390 m_currentCursor
= m_resizeCursor
;
1394 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1395 m_currentCursor
= wxSTANDARD_CURSOR
;
1399 SetCursor(*m_currentCursor
);
1404 void wxTreeListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1406 m_owner
->SetFocus();
1409 void wxTreeListHeaderWindow::SendListEvent(wxEventType type
, wxPoint pos
)
1411 wxWindow
*parent
= GetParent();
1412 wxListEvent
le( type
, parent
->GetId() );
1413 le
.SetEventObject( parent
);
1414 le
.m_pointDrag
= pos
;
1416 // the position should be relative to the parent window, not
1417 // this one for compatibility with MSW and common sense: the
1418 // user code doesn't know anything at all about this header
1419 // window, so why should it get positions relative to it?
1420 le
.m_pointDrag
.y
-= GetSize().y
;
1422 le
.m_col
= m_column
;
1423 parent
->GetEventHandler()->ProcessEvent( le
);
1427 void wxTreeListHeaderWindow::AddColumn(const wxTreeListColumnInfo
& col
)
1430 m_total_col_width
+= col
.GetWidth();
1431 //m_owner->GetHeaderWindow()->Refresh();
1433 m_owner
->AdjustMyScrollbars();
1434 m_owner
->m_dirty
= TRUE
;
1439 void wxTreeListHeaderWindow::SetColumnWidth(size_t column
, size_t width
)
1441 if(column
< GetColumnCount()) {
1442 m_total_col_width
-= m_columns
[column
].GetWidth();
1443 m_columns
[column
].SetWidth(width
);
1444 m_total_col_width
+= width
;
1445 m_owner
->AdjustMyScrollbars();
1446 m_owner
->m_dirty
= TRUE
;
1454 void wxTreeListHeaderWindow::InsertColumn(size_t before
,
1455 const wxTreeListColumnInfo
& col
)
1457 wxCHECK_RET(before
< GetColumnCount(), wxT("Invalid column index"));
1458 m_columns
.Insert(col
, before
);
1459 m_total_col_width
+= col
.GetWidth();
1461 //m_owner->GetHeaderWindow()->Refresh();
1462 m_owner
->AdjustMyScrollbars();
1463 m_owner
->m_dirty
= TRUE
;
1468 void wxTreeListHeaderWindow::RemoveColumn(size_t column
)
1470 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
1471 m_total_col_width
-= m_columns
[column
].GetWidth();
1472 m_columns
.RemoveAt(column
);
1474 m_owner
->AdjustMyScrollbars();
1475 m_owner
->m_dirty
= TRUE
;
1480 void wxTreeListHeaderWindow::SetColumn(size_t column
,
1481 const wxTreeListColumnInfo
& info
)
1483 wxCHECK_RET(column
< GetColumnCount(), wxT("Invalid column"));
1484 size_t w
= m_columns
[column
].GetWidth();
1485 m_columns
[column
] = info
;
1486 //m_owner->GetHeaderWindow()->Refresh();
1488 if(w
!= info
.GetWidth()) {
1489 m_total_col_width
+= info
.GetWidth() - w
;
1490 m_owner
->AdjustMyScrollbars();
1491 m_owner
->m_dirty
= TRUE
;
1496 // ---------------------------------------------------------------------------
1498 // ---------------------------------------------------------------------------
1500 wxTreeListItem::wxTreeListItem(wxTreeListMainWindow
*owner
,
1501 wxTreeListItem
*parent
,
1502 const wxArrayString
& text
,
1503 int image
, int selImage
,
1504 wxTreeItemData
*data
)
1507 m_images
[wxTreeItemIcon_Normal
] = image
;
1508 m_images
[wxTreeItemIcon_Selected
] = selImage
;
1509 m_images
[wxTreeItemIcon_Expanded
] = NO_IMAGE
;
1510 m_images
[wxTreeItemIcon_SelectedExpanded
] = NO_IMAGE
;
1515 m_isCollapsed
= TRUE
;
1516 m_hasHilight
= FALSE
;
1524 m_attr
= (wxTreeItemAttr
*)NULL
;
1527 // We don't know the height here yet.
1532 wxTreeListItem::~wxTreeListItem()
1536 if (m_ownsAttr
) delete m_attr
;
1538 wxASSERT_MSG( m_children
.IsEmpty(),
1539 wxT("please call DeleteChildren() before deleting the item") );
1542 void wxTreeListItem::DeleteChildren(wxTreeListMainWindow
*tree
)
1544 size_t count
= m_children
.Count();
1545 for ( size_t n
= 0; n
< count
; n
++ )
1547 wxTreeListItem
*child
= m_children
[n
];
1549 tree
->SendDeleteEvent(child
);
1551 child
->DeleteChildren(tree
);
1558 void wxTreeListItem::SetText( const wxString
&text
)
1560 if(m_text
.GetCount() > 0) m_text
[0] = text
;
1566 size_t wxTreeListItem::GetChildrenCount(bool recursively
) const
1568 size_t count
= m_children
.Count();
1572 size_t total
= count
;
1573 for (size_t n
= 0; n
< count
; ++n
)
1575 total
+= m_children
[n
]->GetChildrenCount();
1581 void wxTreeListItem::GetSize( int &x
, int &y
,
1582 const wxTreeListMainWindow
*theButton
)
1584 int bottomY
=m_y
+theButton
->GetLineHeight(this);
1585 if ( y
< bottomY
) y
= bottomY
;
1586 int width
= m_x
+ m_width
;
1587 if ( x
< width
) x
= width
;
1591 size_t count
= m_children
.Count();
1592 for ( size_t n
= 0; n
< count
; ++n
)
1594 m_children
[n
]->GetSize( x
, y
, theButton
);
1599 wxTreeListItem
*wxTreeListItem::HitTest(const wxPoint
& point
,
1600 const wxTreeListMainWindow
*theCtrl
,
1604 // for a hidden root node, don't evaluate it, but do evaluate children
1605 if (!(theCtrl
->HasFlag(wxTR_HIDE_ROOT
) && (level
== 0)))
1607 // evaluate the item
1608 int h
= theCtrl
->GetLineHeight(this);
1609 if ((point
.y
> m_y
) && (point
.y
< m_y
+ h
))
1611 // check for above/below middle
1612 int y_mid
= m_y
+ h
/2;
1613 if (point
.y
< y_mid
)
1614 flags
|= wxTREE_HITTEST_ONITEMUPPERPART
;
1616 flags
|= wxTREE_HITTEST_ONITEMLOWERPART
;
1618 // check for button hit
1619 if (HasPlus() && theCtrl
->HasButtons()) {
1620 int bntX
= m_x
- theCtrl
->GetIndent() - theCtrl
->m_btnWidth2
;
1621 int bntY
= y_mid
- theCtrl
->m_btnHeight2
;
1622 if ((point
.x
> bntX
) && (point
.x
< (bntX
+ theCtrl
->m_btnWidth
)) &&
1623 (point
.y
> bntY
) && (point
.y
< (bntY
+ theCtrl
->m_btnHeight
))) {
1624 flags
|= wxTREE_HITTEST_ONITEMBUTTON
;
1629 // check for image hit
1630 int imgX
= m_x
- theCtrl
->m_imgWidth2
;
1631 int imgY
= y_mid
- theCtrl
->m_imgHeight2
;
1632 if ((point
.x
>= imgX
) && (point
.x
<= (imgX
+ theCtrl
->m_imgWidth
)) &&
1633 (point
.y
>= imgY
) && (point
.y
<= (imgY
+ theCtrl
->m_imgHeight
))) {
1634 flags
|= wxTREE_HITTEST_ONITEMICON
;
1638 // check for label hit
1639 int lblX
= m_x
- theCtrl
->m_imgWidth2
+ theCtrl
->m_imgWidth
+ MARGIN
;
1640 if ((point
.x
>= lblX
) && (point
.x
<= (m_x
+ m_width
)) &&
1641 (point
.y
>= m_y
) && (point
.y
<= (m_y
+ h
))) {
1642 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
1646 // else check for indent
1647 if (point
.x
< m_x
) {
1648 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
1652 // else check for item right???
1653 if (point
.x
> m_x
+ m_width
) {
1654 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
1660 // if children are expanded, fall through to evaluate them
1661 if (m_isCollapsed
) return (wxTreeListItem
*) NULL
;
1664 // evaluate children
1665 size_t count
= m_children
.Count();
1666 for ( size_t n
= 0; n
< count
; n
++ )
1668 wxTreeListItem
*res
= m_children
[n
]->HitTest(point
, theCtrl
,
1674 return (wxTreeListItem
*) NULL
;
1678 wxTreeListItem
*wxTreeListItem::HitTest(const wxPoint
& point
,
1679 const wxTreeListMainWindow
*theCtrl
,
1680 int &flags
, int& column
, int level
)
1682 column
= theCtrl
->GetMainColumn(); //-1;
1684 wxTreeListItem
* res
= HitTest(point
, theCtrl
, flags
, level
);
1690 wxTreeListHeaderWindow
* header_win
= theCtrl
->m_owner
->GetHeaderWindow();
1691 if (point
.x
>= header_win
->GetWidth())
1693 else if(flags
& wxTREE_HITTEST_ONITEMINDENT
) {
1695 for(size_t i
= 0; i
< theCtrl
->GetMainColumn(); ++i
) {
1696 if (!header_win
->GetColumnShown(i
)) continue;
1697 int w
= header_win
->GetColumnWidth(i
);
1698 if(point
.x
>= x
&& point
.x
< x
+w
) {
1699 flags
^= wxTREE_HITTEST_ONITEMINDENT
;
1700 flags
|= wxTREE_HITTEST_ONITEMCOLUMN
;
1706 else if(flags
& wxTREE_HITTEST_ONITEMRIGHT
) {
1709 for(i
= 0; i
< theCtrl
->GetMainColumn()+1; ++i
) {
1710 if (!header_win
->GetColumnShown(i
)) continue;
1711 x
+= header_win
->GetColumnWidth(i
);
1713 for(i
= theCtrl
->GetMainColumn()+1; i
< theCtrl
->GetColumnCount(); ++i
) {
1714 if (!header_win
->GetColumnShown(i
)) continue;
1715 int w
= header_win
->GetColumnWidth(i
);
1716 if(point
.x
>= x
&& point
.x
< x
+w
) {
1717 flags
^= wxTREE_HITTEST_ONITEMRIGHT
;
1718 flags
|= wxTREE_HITTEST_ONITEMCOLUMN
;
1729 int wxTreeListItem::GetCurrentImage() const
1731 int image
= NO_IMAGE
;
1736 image
= GetImage(wxTreeItemIcon_SelectedExpanded
);
1739 if ( image
== NO_IMAGE
)
1741 // we usually fall back to the normal item, but try just the
1742 // expanded one (and not selected) first in this case
1743 image
= GetImage(wxTreeItemIcon_Expanded
);
1746 else // not expanded
1749 image
= GetImage(wxTreeItemIcon_Selected
);
1752 // maybe it doesn't have the specific image we want,
1753 // try the default one instead
1754 if ( image
== NO_IMAGE
) image
= GetImage();
1759 // ---------------------------------------------------------------------------
1760 // wxTreeListMainWindow implementation
1761 // ---------------------------------------------------------------------------
1763 IMPLEMENT_DYNAMIC_CLASS(wxTreeListMainWindow
, wxScrolledWindow
)
1765 BEGIN_EVENT_TABLE(wxTreeListMainWindow
, wxScrolledWindow
)
1766 EVT_PAINT (wxTreeListMainWindow::OnPaint
)
1767 EVT_MOUSE_EVENTS (wxTreeListMainWindow::OnMouse
)
1768 EVT_CHAR (wxTreeListMainWindow::OnChar
)
1769 EVT_SET_FOCUS (wxTreeListMainWindow::OnSetFocus
)
1770 EVT_KILL_FOCUS (wxTreeListMainWindow::OnKillFocus
)
1771 EVT_IDLE (wxTreeListMainWindow::OnIdle
)
1772 //EVT_SIZE (wxTreeListMainWindow::OnSize)
1773 EVT_SCROLLWIN (wxTreeListMainWindow::OnScroll
)
1777 // ---------------------------------------------------------------------------
1778 // construction/destruction
1779 // ---------------------------------------------------------------------------
1781 void wxTreeListMainWindow::Init()
1783 m_current
= m_key_current
= m_anchor
= (wxTreeListItem
*) NULL
;
1787 m_lineHeight
= LINEHEIGHT
;
1788 m_indent
= MININDENT
; // min. indent
1791 m_hilightBrush
= new wxBrush
1793 wxSystemSettings::GetSystemColour
1795 wxSYS_COLOUR_HIGHLIGHT
1800 m_hilightUnfocusedBrush
= new wxBrush
1802 wxSystemSettings::GetSystemColour
1804 wxSYS_COLOUR_BTNSHADOW
1809 m_imageListNormal
= m_imageListButtons
=
1810 m_imageListState
= (wxImageList
*) NULL
;
1811 m_ownsImageListNormal
= m_ownsImageListButtons
=
1812 m_ownsImageListState
= FALSE
;
1815 m_isDragging
= FALSE
;
1816 m_dropTarget
= m_oldSelection
= (wxTreeListItem
*)NULL
;
1818 m_renameTimer
= new wxTreeListRenameTimer( this );
1819 m_lastOnSame
= FALSE
;
1821 m_normalFont
= wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT
);
1822 m_boldFont
= wxFont( m_normalFont
.GetPointSize(),
1823 m_normalFont
.GetFamily(),
1824 m_normalFont
.GetStyle(),
1826 m_normalFont
.GetUnderlined());
1830 static const int HEADER_HEIGHT
= 23;
1832 bool wxTreeListMainWindow::Create(wxTreeListCtrl
*parent
,
1837 const wxValidator
&validator
,
1838 const wxString
& name
)
1842 wxGetOsVersion( &major
, &minor
);
1844 if (style
& wxTR_HAS_BUTTONS
) style
|= wxTR_MAC_BUTTONS
;
1845 if (style
& wxTR_HAS_BUTTONS
) style
&= ~wxTR_HAS_BUTTONS
;
1846 style
&= ~wxTR_LINES_AT_ROOT
;
1847 style
|= wxTR_NO_LINES
;
1849 style
|= wxTR_ROW_LINES
;
1852 wxScrolledWindow::Create( parent
, id
, pos
, size
,
1853 style
|wxHSCROLL
|wxVSCROLL
, name
);
1855 #if wxUSE_VALIDATORS
1856 SetValidator( validator
);
1859 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1866 bdc
.SelectObject(bmp
);
1867 bdc
.SetPen(*wxGREY_PEN
);
1868 bdc
.DrawRectangle(-1, -1, 10, 10);
1869 for (i
= 0; i
< 8; i
++) {
1870 for (j
= 0; j
< 8; j
++) {
1871 if (!((i
+ j
) & 1)) {
1872 bdc
.DrawPoint(i
, j
);
1877 m_dottedPen
= wxPen(bmp
, 1);
1880 //m_dottedPen = wxPen( *wxGREY_PEN, 1, wxDOT ); // too slow under XFree86
1881 m_dottedPen
= wxPen( wxT("grey"), 0, 0 ); // Bitmap based pen is not supported by GTK!
1891 wxTreeListMainWindow::~wxTreeListMainWindow()
1893 delete m_hilightBrush
;
1894 delete m_hilightUnfocusedBrush
;
1898 delete m_renameTimer
;
1899 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1900 if (m_ownsImageListState
) delete m_imageListState
;
1901 if (m_ownsImageListButtons
) delete m_imageListButtons
;
1906 //-----------------------------------------------------------------------------
1908 //-----------------------------------------------------------------------------
1911 size_t wxTreeListMainWindow::GetCount() const
1913 return m_anchor
== NULL
? 0u : m_anchor
->GetChildrenCount();
1917 void wxTreeListMainWindow::SetIndent(unsigned int indent
)
1924 void wxTreeListMainWindow::SetLineSpacing(unsigned int spacing
)
1926 m_linespacing
= spacing
;
1928 CalculateLineHeight();
1932 size_t wxTreeListMainWindow::GetChildrenCount(const wxTreeItemId
& item
,
1935 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
1937 return ((wxTreeListItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
1940 void wxTreeListMainWindow::SetWindowStyle(const long styles
)
1942 // right now, just sets the styles. Eventually, we may
1943 // want to update the inherited styles, but right now
1944 // none of the parents has updatable styles
1945 m_windowStyle
= styles
;
1949 //-----------------------------------------------------------------------------
1950 // functions to work with tree items
1951 //-----------------------------------------------------------------------------
1954 int wxTreeListMainWindow::GetItemImage(const wxTreeItemId
& item
, size_t column
,
1955 wxTreeItemIcon which
) const
1957 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
1959 return ((wxTreeListItem
*) item
.m_pItem
)->GetImage(column
, which
);
1963 wxTreeItemData
*wxTreeListMainWindow::GetItemData(const wxTreeItemId
& item
)
1966 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
1968 return ((wxTreeListItem
*) item
.m_pItem
)->GetData();
1972 bool wxTreeListMainWindow::GetItemBold(const wxTreeItemId
& item
) const
1974 wxCHECK_MSG(item
.IsOk(), FALSE
, wxT("invalid tree item"));
1975 return ((wxTreeListItem
*)item
.m_pItem
)->IsBold();
1979 wxColour
wxTreeListMainWindow::GetItemTextColour(const wxTreeItemId
& item
)
1982 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
1984 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
1985 return pItem
->Attr().GetTextColour();
1989 wxColour
wxTreeListMainWindow::GetItemBackgroundColour(
1990 const wxTreeItemId
& item
) const
1992 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
1994 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
1995 return pItem
->Attr().GetBackgroundColour();
1999 wxFont
wxTreeListMainWindow::GetItemFont(const wxTreeItemId
& item
) const
2001 wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") );
2003 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2004 return pItem
->Attr().GetFont();
2010 void wxTreeListMainWindow::SetItemImage(const wxTreeItemId
& item
,
2012 int image
, wxTreeItemIcon which
)
2014 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2016 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2017 pItem
->SetImage(column
, image
, which
);
2019 wxClientDC
dc(this);
2020 CalculateSize(pItem
, dc
);
2025 void wxTreeListMainWindow::SetItemData(const wxTreeItemId
& item
,
2026 wxTreeItemData
*data
)
2028 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2030 ((wxTreeListItem
*) item
.m_pItem
)->SetData(data
);
2034 void wxTreeListMainWindow::SetItemHasChildren(const wxTreeItemId
& item
,
2037 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2039 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2040 pItem
->SetHasPlus(has
);
2045 void wxTreeListMainWindow::SetItemBold(const wxTreeItemId
& item
, bool bold
)
2047 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2049 // avoid redrawing the tree if no real change
2050 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2051 if ( pItem
->IsBold() != bold
)
2053 pItem
->SetBold(bold
);
2059 void wxTreeListMainWindow::SetItemTextColour(const wxTreeItemId
& item
,
2060 const wxColour
& col
)
2062 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2064 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2065 pItem
->Attr().SetTextColour(col
);
2070 void wxTreeListMainWindow::SetItemBackgroundColour(const wxTreeItemId
& item
,
2071 const wxColour
& col
)
2073 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2075 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2076 pItem
->Attr().SetBackgroundColour(col
);
2081 void wxTreeListMainWindow::SetItemFont(const wxTreeItemId
& item
,
2084 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
2086 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2087 pItem
->Attr().SetFont(font
);
2092 bool wxTreeListMainWindow::SetFont( const wxFont
&font
)
2094 wxScrolledWindow::SetFont(font
);
2096 m_normalFont
= font
;
2097 m_boldFont
= wxFont( m_normalFont
.GetPointSize(),
2098 m_normalFont
.GetFamily(),
2099 m_normalFont
.GetStyle(),
2101 m_normalFont
.GetUnderlined());
2107 // ----------------------------------------------------------------------------
2108 // item status inquiries
2109 // ----------------------------------------------------------------------------
2112 bool wxTreeListMainWindow::IsVisible(const wxTreeItemId
& item
) const
2114 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2116 // An item is only visible if it's not a descendant of a collapsed item
2117 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
2118 wxTreeListItem
* parent
= pItem
->GetItemParent();
2121 if (!parent
->IsExpanded())
2123 parent
= parent
->GetItemParent();
2127 GetViewStart(& startX
, & startY
);
2129 wxSize clientSize
= GetClientSize();
2132 if (!GetBoundingRect(item
, rect
))
2134 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
2136 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
2138 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
2145 bool wxTreeListMainWindow::ItemHasChildren(const wxTreeItemId
& item
) const
2147 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2149 // consider that the item does have children if it has the "+" button: it
2150 // might not have them (if it had never been expanded yet) but then it
2151 // could have them as well and it's better to err on this side rather than
2152 // disabling some operations which are restricted to the items with
2153 // children for an item which does have them
2154 return ((wxTreeListItem
*) item
.m_pItem
)->HasPlus();
2158 bool wxTreeListMainWindow::IsExpanded(const wxTreeItemId
& item
) const
2160 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2162 return ((wxTreeListItem
*) item
.m_pItem
)->IsExpanded();
2166 bool wxTreeListMainWindow::IsSelected(const wxTreeItemId
& item
) const
2168 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2170 return ((wxTreeListItem
*) item
.m_pItem
)->IsSelected();
2174 bool wxTreeListMainWindow::IsBold(const wxTreeItemId
& item
) const
2176 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
2178 return ((wxTreeListItem
*) item
.m_pItem
)->IsBold();
2181 // ----------------------------------------------------------------------------
2183 // ----------------------------------------------------------------------------
2186 wxTreeItemId
wxTreeListMainWindow::GetItemParent(const wxTreeItemId
& item
) const
2188 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2190 return ((wxTreeListItem
*) item
.m_pItem
)->GetItemParent();
2194 wxTreeItemId
wxTreeListMainWindow::GetFirstChild(const wxTreeItemId
& item
,
2197 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2200 return GetNextChild(item
, cookie
);
2204 wxTreeItemId
wxTreeListMainWindow::GetNextChild(const wxTreeItemId
& item
,
2207 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2209 wxArrayTreeListItems
& children
= ((wxTreeListItem
*)
2210 item
.m_pItem
)->GetChildren();
2211 if ( (size_t)cookie
< children
.Count() )
2213 return children
.Item((size_t)cookie
++);
2217 // there are no more of them
2218 return wxTreeItemId();
2223 wxTreeItemId
wxTreeListMainWindow::GetLastChild(const wxTreeItemId
& item
) const
2225 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2227 wxArrayTreeListItems
& children
= ((wxTreeListItem
*) item
.m_pItem
)->GetChildren();
2228 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
2232 wxTreeItemId
wxTreeListMainWindow::GetNextSibling(const wxTreeItemId
& item
) const
2234 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2236 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
2237 wxTreeListItem
*parent
= i
->GetItemParent();
2238 if ( parent
== NULL
)
2240 // root item doesn't have any siblings
2241 return wxTreeItemId();
2244 wxArrayTreeListItems
& siblings
= parent
->GetChildren();
2245 int index
= siblings
.Index(i
);
2246 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
2248 size_t n
= (size_t)(index
+ 1);
2249 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
2253 wxTreeItemId
wxTreeListMainWindow::GetPrevSibling(const wxTreeItemId
& item
)
2256 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2258 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
2259 wxTreeListItem
*parent
= i
->GetItemParent();
2260 if ( parent
== NULL
)
2262 // root item doesn't have any siblings
2263 return wxTreeItemId();
2266 wxArrayTreeListItems
& siblings
= parent
->GetChildren();
2267 int index
= siblings
.Index(i
);
2268 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
2270 return index
== 0 ? wxTreeItemId()
2271 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
2274 // Only for internal use right now, but should probably be public
2275 wxTreeItemId
wxTreeListMainWindow::GetNext(const wxTreeItemId
& item
) const
2277 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2279 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
2281 // First see if there are any children.
2282 wxArrayTreeListItems
& children
= i
->GetChildren();
2283 if (children
.GetCount() > 0)
2285 return children
.Item(0);
2289 // Try a sibling of this or ancestor instead
2290 wxTreeItemId p
= item
;
2291 wxTreeItemId toFind
;
2294 toFind
= GetNextSibling(p
);
2295 p
= GetItemParent(p
);
2296 } while (p
.IsOk() && !toFind
.IsOk());
2302 wxTreeItemId
wxTreeListMainWindow::GetFirstVisibleItem() const
2304 wxTreeItemId id
= GetRootItem();
2313 } while (id
.IsOk());
2315 return wxTreeItemId();
2319 wxTreeItemId
wxTreeListMainWindow::GetNextVisible(const wxTreeItemId
& item
)
2322 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2324 wxTreeItemId id
= item
;
2327 while (id
= GetNext(id
), id
.IsOk())
2333 return wxTreeItemId();
2337 wxTreeItemId
wxTreeListMainWindow::GetPrevVisible(const wxTreeItemId
& item
)
2340 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
2342 wxFAIL_MSG(wxT("not implemented"));
2344 return wxTreeItemId();
2347 // ----------------------------------------------------------------------------
2349 // ----------------------------------------------------------------------------
2351 wxTreeItemId
wxTreeListMainWindow::DoInsertItem(const wxTreeItemId
& parentId
,
2353 const wxString
& text
,
2354 int image
, int selImage
,
2355 wxTreeItemData
*data
)
2357 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2360 // should we give a warning here?
2361 return AddRoot(text
, image
, selImage
, data
);
2364 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2368 arr
.Alloc(GetColumnCount());
2369 for(size_t i
= 0; i
< GetColumnCount(); ++i
) {
2370 arr
.Add(wxEmptyString
);
2372 arr
[m_main_column
] = text
;
2373 wxTreeListItem
*item
=
2374 new wxTreeListItem( this, parent
, arr
, image
, selImage
, data
);
2378 data
->SetId((long)item
);
2381 parent
->Insert( item
, previous
);
2386 wxTreeItemId
wxTreeListMainWindow::AddRoot(const wxString
& text
,
2387 int image
, int selImage
,
2388 wxTreeItemData
*data
)
2390 wxCHECK_MSG(!m_anchor
, wxTreeItemId(), wxT("tree can have only one root"));
2391 wxCHECK_MSG(GetColumnCount(), wxTreeItemId(), wxT("Add column(s) before adding the root item"));
2393 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2397 arr
.Alloc(GetColumnCount());
2398 for(size_t i
= 0; i
< GetColumnCount(); ++i
) {
2399 arr
.Add(wxEmptyString
);
2401 arr
[m_main_column
] = text
;
2402 m_anchor
= new wxTreeListItem( this, (wxTreeListItem
*)NULL
, arr
,
2403 image
, selImage
, data
);
2405 if (HasFlag(wxTR_HIDE_ROOT
))
2407 // if root is hidden, make sure we can navigate
2409 m_anchor
->SetHasPlus();
2415 data
->SetId((long)m_anchor
);
2418 if (!HasFlag(wxTR_MULTIPLE
))
2420 m_current
= m_key_current
= m_anchor
;
2421 m_current
->SetHilight( TRUE
);
2428 wxTreeItemId
wxTreeListMainWindow::PrependItem(const wxTreeItemId
& parent
,
2429 const wxString
& text
,
2430 int image
, int selImage
,
2431 wxTreeItemData
*data
)
2433 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
2437 wxTreeItemId
wxTreeListMainWindow::InsertItem(const wxTreeItemId
& parentId
,
2438 const wxTreeItemId
& idPrevious
,
2439 const wxString
& text
,
2440 int image
, int selImage
,
2441 wxTreeItemData
*data
)
2443 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2446 // should we give a warning here?
2447 return AddRoot(text
, image
, selImage
, data
);
2450 int index
= parent
->GetChildren().Index((wxTreeListItem
*) idPrevious
.m_pItem
);
2451 wxASSERT_MSG( index
!= wxNOT_FOUND
,
2452 wxT("previous item in wxTreeListMainWindow::InsertItem() is not a sibling") );
2454 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
2458 wxTreeItemId
wxTreeListMainWindow::InsertItem(const wxTreeItemId
& parentId
,
2460 const wxString
& text
,
2461 int image
, int selImage
,
2462 wxTreeItemData
*data
)
2464 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2467 // should we give a warning here?
2468 return AddRoot(text
, image
, selImage
, data
);
2471 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
2475 wxTreeItemId
wxTreeListMainWindow::AppendItem(const wxTreeItemId
& parentId
,
2476 const wxString
& text
,
2477 int image
, int selImage
,
2478 wxTreeItemData
*data
)
2480 wxTreeListItem
*parent
= (wxTreeListItem
*) parentId
.m_pItem
;
2483 // should we give a warning here?
2484 return AddRoot(text
, image
, selImage
, data
);
2487 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
2488 image
, selImage
, data
);
2491 void wxTreeListMainWindow::SendDeleteEvent(wxTreeListItem
*item
)
2493 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, m_owner
->GetId() );
2494 event
.SetItem((long) item
);
2495 event
.SetEventObject( /*this*/m_owner
);
2496 m_owner
->ProcessEvent( event
);
2500 void wxTreeListMainWindow::DeleteChildren(const wxTreeItemId
& itemId
)
2502 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2504 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2505 item
->DeleteChildren(this);
2509 void wxTreeListMainWindow::Delete(const wxTreeItemId
& itemId
)
2511 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
2513 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2515 // don't stay with invalid m_key_current or we will crash in
2516 // the next call to OnChar()
2517 bool changeKeyCurrent
= FALSE
;
2518 wxTreeListItem
*itemKey
= m_key_current
;
2521 if ( itemKey
== item
)
2523 // m_key_current is a descendant of the item being deleted
2524 changeKeyCurrent
= TRUE
;
2527 itemKey
= itemKey
->GetItemParent();
2530 wxTreeListItem
*parent
= item
->GetItemParent();
2533 parent
->GetChildren().Remove( item
); // remove by value
2536 if ( changeKeyCurrent
)
2538 // may be NULL or not
2539 m_key_current
= parent
;
2542 item
->DeleteChildren(this);
2543 SendDeleteEvent(item
);
2548 void wxTreeListMainWindow::DeleteAllItems()
2554 m_anchor
->DeleteChildren(this);
2561 void wxTreeListMainWindow::Expand(const wxTreeItemId
& itemId
)
2563 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2565 wxCHECK_RET( item
, _T("invalid item in wxTreeListMainWindow::Expand") );
2567 if ( !item
->HasPlus() )
2570 if ( item
->IsExpanded() )
2573 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, m_owner
->GetId() );
2574 event
.SetItem( (long) item
);
2575 event
.SetEventObject( /*this*/m_owner
);
2577 if ( m_owner
->ProcessEvent( event
) && !event
.IsAllowed() )
2579 // cancelled by program
2584 CalculatePositions();
2586 RefreshSubtree(item
);
2588 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
2589 ProcessEvent( event
);
2592 void wxTreeListMainWindow::ExpandAll(const wxTreeItemId
& item
)
2595 if ( IsExpanded(item
) )
2598 wxTreeItemId child
= GetFirstChild(item
, cookie
);
2599 while ( child
.IsOk() )
2603 child
= GetNextChild(item
, cookie
);
2608 void wxTreeListMainWindow::Collapse(const wxTreeItemId
& itemId
)
2610 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2612 if ( !item
->IsExpanded() )
2615 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, m_owner
->GetId() );
2616 event
.SetItem( (long) item
);
2617 event
.SetEventObject( /*this*/m_owner
);
2618 if ( m_owner
->ProcessEvent( event
) && !event
.IsAllowed() )
2620 // cancelled by program
2626 #if 0 // TODO why should items be collapsed recursively?
2627 wxArrayTreeListItems
& children
= item
->GetChildren();
2628 size_t count
= children
.Count();
2629 for ( size_t n
= 0; n
< count
; n
++ )
2631 Collapse(children
[n
]);
2635 CalculatePositions();
2637 RefreshSubtree(item
);
2639 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
2640 ProcessEvent( event
);
2643 void wxTreeListMainWindow::CollapseAndReset(const wxTreeItemId
& item
)
2646 DeleteChildren(item
);
2649 void wxTreeListMainWindow::Toggle(const wxTreeItemId
& itemId
)
2651 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2653 if (item
->IsExpanded())
2659 void wxTreeListMainWindow::Unselect()
2663 m_current
->SetHilight( FALSE
);
2664 RefreshLine( m_current
);
2668 void wxTreeListMainWindow::UnselectAllChildren(wxTreeListItem
*item
)
2670 if (item
->IsSelected())
2672 item
->SetHilight(FALSE
);
2676 if (item
->HasChildren())
2678 wxArrayTreeListItems
& children
= item
->GetChildren();
2679 size_t count
= children
.Count();
2680 for ( size_t n
= 0; n
< count
; ++n
)
2682 UnselectAllChildren(children
[n
]);
2687 void wxTreeListMainWindow::UnselectAll()
2689 UnselectAllChildren((wxTreeListItem
*) GetRootItem().m_pItem
);
2692 // Recursive function !
2693 // To stop we must have crt_item<last_item
2695 // Tag all next children, when no more children,
2696 // Move to parent (not to tag)
2697 // Keep going... if we found last_item, we stop.
2698 bool wxTreeListMainWindow::TagNextChildren(wxTreeListItem
*crt_item
, wxTreeListItem
*last_item
, bool select
)
2700 wxTreeListItem
*parent
= crt_item
->GetItemParent();
2702 if (parent
== NULL
) // This is root item
2703 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
2705 wxArrayTreeListItems
& children
= parent
->GetChildren();
2706 int index
= children
.Index(crt_item
);
2707 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
2709 size_t count
= children
.Count();
2710 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
2712 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return TRUE
;
2715 return TagNextChildren(parent
, last_item
, select
);
2718 bool wxTreeListMainWindow::TagAllChildrenUntilLast(wxTreeListItem
*crt_item
, wxTreeListItem
*last_item
, bool select
)
2720 crt_item
->SetHilight(select
);
2721 RefreshLine(crt_item
);
2723 if (crt_item
==last_item
)
2726 if (crt_item
->HasChildren())
2728 wxArrayTreeListItems
& children
= crt_item
->GetChildren();
2729 size_t count
= children
.Count();
2730 for ( size_t n
= 0; n
< count
; ++n
)
2732 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
2740 void wxTreeListMainWindow::SelectItemRange(wxTreeListItem
*item1
, wxTreeListItem
*item2
)
2742 // item2 is not necessary after item1
2743 wxTreeListItem
*first
=NULL
, *last
=NULL
;
2745 // choice first' and 'last' between item1 and item2
2746 if (item1
->GetY()<item2
->GetY())
2757 bool select
= m_current
->IsSelected();
2759 if ( TagAllChildrenUntilLast(first
,last
,select
) )
2762 TagNextChildren(first
,last
,select
);
2765 void wxTreeListMainWindow::SelectItem(const wxTreeItemId
& itemId
,
2766 bool unselect_others
,
2767 bool extended_select
)
2769 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
2771 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
2772 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
2774 //wxCHECK_RET( ( (!unselect_others) && is_single),
2775 // wxT("this is a single selection tree") );
2777 // to keep going anyhow !!!
2780 if (item
->IsSelected())
2781 return; // nothing to do
2782 unselect_others
= TRUE
;
2783 extended_select
= FALSE
;
2785 else if ( unselect_others
&& item
->IsSelected() )
2787 // selection change if there is more than one item currently selected
2788 wxArrayTreeItemIds selected_items
;
2789 if ( GetSelections(selected_items
) == 1 )
2793 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, m_owner
->GetId() );
2794 event
.SetItem( (long) item
);
2795 event
.SetOldItem( (long) m_current
);
2796 event
.SetEventObject( /*this*/m_owner
);
2797 // TODO : Here we don't send any selection mode yet !
2799 if(m_owner
->GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed())
2802 wxTreeItemId parent
= GetItemParent( itemId
);
2803 while (parent
.IsOk())
2805 if (!IsExpanded(parent
))
2808 parent
= GetItemParent( parent
);
2811 EnsureVisible( itemId
);
2814 if (unselect_others
)
2816 if (is_single
) Unselect(); // to speed up thing
2821 if (extended_select
)
2825 m_current
= m_key_current
= (wxTreeListItem
*) GetRootItem().m_pItem
;
2828 // don't change the mark (m_current)
2829 SelectItemRange(m_current
, item
);
2833 bool select
=TRUE
; // the default
2835 // Check if we need to toggle hilight (ctrl mode)
2836 if (!unselect_others
)
2837 select
=!item
->IsSelected();
2839 m_current
= m_key_current
= item
;
2840 m_current
->SetHilight(select
);
2841 RefreshLine( m_current
);
2844 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
2845 GetEventHandler()->ProcessEvent( event
);
2848 void wxTreeListMainWindow::SelectAll(bool extended_select
)
2850 wxCHECK_RET( GetWindowStyleFlag() & wxTR_MULTIPLE
, wxT("invalid tree style") );
2852 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, m_owner
->GetId() );
2853 event
.SetItem( GetRootItem() );
2854 event
.SetOldItem( (long) m_current
);
2855 event
.SetEventObject( /*this*/m_owner
);
2856 // TODO : Here we don't send any selection mode yet !
2858 if(m_owner
->GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed())
2862 if (!extended_select
)
2871 wxTreeItemId root
= GetRootItem();
2872 wxTreeListItem
*first
= (wxTreeListItem
*)GetFirstChild (root
, cookie
).m_pItem
;
2873 wxTreeListItem
*last
= (wxTreeListItem
*)GetLastChild (GetRootItem()).m_pItem
;
2874 if (TagAllChildrenUntilLast (first
, last
, true)) return;
2875 TagNextChildren (first
, last
, true);
2877 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
2878 GetEventHandler()->ProcessEvent( event
);
2881 void wxTreeListMainWindow::FillArray(wxTreeListItem
*item
,
2882 wxArrayTreeItemIds
&array
) const
2884 if ( item
->IsSelected() )
2885 array
.Add(wxTreeItemId(item
));
2887 if ( item
->HasChildren() )
2889 wxArrayTreeListItems
& children
= item
->GetChildren();
2890 size_t count
= children
.GetCount();
2891 for ( size_t n
= 0; n
< count
; ++n
)
2892 FillArray(children
[n
], array
);
2896 size_t wxTreeListMainWindow::GetSelections(wxArrayTreeItemIds
&array
) const
2899 wxTreeItemId idRoot
= GetRootItem();
2900 if ( idRoot
.IsOk() )
2902 FillArray((wxTreeListItem
*) idRoot
.m_pItem
, array
);
2904 //else: the tree is empty, so no selections
2906 return array
.Count();
2909 void wxTreeListMainWindow::EnsureVisible(const wxTreeItemId
& item
)
2911 if (!item
.IsOk()) return;
2913 wxTreeListItem
*gitem
= (wxTreeListItem
*) item
.m_pItem
;
2915 // first expand all parent branches
2916 wxTreeListItem
*parent
= gitem
->GetItemParent();
2920 parent
= parent
->GetItemParent();
2923 //if (parent) CalculatePositions();
2928 void wxTreeListMainWindow::ScrollTo(const wxTreeItemId
&item
)
2930 if (!item
.IsOk()) return;
2932 // We have to call this here because the label in
2933 // question might just have been added and no screen
2934 // update taken place.
2935 if (m_dirty
) wxYieldIfNeeded();
2937 wxTreeListItem
*gitem
= (wxTreeListItem
*) item
.m_pItem
;
2939 // now scroll to the item
2940 int item_y
= gitem
->GetY();
2944 GetViewStart( &start_x
, &start_y
);
2945 start_y
*= PIXELS_PER_UNIT
;
2949 GetClientSize( &client_w
, &client_h
);
2951 if (item_y
< start_y
+3)
2956 m_anchor
->GetSize( x
, y
, this );
2957 x
= m_owner
->GetHeaderWindow()->GetWidth(); //m_total_col_width; // ALB
2958 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2959 //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
2960 int x_pos
= GetScrollPos( wxHORIZONTAL
);
2961 // Item should appear at top
2962 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
2964 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
2969 m_anchor
->GetSize( x
, y
, this );
2970 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2971 //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
2972 x
= m_owner
->GetHeaderWindow()->GetWidth(); //m_total_col_width; // ALB
2973 item_y
+= PIXELS_PER_UNIT
+2;
2974 int x_pos
= GetScrollPos( wxHORIZONTAL
);
2975 // Item should appear at bottom
2976 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, (item_y
+GetLineHeight(gitem
)-client_h
)/PIXELS_PER_UNIT
);
2980 // FIXME: tree sorting functions are not reentrant and not MT-safe!
2981 static wxTreeListMainWindow
*s_treeBeingSorted
= NULL
;
2983 static int LINKAGEMODE
tree_ctrl_compare_func(wxTreeListItem
**item1
,
2984 wxTreeListItem
**item2
)
2986 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxTreeListMainWindow::SortChildren()") );
2988 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
2991 int wxTreeListMainWindow::OnCompareItems(const wxTreeItemId
& item1
,
2992 const wxTreeItemId
& item2
)
2994 // ALB: delegate to m_owner, to let the user overrride the comparison
2995 //return wxStrcmp(GetItemText(item1), GetItemText(item2));
2996 return m_owner
->OnCompareItems(item1
, item2
);
2999 void wxTreeListMainWindow::SortChildren(const wxTreeItemId
& itemId
)
3001 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
3003 wxTreeListItem
*item
= (wxTreeListItem
*) itemId
.m_pItem
;
3005 wxCHECK_RET( !s_treeBeingSorted
,
3006 wxT("wxTreeListMainWindow::SortChildren is not reentrant") );
3008 wxArrayTreeListItems
& children
= item
->GetChildren();
3009 if ( children
.Count() > 1 )
3013 s_treeBeingSorted
= this;
3014 children
.Sort(tree_ctrl_compare_func
);
3015 s_treeBeingSorted
= NULL
;
3017 //else: don't make the tree dirty as nothing changed
3021 wxImageList
*wxTreeListMainWindow::GetImageList() const
3023 return m_imageListNormal
;
3027 wxImageList
*wxTreeListMainWindow::GetButtonsImageList() const
3029 return m_imageListButtons
;
3033 wxImageList
*wxTreeListMainWindow::GetStateImageList() const
3035 return m_imageListState
;
3038 void wxTreeListMainWindow::CalculateLineHeight()
3040 wxClientDC
dc(this);
3041 dc
.SetFont( m_normalFont
);
3042 m_lineHeight
= (int)(dc
.GetCharHeight() + m_linespacing
);
3044 if ( m_imageListNormal
)
3046 // Calculate a m_lineHeight value from the normal Image sizes.
3047 // May be toggle off. Then wxTreeListMainWindow will spread when
3048 // necessary (which might look ugly).
3049 int n
= m_imageListNormal
->GetImageCount();
3050 for (int i
= 0; i
< n
; i
++)
3052 int width
= 0, height
= 0;
3053 m_imageListNormal
->GetSize(i
, width
, height
);
3054 if (height
> m_lineHeight
) m_lineHeight
= height
+ m_linespacing
;
3058 if (m_imageListButtons
)
3060 // Calculate a m_lineHeight value from the Button image sizes.
3061 // May be toggle off. Then wxTreeListMainWindow will spread when
3062 // necessary (which might look ugly).
3063 int n
= m_imageListButtons
->GetImageCount();
3064 for (int i
= 0; i
< n
; i
++)
3066 int width
= 0, height
= 0;
3067 m_imageListButtons
->GetSize(i
, width
, height
);
3068 if (height
> m_lineHeight
) m_lineHeight
= height
+ m_linespacing
;
3072 /*? FIXME: Don't get what this code is for... Adding a line space is already done!!!
3073 if (m_lineHeight < 30)
3074 m_lineHeight += 2; // at least 2 pixels
3076 m_lineHeight += m_lineHeight/10; // otherwise 10% extra spacing
3081 void wxTreeListMainWindow::SetImageList(wxImageList
*imageList
)
3083 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3084 m_imageListNormal
= imageList
;
3085 m_ownsImageListNormal
= FALSE
;
3087 CalculateLineHeight();
3091 void wxTreeListMainWindow::SetStateImageList(wxImageList
*imageList
)
3093 if (m_ownsImageListState
) delete m_imageListState
;
3094 m_imageListState
= imageList
;
3095 m_ownsImageListState
= FALSE
;
3099 void wxTreeListMainWindow::SetButtonsImageList(wxImageList
*imageList
)
3101 if (m_ownsImageListButtons
) delete m_imageListButtons
;
3102 m_imageListButtons
= imageList
;
3103 m_ownsImageListButtons
= FALSE
;
3105 CalculateLineHeight();
3109 void wxTreeListMainWindow::AssignImageList(wxImageList
*imageList
)
3111 SetImageList(imageList
);
3112 m_ownsImageListNormal
= TRUE
;
3116 void wxTreeListMainWindow::AssignStateImageList(wxImageList
*imageList
)
3118 SetStateImageList(imageList
);
3119 m_ownsImageListState
= TRUE
;
3123 void wxTreeListMainWindow::AssignButtonsImageList(wxImageList
*imageList
)
3125 SetButtonsImageList(imageList
);
3126 m_ownsImageListButtons
= TRUE
;
3129 // ----------------------------------------------------------------------------
3131 // ----------------------------------------------------------------------------
3133 void wxTreeListMainWindow::AdjustMyScrollbars()
3138 m_anchor
->GetSize( x
, y
, this );
3139 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
3140 //x += PIXELS_PER_UNIT+2; // one more scrollbar unit + 2 pixels
3141 int x_pos
= GetScrollPos( wxHORIZONTAL
);
3142 int y_pos
= GetScrollPos( wxVERTICAL
);
3143 x
= m_owner
->GetHeaderWindow()->GetWidth() + 2;
3144 if(x
< GetClientSize().GetWidth()) x_pos
= 0;
3145 //m_total_col_width + 2; // ALB
3146 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
,
3147 y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
3151 SetScrollbars( 0, 0, 0, 0 );
3155 int wxTreeListMainWindow::GetLineHeight(wxTreeListItem
*item
) const
3157 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
3158 return item
->GetHeight();
3160 return m_lineHeight
;
3163 void wxTreeListMainWindow::PaintItem(wxTreeListItem
*item
, wxDC
& dc
)
3165 // TODO implement "state" icon on items
3167 wxTreeItemAttr
*attr
= item
->GetAttributes();
3168 if ( attr
&& attr
->HasFont() )
3169 dc
.SetFont(attr
->GetFont());
3170 else if (item
->IsBold())
3171 dc
.SetFont(m_boldFont
);
3173 long text_w
= 0, text_h
= 0;
3175 dc
.GetTextExtent( item
->GetText(GetMainColumn()), &text_w
, &text_h
);
3177 int total_h
= GetLineHeight(item
);
3179 if ( item
->IsSelected() )
3181 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
3182 int offset
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0;
3183 dc
.DrawRectangle (0, item
->GetY() + offset
,
3184 m_owner
->GetHeaderWindow()->GetWidth(), total_h
-offset
);
3186 #if 0 // this code is probably not needed
3190 if ( attr
&& attr
->HasBackgroundColour() )
3191 colBg
= attr
->GetBackgroundColour();
3193 colBg
= m_backgroundColour
;
3194 dc
.SetBrush(wxBrush(colBg
, wxTRANSPARENT
));
3198 dc
.SetBackgroundMode(wxTRANSPARENT
);
3199 int text_extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
3200 int img_extraH
= (total_h
> m_imgHeight
)? (total_h
-m_imgHeight
)/2: 0;
3202 for ( size_t i
= 0; i
< GetColumnCount(); ++i
) {
3203 if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue;
3204 int colwidth
= m_owner
->GetHeaderWindow()->GetColumnWidth(i
);
3206 int image_x
= x_colstart
+ MARGIN
;
3208 if(i
== GetMainColumn()) {
3209 image
= item
->GetCurrentImage();
3210 image_x
= item
->GetX() - m_imgWidth2
;
3211 image_w
= m_imgWidth
+ MARGIN
;
3215 image
= item
->GetImage(i
);
3216 if (image
!= NO_IMAGE
) image_w
= m_imgWidth
+ MARGIN
;
3219 // honor text alignment
3220 wxString text
= item
->GetText(i
);
3221 switch ( m_owner
->GetHeaderWindow()->GetColumn(i
).GetAlignment() ) {
3222 case wxTL_ALIGN_LEFT
:
3223 // already left aligned
3225 case wxTL_ALIGN_RIGHT
:
3226 dc
.GetTextExtent(text
, &text_w
, NULL
);
3227 image_x
= x_colstart
+ colwidth
- (image_w
+ text_w
+ MARGIN
);
3229 case wxTL_ALIGN_CENTER
:
3230 dc
.GetTextExtent(text
, &text_w
, NULL
);
3231 int w
= colwidth
- image_w
- text_w
;
3232 image_x
= x_colstart
+ (w
> 0)? w
: 0;
3235 int text_x
= image_x
+ image_w
;
3237 wxDCClipper
clipper (dc
, x_colstart
, item
->GetY(), colwidth
, total_h
);
3238 if (image
!= NO_IMAGE
)
3240 int image_y
= item
->GetY() + img_extraH
;
3241 m_imageListNormal
->Draw ( image
, dc
, image_x
, image_y
,
3242 wxIMAGELIST_DRAW_TRANSPARENT
);
3244 int text_y
= item
->GetY() + text_extraH
;
3245 dc
.DrawText ( text
, (wxCoord
)text_x
, (wxCoord
)text_y
);
3247 x_colstart
+= colwidth
;
3250 // restore normal font
3251 dc
.SetFont( m_normalFont
);
3254 // Now y stands for the top of the item, whereas it used to stand for middle !
3255 void wxTreeListMainWindow::PaintLevel (wxTreeListItem
*item
, wxDC
&dc
,
3256 int level
, int &y
, int x_colstart
)
3258 // Handle hide root (only level 0)
3259 if (HasFlag(wxTR_HIDE_ROOT
) && (level
== 0)) {
3260 // always expand hidden root
3261 wxArrayTreeListItems
& children
= item
->GetChildren();
3263 for (n
= 0; n
< (int)children
.Count(); n
++) {
3264 PaintLevel (children
[n
], dc
, 1, y
, x_colstart
);
3266 // end after expanding root
3270 // calculate position of vertical lines
3271 int x
= x_colstart
+ MARGIN
; // start of column
3272 if (HasFlag(wxTR_LINES_AT_ROOT
)) x
+= LINEATROOT
; // space for lines at root
3273 if (HasButtons()) x
+= m_btnWidth2
; // space for buttons etc.
3274 if (!HasFlag(wxTR_HIDE_ROOT
)) x
+= m_indent
; // indent root as well
3275 x
+= m_indent
* level
; // indent according to level
3277 // handle column text
3281 int h
= GetLineHeight(item
);
3283 int y_mid
= y_top
+ (h
/2);
3286 int exposed_x
= dc
.LogicalToDeviceX(0);
3287 int exposed_y
= dc
.LogicalToDeviceY(y_top
);
3289 if (IsExposed(exposed_x
, exposed_y
, 10000, h
)) // 10000 = very much
3291 if (HasFlag(wxTR_ROW_LINES
))
3293 //dc.DestroyClippingRegion();
3294 int total_width
= m_owner
->GetHeaderWindow()->GetWidth();
3295 // if the background colour is white, choose a
3296 // contrasting color for the lines
3297 dc
.SetPen (*((GetBackgroundColour() == *wxWHITE
)?
3298 wxMEDIUM_GREY_PEN
: wxWHITE_PEN
));
3299 dc
.DrawLine(0, y_top
, total_width
, y_top
);
3300 dc
.DrawLine(0, y
, total_width
, y
);
3303 // restore DC objects
3304 dc
.SetBrush(*wxWHITE_BRUSH
);
3305 dc
.SetPen(m_dottedPen
);
3306 dc
.SetTextForeground(*wxBLACK
);
3308 if (((level
== 0) || ((level
== 1) && HasFlag(wxTR_HIDE_ROOT
))) &&
3309 HasFlag(wxTR_LINES_AT_ROOT
) && !HasFlag(wxTR_NO_LINES
)) {
3310 int rootPos
= x_colstart
+ MARGIN
;
3311 dc
.DrawLine (rootPos
, y_mid
, rootPos
+LINEATROOT
, y_mid
);
3314 size_t clip_width
= m_owner
->GetHeaderWindow()->
3315 GetColumn(m_main_column
).GetWidth();
3316 //m_columns[m_main_column].GetWidth();
3318 if (item
->HasPlus() && HasButtons()) // should the item show a button?
3320 if (!HasFlag(wxTR_NO_LINES
)) {
3321 int lineOffset
= m_indent
- m_btnWidth2
;
3322 dc
.DrawLine(x
-lineOffset
, y_mid
, x
-m_imgWidth2
, y_mid
);
3325 // clip to the column width
3326 wxDCClipper
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000);
3328 if (m_imageListButtons
!= NULL
)
3330 // draw the image button here
3331 int image
= wxTreeItemIcon_Normal
;
3332 if (item
->IsExpanded()) image
= wxTreeItemIcon_Expanded
;
3333 if (item
->IsSelected())
3334 image
+= wxTreeItemIcon_Selected
- wxTreeItemIcon_Normal
;
3335 int xx
= x
+ m_btnWidth2
;
3336 int yy
= y_mid
- m_btnHeight2
;
3337 dc
.SetClippingRegion(xx
, yy
, m_btnWidth
, m_btnHeight
);
3338 m_imageListButtons
->Draw(image
, dc
, xx
, yy
,
3339 wxIMAGELIST_DRAW_TRANSPARENT
);
3340 dc
.DestroyClippingRegion();
3342 else if (HasFlag(wxTR_TWIST_BUTTONS
))
3344 // draw the twisty button here
3345 dc
.SetPen(*wxBLACK_PEN
);
3346 dc
.SetBrush(*m_hilightBrush
);
3350 if (item
->IsExpanded())
3352 button
[0].x
= (x
-m_indent
) - m_btnWidth2
;
3353 button
[0].y
= y_mid
- (m_btnHeight
/3-1);
3354 button
[1].x
= button
[0].x
+ m_btnWidth
;
3355 button
[1].y
= button
[0].y
;
3357 button
[2].y
= y_mid
+ (m_btnHeight
/3);
3361 button
[0].x
= (x
-m_indent
) - (m_btnWidth
/3-1);
3362 button
[0].y
= y_mid
-m_btnHeight2
;
3363 button
[1].x
= button
[0].x
;
3364 button
[1].y
= button
[0].y
+ m_btnHeight
;
3365 button
[2].x
= button
[0].x
+ (m_btnWidth
/3);
3366 button
[2].y
= y_mid
;
3368 dc
.DrawPolygon(3, button
);
3370 dc
.SetPen(m_dottedPen
);
3372 else // if (HasFlag(wxTR_HAS_BUTTONS))
3374 // draw the plus sign here
3375 dc
.SetPen(*wxGREY_PEN
);
3376 dc
.SetBrush(*wxWHITE_BRUSH
);
3377 int xpos
= x
- m_indent
;
3378 dc
.DrawRectangle (xpos
-m_btnWidth2
, y_mid
-m_btnHeight2
,
3379 m_btnWidth
, m_btnHeight
);
3380 dc
.SetPen(*wxBLACK_PEN
);
3381 dc
.DrawLine (xpos
-(m_btnWidth2
-3), y_mid
,
3382 xpos
+(m_btnWidth2
-2), y_mid
);
3383 if (!item
->IsExpanded())
3384 dc
.DrawLine (xpos
, y_mid
-(m_btnHeight2
-2),
3385 xpos
, y_mid
+(m_btnHeight2
-1));
3386 dc
.SetPen(m_dottedPen
);
3389 else if (!HasFlag(wxTR_NO_LINES
)) // no button; maybe a line?
3391 // clip to the column width
3392 wxDCClipper
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000);
3394 // draw the horizontal line here
3395 if (!(level
== 0) && !((level
== 1) && HasFlag(wxTR_HIDE_ROOT
))) {
3396 dc
.DrawLine(x
-m_indent
, y_mid
, x
-m_imgWidth2
, y_mid
);
3402 // don't draw rect outline if we already have the
3403 // background color under Mac
3404 (item
->IsSelected() && m_hasFocus
) ? wxBLACK_PEN
:
3405 #endif // !__WXMAC__
3409 if ( item
->IsSelected() )
3411 colText
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
3415 wxTreeItemAttr
*attr
= item
->GetAttributes();
3416 if (attr
&& attr
->HasTextColour())
3417 colText
= attr
->GetTextColour();
3419 //colText = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT);
3420 colText
= GetForegroundColour();
3424 dc
.SetTextForeground(colText
);
3428 PaintItem(item
, dc
);
3431 // restore DC objects
3432 dc
.SetBrush(*wxWHITE_BRUSH
);
3433 dc
.SetPen(m_dottedPen
);
3434 dc
.SetTextForeground(*wxBLACK
);
3436 if (item
->IsExpanded())
3438 wxArrayTreeListItems
& children
= item
->GetChildren();
3440 // clip to the column width
3441 size_t clip_width
= m_owner
->GetHeaderWindow()->
3442 GetColumn(m_main_column
).GetWidth();
3443 wxDCClipper
clipper(dc
, x_colstart
, y_top
, clip_width
, 10000);
3445 // process lower levels
3446 int oldY
= y_mid
+ m_imgHeight2
;
3449 for (n
= 0; n
< (int)children
.Count(); n
++) {
3451 if (!HasFlag(wxTR_NO_LINES
))
3453 // draw line down to last child
3454 if (children
[n
]->HasPlus() && HasButtons()) {
3455 y2
= y
+ h
/2 - m_btnHeight2
;
3456 dc
.DrawLine(x
, oldY
, x
, y2
);
3457 oldY
= y2
+ m_btnHeight
;
3460 dc
.DrawLine(x
, oldY
, x
, y2
);
3465 PaintLevel (children
[n
], dc
, level
+1, y
, x_colstart
);
3470 void wxTreeListMainWindow::DrawDropEffect(wxTreeListItem
*item
)
3474 if ( item
->HasPlus() )
3476 // it's a folder, indicate it by a border
3481 // draw a line under the drop target because the item will be
3483 DrawLine(item
, TRUE
/* below */);
3486 SetCursor(wxCURSOR_BULLSEYE
);
3491 SetCursor(wxCURSOR_NO_ENTRY
);
3495 void wxTreeListMainWindow::DrawBorder(const wxTreeItemId
&item
)
3497 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxTreeListMainWindow::DrawLine") );
3499 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
3501 wxClientDC
dc(this);
3503 dc
.SetLogicalFunction(wxINVERT
);
3504 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
3506 int w
= i
->GetWidth() + 2;
3507 int h
= GetLineHeight(i
) + 2;
3509 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
3512 void wxTreeListMainWindow::DrawLine(const wxTreeItemId
&item
, bool below
)
3514 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxTreeListMainWindow::DrawLine") );
3516 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
3518 wxClientDC
dc(this);
3520 dc
.SetLogicalFunction(wxINVERT
);
3526 y
+= GetLineHeight(i
) - 1;
3529 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
3532 // ----------------------------------------------------------------------------
3533 // wxWindows callbacks
3534 // ----------------------------------------------------------------------------
3536 void wxTreeListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
3542 if(!GetColumnCount()) return; // ALB
3547 // calculate button size
3548 m_btnWidth
= 0, m_btnWidth2
= 0;
3549 m_btnHeight
= 0, m_btnHeight2
= 0;
3550 if (m_imageListButtons
) {
3551 m_imageListButtons
->GetSize (0, m_btnWidth
, m_btnHeight
);
3552 }else if (HasButtons()) {
3553 m_btnWidth
= BTNWIDTH
;
3554 m_btnHeight
= BTNHEIGHT
;
3556 m_btnWidth2
= m_btnWidth
/2;
3557 m_btnHeight2
= m_btnHeight
/2;
3559 // calculate image size
3560 m_imgWidth
= 0, m_imgWidth2
= 0;
3561 m_imgHeight
= 0, m_imgHeight2
= 0;
3562 if (m_imageListNormal
) {
3563 m_imageListNormal
->GetSize (0, m_imgWidth
, m_imgHeight
);
3564 m_imgWidth
+= 4; //? ToDo: Why + 4?
3566 m_imgWidth2
= m_imgWidth
/2;
3567 m_imgHeight2
= m_imgHeight
/2;
3569 // calculate indent size
3570 int btnIndent
= HasButtons()? m_btnWidth
+ LINEATROOT
: 0;
3571 m_indent
= wxMax (MININDENT
, wxMax (m_imgWidth
, btnIndent
)) + MARGIN
;
3573 // set default values
3574 dc
.SetFont( m_normalFont
);
3575 dc
.SetPen( m_dottedPen
);
3577 // this is now done dynamically
3578 //if(GetImageList() == NULL)
3579 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
3581 // calculate column start and paint
3584 for (i
= 0; i
< (int)GetMainColumn(); ++i
) {
3585 if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue;
3586 x_colstart
+= m_owner
->GetHeaderWindow()->GetColumnWidth (i
);
3589 PaintLevel ( m_anchor
, dc
, 0, y
, x_colstart
);
3592 void wxTreeListMainWindow::OnSetFocus( wxFocusEvent
&event
)
3601 void wxTreeListMainWindow::OnKillFocus( wxFocusEvent
&event
)
3610 void wxTreeListMainWindow::OnChar( wxKeyEvent
&event
)
3612 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, m_owner
->GetId() );
3613 te
.SetKeyEvent( event
);
3614 te
.SetEventObject( /*this*/m_owner
);
3615 if ( m_owner
->GetEventHandler()->ProcessEvent( te
) )
3617 // intercepted by the user code
3621 if ( (m_current
== 0) || (m_key_current
== 0) )
3627 // how should the selection work for this event?
3628 bool is_multiple
, extended_select
, unselect_others
;
3629 EventFlagsToSelType(GetWindowStyleFlag(),
3631 event
.ControlDown(),
3632 is_multiple
, extended_select
, unselect_others
);
3634 // + : Expand (not on Win32)
3635 // - : Collaspe (not on Win32)
3636 // * : Expand all/Collapse all
3637 // ' ' | return : activate
3638 // up : go up (not last children!)
3640 // left : go to parent (or collapse on Win32)
3641 // right : open if parent and go next (or expand on Win32)
3642 // home : go to root
3643 // end : go to last item without opening parents
3644 switch (event
.KeyCode())
3646 #ifndef __WXMSW__ // mimic the standard win32 tree ctrl
3649 if (m_current
->HasPlus() && !IsExpanded(m_current
))
3658 if ( !IsExpanded(m_current
) )
3661 ExpandAll(m_current
);
3664 //else: fall through to Collapse() it
3666 #ifndef __WXMSW__ // mimic the standard wxTreeCtrl behaviour
3669 if (IsExpanded(m_current
))
3671 Collapse(m_current
);
3679 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
,
3681 event
.SetItem( (long) m_current
);
3682 event
.SetEventObject( /*this*/m_owner
);
3683 m_owner
->GetEventHandler()->ProcessEvent( event
);
3687 // up goes to the previous sibling or to the last
3688 // of its children if it's expanded
3691 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
3694 prev
= GetItemParent( m_key_current
);
3695 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
3697 break; // don't go to root if it is hidden
3702 wxTreeItemId current
= m_key_current
;
3703 // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be?
3704 if (current
== GetFirstChild( prev
, cookie
))
3706 // otherwise we return to where we came from
3707 SelectItem( prev
, unselect_others
, extended_select
);
3708 m_key_current
= (wxTreeListItem
*) prev
.m_pItem
;
3709 EnsureVisible( prev
);
3716 while ( IsExpanded(prev
) && HasChildren(prev
) )
3718 wxTreeItemId child
= GetLastChild(prev
);
3725 SelectItem( prev
, unselect_others
, extended_select
);
3726 m_key_current
=(wxTreeListItem
*) prev
.m_pItem
;
3727 EnsureVisible( prev
);
3732 // left arrow goes to the parent
3734 #if defined(__WXMSW__) // mimic the standard win32 tree ctrl
3735 if (IsExpanded(m_current
))
3737 Collapse(m_current
);
3742 wxTreeItemId prev
= GetItemParent( m_current
);
3743 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
3745 // don't go to root if it is hidden
3746 prev
= GetPrevSibling( m_current
);
3750 EnsureVisible( prev
);
3751 SelectItem( prev
, unselect_others
, extended_select
);
3757 #if defined(__WXMSW__) // mimic the standard win32 tree ctrl
3758 if (m_current
->HasPlus() && !IsExpanded(m_current
))
3765 // this works the same as the down arrow except that we
3766 // also expand the item if it wasn't expanded yet
3772 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
3775 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
3776 SelectItem( child
, unselect_others
, extended_select
);
3777 m_key_current
=(wxTreeListItem
*) child
.m_pItem
;
3778 EnsureVisible( child
);
3782 wxTreeItemId next
= GetNextSibling( m_key_current
);
3785 wxTreeItemId current
= m_key_current
;
3786 while (current
&& !next
)
3788 current
= GetItemParent( current
);
3789 if (current
) next
= GetNextSibling( current
);
3794 SelectItem( next
, unselect_others
, extended_select
);
3795 m_key_current
=(wxTreeListItem
*) next
.m_pItem
;
3796 EnsureVisible( next
);
3802 // <End> selects the last visible tree item
3805 wxTreeItemId last
= GetRootItem();
3807 while ( last
.IsOk() && IsExpanded(last
) )
3809 wxTreeItemId lastChild
= GetLastChild(last
);
3811 // it may happen if the item was expanded but then all of
3812 // its children have been deleted - so IsExpanded() returned
3813 // TRUE, but GetLastChild() returned invalid item
3822 EnsureVisible( last
);
3823 SelectItem( last
, unselect_others
, extended_select
);
3828 // <Home> selects the root item
3831 wxTreeItemId prev
= GetRootItem();
3833 if (HasFlag(wxTR_HIDE_ROOT
))
3836 prev
= GetFirstChild(prev
, dummy
);
3839 EnsureVisible( prev
);
3840 SelectItem( prev
, unselect_others
, extended_select
);
3849 wxTreeItemId
wxTreeListMainWindow::HitTest(const wxPoint
& point
, int& flags
,
3852 // JACS: removed wxYieldIfNeeded() because it can cause the window
3853 // to be deleted from under us if a close window event is pending
3859 if (point
.x
<0) flags
|= wxTREE_HITTEST_TOLEFT
;
3860 if (point
.x
>w
) flags
|= wxTREE_HITTEST_TORIGHT
;
3861 if (point
.y
<0) flags
|= wxTREE_HITTEST_ABOVE
;
3862 if (point
.y
>h
) flags
|= wxTREE_HITTEST_BELOW
;
3863 if (flags
) return wxTreeItemId();
3865 if (m_anchor
== NULL
)
3867 flags
= wxTREE_HITTEST_NOWHERE
;
3868 return wxTreeItemId();
3871 wxClientDC
dc(this);
3873 wxCoord x
= dc
.DeviceToLogicalX( point
.x
);
3874 wxCoord y
= dc
.DeviceToLogicalY( point
.y
);
3875 wxTreeListItem
*hit
= m_anchor
->HitTest(wxPoint(x
, y
), this, flags
,
3879 flags
= wxTREE_HITTEST_NOWHERE
;
3880 return wxTreeItemId();
3885 // get the bounding rectangle of the item (or of its label only)
3886 bool wxTreeListMainWindow::GetBoundingRect(const wxTreeItemId
& item
,
3888 bool WXUNUSED(textOnly
)) const
3890 wxCHECK_MSG( item
.IsOk(), FALSE
, _T("invalid item in wxTreeListMainWindow::GetBoundingRect") );
3892 wxTreeListItem
*i
= (wxTreeListItem
*) item
.m_pItem
;
3895 GetViewStart(& startX
, & startY
);
3897 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
3898 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
3899 rect
.width
= i
->GetWidth();
3900 //rect.height = i->GetHeight();
3901 rect
.height
= GetLineHeight(i
);
3908 void wxTreeListMainWindow::Edit( const wxTreeItemId
& item
)
3910 if (!item
.IsOk()) return;
3912 m_currentEdit
= (wxTreeListItem
*) item
.m_pItem
;
3914 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, m_owner
->GetId() );
3915 te
.SetItem( (long) m_currentEdit
);
3916 te
.SetEventObject( /*this*/m_owner
);
3917 m_owner
->GetEventHandler()->ProcessEvent( te
);
3919 if (!te
.IsAllowed()) return;
3921 // We have to call this here because the label in
3922 // question might just have been added and no screen
3923 // update taken place.
3924 if (m_dirty
) wxYieldIfNeeded();
3926 wxString s
= m_currentEdit
->GetText(/*ALB*/m_main_column
);
3927 int x
= m_currentEdit
->GetX();
3928 int y
= m_currentEdit
->GetY();
3929 int w
= m_currentEdit
->GetWidth();
3930 int h
= m_currentEdit
->GetHeight();
3932 int image
= m_currentEdit
->GetCurrentImage();
3934 w
-= m_imgWidth
+ 4; // I don't know why +4 is needed
3936 wxClientDC
dc(this);
3938 x
= dc
.LogicalToDeviceX( x
);
3939 y
= dc
.LogicalToDeviceY( y
);
3941 wxTreeListTextCtrl
*text
= new wxTreeListTextCtrl(this, -1,
3951 void wxTreeListMainWindow::OnRenameTimer()
3956 void wxTreeListMainWindow::OnRenameAccept()
3958 // TODO if the validator fails this causes a crash
3959 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, m_owner
->GetId() );
3960 le
.SetItem( (long) m_currentEdit
);
3961 le
.SetEventObject( /*this*/m_owner
);
3962 le
.SetLabel( m_renameRes
);
3963 m_owner
->GetEventHandler()->ProcessEvent( le
);
3965 if (!le
.IsAllowed()) return;
3967 SetItemText( m_currentEdit
, m_renameRes
);
3970 void wxTreeListMainWindow::OnMouse( wxMouseEvent
&event
)
3972 if ( !m_anchor
) return;
3974 // we process left mouse up event (enables in-place edit), right down
3975 // (pass to the user code), left dbl click (activate item) and
3976 // dragging/moving events for items drag-and-drop
3977 if ( !(event
.LeftDown() ||
3979 event
.RightDown() ||
3980 event
.LeftDClick() ||
3982 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
3988 if ( event
.LeftDown() )
3991 wxClientDC
dc(this);
3993 wxCoord x
= dc
.DeviceToLogicalX( event
.GetX() );
3994 wxCoord y
= dc
.DeviceToLogicalY( event
.GetY() );
3997 wxTreeListItem
*item
= m_anchor
->HitTest(wxPoint(x
,y
), this, flags
, 0);
3999 if ( event
.Dragging() && !m_isDragging
)
4001 if (m_dragCount
== 0)
4002 m_dragStart
= wxPoint(x
,y
);
4006 if (m_dragCount
!= 3)
4008 // wait until user drags a bit further...
4012 wxEventType command
= event
.RightIsDown()
4013 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
4014 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
4016 wxTreeEvent
nevent( command
,/*ALB*/ m_owner
->GetId() );
4017 nevent
.SetItem( (long) m_current
);
4018 nevent
.SetEventObject(/*this*/m_owner
); // ALB
4020 // by default the dragging is not supported, the user code must
4021 // explicitly allow the event for it to take place
4024 if ( m_owner
->GetEventHandler()->ProcessEvent(nevent
) &&
4025 nevent
.IsAllowed() )
4027 // we're going to drag this item
4028 m_isDragging
= TRUE
;
4030 // remember the old cursor because we will change it while
4032 m_oldCursor
= m_cursor
;
4034 // in a single selection control, hide the selection temporarily
4035 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
4037 m_oldSelection
= (wxTreeListItem
*) GetSelection().m_pItem
;
4039 if ( m_oldSelection
)
4041 m_oldSelection
->SetHilight(FALSE
);
4042 RefreshLine(m_oldSelection
);
4049 else if ( event
.Moving() )
4051 if ( item
!= m_dropTarget
)
4053 // unhighlight the previous drop target
4054 DrawDropEffect(m_dropTarget
);
4056 m_dropTarget
= item
;
4058 // highlight the current drop target if any
4059 DrawDropEffect(m_dropTarget
);
4064 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
4066 // erase the highlighting
4067 DrawDropEffect(m_dropTarget
);
4069 if ( m_oldSelection
)
4071 m_oldSelection
->SetHilight(TRUE
);
4072 RefreshLine(m_oldSelection
);
4073 m_oldSelection
= (wxTreeListItem
*)NULL
;
4076 // generate the drag end event
4077 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
,/*ALB*/m_owner
->GetId());
4079 event
.SetItem( (long) item
);
4080 event
.SetPoint( wxPoint(x
, y
) );
4081 event
.SetEventObject(/*this*/m_owner
);
4083 (void)m_owner
->GetEventHandler()->ProcessEvent(event
);
4085 m_isDragging
= FALSE
;
4086 m_dropTarget
= (wxTreeListItem
*)NULL
;
4090 SetCursor(m_oldCursor
);
4096 // here we process only the messages which happen on tree items
4100 if ( item
== NULL
) return; /* we hit the blank area */
4102 if ( event
.RightDown() )
4105 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
,
4107 nevent
.SetItem( (long) item
);
4109 CalcScrolledPosition(x
, y
, &nx
, &ny
);
4110 nevent
.SetPoint( wxPoint(nx
, ny
));
4111 nevent
.SetEventObject(/*this*/m_owner
);
4112 m_owner
->GetEventHandler()->ProcessEvent(nevent
);
4114 else if ( event
.LeftUp() )
4118 if ( ( item
== m_current
) &&
4119 ( flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
4120 HasFlag(wxTR_EDIT_LABELS
) )
4122 if ( m_renameTimer
->IsRunning() )
4123 m_renameTimer
->Stop();
4125 m_renameTimer
->Start( 100, TRUE
);
4128 m_lastOnSame
= FALSE
;
4131 else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
4133 if ( event
.LeftDown() )
4136 m_lastOnSame
= item
== m_current
;
4139 if ((flags
& wxTREE_HITTEST_ONITEMBUTTON
) ||
4140 ((flags
& wxTREE_HITTEST_ONITEMICON
)) &&
4141 !HasButtons() && item
->HasPlus())
4143 // only toggle the item for a single click, double click on
4144 // the button doesn't do anything (it toggles the item twice)
4145 if ( event
.LeftDown() )
4150 // don't select the item if the button was clicked
4154 // how should the selection work for this event?
4155 bool is_multiple
, extended_select
, unselect_others
;
4156 EventFlagsToSelType(GetWindowStyleFlag(),
4158 event
.ControlDown(),
4159 is_multiple
, extended_select
, unselect_others
);
4161 SelectItem (item
, unselect_others
, extended_select
);
4163 // For some reason, Windows isn't recognizing a left double-click,
4164 // so we need to simulate it here. Allow 200 milliseconds for now.
4165 if ( event
.LeftDClick() )
4167 // double clicking should not start editing the item label
4168 m_renameTimer
->Stop();
4169 m_lastOnSame
= FALSE
;
4171 // send activate event first
4172 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
,
4174 nevent
.SetItem( (long) item
);
4176 CalcScrolledPosition(x
, y
, &nx
, &ny
);
4177 nevent
.SetPoint( wxPoint(nx
, ny
) );
4178 nevent
.SetEventObject( /*this*/m_owner
);
4179 if ( !m_owner
->GetEventHandler()->ProcessEvent( nevent
) )
4181 // if the user code didn't process the activate event,
4182 // handle it ourselves by toggling the item when it is
4184 if ( item
->HasPlus() )
4194 void wxTreeListMainWindow::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
4196 /* after all changes have been done to the tree control,
4197 * we actually redraw the tree when everything is over */
4199 if (!m_dirty
) return;
4203 CalculatePositions();
4205 AdjustMyScrollbars();
4208 void wxTreeListMainWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
4211 // GetClientSize(&w, &h);
4212 // m_header_win->SetSize(0, 0, w, HEADER_HEIGHT);
4215 void wxTreeListMainWindow::OnScroll(wxScrollWinEvent
& event
)
4218 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
4219 wxScrolledWindow::OnScroll(event
);
4221 HandleOnScroll( event
);
4224 if(event
.GetOrientation() == wxHORIZONTAL
)
4226 m_owner
->GetHeaderWindow()->Refresh();
4228 m_owner
->GetHeaderWindow()->MacUpdateImmediately();
4234 void wxTreeListMainWindow::CalculateSize( wxTreeListItem
*item
, wxDC
&dc
)
4240 dc
.SetFont(m_boldFont
);
4242 dc
.GetTextExtent( item
->GetText(/*ALB*/m_main_column
), &text_w
, &text_h
);
4245 // restore normal font
4246 dc
.SetFont( m_normalFont
);
4248 int image
= item
->GetCurrentImage();
4249 int total_h
= (m_imgHeight
> text_h
) ? m_imgHeight
: text_h
;
4251 item
->SetHeight(total_h
);
4252 if (total_h
>m_lineHeight
)
4253 m_lineHeight
=total_h
;
4255 item
->SetWidth(m_imgWidth
+ text_w
+2);
4258 // -----------------------------------------------------------------------------
4259 // for developper : y is now the top of the level
4260 // not the middle of it !
4261 void wxTreeListMainWindow::CalculateLevel( wxTreeListItem
*item
, wxDC
&dc
,
4262 int level
, int &y
, int x_colstart
)
4264 // calculate position of vertical lines
4265 int x
= x_colstart
+ MARGIN
; // start of column
4266 if (HasFlag(wxTR_LINES_AT_ROOT
)) x
+= LINEATROOT
; // space for lines at root
4267 if (HasButtons()) x
+= m_btnWidth2
; // space for buttons etc.
4268 if (!HasFlag(wxTR_HIDE_ROOT
)) x
+= m_indent
; // indent root as well
4269 x
+= m_indent
* level
; // indent according to level
4271 // a hidden root is not evaluated, but its children are always
4272 if (HasFlag(wxTR_HIDE_ROOT
) && (level
== 0)) goto Recurse
;
4274 CalculateSize( item
, dc
);
4279 y
+= GetLineHeight(item
);
4281 // we don't need to calculate collapsed branches
4282 if ( !item
->IsExpanded() ) return;
4285 wxArrayTreeListItems
& children
= item
->GetChildren();
4286 size_t n
, count
= children
.Count();
4288 for (n
= 0; n
< count
; ++n
)
4289 CalculateLevel( children
[n
], dc
, level
, y
, x_colstart
); // recurse
4292 void wxTreeListMainWindow::CalculatePositions()
4294 if ( !m_anchor
) return;
4296 wxClientDC
dc(this);
4299 dc
.SetFont( m_normalFont
);
4301 dc
.SetPen( m_dottedPen
);
4302 //if(GetImageList() == NULL)
4303 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
4307 for(size_t i
= 0; i
< GetMainColumn(); ++i
) {
4308 if (!m_owner
->GetHeaderWindow()->GetColumnShown(i
)) continue;
4309 x_colstart
+= m_owner
->GetHeaderWindow()->GetColumnWidth(i
);
4311 CalculateLevel( m_anchor
, dc
, 0, y
, x_colstart
); // start recursion
4314 void wxTreeListMainWindow::RefreshSubtree(wxTreeListItem
*item
)
4316 if (m_dirty
) return;
4318 wxClientDC
dc(this);
4323 GetClientSize( &cw
, &ch
);
4326 rect
.x
= dc
.LogicalToDeviceX( 0 );
4328 rect
.y
= dc
.LogicalToDeviceY( item
->GetY() - 2 );
4331 Refresh( TRUE
, &rect
);
4333 AdjustMyScrollbars();
4336 void wxTreeListMainWindow::RefreshLine( wxTreeListItem
*item
)
4338 if (m_dirty
) return;
4340 wxClientDC
dc(this);
4345 GetClientSize( &cw
, &ch
);
4348 rect
.x
= dc
.LogicalToDeviceX( 0 );
4349 rect
.y
= dc
.LogicalToDeviceY( item
->GetY() );
4351 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
4353 Refresh( TRUE
, &rect
);
4356 void wxTreeListMainWindow::RefreshSelected()
4358 // TODO: this is awfully inefficient, we should keep the list of all
4359 // selected items internally, should be much faster
4361 RefreshSelectedUnder(m_anchor
);
4364 void wxTreeListMainWindow::RefreshSelectedUnder(wxTreeListItem
*item
)
4366 if ( item
->IsSelected() )
4369 const wxArrayTreeListItems
& children
= item
->GetChildren();
4370 size_t count
= children
.GetCount();
4371 for ( size_t n
= 0; n
< count
; n
++ )
4373 RefreshSelectedUnder(children
[n
]);
4377 // ----------------------------------------------------------------------------
4378 // changing colours: we need to refresh the tree control
4379 // ----------------------------------------------------------------------------
4381 bool wxTreeListMainWindow::SetBackgroundColour(const wxColour
& colour
)
4383 if ( !wxWindow::SetBackgroundColour(colour
) )
4391 bool wxTreeListMainWindow::SetForegroundColour(const wxColour
& colour
)
4393 if ( !wxWindow::SetForegroundColour(colour
) )
4401 //----------- ALB -------------
4403 void wxTreeListMainWindow::SetItemText(const wxTreeItemId
& item
, size_t column
,
4404 const wxString
& text
)
4406 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
4408 wxClientDC
dc(this);
4409 wxTreeListItem
*pItem
= (wxTreeListItem
*) item
.m_pItem
;
4410 pItem
->SetText(column
, text
);
4411 CalculateSize(pItem
, dc
);
4416 wxString
wxTreeListMainWindow::GetItemText(const wxTreeItemId
& item
,
4417 size_t column
) const
4419 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
4421 return ((wxTreeListItem
*) item
.m_pItem
)->GetText(column
);
4424 //-----------------------------
4426 //-----------------------------------------------------------------------------
4428 //-----------------------------------------------------------------------------
4430 IMPLEMENT_DYNAMIC_CLASS(wxTreeListCtrl
, wxControl
);
4432 BEGIN_EVENT_TABLE(wxTreeListCtrl
, wxControl
)
4433 EVT_SIZE(wxTreeListCtrl::OnSize
)
4436 bool wxTreeListCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4439 long style
, const wxValidator
&validator
,
4440 const wxString
& name
)
4442 long main_style
= style
& ~(wxRAISED_BORDER
|wxSUNKEN_BORDER
4443 |wxSIMPLE_BORDER
|wxNO_BORDER
|wxDOUBLE_BORDER
4445 long ctrl_style
= style
& ~(wxVSCROLL
|wxHSCROLL
);
4447 if (!wxControl::Create(parent
, id
, pos
, size
, ctrl_style
, validator
, name
)) {
4450 m_main_win
= new wxTreeListMainWindow(this, -1, wxPoint(0, 0), size
,
4451 main_style
, validator
);
4452 m_header_win
= new wxTreeListHeaderWindow(this, -1, m_main_win
,
4453 wxPoint(0, 0), wxDefaultSize
,
4458 void wxTreeListCtrl::OnSize(wxSizeEvent
& event
)
4461 GetClientSize(&w
, &h
);
4463 m_header_win
->SetSize(0, 0, w
, HEADER_HEIGHT
);
4465 m_main_win
->SetSize(0, HEADER_HEIGHT
+ 1, w
, h
- HEADER_HEIGHT
- 1);
4469 size_t wxTreeListCtrl::GetCount() const { return m_main_win
->GetCount(); }
4471 unsigned int wxTreeListCtrl::GetIndent() const
4472 { return m_main_win
->GetIndent(); }
4474 void wxTreeListCtrl::SetIndent(unsigned int indent
)
4475 { m_main_win
->SetIndent(indent
); }
4477 unsigned int wxTreeListCtrl::GetLineSpacing() const
4478 { return m_main_win
->GetLineSpacing(); }
4480 void wxTreeListCtrl::SetLineSpacing(unsigned int spacing
)
4481 { m_main_win
->SetLineSpacing(spacing
); }
4483 wxImageList
* wxTreeListCtrl::GetImageList() const
4484 { return m_main_win
->GetImageList(); }
4486 wxImageList
* wxTreeListCtrl::GetStateImageList() const
4487 { return m_main_win
->GetStateImageList(); }
4489 wxImageList
* wxTreeListCtrl::GetButtonsImageList() const
4490 { return m_main_win
->GetButtonsImageList(); }
4492 void wxTreeListCtrl::SetImageList(wxImageList
* imageList
)
4493 { m_main_win
->SetImageList(imageList
); }
4495 void wxTreeListCtrl::SetStateImageList(wxImageList
* imageList
)
4496 { m_main_win
->SetStateImageList(imageList
); }
4498 void wxTreeListCtrl::SetButtonsImageList(wxImageList
* imageList
)
4499 { m_main_win
->SetButtonsImageList(imageList
); }
4501 void wxTreeListCtrl::AssignImageList(wxImageList
* imageList
)
4502 { m_main_win
->AssignImageList(imageList
); }
4504 void wxTreeListCtrl::AssignStateImageList(wxImageList
* imageList
)
4505 { m_main_win
->AssignStateImageList(imageList
); }
4507 void wxTreeListCtrl::AssignButtonsImageList(wxImageList
* imageList
)
4508 { m_main_win
->AssignButtonsImageList(imageList
); }
4510 wxString
wxTreeListCtrl::GetItemText(const wxTreeItemId
& item
, size_t column
)
4512 { return m_main_win
->GetItemText(item
, column
); }
4514 int wxTreeListCtrl::GetItemImage(const wxTreeItemId
& item
, size_t column
,
4515 wxTreeItemIcon which
) const
4516 { return m_main_win
->GetItemImage(item
, column
, which
); }
4518 wxTreeItemData
* wxTreeListCtrl::GetItemData(const wxTreeItemId
& item
) const
4519 { return m_main_win
->GetItemData(item
); }
4521 bool wxTreeListCtrl::GetItemBold(const wxTreeItemId
& item
) const
4522 { return m_main_win
->GetItemBold(item
); }
4524 wxColour
wxTreeListCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
4525 { return m_main_win
->GetItemTextColour(item
); }
4527 wxColour
wxTreeListCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
)
4529 { return m_main_win
->GetItemBackgroundColour(item
); }
4531 wxFont
wxTreeListCtrl::GetItemFont(const wxTreeItemId
& item
) const
4532 { return m_main_win
->GetItemFont(item
); }
4535 void wxTreeListCtrl::SetItemText(const wxTreeItemId
& item
, size_t column
,
4536 const wxString
& text
)
4537 { m_main_win
->SetItemText(item
, column
, text
); }
4539 void wxTreeListCtrl::SetItemImage(const wxTreeItemId
& item
,
4542 wxTreeItemIcon which
)
4543 { m_main_win
->SetItemImage(item
, column
, image
, which
); }
4545 void wxTreeListCtrl::SetItemData(const wxTreeItemId
& item
,
4546 wxTreeItemData
* data
)
4547 { m_main_win
->SetItemData(item
, data
); }
4549 void wxTreeListCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
4550 { m_main_win
->SetItemHasChildren(item
, has
); }
4552 void wxTreeListCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
4553 { m_main_win
->SetItemBold(item
, bold
); }
4555 void wxTreeListCtrl::SetItemTextColour(const wxTreeItemId
& item
,
4556 const wxColour
& col
)
4557 { m_main_win
->SetItemTextColour(item
, col
); }
4559 void wxTreeListCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
4560 const wxColour
& col
)
4561 { m_main_win
->SetItemBackgroundColour(item
, col
); }
4563 void wxTreeListCtrl::SetItemFont(const wxTreeItemId
& item
,
4565 { m_main_win
->SetItemFont(item
, font
); }
4567 bool wxTreeListCtrl::SetFont(const wxFont
& font
)
4569 if(m_header_win
) m_header_win
->SetFont(font
);
4571 return m_main_win
->SetFont(font
);
4575 void wxTreeListCtrl::SetWindowStyle(const long style
)
4578 m_main_win
->SetWindowStyle(style
);
4579 // TODO: provide something like wxTL_NO_HEADERS to hide m_header_win
4582 long wxTreeListCtrl::GetWindowStyle() const
4584 long style
= m_windowStyle
;
4586 style
|= m_main_win
->GetWindowStyle();
4590 bool wxTreeListCtrl::IsVisible(const wxTreeItemId
& item
) const
4591 { return m_main_win
->IsVisible(item
); }
4593 bool wxTreeListCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
4594 { return m_main_win
->ItemHasChildren(item
); }
4596 bool wxTreeListCtrl::IsExpanded(const wxTreeItemId
& item
) const
4597 { return m_main_win
->IsExpanded(item
); }
4599 bool wxTreeListCtrl::IsSelected(const wxTreeItemId
& item
) const
4600 { return m_main_win
->IsSelected(item
); }
4602 bool wxTreeListCtrl::IsBold(const wxTreeItemId
& item
) const
4603 { return m_main_win
->IsBold(item
); }
4605 size_t wxTreeListCtrl::GetChildrenCount(const wxTreeItemId
& item
, bool rec
)
4606 { return m_main_win
->GetChildrenCount(item
, rec
); }
4608 wxTreeItemId
wxTreeListCtrl::GetRootItem() const
4609 { return m_main_win
->GetRootItem(); }
4611 wxTreeItemId
wxTreeListCtrl::GetSelection() const
4612 { return m_main_win
->GetSelection(); }
4614 size_t wxTreeListCtrl::GetSelections(wxArrayTreeItemIds
& arr
) const
4615 { return m_main_win
->GetSelections(arr
); }
4617 wxTreeItemId
wxTreeListCtrl::GetItemParent(const wxTreeItemId
& item
) const
4618 { return m_main_win
->GetItemParent(item
); }
4620 wxTreeItemId
wxTreeListCtrl::GetFirstChild(const wxTreeItemId
& item
,
4622 { return m_main_win
->GetFirstChild(item
, cookie
); }
4624 wxTreeItemId
wxTreeListCtrl::GetNextChild(const wxTreeItemId
& item
,
4626 { return m_main_win
->GetNextChild(item
, cookie
); }
4628 wxTreeItemId
wxTreeListCtrl::GetLastChild(const wxTreeItemId
& item
) const
4629 { return m_main_win
->GetLastChild(item
); }
4631 wxTreeItemId
wxTreeListCtrl::GetNextSibling(const wxTreeItemId
& item
) const
4632 { return m_main_win
->GetNextSibling(item
); }
4634 wxTreeItemId
wxTreeListCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
4635 { return m_main_win
->GetPrevSibling(item
); }
4637 wxTreeItemId
wxTreeListCtrl::GetFirstVisibleItem() const
4638 { return m_main_win
->GetFirstVisibleItem(); }
4640 wxTreeItemId
wxTreeListCtrl::GetNextVisible(const wxTreeItemId
& item
) const
4641 { return m_main_win
->GetNextVisible(item
); }
4643 wxTreeItemId
wxTreeListCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
4644 { return m_main_win
->GetPrevVisible(item
); }
4646 wxTreeItemId
wxTreeListCtrl::GetNext(const wxTreeItemId
& item
) const
4647 { return m_main_win
->GetNext(item
); }
4649 wxTreeItemId
wxTreeListCtrl::AddRoot(const wxString
& text
, int image
,
4650 int selectedImage
, wxTreeItemData
* data
)
4651 { return m_main_win
->AddRoot(text
, image
, selectedImage
, data
); }
4653 wxTreeItemId
wxTreeListCtrl::PrependItem(const wxTreeItemId
& parent
,
4654 const wxString
& text
, int image
,
4656 wxTreeItemData
* data
)
4657 { return m_main_win
->PrependItem(parent
, text
, image
, selectedImage
, data
); }
4659 wxTreeItemId
wxTreeListCtrl::InsertItem(const wxTreeItemId
& parent
,
4660 const wxTreeItemId
& previous
,
4661 const wxString
& text
, int image
,
4663 wxTreeItemData
* data
)
4665 return m_main_win
->InsertItem(parent
, previous
, text
, image
,
4666 selectedImage
, data
);
4669 wxTreeItemId
wxTreeListCtrl::InsertItem(const wxTreeItemId
& parent
,
4671 const wxString
& text
, int image
,
4673 wxTreeItemData
* data
)
4675 return m_main_win
->InsertItem(parent
, index
, text
, image
,
4676 selectedImage
, data
);
4679 wxTreeItemId
wxTreeListCtrl::AppendItem(const wxTreeItemId
& parent
,
4680 const wxString
& text
, int image
,
4682 wxTreeItemData
* data
)
4683 { return m_main_win
->AppendItem(parent
, text
, image
, selectedImage
, data
); }
4685 void wxTreeListCtrl::Delete(const wxTreeItemId
& item
)
4686 { m_main_win
->Delete(item
); }
4688 void wxTreeListCtrl::DeleteChildren(const wxTreeItemId
& item
)
4689 { m_main_win
->DeleteChildren(item
); }
4691 void wxTreeListCtrl::DeleteAllItems()
4692 { m_main_win
->DeleteAllItems(); }
4694 void wxTreeListCtrl::Expand(const wxTreeItemId
& item
)
4695 { m_main_win
->Expand(item
); }
4697 void wxTreeListCtrl::ExpandAll(const wxTreeItemId
& item
)
4698 { m_main_win
->ExpandAll(item
); }
4700 void wxTreeListCtrl::Collapse(const wxTreeItemId
& item
)
4701 { m_main_win
->Collapse(item
); }
4703 void wxTreeListCtrl::CollapseAndReset(const wxTreeItemId
& item
)
4704 { m_main_win
->CollapseAndReset(item
); }
4706 void wxTreeListCtrl::Toggle(const wxTreeItemId
& item
)
4707 { m_main_win
->Toggle(item
); }
4709 void wxTreeListCtrl::Unselect()
4710 { m_main_win
->Unselect(); }
4712 void wxTreeListCtrl::UnselectAll()
4713 { m_main_win
->UnselectAll(); }
4715 void wxTreeListCtrl::SelectItem(const wxTreeItemId
& item
, bool unselect_others
,
4716 bool extended_select
)
4717 { m_main_win
->SelectItem(item
, unselect_others
, extended_select
); }
4719 void wxTreeListCtrl::SelectAll(bool extended_select
)
4720 { m_main_win
->SelectAll(extended_select
); }
4722 void wxTreeListCtrl::EnsureVisible(const wxTreeItemId
& item
)
4723 { m_main_win
->EnsureVisible(item
); }
4725 void wxTreeListCtrl::ScrollTo(const wxTreeItemId
& item
)
4726 { m_main_win
->ScrollTo(item
); }
4728 wxTreeItemId
wxTreeListCtrl::HitTest(const wxPoint
& pos
, int& flags
,
4731 return m_main_win
->HitTest(m_main_win
->ScreenToClient(ClientToScreen(pos
)),
4735 bool wxTreeListCtrl::GetBoundingRect(const wxTreeItemId
& item
, wxRect
& rect
,
4736 bool textOnly
) const
4737 { return m_main_win
->GetBoundingRect(item
, rect
, textOnly
); }
4739 void wxTreeListCtrl::Edit(const wxTreeItemId
& item
)
4740 { m_main_win
->Edit(item
); }
4742 int wxTreeListCtrl::OnCompareItems(const wxTreeItemId
& item1
,
4743 const wxTreeItemId
& item2
)
4745 // ALB: do the comparison here, and not delegate to m_main_win, in order
4746 // to let the user override it
4747 //return m_main_win->OnCompareItems(item1, item2);
4748 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
4751 void wxTreeListCtrl::SortChildren(const wxTreeItemId
& item
)
4752 { m_main_win
->SortChildren(item
); }
4754 bool wxTreeListCtrl::SetBackgroundColour(const wxColour
& colour
)
4755 { return m_main_win
->SetBackgroundColour(colour
); }
4757 bool wxTreeListCtrl::SetForegroundColour(const wxColour
& colour
)
4758 { return m_main_win
->SetForegroundColour(colour
); }
4760 size_t wxTreeListCtrl::GetColumnCount() const
4761 { return m_main_win
->GetColumnCount(); }
4763 void wxTreeListCtrl::SetColumnWidth(size_t column
, size_t width
)
4764 { m_header_win
->SetColumnWidth(column
, width
); }
4766 int wxTreeListCtrl::GetColumnWidth(size_t column
) const
4767 { return m_header_win
->GetColumnWidth(column
); }
4769 void wxTreeListCtrl::SetMainColumn(size_t column
)
4770 { m_main_win
->SetMainColumn(column
); }
4772 size_t wxTreeListCtrl::GetMainColumn() const
4773 { return m_main_win
->GetMainColumn(); }
4775 void wxTreeListCtrl::SetColumnText(size_t column
, const wxString
& text
)
4777 m_header_win
->SetColumnText(column
, text
);
4778 m_header_win
->Refresh();
4781 wxString
wxTreeListCtrl::GetColumnText(size_t column
) const
4782 { return m_header_win
->GetColumnText(column
); }
4784 void wxTreeListCtrl::AddColumn(const wxTreeListColumnInfo
& col
)
4785 { m_header_win
->AddColumn(col
); }
4787 void wxTreeListCtrl::InsertColumn(size_t before
,
4788 const wxTreeListColumnInfo
& col
)
4789 { m_header_win
->InsertColumn(before
, col
); }
4791 void wxTreeListCtrl::RemoveColumn(size_t column
)
4792 { m_header_win
->RemoveColumn(column
); }
4794 void wxTreeListCtrl::SetColumn(size_t column
, const wxTreeListColumnInfo
& col
)
4795 { m_header_win
->SetColumn(column
, col
); }
4797 const wxTreeListColumnInfo
& wxTreeListCtrl::GetColumn(size_t column
) const
4798 { return m_header_win
->GetColumn(column
); }
4800 wxTreeListColumnInfo
& wxTreeListCtrl::GetColumn(size_t column
)
4801 { return m_header_win
->GetColumn(column
); }
4803 void wxTreeListCtrl::SetColumnImage(size_t column
, int image
)
4805 m_header_win
->SetColumn(column
, GetColumn(column
).SetImage(image
));
4808 int wxTreeListCtrl::GetColumnImage(size_t column
) const
4810 return m_header_win
->GetColumn(column
).GetImage();
4813 void wxTreeListCtrl::ShowColumn(size_t column
, bool shown
)
4815 wxASSERT_MSG( column
!= GetMainColumn(),
4816 wxT("The main column may not be hidden") );
4817 m_header_win
->SetColumn(column
, GetColumn(column
).SetShown(GetMainColumn()? true: shown
));
4820 bool wxTreeListCtrl::IsColumnShown(size_t column
) const
4822 return m_header_win
->GetColumn(column
).GetShown();
4825 void wxTreeListCtrl::SetColumnAlignment(size_t column
,
4826 wxTreeListColumnAlign align
)
4828 m_header_win
->SetColumn(column
, GetColumn(column
).SetAlignment(align
));
4831 wxTreeListColumnAlign
wxTreeListCtrl::GetColumnAlignment(size_t column
) const
4833 return m_header_win
->GetColumn(column
).GetAlignment();
4836 void wxTreeListCtrl::Refresh(bool erase
, const wxRect
* rect
)
4838 m_main_win
->Refresh(erase
, rect
);
4839 m_header_win
->Refresh(erase
, rect
);
4842 void wxTreeListCtrl::SetFocus()
4843 { m_main_win
->SetFocus(); }