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
, wxDefaultCoord
);
449 void wxTreeTextCtrl::OnKillFocus( wxFocusEvent
&event
)
454 // We must finish regardless of success, otherwise we'll get
459 // We must let the native text control handle focus, too, otherwise
460 // it could have problems with the cursor (e.g., in wxGTK):
464 // -----------------------------------------------------------------------------
466 // -----------------------------------------------------------------------------
468 wxGenericTreeItem::wxGenericTreeItem(wxGenericTreeItem
*parent
,
469 const wxString
& text
,
470 int image
, int selImage
,
471 wxTreeItemData
*data
)
474 m_images
[wxTreeItemIcon_Normal
] = image
;
475 m_images
[wxTreeItemIcon_Selected
] = selImage
;
476 m_images
[wxTreeItemIcon_Expanded
] = NO_IMAGE
;
477 m_images
[wxTreeItemIcon_SelectedExpanded
] = NO_IMAGE
;
482 m_isCollapsed
= true;
483 m_hasHilight
= false;
489 m_attr
= (wxTreeItemAttr
*)NULL
;
492 // We don't know the height here yet.
497 wxGenericTreeItem::~wxGenericTreeItem()
501 if (m_ownsAttr
) delete m_attr
;
503 wxASSERT_MSG( m_children
.IsEmpty(),
504 wxT("please call DeleteChildren() before deleting the item") );
507 void wxGenericTreeItem::DeleteChildren(wxGenericTreeCtrl
*tree
)
509 size_t count
= m_children
.Count();
510 for ( size_t n
= 0; n
< count
; n
++ )
512 wxGenericTreeItem
*child
= m_children
[n
];
514 tree
->SendDeleteEvent(child
);
516 child
->DeleteChildren(tree
);
523 void wxGenericTreeItem::SetText( const wxString
&text
)
528 size_t wxGenericTreeItem::GetChildrenCount(bool recursively
) const
530 size_t count
= m_children
.Count();
534 size_t total
= count
;
535 for (size_t n
= 0; n
< count
; ++n
)
537 total
+= m_children
[n
]->GetChildrenCount();
543 void wxGenericTreeItem::GetSize( int &x
, int &y
,
544 const wxGenericTreeCtrl
*theButton
)
546 int bottomY
=m_y
+theButton
->GetLineHeight(this);
547 if ( y
< bottomY
) y
= bottomY
;
548 int width
= m_x
+ m_width
;
549 if ( x
< width
) x
= width
;
553 size_t count
= m_children
.Count();
554 for ( size_t n
= 0; n
< count
; ++n
)
556 m_children
[n
]->GetSize( x
, y
, theButton
);
561 wxGenericTreeItem
*wxGenericTreeItem::HitTest(const wxPoint
& point
,
562 const wxGenericTreeCtrl
*theCtrl
,
566 // for a hidden root node, don't evaluate it, but do evaluate children
567 if ( !(level
== 0 && theCtrl
->HasFlag(wxTR_HIDE_ROOT
)) )
570 int h
= theCtrl
->GetLineHeight(this);
571 if ((point
.y
> m_y
) && (point
.y
< m_y
+ h
))
573 int y_mid
= m_y
+ h
/2;
574 if (point
.y
< y_mid
)
575 flags
|= wxTREE_HITTEST_ONITEMUPPERPART
;
577 flags
|= wxTREE_HITTEST_ONITEMLOWERPART
;
579 int xCross
= m_x
- theCtrl
->GetSpacing();
581 // according to the drawing code the triangels are drawn
582 // at -4 , -4 from the position up to +10/+10 max
583 if ((point
.x
> xCross
-4) && (point
.x
< xCross
+10) &&
584 (point
.y
> y_mid
-4) && (point
.y
< y_mid
+10) &&
585 HasPlus() && theCtrl
->HasButtons() )
587 // 5 is the size of the plus sign
588 if ((point
.x
> xCross
-6) && (point
.x
< xCross
+6) &&
589 (point
.y
> y_mid
-6) && (point
.y
< y_mid
+6) &&
590 HasPlus() && theCtrl
->HasButtons() )
593 flags
|= wxTREE_HITTEST_ONITEMBUTTON
;
597 if ((point
.x
>= m_x
) && (point
.x
<= m_x
+m_width
))
602 // assuming every image (normal and selected) has the same size!
603 if ( (GetImage() != NO_IMAGE
) && theCtrl
->m_imageListNormal
)
604 theCtrl
->m_imageListNormal
->GetSize(GetImage(),
607 if ((image_w
!= -1) && (point
.x
<= m_x
+ image_w
+ 1))
608 flags
|= wxTREE_HITTEST_ONITEMICON
;
610 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
616 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
617 if (point
.x
> m_x
+m_width
)
618 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
623 // if children are expanded, fall through to evaluate them
624 if (m_isCollapsed
) return (wxGenericTreeItem
*) NULL
;
628 size_t count
= m_children
.Count();
629 for ( size_t n
= 0; n
< count
; n
++ )
631 wxGenericTreeItem
*res
= m_children
[n
]->HitTest( point
,
639 return (wxGenericTreeItem
*) NULL
;
642 int wxGenericTreeItem::GetCurrentImage() const
644 int image
= NO_IMAGE
;
649 image
= GetImage(wxTreeItemIcon_SelectedExpanded
);
652 if ( image
== NO_IMAGE
)
654 // we usually fall back to the normal item, but try just the
655 // expanded one (and not selected) first in this case
656 image
= GetImage(wxTreeItemIcon_Expanded
);
662 image
= GetImage(wxTreeItemIcon_Selected
);
665 // maybe it doesn't have the specific image we want,
666 // try the default one instead
667 if ( image
== NO_IMAGE
) image
= GetImage();
672 // -----------------------------------------------------------------------------
673 // wxGenericTreeCtrl implementation
674 // -----------------------------------------------------------------------------
676 IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl
, wxScrolledWindow
)
678 BEGIN_EVENT_TABLE(wxGenericTreeCtrl
,wxScrolledWindow
)
679 EVT_PAINT (wxGenericTreeCtrl::OnPaint
)
680 EVT_MOUSE_EVENTS (wxGenericTreeCtrl::OnMouse
)
681 EVT_CHAR (wxGenericTreeCtrl::OnChar
)
682 EVT_SET_FOCUS (wxGenericTreeCtrl::OnSetFocus
)
683 EVT_KILL_FOCUS (wxGenericTreeCtrl::OnKillFocus
)
684 EVT_TREE_ITEM_GETTOOLTIP(wxID_ANY
, wxGenericTreeCtrl::OnGetToolTip
)
687 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
689 * wxTreeCtrl has to be a real class or we have problems with
690 * the run-time information.
693 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxGenericTreeCtrl
)
696 // -----------------------------------------------------------------------------
697 // construction/destruction
698 // -----------------------------------------------------------------------------
700 void wxGenericTreeCtrl::Init()
702 m_current
= m_key_current
= m_anchor
= m_select_me
= (wxGenericTreeItem
*) NULL
;
710 m_hilightBrush
= new wxBrush
712 wxSystemSettings::GetColour
714 wxSYS_COLOUR_HIGHLIGHT
719 m_hilightUnfocusedBrush
= new wxBrush
721 wxSystemSettings::GetColour
723 wxSYS_COLOUR_BTNSHADOW
728 m_imageListNormal
= m_imageListButtons
=
729 m_imageListState
= (wxImageList
*) NULL
;
730 m_ownsImageListNormal
= m_ownsImageListButtons
=
731 m_ownsImageListState
= false;
734 m_isDragging
= false;
735 m_dropTarget
= m_oldSelection
= NULL
;
739 m_renameTimer
= NULL
;
744 m_lastOnSame
= false;
746 #if defined( __WXMAC__ ) && __WXMAC_CARBON__
747 m_normalFont
.MacCreateThemeFont( kThemeViewsFont
) ;
749 m_normalFont
= wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT
);
751 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
752 m_normalFont
.GetFamily(),
753 m_normalFont
.GetStyle(),
755 m_normalFont
.GetUnderlined(),
756 m_normalFont
.GetFaceName(),
757 m_normalFont
.GetEncoding());
760 bool wxGenericTreeCtrl::Create(wxWindow
*parent
,
765 const wxValidator
& wxVALIDATOR_PARAM(validator
),
766 const wxString
& name
)
770 wxGetOsVersion( &major
, &minor
);
772 style
&= ~wxTR_LINES_AT_ROOT
;
773 style
|= wxTR_NO_LINES
;
775 style
|= wxTR_ROW_LINES
;
778 wxScrolledWindow::Create( parent
, id
, pos
, size
,
779 style
|wxHSCROLL
|wxVSCROLL
, name
);
781 // If the tree display has no buttons, but does have
782 // connecting lines, we can use a narrower layout.
783 // It may not be a good idea to force this...
784 if (!HasButtons() && !HasFlag(wxTR_NO_LINES
))
791 SetValidator( validator
);
794 wxVisualAttributes attr
= GetDefaultAttributes();
795 SetOwnForegroundColour( attr
.colFg
);
796 SetOwnBackgroundColour( attr
.colBg
);
798 SetOwnFont(attr
.font
);
800 // m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86
801 m_dottedPen
= wxPen( wxT("grey"), 0, 0 );
808 wxGenericTreeCtrl::~wxGenericTreeCtrl()
810 delete m_hilightBrush
;
811 delete m_hilightUnfocusedBrush
;
815 delete m_renameTimer
;
818 if (m_ownsImageListNormal
)
819 delete m_imageListNormal
;
820 if (m_ownsImageListState
)
821 delete m_imageListState
;
822 if (m_ownsImageListButtons
)
823 delete m_imageListButtons
;
826 // -----------------------------------------------------------------------------
828 // -----------------------------------------------------------------------------
830 size_t wxGenericTreeCtrl::GetCount() const
838 size_t count
= m_anchor
->GetChildrenCount();
839 if ( !HasFlag(wxTR_HIDE_ROOT
) )
841 // take the root itself into account
848 void wxGenericTreeCtrl::SetIndent(unsigned int indent
)
850 m_indent
= (unsigned short) indent
;
854 void wxGenericTreeCtrl::SetSpacing(unsigned int spacing
)
856 m_spacing
= (unsigned short) spacing
;
861 wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
,
862 bool recursively
) const
864 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
866 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
869 void wxGenericTreeCtrl::SetWindowStyle(const long styles
)
871 if (!HasFlag(wxTR_HIDE_ROOT
) && (styles
& wxTR_HIDE_ROOT
))
873 // if we will hide the root, make sure children are visible
874 m_anchor
->SetHasPlus();
876 CalculatePositions();
879 // right now, just sets the styles. Eventually, we may
880 // want to update the inherited styles, but right now
881 // none of the parents has updatable styles
882 m_windowStyle
= styles
;
886 // -----------------------------------------------------------------------------
887 // functions to work with tree items
888 // -----------------------------------------------------------------------------
890 wxString
wxGenericTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
892 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
894 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetText();
897 int wxGenericTreeCtrl::GetItemImage(const wxTreeItemId
& item
,
898 wxTreeItemIcon which
) const
900 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
902 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetImage(which
);
905 wxTreeItemData
*wxGenericTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
907 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
909 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetData();
912 wxColour
wxGenericTreeCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
914 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
916 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
917 return pItem
->Attr().GetTextColour();
920 wxColour
wxGenericTreeCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
) const
922 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
924 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
925 return pItem
->Attr().GetBackgroundColour();
928 wxFont
wxGenericTreeCtrl::GetItemFont(const wxTreeItemId
& item
) const
930 wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") );
932 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
933 return pItem
->Attr().GetFont();
936 void wxGenericTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
938 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
941 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
942 pItem
->SetText(text
);
943 CalculateSize(pItem
, dc
);
947 void wxGenericTreeCtrl::SetItemImage(const wxTreeItemId
& item
,
949 wxTreeItemIcon which
)
951 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
953 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
954 pItem
->SetImage(image
, which
);
957 CalculateSize(pItem
, dc
);
961 void wxGenericTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
963 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
968 ((wxGenericTreeItem
*) item
.m_pItem
)->SetData(data
);
971 void wxGenericTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
973 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
975 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
976 pItem
->SetHasPlus(has
);
980 void wxGenericTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
982 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
984 // avoid redrawing the tree if no real change
985 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
986 if ( pItem
->IsBold() != bold
)
988 pItem
->SetBold(bold
);
993 void wxGenericTreeCtrl::SetItemTextColour(const wxTreeItemId
& item
,
996 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
998 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
999 pItem
->Attr().SetTextColour(col
);
1003 void wxGenericTreeCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
1004 const wxColour
& col
)
1006 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1008 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1009 pItem
->Attr().SetBackgroundColour(col
);
1013 void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
)
1015 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1017 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1018 pItem
->Attr().SetFont(font
);
1022 bool wxGenericTreeCtrl::SetFont( const wxFont
&font
)
1024 wxScrolledWindow::SetFont(font
);
1026 m_normalFont
= font
;
1027 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
1028 m_normalFont
.GetFamily(),
1029 m_normalFont
.GetStyle(),
1031 m_normalFont
.GetUnderlined(),
1032 m_normalFont
.GetFaceName(),
1033 m_normalFont
.GetEncoding());
1039 // -----------------------------------------------------------------------------
1040 // item status inquiries
1041 // -----------------------------------------------------------------------------
1043 bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
1045 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1047 // An item is only visible if it's not a descendant of a collapsed item
1048 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1049 wxGenericTreeItem
* parent
= pItem
->GetParent();
1052 if (!parent
->IsExpanded())
1054 parent
= parent
->GetParent();
1058 GetViewStart(& startX
, & startY
);
1060 wxSize clientSize
= GetClientSize();
1063 if (!GetBoundingRect(item
, rect
))
1065 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
1067 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
1069 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
1075 bool wxGenericTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
1077 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1079 // consider that the item does have children if it has the "+" button: it
1080 // might not have them (if it had never been expanded yet) but then it
1081 // could have them as well and it's better to err on this side rather than
1082 // disabling some operations which are restricted to the items with
1083 // children for an item which does have them
1084 return ((wxGenericTreeItem
*) item
.m_pItem
)->HasPlus();
1087 bool wxGenericTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
1089 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1091 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsExpanded();
1094 bool wxGenericTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
1096 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1098 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsSelected();
1101 bool wxGenericTreeCtrl::IsBold(const wxTreeItemId
& item
) const
1103 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1105 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsBold();
1108 // -----------------------------------------------------------------------------
1110 // -----------------------------------------------------------------------------
1112 wxTreeItemId
wxGenericTreeCtrl::GetItemParent(const wxTreeItemId
& item
) const
1114 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1116 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetParent();
1119 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1120 wxTreeItemIdValue
& cookie
) const
1122 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1125 return GetNextChild(item
, cookie
);
1128 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1129 wxTreeItemIdValue
& cookie
) const
1131 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1133 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1135 // it's ok to cast cookie to size_t, we never have indices big enough to
1136 // overflow "void *"
1137 size_t *pIndex
= (size_t *)&cookie
;
1138 if ( *pIndex
< children
.Count() )
1140 return children
.Item((*pIndex
)++);
1144 // there are no more of them
1145 return wxTreeItemId();
1149 #if WXWIN_COMPATIBILITY_2_4
1151 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1154 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1157 return GetNextChild(item
, cookie
);
1160 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1163 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1165 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1166 if ( (size_t)cookie
< children
.Count() )
1168 return children
.Item((size_t)cookie
++);
1172 // there are no more of them
1173 return wxTreeItemId();
1177 #endif // WXWIN_COMPATIBILITY_2_4
1179 wxTreeItemId
wxGenericTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
1181 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1183 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1184 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
1187 wxTreeItemId
wxGenericTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
1189 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1191 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1192 wxGenericTreeItem
*parent
= i
->GetParent();
1193 if ( parent
== NULL
)
1195 // root item doesn't have any siblings
1196 return wxTreeItemId();
1199 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1200 int index
= siblings
.Index(i
);
1201 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1203 size_t n
= (size_t)(index
+ 1);
1204 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
1207 wxTreeItemId
wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
1209 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1211 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1212 wxGenericTreeItem
*parent
= i
->GetParent();
1213 if ( parent
== NULL
)
1215 // root item doesn't have any siblings
1216 return wxTreeItemId();
1219 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1220 int index
= siblings
.Index(i
);
1221 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1223 return index
== 0 ? wxTreeItemId()
1224 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
1227 // Only for internal use right now, but should probably be public
1228 wxTreeItemId
wxGenericTreeCtrl::GetNext(const wxTreeItemId
& item
) const
1230 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1232 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1234 // First see if there are any children.
1235 wxArrayGenericTreeItems
& children
= i
->GetChildren();
1236 if (children
.GetCount() > 0)
1238 return children
.Item(0);
1242 // Try a sibling of this or ancestor instead
1243 wxTreeItemId p
= item
;
1244 wxTreeItemId toFind
;
1247 toFind
= GetNextSibling(p
);
1248 p
= GetItemParent(p
);
1249 } while (p
.IsOk() && !toFind
.IsOk());
1254 wxTreeItemId
wxGenericTreeCtrl::GetFirstVisibleItem() const
1256 wxTreeItemId id
= GetRootItem();
1265 } while (id
.IsOk());
1267 return wxTreeItemId();
1270 wxTreeItemId
wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
1272 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1274 wxTreeItemId id
= item
;
1277 while (id
= GetNext(id
), id
.IsOk())
1283 return wxTreeItemId();
1286 wxTreeItemId
wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
1288 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1290 wxFAIL_MSG(wxT("not implemented"));
1292 return wxTreeItemId();
1295 // called by wxTextTreeCtrl when it marks itself for deletion
1296 void wxGenericTreeCtrl::ResetTextControl()
1301 // find the first item starting with the given prefix after the given item
1302 wxTreeItemId
wxGenericTreeCtrl::FindItem(const wxTreeItemId
& idParent
,
1303 const wxString
& prefixOrig
) const
1305 // match is case insensitive as this is more convenient to the user: having
1306 // to press Shift-letter to go to the item starting with a capital letter
1307 // would be too bothersome
1308 wxString prefix
= prefixOrig
.Lower();
1310 // determine the starting point: we shouldn't take the current item (this
1311 // allows to switch between two items starting with the same letter just by
1312 // pressing it) but we shouldn't jump to the next one if the user is
1313 // continuing to type as otherwise he might easily skip the item he wanted
1314 wxTreeItemId id
= idParent
;
1315 if ( prefix
.length() == 1 )
1320 // look for the item starting with the given prefix after it
1321 while ( id
.IsOk() && !GetItemText(id
).Lower().StartsWith(prefix
) )
1326 // if we haven't found anything...
1329 // ... wrap to the beginning
1331 if ( HasFlag(wxTR_HIDE_ROOT
) )
1333 // can't select virtual root
1337 // and try all the items (stop when we get to the one we started from)
1338 while ( id
!= idParent
&& !GetItemText(id
).Lower().StartsWith(prefix
) )
1347 // -----------------------------------------------------------------------------
1349 // -----------------------------------------------------------------------------
1351 wxTreeItemId
wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId
& parentId
,
1353 const wxString
& text
,
1354 int image
, int selImage
,
1355 wxTreeItemData
*data
)
1357 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1360 // should we give a warning here?
1361 return AddRoot(text
, image
, selImage
, data
);
1364 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1366 wxGenericTreeItem
*item
=
1367 new wxGenericTreeItem( parent
, text
, image
, selImage
, data
);
1371 data
->m_pItem
= item
;
1374 parent
->Insert( item
, previous
);
1379 wxTreeItemId
wxGenericTreeCtrl::AddRoot(const wxString
& text
,
1380 int image
, int selImage
,
1381 wxTreeItemData
*data
)
1383 wxCHECK_MSG( !m_anchor
, wxTreeItemId(), wxT("tree can have only one root") );
1385 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1387 m_anchor
= new wxGenericTreeItem((wxGenericTreeItem
*)NULL
, text
,
1388 image
, selImage
, data
);
1391 data
->m_pItem
= m_anchor
;
1394 if (HasFlag(wxTR_HIDE_ROOT
))
1396 // if root is hidden, make sure we can navigate
1398 m_anchor
->SetHasPlus();
1400 CalculatePositions();
1403 if (!HasFlag(wxTR_MULTIPLE
))
1405 m_current
= m_key_current
= m_anchor
;
1406 m_current
->SetHilight( true );
1412 wxTreeItemId
wxGenericTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
1413 const wxString
& text
,
1414 int image
, int selImage
,
1415 wxTreeItemData
*data
)
1417 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
1420 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1421 const wxTreeItemId
& idPrevious
,
1422 const wxString
& text
,
1423 int image
, int selImage
,
1424 wxTreeItemData
*data
)
1426 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1429 // should we give a warning here?
1430 return AddRoot(text
, image
, selImage
, data
);
1434 if (idPrevious
.IsOk())
1436 index
= parent
->GetChildren().Index((wxGenericTreeItem
*) idPrevious
.m_pItem
);
1437 wxASSERT_MSG( index
!= wxNOT_FOUND
,
1438 wxT("previous item in wxGenericTreeCtrl::InsertItem() is not a sibling") );
1441 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
1444 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1446 const wxString
& text
,
1447 int image
, int selImage
,
1448 wxTreeItemData
*data
)
1450 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1453 // should we give a warning here?
1454 return AddRoot(text
, image
, selImage
, data
);
1457 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
1460 wxTreeItemId
wxGenericTreeCtrl::AppendItem(const wxTreeItemId
& parentId
,
1461 const wxString
& text
,
1462 int image
, int selImage
,
1463 wxTreeItemData
*data
)
1465 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1468 // should we give a warning here?
1469 return AddRoot(text
, image
, selImage
, data
);
1472 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
1473 image
, selImage
, data
);
1476 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem
*item
)
1478 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, GetId() );
1479 event
.m_item
= item
;
1480 event
.SetEventObject( this );
1481 ProcessEvent( event
);
1484 void wxGenericTreeCtrl::DeleteChildren(const wxTreeItemId
& itemId
)
1486 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1488 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1489 item
->DeleteChildren(this);
1492 void wxGenericTreeCtrl::Delete(const wxTreeItemId
& itemId
)
1494 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1496 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1498 wxGenericTreeItem
*parent
= item
->GetParent();
1500 // don't keep stale pointers around!
1501 if ( IsDescendantOf(item
, m_key_current
) )
1503 // Don't silently change the selection:
1504 // do it properly in idle time, so event
1505 // handlers get called.
1507 // m_key_current = parent;
1508 m_key_current
= NULL
;
1511 // m_select_me records whether we need to select
1512 // a different item, in idle time.
1513 if ( m_select_me
&& IsDescendantOf(item
, m_select_me
) )
1515 m_select_me
= parent
;
1518 if ( IsDescendantOf(item
, m_current
) )
1520 // Don't silently change the selection:
1521 // do it properly in idle time, so event
1522 // handlers get called.
1524 // m_current = parent;
1526 m_select_me
= parent
;
1529 // remove the item from the tree
1532 parent
->GetChildren().Remove( item
); // remove by value
1534 else // deleting the root
1536 // nothing will be left in the tree
1540 // and delete all of its children and the item itself now
1541 item
->DeleteChildren(this);
1542 SendDeleteEvent(item
);
1546 void wxGenericTreeCtrl::DeleteAllItems()
1554 void wxGenericTreeCtrl::Expand(const wxTreeItemId
& itemId
)
1556 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1558 wxCHECK_RET( item
, _T("invalid item in wxGenericTreeCtrl::Expand") );
1559 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1560 _T("can't expand hidden root") );
1562 if ( !item
->HasPlus() )
1565 if ( item
->IsExpanded() )
1568 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, GetId() );
1569 event
.m_item
= item
;
1570 event
.SetEventObject( this );
1572 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1574 // cancelled by program
1579 CalculatePositions();
1581 RefreshSubtree(item
);
1583 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
1584 ProcessEvent( event
);
1587 void wxGenericTreeCtrl::ExpandAll(const wxTreeItemId
& item
)
1589 if ( !HasFlag(wxTR_HIDE_ROOT
) || item
!= GetRootItem())
1592 if ( !IsExpanded(item
) )
1596 wxTreeItemIdValue cookie
;
1597 wxTreeItemId child
= GetFirstChild(item
, cookie
);
1598 while ( child
.IsOk() )
1602 child
= GetNextChild(item
, cookie
);
1606 void wxGenericTreeCtrl::Collapse(const wxTreeItemId
& itemId
)
1608 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1609 _T("can't collapse hidden root") );
1611 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1613 if ( !item
->IsExpanded() )
1616 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, GetId() );
1617 event
.m_item
= item
;
1618 event
.SetEventObject( this );
1619 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1621 // cancelled by program
1627 #if 0 // TODO why should items be collapsed recursively?
1628 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1629 size_t count
= children
.Count();
1630 for ( size_t n
= 0; n
< count
; n
++ )
1632 Collapse(children
[n
]);
1636 CalculatePositions();
1638 RefreshSubtree(item
);
1640 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
1641 ProcessEvent( event
);
1644 void wxGenericTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
1647 DeleteChildren(item
);
1650 void wxGenericTreeCtrl::Toggle(const wxTreeItemId
& itemId
)
1652 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1654 if (item
->IsExpanded())
1660 void wxGenericTreeCtrl::Unselect()
1664 m_current
->SetHilight( false );
1665 RefreshLine( m_current
);
1672 void wxGenericTreeCtrl::UnselectAllChildren(wxGenericTreeItem
*item
)
1674 if (item
->IsSelected())
1676 item
->SetHilight(false);
1680 if (item
->HasChildren())
1682 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1683 size_t count
= children
.Count();
1684 for ( size_t n
= 0; n
< count
; ++n
)
1686 UnselectAllChildren(children
[n
]);
1691 void wxGenericTreeCtrl::UnselectAll()
1693 wxTreeItemId rootItem
= GetRootItem();
1695 // the tree might not have the root item at all
1698 UnselectAllChildren((wxGenericTreeItem
*) rootItem
.m_pItem
);
1702 // Recursive function !
1703 // To stop we must have crt_item<last_item
1705 // Tag all next children, when no more children,
1706 // Move to parent (not to tag)
1707 // Keep going... if we found last_item, we stop.
1708 bool wxGenericTreeCtrl::TagNextChildren(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1710 wxGenericTreeItem
*parent
= crt_item
->GetParent();
1712 if (parent
== NULL
) // This is root item
1713 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
1715 wxArrayGenericTreeItems
& children
= parent
->GetChildren();
1716 int index
= children
.Index(crt_item
);
1717 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1719 size_t count
= children
.Count();
1720 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
1722 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return true;
1725 return TagNextChildren(parent
, last_item
, select
);
1728 bool wxGenericTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1730 crt_item
->SetHilight(select
);
1731 RefreshLine(crt_item
);
1733 if (crt_item
==last_item
)
1736 if (crt_item
->HasChildren())
1738 wxArrayGenericTreeItems
& children
= crt_item
->GetChildren();
1739 size_t count
= children
.Count();
1740 for ( size_t n
= 0; n
< count
; ++n
)
1742 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
1750 void wxGenericTreeCtrl::SelectItemRange(wxGenericTreeItem
*item1
, wxGenericTreeItem
*item2
)
1754 // item2 is not necessary after item1
1755 // choice first' and 'last' between item1 and item2
1756 wxGenericTreeItem
*first
= (item1
->GetY()<item2
->GetY()) ? item1
: item2
;
1757 wxGenericTreeItem
*last
= (item1
->GetY()<item2
->GetY()) ? item2
: item1
;
1759 bool select
= m_current
->IsSelected();
1761 if ( TagAllChildrenUntilLast(first
,last
,select
) )
1764 TagNextChildren(first
,last
,select
);
1767 void wxGenericTreeCtrl::DoSelectItem(const wxTreeItemId
& itemId
,
1768 bool unselect_others
,
1769 bool extended_select
)
1771 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
1775 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
1776 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1778 //wxCHECK_RET( ( (!unselect_others) && is_single),
1779 // wxT("this is a single selection tree") );
1781 // to keep going anyhow !!!
1784 if (item
->IsSelected())
1785 return; // nothing to do
1786 unselect_others
= true;
1787 extended_select
= false;
1789 else if ( unselect_others
&& item
->IsSelected() )
1791 // selection change if there is more than one item currently selected
1792 wxArrayTreeItemIds selected_items
;
1793 if ( GetSelections(selected_items
) == 1 )
1797 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, GetId() );
1798 event
.m_item
= item
;
1799 event
.m_itemOld
= m_current
;
1800 event
.SetEventObject( this );
1801 // TODO : Here we don't send any selection mode yet !
1803 if ( GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed() )
1806 wxTreeItemId parent
= GetItemParent( itemId
);
1807 while (parent
.IsOk())
1809 if (!IsExpanded(parent
))
1812 parent
= GetItemParent( parent
);
1815 EnsureVisible( itemId
);
1818 if (unselect_others
)
1820 if (is_single
) Unselect(); // to speed up thing
1825 if (extended_select
)
1829 m_current
= m_key_current
= (wxGenericTreeItem
*) GetRootItem().m_pItem
;
1832 // don't change the mark (m_current)
1833 SelectItemRange(m_current
, item
);
1837 bool select
= true; // the default
1839 // Check if we need to toggle hilight (ctrl mode)
1840 if (!unselect_others
)
1841 select
=!item
->IsSelected();
1843 m_current
= m_key_current
= item
;
1844 m_current
->SetHilight(select
);
1845 RefreshLine( m_current
);
1848 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
1849 GetEventHandler()->ProcessEvent( event
);
1852 void wxGenericTreeCtrl::SelectItem(const wxTreeItemId
& itemId
, bool select
)
1856 DoSelectItem(itemId
);
1860 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1861 wxCHECK_RET( item
, wxT("SelectItem(): invalid tree item") );
1863 item
->SetHilight(false);
1868 void wxGenericTreeCtrl::FillArray(wxGenericTreeItem
*item
,
1869 wxArrayTreeItemIds
&array
) const
1871 if ( item
->IsSelected() )
1872 array
.Add(wxTreeItemId(item
));
1874 if ( item
->HasChildren() )
1876 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1877 size_t count
= children
.GetCount();
1878 for ( size_t n
= 0; n
< count
; ++n
)
1879 FillArray(children
[n
], array
);
1883 size_t wxGenericTreeCtrl::GetSelections(wxArrayTreeItemIds
&array
) const
1886 wxTreeItemId idRoot
= GetRootItem();
1887 if ( idRoot
.IsOk() )
1889 FillArray((wxGenericTreeItem
*) idRoot
.m_pItem
, array
);
1891 //else: the tree is empty, so no selections
1893 return array
.Count();
1896 void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
1898 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1900 if (!item
.IsOk()) return;
1902 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1904 // first expand all parent branches
1905 wxGenericTreeItem
*parent
= gitem
->GetParent();
1907 if ( HasFlag(wxTR_HIDE_ROOT
) )
1909 while ( parent
&& parent
!= m_anchor
)
1912 parent
= parent
->GetParent();
1920 parent
= parent
->GetParent();
1924 //if (parent) CalculatePositions();
1929 void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId
&item
)
1931 if (!item
.IsOk()) return;
1933 // We have to call this here because the label in
1934 // question might just have been added and no screen
1935 // update taken place.
1937 #if defined( __WXMSW__ ) || defined(__WXMAC__)
1942 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1944 // now scroll to the item
1945 int item_y
= gitem
->GetY();
1949 GetViewStart( &start_x
, &start_y
);
1950 start_y
*= PIXELS_PER_UNIT
;
1954 GetClientSize( &client_w
, &client_h
);
1956 if (item_y
< start_y
+3)
1961 m_anchor
->GetSize( x
, y
, this );
1962 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1963 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1964 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1965 // Item should appear at top
1966 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
1968 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
1973 m_anchor
->GetSize( x
, y
, this );
1974 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1975 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1976 item_y
+= PIXELS_PER_UNIT
+2;
1977 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1978 // Item should appear at bottom
1979 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
);
1983 // FIXME: tree sorting functions are not reentrant and not MT-safe!
1984 static wxGenericTreeCtrl
*s_treeBeingSorted
= NULL
;
1986 static int LINKAGEMODE
tree_ctrl_compare_func(wxGenericTreeItem
**item1
,
1987 wxGenericTreeItem
**item2
)
1989 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxGenericTreeCtrl::SortChildren()") );
1991 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
1994 int wxGenericTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
1995 const wxTreeItemId
& item2
)
1997 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
2000 void wxGenericTreeCtrl::SortChildren(const wxTreeItemId
& itemId
)
2002 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
2004 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
2006 wxCHECK_RET( !s_treeBeingSorted
,
2007 wxT("wxGenericTreeCtrl::SortChildren is not reentrant") );
2009 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2010 if ( children
.Count() > 1 )
2014 s_treeBeingSorted
= this;
2015 children
.Sort(tree_ctrl_compare_func
);
2016 s_treeBeingSorted
= NULL
;
2018 //else: don't make the tree dirty as nothing changed
2021 wxImageList
*wxGenericTreeCtrl::GetImageList() const
2023 return m_imageListNormal
;
2026 wxImageList
*wxGenericTreeCtrl::GetButtonsImageList() const
2028 return m_imageListButtons
;
2031 wxImageList
*wxGenericTreeCtrl::GetStateImageList() const
2033 return m_imageListState
;
2036 void wxGenericTreeCtrl::CalculateLineHeight()
2038 wxClientDC
dc(this);
2039 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
2041 if ( m_imageListNormal
)
2043 // Calculate a m_lineHeight value from the normal Image sizes.
2044 // May be toggle off. Then wxGenericTreeCtrl will spread when
2045 // necessary (which might look ugly).
2046 int n
= m_imageListNormal
->GetImageCount();
2047 for (int i
= 0; i
< n
; i
++)
2049 int width
= 0, height
= 0;
2050 m_imageListNormal
->GetSize(i
, width
, height
);
2051 if (height
> m_lineHeight
) m_lineHeight
= height
;
2055 if (m_imageListButtons
)
2057 // Calculate a m_lineHeight value from the Button image sizes.
2058 // May be toggle off. Then wxGenericTreeCtrl will spread when
2059 // necessary (which might look ugly).
2060 int n
= m_imageListButtons
->GetImageCount();
2061 for (int i
= 0; i
< n
; i
++)
2063 int width
= 0, height
= 0;
2064 m_imageListButtons
->GetSize(i
, width
, height
);
2065 if (height
> m_lineHeight
) m_lineHeight
= height
;
2069 if (m_lineHeight
< 30)
2070 m_lineHeight
+= 2; // at least 2 pixels
2072 m_lineHeight
+= m_lineHeight
/10; // otherwise 10% extra spacing
2075 void wxGenericTreeCtrl::SetImageList(wxImageList
*imageList
)
2077 if (m_ownsImageListNormal
) delete m_imageListNormal
;
2078 m_imageListNormal
= imageList
;
2079 m_ownsImageListNormal
= false;
2081 // Don't do any drawing if we're setting the list to NULL,
2082 // since we may be in the process of deleting the tree control.
2084 CalculateLineHeight();
2087 void wxGenericTreeCtrl::SetStateImageList(wxImageList
*imageList
)
2089 if (m_ownsImageListState
) delete m_imageListState
;
2090 m_imageListState
= imageList
;
2091 m_ownsImageListState
= false;
2094 void wxGenericTreeCtrl::SetButtonsImageList(wxImageList
*imageList
)
2096 if (m_ownsImageListButtons
) delete m_imageListButtons
;
2097 m_imageListButtons
= imageList
;
2098 m_ownsImageListButtons
= false;
2100 CalculateLineHeight();
2103 void wxGenericTreeCtrl::AssignImageList(wxImageList
*imageList
)
2105 SetImageList(imageList
);
2106 m_ownsImageListNormal
= true;
2109 void wxGenericTreeCtrl::AssignStateImageList(wxImageList
*imageList
)
2111 SetStateImageList(imageList
);
2112 m_ownsImageListState
= true;
2115 void wxGenericTreeCtrl::AssignButtonsImageList(wxImageList
*imageList
)
2117 SetButtonsImageList(imageList
);
2118 m_ownsImageListButtons
= true;
2121 // -----------------------------------------------------------------------------
2123 // -----------------------------------------------------------------------------
2125 void wxGenericTreeCtrl::AdjustMyScrollbars()
2130 m_anchor
->GetSize( x
, y
, this );
2131 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2132 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2133 int x_pos
= GetScrollPos( wxHORIZONTAL
);
2134 int y_pos
= GetScrollPos( wxVERTICAL
);
2135 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
2139 SetScrollbars( 0, 0, 0, 0 );
2143 int wxGenericTreeCtrl::GetLineHeight(wxGenericTreeItem
*item
) const
2145 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
2146 return item
->GetHeight();
2148 return m_lineHeight
;
2151 void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem
*item
, wxDC
& dc
)
2153 // TODO implement "state" icon on items
2155 wxTreeItemAttr
*attr
= item
->GetAttributes();
2156 if ( attr
&& attr
->HasFont() )
2157 dc
.SetFont(attr
->GetFont());
2158 else if (item
->IsBold())
2159 dc
.SetFont(m_boldFont
);
2161 long text_w
= 0, text_h
= 0;
2162 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
2164 int image_h
= 0, image_w
= 0;
2165 int image
= item
->GetCurrentImage();
2166 if ( image
!= NO_IMAGE
)
2168 if ( m_imageListNormal
)
2170 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
2179 int total_h
= GetLineHeight(item
);
2181 if ( item
->IsSelected() )
2183 // under mac selections are only a rectangle in case they don't have the focus
2187 dc
.SetBrush( *wxTRANSPARENT_BRUSH
) ;
2188 dc
.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
) , 1 , wxSOLID
) ) ;
2192 dc
.SetBrush( *m_hilightBrush
) ;
2195 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
2201 if ( attr
&& attr
->HasBackgroundColour() )
2202 colBg
= attr
->GetBackgroundColour();
2204 colBg
= m_backgroundColour
;
2205 dc
.SetBrush(wxBrush(colBg
, wxSOLID
));
2208 int offset
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0;
2210 if ( HasFlag(wxTR_FULL_ROW_HIGHLIGHT
) )
2214 DoGetPosition(&x
, &y
);
2216 dc
.DrawRectangle(x
, item
->GetY()+offset
, w
, total_h
-offset
);
2220 if ( item
->IsSelected() && image
!= NO_IMAGE
)
2222 // If it's selected, and there's an image, then we should
2223 // take care to leave the area under the image painted in the
2224 // background colour.
2225 dc
.DrawRectangle( item
->GetX() + image_w
- 2, item
->GetY()+offset
,
2226 item
->GetWidth() - image_w
+ 2, total_h
-offset
);
2230 dc
.DrawRectangle( item
->GetX()-2, item
->GetY()+offset
,
2231 item
->GetWidth()+2, total_h
-offset
);
2235 if ( image
!= NO_IMAGE
)
2237 dc
.SetClippingRegion( item
->GetX(), item
->GetY(), image_w
-2, total_h
);
2238 m_imageListNormal
->Draw( image
, dc
,
2240 item
->GetY() +((total_h
> image_h
)?((total_h
-image_h
)/2):0),
2241 wxIMAGELIST_DRAW_TRANSPARENT
);
2242 dc
.DestroyClippingRegion();
2245 dc
.SetBackgroundMode(wxTRANSPARENT
);
2246 int extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
2247 dc
.DrawText( item
->GetText(),
2248 (wxCoord
)(image_w
+ item
->GetX()),
2249 (wxCoord
)(item
->GetY() + extraH
));
2251 // restore normal font
2252 dc
.SetFont( m_normalFont
);
2255 // Now y stands for the top of the item, whereas it used to stand for middle !
2256 void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
2258 int x
= level
*m_indent
;
2259 if (!HasFlag(wxTR_HIDE_ROOT
))
2263 else if (level
== 0)
2265 // always expand hidden root
2267 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2268 int count
= children
.Count();
2274 PaintLevel(children
[n
], dc
, 1, y
);
2275 } while (++n
< count
);
2277 if (!HasFlag(wxTR_NO_LINES
) && HasFlag(wxTR_LINES_AT_ROOT
) && count
> 0)
2279 // draw line down to last child
2280 origY
+= GetLineHeight(children
[0])>>1;
2281 oldY
+= GetLineHeight(children
[n
-1])>>1;
2282 dc
.DrawLine(3, origY
, 3, oldY
);
2288 item
->SetX(x
+m_spacing
);
2291 int h
= GetLineHeight(item
);
2293 int y_mid
= y_top
+ (h
>>1);
2296 int exposed_x
= dc
.LogicalToDeviceX(0);
2297 int exposed_y
= dc
.LogicalToDeviceY(y_top
);
2299 if (IsExposed(exposed_x
, exposed_y
, 10000, h
)) // 10000 = very much
2303 // don't draw rect outline if we already have the
2304 // background color under Mac
2305 (item
->IsSelected() && m_hasFocus
) ? wxBLACK_PEN
:
2306 #endif // !__WXMAC__
2310 if ( item
->IsSelected() )
2312 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
2316 wxTreeItemAttr
*attr
= item
->GetAttributes();
2317 if (attr
&& attr
->HasTextColour())
2318 colText
= attr
->GetTextColour();
2320 colText
= GetForegroundColour();
2324 dc
.SetTextForeground(colText
);
2328 PaintItem(item
, dc
);
2330 if (HasFlag(wxTR_ROW_LINES
))
2332 // if the background colour is white, choose a
2333 // contrasting color for the lines
2334 dc
.SetPen(*((GetBackgroundColour() == *wxWHITE
)
2335 ? wxMEDIUM_GREY_PEN
: wxWHITE_PEN
));
2336 dc
.DrawLine(0, y_top
, 10000, y_top
);
2337 dc
.DrawLine(0, y
, 10000, y
);
2340 // restore DC objects
2341 dc
.SetBrush(*wxWHITE_BRUSH
);
2342 dc
.SetPen(m_dottedPen
);
2343 dc
.SetTextForeground(*wxBLACK
);
2345 if ( !HasFlag(wxTR_NO_LINES
) )
2347 // draw the horizontal line here
2349 if (x
> (signed)m_indent
)
2350 x_start
-= m_indent
;
2351 else if (HasFlag(wxTR_LINES_AT_ROOT
))
2353 dc
.DrawLine(x_start
, y_mid
, x
+ m_spacing
, y_mid
);
2356 // should the item show a button?
2357 if ( item
->HasPlus() && HasButtons() )
2359 if ( m_imageListButtons
)
2361 // draw the image button here
2364 int image
= item
->IsExpanded() ? wxTreeItemIcon_Expanded
2365 : wxTreeItemIcon_Normal
;
2366 if ( item
->IsSelected() )
2367 image
+= wxTreeItemIcon_Selected
- wxTreeItemIcon_Normal
;
2369 m_imageListButtons
->GetSize(image
, image_w
, image_h
);
2370 int xx
= x
- image_w
/2;
2371 int yy
= y_mid
- image_h
/2;
2373 wxDCClipper
clip(dc
, xx
, yy
, image_w
, image_h
);
2374 m_imageListButtons
->Draw(image
, dc
, xx
, yy
,
2375 wxIMAGELIST_DRAW_TRANSPARENT
);
2377 else // no custom buttons
2379 static const int wImage
= 9;
2380 static const int hImage
= 9;
2383 if (item
->IsExpanded())
2384 flag
|= wxCONTROL_EXPANDED
;
2385 if (item
== m_underMouse
)
2386 flag
|= wxCONTROL_CURRENT
;
2388 wxRendererNative::Get().DrawTreeItemButton
2392 wxRect(x
- wImage
/2,
2401 if (item
->IsExpanded())
2403 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2404 int count
= children
.Count();
2411 PaintLevel(children
[n
], dc
, level
, y
);
2412 } while (++n
< count
);
2414 if (!HasFlag(wxTR_NO_LINES
) && count
> 0)
2416 // draw line down to last child
2417 oldY
+= GetLineHeight(children
[n
-1])>>1;
2418 if (HasButtons()) y_mid
+= 5;
2420 // Only draw the portion of the line that is visible, in case it is huge
2421 wxCoord xOrigin
=0, yOrigin
=0, width
, height
;
2422 dc
.GetDeviceOrigin(&xOrigin
, &yOrigin
);
2423 yOrigin
= abs(yOrigin
);
2424 GetClientSize(&width
, &height
);
2426 // Move end points to the begining/end of the view?
2427 if (y_mid
< yOrigin
)
2429 if (oldY
> yOrigin
+ height
)
2430 oldY
= yOrigin
+ height
;
2432 // after the adjustments if y_mid is larger than oldY then the line
2433 // isn't visible at all so don't draw anything
2435 dc
.DrawLine(x
, y_mid
, x
, oldY
);
2441 void wxGenericTreeCtrl::DrawDropEffect(wxGenericTreeItem
*item
)
2445 if ( item
->HasPlus() )
2447 // it's a folder, indicate it by a border
2452 // draw a line under the drop target because the item will be
2454 DrawLine(item
, true /* below */);
2457 SetCursor(wxCURSOR_BULLSEYE
);
2462 SetCursor(wxCURSOR_NO_ENTRY
);
2466 void wxGenericTreeCtrl::DrawBorder(const wxTreeItemId
&item
)
2468 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2470 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2472 wxClientDC
dc(this);
2474 dc
.SetLogicalFunction(wxINVERT
);
2475 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2477 int w
= i
->GetWidth() + 2;
2478 int h
= GetLineHeight(i
) + 2;
2480 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
2483 void wxGenericTreeCtrl::DrawLine(const wxTreeItemId
&item
, bool below
)
2485 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2487 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2489 wxClientDC
dc(this);
2491 dc
.SetLogicalFunction(wxINVERT
);
2497 y
+= GetLineHeight(i
) - 1;
2500 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
2503 // -----------------------------------------------------------------------------
2504 // wxWidgets callbacks
2505 // -----------------------------------------------------------------------------
2507 void wxGenericTreeCtrl::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2515 dc
.SetFont( m_normalFont
);
2516 dc
.SetPen( m_dottedPen
);
2518 // this is now done dynamically
2519 //if(GetImageList() == NULL)
2520 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
2523 PaintLevel( m_anchor
, dc
, 0, y
);
2526 void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent
&event
)
2535 void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent
&event
)
2544 void wxGenericTreeCtrl::OnChar( wxKeyEvent
&event
)
2546 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, GetId() );
2547 te
.m_evtKey
= event
;
2548 te
.SetEventObject( this );
2549 if ( GetEventHandler()->ProcessEvent( te
) )
2551 // intercepted by the user code
2555 if ( (m_current
== 0) || (m_key_current
== 0) )
2561 // how should the selection work for this event?
2562 bool is_multiple
, extended_select
, unselect_others
;
2563 EventFlagsToSelType(GetWindowStyleFlag(),
2565 event
.ControlDown(),
2566 is_multiple
, extended_select
, unselect_others
);
2570 // * : Expand all/Collapse all
2571 // ' ' | return : activate
2572 // up : go up (not last children!)
2574 // left : go to parent
2575 // right : open if parent and go next
2576 // home : go to root
2577 // end : go to last item without opening parents
2578 // alnum : start or continue searching for the item with this prefix
2579 int keyCode
= event
.GetKeyCode();
2584 if (m_current
->HasPlus() && !IsExpanded(m_current
))
2592 if ( !IsExpanded(m_current
) )
2595 ExpandAll(m_current
);
2598 //else: fall through to Collapse() it
2602 if (IsExpanded(m_current
))
2604 Collapse(m_current
);
2610 if ( !event
.HasModifiers() )
2612 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
2613 event
.m_item
= m_current
;
2614 event
.SetEventObject( this );
2615 GetEventHandler()->ProcessEvent( event
);
2618 // in any case, also generate the normal key event for this key,
2619 // even if we generated the ACTIVATED event above: this is what
2620 // wxMSW does and it makes sense because you might not want to
2621 // process ACTIVATED event at all and handle Space and Return
2622 // directly (and differently) which would be impossible otherwise
2626 // up goes to the previous sibling or to the last
2627 // of its children if it's expanded
2630 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
2633 prev
= GetItemParent( m_key_current
);
2634 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2636 break; // don't go to root if it is hidden
2640 wxTreeItemIdValue cookie
;
2641 wxTreeItemId current
= m_key_current
;
2642 // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be?
2643 if (current
== GetFirstChild( prev
, cookie
))
2645 // otherwise we return to where we came from
2646 DoSelectItem( prev
, unselect_others
, extended_select
);
2647 m_key_current
= (wxGenericTreeItem
*) prev
.m_pItem
;
2654 while ( IsExpanded(prev
) && HasChildren(prev
) )
2656 wxTreeItemId child
= GetLastChild(prev
);
2663 DoSelectItem( prev
, unselect_others
, extended_select
);
2664 m_key_current
=(wxGenericTreeItem
*) prev
.m_pItem
;
2669 // left arrow goes to the parent
2672 wxTreeItemId prev
= GetItemParent( m_current
);
2673 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2675 // don't go to root if it is hidden
2676 prev
= GetPrevSibling( m_current
);
2680 DoSelectItem( prev
, unselect_others
, extended_select
);
2686 // this works the same as the down arrow except that we
2687 // also expand the item if it wasn't expanded yet
2693 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
2695 wxTreeItemIdValue cookie
;
2696 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
2697 DoSelectItem( child
, unselect_others
, extended_select
);
2698 m_key_current
=(wxGenericTreeItem
*) child
.m_pItem
;
2702 wxTreeItemId next
= GetNextSibling( m_key_current
);
2705 wxTreeItemId current
= m_key_current
;
2706 while (current
.IsOk() && !next
)
2708 current
= GetItemParent( current
);
2709 if (current
) next
= GetNextSibling( current
);
2714 DoSelectItem( next
, unselect_others
, extended_select
);
2715 m_key_current
=(wxGenericTreeItem
*) next
.m_pItem
;
2721 // <End> selects the last visible tree item
2724 wxTreeItemId last
= GetRootItem();
2726 while ( last
.IsOk() && IsExpanded(last
) )
2728 wxTreeItemId lastChild
= GetLastChild(last
);
2730 // it may happen if the item was expanded but then all of
2731 // its children have been deleted - so IsExpanded() returned
2732 // true, but GetLastChild() returned invalid item
2741 DoSelectItem( last
, unselect_others
, extended_select
);
2746 // <Home> selects the root item
2749 wxTreeItemId prev
= GetRootItem();
2753 if ( HasFlag(wxTR_HIDE_ROOT
) )
2755 wxTreeItemIdValue cookie
;
2756 prev
= GetFirstChild(prev
, cookie
);
2761 DoSelectItem( prev
, unselect_others
, extended_select
);
2766 // do not use wxIsalnum() here
2767 if ( !event
.HasModifiers() &&
2768 ((keyCode
>= '0' && keyCode
<= '9') ||
2769 (keyCode
>= 'a' && keyCode
<= 'z') ||
2770 (keyCode
>= 'A' && keyCode
<= 'Z' )))
2772 // find the next item starting with the given prefix
2773 wxChar ch
= (wxChar
)keyCode
;
2775 wxTreeItemId id
= FindItem(m_current
, m_findPrefix
+ ch
);
2786 // also start the timer to reset the current prefix if the user
2787 // doesn't press any more alnum keys soon -- we wouldn't want
2788 // to use this prefix for a new item search
2791 m_findTimer
= new wxTreeFindTimer(this);
2794 m_findTimer
->Start(wxTreeFindTimer::DELAY
, wxTIMER_ONE_SHOT
);
2803 wxTreeItemId
wxGenericTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
2805 // JACS: removed wxYieldIfNeeded() because it can cause the window
2806 // to be deleted from under us if a close window event is pending
2811 if (point
.x
<0) flags
|= wxTREE_HITTEST_TOLEFT
;
2812 if (point
.x
>w
) flags
|= wxTREE_HITTEST_TORIGHT
;
2813 if (point
.y
<0) flags
|= wxTREE_HITTEST_ABOVE
;
2814 if (point
.y
>h
) flags
|= wxTREE_HITTEST_BELOW
;
2815 if (flags
) return wxTreeItemId();
2817 if (m_anchor
== NULL
)
2819 flags
= wxTREE_HITTEST_NOWHERE
;
2820 return wxTreeItemId();
2823 wxGenericTreeItem
*hit
= m_anchor
->HitTest(CalcUnscrolledPosition(point
),
2827 flags
= wxTREE_HITTEST_NOWHERE
;
2828 return wxTreeItemId();
2833 // get the bounding rectangle of the item (or of its label only)
2834 bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId
& item
,
2836 bool WXUNUSED(textOnly
)) const
2838 wxCHECK_MSG( item
.IsOk(), false, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
2840 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2843 GetViewStart(& startX
, & startY
);
2845 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
2846 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
2847 rect
.width
= i
->GetWidth();
2848 //rect.height = i->GetHeight();
2849 rect
.height
= GetLineHeight(i
);
2854 void wxGenericTreeCtrl::Edit( const wxTreeItemId
& item
)
2856 wxCHECK_RET( item
.IsOk(), _T("can't edit an invalid item") );
2858 wxGenericTreeItem
*itemEdit
= (wxGenericTreeItem
*)item
.m_pItem
;
2860 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, GetId() );
2861 te
.m_item
= itemEdit
;
2862 te
.SetEventObject( this );
2863 if ( GetEventHandler()->ProcessEvent( te
) && !te
.IsAllowed() )
2869 // We have to call this here because the label in
2870 // question might just have been added and no screen
2871 // update taken place.
2873 #if defined( __WXMSW__ ) || defined(__WXMAC__)
2879 m_textCtrl
= new wxTreeTextCtrl(this, itemEdit
);
2881 m_textCtrl
->SetFocus();
2884 // returns a pointer to the text edit control if the item is being
2885 // edited, NULL otherwise (it's assumed that no more than one item may
2886 // be edited simultaneously)
2887 wxTextCtrl
* wxGenericTreeCtrl::GetEditControl() const
2892 bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem
*item
,
2893 const wxString
& value
)
2895 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2897 le
.SetEventObject( this );
2899 le
.m_editCancelled
= false;
2901 return !GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2904 void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem
*item
)
2906 // let owner know that the edit was cancelled
2907 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2909 le
.SetEventObject( this );
2910 le
.m_label
= wxEmptyString
;
2911 le
.m_editCancelled
= true;
2913 GetEventHandler()->ProcessEvent( le
);
2919 void wxGenericTreeCtrl::OnRenameTimer()
2924 void wxGenericTreeCtrl::OnMouse( wxMouseEvent
&event
)
2926 if ( !m_anchor
) return;
2928 wxPoint pt
= CalcUnscrolledPosition(event
.GetPosition());
2930 // Is the mouse over a tree item button?
2932 wxGenericTreeItem
*thisItem
= m_anchor
->HitTest(pt
, this, flags
, 0);
2933 wxGenericTreeItem
*underMouse
= thisItem
;
2935 bool underMouseChanged
= (underMouse
!= m_underMouse
) ;
2936 #endif // wxUSE_TOOLTIPS
2939 (flags
& wxTREE_HITTEST_ONITEMBUTTON
) &&
2940 (!event
.LeftIsDown()) &&
2942 (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2950 if (underMouse
!= m_underMouse
)
2954 // unhighlight old item
2955 wxGenericTreeItem
*tmp
= m_underMouse
;
2956 m_underMouse
= NULL
;
2960 m_underMouse
= underMouse
;
2962 RefreshLine( m_underMouse
);
2966 // Determines what item we are hovering over and need a tooltip for
2967 wxTreeItemId hoverItem
= thisItem
;
2969 // We do not want a tooltip if we are dragging, or if the rename timer is running
2970 if (underMouseChanged
&& hoverItem
.IsOk() && !m_isDragging
&& (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2972 // Ask the tree control what tooltip (if any) should be shown
2973 wxTreeEvent
hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP
, GetId());
2974 hevent
.m_item
= hoverItem
;
2975 hevent
.SetEventObject(this);
2977 if ( GetEventHandler()->ProcessEvent(hevent
) && hevent
.IsAllowed() )
2979 SetToolTip(hevent
.m_label
);
2984 // we process left mouse up event (enables in-place edit), right down
2985 // (pass to the user code), left dbl click (activate item) and
2986 // dragging/moving events for items drag-and-drop
2987 if ( !(event
.LeftDown() ||
2989 event
.RightDown() ||
2990 event
.LeftDClick() ||
2992 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
3001 wxGenericTreeItem
*item
= m_anchor
->HitTest(pt
, this, flags
, 0);
3003 if ( event
.Dragging() && !m_isDragging
)
3005 if (m_dragCount
== 0)
3010 if (m_dragCount
!= 3)
3012 // wait until user drags a bit further...
3016 wxEventType command
= event
.RightIsDown()
3017 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
3018 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
3020 wxTreeEvent
nevent( command
, GetId() );
3021 nevent
.m_item
= m_current
;
3022 nevent
.SetEventObject(this);
3024 // by default the dragging is not supported, the user code must
3025 // explicitly allow the event for it to take place
3028 if ( GetEventHandler()->ProcessEvent(nevent
) && nevent
.IsAllowed() )
3030 // we're going to drag this item
3031 m_isDragging
= true;
3033 // remember the old cursor because we will change it while
3035 m_oldCursor
= m_cursor
;
3037 // in a single selection control, hide the selection temporarily
3038 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
3040 m_oldSelection
= (wxGenericTreeItem
*) GetSelection().m_pItem
;
3042 if ( m_oldSelection
)
3044 m_oldSelection
->SetHilight(false);
3045 RefreshLine(m_oldSelection
);
3052 else if ( event
.Moving() )
3054 if ( item
!= m_dropTarget
)
3056 // unhighlight the previous drop target
3057 DrawDropEffect(m_dropTarget
);
3059 m_dropTarget
= item
;
3061 // highlight the current drop target if any
3062 DrawDropEffect(m_dropTarget
);
3064 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3071 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
3073 // erase the highlighting
3074 DrawDropEffect(m_dropTarget
);
3076 if ( m_oldSelection
)
3078 m_oldSelection
->SetHilight(true);
3079 RefreshLine(m_oldSelection
);
3080 m_oldSelection
= (wxGenericTreeItem
*)NULL
;
3083 // generate the drag end event
3084 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
, GetId());
3086 event
.m_item
= item
;
3087 event
.m_pointDrag
= pt
;
3088 event
.SetEventObject(this);
3090 (void)GetEventHandler()->ProcessEvent(event
);
3092 m_isDragging
= false;
3093 m_dropTarget
= (wxGenericTreeItem
*)NULL
;
3097 SetCursor(m_oldCursor
);
3099 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3107 // here we process only the messages which happen on tree items
3111 if (item
== NULL
) return; /* we hit the blank area */
3113 if ( event
.RightDown() )
3115 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
, GetId());
3116 nevent
.m_item
= item
;
3117 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3118 nevent
.SetEventObject(this);
3119 GetEventHandler()->ProcessEvent(nevent
);
3121 else if ( event
.LeftUp() )
3123 // this facilitates multiple-item drag-and-drop
3125 if (item
&& HasFlag(wxTR_MULTIPLE
))
3127 wxArrayTreeItemIds selections
;
3128 size_t count
= GetSelections(selections
);
3131 !event
.ControlDown() &&
3134 DoSelectItem(item
, true, false);
3140 if ( (item
== m_current
) &&
3141 (flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
3142 HasFlag(wxTR_EDIT_LABELS
) )
3144 if ( m_renameTimer
)
3146 if ( m_renameTimer
->IsRunning() )
3147 m_renameTimer
->Stop();
3151 m_renameTimer
= new wxTreeRenameTimer( this );
3154 m_renameTimer
->Start( wxTreeRenameTimer::DELAY
, true );
3157 m_lastOnSame
= false;
3160 else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
3162 if ( event
.LeftDown() )
3164 m_lastOnSame
= item
== m_current
;
3167 if ( flags
& wxTREE_HITTEST_ONITEMBUTTON
)
3169 // only toggle the item for a single click, double click on
3170 // the button doesn't do anything (it toggles the item twice)
3171 if ( event
.LeftDown() )
3176 // don't select the item if the button was clicked
3181 // clear the previously selected items, if the
3182 // user clicked outside of the present selection.
3183 // otherwise, perform the deselection on mouse-up.
3184 // this allows multiple drag and drop to work.
3186 if (!IsSelected(item
))
3188 // how should the selection work for this event?
3189 bool is_multiple
, extended_select
, unselect_others
;
3190 EventFlagsToSelType(GetWindowStyleFlag(),
3192 event
.ControlDown(),
3193 is_multiple
, extended_select
, unselect_others
);
3195 DoSelectItem(item
, unselect_others
, extended_select
);
3199 // For some reason, Windows isn't recognizing a left double-click,
3200 // so we need to simulate it here. Allow 200 milliseconds for now.
3201 if ( event
.LeftDClick() )
3203 // double clicking should not start editing the item label
3204 if ( m_renameTimer
)
3205 m_renameTimer
->Stop();
3207 m_lastOnSame
= false;
3209 // send activate event first
3210 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
3211 nevent
.m_item
= item
;
3212 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3213 nevent
.SetEventObject( this );
3214 if ( !GetEventHandler()->ProcessEvent( nevent
) )
3216 // if the user code didn't process the activate event,
3217 // handle it ourselves by toggling the item when it is
3219 if ( item
->HasPlus() )
3229 void wxGenericTreeCtrl::OnInternalIdle()
3231 wxWindow::OnInternalIdle();
3233 // Check if we need to select the root item
3234 // because nothing else has been selected.
3235 // Delaying it means that we can invoke event handlers
3236 // as required, when a first item is selected.
3237 if (!HasFlag(wxTR_MULTIPLE
) && !GetSelection().IsOk())
3240 SelectItem(m_select_me
);
3241 else if (GetRootItem().IsOk())
3242 SelectItem(GetRootItem());
3245 /* after all changes have been done to the tree control,
3246 * we actually redraw the tree when everything is over */
3248 if (!m_dirty
) return;
3249 if (m_freezeCount
) return;
3253 CalculatePositions();
3255 AdjustMyScrollbars();
3258 void wxGenericTreeCtrl::CalculateSize( wxGenericTreeItem
*item
, wxDC
&dc
)
3263 wxTreeItemAttr
*attr
= item
->GetAttributes();
3264 if ( attr
&& attr
->HasFont() )
3265 dc
.SetFont(attr
->GetFont());
3266 else if ( item
->IsBold() )
3267 dc
.SetFont(m_boldFont
);
3269 dc
.SetFont(m_normalFont
);
3271 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
3274 // restore normal font
3275 dc
.SetFont( m_normalFont
);
3279 int image
= item
->GetCurrentImage();
3280 if ( image
!= NO_IMAGE
)
3282 if ( m_imageListNormal
)
3284 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
3289 int total_h
= (image_h
> text_h
) ? image_h
: text_h
;
3292 total_h
+= 2; // at least 2 pixels
3294 total_h
+= total_h
/10; // otherwise 10% extra spacing
3296 item
->SetHeight(total_h
);
3297 if (total_h
>m_lineHeight
)
3298 m_lineHeight
=total_h
;
3300 item
->SetWidth(image_w
+text_w
+2);
3303 // -----------------------------------------------------------------------------
3304 // for developper : y is now the top of the level
3305 // not the middle of it !
3306 void wxGenericTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
3308 int x
= level
*m_indent
;
3309 if (!HasFlag(wxTR_HIDE_ROOT
))
3313 else if (level
== 0)
3315 // a hidden root is not evaluated, but its
3316 // children are always calculated
3320 CalculateSize( item
, dc
);
3323 item
->SetX( x
+m_spacing
);
3325 y
+= GetLineHeight(item
);
3327 if ( !item
->IsExpanded() )
3329 // we don't need to calculate collapsed branches
3334 wxArrayGenericTreeItems
& children
= item
->GetChildren();
3335 size_t n
, count
= children
.Count();
3337 for (n
= 0; n
< count
; ++n
)
3338 CalculateLevel( children
[n
], dc
, level
, y
); // recurse
3341 void wxGenericTreeCtrl::CalculatePositions()
3343 if ( !m_anchor
) return;
3345 wxClientDC
dc(this);
3348 dc
.SetFont( m_normalFont
);
3350 dc
.SetPen( m_dottedPen
);
3351 //if(GetImageList() == NULL)
3352 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
3355 CalculateLevel( m_anchor
, dc
, 0, y
); // start recursion
3358 void wxGenericTreeCtrl::RefreshSubtree(wxGenericTreeItem
*item
)
3360 if (m_dirty
) return;
3361 if (m_freezeCount
) return;
3363 wxSize client
= GetClientSize();
3366 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3367 rect
.width
= client
.x
;
3368 rect
.height
= client
.y
;
3370 Refresh(true, &rect
);
3372 AdjustMyScrollbars();
3375 void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
3377 if (m_dirty
) return;
3378 if (m_freezeCount
) return;
3381 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3382 rect
.width
= GetClientSize().x
;
3383 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
3385 Refresh(true, &rect
);
3388 void wxGenericTreeCtrl::RefreshSelected()
3390 if (m_freezeCount
) return;
3392 // TODO: this is awfully inefficient, we should keep the list of all
3393 // selected items internally, should be much faster
3395 RefreshSelectedUnder(m_anchor
);
3398 void wxGenericTreeCtrl::RefreshSelectedUnder(wxGenericTreeItem
*item
)
3400 if (m_freezeCount
) return;
3402 if ( item
->IsSelected() )
3405 const wxArrayGenericTreeItems
& children
= item
->GetChildren();
3406 size_t count
= children
.GetCount();
3407 for ( size_t n
= 0; n
< count
; n
++ )
3409 RefreshSelectedUnder(children
[n
]);
3413 void wxGenericTreeCtrl::Freeze()
3418 void wxGenericTreeCtrl::Thaw()
3420 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen tree control?") );
3422 if ( !--m_freezeCount
)
3428 // ----------------------------------------------------------------------------
3429 // changing colours: we need to refresh the tree control
3430 // ----------------------------------------------------------------------------
3432 bool wxGenericTreeCtrl::SetBackgroundColour(const wxColour
& colour
)
3434 if ( !wxWindow::SetBackgroundColour(colour
) )
3437 if (m_freezeCount
) return true;
3444 bool wxGenericTreeCtrl::SetForegroundColour(const wxColour
& colour
)
3446 if ( !wxWindow::SetForegroundColour(colour
) )
3449 if (m_freezeCount
) return true;
3456 // Process the tooltip event, to speed up event processing.
3457 // Doesn't actually get a tooltip.
3458 void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent
&event
)
3464 // NOTE: If using the wxListBox visual attributes works everywhere then this can
3465 // be removed, as well as the #else case below.
3466 #define _USE_VISATTR 0
3469 #include "wx/listbox.h"
3475 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
3477 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3481 // Use the same color scheme as wxListBox
3482 return wxListBox::GetClassDefaultAttributes(variant
);
3484 wxVisualAttributes attr
;
3485 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
3486 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
3487 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
3492 #endif // wxUSE_TREECTRL