1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: generic tree control implementation
4 // Author: Robert Roebling
6 // Modified: 22/10/98 - almost total rewrite, simpler interface (VZ)
8 // Copyright: (c) 1998 Robert Roebling and Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // =============================================================================
14 // =============================================================================
16 // -----------------------------------------------------------------------------
18 // -----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "treectlg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/treebase.h"
34 #include "wx/generic/treectlg.h"
36 #include "wx/textctrl.h"
37 #include "wx/imaglist.h"
38 #include "wx/settings.h"
39 #include "wx/dcclient.h"
41 #include "wx/renderer.h"
44 #include "wx/mac/private.h"
47 // -----------------------------------------------------------------------------
49 // -----------------------------------------------------------------------------
51 class WXDLLEXPORT wxGenericTreeItem
;
53 WX_DEFINE_EXPORTED_ARRAY_PTR(wxGenericTreeItem
*, wxArrayGenericTreeItems
);
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 static const int NO_IMAGE
= -1;
61 static const int PIXELS_PER_UNIT
= 10;
63 // -----------------------------------------------------------------------------
65 // -----------------------------------------------------------------------------
67 // timer used for enabling in-place edit
68 class WXDLLEXPORT wxTreeRenameTimer
: public wxTimer
71 // start editing the current item after half a second (if the mouse hasn't
72 // been clicked/moved)
75 wxTreeRenameTimer( wxGenericTreeCtrl
*owner
);
77 virtual void Notify();
80 wxGenericTreeCtrl
*m_owner
;
82 DECLARE_NO_COPY_CLASS(wxTreeRenameTimer
)
85 // control used for in-place edit
86 class WXDLLEXPORT wxTreeTextCtrl
: public wxTextCtrl
89 wxTreeTextCtrl(wxGenericTreeCtrl
*owner
, wxGenericTreeItem
*item
);
92 void OnChar( wxKeyEvent
&event
);
93 void OnKeyUp( wxKeyEvent
&event
);
94 void OnKillFocus( wxFocusEvent
&event
);
100 wxGenericTreeCtrl
*m_owner
;
101 wxGenericTreeItem
*m_itemEdited
;
102 wxString m_startValue
;
105 DECLARE_EVENT_TABLE()
106 DECLARE_NO_COPY_CLASS(wxTreeTextCtrl
)
109 // timer used to clear wxGenericTreeCtrl::m_findPrefix if no key was pressed
110 // for a sufficiently long time
111 class WXDLLEXPORT wxTreeFindTimer
: public wxTimer
114 // reset the current prefix after half a second of inactivity
115 enum { DELAY
= 500 };
117 wxTreeFindTimer( wxGenericTreeCtrl
*owner
) { m_owner
= owner
; }
119 virtual void Notify() { m_owner
->m_findPrefix
.clear(); }
122 wxGenericTreeCtrl
*m_owner
;
124 DECLARE_NO_COPY_CLASS(wxTreeFindTimer
)
128 class WXDLLEXPORT wxGenericTreeItem
132 wxGenericTreeItem() { m_data
= NULL
; }
133 wxGenericTreeItem( wxGenericTreeItem
*parent
,
134 const wxString
& text
,
137 wxTreeItemData
*data
);
139 ~wxGenericTreeItem();
142 wxArrayGenericTreeItems
& GetChildren() { return m_children
; }
144 const wxString
& GetText() const { return m_text
; }
145 int GetImage(wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
146 { return m_images
[which
]; }
147 wxTreeItemData
*GetData() const { return m_data
; }
149 // returns the current image for the item (depending on its
150 // selected/expanded/whatever state)
151 int GetCurrentImage() const;
153 void SetText( const wxString
&text
);
154 void SetImage(int image
, wxTreeItemIcon which
) { m_images
[which
] = image
; }
155 void SetData(wxTreeItemData
*data
) { m_data
= data
; }
157 void SetHasPlus(bool has
= TRUE
) { m_hasPlus
= has
; }
159 void SetBold(bool bold
) { m_isBold
= bold
; }
161 int GetX() const { return m_x
; }
162 int GetY() const { return m_y
; }
164 void SetX(int x
) { m_x
= x
; }
165 void SetY(int y
) { m_y
= y
; }
167 int GetHeight() const { return m_height
; }
168 int GetWidth() const { return m_width
; }
170 void SetHeight(int h
) { m_height
= h
; }
171 void SetWidth(int w
) { m_width
= w
; }
173 wxGenericTreeItem
*GetParent() const { return m_parent
; }
176 // deletes all children notifying the treectrl about it if !NULL
178 void DeleteChildren(wxGenericTreeCtrl
*tree
= NULL
);
180 // get count of all children (and grand children if 'recursively')
181 size_t GetChildrenCount(bool recursively
= TRUE
) const;
183 void Insert(wxGenericTreeItem
*child
, size_t index
)
184 { m_children
.Insert(child
, index
); }
186 void GetSize( int &x
, int &y
, const wxGenericTreeCtrl
* );
188 // return the item at given position (or NULL if no item), onButton is
189 // TRUE if the point belongs to the item's button, otherwise it lies
190 // on the item's label
191 wxGenericTreeItem
*HitTest( const wxPoint
& point
,
192 const wxGenericTreeCtrl
*,
196 void Expand() { m_isCollapsed
= FALSE
; }
197 void Collapse() { m_isCollapsed
= TRUE
; }
199 void SetHilight( bool set
= TRUE
) { m_hasHilight
= set
; }
202 bool HasChildren() const { return !m_children
.IsEmpty(); }
203 bool IsSelected() const { return m_hasHilight
!= 0; }
204 bool IsExpanded() const { return !m_isCollapsed
; }
205 bool HasPlus() const { return m_hasPlus
|| HasChildren(); }
206 bool IsBold() const { return m_isBold
!= 0; }
209 // get them - may be NULL
210 wxTreeItemAttr
*GetAttributes() const { return m_attr
; }
211 // get them ensuring that the pointer is not NULL
212 wxTreeItemAttr
& Attr()
216 m_attr
= new wxTreeItemAttr
;
222 void SetAttributes(wxTreeItemAttr
*attr
)
224 if ( m_ownsAttr
) delete m_attr
;
228 // set them and delete when done
229 void AssignAttributes(wxTreeItemAttr
*attr
)
236 // since there can be very many of these, we save size by chosing
237 // the smallest representation for the elements and by ordering
238 // the members to avoid padding.
239 wxString m_text
; // label to be rendered for item
241 wxTreeItemData
*m_data
; // user-provided data
243 wxArrayGenericTreeItems m_children
; // list of children
244 wxGenericTreeItem
*m_parent
; // parent of this item
246 wxTreeItemAttr
*m_attr
; // attributes???
248 // tree ctrl images for the normal, selected, expanded and
249 // expanded+selected states
250 short m_images
[wxTreeItemIcon_Max
];
252 wxCoord m_x
; // (virtual) offset from top
253 wxCoord m_y
; // (virtual) offset from left
254 short m_width
; // width of this item
255 unsigned char m_height
; // height of this item
257 // use bitfields to save size
258 int m_isCollapsed
:1;
259 int m_hasHilight
:1; // same as focused
260 int m_hasPlus
:1; // used for item which doesn't have
261 // children but has a [+] button
262 int m_isBold
:1; // render the label in bold font
263 int m_ownsAttr
:1; // delete attribute when done
265 DECLARE_NO_COPY_CLASS(wxGenericTreeItem
)
268 // =============================================================================
270 // =============================================================================
272 // ----------------------------------------------------------------------------
274 // ----------------------------------------------------------------------------
276 // translate the key or mouse event flags to the type of selection we're
278 static void EventFlagsToSelType(long style
,
282 bool &extended_select
,
283 bool &unselect_others
)
285 is_multiple
= (style
& wxTR_MULTIPLE
) != 0;
286 extended_select
= shiftDown
&& is_multiple
;
287 unselect_others
= !(extended_select
|| (ctrlDown
&& is_multiple
));
290 // check if the given item is under another one
291 static bool IsDescendantOf(wxGenericTreeItem
*parent
, wxGenericTreeItem
*item
)
295 if ( item
== parent
)
297 // item is a descendant of parent
301 item
= item
->GetParent();
307 // -----------------------------------------------------------------------------
308 // wxTreeRenameTimer (internal)
309 // -----------------------------------------------------------------------------
311 wxTreeRenameTimer::wxTreeRenameTimer( wxGenericTreeCtrl
*owner
)
316 void wxTreeRenameTimer::Notify()
318 m_owner
->OnRenameTimer();
321 //-----------------------------------------------------------------------------
322 // wxTreeTextCtrl (internal)
323 //-----------------------------------------------------------------------------
325 BEGIN_EVENT_TABLE(wxTreeTextCtrl
,wxTextCtrl
)
326 EVT_CHAR (wxTreeTextCtrl::OnChar
)
327 EVT_KEY_UP (wxTreeTextCtrl::OnKeyUp
)
328 EVT_KILL_FOCUS (wxTreeTextCtrl::OnKillFocus
)
331 wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl
*owner
,
332 wxGenericTreeItem
*item
)
333 : m_itemEdited(item
), m_startValue(item
->GetText())
338 int w
= m_itemEdited
->GetWidth(),
339 h
= m_itemEdited
->GetHeight();
342 m_owner
->CalcScrolledPosition(item
->GetX(), item
->GetY(), &x
, &y
);
347 int image
= item
->GetCurrentImage();
348 if ( image
!= NO_IMAGE
)
350 if ( m_owner
->m_imageListNormal
)
352 m_owner
->m_imageListNormal
->GetSize( image
, image_w
, image_h
);
357 wxFAIL_MSG(_T("you must create an image list to use images!"));
361 // FIXME: what are all these hardcoded 4, 8 and 11s really?
365 (void)Create(m_owner
, wxID_ANY
, m_startValue
,
366 wxPoint(x
- 4, y
- 4), wxSize(w
+ 11, h
+ 8));
369 bool wxTreeTextCtrl::AcceptChanges()
371 const wxString value
= GetValue();
373 if ( value
== m_startValue
)
375 // nothing changed, always accept
379 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
381 // vetoed by the user
385 // accepted, do rename the item
386 m_owner
->SetItemText(m_itemEdited
, value
);
391 void wxTreeTextCtrl::Finish()
395 m_owner
->ResetTextControl();
397 wxPendingDelete
.Append(this);
401 m_owner
->SetFocus(); // This doesn't work. TODO.
405 void wxTreeTextCtrl::OnChar( wxKeyEvent
&event
)
407 switch ( event
.m_keyCode
)
410 if ( !AcceptChanges() )
412 // vetoed by the user, don't disappear
419 m_owner
->OnRenameCancelled(m_itemEdited
);
427 void wxTreeTextCtrl::OnKeyUp( wxKeyEvent
&event
)
431 // auto-grow the textctrl:
432 wxSize parentSize
= m_owner
->GetSize();
433 wxPoint myPos
= GetPosition();
434 wxSize mySize
= GetSize();
436 GetTextExtent(GetValue() + _T("M"), &sx
, &sy
);
437 if (myPos
.x
+ sx
> parentSize
.x
)
438 sx
= parentSize
.x
- myPos
.x
;
447 void wxTreeTextCtrl::OnKillFocus( wxFocusEvent
&event
)
455 if ( AcceptChanges() )
461 // -----------------------------------------------------------------------------
463 // -----------------------------------------------------------------------------
465 wxGenericTreeItem::wxGenericTreeItem(wxGenericTreeItem
*parent
,
466 const wxString
& text
,
467 int image
, int selImage
,
468 wxTreeItemData
*data
)
471 m_images
[wxTreeItemIcon_Normal
] = image
;
472 m_images
[wxTreeItemIcon_Selected
] = selImage
;
473 m_images
[wxTreeItemIcon_Expanded
] = NO_IMAGE
;
474 m_images
[wxTreeItemIcon_SelectedExpanded
] = NO_IMAGE
;
479 m_isCollapsed
= TRUE
;
480 m_hasHilight
= FALSE
;
486 m_attr
= (wxTreeItemAttr
*)NULL
;
489 // We don't know the height here yet.
494 wxGenericTreeItem::~wxGenericTreeItem()
498 if (m_ownsAttr
) delete m_attr
;
500 wxASSERT_MSG( m_children
.IsEmpty(),
501 wxT("please call DeleteChildren() before deleting the item") );
504 void wxGenericTreeItem::DeleteChildren(wxGenericTreeCtrl
*tree
)
506 size_t count
= m_children
.Count();
507 for ( size_t n
= 0; n
< count
; n
++ )
509 wxGenericTreeItem
*child
= m_children
[n
];
511 tree
->SendDeleteEvent(child
);
513 child
->DeleteChildren(tree
);
520 void wxGenericTreeItem::SetText( const wxString
&text
)
525 size_t wxGenericTreeItem::GetChildrenCount(bool recursively
) const
527 size_t count
= m_children
.Count();
531 size_t total
= count
;
532 for (size_t n
= 0; n
< count
; ++n
)
534 total
+= m_children
[n
]->GetChildrenCount();
540 void wxGenericTreeItem::GetSize( int &x
, int &y
,
541 const wxGenericTreeCtrl
*theButton
)
543 int bottomY
=m_y
+theButton
->GetLineHeight(this);
544 if ( y
< bottomY
) y
= bottomY
;
545 int width
= m_x
+ m_width
;
546 if ( x
< width
) x
= width
;
550 size_t count
= m_children
.Count();
551 for ( size_t n
= 0; n
< count
; ++n
)
553 m_children
[n
]->GetSize( x
, y
, theButton
);
558 wxGenericTreeItem
*wxGenericTreeItem::HitTest(const wxPoint
& point
,
559 const wxGenericTreeCtrl
*theCtrl
,
563 // for a hidden root node, don't evaluate it, but do evaluate children
564 if ( !(level
== 0 && theCtrl
->HasFlag(wxTR_HIDE_ROOT
)) )
567 int h
= theCtrl
->GetLineHeight(this);
568 if ((point
.y
> m_y
) && (point
.y
< m_y
+ h
))
570 int y_mid
= m_y
+ h
/2;
571 if (point
.y
< y_mid
)
572 flags
|= wxTREE_HITTEST_ONITEMUPPERPART
;
574 flags
|= wxTREE_HITTEST_ONITEMLOWERPART
;
576 int xCross
= m_x
- theCtrl
->GetSpacing();
578 // according to the drawing code the triangels are drawn
579 // at -4 , -4 from the position up to +10/+10 max
580 if ((point
.x
> xCross
-4) && (point
.x
< xCross
+10) &&
581 (point
.y
> y_mid
-4) && (point
.y
< y_mid
+10) &&
582 HasPlus() && theCtrl
->HasButtons() )
584 // 5 is the size of the plus sign
585 if ((point
.x
> xCross
-6) && (point
.x
< xCross
+6) &&
586 (point
.y
> y_mid
-6) && (point
.y
< y_mid
+6) &&
587 HasPlus() && theCtrl
->HasButtons() )
590 flags
|= wxTREE_HITTEST_ONITEMBUTTON
;
594 if ((point
.x
>= m_x
) && (point
.x
<= m_x
+m_width
))
599 // assuming every image (normal and selected) has the same size!
600 if ( (GetImage() != NO_IMAGE
) && theCtrl
->m_imageListNormal
)
601 theCtrl
->m_imageListNormal
->GetSize(GetImage(),
604 if ((image_w
!= -1) && (point
.x
<= m_x
+ image_w
+ 1))
605 flags
|= wxTREE_HITTEST_ONITEMICON
;
607 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
613 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
614 if (point
.x
> m_x
+m_width
)
615 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
620 // if children are expanded, fall through to evaluate them
621 if (m_isCollapsed
) return (wxGenericTreeItem
*) NULL
;
625 size_t count
= m_children
.Count();
626 for ( size_t n
= 0; n
< count
; n
++ )
628 wxGenericTreeItem
*res
= m_children
[n
]->HitTest( point
,
636 return (wxGenericTreeItem
*) NULL
;
639 int wxGenericTreeItem::GetCurrentImage() const
641 int image
= NO_IMAGE
;
646 image
= GetImage(wxTreeItemIcon_SelectedExpanded
);
649 if ( image
== NO_IMAGE
)
651 // we usually fall back to the normal item, but try just the
652 // expanded one (and not selected) first in this case
653 image
= GetImage(wxTreeItemIcon_Expanded
);
659 image
= GetImage(wxTreeItemIcon_Selected
);
662 // maybe it doesn't have the specific image we want,
663 // try the default one instead
664 if ( image
== NO_IMAGE
) image
= GetImage();
669 // -----------------------------------------------------------------------------
670 // wxGenericTreeCtrl implementation
671 // -----------------------------------------------------------------------------
673 IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl
, wxScrolledWindow
)
675 BEGIN_EVENT_TABLE(wxGenericTreeCtrl
,wxScrolledWindow
)
676 EVT_PAINT (wxGenericTreeCtrl::OnPaint
)
677 EVT_MOUSE_EVENTS (wxGenericTreeCtrl::OnMouse
)
678 EVT_CHAR (wxGenericTreeCtrl::OnChar
)
679 EVT_SET_FOCUS (wxGenericTreeCtrl::OnSetFocus
)
680 EVT_KILL_FOCUS (wxGenericTreeCtrl::OnKillFocus
)
681 EVT_TREE_ITEM_GETTOOLTIP(-1, wxGenericTreeCtrl::OnGetToolTip
)
684 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
686 * wxTreeCtrl has to be a real class or we have problems with
687 * the run-time information.
690 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxGenericTreeCtrl
)
693 // -----------------------------------------------------------------------------
694 // construction/destruction
695 // -----------------------------------------------------------------------------
697 void wxGenericTreeCtrl::Init()
699 m_current
= m_key_current
= m_anchor
= m_select_me
= (wxGenericTreeItem
*) NULL
;
707 m_hilightBrush
= new wxBrush
709 wxSystemSettings::GetColour
711 wxSYS_COLOUR_HIGHLIGHT
716 m_hilightUnfocusedBrush
= new wxBrush
718 wxSystemSettings::GetColour
720 wxSYS_COLOUR_BTNSHADOW
725 m_imageListNormal
= m_imageListButtons
=
726 m_imageListState
= (wxImageList
*) NULL
;
727 m_ownsImageListNormal
= m_ownsImageListButtons
=
728 m_ownsImageListState
= FALSE
;
731 m_isDragging
= FALSE
;
732 m_dropTarget
= m_oldSelection
= NULL
;
736 m_renameTimer
= NULL
;
741 m_lastOnSame
= FALSE
;
743 #if defined( __WXMAC__ ) && __WXMAC_CARBON__
744 m_normalFont
.MacCreateThemeFont( kThemeViewsFont
) ;
746 m_normalFont
= wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT
);
748 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
749 m_normalFont
.GetFamily(),
750 m_normalFont
.GetStyle(),
752 m_normalFont
.GetUnderlined(),
753 m_normalFont
.GetFaceName(),
754 m_normalFont
.GetEncoding());
757 bool wxGenericTreeCtrl::Create(wxWindow
*parent
,
762 const wxValidator
& wxVALIDATOR_PARAM(validator
),
763 const wxString
& name
)
767 wxGetOsVersion( &major
, &minor
);
769 style
&= ~wxTR_LINES_AT_ROOT
;
770 style
|= wxTR_NO_LINES
;
772 style
|= wxTR_ROW_LINES
;
775 wxScrolledWindow::Create( parent
, id
, pos
, size
,
776 style
|wxHSCROLL
|wxVSCROLL
, name
);
778 // If the tree display has no buttons, but does have
779 // connecting lines, we can use a narrower layout.
780 // It may not be a good idea to force this...
781 if (!HasButtons() && !HasFlag(wxTR_NO_LINES
))
788 SetValidator( validator
);
791 wxVisualAttributes attr
= GetDefaultAttributes();
792 SetDefaultForegroundColour( attr
.colFg
);
793 SetDefaultBackgroundColour( attr
.colBg
);
794 SetDefaultFont(attr
.font
);
796 // m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86
797 m_dottedPen
= wxPen( wxT("grey"), 0, 0 );
804 wxGenericTreeCtrl::~wxGenericTreeCtrl()
806 delete m_hilightBrush
;
807 delete m_hilightUnfocusedBrush
;
811 delete m_renameTimer
;
814 if (m_ownsImageListNormal
)
815 delete m_imageListNormal
;
816 if (m_ownsImageListState
)
817 delete m_imageListState
;
818 if (m_ownsImageListButtons
)
819 delete m_imageListButtons
;
822 // -----------------------------------------------------------------------------
824 // -----------------------------------------------------------------------------
826 size_t wxGenericTreeCtrl::GetCount() const
834 size_t count
= m_anchor
->GetChildrenCount();
835 if ( !HasFlag(wxTR_HIDE_ROOT
) )
837 // take the root itself into account
844 void wxGenericTreeCtrl::SetIndent(unsigned int indent
)
846 m_indent
= (unsigned short) indent
;
850 void wxGenericTreeCtrl::SetSpacing(unsigned int spacing
)
852 m_spacing
= (unsigned short) spacing
;
857 wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
,
858 bool recursively
) const
860 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
862 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
865 void wxGenericTreeCtrl::SetWindowStyle(const long styles
)
867 if (!HasFlag(wxTR_HIDE_ROOT
) && (styles
& wxTR_HIDE_ROOT
))
869 // if we will hide the root, make sure children are visible
870 m_anchor
->SetHasPlus();
872 CalculatePositions();
875 // right now, just sets the styles. Eventually, we may
876 // want to update the inherited styles, but right now
877 // none of the parents has updatable styles
878 m_windowStyle
= styles
;
882 // -----------------------------------------------------------------------------
883 // functions to work with tree items
884 // -----------------------------------------------------------------------------
886 wxString
wxGenericTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
888 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
890 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetText();
893 int wxGenericTreeCtrl::GetItemImage(const wxTreeItemId
& item
,
894 wxTreeItemIcon which
) const
896 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
898 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetImage(which
);
901 wxTreeItemData
*wxGenericTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
903 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
905 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetData();
908 wxColour
wxGenericTreeCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
910 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
912 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
913 return pItem
->Attr().GetTextColour();
916 wxColour
wxGenericTreeCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
) const
918 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
920 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
921 return pItem
->Attr().GetBackgroundColour();
924 wxFont
wxGenericTreeCtrl::GetItemFont(const wxTreeItemId
& item
) const
926 wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") );
928 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
929 return pItem
->Attr().GetFont();
932 void wxGenericTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
934 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
937 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
938 pItem
->SetText(text
);
939 CalculateSize(pItem
, dc
);
943 void wxGenericTreeCtrl::SetItemImage(const wxTreeItemId
& item
,
945 wxTreeItemIcon which
)
947 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
949 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
950 pItem
->SetImage(image
, which
);
953 CalculateSize(pItem
, dc
);
957 void wxGenericTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
959 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
964 ((wxGenericTreeItem
*) item
.m_pItem
)->SetData(data
);
967 void wxGenericTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
969 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
971 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
972 pItem
->SetHasPlus(has
);
976 void wxGenericTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
978 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
980 // avoid redrawing the tree if no real change
981 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
982 if ( pItem
->IsBold() != bold
)
984 pItem
->SetBold(bold
);
989 void wxGenericTreeCtrl::SetItemTextColour(const wxTreeItemId
& item
,
992 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
994 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
995 pItem
->Attr().SetTextColour(col
);
999 void wxGenericTreeCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
1000 const wxColour
& col
)
1002 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1004 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1005 pItem
->Attr().SetBackgroundColour(col
);
1009 void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
)
1011 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1013 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1014 pItem
->Attr().SetFont(font
);
1018 bool wxGenericTreeCtrl::SetFont( const wxFont
&font
)
1020 wxScrolledWindow::SetFont(font
);
1022 m_normalFont
= font
;
1023 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
1024 m_normalFont
.GetFamily(),
1025 m_normalFont
.GetStyle(),
1027 m_normalFont
.GetUnderlined(),
1028 m_normalFont
.GetFaceName(),
1029 m_normalFont
.GetEncoding());
1035 // -----------------------------------------------------------------------------
1036 // item status inquiries
1037 // -----------------------------------------------------------------------------
1039 bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
1041 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
1043 // An item is only visible if it's not a descendant of a collapsed item
1044 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1045 wxGenericTreeItem
* parent
= pItem
->GetParent();
1048 if (!parent
->IsExpanded())
1050 parent
= parent
->GetParent();
1054 GetViewStart(& startX
, & startY
);
1056 wxSize clientSize
= GetClientSize();
1059 if (!GetBoundingRect(item
, rect
))
1061 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
1063 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
1065 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
1071 bool wxGenericTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
1073 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
1075 // consider that the item does have children if it has the "+" button: it
1076 // might not have them (if it had never been expanded yet) but then it
1077 // could have them as well and it's better to err on this side rather than
1078 // disabling some operations which are restricted to the items with
1079 // children for an item which does have them
1080 return ((wxGenericTreeItem
*) item
.m_pItem
)->HasPlus();
1083 bool wxGenericTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
1085 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
1087 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsExpanded();
1090 bool wxGenericTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
1092 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
1094 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsSelected();
1097 bool wxGenericTreeCtrl::IsBold(const wxTreeItemId
& item
) const
1099 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
1101 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsBold();
1104 // -----------------------------------------------------------------------------
1106 // -----------------------------------------------------------------------------
1108 wxTreeItemId
wxGenericTreeCtrl::GetItemParent(const wxTreeItemId
& item
) const
1110 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1112 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetParent();
1115 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1116 wxTreeItemIdValue
& cookie
) const
1118 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1121 return GetNextChild(item
, cookie
);
1124 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1125 wxTreeItemIdValue
& cookie
) const
1127 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1129 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1131 // it's ok to cast cookie to size_t, we never have indices big enough to
1132 // overflow "void *"
1133 size_t *pIndex
= (size_t *)&cookie
;
1134 if ( *pIndex
< children
.Count() )
1136 return children
.Item((*pIndex
)++);
1140 // there are no more of them
1141 return wxTreeItemId();
1145 #if WXWIN_COMPATIBILITY_2_4
1147 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1150 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1153 return GetNextChild(item
, cookie
);
1156 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1159 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1161 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1162 if ( (size_t)cookie
< children
.Count() )
1164 return children
.Item((size_t)cookie
++);
1168 // there are no more of them
1169 return wxTreeItemId();
1173 #endif // WXWIN_COMPATIBILITY_2_4
1175 wxTreeItemId
wxGenericTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
1177 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1179 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1180 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
1183 wxTreeItemId
wxGenericTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
1185 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1187 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1188 wxGenericTreeItem
*parent
= i
->GetParent();
1189 if ( parent
== NULL
)
1191 // root item doesn't have any siblings
1192 return wxTreeItemId();
1195 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1196 int index
= siblings
.Index(i
);
1197 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1199 size_t n
= (size_t)(index
+ 1);
1200 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
1203 wxTreeItemId
wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
1205 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1207 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1208 wxGenericTreeItem
*parent
= i
->GetParent();
1209 if ( parent
== NULL
)
1211 // root item doesn't have any siblings
1212 return wxTreeItemId();
1215 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1216 int index
= siblings
.Index(i
);
1217 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1219 return index
== 0 ? wxTreeItemId()
1220 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
1223 // Only for internal use right now, but should probably be public
1224 wxTreeItemId
wxGenericTreeCtrl::GetNext(const wxTreeItemId
& item
) const
1226 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1228 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1230 // First see if there are any children.
1231 wxArrayGenericTreeItems
& children
= i
->GetChildren();
1232 if (children
.GetCount() > 0)
1234 return children
.Item(0);
1238 // Try a sibling of this or ancestor instead
1239 wxTreeItemId p
= item
;
1240 wxTreeItemId toFind
;
1243 toFind
= GetNextSibling(p
);
1244 p
= GetItemParent(p
);
1245 } while (p
.IsOk() && !toFind
.IsOk());
1250 wxTreeItemId
wxGenericTreeCtrl::GetFirstVisibleItem() const
1252 wxTreeItemId id
= GetRootItem();
1261 } while (id
.IsOk());
1263 return wxTreeItemId();
1266 wxTreeItemId
wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
1268 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1270 wxTreeItemId id
= item
;
1273 while (id
= GetNext(id
), id
.IsOk())
1279 return wxTreeItemId();
1282 wxTreeItemId
wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
1284 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1286 wxFAIL_MSG(wxT("not implemented"));
1288 return wxTreeItemId();
1291 // called by wxTextTreeCtrl when it marks itself for deletion
1292 void wxGenericTreeCtrl::ResetTextControl()
1297 // find the first item starting with the given prefix after the given item
1298 wxTreeItemId
wxGenericTreeCtrl::FindItem(const wxTreeItemId
& idParent
,
1299 const wxString
& prefixOrig
) const
1301 // match is case insensitive as this is more convenient to the user: having
1302 // to press Shift-letter to go to the item starting with a capital letter
1303 // would be too bothersome
1304 wxString prefix
= prefixOrig
.Lower();
1306 // determine the starting point: we shouldn't take the current item (this
1307 // allows to switch between two items starting with the same letter just by
1308 // pressing it) but we shouldn't jump to the next one if the user is
1309 // continuing to type as otherwise he might easily skip the item he wanted
1310 wxTreeItemId id
= idParent
;
1311 if ( prefix
.length() == 1 )
1316 // look for the item starting with the given prefix after it
1317 while ( id
.IsOk() && !GetItemText(id
).Lower().StartsWith(prefix
) )
1322 // if we haven't found anything...
1325 // ... wrap to the beginning
1327 if ( HasFlag(wxTR_HIDE_ROOT
) )
1329 // can't select virtual root
1333 // and try all the items (stop when we get to the one we started from)
1334 while ( id
!= idParent
&& !GetItemText(id
).Lower().StartsWith(prefix
) )
1343 // -----------------------------------------------------------------------------
1345 // -----------------------------------------------------------------------------
1347 wxTreeItemId
wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId
& parentId
,
1349 const wxString
& text
,
1350 int image
, int selImage
,
1351 wxTreeItemData
*data
)
1353 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1356 // should we give a warning here?
1357 return AddRoot(text
, image
, selImage
, data
);
1360 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
1362 wxGenericTreeItem
*item
=
1363 new wxGenericTreeItem( parent
, text
, image
, selImage
, data
);
1367 data
->m_pItem
= item
;
1370 parent
->Insert( item
, previous
);
1375 wxTreeItemId
wxGenericTreeCtrl::AddRoot(const wxString
& text
,
1376 int image
, int selImage
,
1377 wxTreeItemData
*data
)
1379 wxCHECK_MSG( !m_anchor
, wxTreeItemId(), wxT("tree can have only one root") );
1381 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
1383 m_anchor
= new wxGenericTreeItem((wxGenericTreeItem
*)NULL
, text
,
1384 image
, selImage
, data
);
1387 data
->m_pItem
= m_anchor
;
1390 if (HasFlag(wxTR_HIDE_ROOT
))
1392 // if root is hidden, make sure we can navigate
1394 m_anchor
->SetHasPlus();
1396 CalculatePositions();
1399 if (!HasFlag(wxTR_MULTIPLE
))
1401 m_current
= m_key_current
= m_anchor
;
1402 m_current
->SetHilight( TRUE
);
1408 wxTreeItemId
wxGenericTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
1409 const wxString
& text
,
1410 int image
, int selImage
,
1411 wxTreeItemData
*data
)
1413 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
1416 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1417 const wxTreeItemId
& idPrevious
,
1418 const wxString
& text
,
1419 int image
, int selImage
,
1420 wxTreeItemData
*data
)
1422 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1425 // should we give a warning here?
1426 return AddRoot(text
, image
, selImage
, data
);
1430 if (idPrevious
.IsOk())
1432 index
= parent
->GetChildren().Index((wxGenericTreeItem
*) idPrevious
.m_pItem
);
1433 wxASSERT_MSG( index
!= wxNOT_FOUND
,
1434 wxT("previous item in wxGenericTreeCtrl::InsertItem() is not a sibling") );
1437 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
1440 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1442 const wxString
& text
,
1443 int image
, int selImage
,
1444 wxTreeItemData
*data
)
1446 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1449 // should we give a warning here?
1450 return AddRoot(text
, image
, selImage
, data
);
1453 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
1456 wxTreeItemId
wxGenericTreeCtrl::AppendItem(const wxTreeItemId
& parentId
,
1457 const wxString
& text
,
1458 int image
, int selImage
,
1459 wxTreeItemData
*data
)
1461 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1464 // should we give a warning here?
1465 return AddRoot(text
, image
, selImage
, data
);
1468 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
1469 image
, selImage
, data
);
1472 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem
*item
)
1474 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, GetId() );
1475 event
.m_item
= item
;
1476 event
.SetEventObject( this );
1477 ProcessEvent( event
);
1480 void wxGenericTreeCtrl::DeleteChildren(const wxTreeItemId
& itemId
)
1482 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
1484 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1485 item
->DeleteChildren(this);
1488 void wxGenericTreeCtrl::Delete(const wxTreeItemId
& itemId
)
1490 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
1492 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1494 wxGenericTreeItem
*parent
= item
->GetParent();
1496 // don't keep stale pointers around!
1497 if ( IsDescendantOf(item
, m_key_current
) )
1499 // Don't silently change the selection:
1500 // do it properly in idle time, so event
1501 // handlers get called.
1503 // m_key_current = parent;
1504 m_key_current
= NULL
;
1507 // m_select_me records whether we need to select
1508 // a different item, in idle time.
1509 if ( m_select_me
&& IsDescendantOf(item
, m_select_me
) )
1511 m_select_me
= parent
;
1514 if ( IsDescendantOf(item
, m_current
) )
1516 // Don't silently change the selection:
1517 // do it properly in idle time, so event
1518 // handlers get called.
1520 // m_current = parent;
1522 m_select_me
= parent
;
1525 // remove the item from the tree
1528 parent
->GetChildren().Remove( item
); // remove by value
1530 else // deleting the root
1532 // nothing will be left in the tree
1536 // and delete all of its children and the item itself now
1537 item
->DeleteChildren(this);
1538 SendDeleteEvent(item
);
1542 void wxGenericTreeCtrl::DeleteAllItems()
1550 void wxGenericTreeCtrl::Expand(const wxTreeItemId
& itemId
)
1552 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1554 wxCHECK_RET( item
, _T("invalid item in wxGenericTreeCtrl::Expand") );
1555 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1556 _T("can't expand hidden root") );
1558 if ( !item
->HasPlus() )
1561 if ( item
->IsExpanded() )
1564 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, GetId() );
1565 event
.m_item
= item
;
1566 event
.SetEventObject( this );
1568 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1570 // cancelled by program
1575 CalculatePositions();
1577 RefreshSubtree(item
);
1579 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
1580 ProcessEvent( event
);
1583 void wxGenericTreeCtrl::ExpandAll(const wxTreeItemId
& item
)
1585 if ( !HasFlag(wxTR_HIDE_ROOT
) || item
!= GetRootItem())
1588 if ( !IsExpanded(item
) )
1592 wxTreeItemIdValue cookie
;
1593 wxTreeItemId child
= GetFirstChild(item
, cookie
);
1594 while ( child
.IsOk() )
1598 child
= GetNextChild(item
, cookie
);
1602 void wxGenericTreeCtrl::Collapse(const wxTreeItemId
& itemId
)
1604 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1605 _T("can't collapse hidden root") );
1607 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1609 if ( !item
->IsExpanded() )
1612 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, GetId() );
1613 event
.m_item
= item
;
1614 event
.SetEventObject( this );
1615 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1617 // cancelled by program
1623 #if 0 // TODO why should items be collapsed recursively?
1624 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1625 size_t count
= children
.Count();
1626 for ( size_t n
= 0; n
< count
; n
++ )
1628 Collapse(children
[n
]);
1632 CalculatePositions();
1634 RefreshSubtree(item
);
1636 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
1637 ProcessEvent( event
);
1640 void wxGenericTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
1643 DeleteChildren(item
);
1646 void wxGenericTreeCtrl::Toggle(const wxTreeItemId
& itemId
)
1648 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1650 if (item
->IsExpanded())
1656 void wxGenericTreeCtrl::Unselect()
1660 m_current
->SetHilight( FALSE
);
1661 RefreshLine( m_current
);
1668 void wxGenericTreeCtrl::UnselectAllChildren(wxGenericTreeItem
*item
)
1670 if (item
->IsSelected())
1672 item
->SetHilight(FALSE
);
1676 if (item
->HasChildren())
1678 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1679 size_t count
= children
.Count();
1680 for ( size_t n
= 0; n
< count
; ++n
)
1682 UnselectAllChildren(children
[n
]);
1687 void wxGenericTreeCtrl::UnselectAll()
1689 wxTreeItemId rootItem
= GetRootItem();
1691 // the tree might not have the root item at all
1694 UnselectAllChildren((wxGenericTreeItem
*) rootItem
.m_pItem
);
1698 // Recursive function !
1699 // To stop we must have crt_item<last_item
1701 // Tag all next children, when no more children,
1702 // Move to parent (not to tag)
1703 // Keep going... if we found last_item, we stop.
1704 bool wxGenericTreeCtrl::TagNextChildren(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1706 wxGenericTreeItem
*parent
= crt_item
->GetParent();
1708 if (parent
== NULL
) // This is root item
1709 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
1711 wxArrayGenericTreeItems
& children
= parent
->GetChildren();
1712 int index
= children
.Index(crt_item
);
1713 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1715 size_t count
= children
.Count();
1716 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
1718 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return TRUE
;
1721 return TagNextChildren(parent
, last_item
, select
);
1724 bool wxGenericTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1726 crt_item
->SetHilight(select
);
1727 RefreshLine(crt_item
);
1729 if (crt_item
==last_item
)
1732 if (crt_item
->HasChildren())
1734 wxArrayGenericTreeItems
& children
= crt_item
->GetChildren();
1735 size_t count
= children
.Count();
1736 for ( size_t n
= 0; n
< count
; ++n
)
1738 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
1746 void wxGenericTreeCtrl::SelectItemRange(wxGenericTreeItem
*item1
, wxGenericTreeItem
*item2
)
1750 // item2 is not necessary after item1
1751 // choice first' and 'last' between item1 and item2
1752 wxGenericTreeItem
*first
= (item1
->GetY()<item2
->GetY()) ? item1
: item2
;
1753 wxGenericTreeItem
*last
= (item1
->GetY()<item2
->GetY()) ? item2
: item1
;
1755 bool select
= m_current
->IsSelected();
1757 if ( TagAllChildrenUntilLast(first
,last
,select
) )
1760 TagNextChildren(first
,last
,select
);
1763 void wxGenericTreeCtrl::DoSelectItem(const wxTreeItemId
& itemId
,
1764 bool unselect_others
,
1765 bool extended_select
)
1767 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
1771 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
1772 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1774 //wxCHECK_RET( ( (!unselect_others) && is_single),
1775 // wxT("this is a single selection tree") );
1777 // to keep going anyhow !!!
1780 if (item
->IsSelected())
1781 return; // nothing to do
1782 unselect_others
= TRUE
;
1783 extended_select
= FALSE
;
1785 else if ( unselect_others
&& item
->IsSelected() )
1787 // selection change if there is more than one item currently selected
1788 wxArrayTreeItemIds selected_items
;
1789 if ( GetSelections(selected_items
) == 1 )
1793 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, GetId() );
1794 event
.m_item
= item
;
1795 event
.m_itemOld
= m_current
;
1796 event
.SetEventObject( this );
1797 // TODO : Here we don't send any selection mode yet !
1799 if ( GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed() )
1802 wxTreeItemId parent
= GetItemParent( itemId
);
1803 while (parent
.IsOk())
1805 if (!IsExpanded(parent
))
1808 parent
= GetItemParent( parent
);
1811 EnsureVisible( itemId
);
1814 if (unselect_others
)
1816 if (is_single
) Unselect(); // to speed up thing
1821 if (extended_select
)
1825 m_current
= m_key_current
= (wxGenericTreeItem
*) GetRootItem().m_pItem
;
1828 // don't change the mark (m_current)
1829 SelectItemRange(m_current
, item
);
1833 bool select
=TRUE
; // the default
1835 // Check if we need to toggle hilight (ctrl mode)
1836 if (!unselect_others
)
1837 select
=!item
->IsSelected();
1839 m_current
= m_key_current
= item
;
1840 m_current
->SetHilight(select
);
1841 RefreshLine( m_current
);
1844 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
1845 GetEventHandler()->ProcessEvent( event
);
1848 void wxGenericTreeCtrl::SelectItem(const wxTreeItemId
& itemId
, bool select
)
1852 DoSelectItem(itemId
);
1856 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1857 wxCHECK_RET( item
, wxT("SelectItem(): invalid tree item") );
1859 item
->SetHilight(FALSE
);
1864 void wxGenericTreeCtrl::FillArray(wxGenericTreeItem
*item
,
1865 wxArrayTreeItemIds
&array
) const
1867 if ( item
->IsSelected() )
1868 array
.Add(wxTreeItemId(item
));
1870 if ( item
->HasChildren() )
1872 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1873 size_t count
= children
.GetCount();
1874 for ( size_t n
= 0; n
< count
; ++n
)
1875 FillArray(children
[n
], array
);
1879 size_t wxGenericTreeCtrl::GetSelections(wxArrayTreeItemIds
&array
) const
1882 wxTreeItemId idRoot
= GetRootItem();
1883 if ( idRoot
.IsOk() )
1885 FillArray((wxGenericTreeItem
*) idRoot
.m_pItem
, array
);
1887 //else: the tree is empty, so no selections
1889 return array
.Count();
1892 void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
1894 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1896 if (!item
.IsOk()) return;
1898 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1900 // first expand all parent branches
1901 wxGenericTreeItem
*parent
= gitem
->GetParent();
1903 if ( HasFlag(wxTR_HIDE_ROOT
) )
1905 while ( parent
&& parent
!= m_anchor
)
1908 parent
= parent
->GetParent();
1916 parent
= parent
->GetParent();
1920 //if (parent) CalculatePositions();
1925 void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId
&item
)
1927 if (!item
.IsOk()) return;
1929 // We have to call this here because the label in
1930 // question might just have been added and no screen
1931 // update taken place.
1933 #if defined( __WXMSW__ ) || defined(__WXMAC__)
1938 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1940 // now scroll to the item
1941 int item_y
= gitem
->GetY();
1945 GetViewStart( &start_x
, &start_y
);
1946 start_y
*= PIXELS_PER_UNIT
;
1950 GetClientSize( &client_w
, &client_h
);
1952 if (item_y
< start_y
+3)
1957 m_anchor
->GetSize( x
, y
, this );
1958 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1959 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1960 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1961 // Item should appear at top
1962 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
1964 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
1969 m_anchor
->GetSize( x
, y
, this );
1970 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1971 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1972 item_y
+= PIXELS_PER_UNIT
+2;
1973 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1974 // Item should appear at bottom
1975 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
);
1979 // FIXME: tree sorting functions are not reentrant and not MT-safe!
1980 static wxGenericTreeCtrl
*s_treeBeingSorted
= NULL
;
1982 static int LINKAGEMODE
tree_ctrl_compare_func(wxGenericTreeItem
**item1
,
1983 wxGenericTreeItem
**item2
)
1985 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxGenericTreeCtrl::SortChildren()") );
1987 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
1990 int wxGenericTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
1991 const wxTreeItemId
& item2
)
1993 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
1996 void wxGenericTreeCtrl::SortChildren(const wxTreeItemId
& itemId
)
1998 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
2000 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
2002 wxCHECK_RET( !s_treeBeingSorted
,
2003 wxT("wxGenericTreeCtrl::SortChildren is not reentrant") );
2005 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2006 if ( children
.Count() > 1 )
2010 s_treeBeingSorted
= this;
2011 children
.Sort(tree_ctrl_compare_func
);
2012 s_treeBeingSorted
= NULL
;
2014 //else: don't make the tree dirty as nothing changed
2017 wxImageList
*wxGenericTreeCtrl::GetImageList() const
2019 return m_imageListNormal
;
2022 wxImageList
*wxGenericTreeCtrl::GetButtonsImageList() const
2024 return m_imageListButtons
;
2027 wxImageList
*wxGenericTreeCtrl::GetStateImageList() const
2029 return m_imageListState
;
2032 void wxGenericTreeCtrl::CalculateLineHeight()
2034 wxClientDC
dc(this);
2035 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
2037 if ( m_imageListNormal
)
2039 // Calculate a m_lineHeight value from the normal Image sizes.
2040 // May be toggle off. Then wxGenericTreeCtrl will spread when
2041 // necessary (which might look ugly).
2042 int n
= m_imageListNormal
->GetImageCount();
2043 for (int i
= 0; i
< n
; i
++)
2045 int width
= 0, height
= 0;
2046 m_imageListNormal
->GetSize(i
, width
, height
);
2047 if (height
> m_lineHeight
) m_lineHeight
= height
;
2051 if (m_imageListButtons
)
2053 // Calculate a m_lineHeight value from the Button image sizes.
2054 // May be toggle off. Then wxGenericTreeCtrl will spread when
2055 // necessary (which might look ugly).
2056 int n
= m_imageListButtons
->GetImageCount();
2057 for (int i
= 0; i
< n
; i
++)
2059 int width
= 0, height
= 0;
2060 m_imageListButtons
->GetSize(i
, width
, height
);
2061 if (height
> m_lineHeight
) m_lineHeight
= height
;
2065 if (m_lineHeight
< 30)
2066 m_lineHeight
+= 2; // at least 2 pixels
2068 m_lineHeight
+= m_lineHeight
/10; // otherwise 10% extra spacing
2071 void wxGenericTreeCtrl::SetImageList(wxImageList
*imageList
)
2073 if (m_ownsImageListNormal
) delete m_imageListNormal
;
2074 m_imageListNormal
= imageList
;
2075 m_ownsImageListNormal
= FALSE
;
2077 // Don't do any drawing if we're setting the list to NULL,
2078 // since we may be in the process of deleting the tree control.
2080 CalculateLineHeight();
2083 void wxGenericTreeCtrl::SetStateImageList(wxImageList
*imageList
)
2085 if (m_ownsImageListState
) delete m_imageListState
;
2086 m_imageListState
= imageList
;
2087 m_ownsImageListState
= FALSE
;
2090 void wxGenericTreeCtrl::SetButtonsImageList(wxImageList
*imageList
)
2092 if (m_ownsImageListButtons
) delete m_imageListButtons
;
2093 m_imageListButtons
= imageList
;
2094 m_ownsImageListButtons
= FALSE
;
2096 CalculateLineHeight();
2099 void wxGenericTreeCtrl::AssignImageList(wxImageList
*imageList
)
2101 SetImageList(imageList
);
2102 m_ownsImageListNormal
= TRUE
;
2105 void wxGenericTreeCtrl::AssignStateImageList(wxImageList
*imageList
)
2107 SetStateImageList(imageList
);
2108 m_ownsImageListState
= TRUE
;
2111 void wxGenericTreeCtrl::AssignButtonsImageList(wxImageList
*imageList
)
2113 SetButtonsImageList(imageList
);
2114 m_ownsImageListButtons
= TRUE
;
2117 // -----------------------------------------------------------------------------
2119 // -----------------------------------------------------------------------------
2121 void wxGenericTreeCtrl::AdjustMyScrollbars()
2126 m_anchor
->GetSize( x
, y
, this );
2127 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2128 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2129 int x_pos
= GetScrollPos( wxHORIZONTAL
);
2130 int y_pos
= GetScrollPos( wxVERTICAL
);
2131 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
2135 SetScrollbars( 0, 0, 0, 0 );
2139 int wxGenericTreeCtrl::GetLineHeight(wxGenericTreeItem
*item
) const
2141 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
2142 return item
->GetHeight();
2144 return m_lineHeight
;
2147 void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem
*item
, wxDC
& dc
)
2149 // TODO implement "state" icon on items
2151 wxTreeItemAttr
*attr
= item
->GetAttributes();
2152 if ( attr
&& attr
->HasFont() )
2153 dc
.SetFont(attr
->GetFont());
2154 else if (item
->IsBold())
2155 dc
.SetFont(m_boldFont
);
2157 long text_w
= 0, text_h
= 0;
2158 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
2160 int image_h
= 0, image_w
= 0;
2161 int image
= item
->GetCurrentImage();
2162 if ( image
!= NO_IMAGE
)
2164 if ( m_imageListNormal
)
2166 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
2175 int total_h
= GetLineHeight(item
);
2177 if ( item
->IsSelected() )
2179 // under mac selections are only a rectangle in case they don't have the focus
2183 dc
.SetBrush( *wxTRANSPARENT_BRUSH
) ;
2184 dc
.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
) , 1 , wxSOLID
) ) ;
2188 dc
.SetBrush( *m_hilightBrush
) ;
2191 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
2197 if ( attr
&& attr
->HasBackgroundColour() )
2198 colBg
= attr
->GetBackgroundColour();
2200 colBg
= m_backgroundColour
;
2201 dc
.SetBrush(wxBrush(colBg
, wxSOLID
));
2204 int offset
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0;
2206 if ( HasFlag(wxTR_FULL_ROW_HIGHLIGHT
) )
2210 DoGetPosition(&x
, &y
);
2212 dc
.DrawRectangle(x
, item
->GetY()+offset
, w
, total_h
-offset
);
2216 if ( item
->IsSelected() && image
!= NO_IMAGE
)
2218 // If it's selected, and there's an image, then we should
2219 // take care to leave the area under the image painted in the
2220 // background colour.
2221 dc
.DrawRectangle( item
->GetX() + image_w
- 2, item
->GetY()+offset
,
2222 item
->GetWidth() - image_w
+ 2, total_h
-offset
);
2226 dc
.DrawRectangle( item
->GetX()-2, item
->GetY()+offset
,
2227 item
->GetWidth()+2, total_h
-offset
);
2231 if ( image
!= NO_IMAGE
)
2233 dc
.SetClippingRegion( item
->GetX(), item
->GetY(), image_w
-2, total_h
);
2234 m_imageListNormal
->Draw( image
, dc
,
2236 item
->GetY() +((total_h
> image_h
)?((total_h
-image_h
)/2):0),
2237 wxIMAGELIST_DRAW_TRANSPARENT
);
2238 dc
.DestroyClippingRegion();
2241 dc
.SetBackgroundMode(wxTRANSPARENT
);
2242 int extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
2243 dc
.DrawText( item
->GetText(),
2244 (wxCoord
)(image_w
+ item
->GetX()),
2245 (wxCoord
)(item
->GetY() + extraH
));
2247 // restore normal font
2248 dc
.SetFont( m_normalFont
);
2251 // Now y stands for the top of the item, whereas it used to stand for middle !
2252 void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
2254 int x
= level
*m_indent
;
2255 if (!HasFlag(wxTR_HIDE_ROOT
))
2259 else if (level
== 0)
2261 // always expand hidden root
2263 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2264 int count
= children
.Count();
2270 PaintLevel(children
[n
], dc
, 1, y
);
2271 } while (++n
< count
);
2273 if (!HasFlag(wxTR_NO_LINES
) && HasFlag(wxTR_LINES_AT_ROOT
) && count
> 0)
2275 // draw line down to last child
2276 origY
+= GetLineHeight(children
[0])>>1;
2277 oldY
+= GetLineHeight(children
[n
-1])>>1;
2278 dc
.DrawLine(3, origY
, 3, oldY
);
2284 item
->SetX(x
+m_spacing
);
2287 int h
= GetLineHeight(item
);
2289 int y_mid
= y_top
+ (h
>>1);
2292 int exposed_x
= dc
.LogicalToDeviceX(0);
2293 int exposed_y
= dc
.LogicalToDeviceY(y_top
);
2295 if (IsExposed(exposed_x
, exposed_y
, 10000, h
)) // 10000 = very much
2299 // don't draw rect outline if we already have the
2300 // background color under Mac
2301 (item
->IsSelected() && m_hasFocus
) ? wxBLACK_PEN
:
2302 #endif // !__WXMAC__
2306 if ( item
->IsSelected() )
2308 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
2312 wxTreeItemAttr
*attr
= item
->GetAttributes();
2313 if (attr
&& attr
->HasTextColour())
2314 colText
= attr
->GetTextColour();
2316 colText
= GetForegroundColour();
2320 dc
.SetTextForeground(colText
);
2324 PaintItem(item
, dc
);
2326 if (HasFlag(wxTR_ROW_LINES
))
2328 // if the background colour is white, choose a
2329 // contrasting color for the lines
2330 dc
.SetPen(*((GetBackgroundColour() == *wxWHITE
)
2331 ? wxMEDIUM_GREY_PEN
: wxWHITE_PEN
));
2332 dc
.DrawLine(0, y_top
, 10000, y_top
);
2333 dc
.DrawLine(0, y
, 10000, y
);
2336 // restore DC objects
2337 dc
.SetBrush(*wxWHITE_BRUSH
);
2338 dc
.SetPen(m_dottedPen
);
2339 dc
.SetTextForeground(*wxBLACK
);
2341 if ( !HasFlag(wxTR_NO_LINES
) )
2343 // draw the horizontal line here
2345 if (x
> (signed)m_indent
)
2346 x_start
-= m_indent
;
2347 else if (HasFlag(wxTR_LINES_AT_ROOT
))
2349 dc
.DrawLine(x_start
, y_mid
, x
+ m_spacing
, y_mid
);
2352 // should the item show a button?
2353 if ( item
->HasPlus() && HasButtons() )
2355 if ( m_imageListButtons
)
2357 // draw the image button here
2360 int image
= item
->IsExpanded() ? wxTreeItemIcon_Expanded
2361 : wxTreeItemIcon_Normal
;
2362 if ( item
->IsSelected() )
2363 image
+= wxTreeItemIcon_Selected
- wxTreeItemIcon_Normal
;
2365 m_imageListButtons
->GetSize(image
, image_w
, image_h
);
2366 int xx
= x
- image_w
/2;
2367 int yy
= y_mid
- image_h
/2;
2369 wxDCClipper
clip(dc
, xx
, yy
, image_w
, image_h
);
2370 m_imageListButtons
->Draw(image
, dc
, xx
, yy
,
2371 wxIMAGELIST_DRAW_TRANSPARENT
);
2373 else // no custom buttons
2375 static const int wImage
= 9;
2376 static const int hImage
= 9;
2379 if (item
->IsExpanded())
2380 flag
|= wxCONTROL_EXPANDED
;
2381 if (item
== m_underMouse
)
2382 flag
|= wxCONTROL_CURRENT
;
2384 wxRendererNative::Get().DrawTreeItemButton
2388 wxRect(x
- wImage
/2,
2397 if (item
->IsExpanded())
2399 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2400 int count
= children
.Count();
2407 PaintLevel(children
[n
], dc
, level
, y
);
2408 } while (++n
< count
);
2410 if (!HasFlag(wxTR_NO_LINES
) && count
> 0)
2412 // draw line down to last child
2413 oldY
+= GetLineHeight(children
[n
-1])>>1;
2414 if (HasButtons()) y_mid
+= 5;
2416 // Only draw the portion of the line that is visible, in case it is huge
2417 wxCoord xOrigin
=0, yOrigin
=0, width
, height
;
2418 dc
.GetDeviceOrigin(&xOrigin
, &yOrigin
);
2419 yOrigin
= abs(yOrigin
);
2420 GetClientSize(&width
, &height
);
2422 // Move end points to the begining/end of the view?
2423 if (y_mid
< yOrigin
)
2425 if (oldY
> yOrigin
+ height
)
2426 oldY
= yOrigin
+ height
;
2428 // after the adjustments if y_mid is larger than oldY then the line
2429 // isn't visible at all so don't draw anything
2431 dc
.DrawLine(x
, y_mid
, x
, oldY
);
2437 void wxGenericTreeCtrl::DrawDropEffect(wxGenericTreeItem
*item
)
2441 if ( item
->HasPlus() )
2443 // it's a folder, indicate it by a border
2448 // draw a line under the drop target because the item will be
2450 DrawLine(item
, TRUE
/* below */);
2453 SetCursor(wxCURSOR_BULLSEYE
);
2458 SetCursor(wxCURSOR_NO_ENTRY
);
2462 void wxGenericTreeCtrl::DrawBorder(const wxTreeItemId
&item
)
2464 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2466 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2468 wxClientDC
dc(this);
2470 dc
.SetLogicalFunction(wxINVERT
);
2471 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2473 int w
= i
->GetWidth() + 2;
2474 int h
= GetLineHeight(i
) + 2;
2476 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
2479 void wxGenericTreeCtrl::DrawLine(const wxTreeItemId
&item
, bool below
)
2481 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2483 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2485 wxClientDC
dc(this);
2487 dc
.SetLogicalFunction(wxINVERT
);
2493 y
+= GetLineHeight(i
) - 1;
2496 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
2499 // -----------------------------------------------------------------------------
2500 // wxWidgets callbacks
2501 // -----------------------------------------------------------------------------
2503 void wxGenericTreeCtrl::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2511 dc
.SetFont( m_normalFont
);
2512 dc
.SetPen( m_dottedPen
);
2514 // this is now done dynamically
2515 //if(GetImageList() == NULL)
2516 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
2519 PaintLevel( m_anchor
, dc
, 0, y
);
2522 void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent
&event
)
2531 void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent
&event
)
2540 void wxGenericTreeCtrl::OnChar( wxKeyEvent
&event
)
2542 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, GetId() );
2543 te
.m_evtKey
= event
;
2544 te
.SetEventObject( this );
2545 if ( GetEventHandler()->ProcessEvent( te
) )
2547 // intercepted by the user code
2551 if ( (m_current
== 0) || (m_key_current
== 0) )
2557 // how should the selection work for this event?
2558 bool is_multiple
, extended_select
, unselect_others
;
2559 EventFlagsToSelType(GetWindowStyleFlag(),
2561 event
.ControlDown(),
2562 is_multiple
, extended_select
, unselect_others
);
2566 // * : Expand all/Collapse all
2567 // ' ' | return : activate
2568 // up : go up (not last children!)
2570 // left : go to parent
2571 // right : open if parent and go next
2572 // home : go to root
2573 // end : go to last item without opening parents
2574 // alnum : start or continue searching for the item with this prefix
2575 int keyCode
= event
.GetKeyCode();
2580 if (m_current
->HasPlus() && !IsExpanded(m_current
))
2588 if ( !IsExpanded(m_current
) )
2591 ExpandAll(m_current
);
2594 //else: fall through to Collapse() it
2598 if (IsExpanded(m_current
))
2600 Collapse(m_current
);
2606 if ( !event
.HasModifiers() )
2608 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
2609 event
.m_item
= m_current
;
2610 event
.SetEventObject( this );
2611 GetEventHandler()->ProcessEvent( event
);
2614 // in any case, also generate the normal key event for this key,
2615 // even if we generated the ACTIVATED event above: this is what
2616 // wxMSW does and it makes sense because you might not want to
2617 // process ACTIVATED event at all and handle Space and Return
2618 // directly (and differently) which would be impossible otherwise
2622 // up goes to the previous sibling or to the last
2623 // of its children if it's expanded
2626 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
2629 prev
= GetItemParent( m_key_current
);
2630 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2632 break; // don't go to root if it is hidden
2636 wxTreeItemIdValue cookie
;
2637 wxTreeItemId current
= m_key_current
;
2638 // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be?
2639 if (current
== GetFirstChild( prev
, cookie
))
2641 // otherwise we return to where we came from
2642 DoSelectItem( prev
, unselect_others
, extended_select
);
2643 m_key_current
= (wxGenericTreeItem
*) prev
.m_pItem
;
2650 while ( IsExpanded(prev
) && HasChildren(prev
) )
2652 wxTreeItemId child
= GetLastChild(prev
);
2659 DoSelectItem( prev
, unselect_others
, extended_select
);
2660 m_key_current
=(wxGenericTreeItem
*) prev
.m_pItem
;
2665 // left arrow goes to the parent
2668 wxTreeItemId prev
= GetItemParent( m_current
);
2669 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2671 // don't go to root if it is hidden
2672 prev
= GetPrevSibling( m_current
);
2676 DoSelectItem( prev
, unselect_others
, extended_select
);
2682 // this works the same as the down arrow except that we
2683 // also expand the item if it wasn't expanded yet
2689 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
2691 wxTreeItemIdValue cookie
;
2692 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
2693 DoSelectItem( child
, unselect_others
, extended_select
);
2694 m_key_current
=(wxGenericTreeItem
*) child
.m_pItem
;
2698 wxTreeItemId next
= GetNextSibling( m_key_current
);
2701 wxTreeItemId current
= m_key_current
;
2702 while (current
.IsOk() && !next
)
2704 current
= GetItemParent( current
);
2705 if (current
) next
= GetNextSibling( current
);
2710 DoSelectItem( next
, unselect_others
, extended_select
);
2711 m_key_current
=(wxGenericTreeItem
*) next
.m_pItem
;
2717 // <End> selects the last visible tree item
2720 wxTreeItemId last
= GetRootItem();
2722 while ( last
.IsOk() && IsExpanded(last
) )
2724 wxTreeItemId lastChild
= GetLastChild(last
);
2726 // it may happen if the item was expanded but then all of
2727 // its children have been deleted - so IsExpanded() returned
2728 // TRUE, but GetLastChild() returned invalid item
2737 DoSelectItem( last
, unselect_others
, extended_select
);
2742 // <Home> selects the root item
2745 wxTreeItemId prev
= GetRootItem();
2749 if ( HasFlag(wxTR_HIDE_ROOT
) )
2751 wxTreeItemIdValue cookie
;
2752 prev
= GetFirstChild(prev
, cookie
);
2757 DoSelectItem( prev
, unselect_others
, extended_select
);
2762 // do not use wxIsalnum() here
2763 if ( !event
.HasModifiers() &&
2764 ((keyCode
>= '0' && keyCode
<= '9') ||
2765 (keyCode
>= 'a' && keyCode
<= 'z') ||
2766 (keyCode
>= 'A' && keyCode
<= 'Z' )))
2768 // find the next item starting with the given prefix
2769 char ch
= (char)keyCode
;
2771 wxTreeItemId id
= FindItem(m_current
, m_findPrefix
+ (wxChar
)ch
);
2782 // also start the timer to reset the current prefix if the user
2783 // doesn't press any more alnum keys soon -- we wouldn't want
2784 // to use this prefix for a new item search
2787 m_findTimer
= new wxTreeFindTimer(this);
2790 m_findTimer
->Start(wxTreeFindTimer::DELAY
, wxTIMER_ONE_SHOT
);
2799 wxTreeItemId
wxGenericTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
2801 // JACS: removed wxYieldIfNeeded() because it can cause the window
2802 // to be deleted from under us if a close window event is pending
2807 if (point
.x
<0) flags
|= wxTREE_HITTEST_TOLEFT
;
2808 if (point
.x
>w
) flags
|= wxTREE_HITTEST_TORIGHT
;
2809 if (point
.y
<0) flags
|= wxTREE_HITTEST_ABOVE
;
2810 if (point
.y
>h
) flags
|= wxTREE_HITTEST_BELOW
;
2811 if (flags
) return wxTreeItemId();
2813 if (m_anchor
== NULL
)
2815 flags
= wxTREE_HITTEST_NOWHERE
;
2816 return wxTreeItemId();
2819 wxGenericTreeItem
*hit
= m_anchor
->HitTest(CalcUnscrolledPosition(point
),
2823 flags
= wxTREE_HITTEST_NOWHERE
;
2824 return wxTreeItemId();
2829 // get the bounding rectangle of the item (or of its label only)
2830 bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId
& item
,
2832 bool WXUNUSED(textOnly
)) const
2834 wxCHECK_MSG( item
.IsOk(), FALSE
, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
2836 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2839 GetViewStart(& startX
, & startY
);
2841 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
2842 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
2843 rect
.width
= i
->GetWidth();
2844 //rect.height = i->GetHeight();
2845 rect
.height
= GetLineHeight(i
);
2850 void wxGenericTreeCtrl::Edit( const wxTreeItemId
& item
)
2852 wxCHECK_RET( item
.IsOk(), _T("can't edit an invalid item") );
2854 wxGenericTreeItem
*itemEdit
= (wxGenericTreeItem
*)item
.m_pItem
;
2856 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, GetId() );
2857 te
.m_item
= itemEdit
;
2858 te
.SetEventObject( this );
2859 if ( GetEventHandler()->ProcessEvent( te
) && !te
.IsAllowed() )
2865 // We have to call this here because the label in
2866 // question might just have been added and no screen
2867 // update taken place.
2869 #if defined( __WXMSW__ ) || defined(__WXMAC__)
2875 m_textCtrl
= new wxTreeTextCtrl(this, itemEdit
);
2877 m_textCtrl
->SetFocus();
2880 // returns a pointer to the text edit control if the item is being
2881 // edited, NULL otherwise (it's assumed that no more than one item may
2882 // be edited simultaneously)
2883 wxTextCtrl
* wxGenericTreeCtrl::GetEditControl() const
2888 bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem
*item
,
2889 const wxString
& value
)
2891 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2893 le
.SetEventObject( this );
2895 le
.m_editCancelled
= FALSE
;
2897 return !GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2900 void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem
*item
)
2902 // let owner know that the edit was cancelled
2903 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2905 le
.SetEventObject( this );
2906 le
.m_label
= wxEmptyString
;
2907 le
.m_editCancelled
= TRUE
;
2909 GetEventHandler()->ProcessEvent( le
);
2915 void wxGenericTreeCtrl::OnRenameTimer()
2920 void wxGenericTreeCtrl::OnMouse( wxMouseEvent
&event
)
2922 if ( !m_anchor
) return;
2924 wxPoint pt
= CalcUnscrolledPosition(event
.GetPosition());
2926 // Is the mouse over a tree item button?
2928 wxGenericTreeItem
*thisItem
= m_anchor
->HitTest(pt
, this, flags
, 0);
2929 wxGenericTreeItem
*underMouse
= thisItem
;
2931 bool underMouseChanged
= (underMouse
!= m_underMouse
) ;
2932 #endif // wxUSE_TOOLTIPS
2935 (flags
& wxTREE_HITTEST_ONITEMBUTTON
) &&
2936 (!event
.LeftIsDown()) &&
2938 (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2946 if (underMouse
!= m_underMouse
)
2950 // unhighlight old item
2951 wxGenericTreeItem
*tmp
= m_underMouse
;
2952 m_underMouse
= NULL
;
2956 m_underMouse
= underMouse
;
2958 RefreshLine( m_underMouse
);
2962 // Determines what item we are hovering over and need a tooltip for
2963 wxTreeItemId hoverItem
= thisItem
;
2965 // We do not want a tooltip if we are dragging, or if the rename timer is running
2966 if (underMouseChanged
&& hoverItem
.IsOk() && !m_isDragging
&& (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2968 // Ask the tree control what tooltip (if any) should be shown
2969 wxTreeEvent
hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP
, GetId());
2970 hevent
.m_item
= hoverItem
;
2971 hevent
.SetEventObject(this);
2973 if ( GetEventHandler()->ProcessEvent(hevent
) && hevent
.IsAllowed() )
2975 SetToolTip(hevent
.m_label
);
2980 // we process left mouse up event (enables in-place edit), right down
2981 // (pass to the user code), left dbl click (activate item) and
2982 // dragging/moving events for items drag-and-drop
2983 if ( !(event
.LeftDown() ||
2985 event
.RightDown() ||
2986 event
.LeftDClick() ||
2988 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
2997 wxGenericTreeItem
*item
= m_anchor
->HitTest(pt
, this, flags
, 0);
2999 if ( event
.Dragging() && !m_isDragging
)
3001 if (m_dragCount
== 0)
3006 if (m_dragCount
!= 3)
3008 // wait until user drags a bit further...
3012 wxEventType command
= event
.RightIsDown()
3013 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
3014 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
3016 wxTreeEvent
nevent( command
, GetId() );
3017 nevent
.m_item
= m_current
;
3018 nevent
.SetEventObject(this);
3020 // by default the dragging is not supported, the user code must
3021 // explicitly allow the event for it to take place
3024 if ( GetEventHandler()->ProcessEvent(nevent
) && nevent
.IsAllowed() )
3026 // we're going to drag this item
3027 m_isDragging
= TRUE
;
3029 // remember the old cursor because we will change it while
3031 m_oldCursor
= m_cursor
;
3033 // in a single selection control, hide the selection temporarily
3034 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
3036 m_oldSelection
= (wxGenericTreeItem
*) GetSelection().m_pItem
;
3038 if ( m_oldSelection
)
3040 m_oldSelection
->SetHilight(FALSE
);
3041 RefreshLine(m_oldSelection
);
3048 else if ( event
.Moving() )
3050 if ( item
!= m_dropTarget
)
3052 // unhighlight the previous drop target
3053 DrawDropEffect(m_dropTarget
);
3055 m_dropTarget
= item
;
3057 // highlight the current drop target if any
3058 DrawDropEffect(m_dropTarget
);
3060 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3067 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
3069 // erase the highlighting
3070 DrawDropEffect(m_dropTarget
);
3072 if ( m_oldSelection
)
3074 m_oldSelection
->SetHilight(TRUE
);
3075 RefreshLine(m_oldSelection
);
3076 m_oldSelection
= (wxGenericTreeItem
*)NULL
;
3079 // generate the drag end event
3080 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
, GetId());
3082 event
.m_item
= item
;
3083 event
.m_pointDrag
= pt
;
3084 event
.SetEventObject(this);
3086 (void)GetEventHandler()->ProcessEvent(event
);
3088 m_isDragging
= FALSE
;
3089 m_dropTarget
= (wxGenericTreeItem
*)NULL
;
3093 SetCursor(m_oldCursor
);
3095 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3103 // here we process only the messages which happen on tree items
3107 if (item
== NULL
) return; /* we hit the blank area */
3109 if ( event
.RightDown() )
3111 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
, GetId());
3112 nevent
.m_item
= item
;
3113 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3114 nevent
.SetEventObject(this);
3115 GetEventHandler()->ProcessEvent(nevent
);
3117 else if ( event
.LeftUp() )
3119 // this facilitates multiple-item drag-and-drop
3121 if (item
&& HasFlag(wxTR_MULTIPLE
))
3123 wxArrayTreeItemIds selections
;
3124 size_t count
= GetSelections(selections
);
3127 !event
.ControlDown() &&
3130 DoSelectItem(item
, true, false);
3136 if ( (item
== m_current
) &&
3137 (flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
3138 HasFlag(wxTR_EDIT_LABELS
) )
3140 if ( m_renameTimer
)
3142 if ( m_renameTimer
->IsRunning() )
3143 m_renameTimer
->Stop();
3147 m_renameTimer
= new wxTreeRenameTimer( this );
3150 m_renameTimer
->Start( wxTreeRenameTimer::DELAY
, TRUE
);
3153 m_lastOnSame
= FALSE
;
3156 else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
3158 if ( event
.LeftDown() )
3160 m_lastOnSame
= item
== m_current
;
3163 if ( flags
& wxTREE_HITTEST_ONITEMBUTTON
)
3165 // only toggle the item for a single click, double click on
3166 // the button doesn't do anything (it toggles the item twice)
3167 if ( event
.LeftDown() )
3172 // don't select the item if the button was clicked
3177 // clear the previously selected items, if the
3178 // user clicked outside of the present selection.
3179 // otherwise, perform the deselection on mouse-up.
3180 // this allows multiple drag and drop to work.
3182 if (!IsSelected(item
))
3184 // how should the selection work for this event?
3185 bool is_multiple
, extended_select
, unselect_others
;
3186 EventFlagsToSelType(GetWindowStyleFlag(),
3188 event
.ControlDown(),
3189 is_multiple
, extended_select
, unselect_others
);
3191 DoSelectItem(item
, unselect_others
, extended_select
);
3195 // For some reason, Windows isn't recognizing a left double-click,
3196 // so we need to simulate it here. Allow 200 milliseconds for now.
3197 if ( event
.LeftDClick() )
3199 // double clicking should not start editing the item label
3200 if ( m_renameTimer
)
3201 m_renameTimer
->Stop();
3203 m_lastOnSame
= FALSE
;
3205 // send activate event first
3206 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
3207 nevent
.m_item
= item
;
3208 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3209 nevent
.SetEventObject( this );
3210 if ( !GetEventHandler()->ProcessEvent( nevent
) )
3212 // if the user code didn't process the activate event,
3213 // handle it ourselves by toggling the item when it is
3215 if ( item
->HasPlus() )
3225 void wxGenericTreeCtrl::OnInternalIdle()
3227 wxWindow::OnInternalIdle();
3229 // Check if we need to select the root item
3230 // because nothing else has been selected.
3231 // Delaying it means that we can invoke event handlers
3232 // as required, when a first item is selected.
3233 if (!HasFlag(wxTR_MULTIPLE
) && !GetSelection().IsOk())
3236 SelectItem(m_select_me
);
3237 else if (GetRootItem().IsOk())
3238 SelectItem(GetRootItem());
3241 /* after all changes have been done to the tree control,
3242 * we actually redraw the tree when everything is over */
3244 if (!m_dirty
) return;
3245 if (m_freezeCount
) return;
3249 CalculatePositions();
3251 AdjustMyScrollbars();
3254 void wxGenericTreeCtrl::CalculateSize( wxGenericTreeItem
*item
, wxDC
&dc
)
3259 wxTreeItemAttr
*attr
= item
->GetAttributes();
3260 if ( attr
&& attr
->HasFont() )
3261 dc
.SetFont(attr
->GetFont());
3262 else if ( item
->IsBold() )
3263 dc
.SetFont(m_boldFont
);
3265 dc
.SetFont(m_normalFont
);
3267 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
3270 // restore normal font
3271 dc
.SetFont( m_normalFont
);
3275 int image
= item
->GetCurrentImage();
3276 if ( image
!= NO_IMAGE
)
3278 if ( m_imageListNormal
)
3280 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
3285 int total_h
= (image_h
> text_h
) ? image_h
: text_h
;
3288 total_h
+= 2; // at least 2 pixels
3290 total_h
+= total_h
/10; // otherwise 10% extra spacing
3292 item
->SetHeight(total_h
);
3293 if (total_h
>m_lineHeight
)
3294 m_lineHeight
=total_h
;
3296 item
->SetWidth(image_w
+text_w
+2);
3299 // -----------------------------------------------------------------------------
3300 // for developper : y is now the top of the level
3301 // not the middle of it !
3302 void wxGenericTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
3304 int x
= level
*m_indent
;
3305 if (!HasFlag(wxTR_HIDE_ROOT
))
3309 else if (level
== 0)
3311 // a hidden root is not evaluated, but its
3312 // children are always calculated
3316 CalculateSize( item
, dc
);
3319 item
->SetX( x
+m_spacing
);
3321 y
+= GetLineHeight(item
);
3323 if ( !item
->IsExpanded() )
3325 // we don't need to calculate collapsed branches
3330 wxArrayGenericTreeItems
& children
= item
->GetChildren();
3331 size_t n
, count
= children
.Count();
3333 for (n
= 0; n
< count
; ++n
)
3334 CalculateLevel( children
[n
], dc
, level
, y
); // recurse
3337 void wxGenericTreeCtrl::CalculatePositions()
3339 if ( !m_anchor
) return;
3341 wxClientDC
dc(this);
3344 dc
.SetFont( m_normalFont
);
3346 dc
.SetPen( m_dottedPen
);
3347 //if(GetImageList() == NULL)
3348 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
3351 CalculateLevel( m_anchor
, dc
, 0, y
); // start recursion
3354 void wxGenericTreeCtrl::RefreshSubtree(wxGenericTreeItem
*item
)
3356 if (m_dirty
) return;
3357 if (m_freezeCount
) return;
3359 wxSize client
= GetClientSize();
3362 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3363 rect
.width
= client
.x
;
3364 rect
.height
= client
.y
;
3366 Refresh(TRUE
, &rect
);
3368 AdjustMyScrollbars();
3371 void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
3373 if (m_dirty
) return;
3374 if (m_freezeCount
) return;
3377 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3378 rect
.width
= GetClientSize().x
;
3379 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
3381 Refresh(TRUE
, &rect
);
3384 void wxGenericTreeCtrl::RefreshSelected()
3386 if (m_freezeCount
) return;
3388 // TODO: this is awfully inefficient, we should keep the list of all
3389 // selected items internally, should be much faster
3391 RefreshSelectedUnder(m_anchor
);
3394 void wxGenericTreeCtrl::RefreshSelectedUnder(wxGenericTreeItem
*item
)
3396 if (m_freezeCount
) return;
3398 if ( item
->IsSelected() )
3401 const wxArrayGenericTreeItems
& children
= item
->GetChildren();
3402 size_t count
= children
.GetCount();
3403 for ( size_t n
= 0; n
< count
; n
++ )
3405 RefreshSelectedUnder(children
[n
]);
3409 void wxGenericTreeCtrl::Freeze()
3414 void wxGenericTreeCtrl::Thaw()
3416 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen tree control?") );
3418 if ( !--m_freezeCount
)
3424 // ----------------------------------------------------------------------------
3425 // changing colours: we need to refresh the tree control
3426 // ----------------------------------------------------------------------------
3428 bool wxGenericTreeCtrl::SetBackgroundColour(const wxColour
& colour
)
3430 if ( !wxWindow::SetBackgroundColour(colour
) )
3433 if (m_freezeCount
) return TRUE
;
3440 bool wxGenericTreeCtrl::SetForegroundColour(const wxColour
& colour
)
3442 if ( !wxWindow::SetForegroundColour(colour
) )
3445 if (m_freezeCount
) return TRUE
;
3452 // Process the tooltip event, to speed up event processing.
3453 // Doesn't actually get a tooltip.
3454 void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent
&event
)
3460 // NOTE: If using the wxListBox visual attributes works everywhere then this can
3461 // be removed, as well as the #else case below.
3462 #define _USE_VISATTR 0
3465 #include "wx/listbox.h"
3471 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
3473 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3477 // Use the same color scheme as wxListBox
3478 return wxListBox::GetClassDefaultAttributes(variant
);
3480 wxVisualAttributes attr
;
3481 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
3482 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
3483 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
3488 #endif // wxUSE_TREECTRL