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 SetOwnForegroundColour( attr
.colFg
);
795 SetOwnBackgroundColour( attr
.colBg
);
797 SetOwnFont(attr
.font
);
799 // m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86
800 m_dottedPen
= wxPen( wxT("grey"), 0, 0 );
807 wxGenericTreeCtrl::~wxGenericTreeCtrl()
809 delete m_hilightBrush
;
810 delete m_hilightUnfocusedBrush
;
814 delete m_renameTimer
;
817 if (m_ownsImageListNormal
)
818 delete m_imageListNormal
;
819 if (m_ownsImageListState
)
820 delete m_imageListState
;
821 if (m_ownsImageListButtons
)
822 delete m_imageListButtons
;
825 // -----------------------------------------------------------------------------
827 // -----------------------------------------------------------------------------
829 size_t wxGenericTreeCtrl::GetCount() const
837 size_t count
= m_anchor
->GetChildrenCount();
838 if ( !HasFlag(wxTR_HIDE_ROOT
) )
840 // take the root itself into account
847 void wxGenericTreeCtrl::SetIndent(unsigned int indent
)
849 m_indent
= (unsigned short) indent
;
853 void wxGenericTreeCtrl::SetSpacing(unsigned int spacing
)
855 m_spacing
= (unsigned short) spacing
;
860 wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
,
861 bool recursively
) const
863 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
865 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
868 void wxGenericTreeCtrl::SetWindowStyle(const long styles
)
870 if (!HasFlag(wxTR_HIDE_ROOT
) && (styles
& wxTR_HIDE_ROOT
))
872 // if we will hide the root, make sure children are visible
873 m_anchor
->SetHasPlus();
875 CalculatePositions();
878 // right now, just sets the styles. Eventually, we may
879 // want to update the inherited styles, but right now
880 // none of the parents has updatable styles
881 m_windowStyle
= styles
;
885 // -----------------------------------------------------------------------------
886 // functions to work with tree items
887 // -----------------------------------------------------------------------------
889 wxString
wxGenericTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
891 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
893 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetText();
896 int wxGenericTreeCtrl::GetItemImage(const wxTreeItemId
& item
,
897 wxTreeItemIcon which
) const
899 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
901 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetImage(which
);
904 wxTreeItemData
*wxGenericTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
906 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
908 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetData();
911 wxColour
wxGenericTreeCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
913 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
915 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
916 return pItem
->Attr().GetTextColour();
919 wxColour
wxGenericTreeCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
) const
921 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
923 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
924 return pItem
->Attr().GetBackgroundColour();
927 wxFont
wxGenericTreeCtrl::GetItemFont(const wxTreeItemId
& item
) const
929 wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") );
931 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
932 return pItem
->Attr().GetFont();
935 void wxGenericTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
937 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
940 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
941 pItem
->SetText(text
);
942 CalculateSize(pItem
, dc
);
946 void wxGenericTreeCtrl::SetItemImage(const wxTreeItemId
& item
,
948 wxTreeItemIcon which
)
950 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
952 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
953 pItem
->SetImage(image
, which
);
956 CalculateSize(pItem
, dc
);
960 void wxGenericTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
962 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
967 ((wxGenericTreeItem
*) item
.m_pItem
)->SetData(data
);
970 void wxGenericTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
972 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
974 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
975 pItem
->SetHasPlus(has
);
979 void wxGenericTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
981 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
983 // avoid redrawing the tree if no real change
984 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
985 if ( pItem
->IsBold() != bold
)
987 pItem
->SetBold(bold
);
992 void wxGenericTreeCtrl::SetItemTextColour(const wxTreeItemId
& item
,
995 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
997 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
998 pItem
->Attr().SetTextColour(col
);
1002 void wxGenericTreeCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
1003 const wxColour
& col
)
1005 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1007 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1008 pItem
->Attr().SetBackgroundColour(col
);
1012 void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
)
1014 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1016 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1017 pItem
->Attr().SetFont(font
);
1021 bool wxGenericTreeCtrl::SetFont( const wxFont
&font
)
1023 wxScrolledWindow::SetFont(font
);
1025 m_normalFont
= font
;
1026 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
1027 m_normalFont
.GetFamily(),
1028 m_normalFont
.GetStyle(),
1030 m_normalFont
.GetUnderlined(),
1031 m_normalFont
.GetFaceName(),
1032 m_normalFont
.GetEncoding());
1038 // -----------------------------------------------------------------------------
1039 // item status inquiries
1040 // -----------------------------------------------------------------------------
1042 bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
1044 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1046 // An item is only visible if it's not a descendant of a collapsed item
1047 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1048 wxGenericTreeItem
* parent
= pItem
->GetParent();
1051 if (!parent
->IsExpanded())
1053 parent
= parent
->GetParent();
1057 GetViewStart(& startX
, & startY
);
1059 wxSize clientSize
= GetClientSize();
1062 if (!GetBoundingRect(item
, rect
))
1064 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
1066 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
1068 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
1074 bool wxGenericTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
1076 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1078 // consider that the item does have children if it has the "+" button: it
1079 // might not have them (if it had never been expanded yet) but then it
1080 // could have them as well and it's better to err on this side rather than
1081 // disabling some operations which are restricted to the items with
1082 // children for an item which does have them
1083 return ((wxGenericTreeItem
*) item
.m_pItem
)->HasPlus();
1086 bool wxGenericTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
1088 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1090 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsExpanded();
1093 bool wxGenericTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
1095 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1097 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsSelected();
1100 bool wxGenericTreeCtrl::IsBold(const wxTreeItemId
& item
) const
1102 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1104 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsBold();
1107 // -----------------------------------------------------------------------------
1109 // -----------------------------------------------------------------------------
1111 wxTreeItemId
wxGenericTreeCtrl::GetItemParent(const wxTreeItemId
& item
) const
1113 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1115 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetParent();
1118 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1119 wxTreeItemIdValue
& cookie
) const
1121 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1124 return GetNextChild(item
, cookie
);
1127 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1128 wxTreeItemIdValue
& cookie
) const
1130 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1132 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1134 // it's ok to cast cookie to size_t, we never have indices big enough to
1135 // overflow "void *"
1136 size_t *pIndex
= (size_t *)&cookie
;
1137 if ( *pIndex
< children
.Count() )
1139 return children
.Item((*pIndex
)++);
1143 // there are no more of them
1144 return wxTreeItemId();
1148 #if WXWIN_COMPATIBILITY_2_4
1150 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1153 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1156 return GetNextChild(item
, cookie
);
1159 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1162 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1164 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1165 if ( (size_t)cookie
< children
.Count() )
1167 return children
.Item((size_t)cookie
++);
1171 // there are no more of them
1172 return wxTreeItemId();
1176 #endif // WXWIN_COMPATIBILITY_2_4
1178 wxTreeItemId
wxGenericTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
1180 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1182 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1183 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
1186 wxTreeItemId
wxGenericTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
1188 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1190 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1191 wxGenericTreeItem
*parent
= i
->GetParent();
1192 if ( parent
== NULL
)
1194 // root item doesn't have any siblings
1195 return wxTreeItemId();
1198 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1199 int index
= siblings
.Index(i
);
1200 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1202 size_t n
= (size_t)(index
+ 1);
1203 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
1206 wxTreeItemId
wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
1208 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1210 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1211 wxGenericTreeItem
*parent
= i
->GetParent();
1212 if ( parent
== NULL
)
1214 // root item doesn't have any siblings
1215 return wxTreeItemId();
1218 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1219 int index
= siblings
.Index(i
);
1220 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1222 return index
== 0 ? wxTreeItemId()
1223 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
1226 // Only for internal use right now, but should probably be public
1227 wxTreeItemId
wxGenericTreeCtrl::GetNext(const wxTreeItemId
& item
) const
1229 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1231 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1233 // First see if there are any children.
1234 wxArrayGenericTreeItems
& children
= i
->GetChildren();
1235 if (children
.GetCount() > 0)
1237 return children
.Item(0);
1241 // Try a sibling of this or ancestor instead
1242 wxTreeItemId p
= item
;
1243 wxTreeItemId toFind
;
1246 toFind
= GetNextSibling(p
);
1247 p
= GetItemParent(p
);
1248 } while (p
.IsOk() && !toFind
.IsOk());
1253 wxTreeItemId
wxGenericTreeCtrl::GetFirstVisibleItem() const
1255 wxTreeItemId id
= GetRootItem();
1264 } while (id
.IsOk());
1266 return wxTreeItemId();
1269 wxTreeItemId
wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
1271 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1273 wxTreeItemId id
= item
;
1276 while (id
= GetNext(id
), id
.IsOk())
1282 return wxTreeItemId();
1285 wxTreeItemId
wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
1287 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1289 wxFAIL_MSG(wxT("not implemented"));
1291 return wxTreeItemId();
1294 // called by wxTextTreeCtrl when it marks itself for deletion
1295 void wxGenericTreeCtrl::ResetTextControl()
1300 // find the first item starting with the given prefix after the given item
1301 wxTreeItemId
wxGenericTreeCtrl::FindItem(const wxTreeItemId
& idParent
,
1302 const wxString
& prefixOrig
) const
1304 // match is case insensitive as this is more convenient to the user: having
1305 // to press Shift-letter to go to the item starting with a capital letter
1306 // would be too bothersome
1307 wxString prefix
= prefixOrig
.Lower();
1309 // determine the starting point: we shouldn't take the current item (this
1310 // allows to switch between two items starting with the same letter just by
1311 // pressing it) but we shouldn't jump to the next one if the user is
1312 // continuing to type as otherwise he might easily skip the item he wanted
1313 wxTreeItemId id
= idParent
;
1314 if ( prefix
.length() == 1 )
1319 // look for the item starting with the given prefix after it
1320 while ( id
.IsOk() && !GetItemText(id
).Lower().StartsWith(prefix
) )
1325 // if we haven't found anything...
1328 // ... wrap to the beginning
1330 if ( HasFlag(wxTR_HIDE_ROOT
) )
1332 // can't select virtual root
1336 // and try all the items (stop when we get to the one we started from)
1337 while ( id
!= idParent
&& !GetItemText(id
).Lower().StartsWith(prefix
) )
1346 // -----------------------------------------------------------------------------
1348 // -----------------------------------------------------------------------------
1350 wxTreeItemId
wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId
& parentId
,
1352 const wxString
& text
,
1353 int image
, int selImage
,
1354 wxTreeItemData
*data
)
1356 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1359 // should we give a warning here?
1360 return AddRoot(text
, image
, selImage
, data
);
1363 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1365 wxGenericTreeItem
*item
=
1366 new wxGenericTreeItem( parent
, text
, image
, selImage
, data
);
1370 data
->m_pItem
= item
;
1373 parent
->Insert( item
, previous
);
1378 wxTreeItemId
wxGenericTreeCtrl::AddRoot(const wxString
& text
,
1379 int image
, int selImage
,
1380 wxTreeItemData
*data
)
1382 wxCHECK_MSG( !m_anchor
, wxTreeItemId(), wxT("tree can have only one root") );
1384 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1386 m_anchor
= new wxGenericTreeItem((wxGenericTreeItem
*)NULL
, text
,
1387 image
, selImage
, data
);
1390 data
->m_pItem
= m_anchor
;
1393 if (HasFlag(wxTR_HIDE_ROOT
))
1395 // if root is hidden, make sure we can navigate
1397 m_anchor
->SetHasPlus();
1399 CalculatePositions();
1402 if (!HasFlag(wxTR_MULTIPLE
))
1404 m_current
= m_key_current
= m_anchor
;
1405 m_current
->SetHilight( true );
1411 wxTreeItemId
wxGenericTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
1412 const wxString
& text
,
1413 int image
, int selImage
,
1414 wxTreeItemData
*data
)
1416 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
1419 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1420 const wxTreeItemId
& idPrevious
,
1421 const wxString
& text
,
1422 int image
, int selImage
,
1423 wxTreeItemData
*data
)
1425 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1428 // should we give a warning here?
1429 return AddRoot(text
, image
, selImage
, data
);
1433 if (idPrevious
.IsOk())
1435 index
= parent
->GetChildren().Index((wxGenericTreeItem
*) idPrevious
.m_pItem
);
1436 wxASSERT_MSG( index
!= wxNOT_FOUND
,
1437 wxT("previous item in wxGenericTreeCtrl::InsertItem() is not a sibling") );
1440 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
1443 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1445 const wxString
& text
,
1446 int image
, int selImage
,
1447 wxTreeItemData
*data
)
1449 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1452 // should we give a warning here?
1453 return AddRoot(text
, image
, selImage
, data
);
1456 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
1459 wxTreeItemId
wxGenericTreeCtrl::AppendItem(const wxTreeItemId
& parentId
,
1460 const wxString
& text
,
1461 int image
, int selImage
,
1462 wxTreeItemData
*data
)
1464 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1467 // should we give a warning here?
1468 return AddRoot(text
, image
, selImage
, data
);
1471 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
1472 image
, selImage
, data
);
1475 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem
*item
)
1477 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, GetId() );
1478 event
.m_item
= item
;
1479 event
.SetEventObject( this );
1480 ProcessEvent( event
);
1483 void wxGenericTreeCtrl::DeleteChildren(const wxTreeItemId
& itemId
)
1485 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1487 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1488 item
->DeleteChildren(this);
1491 void wxGenericTreeCtrl::Delete(const wxTreeItemId
& itemId
)
1493 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1495 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1497 wxGenericTreeItem
*parent
= item
->GetParent();
1499 // don't keep stale pointers around!
1500 if ( IsDescendantOf(item
, m_key_current
) )
1502 // Don't silently change the selection:
1503 // do it properly in idle time, so event
1504 // handlers get called.
1506 // m_key_current = parent;
1507 m_key_current
= NULL
;
1510 // m_select_me records whether we need to select
1511 // a different item, in idle time.
1512 if ( m_select_me
&& IsDescendantOf(item
, m_select_me
) )
1514 m_select_me
= parent
;
1517 if ( IsDescendantOf(item
, m_current
) )
1519 // Don't silently change the selection:
1520 // do it properly in idle time, so event
1521 // handlers get called.
1523 // m_current = parent;
1525 m_select_me
= parent
;
1528 // remove the item from the tree
1531 parent
->GetChildren().Remove( item
); // remove by value
1533 else // deleting the root
1535 // nothing will be left in the tree
1539 // and delete all of its children and the item itself now
1540 item
->DeleteChildren(this);
1541 SendDeleteEvent(item
);
1545 void wxGenericTreeCtrl::DeleteAllItems()
1553 void wxGenericTreeCtrl::Expand(const wxTreeItemId
& itemId
)
1555 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1557 wxCHECK_RET( item
, _T("invalid item in wxGenericTreeCtrl::Expand") );
1558 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1559 _T("can't expand hidden root") );
1561 if ( !item
->HasPlus() )
1564 if ( item
->IsExpanded() )
1567 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, GetId() );
1568 event
.m_item
= item
;
1569 event
.SetEventObject( this );
1571 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1573 // cancelled by program
1578 CalculatePositions();
1580 RefreshSubtree(item
);
1582 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
1583 ProcessEvent( event
);
1586 void wxGenericTreeCtrl::ExpandAll(const wxTreeItemId
& item
)
1588 if ( !HasFlag(wxTR_HIDE_ROOT
) || item
!= GetRootItem())
1591 if ( !IsExpanded(item
) )
1595 wxTreeItemIdValue cookie
;
1596 wxTreeItemId child
= GetFirstChild(item
, cookie
);
1597 while ( child
.IsOk() )
1601 child
= GetNextChild(item
, cookie
);
1605 void wxGenericTreeCtrl::Collapse(const wxTreeItemId
& itemId
)
1607 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1608 _T("can't collapse hidden root") );
1610 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1612 if ( !item
->IsExpanded() )
1615 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, GetId() );
1616 event
.m_item
= item
;
1617 event
.SetEventObject( this );
1618 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1620 // cancelled by program
1626 #if 0 // TODO why should items be collapsed recursively?
1627 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1628 size_t count
= children
.Count();
1629 for ( size_t n
= 0; n
< count
; n
++ )
1631 Collapse(children
[n
]);
1635 CalculatePositions();
1637 RefreshSubtree(item
);
1639 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
1640 ProcessEvent( event
);
1643 void wxGenericTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
1646 DeleteChildren(item
);
1649 void wxGenericTreeCtrl::Toggle(const wxTreeItemId
& itemId
)
1651 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1653 if (item
->IsExpanded())
1659 void wxGenericTreeCtrl::Unselect()
1663 m_current
->SetHilight( false );
1664 RefreshLine( m_current
);
1671 void wxGenericTreeCtrl::UnselectAllChildren(wxGenericTreeItem
*item
)
1673 if (item
->IsSelected())
1675 item
->SetHilight(false);
1679 if (item
->HasChildren())
1681 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1682 size_t count
= children
.Count();
1683 for ( size_t n
= 0; n
< count
; ++n
)
1685 UnselectAllChildren(children
[n
]);
1690 void wxGenericTreeCtrl::UnselectAll()
1692 wxTreeItemId rootItem
= GetRootItem();
1694 // the tree might not have the root item at all
1697 UnselectAllChildren((wxGenericTreeItem
*) rootItem
.m_pItem
);
1701 // Recursive function !
1702 // To stop we must have crt_item<last_item
1704 // Tag all next children, when no more children,
1705 // Move to parent (not to tag)
1706 // Keep going... if we found last_item, we stop.
1707 bool wxGenericTreeCtrl::TagNextChildren(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1709 wxGenericTreeItem
*parent
= crt_item
->GetParent();
1711 if (parent
== NULL
) // This is root item
1712 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
1714 wxArrayGenericTreeItems
& children
= parent
->GetChildren();
1715 int index
= children
.Index(crt_item
);
1716 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1718 size_t count
= children
.Count();
1719 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
1721 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return true;
1724 return TagNextChildren(parent
, last_item
, select
);
1727 bool wxGenericTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1729 crt_item
->SetHilight(select
);
1730 RefreshLine(crt_item
);
1732 if (crt_item
==last_item
)
1735 if (crt_item
->HasChildren())
1737 wxArrayGenericTreeItems
& children
= crt_item
->GetChildren();
1738 size_t count
= children
.Count();
1739 for ( size_t n
= 0; n
< count
; ++n
)
1741 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
1749 void wxGenericTreeCtrl::SelectItemRange(wxGenericTreeItem
*item1
, wxGenericTreeItem
*item2
)
1753 // item2 is not necessary after item1
1754 // choice first' and 'last' between item1 and item2
1755 wxGenericTreeItem
*first
= (item1
->GetY()<item2
->GetY()) ? item1
: item2
;
1756 wxGenericTreeItem
*last
= (item1
->GetY()<item2
->GetY()) ? item2
: item1
;
1758 bool select
= m_current
->IsSelected();
1760 if ( TagAllChildrenUntilLast(first
,last
,select
) )
1763 TagNextChildren(first
,last
,select
);
1766 void wxGenericTreeCtrl::DoSelectItem(const wxTreeItemId
& itemId
,
1767 bool unselect_others
,
1768 bool extended_select
)
1770 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
1774 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
1775 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1777 //wxCHECK_RET( ( (!unselect_others) && is_single),
1778 // wxT("this is a single selection tree") );
1780 // to keep going anyhow !!!
1783 if (item
->IsSelected())
1784 return; // nothing to do
1785 unselect_others
= true;
1786 extended_select
= false;
1788 else if ( unselect_others
&& item
->IsSelected() )
1790 // selection change if there is more than one item currently selected
1791 wxArrayTreeItemIds selected_items
;
1792 if ( GetSelections(selected_items
) == 1 )
1796 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, GetId() );
1797 event
.m_item
= item
;
1798 event
.m_itemOld
= m_current
;
1799 event
.SetEventObject( this );
1800 // TODO : Here we don't send any selection mode yet !
1802 if ( GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed() )
1805 wxTreeItemId parent
= GetItemParent( itemId
);
1806 while (parent
.IsOk())
1808 if (!IsExpanded(parent
))
1811 parent
= GetItemParent( parent
);
1814 EnsureVisible( itemId
);
1817 if (unselect_others
)
1819 if (is_single
) Unselect(); // to speed up thing
1824 if (extended_select
)
1828 m_current
= m_key_current
= (wxGenericTreeItem
*) GetRootItem().m_pItem
;
1831 // don't change the mark (m_current)
1832 SelectItemRange(m_current
, item
);
1836 bool select
= true; // the default
1838 // Check if we need to toggle hilight (ctrl mode)
1839 if (!unselect_others
)
1840 select
=!item
->IsSelected();
1842 m_current
= m_key_current
= item
;
1843 m_current
->SetHilight(select
);
1844 RefreshLine( m_current
);
1847 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
1848 GetEventHandler()->ProcessEvent( event
);
1851 void wxGenericTreeCtrl::SelectItem(const wxTreeItemId
& itemId
, bool select
)
1855 DoSelectItem(itemId
);
1859 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1860 wxCHECK_RET( item
, wxT("SelectItem(): invalid tree item") );
1862 item
->SetHilight(false);
1867 void wxGenericTreeCtrl::FillArray(wxGenericTreeItem
*item
,
1868 wxArrayTreeItemIds
&array
) const
1870 if ( item
->IsSelected() )
1871 array
.Add(wxTreeItemId(item
));
1873 if ( item
->HasChildren() )
1875 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1876 size_t count
= children
.GetCount();
1877 for ( size_t n
= 0; n
< count
; ++n
)
1878 FillArray(children
[n
], array
);
1882 size_t wxGenericTreeCtrl::GetSelections(wxArrayTreeItemIds
&array
) const
1885 wxTreeItemId idRoot
= GetRootItem();
1886 if ( idRoot
.IsOk() )
1888 FillArray((wxGenericTreeItem
*) idRoot
.m_pItem
, array
);
1890 //else: the tree is empty, so no selections
1892 return array
.Count();
1895 void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
1897 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1899 if (!item
.IsOk()) return;
1901 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1903 // first expand all parent branches
1904 wxGenericTreeItem
*parent
= gitem
->GetParent();
1906 if ( HasFlag(wxTR_HIDE_ROOT
) )
1908 while ( parent
&& parent
!= m_anchor
)
1911 parent
= parent
->GetParent();
1919 parent
= parent
->GetParent();
1923 //if (parent) CalculatePositions();
1928 void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId
&item
)
1930 if (!item
.IsOk()) return;
1932 // We have to call this here because the label in
1933 // question might just have been added and no screen
1934 // update taken place.
1936 #if defined( __WXMSW__ ) || defined(__WXMAC__)
1941 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1943 // now scroll to the item
1944 int item_y
= gitem
->GetY();
1948 GetViewStart( &start_x
, &start_y
);
1949 start_y
*= PIXELS_PER_UNIT
;
1953 GetClientSize( &client_w
, &client_h
);
1955 if (item_y
< start_y
+3)
1960 m_anchor
->GetSize( x
, y
, this );
1961 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1962 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1963 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1964 // Item should appear at top
1965 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
1967 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
1972 m_anchor
->GetSize( x
, y
, this );
1973 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1974 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1975 item_y
+= PIXELS_PER_UNIT
+2;
1976 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1977 // Item should appear at bottom
1978 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
);
1982 // FIXME: tree sorting functions are not reentrant and not MT-safe!
1983 static wxGenericTreeCtrl
*s_treeBeingSorted
= NULL
;
1985 static int LINKAGEMODE
tree_ctrl_compare_func(wxGenericTreeItem
**item1
,
1986 wxGenericTreeItem
**item2
)
1988 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxGenericTreeCtrl::SortChildren()") );
1990 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
1993 int wxGenericTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
1994 const wxTreeItemId
& item2
)
1996 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
1999 void wxGenericTreeCtrl::SortChildren(const wxTreeItemId
& itemId
)
2001 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
2003 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
2005 wxCHECK_RET( !s_treeBeingSorted
,
2006 wxT("wxGenericTreeCtrl::SortChildren is not reentrant") );
2008 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2009 if ( children
.Count() > 1 )
2013 s_treeBeingSorted
= this;
2014 children
.Sort(tree_ctrl_compare_func
);
2015 s_treeBeingSorted
= NULL
;
2017 //else: don't make the tree dirty as nothing changed
2020 wxImageList
*wxGenericTreeCtrl::GetImageList() const
2022 return m_imageListNormal
;
2025 wxImageList
*wxGenericTreeCtrl::GetButtonsImageList() const
2027 return m_imageListButtons
;
2030 wxImageList
*wxGenericTreeCtrl::GetStateImageList() const
2032 return m_imageListState
;
2035 void wxGenericTreeCtrl::CalculateLineHeight()
2037 wxClientDC
dc(this);
2038 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
2040 if ( m_imageListNormal
)
2042 // Calculate a m_lineHeight value from the normal Image sizes.
2043 // May be toggle off. Then wxGenericTreeCtrl will spread when
2044 // necessary (which might look ugly).
2045 int n
= m_imageListNormal
->GetImageCount();
2046 for (int i
= 0; i
< n
; i
++)
2048 int width
= 0, height
= 0;
2049 m_imageListNormal
->GetSize(i
, width
, height
);
2050 if (height
> m_lineHeight
) m_lineHeight
= height
;
2054 if (m_imageListButtons
)
2056 // Calculate a m_lineHeight value from the Button image sizes.
2057 // May be toggle off. Then wxGenericTreeCtrl will spread when
2058 // necessary (which might look ugly).
2059 int n
= m_imageListButtons
->GetImageCount();
2060 for (int i
= 0; i
< n
; i
++)
2062 int width
= 0, height
= 0;
2063 m_imageListButtons
->GetSize(i
, width
, height
);
2064 if (height
> m_lineHeight
) m_lineHeight
= height
;
2068 if (m_lineHeight
< 30)
2069 m_lineHeight
+= 2; // at least 2 pixels
2071 m_lineHeight
+= m_lineHeight
/10; // otherwise 10% extra spacing
2074 void wxGenericTreeCtrl::SetImageList(wxImageList
*imageList
)
2076 if (m_ownsImageListNormal
) delete m_imageListNormal
;
2077 m_imageListNormal
= imageList
;
2078 m_ownsImageListNormal
= false;
2080 // Don't do any drawing if we're setting the list to NULL,
2081 // since we may be in the process of deleting the tree control.
2083 CalculateLineHeight();
2086 void wxGenericTreeCtrl::SetStateImageList(wxImageList
*imageList
)
2088 if (m_ownsImageListState
) delete m_imageListState
;
2089 m_imageListState
= imageList
;
2090 m_ownsImageListState
= false;
2093 void wxGenericTreeCtrl::SetButtonsImageList(wxImageList
*imageList
)
2095 if (m_ownsImageListButtons
) delete m_imageListButtons
;
2096 m_imageListButtons
= imageList
;
2097 m_ownsImageListButtons
= false;
2099 CalculateLineHeight();
2102 void wxGenericTreeCtrl::AssignImageList(wxImageList
*imageList
)
2104 SetImageList(imageList
);
2105 m_ownsImageListNormal
= true;
2108 void wxGenericTreeCtrl::AssignStateImageList(wxImageList
*imageList
)
2110 SetStateImageList(imageList
);
2111 m_ownsImageListState
= true;
2114 void wxGenericTreeCtrl::AssignButtonsImageList(wxImageList
*imageList
)
2116 SetButtonsImageList(imageList
);
2117 m_ownsImageListButtons
= true;
2120 // -----------------------------------------------------------------------------
2122 // -----------------------------------------------------------------------------
2124 void wxGenericTreeCtrl::AdjustMyScrollbars()
2129 m_anchor
->GetSize( x
, y
, this );
2130 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2131 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2132 int x_pos
= GetScrollPos( wxHORIZONTAL
);
2133 int y_pos
= GetScrollPos( wxVERTICAL
);
2134 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
2138 SetScrollbars( 0, 0, 0, 0 );
2142 int wxGenericTreeCtrl::GetLineHeight(wxGenericTreeItem
*item
) const
2144 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
2145 return item
->GetHeight();
2147 return m_lineHeight
;
2150 void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem
*item
, wxDC
& dc
)
2152 // TODO implement "state" icon on items
2154 wxTreeItemAttr
*attr
= item
->GetAttributes();
2155 if ( attr
&& attr
->HasFont() )
2156 dc
.SetFont(attr
->GetFont());
2157 else if (item
->IsBold())
2158 dc
.SetFont(m_boldFont
);
2160 long text_w
= 0, text_h
= 0;
2161 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
2163 int image_h
= 0, image_w
= 0;
2164 int image
= item
->GetCurrentImage();
2165 if ( image
!= NO_IMAGE
)
2167 if ( m_imageListNormal
)
2169 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
2178 int total_h
= GetLineHeight(item
);
2180 if ( item
->IsSelected() )
2182 // under mac selections are only a rectangle in case they don't have the focus
2186 dc
.SetBrush( *wxTRANSPARENT_BRUSH
) ;
2187 dc
.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
) , 1 , wxSOLID
) ) ;
2191 dc
.SetBrush( *m_hilightBrush
) ;
2194 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
2200 if ( attr
&& attr
->HasBackgroundColour() )
2201 colBg
= attr
->GetBackgroundColour();
2203 colBg
= m_backgroundColour
;
2204 dc
.SetBrush(wxBrush(colBg
, wxSOLID
));
2207 int offset
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0;
2209 if ( HasFlag(wxTR_FULL_ROW_HIGHLIGHT
) )
2213 DoGetPosition(&x
, &y
);
2215 dc
.DrawRectangle(x
, item
->GetY()+offset
, w
, total_h
-offset
);
2219 if ( item
->IsSelected() && image
!= NO_IMAGE
)
2221 // If it's selected, and there's an image, then we should
2222 // take care to leave the area under the image painted in the
2223 // background colour.
2224 dc
.DrawRectangle( item
->GetX() + image_w
- 2, item
->GetY()+offset
,
2225 item
->GetWidth() - image_w
+ 2, total_h
-offset
);
2229 dc
.DrawRectangle( item
->GetX()-2, item
->GetY()+offset
,
2230 item
->GetWidth()+2, total_h
-offset
);
2234 if ( image
!= NO_IMAGE
)
2236 dc
.SetClippingRegion( item
->GetX(), item
->GetY(), image_w
-2, total_h
);
2237 m_imageListNormal
->Draw( image
, dc
,
2239 item
->GetY() +((total_h
> image_h
)?((total_h
-image_h
)/2):0),
2240 wxIMAGELIST_DRAW_TRANSPARENT
);
2241 dc
.DestroyClippingRegion();
2244 dc
.SetBackgroundMode(wxTRANSPARENT
);
2245 int extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
2246 dc
.DrawText( item
->GetText(),
2247 (wxCoord
)(image_w
+ item
->GetX()),
2248 (wxCoord
)(item
->GetY() + extraH
));
2250 // restore normal font
2251 dc
.SetFont( m_normalFont
);
2254 // Now y stands for the top of the item, whereas it used to stand for middle !
2255 void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
2257 int x
= level
*m_indent
;
2258 if (!HasFlag(wxTR_HIDE_ROOT
))
2262 else if (level
== 0)
2264 // always expand hidden root
2266 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2267 int count
= children
.Count();
2273 PaintLevel(children
[n
], dc
, 1, y
);
2274 } while (++n
< count
);
2276 if (!HasFlag(wxTR_NO_LINES
) && HasFlag(wxTR_LINES_AT_ROOT
) && count
> 0)
2278 // draw line down to last child
2279 origY
+= GetLineHeight(children
[0])>>1;
2280 oldY
+= GetLineHeight(children
[n
-1])>>1;
2281 dc
.DrawLine(3, origY
, 3, oldY
);
2287 item
->SetX(x
+m_spacing
);
2290 int h
= GetLineHeight(item
);
2292 int y_mid
= y_top
+ (h
>>1);
2295 int exposed_x
= dc
.LogicalToDeviceX(0);
2296 int exposed_y
= dc
.LogicalToDeviceY(y_top
);
2298 if (IsExposed(exposed_x
, exposed_y
, 10000, h
)) // 10000 = very much
2302 // don't draw rect outline if we already have the
2303 // background color under Mac
2304 (item
->IsSelected() && m_hasFocus
) ? wxBLACK_PEN
:
2305 #endif // !__WXMAC__
2309 if ( item
->IsSelected() )
2311 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
2315 wxTreeItemAttr
*attr
= item
->GetAttributes();
2316 if (attr
&& attr
->HasTextColour())
2317 colText
= attr
->GetTextColour();
2319 colText
= GetForegroundColour();
2323 dc
.SetTextForeground(colText
);
2327 PaintItem(item
, dc
);
2329 if (HasFlag(wxTR_ROW_LINES
))
2331 // if the background colour is white, choose a
2332 // contrasting color for the lines
2333 dc
.SetPen(*((GetBackgroundColour() == *wxWHITE
)
2334 ? wxMEDIUM_GREY_PEN
: wxWHITE_PEN
));
2335 dc
.DrawLine(0, y_top
, 10000, y_top
);
2336 dc
.DrawLine(0, y
, 10000, y
);
2339 // restore DC objects
2340 dc
.SetBrush(*wxWHITE_BRUSH
);
2341 dc
.SetPen(m_dottedPen
);
2342 dc
.SetTextForeground(*wxBLACK
);
2344 if ( !HasFlag(wxTR_NO_LINES
) )
2346 // draw the horizontal line here
2348 if (x
> (signed)m_indent
)
2349 x_start
-= m_indent
;
2350 else if (HasFlag(wxTR_LINES_AT_ROOT
))
2352 dc
.DrawLine(x_start
, y_mid
, x
+ m_spacing
, y_mid
);
2355 // should the item show a button?
2356 if ( item
->HasPlus() && HasButtons() )
2358 if ( m_imageListButtons
)
2360 // draw the image button here
2363 int image
= item
->IsExpanded() ? wxTreeItemIcon_Expanded
2364 : wxTreeItemIcon_Normal
;
2365 if ( item
->IsSelected() )
2366 image
+= wxTreeItemIcon_Selected
- wxTreeItemIcon_Normal
;
2368 m_imageListButtons
->GetSize(image
, image_w
, image_h
);
2369 int xx
= x
- image_w
/2;
2370 int yy
= y_mid
- image_h
/2;
2372 wxDCClipper
clip(dc
, xx
, yy
, image_w
, image_h
);
2373 m_imageListButtons
->Draw(image
, dc
, xx
, yy
,
2374 wxIMAGELIST_DRAW_TRANSPARENT
);
2376 else // no custom buttons
2378 static const int wImage
= 9;
2379 static const int hImage
= 9;
2382 if (item
->IsExpanded())
2383 flag
|= wxCONTROL_EXPANDED
;
2384 if (item
== m_underMouse
)
2385 flag
|= wxCONTROL_CURRENT
;
2387 wxRendererNative::Get().DrawTreeItemButton
2391 wxRect(x
- wImage
/2,
2400 if (item
->IsExpanded())
2402 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2403 int count
= children
.Count();
2410 PaintLevel(children
[n
], dc
, level
, y
);
2411 } while (++n
< count
);
2413 if (!HasFlag(wxTR_NO_LINES
) && count
> 0)
2415 // draw line down to last child
2416 oldY
+= GetLineHeight(children
[n
-1])>>1;
2417 if (HasButtons()) y_mid
+= 5;
2419 // Only draw the portion of the line that is visible, in case it is huge
2420 wxCoord xOrigin
=0, yOrigin
=0, width
, height
;
2421 dc
.GetDeviceOrigin(&xOrigin
, &yOrigin
);
2422 yOrigin
= abs(yOrigin
);
2423 GetClientSize(&width
, &height
);
2425 // Move end points to the begining/end of the view?
2426 if (y_mid
< yOrigin
)
2428 if (oldY
> yOrigin
+ height
)
2429 oldY
= yOrigin
+ height
;
2431 // after the adjustments if y_mid is larger than oldY then the line
2432 // isn't visible at all so don't draw anything
2434 dc
.DrawLine(x
, y_mid
, x
, oldY
);
2440 void wxGenericTreeCtrl::DrawDropEffect(wxGenericTreeItem
*item
)
2444 if ( item
->HasPlus() )
2446 // it's a folder, indicate it by a border
2451 // draw a line under the drop target because the item will be
2453 DrawLine(item
, true /* below */);
2456 SetCursor(wxCURSOR_BULLSEYE
);
2461 SetCursor(wxCURSOR_NO_ENTRY
);
2465 void wxGenericTreeCtrl::DrawBorder(const wxTreeItemId
&item
)
2467 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2469 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2471 wxClientDC
dc(this);
2473 dc
.SetLogicalFunction(wxINVERT
);
2474 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2476 int w
= i
->GetWidth() + 2;
2477 int h
= GetLineHeight(i
) + 2;
2479 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
2482 void wxGenericTreeCtrl::DrawLine(const wxTreeItemId
&item
, bool below
)
2484 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2486 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2488 wxClientDC
dc(this);
2490 dc
.SetLogicalFunction(wxINVERT
);
2496 y
+= GetLineHeight(i
) - 1;
2499 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
2502 // -----------------------------------------------------------------------------
2503 // wxWidgets callbacks
2504 // -----------------------------------------------------------------------------
2506 void wxGenericTreeCtrl::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2514 dc
.SetFont( m_normalFont
);
2515 dc
.SetPen( m_dottedPen
);
2517 // this is now done dynamically
2518 //if(GetImageList() == NULL)
2519 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
2522 PaintLevel( m_anchor
, dc
, 0, y
);
2525 void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent
&event
)
2534 void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent
&event
)
2543 void wxGenericTreeCtrl::OnChar( wxKeyEvent
&event
)
2545 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, GetId() );
2546 te
.m_evtKey
= event
;
2547 te
.SetEventObject( this );
2548 if ( GetEventHandler()->ProcessEvent( te
) )
2550 // intercepted by the user code
2554 if ( (m_current
== 0) || (m_key_current
== 0) )
2560 // how should the selection work for this event?
2561 bool is_multiple
, extended_select
, unselect_others
;
2562 EventFlagsToSelType(GetWindowStyleFlag(),
2564 event
.ControlDown(),
2565 is_multiple
, extended_select
, unselect_others
);
2569 // * : Expand all/Collapse all
2570 // ' ' | return : activate
2571 // up : go up (not last children!)
2573 // left : go to parent
2574 // right : open if parent and go next
2575 // home : go to root
2576 // end : go to last item without opening parents
2577 // alnum : start or continue searching for the item with this prefix
2578 int keyCode
= event
.GetKeyCode();
2583 if (m_current
->HasPlus() && !IsExpanded(m_current
))
2591 if ( !IsExpanded(m_current
) )
2594 ExpandAll(m_current
);
2597 //else: fall through to Collapse() it
2601 if (IsExpanded(m_current
))
2603 Collapse(m_current
);
2609 if ( !event
.HasModifiers() )
2611 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
2612 event
.m_item
= m_current
;
2613 event
.SetEventObject( this );
2614 GetEventHandler()->ProcessEvent( event
);
2617 // in any case, also generate the normal key event for this key,
2618 // even if we generated the ACTIVATED event above: this is what
2619 // wxMSW does and it makes sense because you might not want to
2620 // process ACTIVATED event at all and handle Space and Return
2621 // directly (and differently) which would be impossible otherwise
2625 // up goes to the previous sibling or to the last
2626 // of its children if it's expanded
2629 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
2632 prev
= GetItemParent( m_key_current
);
2633 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2635 break; // don't go to root if it is hidden
2639 wxTreeItemIdValue cookie
;
2640 wxTreeItemId current
= m_key_current
;
2641 // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be?
2642 if (current
== GetFirstChild( prev
, cookie
))
2644 // otherwise we return to where we came from
2645 DoSelectItem( prev
, unselect_others
, extended_select
);
2646 m_key_current
= (wxGenericTreeItem
*) prev
.m_pItem
;
2653 while ( IsExpanded(prev
) && HasChildren(prev
) )
2655 wxTreeItemId child
= GetLastChild(prev
);
2662 DoSelectItem( prev
, unselect_others
, extended_select
);
2663 m_key_current
=(wxGenericTreeItem
*) prev
.m_pItem
;
2668 // left arrow goes to the parent
2671 wxTreeItemId prev
= GetItemParent( m_current
);
2672 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2674 // don't go to root if it is hidden
2675 prev
= GetPrevSibling( m_current
);
2679 DoSelectItem( prev
, unselect_others
, extended_select
);
2685 // this works the same as the down arrow except that we
2686 // also expand the item if it wasn't expanded yet
2692 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
2694 wxTreeItemIdValue cookie
;
2695 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
2696 DoSelectItem( child
, unselect_others
, extended_select
);
2697 m_key_current
=(wxGenericTreeItem
*) child
.m_pItem
;
2701 wxTreeItemId next
= GetNextSibling( m_key_current
);
2704 wxTreeItemId current
= m_key_current
;
2705 while (current
.IsOk() && !next
)
2707 current
= GetItemParent( current
);
2708 if (current
) next
= GetNextSibling( current
);
2713 DoSelectItem( next
, unselect_others
, extended_select
);
2714 m_key_current
=(wxGenericTreeItem
*) next
.m_pItem
;
2720 // <End> selects the last visible tree item
2723 wxTreeItemId last
= GetRootItem();
2725 while ( last
.IsOk() && IsExpanded(last
) )
2727 wxTreeItemId lastChild
= GetLastChild(last
);
2729 // it may happen if the item was expanded but then all of
2730 // its children have been deleted - so IsExpanded() returned
2731 // true, but GetLastChild() returned invalid item
2740 DoSelectItem( last
, unselect_others
, extended_select
);
2745 // <Home> selects the root item
2748 wxTreeItemId prev
= GetRootItem();
2752 if ( HasFlag(wxTR_HIDE_ROOT
) )
2754 wxTreeItemIdValue cookie
;
2755 prev
= GetFirstChild(prev
, cookie
);
2760 DoSelectItem( prev
, unselect_others
, extended_select
);
2765 // do not use wxIsalnum() here
2766 if ( !event
.HasModifiers() &&
2767 ((keyCode
>= '0' && keyCode
<= '9') ||
2768 (keyCode
>= 'a' && keyCode
<= 'z') ||
2769 (keyCode
>= 'A' && keyCode
<= 'Z' )))
2771 // find the next item starting with the given prefix
2772 wxChar ch
= (wxChar
)keyCode
;
2774 wxTreeItemId id
= FindItem(m_current
, m_findPrefix
+ ch
);
2785 // also start the timer to reset the current prefix if the user
2786 // doesn't press any more alnum keys soon -- we wouldn't want
2787 // to use this prefix for a new item search
2790 m_findTimer
= new wxTreeFindTimer(this);
2793 m_findTimer
->Start(wxTreeFindTimer::DELAY
, wxTIMER_ONE_SHOT
);
2802 wxTreeItemId
wxGenericTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
2804 // JACS: removed wxYieldIfNeeded() because it can cause the window
2805 // to be deleted from under us if a close window event is pending
2810 if (point
.x
<0) flags
|= wxTREE_HITTEST_TOLEFT
;
2811 if (point
.x
>w
) flags
|= wxTREE_HITTEST_TORIGHT
;
2812 if (point
.y
<0) flags
|= wxTREE_HITTEST_ABOVE
;
2813 if (point
.y
>h
) flags
|= wxTREE_HITTEST_BELOW
;
2814 if (flags
) return wxTreeItemId();
2816 if (m_anchor
== NULL
)
2818 flags
= wxTREE_HITTEST_NOWHERE
;
2819 return wxTreeItemId();
2822 wxGenericTreeItem
*hit
= m_anchor
->HitTest(CalcUnscrolledPosition(point
),
2826 flags
= wxTREE_HITTEST_NOWHERE
;
2827 return wxTreeItemId();
2832 // get the bounding rectangle of the item (or of its label only)
2833 bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId
& item
,
2835 bool WXUNUSED(textOnly
)) const
2837 wxCHECK_MSG( item
.IsOk(), false, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
2839 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2842 GetViewStart(& startX
, & startY
);
2844 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
2845 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
2846 rect
.width
= i
->GetWidth();
2847 //rect.height = i->GetHeight();
2848 rect
.height
= GetLineHeight(i
);
2853 void wxGenericTreeCtrl::Edit( const wxTreeItemId
& item
)
2855 wxCHECK_RET( item
.IsOk(), _T("can't edit an invalid item") );
2857 wxGenericTreeItem
*itemEdit
= (wxGenericTreeItem
*)item
.m_pItem
;
2859 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, GetId() );
2860 te
.m_item
= itemEdit
;
2861 te
.SetEventObject( this );
2862 if ( GetEventHandler()->ProcessEvent( te
) && !te
.IsAllowed() )
2868 // We have to call this here because the label in
2869 // question might just have been added and no screen
2870 // update taken place.
2872 #if defined( __WXMSW__ ) || defined(__WXMAC__)
2878 m_textCtrl
= new wxTreeTextCtrl(this, itemEdit
);
2880 m_textCtrl
->SetFocus();
2883 // returns a pointer to the text edit control if the item is being
2884 // edited, NULL otherwise (it's assumed that no more than one item may
2885 // be edited simultaneously)
2886 wxTextCtrl
* wxGenericTreeCtrl::GetEditControl() const
2891 bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem
*item
,
2892 const wxString
& value
)
2894 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2896 le
.SetEventObject( this );
2898 le
.m_editCancelled
= false;
2900 return !GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2903 void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem
*item
)
2905 // let owner know that the edit was cancelled
2906 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2908 le
.SetEventObject( this );
2909 le
.m_label
= wxEmptyString
;
2910 le
.m_editCancelled
= true;
2912 GetEventHandler()->ProcessEvent( le
);
2918 void wxGenericTreeCtrl::OnRenameTimer()
2923 void wxGenericTreeCtrl::OnMouse( wxMouseEvent
&event
)
2925 if ( !m_anchor
) return;
2927 wxPoint pt
= CalcUnscrolledPosition(event
.GetPosition());
2929 // Is the mouse over a tree item button?
2931 wxGenericTreeItem
*thisItem
= m_anchor
->HitTest(pt
, this, flags
, 0);
2932 wxGenericTreeItem
*underMouse
= thisItem
;
2934 bool underMouseChanged
= (underMouse
!= m_underMouse
) ;
2935 #endif // wxUSE_TOOLTIPS
2938 (flags
& wxTREE_HITTEST_ONITEMBUTTON
) &&
2939 (!event
.LeftIsDown()) &&
2941 (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2949 if (underMouse
!= m_underMouse
)
2953 // unhighlight old item
2954 wxGenericTreeItem
*tmp
= m_underMouse
;
2955 m_underMouse
= NULL
;
2959 m_underMouse
= underMouse
;
2961 RefreshLine( m_underMouse
);
2965 // Determines what item we are hovering over and need a tooltip for
2966 wxTreeItemId hoverItem
= thisItem
;
2968 // We do not want a tooltip if we are dragging, or if the rename timer is running
2969 if (underMouseChanged
&& hoverItem
.IsOk() && !m_isDragging
&& (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2971 // Ask the tree control what tooltip (if any) should be shown
2972 wxTreeEvent
hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP
, GetId());
2973 hevent
.m_item
= hoverItem
;
2974 hevent
.SetEventObject(this);
2976 if ( GetEventHandler()->ProcessEvent(hevent
) && hevent
.IsAllowed() )
2978 SetToolTip(hevent
.m_label
);
2983 // we process left mouse up event (enables in-place edit), right down
2984 // (pass to the user code), left dbl click (activate item) and
2985 // dragging/moving events for items drag-and-drop
2986 if ( !(event
.LeftDown() ||
2988 event
.RightDown() ||
2989 event
.LeftDClick() ||
2991 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
3000 wxGenericTreeItem
*item
= m_anchor
->HitTest(pt
, this, flags
, 0);
3002 if ( event
.Dragging() && !m_isDragging
)
3004 if (m_dragCount
== 0)
3009 if (m_dragCount
!= 3)
3011 // wait until user drags a bit further...
3015 wxEventType command
= event
.RightIsDown()
3016 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
3017 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
3019 wxTreeEvent
nevent( command
, GetId() );
3020 nevent
.m_item
= m_current
;
3021 nevent
.SetEventObject(this);
3023 // by default the dragging is not supported, the user code must
3024 // explicitly allow the event for it to take place
3027 if ( GetEventHandler()->ProcessEvent(nevent
) && nevent
.IsAllowed() )
3029 // we're going to drag this item
3030 m_isDragging
= true;
3032 // remember the old cursor because we will change it while
3034 m_oldCursor
= m_cursor
;
3036 // in a single selection control, hide the selection temporarily
3037 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
3039 m_oldSelection
= (wxGenericTreeItem
*) GetSelection().m_pItem
;
3041 if ( m_oldSelection
)
3043 m_oldSelection
->SetHilight(false);
3044 RefreshLine(m_oldSelection
);
3051 else if ( event
.Moving() )
3053 if ( item
!= m_dropTarget
)
3055 // unhighlight the previous drop target
3056 DrawDropEffect(m_dropTarget
);
3058 m_dropTarget
= item
;
3060 // highlight the current drop target if any
3061 DrawDropEffect(m_dropTarget
);
3063 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3070 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
3072 // erase the highlighting
3073 DrawDropEffect(m_dropTarget
);
3075 if ( m_oldSelection
)
3077 m_oldSelection
->SetHilight(true);
3078 RefreshLine(m_oldSelection
);
3079 m_oldSelection
= (wxGenericTreeItem
*)NULL
;
3082 // generate the drag end event
3083 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
, GetId());
3085 event
.m_item
= item
;
3086 event
.m_pointDrag
= pt
;
3087 event
.SetEventObject(this);
3089 (void)GetEventHandler()->ProcessEvent(event
);
3091 m_isDragging
= false;
3092 m_dropTarget
= (wxGenericTreeItem
*)NULL
;
3096 SetCursor(m_oldCursor
);
3098 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3106 // here we process only the messages which happen on tree items
3110 if (item
== NULL
) return; /* we hit the blank area */
3112 if ( event
.RightDown() )
3114 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
, GetId());
3115 nevent
.m_item
= item
;
3116 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3117 nevent
.SetEventObject(this);
3118 GetEventHandler()->ProcessEvent(nevent
);
3120 else if ( event
.LeftUp() )
3122 // this facilitates multiple-item drag-and-drop
3124 if (item
&& HasFlag(wxTR_MULTIPLE
))
3126 wxArrayTreeItemIds selections
;
3127 size_t count
= GetSelections(selections
);
3130 !event
.ControlDown() &&
3133 DoSelectItem(item
, true, false);
3139 if ( (item
== m_current
) &&
3140 (flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
3141 HasFlag(wxTR_EDIT_LABELS
) )
3143 if ( m_renameTimer
)
3145 if ( m_renameTimer
->IsRunning() )
3146 m_renameTimer
->Stop();
3150 m_renameTimer
= new wxTreeRenameTimer( this );
3153 m_renameTimer
->Start( wxTreeRenameTimer::DELAY
, true );
3156 m_lastOnSame
= false;
3159 else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
3161 if ( event
.LeftDown() )
3163 m_lastOnSame
= item
== m_current
;
3166 if ( flags
& wxTREE_HITTEST_ONITEMBUTTON
)
3168 // only toggle the item for a single click, double click on
3169 // the button doesn't do anything (it toggles the item twice)
3170 if ( event
.LeftDown() )
3175 // don't select the item if the button was clicked
3180 // clear the previously selected items, if the
3181 // user clicked outside of the present selection.
3182 // otherwise, perform the deselection on mouse-up.
3183 // this allows multiple drag and drop to work.
3185 if (!IsSelected(item
))
3187 // how should the selection work for this event?
3188 bool is_multiple
, extended_select
, unselect_others
;
3189 EventFlagsToSelType(GetWindowStyleFlag(),
3191 event
.ControlDown(),
3192 is_multiple
, extended_select
, unselect_others
);
3194 DoSelectItem(item
, unselect_others
, extended_select
);
3198 // For some reason, Windows isn't recognizing a left double-click,
3199 // so we need to simulate it here. Allow 200 milliseconds for now.
3200 if ( event
.LeftDClick() )
3202 // double clicking should not start editing the item label
3203 if ( m_renameTimer
)
3204 m_renameTimer
->Stop();
3206 m_lastOnSame
= false;
3208 // send activate event first
3209 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
3210 nevent
.m_item
= item
;
3211 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3212 nevent
.SetEventObject( this );
3213 if ( !GetEventHandler()->ProcessEvent( nevent
) )
3215 // if the user code didn't process the activate event,
3216 // handle it ourselves by toggling the item when it is
3218 if ( item
->HasPlus() )
3228 void wxGenericTreeCtrl::OnInternalIdle()
3230 wxWindow::OnInternalIdle();
3232 // Check if we need to select the root item
3233 // because nothing else has been selected.
3234 // Delaying it means that we can invoke event handlers
3235 // as required, when a first item is selected.
3236 if (!HasFlag(wxTR_MULTIPLE
) && !GetSelection().IsOk())
3239 SelectItem(m_select_me
);
3240 else if (GetRootItem().IsOk())
3241 SelectItem(GetRootItem());
3244 /* after all changes have been done to the tree control,
3245 * we actually redraw the tree when everything is over */
3247 if (!m_dirty
) return;
3248 if (m_freezeCount
) return;
3252 CalculatePositions();
3254 AdjustMyScrollbars();
3257 void wxGenericTreeCtrl::CalculateSize( wxGenericTreeItem
*item
, wxDC
&dc
)
3262 wxTreeItemAttr
*attr
= item
->GetAttributes();
3263 if ( attr
&& attr
->HasFont() )
3264 dc
.SetFont(attr
->GetFont());
3265 else if ( item
->IsBold() )
3266 dc
.SetFont(m_boldFont
);
3268 dc
.SetFont(m_normalFont
);
3270 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
3273 // restore normal font
3274 dc
.SetFont( m_normalFont
);
3278 int image
= item
->GetCurrentImage();
3279 if ( image
!= NO_IMAGE
)
3281 if ( m_imageListNormal
)
3283 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
3288 int total_h
= (image_h
> text_h
) ? image_h
: text_h
;
3291 total_h
+= 2; // at least 2 pixels
3293 total_h
+= total_h
/10; // otherwise 10% extra spacing
3295 item
->SetHeight(total_h
);
3296 if (total_h
>m_lineHeight
)
3297 m_lineHeight
=total_h
;
3299 item
->SetWidth(image_w
+text_w
+2);
3302 // -----------------------------------------------------------------------------
3303 // for developper : y is now the top of the level
3304 // not the middle of it !
3305 void wxGenericTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
3307 int x
= level
*m_indent
;
3308 if (!HasFlag(wxTR_HIDE_ROOT
))
3312 else if (level
== 0)
3314 // a hidden root is not evaluated, but its
3315 // children are always calculated
3319 CalculateSize( item
, dc
);
3322 item
->SetX( x
+m_spacing
);
3324 y
+= GetLineHeight(item
);
3326 if ( !item
->IsExpanded() )
3328 // we don't need to calculate collapsed branches
3333 wxArrayGenericTreeItems
& children
= item
->GetChildren();
3334 size_t n
, count
= children
.Count();
3336 for (n
= 0; n
< count
; ++n
)
3337 CalculateLevel( children
[n
], dc
, level
, y
); // recurse
3340 void wxGenericTreeCtrl::CalculatePositions()
3342 if ( !m_anchor
) return;
3344 wxClientDC
dc(this);
3347 dc
.SetFont( m_normalFont
);
3349 dc
.SetPen( m_dottedPen
);
3350 //if(GetImageList() == NULL)
3351 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
3354 CalculateLevel( m_anchor
, dc
, 0, y
); // start recursion
3357 void wxGenericTreeCtrl::RefreshSubtree(wxGenericTreeItem
*item
)
3359 if (m_dirty
) return;
3360 if (m_freezeCount
) return;
3362 wxSize client
= GetClientSize();
3365 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3366 rect
.width
= client
.x
;
3367 rect
.height
= client
.y
;
3369 Refresh(true, &rect
);
3371 AdjustMyScrollbars();
3374 void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
3376 if (m_dirty
) return;
3377 if (m_freezeCount
) return;
3380 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3381 rect
.width
= GetClientSize().x
;
3382 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
3384 Refresh(true, &rect
);
3387 void wxGenericTreeCtrl::RefreshSelected()
3389 if (m_freezeCount
) return;
3391 // TODO: this is awfully inefficient, we should keep the list of all
3392 // selected items internally, should be much faster
3394 RefreshSelectedUnder(m_anchor
);
3397 void wxGenericTreeCtrl::RefreshSelectedUnder(wxGenericTreeItem
*item
)
3399 if (m_freezeCount
) return;
3401 if ( item
->IsSelected() )
3404 const wxArrayGenericTreeItems
& children
= item
->GetChildren();
3405 size_t count
= children
.GetCount();
3406 for ( size_t n
= 0; n
< count
; n
++ )
3408 RefreshSelectedUnder(children
[n
]);
3412 void wxGenericTreeCtrl::Freeze()
3417 void wxGenericTreeCtrl::Thaw()
3419 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen tree control?") );
3421 if ( !--m_freezeCount
)
3427 // ----------------------------------------------------------------------------
3428 // changing colours: we need to refresh the tree control
3429 // ----------------------------------------------------------------------------
3431 bool wxGenericTreeCtrl::SetBackgroundColour(const wxColour
& colour
)
3433 if ( !wxWindow::SetBackgroundColour(colour
) )
3436 if (m_freezeCount
) return true;
3443 bool wxGenericTreeCtrl::SetForegroundColour(const wxColour
& colour
)
3445 if ( !wxWindow::SetForegroundColour(colour
) )
3448 if (m_freezeCount
) return true;
3455 // Process the tooltip event, to speed up event processing.
3456 // Doesn't actually get a tooltip.
3457 void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent
&event
)
3463 // NOTE: If using the wxListBox visual attributes works everywhere then this can
3464 // be removed, as well as the #else case below.
3465 #define _USE_VISATTR 0
3468 #include "wx/listbox.h"
3474 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
3476 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3480 // Use the same color scheme as wxListBox
3481 return wxListBox::GetClassDefaultAttributes(variant
);
3483 wxVisualAttributes attr
;
3484 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
3485 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
3486 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
3491 #endif // wxUSE_TREECTRL