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 // Close the text control, changes were accepted
415 // else do nothing, do not accept and do not close
421 m_owner
->OnRenameCancelled(m_itemEdited
);
429 void wxTreeTextCtrl::OnKeyUp( wxKeyEvent
&event
)
433 // auto-grow the textctrl:
434 wxSize parentSize
= m_owner
->GetSize();
435 wxPoint myPos
= GetPosition();
436 wxSize mySize
= GetSize();
438 GetTextExtent(GetValue() + _T("M"), &sx
, &sy
);
439 if (myPos
.x
+ sx
> parentSize
.x
)
440 sx
= parentSize
.x
- myPos
.x
;
443 SetSize(sx
, wxDefaultSize
.y
);
449 void wxTreeTextCtrl::OnKillFocus( wxFocusEvent
&event
)
457 if ( AcceptChanges() )
463 // -----------------------------------------------------------------------------
465 // -----------------------------------------------------------------------------
467 wxGenericTreeItem::wxGenericTreeItem(wxGenericTreeItem
*parent
,
468 const wxString
& text
,
469 int image
, int selImage
,
470 wxTreeItemData
*data
)
473 m_images
[wxTreeItemIcon_Normal
] = image
;
474 m_images
[wxTreeItemIcon_Selected
] = selImage
;
475 m_images
[wxTreeItemIcon_Expanded
] = NO_IMAGE
;
476 m_images
[wxTreeItemIcon_SelectedExpanded
] = NO_IMAGE
;
481 m_isCollapsed
= true;
482 m_hasHilight
= false;
488 m_attr
= (wxTreeItemAttr
*)NULL
;
491 // We don't know the height here yet.
496 wxGenericTreeItem::~wxGenericTreeItem()
500 if (m_ownsAttr
) delete m_attr
;
502 wxASSERT_MSG( m_children
.IsEmpty(),
503 wxT("please call DeleteChildren() before deleting the item") );
506 void wxGenericTreeItem::DeleteChildren(wxGenericTreeCtrl
*tree
)
508 size_t count
= m_children
.Count();
509 for ( size_t n
= 0; n
< count
; n
++ )
511 wxGenericTreeItem
*child
= m_children
[n
];
513 tree
->SendDeleteEvent(child
);
515 child
->DeleteChildren(tree
);
522 void wxGenericTreeItem::SetText( const wxString
&text
)
527 size_t wxGenericTreeItem::GetChildrenCount(bool recursively
) const
529 size_t count
= m_children
.Count();
533 size_t total
= count
;
534 for (size_t n
= 0; n
< count
; ++n
)
536 total
+= m_children
[n
]->GetChildrenCount();
542 void wxGenericTreeItem::GetSize( int &x
, int &y
,
543 const wxGenericTreeCtrl
*theButton
)
545 int bottomY
=m_y
+theButton
->GetLineHeight(this);
546 if ( y
< bottomY
) y
= bottomY
;
547 int width
= m_x
+ m_width
;
548 if ( x
< width
) x
= width
;
552 size_t count
= m_children
.Count();
553 for ( size_t n
= 0; n
< count
; ++n
)
555 m_children
[n
]->GetSize( x
, y
, theButton
);
560 wxGenericTreeItem
*wxGenericTreeItem::HitTest(const wxPoint
& point
,
561 const wxGenericTreeCtrl
*theCtrl
,
565 // for a hidden root node, don't evaluate it, but do evaluate children
566 if ( !(level
== 0 && theCtrl
->HasFlag(wxTR_HIDE_ROOT
)) )
569 int h
= theCtrl
->GetLineHeight(this);
570 if ((point
.y
> m_y
) && (point
.y
< m_y
+ h
))
572 int y_mid
= m_y
+ h
/2;
573 if (point
.y
< y_mid
)
574 flags
|= wxTREE_HITTEST_ONITEMUPPERPART
;
576 flags
|= wxTREE_HITTEST_ONITEMLOWERPART
;
578 int xCross
= m_x
- theCtrl
->GetSpacing();
580 // according to the drawing code the triangels are drawn
581 // at -4 , -4 from the position up to +10/+10 max
582 if ((point
.x
> xCross
-4) && (point
.x
< xCross
+10) &&
583 (point
.y
> y_mid
-4) && (point
.y
< y_mid
+10) &&
584 HasPlus() && theCtrl
->HasButtons() )
586 // 5 is the size of the plus sign
587 if ((point
.x
> xCross
-6) && (point
.x
< xCross
+6) &&
588 (point
.y
> y_mid
-6) && (point
.y
< y_mid
+6) &&
589 HasPlus() && theCtrl
->HasButtons() )
592 flags
|= wxTREE_HITTEST_ONITEMBUTTON
;
596 if ((point
.x
>= m_x
) && (point
.x
<= m_x
+m_width
))
601 // assuming every image (normal and selected) has the same size!
602 if ( (GetImage() != NO_IMAGE
) && theCtrl
->m_imageListNormal
)
603 theCtrl
->m_imageListNormal
->GetSize(GetImage(),
606 if ((image_w
!= -1) && (point
.x
<= m_x
+ image_w
+ 1))
607 flags
|= wxTREE_HITTEST_ONITEMICON
;
609 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
615 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
616 if (point
.x
> m_x
+m_width
)
617 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
622 // if children are expanded, fall through to evaluate them
623 if (m_isCollapsed
) return (wxGenericTreeItem
*) NULL
;
627 size_t count
= m_children
.Count();
628 for ( size_t n
= 0; n
< count
; n
++ )
630 wxGenericTreeItem
*res
= m_children
[n
]->HitTest( point
,
638 return (wxGenericTreeItem
*) NULL
;
641 int wxGenericTreeItem::GetCurrentImage() const
643 int image
= NO_IMAGE
;
648 image
= GetImage(wxTreeItemIcon_SelectedExpanded
);
651 if ( image
== NO_IMAGE
)
653 // we usually fall back to the normal item, but try just the
654 // expanded one (and not selected) first in this case
655 image
= GetImage(wxTreeItemIcon_Expanded
);
661 image
= GetImage(wxTreeItemIcon_Selected
);
664 // maybe it doesn't have the specific image we want,
665 // try the default one instead
666 if ( image
== NO_IMAGE
) image
= GetImage();
671 // -----------------------------------------------------------------------------
672 // wxGenericTreeCtrl implementation
673 // -----------------------------------------------------------------------------
675 IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl
, wxScrolledWindow
)
677 BEGIN_EVENT_TABLE(wxGenericTreeCtrl
,wxScrolledWindow
)
678 EVT_PAINT (wxGenericTreeCtrl::OnPaint
)
679 EVT_MOUSE_EVENTS (wxGenericTreeCtrl::OnMouse
)
680 EVT_CHAR (wxGenericTreeCtrl::OnChar
)
681 EVT_SET_FOCUS (wxGenericTreeCtrl::OnSetFocus
)
682 EVT_KILL_FOCUS (wxGenericTreeCtrl::OnKillFocus
)
683 EVT_TREE_ITEM_GETTOOLTIP(wxID_ANY
, wxGenericTreeCtrl::OnGetToolTip
)
686 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
688 * wxTreeCtrl has to be a real class or we have problems with
689 * the run-time information.
692 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxGenericTreeCtrl
)
695 // -----------------------------------------------------------------------------
696 // construction/destruction
697 // -----------------------------------------------------------------------------
699 void wxGenericTreeCtrl::Init()
701 m_current
= m_key_current
= m_anchor
= m_select_me
= (wxGenericTreeItem
*) NULL
;
709 m_hilightBrush
= new wxBrush
711 wxSystemSettings::GetColour
713 wxSYS_COLOUR_HIGHLIGHT
718 m_hilightUnfocusedBrush
= new wxBrush
720 wxSystemSettings::GetColour
722 wxSYS_COLOUR_BTNSHADOW
727 m_imageListNormal
= m_imageListButtons
=
728 m_imageListState
= (wxImageList
*) NULL
;
729 m_ownsImageListNormal
= m_ownsImageListButtons
=
730 m_ownsImageListState
= false;
733 m_isDragging
= false;
734 m_dropTarget
= m_oldSelection
= NULL
;
738 m_renameTimer
= NULL
;
743 m_lastOnSame
= false;
745 #if defined( __WXMAC__ ) && __WXMAC_CARBON__
746 m_normalFont
.MacCreateThemeFont( kThemeViewsFont
) ;
748 m_normalFont
= wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT
);
750 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
751 m_normalFont
.GetFamily(),
752 m_normalFont
.GetStyle(),
754 m_normalFont
.GetUnderlined(),
755 m_normalFont
.GetFaceName(),
756 m_normalFont
.GetEncoding());
759 bool wxGenericTreeCtrl::Create(wxWindow
*parent
,
764 const wxValidator
& wxVALIDATOR_PARAM(validator
),
765 const wxString
& name
)
769 wxGetOsVersion( &major
, &minor
);
771 style
&= ~wxTR_LINES_AT_ROOT
;
772 style
|= wxTR_NO_LINES
;
774 style
|= wxTR_ROW_LINES
;
777 wxScrolledWindow::Create( parent
, id
, pos
, size
,
778 style
|wxHSCROLL
|wxVSCROLL
, name
);
780 // If the tree display has no buttons, but does have
781 // connecting lines, we can use a narrower layout.
782 // It may not be a good idea to force this...
783 if (!HasButtons() && !HasFlag(wxTR_NO_LINES
))
790 SetValidator( validator
);
793 wxVisualAttributes attr
= GetDefaultAttributes();
794 SetDefaultForegroundColour( attr
.colFg
);
795 SetDefaultBackgroundColour( attr
.colBg
);
796 SetDefaultFont(attr
.font
);
798 // m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86
799 m_dottedPen
= wxPen( wxT("grey"), 0, 0 );
806 wxGenericTreeCtrl::~wxGenericTreeCtrl()
808 delete m_hilightBrush
;
809 delete m_hilightUnfocusedBrush
;
813 delete m_renameTimer
;
816 if (m_ownsImageListNormal
)
817 delete m_imageListNormal
;
818 if (m_ownsImageListState
)
819 delete m_imageListState
;
820 if (m_ownsImageListButtons
)
821 delete m_imageListButtons
;
824 // -----------------------------------------------------------------------------
826 // -----------------------------------------------------------------------------
828 size_t wxGenericTreeCtrl::GetCount() const
836 size_t count
= m_anchor
->GetChildrenCount();
837 if ( !HasFlag(wxTR_HIDE_ROOT
) )
839 // take the root itself into account
846 void wxGenericTreeCtrl::SetIndent(unsigned int indent
)
848 m_indent
= (unsigned short) indent
;
852 void wxGenericTreeCtrl::SetSpacing(unsigned int spacing
)
854 m_spacing
= (unsigned short) spacing
;
859 wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
,
860 bool recursively
) const
862 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
864 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
867 void wxGenericTreeCtrl::SetWindowStyle(const long styles
)
869 if (!HasFlag(wxTR_HIDE_ROOT
) && (styles
& wxTR_HIDE_ROOT
))
871 // if we will hide the root, make sure children are visible
872 m_anchor
->SetHasPlus();
874 CalculatePositions();
877 // right now, just sets the styles. Eventually, we may
878 // want to update the inherited styles, but right now
879 // none of the parents has updatable styles
880 m_windowStyle
= styles
;
884 // -----------------------------------------------------------------------------
885 // functions to work with tree items
886 // -----------------------------------------------------------------------------
888 wxString
wxGenericTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
890 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
892 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetText();
895 int wxGenericTreeCtrl::GetItemImage(const wxTreeItemId
& item
,
896 wxTreeItemIcon which
) const
898 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
900 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetImage(which
);
903 wxTreeItemData
*wxGenericTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
905 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
907 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetData();
910 wxColour
wxGenericTreeCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
912 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
914 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
915 return pItem
->Attr().GetTextColour();
918 wxColour
wxGenericTreeCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
) const
920 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
922 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
923 return pItem
->Attr().GetBackgroundColour();
926 wxFont
wxGenericTreeCtrl::GetItemFont(const wxTreeItemId
& item
) const
928 wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") );
930 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
931 return pItem
->Attr().GetFont();
934 void wxGenericTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
936 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
939 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
940 pItem
->SetText(text
);
941 CalculateSize(pItem
, dc
);
945 void wxGenericTreeCtrl::SetItemImage(const wxTreeItemId
& item
,
947 wxTreeItemIcon which
)
949 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
951 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
952 pItem
->SetImage(image
, which
);
955 CalculateSize(pItem
, dc
);
959 void wxGenericTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
961 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
966 ((wxGenericTreeItem
*) item
.m_pItem
)->SetData(data
);
969 void wxGenericTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
971 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
973 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
974 pItem
->SetHasPlus(has
);
978 void wxGenericTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
980 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
982 // avoid redrawing the tree if no real change
983 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
984 if ( pItem
->IsBold() != bold
)
986 pItem
->SetBold(bold
);
991 void wxGenericTreeCtrl::SetItemTextColour(const wxTreeItemId
& item
,
994 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
996 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
997 pItem
->Attr().SetTextColour(col
);
1001 void wxGenericTreeCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
1002 const wxColour
& col
)
1004 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1006 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1007 pItem
->Attr().SetBackgroundColour(col
);
1011 void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
)
1013 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1015 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1016 pItem
->Attr().SetFont(font
);
1020 bool wxGenericTreeCtrl::SetFont( const wxFont
&font
)
1022 wxScrolledWindow::SetFont(font
);
1024 m_normalFont
= font
;
1025 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
1026 m_normalFont
.GetFamily(),
1027 m_normalFont
.GetStyle(),
1029 m_normalFont
.GetUnderlined(),
1030 m_normalFont
.GetFaceName(),
1031 m_normalFont
.GetEncoding());
1037 // -----------------------------------------------------------------------------
1038 // item status inquiries
1039 // -----------------------------------------------------------------------------
1041 bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
1043 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1045 // An item is only visible if it's not a descendant of a collapsed item
1046 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1047 wxGenericTreeItem
* parent
= pItem
->GetParent();
1050 if (!parent
->IsExpanded())
1052 parent
= parent
->GetParent();
1056 GetViewStart(& startX
, & startY
);
1058 wxSize clientSize
= GetClientSize();
1061 if (!GetBoundingRect(item
, rect
))
1063 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
1065 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
1067 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
1073 bool wxGenericTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
1075 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1077 // consider that the item does have children if it has the "+" button: it
1078 // might not have them (if it had never been expanded yet) but then it
1079 // could have them as well and it's better to err on this side rather than
1080 // disabling some operations which are restricted to the items with
1081 // children for an item which does have them
1082 return ((wxGenericTreeItem
*) item
.m_pItem
)->HasPlus();
1085 bool wxGenericTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
1087 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1089 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsExpanded();
1092 bool wxGenericTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
1094 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1096 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsSelected();
1099 bool wxGenericTreeCtrl::IsBold(const wxTreeItemId
& item
) const
1101 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1103 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsBold();
1106 // -----------------------------------------------------------------------------
1108 // -----------------------------------------------------------------------------
1110 wxTreeItemId
wxGenericTreeCtrl::GetItemParent(const wxTreeItemId
& item
) const
1112 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1114 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetParent();
1117 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1118 wxTreeItemIdValue
& cookie
) const
1120 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1123 return GetNextChild(item
, cookie
);
1126 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1127 wxTreeItemIdValue
& cookie
) const
1129 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1131 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1133 // it's ok to cast cookie to size_t, we never have indices big enough to
1134 // overflow "void *"
1135 size_t *pIndex
= (size_t *)&cookie
;
1136 if ( *pIndex
< children
.Count() )
1138 return children
.Item((*pIndex
)++);
1142 // there are no more of them
1143 return wxTreeItemId();
1147 #if WXWIN_COMPATIBILITY_2_4
1149 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1152 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1155 return GetNextChild(item
, cookie
);
1158 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1161 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1163 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1164 if ( (size_t)cookie
< children
.Count() )
1166 return children
.Item((size_t)cookie
++);
1170 // there are no more of them
1171 return wxTreeItemId();
1175 #endif // WXWIN_COMPATIBILITY_2_4
1177 wxTreeItemId
wxGenericTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
1179 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1181 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1182 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
1185 wxTreeItemId
wxGenericTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
1187 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1189 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1190 wxGenericTreeItem
*parent
= i
->GetParent();
1191 if ( parent
== NULL
)
1193 // root item doesn't have any siblings
1194 return wxTreeItemId();
1197 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1198 int index
= siblings
.Index(i
);
1199 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1201 size_t n
= (size_t)(index
+ 1);
1202 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
1205 wxTreeItemId
wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
1207 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1209 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1210 wxGenericTreeItem
*parent
= i
->GetParent();
1211 if ( parent
== NULL
)
1213 // root item doesn't have any siblings
1214 return wxTreeItemId();
1217 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1218 int index
= siblings
.Index(i
);
1219 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1221 return index
== 0 ? wxTreeItemId()
1222 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
1225 // Only for internal use right now, but should probably be public
1226 wxTreeItemId
wxGenericTreeCtrl::GetNext(const wxTreeItemId
& item
) const
1228 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1230 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1232 // First see if there are any children.
1233 wxArrayGenericTreeItems
& children
= i
->GetChildren();
1234 if (children
.GetCount() > 0)
1236 return children
.Item(0);
1240 // Try a sibling of this or ancestor instead
1241 wxTreeItemId p
= item
;
1242 wxTreeItemId toFind
;
1245 toFind
= GetNextSibling(p
);
1246 p
= GetItemParent(p
);
1247 } while (p
.IsOk() && !toFind
.IsOk());
1252 wxTreeItemId
wxGenericTreeCtrl::GetFirstVisibleItem() const
1254 wxTreeItemId id
= GetRootItem();
1263 } while (id
.IsOk());
1265 return wxTreeItemId();
1268 wxTreeItemId
wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
1270 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1272 wxTreeItemId id
= item
;
1275 while (id
= GetNext(id
), id
.IsOk())
1281 return wxTreeItemId();
1284 wxTreeItemId
wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
1286 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1288 wxFAIL_MSG(wxT("not implemented"));
1290 return wxTreeItemId();
1293 // called by wxTextTreeCtrl when it marks itself for deletion
1294 void wxGenericTreeCtrl::ResetTextControl()
1299 // find the first item starting with the given prefix after the given item
1300 wxTreeItemId
wxGenericTreeCtrl::FindItem(const wxTreeItemId
& idParent
,
1301 const wxString
& prefixOrig
) const
1303 // match is case insensitive as this is more convenient to the user: having
1304 // to press Shift-letter to go to the item starting with a capital letter
1305 // would be too bothersome
1306 wxString prefix
= prefixOrig
.Lower();
1308 // determine the starting point: we shouldn't take the current item (this
1309 // allows to switch between two items starting with the same letter just by
1310 // pressing it) but we shouldn't jump to the next one if the user is
1311 // continuing to type as otherwise he might easily skip the item he wanted
1312 wxTreeItemId id
= idParent
;
1313 if ( prefix
.length() == 1 )
1318 // look for the item starting with the given prefix after it
1319 while ( id
.IsOk() && !GetItemText(id
).Lower().StartsWith(prefix
) )
1324 // if we haven't found anything...
1327 // ... wrap to the beginning
1329 if ( HasFlag(wxTR_HIDE_ROOT
) )
1331 // can't select virtual root
1335 // and try all the items (stop when we get to the one we started from)
1336 while ( id
!= idParent
&& !GetItemText(id
).Lower().StartsWith(prefix
) )
1345 // -----------------------------------------------------------------------------
1347 // -----------------------------------------------------------------------------
1349 wxTreeItemId
wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId
& parentId
,
1351 const wxString
& text
,
1352 int image
, int selImage
,
1353 wxTreeItemData
*data
)
1355 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1358 // should we give a warning here?
1359 return AddRoot(text
, image
, selImage
, data
);
1362 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1364 wxGenericTreeItem
*item
=
1365 new wxGenericTreeItem( parent
, text
, image
, selImage
, data
);
1369 data
->m_pItem
= item
;
1372 parent
->Insert( item
, previous
);
1377 wxTreeItemId
wxGenericTreeCtrl::AddRoot(const wxString
& text
,
1378 int image
, int selImage
,
1379 wxTreeItemData
*data
)
1381 wxCHECK_MSG( !m_anchor
, wxTreeItemId(), wxT("tree can have only one root") );
1383 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1385 m_anchor
= new wxGenericTreeItem((wxGenericTreeItem
*)NULL
, text
,
1386 image
, selImage
, data
);
1389 data
->m_pItem
= m_anchor
;
1392 if (HasFlag(wxTR_HIDE_ROOT
))
1394 // if root is hidden, make sure we can navigate
1396 m_anchor
->SetHasPlus();
1398 CalculatePositions();
1401 if (!HasFlag(wxTR_MULTIPLE
))
1403 m_current
= m_key_current
= m_anchor
;
1404 m_current
->SetHilight( true );
1410 wxTreeItemId
wxGenericTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
1411 const wxString
& text
,
1412 int image
, int selImage
,
1413 wxTreeItemData
*data
)
1415 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
1418 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1419 const wxTreeItemId
& idPrevious
,
1420 const wxString
& text
,
1421 int image
, int selImage
,
1422 wxTreeItemData
*data
)
1424 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1427 // should we give a warning here?
1428 return AddRoot(text
, image
, selImage
, data
);
1432 if (idPrevious
.IsOk())
1434 index
= parent
->GetChildren().Index((wxGenericTreeItem
*) idPrevious
.m_pItem
);
1435 wxASSERT_MSG( index
!= wxNOT_FOUND
,
1436 wxT("previous item in wxGenericTreeCtrl::InsertItem() is not a sibling") );
1439 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
1442 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1444 const wxString
& text
,
1445 int image
, int selImage
,
1446 wxTreeItemData
*data
)
1448 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1451 // should we give a warning here?
1452 return AddRoot(text
, image
, selImage
, data
);
1455 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
1458 wxTreeItemId
wxGenericTreeCtrl::AppendItem(const wxTreeItemId
& parentId
,
1459 const wxString
& text
,
1460 int image
, int selImage
,
1461 wxTreeItemData
*data
)
1463 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1466 // should we give a warning here?
1467 return AddRoot(text
, image
, selImage
, data
);
1470 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
1471 image
, selImage
, data
);
1474 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem
*item
)
1476 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, GetId() );
1477 event
.m_item
= item
;
1478 event
.SetEventObject( this );
1479 ProcessEvent( event
);
1482 void wxGenericTreeCtrl::DeleteChildren(const wxTreeItemId
& itemId
)
1484 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1486 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1487 item
->DeleteChildren(this);
1490 void wxGenericTreeCtrl::Delete(const wxTreeItemId
& itemId
)
1492 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1494 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1496 wxGenericTreeItem
*parent
= item
->GetParent();
1498 // don't keep stale pointers around!
1499 if ( IsDescendantOf(item
, m_key_current
) )
1501 // Don't silently change the selection:
1502 // do it properly in idle time, so event
1503 // handlers get called.
1505 // m_key_current = parent;
1506 m_key_current
= NULL
;
1509 // m_select_me records whether we need to select
1510 // a different item, in idle time.
1511 if ( m_select_me
&& IsDescendantOf(item
, m_select_me
) )
1513 m_select_me
= parent
;
1516 if ( IsDescendantOf(item
, m_current
) )
1518 // Don't silently change the selection:
1519 // do it properly in idle time, so event
1520 // handlers get called.
1522 // m_current = parent;
1524 m_select_me
= parent
;
1527 // remove the item from the tree
1530 parent
->GetChildren().Remove( item
); // remove by value
1532 else // deleting the root
1534 // nothing will be left in the tree
1538 // and delete all of its children and the item itself now
1539 item
->DeleteChildren(this);
1540 SendDeleteEvent(item
);
1544 void wxGenericTreeCtrl::DeleteAllItems()
1552 void wxGenericTreeCtrl::Expand(const wxTreeItemId
& itemId
)
1554 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1556 wxCHECK_RET( item
, _T("invalid item in wxGenericTreeCtrl::Expand") );
1557 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1558 _T("can't expand hidden root") );
1560 if ( !item
->HasPlus() )
1563 if ( item
->IsExpanded() )
1566 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, GetId() );
1567 event
.m_item
= item
;
1568 event
.SetEventObject( this );
1570 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1572 // cancelled by program
1577 CalculatePositions();
1579 RefreshSubtree(item
);
1581 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
1582 ProcessEvent( event
);
1585 void wxGenericTreeCtrl::ExpandAll(const wxTreeItemId
& item
)
1587 if ( !HasFlag(wxTR_HIDE_ROOT
) || item
!= GetRootItem())
1590 if ( !IsExpanded(item
) )
1594 wxTreeItemIdValue cookie
;
1595 wxTreeItemId child
= GetFirstChild(item
, cookie
);
1596 while ( child
.IsOk() )
1600 child
= GetNextChild(item
, cookie
);
1604 void wxGenericTreeCtrl::Collapse(const wxTreeItemId
& itemId
)
1606 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1607 _T("can't collapse hidden root") );
1609 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1611 if ( !item
->IsExpanded() )
1614 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, GetId() );
1615 event
.m_item
= item
;
1616 event
.SetEventObject( this );
1617 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1619 // cancelled by program
1625 #if 0 // TODO why should items be collapsed recursively?
1626 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1627 size_t count
= children
.Count();
1628 for ( size_t n
= 0; n
< count
; n
++ )
1630 Collapse(children
[n
]);
1634 CalculatePositions();
1636 RefreshSubtree(item
);
1638 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
1639 ProcessEvent( event
);
1642 void wxGenericTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
1645 DeleteChildren(item
);
1648 void wxGenericTreeCtrl::Toggle(const wxTreeItemId
& itemId
)
1650 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1652 if (item
->IsExpanded())
1658 void wxGenericTreeCtrl::Unselect()
1662 m_current
->SetHilight( false );
1663 RefreshLine( m_current
);
1670 void wxGenericTreeCtrl::UnselectAllChildren(wxGenericTreeItem
*item
)
1672 if (item
->IsSelected())
1674 item
->SetHilight(false);
1678 if (item
->HasChildren())
1680 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1681 size_t count
= children
.Count();
1682 for ( size_t n
= 0; n
< count
; ++n
)
1684 UnselectAllChildren(children
[n
]);
1689 void wxGenericTreeCtrl::UnselectAll()
1691 wxTreeItemId rootItem
= GetRootItem();
1693 // the tree might not have the root item at all
1696 UnselectAllChildren((wxGenericTreeItem
*) rootItem
.m_pItem
);
1700 // Recursive function !
1701 // To stop we must have crt_item<last_item
1703 // Tag all next children, when no more children,
1704 // Move to parent (not to tag)
1705 // Keep going... if we found last_item, we stop.
1706 bool wxGenericTreeCtrl::TagNextChildren(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1708 wxGenericTreeItem
*parent
= crt_item
->GetParent();
1710 if (parent
== NULL
) // This is root item
1711 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
1713 wxArrayGenericTreeItems
& children
= parent
->GetChildren();
1714 int index
= children
.Index(crt_item
);
1715 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1717 size_t count
= children
.Count();
1718 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
1720 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return true;
1723 return TagNextChildren(parent
, last_item
, select
);
1726 bool wxGenericTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1728 crt_item
->SetHilight(select
);
1729 RefreshLine(crt_item
);
1731 if (crt_item
==last_item
)
1734 if (crt_item
->HasChildren())
1736 wxArrayGenericTreeItems
& children
= crt_item
->GetChildren();
1737 size_t count
= children
.Count();
1738 for ( size_t n
= 0; n
< count
; ++n
)
1740 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
1748 void wxGenericTreeCtrl::SelectItemRange(wxGenericTreeItem
*item1
, wxGenericTreeItem
*item2
)
1752 // item2 is not necessary after item1
1753 // choice first' and 'last' between item1 and item2
1754 wxGenericTreeItem
*first
= (item1
->GetY()<item2
->GetY()) ? item1
: item2
;
1755 wxGenericTreeItem
*last
= (item1
->GetY()<item2
->GetY()) ? item2
: item1
;
1757 bool select
= m_current
->IsSelected();
1759 if ( TagAllChildrenUntilLast(first
,last
,select
) )
1762 TagNextChildren(first
,last
,select
);
1765 void wxGenericTreeCtrl::DoSelectItem(const wxTreeItemId
& itemId
,
1766 bool unselect_others
,
1767 bool extended_select
)
1769 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
1773 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
1774 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1776 //wxCHECK_RET( ( (!unselect_others) && is_single),
1777 // wxT("this is a single selection tree") );
1779 // to keep going anyhow !!!
1782 if (item
->IsSelected())
1783 return; // nothing to do
1784 unselect_others
= true;
1785 extended_select
= false;
1787 else if ( unselect_others
&& item
->IsSelected() )
1789 // selection change if there is more than one item currently selected
1790 wxArrayTreeItemIds selected_items
;
1791 if ( GetSelections(selected_items
) == 1 )
1795 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, GetId() );
1796 event
.m_item
= item
;
1797 event
.m_itemOld
= m_current
;
1798 event
.SetEventObject( this );
1799 // TODO : Here we don't send any selection mode yet !
1801 if ( GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed() )
1804 wxTreeItemId parent
= GetItemParent( itemId
);
1805 while (parent
.IsOk())
1807 if (!IsExpanded(parent
))
1810 parent
= GetItemParent( parent
);
1813 EnsureVisible( itemId
);
1816 if (unselect_others
)
1818 if (is_single
) Unselect(); // to speed up thing
1823 if (extended_select
)
1827 m_current
= m_key_current
= (wxGenericTreeItem
*) GetRootItem().m_pItem
;
1830 // don't change the mark (m_current)
1831 SelectItemRange(m_current
, item
);
1835 bool select
= true; // the default
1837 // Check if we need to toggle hilight (ctrl mode)
1838 if (!unselect_others
)
1839 select
=!item
->IsSelected();
1841 m_current
= m_key_current
= item
;
1842 m_current
->SetHilight(select
);
1843 RefreshLine( m_current
);
1846 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
1847 GetEventHandler()->ProcessEvent( event
);
1850 void wxGenericTreeCtrl::SelectItem(const wxTreeItemId
& itemId
, bool select
)
1854 DoSelectItem(itemId
);
1858 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1859 wxCHECK_RET( item
, wxT("SelectItem(): invalid tree item") );
1861 item
->SetHilight(false);
1866 void wxGenericTreeCtrl::FillArray(wxGenericTreeItem
*item
,
1867 wxArrayTreeItemIds
&array
) const
1869 if ( item
->IsSelected() )
1870 array
.Add(wxTreeItemId(item
));
1872 if ( item
->HasChildren() )
1874 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1875 size_t count
= children
.GetCount();
1876 for ( size_t n
= 0; n
< count
; ++n
)
1877 FillArray(children
[n
], array
);
1881 size_t wxGenericTreeCtrl::GetSelections(wxArrayTreeItemIds
&array
) const
1884 wxTreeItemId idRoot
= GetRootItem();
1885 if ( idRoot
.IsOk() )
1887 FillArray((wxGenericTreeItem
*) idRoot
.m_pItem
, array
);
1889 //else: the tree is empty, so no selections
1891 return array
.Count();
1894 void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
1896 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1898 if (!item
.IsOk()) return;
1900 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1902 // first expand all parent branches
1903 wxGenericTreeItem
*parent
= gitem
->GetParent();
1905 if ( HasFlag(wxTR_HIDE_ROOT
) )
1907 while ( parent
&& parent
!= m_anchor
)
1910 parent
= parent
->GetParent();
1918 parent
= parent
->GetParent();
1922 //if (parent) CalculatePositions();
1927 void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId
&item
)
1929 if (!item
.IsOk()) return;
1931 // We have to call this here because the label in
1932 // question might just have been added and no screen
1933 // update taken place.
1935 #if defined( __WXMSW__ ) || defined(__WXMAC__)
1940 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1942 // now scroll to the item
1943 int item_y
= gitem
->GetY();
1947 GetViewStart( &start_x
, &start_y
);
1948 start_y
*= PIXELS_PER_UNIT
;
1952 GetClientSize( &client_w
, &client_h
);
1954 if (item_y
< start_y
+3)
1959 m_anchor
->GetSize( x
, y
, this );
1960 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1961 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1962 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1963 // Item should appear at top
1964 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
1966 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
1971 m_anchor
->GetSize( x
, y
, this );
1972 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1973 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1974 item_y
+= PIXELS_PER_UNIT
+2;
1975 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1976 // Item should appear at bottom
1977 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
);
1981 // FIXME: tree sorting functions are not reentrant and not MT-safe!
1982 static wxGenericTreeCtrl
*s_treeBeingSorted
= NULL
;
1984 static int LINKAGEMODE
tree_ctrl_compare_func(wxGenericTreeItem
**item1
,
1985 wxGenericTreeItem
**item2
)
1987 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxGenericTreeCtrl::SortChildren()") );
1989 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
1992 int wxGenericTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
1993 const wxTreeItemId
& item2
)
1995 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
1998 void wxGenericTreeCtrl::SortChildren(const wxTreeItemId
& itemId
)
2000 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
2002 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
2004 wxCHECK_RET( !s_treeBeingSorted
,
2005 wxT("wxGenericTreeCtrl::SortChildren is not reentrant") );
2007 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2008 if ( children
.Count() > 1 )
2012 s_treeBeingSorted
= this;
2013 children
.Sort(tree_ctrl_compare_func
);
2014 s_treeBeingSorted
= NULL
;
2016 //else: don't make the tree dirty as nothing changed
2019 wxImageList
*wxGenericTreeCtrl::GetImageList() const
2021 return m_imageListNormal
;
2024 wxImageList
*wxGenericTreeCtrl::GetButtonsImageList() const
2026 return m_imageListButtons
;
2029 wxImageList
*wxGenericTreeCtrl::GetStateImageList() const
2031 return m_imageListState
;
2034 void wxGenericTreeCtrl::CalculateLineHeight()
2036 wxClientDC
dc(this);
2037 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
2039 if ( m_imageListNormal
)
2041 // Calculate a m_lineHeight value from the normal Image sizes.
2042 // May be toggle off. Then wxGenericTreeCtrl will spread when
2043 // necessary (which might look ugly).
2044 int n
= m_imageListNormal
->GetImageCount();
2045 for (int i
= 0; i
< n
; i
++)
2047 int width
= 0, height
= 0;
2048 m_imageListNormal
->GetSize(i
, width
, height
);
2049 if (height
> m_lineHeight
) m_lineHeight
= height
;
2053 if (m_imageListButtons
)
2055 // Calculate a m_lineHeight value from the Button image sizes.
2056 // May be toggle off. Then wxGenericTreeCtrl will spread when
2057 // necessary (which might look ugly).
2058 int n
= m_imageListButtons
->GetImageCount();
2059 for (int i
= 0; i
< n
; i
++)
2061 int width
= 0, height
= 0;
2062 m_imageListButtons
->GetSize(i
, width
, height
);
2063 if (height
> m_lineHeight
) m_lineHeight
= height
;
2067 if (m_lineHeight
< 30)
2068 m_lineHeight
+= 2; // at least 2 pixels
2070 m_lineHeight
+= m_lineHeight
/10; // otherwise 10% extra spacing
2073 void wxGenericTreeCtrl::SetImageList(wxImageList
*imageList
)
2075 if (m_ownsImageListNormal
) delete m_imageListNormal
;
2076 m_imageListNormal
= imageList
;
2077 m_ownsImageListNormal
= false;
2079 // Don't do any drawing if we're setting the list to NULL,
2080 // since we may be in the process of deleting the tree control.
2082 CalculateLineHeight();
2085 void wxGenericTreeCtrl::SetStateImageList(wxImageList
*imageList
)
2087 if (m_ownsImageListState
) delete m_imageListState
;
2088 m_imageListState
= imageList
;
2089 m_ownsImageListState
= false;
2092 void wxGenericTreeCtrl::SetButtonsImageList(wxImageList
*imageList
)
2094 if (m_ownsImageListButtons
) delete m_imageListButtons
;
2095 m_imageListButtons
= imageList
;
2096 m_ownsImageListButtons
= false;
2098 CalculateLineHeight();
2101 void wxGenericTreeCtrl::AssignImageList(wxImageList
*imageList
)
2103 SetImageList(imageList
);
2104 m_ownsImageListNormal
= true;
2107 void wxGenericTreeCtrl::AssignStateImageList(wxImageList
*imageList
)
2109 SetStateImageList(imageList
);
2110 m_ownsImageListState
= true;
2113 void wxGenericTreeCtrl::AssignButtonsImageList(wxImageList
*imageList
)
2115 SetButtonsImageList(imageList
);
2116 m_ownsImageListButtons
= true;
2119 // -----------------------------------------------------------------------------
2121 // -----------------------------------------------------------------------------
2123 void wxGenericTreeCtrl::AdjustMyScrollbars()
2128 m_anchor
->GetSize( x
, y
, this );
2129 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2130 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2131 int x_pos
= GetScrollPos( wxHORIZONTAL
);
2132 int y_pos
= GetScrollPos( wxVERTICAL
);
2133 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
2137 SetScrollbars( 0, 0, 0, 0 );
2141 int wxGenericTreeCtrl::GetLineHeight(wxGenericTreeItem
*item
) const
2143 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
2144 return item
->GetHeight();
2146 return m_lineHeight
;
2149 void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem
*item
, wxDC
& dc
)
2151 // TODO implement "state" icon on items
2153 wxTreeItemAttr
*attr
= item
->GetAttributes();
2154 if ( attr
&& attr
->HasFont() )
2155 dc
.SetFont(attr
->GetFont());
2156 else if (item
->IsBold())
2157 dc
.SetFont(m_boldFont
);
2159 long text_w
= 0, text_h
= 0;
2160 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
2162 int image_h
= 0, image_w
= 0;
2163 int image
= item
->GetCurrentImage();
2164 if ( image
!= NO_IMAGE
)
2166 if ( m_imageListNormal
)
2168 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
2177 int total_h
= GetLineHeight(item
);
2179 if ( item
->IsSelected() )
2181 // under mac selections are only a rectangle in case they don't have the focus
2185 dc
.SetBrush( *wxTRANSPARENT_BRUSH
) ;
2186 dc
.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
) , 1 , wxSOLID
) ) ;
2190 dc
.SetBrush( *m_hilightBrush
) ;
2193 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
2199 if ( attr
&& attr
->HasBackgroundColour() )
2200 colBg
= attr
->GetBackgroundColour();
2202 colBg
= m_backgroundColour
;
2203 dc
.SetBrush(wxBrush(colBg
, wxSOLID
));
2206 int offset
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0;
2208 if ( HasFlag(wxTR_FULL_ROW_HIGHLIGHT
) )
2212 DoGetPosition(&x
, &y
);
2214 dc
.DrawRectangle(x
, item
->GetY()+offset
, w
, total_h
-offset
);
2218 if ( item
->IsSelected() && image
!= NO_IMAGE
)
2220 // If it's selected, and there's an image, then we should
2221 // take care to leave the area under the image painted in the
2222 // background colour.
2223 dc
.DrawRectangle( item
->GetX() + image_w
- 2, item
->GetY()+offset
,
2224 item
->GetWidth() - image_w
+ 2, total_h
-offset
);
2228 dc
.DrawRectangle( item
->GetX()-2, item
->GetY()+offset
,
2229 item
->GetWidth()+2, total_h
-offset
);
2233 if ( image
!= NO_IMAGE
)
2235 dc
.SetClippingRegion( item
->GetX(), item
->GetY(), image_w
-2, total_h
);
2236 m_imageListNormal
->Draw( image
, dc
,
2238 item
->GetY() +((total_h
> image_h
)?((total_h
-image_h
)/2):0),
2239 wxIMAGELIST_DRAW_TRANSPARENT
);
2240 dc
.DestroyClippingRegion();
2243 dc
.SetBackgroundMode(wxTRANSPARENT
);
2244 int extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
2245 dc
.DrawText( item
->GetText(),
2246 (wxCoord
)(image_w
+ item
->GetX()),
2247 (wxCoord
)(item
->GetY() + extraH
));
2249 // restore normal font
2250 dc
.SetFont( m_normalFont
);
2253 // Now y stands for the top of the item, whereas it used to stand for middle !
2254 void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
2256 int x
= level
*m_indent
;
2257 if (!HasFlag(wxTR_HIDE_ROOT
))
2261 else if (level
== 0)
2263 // always expand hidden root
2265 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2266 int count
= children
.Count();
2272 PaintLevel(children
[n
], dc
, 1, y
);
2273 } while (++n
< count
);
2275 if (!HasFlag(wxTR_NO_LINES
) && HasFlag(wxTR_LINES_AT_ROOT
) && count
> 0)
2277 // draw line down to last child
2278 origY
+= GetLineHeight(children
[0])>>1;
2279 oldY
+= GetLineHeight(children
[n
-1])>>1;
2280 dc
.DrawLine(3, origY
, 3, oldY
);
2286 item
->SetX(x
+m_spacing
);
2289 int h
= GetLineHeight(item
);
2291 int y_mid
= y_top
+ (h
>>1);
2294 int exposed_x
= dc
.LogicalToDeviceX(0);
2295 int exposed_y
= dc
.LogicalToDeviceY(y_top
);
2297 if (IsExposed(exposed_x
, exposed_y
, 10000, h
)) // 10000 = very much
2301 // don't draw rect outline if we already have the
2302 // background color under Mac
2303 (item
->IsSelected() && m_hasFocus
) ? wxBLACK_PEN
:
2304 #endif // !__WXMAC__
2308 if ( item
->IsSelected() )
2310 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
2314 wxTreeItemAttr
*attr
= item
->GetAttributes();
2315 if (attr
&& attr
->HasTextColour())
2316 colText
= attr
->GetTextColour();
2318 colText
= GetForegroundColour();
2322 dc
.SetTextForeground(colText
);
2326 PaintItem(item
, dc
);
2328 if (HasFlag(wxTR_ROW_LINES
))
2330 // if the background colour is white, choose a
2331 // contrasting color for the lines
2332 dc
.SetPen(*((GetBackgroundColour() == *wxWHITE
)
2333 ? wxMEDIUM_GREY_PEN
: wxWHITE_PEN
));
2334 dc
.DrawLine(0, y_top
, 10000, y_top
);
2335 dc
.DrawLine(0, y
, 10000, y
);
2338 // restore DC objects
2339 dc
.SetBrush(*wxWHITE_BRUSH
);
2340 dc
.SetPen(m_dottedPen
);
2341 dc
.SetTextForeground(*wxBLACK
);
2343 if ( !HasFlag(wxTR_NO_LINES
) )
2345 // draw the horizontal line here
2347 if (x
> (signed)m_indent
)
2348 x_start
-= m_indent
;
2349 else if (HasFlag(wxTR_LINES_AT_ROOT
))
2351 dc
.DrawLine(x_start
, y_mid
, x
+ m_spacing
, y_mid
);
2354 // should the item show a button?
2355 if ( item
->HasPlus() && HasButtons() )
2357 if ( m_imageListButtons
)
2359 // draw the image button here
2362 int image
= item
->IsExpanded() ? wxTreeItemIcon_Expanded
2363 : wxTreeItemIcon_Normal
;
2364 if ( item
->IsSelected() )
2365 image
+= wxTreeItemIcon_Selected
- wxTreeItemIcon_Normal
;
2367 m_imageListButtons
->GetSize(image
, image_w
, image_h
);
2368 int xx
= x
- image_w
/2;
2369 int yy
= y_mid
- image_h
/2;
2371 wxDCClipper
clip(dc
, xx
, yy
, image_w
, image_h
);
2372 m_imageListButtons
->Draw(image
, dc
, xx
, yy
,
2373 wxIMAGELIST_DRAW_TRANSPARENT
);
2375 else // no custom buttons
2377 static const int wImage
= 9;
2378 static const int hImage
= 9;
2381 if (item
->IsExpanded())
2382 flag
|= wxCONTROL_EXPANDED
;
2383 if (item
== m_underMouse
)
2384 flag
|= wxCONTROL_CURRENT
;
2386 wxRendererNative::Get().DrawTreeItemButton
2390 wxRect(x
- wImage
/2,
2399 if (item
->IsExpanded())
2401 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2402 int count
= children
.Count();
2409 PaintLevel(children
[n
], dc
, level
, y
);
2410 } while (++n
< count
);
2412 if (!HasFlag(wxTR_NO_LINES
) && count
> 0)
2414 // draw line down to last child
2415 oldY
+= GetLineHeight(children
[n
-1])>>1;
2416 if (HasButtons()) y_mid
+= 5;
2418 // Only draw the portion of the line that is visible, in case it is huge
2419 wxCoord xOrigin
=0, yOrigin
=0, width
, height
;
2420 dc
.GetDeviceOrigin(&xOrigin
, &yOrigin
);
2421 yOrigin
= abs(yOrigin
);
2422 GetClientSize(&width
, &height
);
2424 // Move end points to the begining/end of the view?
2425 if (y_mid
< yOrigin
)
2427 if (oldY
> yOrigin
+ height
)
2428 oldY
= yOrigin
+ height
;
2430 // after the adjustments if y_mid is larger than oldY then the line
2431 // isn't visible at all so don't draw anything
2433 dc
.DrawLine(x
, y_mid
, x
, oldY
);
2439 void wxGenericTreeCtrl::DrawDropEffect(wxGenericTreeItem
*item
)
2443 if ( item
->HasPlus() )
2445 // it's a folder, indicate it by a border
2450 // draw a line under the drop target because the item will be
2452 DrawLine(item
, true /* below */);
2455 SetCursor(wxCURSOR_BULLSEYE
);
2460 SetCursor(wxCURSOR_NO_ENTRY
);
2464 void wxGenericTreeCtrl::DrawBorder(const wxTreeItemId
&item
)
2466 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2468 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2470 wxClientDC
dc(this);
2472 dc
.SetLogicalFunction(wxINVERT
);
2473 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2475 int w
= i
->GetWidth() + 2;
2476 int h
= GetLineHeight(i
) + 2;
2478 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
2481 void wxGenericTreeCtrl::DrawLine(const wxTreeItemId
&item
, bool below
)
2483 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2485 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2487 wxClientDC
dc(this);
2489 dc
.SetLogicalFunction(wxINVERT
);
2495 y
+= GetLineHeight(i
) - 1;
2498 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
2501 // -----------------------------------------------------------------------------
2502 // wxWidgets callbacks
2503 // -----------------------------------------------------------------------------
2505 void wxGenericTreeCtrl::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2513 dc
.SetFont( m_normalFont
);
2514 dc
.SetPen( m_dottedPen
);
2516 // this is now done dynamically
2517 //if(GetImageList() == NULL)
2518 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
2521 PaintLevel( m_anchor
, dc
, 0, y
);
2524 void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent
&event
)
2533 void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent
&event
)
2542 void wxGenericTreeCtrl::OnChar( wxKeyEvent
&event
)
2544 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, GetId() );
2545 te
.m_evtKey
= event
;
2546 te
.SetEventObject( this );
2547 if ( GetEventHandler()->ProcessEvent( te
) )
2549 // intercepted by the user code
2553 if ( (m_current
== 0) || (m_key_current
== 0) )
2559 // how should the selection work for this event?
2560 bool is_multiple
, extended_select
, unselect_others
;
2561 EventFlagsToSelType(GetWindowStyleFlag(),
2563 event
.ControlDown(),
2564 is_multiple
, extended_select
, unselect_others
);
2568 // * : Expand all/Collapse all
2569 // ' ' | return : activate
2570 // up : go up (not last children!)
2572 // left : go to parent
2573 // right : open if parent and go next
2574 // home : go to root
2575 // end : go to last item without opening parents
2576 // alnum : start or continue searching for the item with this prefix
2577 int keyCode
= event
.GetKeyCode();
2582 if (m_current
->HasPlus() && !IsExpanded(m_current
))
2590 if ( !IsExpanded(m_current
) )
2593 ExpandAll(m_current
);
2596 //else: fall through to Collapse() it
2600 if (IsExpanded(m_current
))
2602 Collapse(m_current
);
2608 if ( !event
.HasModifiers() )
2610 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
2611 event
.m_item
= m_current
;
2612 event
.SetEventObject( this );
2613 GetEventHandler()->ProcessEvent( event
);
2616 // in any case, also generate the normal key event for this key,
2617 // even if we generated the ACTIVATED event above: this is what
2618 // wxMSW does and it makes sense because you might not want to
2619 // process ACTIVATED event at all and handle Space and Return
2620 // directly (and differently) which would be impossible otherwise
2624 // up goes to the previous sibling or to the last
2625 // of its children if it's expanded
2628 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
2631 prev
= GetItemParent( m_key_current
);
2632 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2634 break; // don't go to root if it is hidden
2638 wxTreeItemIdValue cookie
;
2639 wxTreeItemId current
= m_key_current
;
2640 // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be?
2641 if (current
== GetFirstChild( prev
, cookie
))
2643 // otherwise we return to where we came from
2644 DoSelectItem( prev
, unselect_others
, extended_select
);
2645 m_key_current
= (wxGenericTreeItem
*) prev
.m_pItem
;
2652 while ( IsExpanded(prev
) && HasChildren(prev
) )
2654 wxTreeItemId child
= GetLastChild(prev
);
2661 DoSelectItem( prev
, unselect_others
, extended_select
);
2662 m_key_current
=(wxGenericTreeItem
*) prev
.m_pItem
;
2667 // left arrow goes to the parent
2670 wxTreeItemId prev
= GetItemParent( m_current
);
2671 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2673 // don't go to root if it is hidden
2674 prev
= GetPrevSibling( m_current
);
2678 DoSelectItem( prev
, unselect_others
, extended_select
);
2684 // this works the same as the down arrow except that we
2685 // also expand the item if it wasn't expanded yet
2691 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
2693 wxTreeItemIdValue cookie
;
2694 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
2695 DoSelectItem( child
, unselect_others
, extended_select
);
2696 m_key_current
=(wxGenericTreeItem
*) child
.m_pItem
;
2700 wxTreeItemId next
= GetNextSibling( m_key_current
);
2703 wxTreeItemId current
= m_key_current
;
2704 while (current
.IsOk() && !next
)
2706 current
= GetItemParent( current
);
2707 if (current
) next
= GetNextSibling( current
);
2712 DoSelectItem( next
, unselect_others
, extended_select
);
2713 m_key_current
=(wxGenericTreeItem
*) next
.m_pItem
;
2719 // <End> selects the last visible tree item
2722 wxTreeItemId last
= GetRootItem();
2724 while ( last
.IsOk() && IsExpanded(last
) )
2726 wxTreeItemId lastChild
= GetLastChild(last
);
2728 // it may happen if the item was expanded but then all of
2729 // its children have been deleted - so IsExpanded() returned
2730 // true, but GetLastChild() returned invalid item
2739 DoSelectItem( last
, unselect_others
, extended_select
);
2744 // <Home> selects the root item
2747 wxTreeItemId prev
= GetRootItem();
2751 if ( HasFlag(wxTR_HIDE_ROOT
) )
2753 wxTreeItemIdValue cookie
;
2754 prev
= GetFirstChild(prev
, cookie
);
2759 DoSelectItem( prev
, unselect_others
, extended_select
);
2764 // do not use wxIsalnum() here
2765 if ( !event
.HasModifiers() &&
2766 ((keyCode
>= '0' && keyCode
<= '9') ||
2767 (keyCode
>= 'a' && keyCode
<= 'z') ||
2768 (keyCode
>= 'A' && keyCode
<= 'Z' )))
2770 // find the next item starting with the given prefix
2771 wxChar ch
= (wxChar
)keyCode
;
2773 wxTreeItemId id
= FindItem(m_current
, m_findPrefix
+ ch
);
2784 // also start the timer to reset the current prefix if the user
2785 // doesn't press any more alnum keys soon -- we wouldn't want
2786 // to use this prefix for a new item search
2789 m_findTimer
= new wxTreeFindTimer(this);
2792 m_findTimer
->Start(wxTreeFindTimer::DELAY
, wxTIMER_ONE_SHOT
);
2801 wxTreeItemId
wxGenericTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
2803 // JACS: removed wxYieldIfNeeded() because it can cause the window
2804 // to be deleted from under us if a close window event is pending
2809 if (point
.x
<0) flags
|= wxTREE_HITTEST_TOLEFT
;
2810 if (point
.x
>w
) flags
|= wxTREE_HITTEST_TORIGHT
;
2811 if (point
.y
<0) flags
|= wxTREE_HITTEST_ABOVE
;
2812 if (point
.y
>h
) flags
|= wxTREE_HITTEST_BELOW
;
2813 if (flags
) return wxTreeItemId();
2815 if (m_anchor
== NULL
)
2817 flags
= wxTREE_HITTEST_NOWHERE
;
2818 return wxTreeItemId();
2821 wxGenericTreeItem
*hit
= m_anchor
->HitTest(CalcUnscrolledPosition(point
),
2825 flags
= wxTREE_HITTEST_NOWHERE
;
2826 return wxTreeItemId();
2831 // get the bounding rectangle of the item (or of its label only)
2832 bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId
& item
,
2834 bool WXUNUSED(textOnly
)) const
2836 wxCHECK_MSG( item
.IsOk(), false, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
2838 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2841 GetViewStart(& startX
, & startY
);
2843 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
2844 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
2845 rect
.width
= i
->GetWidth();
2846 //rect.height = i->GetHeight();
2847 rect
.height
= GetLineHeight(i
);
2852 void wxGenericTreeCtrl::Edit( const wxTreeItemId
& item
)
2854 wxCHECK_RET( item
.IsOk(), _T("can't edit an invalid item") );
2856 wxGenericTreeItem
*itemEdit
= (wxGenericTreeItem
*)item
.m_pItem
;
2858 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, GetId() );
2859 te
.m_item
= itemEdit
;
2860 te
.SetEventObject( this );
2861 if ( GetEventHandler()->ProcessEvent( te
) && !te
.IsAllowed() )
2867 // We have to call this here because the label in
2868 // question might just have been added and no screen
2869 // update taken place.
2871 #if defined( __WXMSW__ ) || defined(__WXMAC__)
2877 m_textCtrl
= new wxTreeTextCtrl(this, itemEdit
);
2879 m_textCtrl
->SetFocus();
2882 // returns a pointer to the text edit control if the item is being
2883 // edited, NULL otherwise (it's assumed that no more than one item may
2884 // be edited simultaneously)
2885 wxTextCtrl
* wxGenericTreeCtrl::GetEditControl() const
2890 bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem
*item
,
2891 const wxString
& value
)
2893 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2895 le
.SetEventObject( this );
2897 le
.m_editCancelled
= false;
2899 return !GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2902 void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem
*item
)
2904 // let owner know that the edit was cancelled
2905 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2907 le
.SetEventObject( this );
2908 le
.m_label
= wxEmptyString
;
2909 le
.m_editCancelled
= true;
2911 GetEventHandler()->ProcessEvent( le
);
2917 void wxGenericTreeCtrl::OnRenameTimer()
2922 void wxGenericTreeCtrl::OnMouse( wxMouseEvent
&event
)
2924 if ( !m_anchor
) return;
2926 wxPoint pt
= CalcUnscrolledPosition(event
.GetPosition());
2928 // Is the mouse over a tree item button?
2930 wxGenericTreeItem
*thisItem
= m_anchor
->HitTest(pt
, this, flags
, 0);
2931 wxGenericTreeItem
*underMouse
= thisItem
;
2933 bool underMouseChanged
= (underMouse
!= m_underMouse
) ;
2934 #endif // wxUSE_TOOLTIPS
2937 (flags
& wxTREE_HITTEST_ONITEMBUTTON
) &&
2938 (!event
.LeftIsDown()) &&
2940 (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2948 if (underMouse
!= m_underMouse
)
2952 // unhighlight old item
2953 wxGenericTreeItem
*tmp
= m_underMouse
;
2954 m_underMouse
= NULL
;
2958 m_underMouse
= underMouse
;
2960 RefreshLine( m_underMouse
);
2964 // Determines what item we are hovering over and need a tooltip for
2965 wxTreeItemId hoverItem
= thisItem
;
2967 // We do not want a tooltip if we are dragging, or if the rename timer is running
2968 if (underMouseChanged
&& hoverItem
.IsOk() && !m_isDragging
&& (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2970 // Ask the tree control what tooltip (if any) should be shown
2971 wxTreeEvent
hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP
, GetId());
2972 hevent
.m_item
= hoverItem
;
2973 hevent
.SetEventObject(this);
2975 if ( GetEventHandler()->ProcessEvent(hevent
) && hevent
.IsAllowed() )
2977 SetToolTip(hevent
.m_label
);
2982 // we process left mouse up event (enables in-place edit), right down
2983 // (pass to the user code), left dbl click (activate item) and
2984 // dragging/moving events for items drag-and-drop
2985 if ( !(event
.LeftDown() ||
2987 event
.RightDown() ||
2988 event
.LeftDClick() ||
2990 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
2999 wxGenericTreeItem
*item
= m_anchor
->HitTest(pt
, this, flags
, 0);
3001 if ( event
.Dragging() && !m_isDragging
)
3003 if (m_dragCount
== 0)
3008 if (m_dragCount
!= 3)
3010 // wait until user drags a bit further...
3014 wxEventType command
= event
.RightIsDown()
3015 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
3016 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
3018 wxTreeEvent
nevent( command
, GetId() );
3019 nevent
.m_item
= m_current
;
3020 nevent
.SetEventObject(this);
3022 // by default the dragging is not supported, the user code must
3023 // explicitly allow the event for it to take place
3026 if ( GetEventHandler()->ProcessEvent(nevent
) && nevent
.IsAllowed() )
3028 // we're going to drag this item
3029 m_isDragging
= true;
3031 // remember the old cursor because we will change it while
3033 m_oldCursor
= m_cursor
;
3035 // in a single selection control, hide the selection temporarily
3036 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
3038 m_oldSelection
= (wxGenericTreeItem
*) GetSelection().m_pItem
;
3040 if ( m_oldSelection
)
3042 m_oldSelection
->SetHilight(false);
3043 RefreshLine(m_oldSelection
);
3050 else if ( event
.Moving() )
3052 if ( item
!= m_dropTarget
)
3054 // unhighlight the previous drop target
3055 DrawDropEffect(m_dropTarget
);
3057 m_dropTarget
= item
;
3059 // highlight the current drop target if any
3060 DrawDropEffect(m_dropTarget
);
3062 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3069 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
3071 // erase the highlighting
3072 DrawDropEffect(m_dropTarget
);
3074 if ( m_oldSelection
)
3076 m_oldSelection
->SetHilight(true);
3077 RefreshLine(m_oldSelection
);
3078 m_oldSelection
= (wxGenericTreeItem
*)NULL
;
3081 // generate the drag end event
3082 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
, GetId());
3084 event
.m_item
= item
;
3085 event
.m_pointDrag
= pt
;
3086 event
.SetEventObject(this);
3088 (void)GetEventHandler()->ProcessEvent(event
);
3090 m_isDragging
= false;
3091 m_dropTarget
= (wxGenericTreeItem
*)NULL
;
3095 SetCursor(m_oldCursor
);
3097 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3105 // here we process only the messages which happen on tree items
3109 if (item
== NULL
) return; /* we hit the blank area */
3111 if ( event
.RightDown() )
3113 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
, GetId());
3114 nevent
.m_item
= item
;
3115 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3116 nevent
.SetEventObject(this);
3117 GetEventHandler()->ProcessEvent(nevent
);
3119 else if ( event
.LeftUp() )
3121 // this facilitates multiple-item drag-and-drop
3123 if (item
&& HasFlag(wxTR_MULTIPLE
))
3125 wxArrayTreeItemIds selections
;
3126 size_t count
= GetSelections(selections
);
3129 !event
.ControlDown() &&
3132 DoSelectItem(item
, true, false);
3138 if ( (item
== m_current
) &&
3139 (flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
3140 HasFlag(wxTR_EDIT_LABELS
) )
3142 if ( m_renameTimer
)
3144 if ( m_renameTimer
->IsRunning() )
3145 m_renameTimer
->Stop();
3149 m_renameTimer
= new wxTreeRenameTimer( this );
3152 m_renameTimer
->Start( wxTreeRenameTimer::DELAY
, true );
3155 m_lastOnSame
= false;
3158 else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
3160 if ( event
.LeftDown() )
3162 m_lastOnSame
= item
== m_current
;
3165 if ( flags
& wxTREE_HITTEST_ONITEMBUTTON
)
3167 // only toggle the item for a single click, double click on
3168 // the button doesn't do anything (it toggles the item twice)
3169 if ( event
.LeftDown() )
3174 // don't select the item if the button was clicked
3179 // clear the previously selected items, if the
3180 // user clicked outside of the present selection.
3181 // otherwise, perform the deselection on mouse-up.
3182 // this allows multiple drag and drop to work.
3184 if (!IsSelected(item
))
3186 // how should the selection work for this event?
3187 bool is_multiple
, extended_select
, unselect_others
;
3188 EventFlagsToSelType(GetWindowStyleFlag(),
3190 event
.ControlDown(),
3191 is_multiple
, extended_select
, unselect_others
);
3193 DoSelectItem(item
, unselect_others
, extended_select
);
3197 // For some reason, Windows isn't recognizing a left double-click,
3198 // so we need to simulate it here. Allow 200 milliseconds for now.
3199 if ( event
.LeftDClick() )
3201 // double clicking should not start editing the item label
3202 if ( m_renameTimer
)
3203 m_renameTimer
->Stop();
3205 m_lastOnSame
= false;
3207 // send activate event first
3208 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
3209 nevent
.m_item
= item
;
3210 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3211 nevent
.SetEventObject( this );
3212 if ( !GetEventHandler()->ProcessEvent( nevent
) )
3214 // if the user code didn't process the activate event,
3215 // handle it ourselves by toggling the item when it is
3217 if ( item
->HasPlus() )
3227 void wxGenericTreeCtrl::OnInternalIdle()
3229 wxWindow::OnInternalIdle();
3231 // Check if we need to select the root item
3232 // because nothing else has been selected.
3233 // Delaying it means that we can invoke event handlers
3234 // as required, when a first item is selected.
3235 if (!HasFlag(wxTR_MULTIPLE
) && !GetSelection().IsOk())
3238 SelectItem(m_select_me
);
3239 else if (GetRootItem().IsOk())
3240 SelectItem(GetRootItem());
3243 /* after all changes have been done to the tree control,
3244 * we actually redraw the tree when everything is over */
3246 if (!m_dirty
) return;
3247 if (m_freezeCount
) return;
3251 CalculatePositions();
3253 AdjustMyScrollbars();
3256 void wxGenericTreeCtrl::CalculateSize( wxGenericTreeItem
*item
, wxDC
&dc
)
3261 wxTreeItemAttr
*attr
= item
->GetAttributes();
3262 if ( attr
&& attr
->HasFont() )
3263 dc
.SetFont(attr
->GetFont());
3264 else if ( item
->IsBold() )
3265 dc
.SetFont(m_boldFont
);
3267 dc
.SetFont(m_normalFont
);
3269 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
3272 // restore normal font
3273 dc
.SetFont( m_normalFont
);
3277 int image
= item
->GetCurrentImage();
3278 if ( image
!= NO_IMAGE
)
3280 if ( m_imageListNormal
)
3282 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
3287 int total_h
= (image_h
> text_h
) ? image_h
: text_h
;
3290 total_h
+= 2; // at least 2 pixels
3292 total_h
+= total_h
/10; // otherwise 10% extra spacing
3294 item
->SetHeight(total_h
);
3295 if (total_h
>m_lineHeight
)
3296 m_lineHeight
=total_h
;
3298 item
->SetWidth(image_w
+text_w
+2);
3301 // -----------------------------------------------------------------------------
3302 // for developper : y is now the top of the level
3303 // not the middle of it !
3304 void wxGenericTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
3306 int x
= level
*m_indent
;
3307 if (!HasFlag(wxTR_HIDE_ROOT
))
3311 else if (level
== 0)
3313 // a hidden root is not evaluated, but its
3314 // children are always calculated
3318 CalculateSize( item
, dc
);
3321 item
->SetX( x
+m_spacing
);
3323 y
+= GetLineHeight(item
);
3325 if ( !item
->IsExpanded() )
3327 // we don't need to calculate collapsed branches
3332 wxArrayGenericTreeItems
& children
= item
->GetChildren();
3333 size_t n
, count
= children
.Count();
3335 for (n
= 0; n
< count
; ++n
)
3336 CalculateLevel( children
[n
], dc
, level
, y
); // recurse
3339 void wxGenericTreeCtrl::CalculatePositions()
3341 if ( !m_anchor
) return;
3343 wxClientDC
dc(this);
3346 dc
.SetFont( m_normalFont
);
3348 dc
.SetPen( m_dottedPen
);
3349 //if(GetImageList() == NULL)
3350 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
3353 CalculateLevel( m_anchor
, dc
, 0, y
); // start recursion
3356 void wxGenericTreeCtrl::RefreshSubtree(wxGenericTreeItem
*item
)
3358 if (m_dirty
) return;
3359 if (m_freezeCount
) return;
3361 wxSize client
= GetClientSize();
3364 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3365 rect
.width
= client
.x
;
3366 rect
.height
= client
.y
;
3368 Refresh(true, &rect
);
3370 AdjustMyScrollbars();
3373 void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
3375 if (m_dirty
) return;
3376 if (m_freezeCount
) return;
3379 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3380 rect
.width
= GetClientSize().x
;
3381 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
3383 Refresh(true, &rect
);
3386 void wxGenericTreeCtrl::RefreshSelected()
3388 if (m_freezeCount
) return;
3390 // TODO: this is awfully inefficient, we should keep the list of all
3391 // selected items internally, should be much faster
3393 RefreshSelectedUnder(m_anchor
);
3396 void wxGenericTreeCtrl::RefreshSelectedUnder(wxGenericTreeItem
*item
)
3398 if (m_freezeCount
) return;
3400 if ( item
->IsSelected() )
3403 const wxArrayGenericTreeItems
& children
= item
->GetChildren();
3404 size_t count
= children
.GetCount();
3405 for ( size_t n
= 0; n
< count
; n
++ )
3407 RefreshSelectedUnder(children
[n
]);
3411 void wxGenericTreeCtrl::Freeze()
3416 void wxGenericTreeCtrl::Thaw()
3418 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen tree control?") );
3420 if ( !--m_freezeCount
)
3426 // ----------------------------------------------------------------------------
3427 // changing colours: we need to refresh the tree control
3428 // ----------------------------------------------------------------------------
3430 bool wxGenericTreeCtrl::SetBackgroundColour(const wxColour
& colour
)
3432 if ( !wxWindow::SetBackgroundColour(colour
) )
3435 if (m_freezeCount
) return true;
3442 bool wxGenericTreeCtrl::SetForegroundColour(const wxColour
& colour
)
3444 if ( !wxWindow::SetForegroundColour(colour
) )
3447 if (m_freezeCount
) return true;
3454 // Process the tooltip event, to speed up event processing.
3455 // Doesn't actually get a tooltip.
3456 void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent
&event
)
3462 // NOTE: If using the wxListBox visual attributes works everywhere then this can
3463 // be removed, as well as the #else case below.
3464 #define _USE_VISATTR 0
3467 #include "wx/listbox.h"
3473 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
3475 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3479 // Use the same color scheme as wxListBox
3480 return wxListBox::GetClassDefaultAttributes(variant
);
3482 wxVisualAttributes attr
;
3483 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
3484 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
3485 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
3490 #endif // wxUSE_TREECTRL