1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: generic tree control implementation
4 // Author: Robert Roebling
6 // Modified: 22/10/98 - almost total rewrite, simpler interface (VZ)
8 // Copyright: (c) 1998 Robert Roebling and Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // =============================================================================
14 // =============================================================================
16 // -----------------------------------------------------------------------------
18 // -----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "treectlg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/treebase.h"
34 #include "wx/generic/treectlg.h"
36 #include "wx/textctrl.h"
37 #include "wx/imaglist.h"
38 #include "wx/settings.h"
39 #include "wx/dcclient.h"
41 #include "wx/renderer.h"
44 #include "wx/mac/private.h"
47 // -----------------------------------------------------------------------------
49 // -----------------------------------------------------------------------------
51 class WXDLLEXPORT wxGenericTreeItem
;
53 WX_DEFINE_EXPORTED_ARRAY_PTR(wxGenericTreeItem
*, wxArrayGenericTreeItems
);
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 static const int NO_IMAGE
= -1;
61 static const int PIXELS_PER_UNIT
= 10;
63 // -----------------------------------------------------------------------------
65 // -----------------------------------------------------------------------------
67 // timer used for enabling in-place edit
68 class WXDLLEXPORT wxTreeRenameTimer
: public wxTimer
71 // start editing the current item after half a second (if the mouse hasn't
72 // been clicked/moved)
75 wxTreeRenameTimer( wxGenericTreeCtrl
*owner
);
77 virtual void Notify();
80 wxGenericTreeCtrl
*m_owner
;
82 DECLARE_NO_COPY_CLASS(wxTreeRenameTimer
)
85 // control used for in-place edit
86 class WXDLLEXPORT wxTreeTextCtrl
: public wxTextCtrl
89 wxTreeTextCtrl(wxGenericTreeCtrl
*owner
, wxGenericTreeItem
*item
);
92 void OnChar( wxKeyEvent
&event
);
93 void OnKeyUp( wxKeyEvent
&event
);
94 void OnKillFocus( wxFocusEvent
&event
);
100 wxGenericTreeCtrl
*m_owner
;
101 wxGenericTreeItem
*m_itemEdited
;
102 wxString m_startValue
;
105 DECLARE_EVENT_TABLE()
106 DECLARE_NO_COPY_CLASS(wxTreeTextCtrl
)
109 // timer used to clear wxGenericTreeCtrl::m_findPrefix if no key was pressed
110 // for a sufficiently long time
111 class WXDLLEXPORT wxTreeFindTimer
: public wxTimer
114 // reset the current prefix after half a second of inactivity
115 enum { DELAY
= 500 };
117 wxTreeFindTimer( wxGenericTreeCtrl
*owner
) { m_owner
= owner
; }
119 virtual void Notify() { m_owner
->m_findPrefix
.clear(); }
122 wxGenericTreeCtrl
*m_owner
;
124 DECLARE_NO_COPY_CLASS(wxTreeFindTimer
)
128 class WXDLLEXPORT wxGenericTreeItem
132 wxGenericTreeItem() { m_data
= NULL
; }
133 wxGenericTreeItem( wxGenericTreeItem
*parent
,
134 const wxString
& text
,
137 wxTreeItemData
*data
);
139 ~wxGenericTreeItem();
142 wxArrayGenericTreeItems
& GetChildren() { return m_children
; }
144 const wxString
& GetText() const { return m_text
; }
145 int GetImage(wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
146 { return m_images
[which
]; }
147 wxTreeItemData
*GetData() const { return m_data
; }
149 // returns the current image for the item (depending on its
150 // selected/expanded/whatever state)
151 int GetCurrentImage() const;
153 void SetText( const wxString
&text
);
154 void SetImage(int image
, wxTreeItemIcon which
) { m_images
[which
] = image
; }
155 void SetData(wxTreeItemData
*data
) { m_data
= data
; }
157 void SetHasPlus(bool has
= TRUE
) { m_hasPlus
= has
; }
159 void SetBold(bool bold
) { m_isBold
= bold
; }
161 int GetX() const { return m_x
; }
162 int GetY() const { return m_y
; }
164 void SetX(int x
) { m_x
= x
; }
165 void SetY(int y
) { m_y
= y
; }
167 int GetHeight() const { return m_height
; }
168 int GetWidth() const { return m_width
; }
170 void SetHeight(int h
) { m_height
= h
; }
171 void SetWidth(int w
) { m_width
= w
; }
173 wxGenericTreeItem
*GetParent() const { return m_parent
; }
176 // deletes all children notifying the treectrl about it if !NULL
178 void DeleteChildren(wxGenericTreeCtrl
*tree
= NULL
);
180 // get count of all children (and grand children if 'recursively')
181 size_t GetChildrenCount(bool recursively
= TRUE
) const;
183 void Insert(wxGenericTreeItem
*child
, size_t index
)
184 { m_children
.Insert(child
, index
); }
186 void GetSize( int &x
, int &y
, const wxGenericTreeCtrl
* );
188 // return the item at given position (or NULL if no item), onButton is
189 // TRUE if the point belongs to the item's button, otherwise it lies
190 // on the item's label
191 wxGenericTreeItem
*HitTest( const wxPoint
& point
,
192 const wxGenericTreeCtrl
*,
196 void Expand() { m_isCollapsed
= FALSE
; }
197 void Collapse() { m_isCollapsed
= TRUE
; }
199 void SetHilight( bool set
= TRUE
) { m_hasHilight
= set
; }
202 bool HasChildren() const { return !m_children
.IsEmpty(); }
203 bool IsSelected() const { return m_hasHilight
!= 0; }
204 bool IsExpanded() const { return !m_isCollapsed
; }
205 bool HasPlus() const { return m_hasPlus
|| HasChildren(); }
206 bool IsBold() const { return m_isBold
!= 0; }
209 // get them - may be NULL
210 wxTreeItemAttr
*GetAttributes() const { return m_attr
; }
211 // get them ensuring that the pointer is not NULL
212 wxTreeItemAttr
& Attr()
216 m_attr
= new wxTreeItemAttr
;
222 void SetAttributes(wxTreeItemAttr
*attr
)
224 if ( m_ownsAttr
) delete m_attr
;
228 // set them and delete when done
229 void AssignAttributes(wxTreeItemAttr
*attr
)
236 // since there can be very many of these, we save size by chosing
237 // the smallest representation for the elements and by ordering
238 // the members to avoid padding.
239 wxString m_text
; // label to be rendered for item
241 wxTreeItemData
*m_data
; // user-provided data
243 wxArrayGenericTreeItems m_children
; // list of children
244 wxGenericTreeItem
*m_parent
; // parent of this item
246 wxTreeItemAttr
*m_attr
; // attributes???
248 // tree ctrl images for the normal, selected, expanded and
249 // expanded+selected states
250 short m_images
[wxTreeItemIcon_Max
];
252 wxCoord m_x
; // (virtual) offset from top
253 wxCoord m_y
; // (virtual) offset from left
254 short m_width
; // width of this item
255 unsigned char m_height
; // height of this item
257 // use bitfields to save size
258 int m_isCollapsed
:1;
259 int m_hasHilight
:1; // same as focused
260 int m_hasPlus
:1; // used for item which doesn't have
261 // children but has a [+] button
262 int m_isBold
:1; // render the label in bold font
263 int m_ownsAttr
:1; // delete attribute when done
265 DECLARE_NO_COPY_CLASS(wxGenericTreeItem
)
268 // =============================================================================
270 // =============================================================================
272 // ----------------------------------------------------------------------------
274 // ----------------------------------------------------------------------------
276 // translate the key or mouse event flags to the type of selection we're
278 static void EventFlagsToSelType(long style
,
282 bool &extended_select
,
283 bool &unselect_others
)
285 is_multiple
= (style
& wxTR_MULTIPLE
) != 0;
286 extended_select
= shiftDown
&& is_multiple
;
287 unselect_others
= !(extended_select
|| (ctrlDown
&& is_multiple
));
290 // check if the given item is under another one
291 static bool IsDescendantOf(wxGenericTreeItem
*parent
, wxGenericTreeItem
*item
)
295 if ( item
== parent
)
297 // item is a descendant of parent
301 item
= item
->GetParent();
307 // -----------------------------------------------------------------------------
308 // wxTreeRenameTimer (internal)
309 // -----------------------------------------------------------------------------
311 wxTreeRenameTimer::wxTreeRenameTimer( wxGenericTreeCtrl
*owner
)
316 void wxTreeRenameTimer::Notify()
318 m_owner
->OnRenameTimer();
321 //-----------------------------------------------------------------------------
322 // wxTreeTextCtrl (internal)
323 //-----------------------------------------------------------------------------
325 BEGIN_EVENT_TABLE(wxTreeTextCtrl
,wxTextCtrl
)
326 EVT_CHAR (wxTreeTextCtrl::OnChar
)
327 EVT_KEY_UP (wxTreeTextCtrl::OnKeyUp
)
328 EVT_KILL_FOCUS (wxTreeTextCtrl::OnKillFocus
)
331 wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl
*owner
,
332 wxGenericTreeItem
*item
)
333 : m_itemEdited(item
), m_startValue(item
->GetText())
338 int w
= m_itemEdited
->GetWidth(),
339 h
= m_itemEdited
->GetHeight();
342 m_owner
->CalcScrolledPosition(item
->GetX(), item
->GetY(), &x
, &y
);
347 int image
= item
->GetCurrentImage();
348 if ( image
!= NO_IMAGE
)
350 if ( m_owner
->m_imageListNormal
)
352 m_owner
->m_imageListNormal
->GetSize( image
, image_w
, image_h
);
357 wxFAIL_MSG(_T("you must create an image list to use images!"));
361 // FIXME: what are all these hardcoded 4, 8 and 11s really?
365 (void)Create(m_owner
, wxID_ANY
, m_startValue
,
366 wxPoint(x
- 4, y
- 4), wxSize(w
+ 11, h
+ 8));
369 bool wxTreeTextCtrl::AcceptChanges()
371 const wxString value
= GetValue();
373 if ( value
== m_startValue
)
375 // nothing changed, always accept
379 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
381 // vetoed by the user
385 // accepted, do rename the item
386 m_owner
->SetItemText(m_itemEdited
, value
);
391 void wxTreeTextCtrl::Finish()
395 m_owner
->ResetTextControl();
397 wxPendingDelete
.Append(this);
401 m_owner
->SetFocus(); // This doesn't work. TODO.
405 void wxTreeTextCtrl::OnChar( wxKeyEvent
&event
)
407 switch ( event
.m_keyCode
)
410 if ( !AcceptChanges() )
412 // vetoed by the user, don't disappear
419 m_owner
->OnRenameCancelled(m_itemEdited
);
427 void wxTreeTextCtrl::OnKeyUp( wxKeyEvent
&event
)
431 // auto-grow the textctrl:
432 wxSize parentSize
= m_owner
->GetSize();
433 wxPoint myPos
= GetPosition();
434 wxSize mySize
= GetSize();
436 GetTextExtent(GetValue() + _T("M"), &sx
, &sy
);
437 if (myPos
.x
+ sx
> parentSize
.x
)
438 sx
= parentSize
.x
- myPos
.x
;
447 void wxTreeTextCtrl::OnKillFocus( wxFocusEvent
&event
)
455 if ( AcceptChanges() )
461 // -----------------------------------------------------------------------------
463 // -----------------------------------------------------------------------------
465 wxGenericTreeItem::wxGenericTreeItem(wxGenericTreeItem
*parent
,
466 const wxString
& text
,
467 int image
, int selImage
,
468 wxTreeItemData
*data
)
471 m_images
[wxTreeItemIcon_Normal
] = image
;
472 m_images
[wxTreeItemIcon_Selected
] = selImage
;
473 m_images
[wxTreeItemIcon_Expanded
] = NO_IMAGE
;
474 m_images
[wxTreeItemIcon_SelectedExpanded
] = NO_IMAGE
;
479 m_isCollapsed
= TRUE
;
480 m_hasHilight
= FALSE
;
486 m_attr
= (wxTreeItemAttr
*)NULL
;
489 // We don't know the height here yet.
494 wxGenericTreeItem::~wxGenericTreeItem()
498 if (m_ownsAttr
) delete m_attr
;
500 wxASSERT_MSG( m_children
.IsEmpty(),
501 wxT("please call DeleteChildren() before deleting the item") );
504 void wxGenericTreeItem::DeleteChildren(wxGenericTreeCtrl
*tree
)
506 size_t count
= m_children
.Count();
507 for ( size_t n
= 0; n
< count
; n
++ )
509 wxGenericTreeItem
*child
= m_children
[n
];
511 tree
->SendDeleteEvent(child
);
513 child
->DeleteChildren(tree
);
520 void wxGenericTreeItem::SetText( const wxString
&text
)
525 size_t wxGenericTreeItem::GetChildrenCount(bool recursively
) const
527 size_t count
= m_children
.Count();
531 size_t total
= count
;
532 for (size_t n
= 0; n
< count
; ++n
)
534 total
+= m_children
[n
]->GetChildrenCount();
540 void wxGenericTreeItem::GetSize( int &x
, int &y
,
541 const wxGenericTreeCtrl
*theButton
)
543 int bottomY
=m_y
+theButton
->GetLineHeight(this);
544 if ( y
< bottomY
) y
= bottomY
;
545 int width
= m_x
+ m_width
;
546 if ( x
< width
) x
= width
;
550 size_t count
= m_children
.Count();
551 for ( size_t n
= 0; n
< count
; ++n
)
553 m_children
[n
]->GetSize( x
, y
, theButton
);
558 wxGenericTreeItem
*wxGenericTreeItem::HitTest(const wxPoint
& point
,
559 const wxGenericTreeCtrl
*theCtrl
,
563 // for a hidden root node, don't evaluate it, but do evaluate children
564 if ( !(level
== 0 && theCtrl
->HasFlag(wxTR_HIDE_ROOT
)) )
567 int h
= theCtrl
->GetLineHeight(this);
568 if ((point
.y
> m_y
) && (point
.y
< m_y
+ h
))
570 int y_mid
= m_y
+ h
/2;
571 if (point
.y
< y_mid
)
572 flags
|= wxTREE_HITTEST_ONITEMUPPERPART
;
574 flags
|= wxTREE_HITTEST_ONITEMLOWERPART
;
576 int xCross
= m_x
- theCtrl
->GetSpacing();
578 // according to the drawing code the triangels are drawn
579 // at -4 , -4 from the position up to +10/+10 max
580 if ((point
.x
> xCross
-4) && (point
.x
< xCross
+10) &&
581 (point
.y
> y_mid
-4) && (point
.y
< y_mid
+10) &&
582 HasPlus() && theCtrl
->HasButtons() )
584 // 5 is the size of the plus sign
585 if ((point
.x
> xCross
-6) && (point
.x
< xCross
+6) &&
586 (point
.y
> y_mid
-6) && (point
.y
< y_mid
+6) &&
587 HasPlus() && theCtrl
->HasButtons() )
590 flags
|= wxTREE_HITTEST_ONITEMBUTTON
;
594 if ((point
.x
>= m_x
) && (point
.x
<= m_x
+m_width
))
599 // assuming every image (normal and selected) has the same size!
600 if ( (GetImage() != NO_IMAGE
) && theCtrl
->m_imageListNormal
)
601 theCtrl
->m_imageListNormal
->GetSize(GetImage(),
604 if ((image_w
!= -1) && (point
.x
<= m_x
+ image_w
+ 1))
605 flags
|= wxTREE_HITTEST_ONITEMICON
;
607 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
613 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
614 if (point
.x
> m_x
+m_width
)
615 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
620 // if children are expanded, fall through to evaluate them
621 if (m_isCollapsed
) return (wxGenericTreeItem
*) NULL
;
625 size_t count
= m_children
.Count();
626 for ( size_t n
= 0; n
< count
; n
++ )
628 wxGenericTreeItem
*res
= m_children
[n
]->HitTest( point
,
636 return (wxGenericTreeItem
*) NULL
;
639 int wxGenericTreeItem::GetCurrentImage() const
641 int image
= NO_IMAGE
;
646 image
= GetImage(wxTreeItemIcon_SelectedExpanded
);
649 if ( image
== NO_IMAGE
)
651 // we usually fall back to the normal item, but try just the
652 // expanded one (and not selected) first in this case
653 image
= GetImage(wxTreeItemIcon_Expanded
);
659 image
= GetImage(wxTreeItemIcon_Selected
);
662 // maybe it doesn't have the specific image we want,
663 // try the default one instead
664 if ( image
== NO_IMAGE
) image
= GetImage();
669 // -----------------------------------------------------------------------------
670 // wxGenericTreeCtrl implementation
671 // -----------------------------------------------------------------------------
673 IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl
, wxScrolledWindow
)
675 BEGIN_EVENT_TABLE(wxGenericTreeCtrl
,wxScrolledWindow
)
676 EVT_PAINT (wxGenericTreeCtrl::OnPaint
)
677 EVT_MOUSE_EVENTS (wxGenericTreeCtrl::OnMouse
)
678 EVT_CHAR (wxGenericTreeCtrl::OnChar
)
679 EVT_SET_FOCUS (wxGenericTreeCtrl::OnSetFocus
)
680 EVT_KILL_FOCUS (wxGenericTreeCtrl::OnKillFocus
)
681 EVT_TREE_ITEM_GETTOOLTIP(-1, wxGenericTreeCtrl::OnGetToolTip
)
684 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
686 * wxTreeCtrl has to be a real class or we have problems with
687 * the run-time information.
690 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxGenericTreeCtrl
)
693 // -----------------------------------------------------------------------------
694 // construction/destruction
695 // -----------------------------------------------------------------------------
697 void wxGenericTreeCtrl::Init()
699 m_current
= m_key_current
= m_anchor
= m_select_me
= (wxGenericTreeItem
*) NULL
;
707 m_hilightBrush
= new wxBrush
709 wxSystemSettings::GetColour
711 wxSYS_COLOUR_HIGHLIGHT
716 m_hilightUnfocusedBrush
= new wxBrush
718 wxSystemSettings::GetColour
720 wxSYS_COLOUR_BTNSHADOW
725 m_imageListNormal
= m_imageListButtons
=
726 m_imageListState
= (wxImageList
*) NULL
;
727 m_ownsImageListNormal
= m_ownsImageListButtons
=
728 m_ownsImageListState
= FALSE
;
731 m_isDragging
= FALSE
;
732 m_dropTarget
= m_oldSelection
= NULL
;
736 m_renameTimer
= NULL
;
741 m_lastOnSame
= FALSE
;
743 #if defined( __WXMAC__ ) && __WXMAC_CARBON__
744 m_normalFont
.MacCreateThemeFont( kThemeViewsFont
) ;
746 m_normalFont
= wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT
);
748 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
749 m_normalFont
.GetFamily(),
750 m_normalFont
.GetStyle(),
752 m_normalFont
.GetUnderlined(),
753 m_normalFont
.GetFaceName(),
754 m_normalFont
.GetEncoding());
757 bool wxGenericTreeCtrl::Create(wxWindow
*parent
,
762 const wxValidator
& wxVALIDATOR_PARAM(validator
),
763 const wxString
& name
)
767 wxGetOsVersion( &major
, &minor
);
769 style
&= ~wxTR_LINES_AT_ROOT
;
770 style
|= wxTR_NO_LINES
;
772 style
|= wxTR_ROW_LINES
;
775 wxScrolledWindow::Create( parent
, id
, pos
, size
,
776 style
|wxHSCROLL
|wxVSCROLL
, name
);
778 // If the tree display has no buttons, but does have
779 // connecting lines, we can use a narrower layout.
780 // It may not be a good idea to force this...
781 if (!HasButtons() && !HasFlag(wxTR_NO_LINES
))
788 SetValidator( validator
);
791 wxVisualAttributes attr
= GetDefaultAttributes();
792 SetDefaultForegroundColour( attr
.colFg
);
793 SetDefaultBackgroundColour( attr
.colBg
);
794 SetDefaultFont(attr
.font
);
796 // m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86
797 m_dottedPen
= wxPen( wxT("grey"), 0, 0 );
804 wxGenericTreeCtrl::~wxGenericTreeCtrl()
806 delete m_hilightBrush
;
807 delete m_hilightUnfocusedBrush
;
811 delete m_renameTimer
;
814 if (m_ownsImageListNormal
)
815 delete m_imageListNormal
;
816 if (m_ownsImageListState
)
817 delete m_imageListState
;
818 if (m_ownsImageListButtons
)
819 delete m_imageListButtons
;
822 // -----------------------------------------------------------------------------
824 // -----------------------------------------------------------------------------
826 size_t wxGenericTreeCtrl::GetCount() const
828 return m_anchor
== NULL
? 0u : m_anchor
->GetChildrenCount();
831 void wxGenericTreeCtrl::SetIndent(unsigned int indent
)
833 m_indent
= (unsigned short) indent
;
837 void wxGenericTreeCtrl::SetSpacing(unsigned int spacing
)
839 m_spacing
= (unsigned short) spacing
;
844 wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
,
845 bool recursively
) const
847 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
849 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
852 void wxGenericTreeCtrl::SetWindowStyle(const long styles
)
854 if (!HasFlag(wxTR_HIDE_ROOT
) && (styles
& wxTR_HIDE_ROOT
))
856 // if we will hide the root, make sure children are visible
857 m_anchor
->SetHasPlus();
859 CalculatePositions();
862 // right now, just sets the styles. Eventually, we may
863 // want to update the inherited styles, but right now
864 // none of the parents has updatable styles
865 m_windowStyle
= styles
;
869 // -----------------------------------------------------------------------------
870 // functions to work with tree items
871 // -----------------------------------------------------------------------------
873 wxString
wxGenericTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
875 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
877 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetText();
880 int wxGenericTreeCtrl::GetItemImage(const wxTreeItemId
& item
,
881 wxTreeItemIcon which
) const
883 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
885 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetImage(which
);
888 wxTreeItemData
*wxGenericTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
890 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
892 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetData();
895 wxColour
wxGenericTreeCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
897 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
899 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
900 return pItem
->Attr().GetTextColour();
903 wxColour
wxGenericTreeCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
) const
905 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
907 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
908 return pItem
->Attr().GetBackgroundColour();
911 wxFont
wxGenericTreeCtrl::GetItemFont(const wxTreeItemId
& item
) const
913 wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") );
915 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
916 return pItem
->Attr().GetFont();
919 void wxGenericTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
921 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
924 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
925 pItem
->SetText(text
);
926 CalculateSize(pItem
, dc
);
930 void wxGenericTreeCtrl::SetItemImage(const wxTreeItemId
& item
,
932 wxTreeItemIcon which
)
934 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
936 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
937 pItem
->SetImage(image
, which
);
940 CalculateSize(pItem
, dc
);
944 void wxGenericTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
946 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
951 ((wxGenericTreeItem
*) item
.m_pItem
)->SetData(data
);
954 void wxGenericTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
956 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
958 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
959 pItem
->SetHasPlus(has
);
963 void wxGenericTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
965 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
967 // avoid redrawing the tree if no real change
968 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
969 if ( pItem
->IsBold() != bold
)
971 pItem
->SetBold(bold
);
976 void wxGenericTreeCtrl::SetItemTextColour(const wxTreeItemId
& item
,
979 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
981 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
982 pItem
->Attr().SetTextColour(col
);
986 void wxGenericTreeCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
989 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
991 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
992 pItem
->Attr().SetBackgroundColour(col
);
996 void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
)
998 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1000 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1001 pItem
->Attr().SetFont(font
);
1005 bool wxGenericTreeCtrl::SetFont( const wxFont
&font
)
1007 wxScrolledWindow::SetFont(font
);
1009 m_normalFont
= font
;
1010 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
1011 m_normalFont
.GetFamily(),
1012 m_normalFont
.GetStyle(),
1014 m_normalFont
.GetUnderlined(),
1015 m_normalFont
.GetFaceName(),
1016 m_normalFont
.GetEncoding());
1022 // -----------------------------------------------------------------------------
1023 // item status inquiries
1024 // -----------------------------------------------------------------------------
1026 bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
1028 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
1030 // An item is only visible if it's not a descendant of a collapsed item
1031 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1032 wxGenericTreeItem
* parent
= pItem
->GetParent();
1035 if (!parent
->IsExpanded())
1037 parent
= parent
->GetParent();
1041 GetViewStart(& startX
, & startY
);
1043 wxSize clientSize
= GetClientSize();
1046 if (!GetBoundingRect(item
, rect
))
1048 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
1050 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
1052 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
1058 bool wxGenericTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
1060 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
1062 // consider that the item does have children if it has the "+" button: it
1063 // might not have them (if it had never been expanded yet) but then it
1064 // could have them as well and it's better to err on this side rather than
1065 // disabling some operations which are restricted to the items with
1066 // children for an item which does have them
1067 return ((wxGenericTreeItem
*) item
.m_pItem
)->HasPlus();
1070 bool wxGenericTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
1072 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
1074 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsExpanded();
1077 bool wxGenericTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
1079 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
1081 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsSelected();
1084 bool wxGenericTreeCtrl::IsBold(const wxTreeItemId
& item
) const
1086 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
1088 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsBold();
1091 // -----------------------------------------------------------------------------
1093 // -----------------------------------------------------------------------------
1095 wxTreeItemId
wxGenericTreeCtrl::GetItemParent(const wxTreeItemId
& item
) const
1097 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1099 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetParent();
1102 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1103 wxTreeItemIdValue
& cookie
) const
1105 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1108 return GetNextChild(item
, cookie
);
1111 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1112 wxTreeItemIdValue
& cookie
) const
1114 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1116 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1118 // it's ok to cast cookie to size_t, we never have indices big enough to
1119 // overflow "void *"
1120 size_t *pIndex
= (size_t *)&cookie
;
1121 if ( *pIndex
< children
.Count() )
1123 return children
.Item((*pIndex
)++);
1127 // there are no more of them
1128 return wxTreeItemId();
1132 #if WXWIN_COMPATIBILITY_2_4
1134 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1137 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1140 return GetNextChild(item
, cookie
);
1143 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1146 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1148 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1149 if ( (size_t)cookie
< children
.Count() )
1151 return children
.Item((size_t)cookie
++);
1155 // there are no more of them
1156 return wxTreeItemId();
1160 #endif // WXWIN_COMPATIBILITY_2_4
1162 wxTreeItemId
wxGenericTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
1164 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1166 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1167 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
1170 wxTreeItemId
wxGenericTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
1172 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1174 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1175 wxGenericTreeItem
*parent
= i
->GetParent();
1176 if ( parent
== NULL
)
1178 // root item doesn't have any siblings
1179 return wxTreeItemId();
1182 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1183 int index
= siblings
.Index(i
);
1184 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1186 size_t n
= (size_t)(index
+ 1);
1187 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
1190 wxTreeItemId
wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
1192 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1194 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1195 wxGenericTreeItem
*parent
= i
->GetParent();
1196 if ( parent
== NULL
)
1198 // root item doesn't have any siblings
1199 return wxTreeItemId();
1202 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1203 int index
= siblings
.Index(i
);
1204 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1206 return index
== 0 ? wxTreeItemId()
1207 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
1210 // Only for internal use right now, but should probably be public
1211 wxTreeItemId
wxGenericTreeCtrl::GetNext(const wxTreeItemId
& item
) const
1213 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1215 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1217 // First see if there are any children.
1218 wxArrayGenericTreeItems
& children
= i
->GetChildren();
1219 if (children
.GetCount() > 0)
1221 return children
.Item(0);
1225 // Try a sibling of this or ancestor instead
1226 wxTreeItemId p
= item
;
1227 wxTreeItemId toFind
;
1230 toFind
= GetNextSibling(p
);
1231 p
= GetItemParent(p
);
1232 } while (p
.IsOk() && !toFind
.IsOk());
1237 wxTreeItemId
wxGenericTreeCtrl::GetFirstVisibleItem() const
1239 wxTreeItemId id
= GetRootItem();
1248 } while (id
.IsOk());
1250 return wxTreeItemId();
1253 wxTreeItemId
wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
1255 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1257 wxTreeItemId id
= item
;
1260 while (id
= GetNext(id
), id
.IsOk())
1266 return wxTreeItemId();
1269 wxTreeItemId
wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
1271 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1273 wxFAIL_MSG(wxT("not implemented"));
1275 return wxTreeItemId();
1278 // called by wxTextTreeCtrl when it marks itself for deletion
1279 void wxGenericTreeCtrl::ResetTextControl()
1284 // find the first item starting with the given prefix after the given item
1285 wxTreeItemId
wxGenericTreeCtrl::FindItem(const wxTreeItemId
& idParent
,
1286 const wxString
& prefixOrig
) const
1288 // match is case insensitive as this is more convenient to the user: having
1289 // to press Shift-letter to go to the item starting with a capital letter
1290 // would be too bothersome
1291 wxString prefix
= prefixOrig
.Lower();
1293 // determine the starting point: we shouldn't take the current item (this
1294 // allows to switch between two items starting with the same letter just by
1295 // pressing it) but we shouldn't jump to the next one if the user is
1296 // continuing to type as otherwise he might easily skip the item he wanted
1297 wxTreeItemId id
= idParent
;
1298 if ( prefix
.length() == 1 )
1303 // look for the item starting with the given prefix after it
1304 while ( id
.IsOk() && !GetItemText(id
).Lower().StartsWith(prefix
) )
1309 // if we haven't found anything...
1312 // ... wrap to the beginning
1314 if ( HasFlag(wxTR_HIDE_ROOT
) )
1316 // can't select virtual root
1320 // and try all the items (stop when we get to the one we started from)
1321 while ( id
!= idParent
&& !GetItemText(id
).Lower().StartsWith(prefix
) )
1330 // -----------------------------------------------------------------------------
1332 // -----------------------------------------------------------------------------
1334 wxTreeItemId
wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId
& parentId
,
1336 const wxString
& text
,
1337 int image
, int selImage
,
1338 wxTreeItemData
*data
)
1340 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1343 // should we give a warning here?
1344 return AddRoot(text
, image
, selImage
, data
);
1347 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
1349 wxGenericTreeItem
*item
=
1350 new wxGenericTreeItem( parent
, text
, image
, selImage
, data
);
1354 data
->m_pItem
= item
;
1357 parent
->Insert( item
, previous
);
1362 wxTreeItemId
wxGenericTreeCtrl::AddRoot(const wxString
& text
,
1363 int image
, int selImage
,
1364 wxTreeItemData
*data
)
1366 wxCHECK_MSG( !m_anchor
, wxTreeItemId(), wxT("tree can have only one root") );
1368 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
1370 m_anchor
= new wxGenericTreeItem((wxGenericTreeItem
*)NULL
, text
,
1371 image
, selImage
, data
);
1374 data
->m_pItem
= m_anchor
;
1377 if (HasFlag(wxTR_HIDE_ROOT
))
1379 // if root is hidden, make sure we can navigate
1381 m_anchor
->SetHasPlus();
1383 CalculatePositions();
1386 if (!HasFlag(wxTR_MULTIPLE
))
1388 m_current
= m_key_current
= m_anchor
;
1389 m_current
->SetHilight( TRUE
);
1395 wxTreeItemId
wxGenericTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
1396 const wxString
& text
,
1397 int image
, int selImage
,
1398 wxTreeItemData
*data
)
1400 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
1403 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1404 const wxTreeItemId
& idPrevious
,
1405 const wxString
& text
,
1406 int image
, int selImage
,
1407 wxTreeItemData
*data
)
1409 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1412 // should we give a warning here?
1413 return AddRoot(text
, image
, selImage
, data
);
1417 if (idPrevious
.IsOk())
1419 index
= parent
->GetChildren().Index((wxGenericTreeItem
*) idPrevious
.m_pItem
);
1420 wxASSERT_MSG( index
!= wxNOT_FOUND
,
1421 wxT("previous item in wxGenericTreeCtrl::InsertItem() is not a sibling") );
1424 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
1427 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1429 const wxString
& text
,
1430 int image
, int selImage
,
1431 wxTreeItemData
*data
)
1433 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1436 // should we give a warning here?
1437 return AddRoot(text
, image
, selImage
, data
);
1440 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
1443 wxTreeItemId
wxGenericTreeCtrl::AppendItem(const wxTreeItemId
& parentId
,
1444 const wxString
& text
,
1445 int image
, int selImage
,
1446 wxTreeItemData
*data
)
1448 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1451 // should we give a warning here?
1452 return AddRoot(text
, image
, selImage
, data
);
1455 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
1456 image
, selImage
, data
);
1459 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem
*item
)
1461 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, GetId() );
1462 event
.m_item
= item
;
1463 event
.SetEventObject( this );
1464 ProcessEvent( event
);
1467 void wxGenericTreeCtrl::DeleteChildren(const wxTreeItemId
& itemId
)
1469 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
1471 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1472 item
->DeleteChildren(this);
1475 void wxGenericTreeCtrl::Delete(const wxTreeItemId
& itemId
)
1477 m_dirty
= TRUE
; // do this first so stuff below doesn't cause flicker
1479 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1481 wxGenericTreeItem
*parent
= item
->GetParent();
1483 // don't keep stale pointers around!
1484 if ( IsDescendantOf(item
, m_key_current
) )
1486 // Don't silently change the selection:
1487 // do it properly in idle time, so event
1488 // handlers get called.
1490 // m_key_current = parent;
1491 m_key_current
= NULL
;
1494 // m_select_me records whether we need to select
1495 // a different item, in idle time.
1496 if ( m_select_me
&& IsDescendantOf(item
, m_select_me
) )
1498 m_select_me
= parent
;
1501 if ( IsDescendantOf(item
, m_current
) )
1503 // Don't silently change the selection:
1504 // do it properly in idle time, so event
1505 // handlers get called.
1507 // m_current = parent;
1509 m_select_me
= parent
;
1512 // remove the item from the tree
1515 parent
->GetChildren().Remove( item
); // remove by value
1517 else // deleting the root
1519 // nothing will be left in the tree
1523 // and delete all of its children and the item itself now
1524 item
->DeleteChildren(this);
1525 SendDeleteEvent(item
);
1529 void wxGenericTreeCtrl::DeleteAllItems()
1537 void wxGenericTreeCtrl::Expand(const wxTreeItemId
& itemId
)
1539 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1541 wxCHECK_RET( item
, _T("invalid item in wxGenericTreeCtrl::Expand") );
1542 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1543 _T("can't expand hidden root") );
1545 if ( !item
->HasPlus() )
1548 if ( item
->IsExpanded() )
1551 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, GetId() );
1552 event
.m_item
= item
;
1553 event
.SetEventObject( this );
1555 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1557 // cancelled by program
1562 CalculatePositions();
1564 RefreshSubtree(item
);
1566 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
1567 ProcessEvent( event
);
1570 void wxGenericTreeCtrl::ExpandAll(const wxTreeItemId
& item
)
1572 if ( !HasFlag(wxTR_HIDE_ROOT
) || item
!= GetRootItem())
1575 if ( !IsExpanded(item
) )
1579 wxTreeItemIdValue cookie
;
1580 wxTreeItemId child
= GetFirstChild(item
, cookie
);
1581 while ( child
.IsOk() )
1585 child
= GetNextChild(item
, cookie
);
1589 void wxGenericTreeCtrl::Collapse(const wxTreeItemId
& itemId
)
1591 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1592 _T("can't collapse hidden root") );
1594 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1596 if ( !item
->IsExpanded() )
1599 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, GetId() );
1600 event
.m_item
= item
;
1601 event
.SetEventObject( this );
1602 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1604 // cancelled by program
1610 #if 0 // TODO why should items be collapsed recursively?
1611 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1612 size_t count
= children
.Count();
1613 for ( size_t n
= 0; n
< count
; n
++ )
1615 Collapse(children
[n
]);
1619 CalculatePositions();
1621 RefreshSubtree(item
);
1623 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
1624 ProcessEvent( event
);
1627 void wxGenericTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
1630 DeleteChildren(item
);
1633 void wxGenericTreeCtrl::Toggle(const wxTreeItemId
& itemId
)
1635 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1637 if (item
->IsExpanded())
1643 void wxGenericTreeCtrl::Unselect()
1647 m_current
->SetHilight( FALSE
);
1648 RefreshLine( m_current
);
1655 void wxGenericTreeCtrl::UnselectAllChildren(wxGenericTreeItem
*item
)
1657 if (item
->IsSelected())
1659 item
->SetHilight(FALSE
);
1663 if (item
->HasChildren())
1665 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1666 size_t count
= children
.Count();
1667 for ( size_t n
= 0; n
< count
; ++n
)
1669 UnselectAllChildren(children
[n
]);
1674 void wxGenericTreeCtrl::UnselectAll()
1676 wxTreeItemId rootItem
= GetRootItem();
1678 // the tree might not have the root item at all
1681 UnselectAllChildren((wxGenericTreeItem
*) rootItem
.m_pItem
);
1685 // Recursive function !
1686 // To stop we must have crt_item<last_item
1688 // Tag all next children, when no more children,
1689 // Move to parent (not to tag)
1690 // Keep going... if we found last_item, we stop.
1691 bool wxGenericTreeCtrl::TagNextChildren(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1693 wxGenericTreeItem
*parent
= crt_item
->GetParent();
1695 if (parent
== NULL
) // This is root item
1696 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
1698 wxArrayGenericTreeItems
& children
= parent
->GetChildren();
1699 int index
= children
.Index(crt_item
);
1700 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1702 size_t count
= children
.Count();
1703 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
1705 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return TRUE
;
1708 return TagNextChildren(parent
, last_item
, select
);
1711 bool wxGenericTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1713 crt_item
->SetHilight(select
);
1714 RefreshLine(crt_item
);
1716 if (crt_item
==last_item
)
1719 if (crt_item
->HasChildren())
1721 wxArrayGenericTreeItems
& children
= crt_item
->GetChildren();
1722 size_t count
= children
.Count();
1723 for ( size_t n
= 0; n
< count
; ++n
)
1725 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
1733 void wxGenericTreeCtrl::SelectItemRange(wxGenericTreeItem
*item1
, wxGenericTreeItem
*item2
)
1737 // item2 is not necessary after item1
1738 // choice first' and 'last' between item1 and item2
1739 wxGenericTreeItem
*first
= (item1
->GetY()<item2
->GetY()) ? item1
: item2
;
1740 wxGenericTreeItem
*last
= (item1
->GetY()<item2
->GetY()) ? item2
: item1
;
1742 bool select
= m_current
->IsSelected();
1744 if ( TagAllChildrenUntilLast(first
,last
,select
) )
1747 TagNextChildren(first
,last
,select
);
1750 void wxGenericTreeCtrl::DoSelectItem(const wxTreeItemId
& itemId
,
1751 bool unselect_others
,
1752 bool extended_select
)
1754 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
1758 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
1759 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1761 //wxCHECK_RET( ( (!unselect_others) && is_single),
1762 // wxT("this is a single selection tree") );
1764 // to keep going anyhow !!!
1767 if (item
->IsSelected())
1768 return; // nothing to do
1769 unselect_others
= TRUE
;
1770 extended_select
= FALSE
;
1772 else if ( unselect_others
&& item
->IsSelected() )
1774 // selection change if there is more than one item currently selected
1775 wxArrayTreeItemIds selected_items
;
1776 if ( GetSelections(selected_items
) == 1 )
1780 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, GetId() );
1781 event
.m_item
= item
;
1782 event
.m_itemOld
= m_current
;
1783 event
.SetEventObject( this );
1784 // TODO : Here we don't send any selection mode yet !
1786 if ( GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed() )
1789 wxTreeItemId parent
= GetItemParent( itemId
);
1790 while (parent
.IsOk())
1792 if (!IsExpanded(parent
))
1795 parent
= GetItemParent( parent
);
1798 EnsureVisible( itemId
);
1801 if (unselect_others
)
1803 if (is_single
) Unselect(); // to speed up thing
1808 if (extended_select
)
1812 m_current
= m_key_current
= (wxGenericTreeItem
*) GetRootItem().m_pItem
;
1815 // don't change the mark (m_current)
1816 SelectItemRange(m_current
, item
);
1820 bool select
=TRUE
; // the default
1822 // Check if we need to toggle hilight (ctrl mode)
1823 if (!unselect_others
)
1824 select
=!item
->IsSelected();
1826 m_current
= m_key_current
= item
;
1827 m_current
->SetHilight(select
);
1828 RefreshLine( m_current
);
1831 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
1832 GetEventHandler()->ProcessEvent( event
);
1835 void wxGenericTreeCtrl::SelectItem(const wxTreeItemId
& itemId
, bool select
)
1839 DoSelectItem(itemId
);
1843 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1844 wxCHECK_RET( item
, wxT("SelectItem(): invalid tree item") );
1846 item
->SetHilight(FALSE
);
1851 void wxGenericTreeCtrl::FillArray(wxGenericTreeItem
*item
,
1852 wxArrayTreeItemIds
&array
) const
1854 if ( item
->IsSelected() )
1855 array
.Add(wxTreeItemId(item
));
1857 if ( item
->HasChildren() )
1859 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1860 size_t count
= children
.GetCount();
1861 for ( size_t n
= 0; n
< count
; ++n
)
1862 FillArray(children
[n
], array
);
1866 size_t wxGenericTreeCtrl::GetSelections(wxArrayTreeItemIds
&array
) const
1869 wxTreeItemId idRoot
= GetRootItem();
1870 if ( idRoot
.IsOk() )
1872 FillArray((wxGenericTreeItem
*) idRoot
.m_pItem
, array
);
1874 //else: the tree is empty, so no selections
1876 return array
.Count();
1879 void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
1881 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1883 if (!item
.IsOk()) return;
1885 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1887 // first expand all parent branches
1888 wxGenericTreeItem
*parent
= gitem
->GetParent();
1890 if ( HasFlag(wxTR_HIDE_ROOT
) )
1892 while ( parent
&& parent
!= m_anchor
)
1895 parent
= parent
->GetParent();
1903 parent
= parent
->GetParent();
1907 //if (parent) CalculatePositions();
1912 void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId
&item
)
1914 if (!item
.IsOk()) return;
1916 // We have to call this here because the label in
1917 // question might just have been added and no screen
1918 // update taken place.
1920 #if defined( __WXMSW__ ) || defined(__WXMAC__)
1925 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1927 // now scroll to the item
1928 int item_y
= gitem
->GetY();
1932 GetViewStart( &start_x
, &start_y
);
1933 start_y
*= PIXELS_PER_UNIT
;
1937 GetClientSize( &client_w
, &client_h
);
1939 if (item_y
< start_y
+3)
1944 m_anchor
->GetSize( x
, y
, this );
1945 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1946 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1947 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1948 // Item should appear at top
1949 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
1951 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
1956 m_anchor
->GetSize( x
, y
, this );
1957 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1958 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1959 item_y
+= PIXELS_PER_UNIT
+2;
1960 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1961 // Item should appear at bottom
1962 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
);
1966 // FIXME: tree sorting functions are not reentrant and not MT-safe!
1967 static wxGenericTreeCtrl
*s_treeBeingSorted
= NULL
;
1969 static int LINKAGEMODE
tree_ctrl_compare_func(wxGenericTreeItem
**item1
,
1970 wxGenericTreeItem
**item2
)
1972 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxGenericTreeCtrl::SortChildren()") );
1974 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
1977 int wxGenericTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
1978 const wxTreeItemId
& item2
)
1980 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
1983 void wxGenericTreeCtrl::SortChildren(const wxTreeItemId
& itemId
)
1985 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
1987 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1989 wxCHECK_RET( !s_treeBeingSorted
,
1990 wxT("wxGenericTreeCtrl::SortChildren is not reentrant") );
1992 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1993 if ( children
.Count() > 1 )
1997 s_treeBeingSorted
= this;
1998 children
.Sort(tree_ctrl_compare_func
);
1999 s_treeBeingSorted
= NULL
;
2001 //else: don't make the tree dirty as nothing changed
2004 wxImageList
*wxGenericTreeCtrl::GetImageList() const
2006 return m_imageListNormal
;
2009 wxImageList
*wxGenericTreeCtrl::GetButtonsImageList() const
2011 return m_imageListButtons
;
2014 wxImageList
*wxGenericTreeCtrl::GetStateImageList() const
2016 return m_imageListState
;
2019 void wxGenericTreeCtrl::CalculateLineHeight()
2021 wxClientDC
dc(this);
2022 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
2024 if ( m_imageListNormal
)
2026 // Calculate a m_lineHeight value from the normal Image sizes.
2027 // May be toggle off. Then wxGenericTreeCtrl will spread when
2028 // necessary (which might look ugly).
2029 int n
= m_imageListNormal
->GetImageCount();
2030 for (int i
= 0; i
< n
; i
++)
2032 int width
= 0, height
= 0;
2033 m_imageListNormal
->GetSize(i
, width
, height
);
2034 if (height
> m_lineHeight
) m_lineHeight
= height
;
2038 if (m_imageListButtons
)
2040 // Calculate a m_lineHeight value from the Button image sizes.
2041 // May be toggle off. Then wxGenericTreeCtrl will spread when
2042 // necessary (which might look ugly).
2043 int n
= m_imageListButtons
->GetImageCount();
2044 for (int i
= 0; i
< n
; i
++)
2046 int width
= 0, height
= 0;
2047 m_imageListButtons
->GetSize(i
, width
, height
);
2048 if (height
> m_lineHeight
) m_lineHeight
= height
;
2052 if (m_lineHeight
< 30)
2053 m_lineHeight
+= 2; // at least 2 pixels
2055 m_lineHeight
+= m_lineHeight
/10; // otherwise 10% extra spacing
2058 void wxGenericTreeCtrl::SetImageList(wxImageList
*imageList
)
2060 if (m_ownsImageListNormal
) delete m_imageListNormal
;
2061 m_imageListNormal
= imageList
;
2062 m_ownsImageListNormal
= FALSE
;
2064 // Don't do any drawing if we're setting the list to NULL,
2065 // since we may be in the process of deleting the tree control.
2067 CalculateLineHeight();
2070 void wxGenericTreeCtrl::SetStateImageList(wxImageList
*imageList
)
2072 if (m_ownsImageListState
) delete m_imageListState
;
2073 m_imageListState
= imageList
;
2074 m_ownsImageListState
= FALSE
;
2077 void wxGenericTreeCtrl::SetButtonsImageList(wxImageList
*imageList
)
2079 if (m_ownsImageListButtons
) delete m_imageListButtons
;
2080 m_imageListButtons
= imageList
;
2081 m_ownsImageListButtons
= FALSE
;
2083 CalculateLineHeight();
2086 void wxGenericTreeCtrl::AssignImageList(wxImageList
*imageList
)
2088 SetImageList(imageList
);
2089 m_ownsImageListNormal
= TRUE
;
2092 void wxGenericTreeCtrl::AssignStateImageList(wxImageList
*imageList
)
2094 SetStateImageList(imageList
);
2095 m_ownsImageListState
= TRUE
;
2098 void wxGenericTreeCtrl::AssignButtonsImageList(wxImageList
*imageList
)
2100 SetButtonsImageList(imageList
);
2101 m_ownsImageListButtons
= TRUE
;
2104 // -----------------------------------------------------------------------------
2106 // -----------------------------------------------------------------------------
2108 void wxGenericTreeCtrl::AdjustMyScrollbars()
2113 m_anchor
->GetSize( x
, y
, this );
2114 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2115 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2116 int x_pos
= GetScrollPos( wxHORIZONTAL
);
2117 int y_pos
= GetScrollPos( wxVERTICAL
);
2118 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
2122 SetScrollbars( 0, 0, 0, 0 );
2126 int wxGenericTreeCtrl::GetLineHeight(wxGenericTreeItem
*item
) const
2128 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
2129 return item
->GetHeight();
2131 return m_lineHeight
;
2134 void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem
*item
, wxDC
& dc
)
2136 // TODO implement "state" icon on items
2138 wxTreeItemAttr
*attr
= item
->GetAttributes();
2139 if ( attr
&& attr
->HasFont() )
2140 dc
.SetFont(attr
->GetFont());
2141 else if (item
->IsBold())
2142 dc
.SetFont(m_boldFont
);
2144 long text_w
= 0, text_h
= 0;
2145 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
2147 int image_h
= 0, image_w
= 0;
2148 int image
= item
->GetCurrentImage();
2149 if ( image
!= NO_IMAGE
)
2151 if ( m_imageListNormal
)
2153 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
2162 int total_h
= GetLineHeight(item
);
2164 if ( item
->IsSelected() )
2166 // under mac selections are only a rectangle in case they don't have the focus
2170 dc
.SetBrush( *wxTRANSPARENT_BRUSH
) ;
2171 dc
.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
) , 1 , wxSOLID
) ) ;
2175 dc
.SetBrush( *m_hilightBrush
) ;
2178 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
2184 if ( attr
&& attr
->HasBackgroundColour() )
2185 colBg
= attr
->GetBackgroundColour();
2187 colBg
= m_backgroundColour
;
2188 dc
.SetBrush(wxBrush(colBg
, wxSOLID
));
2191 int offset
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0;
2193 if ( HasFlag(wxTR_FULL_ROW_HIGHLIGHT
) )
2197 DoGetPosition(&x
, &y
);
2199 dc
.DrawRectangle(x
, item
->GetY()+offset
, w
, total_h
-offset
);
2203 if ( item
->IsSelected() && image
!= NO_IMAGE
)
2205 // If it's selected, and there's an image, then we should
2206 // take care to leave the area under the image painted in the
2207 // background colour.
2208 dc
.DrawRectangle( item
->GetX() + image_w
- 2, item
->GetY()+offset
,
2209 item
->GetWidth() - image_w
+ 2, total_h
-offset
);
2213 dc
.DrawRectangle( item
->GetX()-2, item
->GetY()+offset
,
2214 item
->GetWidth()+2, total_h
-offset
);
2218 if ( image
!= NO_IMAGE
)
2220 dc
.SetClippingRegion( item
->GetX(), item
->GetY(), image_w
-2, total_h
);
2221 m_imageListNormal
->Draw( image
, dc
,
2223 item
->GetY() +((total_h
> image_h
)?((total_h
-image_h
)/2):0),
2224 wxIMAGELIST_DRAW_TRANSPARENT
);
2225 dc
.DestroyClippingRegion();
2228 dc
.SetBackgroundMode(wxTRANSPARENT
);
2229 int extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
2230 dc
.DrawText( item
->GetText(),
2231 (wxCoord
)(image_w
+ item
->GetX()),
2232 (wxCoord
)(item
->GetY() + extraH
));
2234 // restore normal font
2235 dc
.SetFont( m_normalFont
);
2238 // Now y stands for the top of the item, whereas it used to stand for middle !
2239 void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
2241 int x
= level
*m_indent
;
2242 if (!HasFlag(wxTR_HIDE_ROOT
))
2246 else if (level
== 0)
2248 // always expand hidden root
2250 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2251 int count
= children
.Count();
2257 PaintLevel(children
[n
], dc
, 1, y
);
2258 } while (++n
< count
);
2260 if (!HasFlag(wxTR_NO_LINES
) && HasFlag(wxTR_LINES_AT_ROOT
) && count
> 0)
2262 // draw line down to last child
2263 origY
+= GetLineHeight(children
[0])>>1;
2264 oldY
+= GetLineHeight(children
[n
-1])>>1;
2265 dc
.DrawLine(3, origY
, 3, oldY
);
2271 item
->SetX(x
+m_spacing
);
2274 int h
= GetLineHeight(item
);
2276 int y_mid
= y_top
+ (h
>>1);
2279 int exposed_x
= dc
.LogicalToDeviceX(0);
2280 int exposed_y
= dc
.LogicalToDeviceY(y_top
);
2282 if (IsExposed(exposed_x
, exposed_y
, 10000, h
)) // 10000 = very much
2286 // don't draw rect outline if we already have the
2287 // background color under Mac
2288 (item
->IsSelected() && m_hasFocus
) ? wxBLACK_PEN
:
2289 #endif // !__WXMAC__
2293 if ( item
->IsSelected() )
2295 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
2299 wxTreeItemAttr
*attr
= item
->GetAttributes();
2300 if (attr
&& attr
->HasTextColour())
2301 colText
= attr
->GetTextColour();
2303 colText
= GetForegroundColour();
2307 dc
.SetTextForeground(colText
);
2311 PaintItem(item
, dc
);
2313 if (HasFlag(wxTR_ROW_LINES
))
2315 // if the background colour is white, choose a
2316 // contrasting color for the lines
2317 dc
.SetPen(*((GetBackgroundColour() == *wxWHITE
)
2318 ? wxMEDIUM_GREY_PEN
: wxWHITE_PEN
));
2319 dc
.DrawLine(0, y_top
, 10000, y_top
);
2320 dc
.DrawLine(0, y
, 10000, y
);
2323 // restore DC objects
2324 dc
.SetBrush(*wxWHITE_BRUSH
);
2325 dc
.SetPen(m_dottedPen
);
2326 dc
.SetTextForeground(*wxBLACK
);
2328 if ( !HasFlag(wxTR_NO_LINES
) )
2330 // draw the horizontal line here
2332 if (x
> (signed)m_indent
)
2333 x_start
-= m_indent
;
2334 else if (HasFlag(wxTR_LINES_AT_ROOT
))
2336 dc
.DrawLine(x_start
, y_mid
, x
+ m_spacing
, y_mid
);
2339 // should the item show a button?
2340 if ( item
->HasPlus() && HasButtons() )
2342 if ( m_imageListButtons
)
2344 // draw the image button here
2347 int image
= item
->IsExpanded() ? wxTreeItemIcon_Expanded
2348 : wxTreeItemIcon_Normal
;
2349 if ( item
->IsSelected() )
2350 image
+= wxTreeItemIcon_Selected
- wxTreeItemIcon_Normal
;
2352 m_imageListButtons
->GetSize(image
, image_w
, image_h
);
2353 int xx
= x
- image_w
/2;
2354 int yy
= y_mid
- image_h
/2;
2356 wxDCClipper
clip(dc
, xx
, yy
, image_w
, image_h
);
2357 m_imageListButtons
->Draw(image
, dc
, xx
, yy
,
2358 wxIMAGELIST_DRAW_TRANSPARENT
);
2360 else // no custom buttons
2362 static const int wImage
= 9;
2363 static const int hImage
= 9;
2366 if (item
->IsExpanded())
2367 flag
|= wxCONTROL_EXPANDED
;
2368 if (item
== m_underMouse
)
2369 flag
|= wxCONTROL_CURRENT
;
2371 wxRendererNative::Get().DrawTreeItemButton
2375 wxRect(x
- wImage
/2,
2384 if (item
->IsExpanded())
2386 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2387 int count
= children
.Count();
2394 PaintLevel(children
[n
], dc
, level
, y
);
2395 } while (++n
< count
);
2397 if (!HasFlag(wxTR_NO_LINES
) && count
> 0)
2399 // draw line down to last child
2400 oldY
+= GetLineHeight(children
[n
-1])>>1;
2401 if (HasButtons()) y_mid
+= 5;
2403 // Only draw the portion of the line that is visible, in case it is huge
2404 wxCoord xOrigin
=0, yOrigin
=0, width
, height
;
2405 dc
.GetDeviceOrigin(&xOrigin
, &yOrigin
);
2406 yOrigin
= abs(yOrigin
);
2407 GetClientSize(&width
, &height
);
2409 // Move end points to the begining/end of the view?
2410 if (y_mid
< yOrigin
)
2412 if (oldY
> yOrigin
+ height
)
2413 oldY
= yOrigin
+ height
;
2415 // after the adjustments if y_mid is larger than oldY then the line
2416 // isn't visible at all so don't draw anything
2418 dc
.DrawLine(x
, y_mid
, x
, oldY
);
2424 void wxGenericTreeCtrl::DrawDropEffect(wxGenericTreeItem
*item
)
2428 if ( item
->HasPlus() )
2430 // it's a folder, indicate it by a border
2435 // draw a line under the drop target because the item will be
2437 DrawLine(item
, TRUE
/* below */);
2440 SetCursor(wxCURSOR_BULLSEYE
);
2445 SetCursor(wxCURSOR_NO_ENTRY
);
2449 void wxGenericTreeCtrl::DrawBorder(const wxTreeItemId
&item
)
2451 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2453 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2455 wxClientDC
dc(this);
2457 dc
.SetLogicalFunction(wxINVERT
);
2458 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2460 int w
= i
->GetWidth() + 2;
2461 int h
= GetLineHeight(i
) + 2;
2463 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
2466 void wxGenericTreeCtrl::DrawLine(const wxTreeItemId
&item
, bool below
)
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
);
2480 y
+= GetLineHeight(i
) - 1;
2483 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
2486 // -----------------------------------------------------------------------------
2487 // wxWidgets callbacks
2488 // -----------------------------------------------------------------------------
2490 void wxGenericTreeCtrl::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2498 dc
.SetFont( m_normalFont
);
2499 dc
.SetPen( m_dottedPen
);
2501 // this is now done dynamically
2502 //if(GetImageList() == NULL)
2503 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
2506 PaintLevel( m_anchor
, dc
, 0, y
);
2509 void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent
&event
)
2518 void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent
&event
)
2527 void wxGenericTreeCtrl::OnChar( wxKeyEvent
&event
)
2529 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, GetId() );
2530 te
.m_evtKey
= event
;
2531 te
.SetEventObject( this );
2532 if ( GetEventHandler()->ProcessEvent( te
) )
2534 // intercepted by the user code
2538 if ( (m_current
== 0) || (m_key_current
== 0) )
2544 // how should the selection work for this event?
2545 bool is_multiple
, extended_select
, unselect_others
;
2546 EventFlagsToSelType(GetWindowStyleFlag(),
2548 event
.ControlDown(),
2549 is_multiple
, extended_select
, unselect_others
);
2553 // * : Expand all/Collapse all
2554 // ' ' | return : activate
2555 // up : go up (not last children!)
2557 // left : go to parent
2558 // right : open if parent and go next
2559 // home : go to root
2560 // end : go to last item without opening parents
2561 // alnum : start or continue searching for the item with this prefix
2562 int keyCode
= event
.GetKeyCode();
2567 if (m_current
->HasPlus() && !IsExpanded(m_current
))
2575 if ( !IsExpanded(m_current
) )
2578 ExpandAll(m_current
);
2581 //else: fall through to Collapse() it
2585 if (IsExpanded(m_current
))
2587 Collapse(m_current
);
2593 if ( !event
.HasModifiers() )
2595 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
2596 event
.m_item
= m_current
;
2597 event
.SetEventObject( this );
2598 GetEventHandler()->ProcessEvent( event
);
2601 // in any case, also generate the normal key event for this key,
2602 // even if we generated the ACTIVATED event above: this is what
2603 // wxMSW does and it makes sense because you might not want to
2604 // process ACTIVATED event at all and handle Space and Return
2605 // directly (and differently) which would be impossible otherwise
2609 // up goes to the previous sibling or to the last
2610 // of its children if it's expanded
2613 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
2616 prev
= GetItemParent( m_key_current
);
2617 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2619 break; // don't go to root if it is hidden
2623 wxTreeItemIdValue cookie
;
2624 wxTreeItemId current
= m_key_current
;
2625 // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be?
2626 if (current
== GetFirstChild( prev
, cookie
))
2628 // otherwise we return to where we came from
2629 DoSelectItem( prev
, unselect_others
, extended_select
);
2630 m_key_current
= (wxGenericTreeItem
*) prev
.m_pItem
;
2637 while ( IsExpanded(prev
) && HasChildren(prev
) )
2639 wxTreeItemId child
= GetLastChild(prev
);
2646 DoSelectItem( prev
, unselect_others
, extended_select
);
2647 m_key_current
=(wxGenericTreeItem
*) prev
.m_pItem
;
2652 // left arrow goes to the parent
2655 wxTreeItemId prev
= GetItemParent( m_current
);
2656 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2658 // don't go to root if it is hidden
2659 prev
= GetPrevSibling( m_current
);
2663 DoSelectItem( prev
, unselect_others
, extended_select
);
2669 // this works the same as the down arrow except that we
2670 // also expand the item if it wasn't expanded yet
2676 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
2678 wxTreeItemIdValue cookie
;
2679 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
2680 DoSelectItem( child
, unselect_others
, extended_select
);
2681 m_key_current
=(wxGenericTreeItem
*) child
.m_pItem
;
2685 wxTreeItemId next
= GetNextSibling( m_key_current
);
2688 wxTreeItemId current
= m_key_current
;
2689 while (current
.IsOk() && !next
)
2691 current
= GetItemParent( current
);
2692 if (current
) next
= GetNextSibling( current
);
2697 DoSelectItem( next
, unselect_others
, extended_select
);
2698 m_key_current
=(wxGenericTreeItem
*) next
.m_pItem
;
2704 // <End> selects the last visible tree item
2707 wxTreeItemId last
= GetRootItem();
2709 while ( last
.IsOk() && IsExpanded(last
) )
2711 wxTreeItemId lastChild
= GetLastChild(last
);
2713 // it may happen if the item was expanded but then all of
2714 // its children have been deleted - so IsExpanded() returned
2715 // TRUE, but GetLastChild() returned invalid item
2724 DoSelectItem( last
, unselect_others
, extended_select
);
2729 // <Home> selects the root item
2732 wxTreeItemId prev
= GetRootItem();
2736 if ( HasFlag(wxTR_HIDE_ROOT
) )
2738 wxTreeItemIdValue cookie
;
2739 prev
= GetFirstChild(prev
, cookie
);
2744 DoSelectItem( prev
, unselect_others
, extended_select
);
2749 // do not use wxIsalnum() here
2750 if ( !event
.HasModifiers() &&
2751 ((keyCode
>= '0' && keyCode
<= '9') ||
2752 (keyCode
>= 'a' && keyCode
<= 'z') ||
2753 (keyCode
>= 'A' && keyCode
<= 'Z' )))
2755 // find the next item starting with the given prefix
2756 char ch
= (char)keyCode
;
2758 wxTreeItemId id
= FindItem(m_current
, m_findPrefix
+ (wxChar
)ch
);
2769 // also start the timer to reset the current prefix if the user
2770 // doesn't press any more alnum keys soon -- we wouldn't want
2771 // to use this prefix for a new item search
2774 m_findTimer
= new wxTreeFindTimer(this);
2777 m_findTimer
->Start(wxTreeFindTimer::DELAY
, wxTIMER_ONE_SHOT
);
2786 wxTreeItemId
wxGenericTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
2788 // JACS: removed wxYieldIfNeeded() because it can cause the window
2789 // to be deleted from under us if a close window event is pending
2794 if (point
.x
<0) flags
|= wxTREE_HITTEST_TOLEFT
;
2795 if (point
.x
>w
) flags
|= wxTREE_HITTEST_TORIGHT
;
2796 if (point
.y
<0) flags
|= wxTREE_HITTEST_ABOVE
;
2797 if (point
.y
>h
) flags
|= wxTREE_HITTEST_BELOW
;
2798 if (flags
) return wxTreeItemId();
2800 if (m_anchor
== NULL
)
2802 flags
= wxTREE_HITTEST_NOWHERE
;
2803 return wxTreeItemId();
2806 wxGenericTreeItem
*hit
= m_anchor
->HitTest(CalcUnscrolledPosition(point
),
2810 flags
= wxTREE_HITTEST_NOWHERE
;
2811 return wxTreeItemId();
2816 // get the bounding rectangle of the item (or of its label only)
2817 bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId
& item
,
2819 bool WXUNUSED(textOnly
)) const
2821 wxCHECK_MSG( item
.IsOk(), FALSE
, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
2823 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2826 GetViewStart(& startX
, & startY
);
2828 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
2829 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
2830 rect
.width
= i
->GetWidth();
2831 //rect.height = i->GetHeight();
2832 rect
.height
= GetLineHeight(i
);
2837 void wxGenericTreeCtrl::Edit( const wxTreeItemId
& item
)
2839 wxCHECK_RET( item
.IsOk(), _T("can't edit an invalid item") );
2841 wxGenericTreeItem
*itemEdit
= (wxGenericTreeItem
*)item
.m_pItem
;
2843 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, GetId() );
2844 te
.m_item
= itemEdit
;
2845 te
.SetEventObject( this );
2846 if ( GetEventHandler()->ProcessEvent( te
) && !te
.IsAllowed() )
2852 // We have to call this here because the label in
2853 // question might just have been added and no screen
2854 // update taken place.
2856 #if defined( __WXMSW__ ) || defined(__WXMAC__)
2862 m_textCtrl
= new wxTreeTextCtrl(this, itemEdit
);
2864 m_textCtrl
->SetFocus();
2867 // returns a pointer to the text edit control if the item is being
2868 // edited, NULL otherwise (it's assumed that no more than one item may
2869 // be edited simultaneously)
2870 wxTextCtrl
* wxGenericTreeCtrl::GetEditControl() const
2875 bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem
*item
,
2876 const wxString
& value
)
2878 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2880 le
.SetEventObject( this );
2882 le
.m_editCancelled
= FALSE
;
2884 return !GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2887 void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem
*item
)
2889 // let owner know that the edit was cancelled
2890 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2892 le
.SetEventObject( this );
2893 le
.m_label
= wxEmptyString
;
2894 le
.m_editCancelled
= TRUE
;
2896 GetEventHandler()->ProcessEvent( le
);
2902 void wxGenericTreeCtrl::OnRenameTimer()
2907 void wxGenericTreeCtrl::OnMouse( wxMouseEvent
&event
)
2909 if ( !m_anchor
) return;
2911 wxPoint pt
= CalcUnscrolledPosition(event
.GetPosition());
2913 // Is the mouse over a tree item button?
2915 wxGenericTreeItem
*thisItem
= m_anchor
->HitTest(pt
, this, flags
, 0);
2916 wxGenericTreeItem
*underMouse
= thisItem
;
2918 bool underMouseChanged
= (underMouse
!= m_underMouse
) ;
2919 #endif // wxUSE_TOOLTIPS
2922 (flags
& wxTREE_HITTEST_ONITEMBUTTON
) &&
2923 (!event
.LeftIsDown()) &&
2925 (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2933 if (underMouse
!= m_underMouse
)
2937 // unhighlight old item
2938 wxGenericTreeItem
*tmp
= m_underMouse
;
2939 m_underMouse
= NULL
;
2943 m_underMouse
= underMouse
;
2945 RefreshLine( m_underMouse
);
2949 // Determines what item we are hovering over and need a tooltip for
2950 wxTreeItemId hoverItem
= thisItem
;
2952 // We do not want a tooltip if we are dragging, or if the rename timer is running
2953 if (underMouseChanged
&& hoverItem
.IsOk() && !m_isDragging
&& (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2955 // Ask the tree control what tooltip (if any) should be shown
2956 wxTreeEvent
hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP
, GetId());
2957 hevent
.m_item
= hoverItem
;
2958 hevent
.SetEventObject(this);
2960 if ( GetEventHandler()->ProcessEvent(hevent
) && hevent
.IsAllowed() )
2962 SetToolTip(hevent
.m_label
);
2967 // we process left mouse up event (enables in-place edit), right down
2968 // (pass to the user code), left dbl click (activate item) and
2969 // dragging/moving events for items drag-and-drop
2970 if ( !(event
.LeftDown() ||
2972 event
.RightDown() ||
2973 event
.LeftDClick() ||
2975 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
2984 wxGenericTreeItem
*item
= m_anchor
->HitTest(pt
, this, flags
, 0);
2986 if ( event
.Dragging() && !m_isDragging
)
2988 if (m_dragCount
== 0)
2993 if (m_dragCount
!= 3)
2995 // wait until user drags a bit further...
2999 wxEventType command
= event
.RightIsDown()
3000 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
3001 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
3003 wxTreeEvent
nevent( command
, GetId() );
3004 nevent
.m_item
= m_current
;
3005 nevent
.SetEventObject(this);
3007 // by default the dragging is not supported, the user code must
3008 // explicitly allow the event for it to take place
3011 if ( GetEventHandler()->ProcessEvent(nevent
) && nevent
.IsAllowed() )
3013 // we're going to drag this item
3014 m_isDragging
= TRUE
;
3016 // remember the old cursor because we will change it while
3018 m_oldCursor
= m_cursor
;
3020 // in a single selection control, hide the selection temporarily
3021 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
3023 m_oldSelection
= (wxGenericTreeItem
*) GetSelection().m_pItem
;
3025 if ( m_oldSelection
)
3027 m_oldSelection
->SetHilight(FALSE
);
3028 RefreshLine(m_oldSelection
);
3035 else if ( event
.Moving() )
3037 if ( item
!= m_dropTarget
)
3039 // unhighlight the previous drop target
3040 DrawDropEffect(m_dropTarget
);
3042 m_dropTarget
= item
;
3044 // highlight the current drop target if any
3045 DrawDropEffect(m_dropTarget
);
3047 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3054 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
3056 // erase the highlighting
3057 DrawDropEffect(m_dropTarget
);
3059 if ( m_oldSelection
)
3061 m_oldSelection
->SetHilight(TRUE
);
3062 RefreshLine(m_oldSelection
);
3063 m_oldSelection
= (wxGenericTreeItem
*)NULL
;
3066 // generate the drag end event
3067 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
, GetId());
3069 event
.m_item
= item
;
3070 event
.m_pointDrag
= pt
;
3071 event
.SetEventObject(this);
3073 (void)GetEventHandler()->ProcessEvent(event
);
3075 m_isDragging
= FALSE
;
3076 m_dropTarget
= (wxGenericTreeItem
*)NULL
;
3080 SetCursor(m_oldCursor
);
3082 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3090 // here we process only the messages which happen on tree items
3094 if (item
== NULL
) return; /* we hit the blank area */
3096 if ( event
.RightDown() )
3098 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
, GetId());
3099 nevent
.m_item
= item
;
3100 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3101 nevent
.SetEventObject(this);
3102 GetEventHandler()->ProcessEvent(nevent
);
3104 else if ( event
.LeftUp() )
3106 // this facilitates multiple-item drag-and-drop
3108 if (item
&& HasFlag(wxTR_MULTIPLE
))
3110 wxArrayTreeItemIds selections
;
3111 size_t count
= GetSelections(selections
);
3114 !event
.ControlDown() &&
3117 DoSelectItem(item
, true, false);
3123 if ( (item
== m_current
) &&
3124 (flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
3125 HasFlag(wxTR_EDIT_LABELS
) )
3127 if ( m_renameTimer
)
3129 if ( m_renameTimer
->IsRunning() )
3130 m_renameTimer
->Stop();
3134 m_renameTimer
= new wxTreeRenameTimer( this );
3137 m_renameTimer
->Start( wxTreeRenameTimer::DELAY
, TRUE
);
3140 m_lastOnSame
= FALSE
;
3143 else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
3145 if ( event
.LeftDown() )
3147 m_lastOnSame
= item
== m_current
;
3150 if ( flags
& wxTREE_HITTEST_ONITEMBUTTON
)
3152 // only toggle the item for a single click, double click on
3153 // the button doesn't do anything (it toggles the item twice)
3154 if ( event
.LeftDown() )
3159 // don't select the item if the button was clicked
3164 // clear the previously selected items, if the
3165 // user clicked outside of the present selection.
3166 // otherwise, perform the deselection on mouse-up.
3167 // this allows multiple drag and drop to work.
3169 if (!IsSelected(item
))
3171 // how should the selection work for this event?
3172 bool is_multiple
, extended_select
, unselect_others
;
3173 EventFlagsToSelType(GetWindowStyleFlag(),
3175 event
.ControlDown(),
3176 is_multiple
, extended_select
, unselect_others
);
3178 DoSelectItem(item
, unselect_others
, extended_select
);
3182 // For some reason, Windows isn't recognizing a left double-click,
3183 // so we need to simulate it here. Allow 200 milliseconds for now.
3184 if ( event
.LeftDClick() )
3186 // double clicking should not start editing the item label
3187 if ( m_renameTimer
)
3188 m_renameTimer
->Stop();
3190 m_lastOnSame
= FALSE
;
3192 // send activate event first
3193 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
3194 nevent
.m_item
= item
;
3195 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3196 nevent
.SetEventObject( this );
3197 if ( !GetEventHandler()->ProcessEvent( nevent
) )
3199 // if the user code didn't process the activate event,
3200 // handle it ourselves by toggling the item when it is
3202 if ( item
->HasPlus() )
3212 void wxGenericTreeCtrl::OnInternalIdle()
3214 wxWindow::OnInternalIdle();
3216 // Check if we need to select the root item
3217 // because nothing else has been selected.
3218 // Delaying it means that we can invoke event handlers
3219 // as required, when a first item is selected.
3220 if (!HasFlag(wxTR_MULTIPLE
) && !GetSelection().IsOk())
3223 SelectItem(m_select_me
);
3224 else if (GetRootItem().IsOk())
3225 SelectItem(GetRootItem());
3228 /* after all changes have been done to the tree control,
3229 * we actually redraw the tree when everything is over */
3231 if (!m_dirty
) return;
3232 if (m_freezeCount
) return;
3236 CalculatePositions();
3238 AdjustMyScrollbars();
3241 void wxGenericTreeCtrl::CalculateSize( wxGenericTreeItem
*item
, wxDC
&dc
)
3246 wxTreeItemAttr
*attr
= item
->GetAttributes();
3247 if ( attr
&& attr
->HasFont() )
3248 dc
.SetFont(attr
->GetFont());
3249 else if ( item
->IsBold() )
3250 dc
.SetFont(m_boldFont
);
3252 dc
.SetFont(m_normalFont
);
3254 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
3257 // restore normal font
3258 dc
.SetFont( m_normalFont
);
3262 int image
= item
->GetCurrentImage();
3263 if ( image
!= NO_IMAGE
)
3265 if ( m_imageListNormal
)
3267 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
3272 int total_h
= (image_h
> text_h
) ? image_h
: text_h
;
3275 total_h
+= 2; // at least 2 pixels
3277 total_h
+= total_h
/10; // otherwise 10% extra spacing
3279 item
->SetHeight(total_h
);
3280 if (total_h
>m_lineHeight
)
3281 m_lineHeight
=total_h
;
3283 item
->SetWidth(image_w
+text_w
+2);
3286 // -----------------------------------------------------------------------------
3287 // for developper : y is now the top of the level
3288 // not the middle of it !
3289 void wxGenericTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
3291 int x
= level
*m_indent
;
3292 if (!HasFlag(wxTR_HIDE_ROOT
))
3296 else if (level
== 0)
3298 // a hidden root is not evaluated, but its
3299 // children are always calculated
3303 CalculateSize( item
, dc
);
3306 item
->SetX( x
+m_spacing
);
3308 y
+= GetLineHeight(item
);
3310 if ( !item
->IsExpanded() )
3312 // we don't need to calculate collapsed branches
3317 wxArrayGenericTreeItems
& children
= item
->GetChildren();
3318 size_t n
, count
= children
.Count();
3320 for (n
= 0; n
< count
; ++n
)
3321 CalculateLevel( children
[n
], dc
, level
, y
); // recurse
3324 void wxGenericTreeCtrl::CalculatePositions()
3326 if ( !m_anchor
) return;
3328 wxClientDC
dc(this);
3331 dc
.SetFont( m_normalFont
);
3333 dc
.SetPen( m_dottedPen
);
3334 //if(GetImageList() == NULL)
3335 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
3338 CalculateLevel( m_anchor
, dc
, 0, y
); // start recursion
3341 void wxGenericTreeCtrl::RefreshSubtree(wxGenericTreeItem
*item
)
3343 if (m_dirty
) return;
3344 if (m_freezeCount
) return;
3346 wxSize client
= GetClientSize();
3349 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3350 rect
.width
= client
.x
;
3351 rect
.height
= client
.y
;
3353 Refresh(TRUE
, &rect
);
3355 AdjustMyScrollbars();
3358 void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
3360 if (m_dirty
) return;
3361 if (m_freezeCount
) return;
3364 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3365 rect
.width
= GetClientSize().x
;
3366 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
3368 Refresh(TRUE
, &rect
);
3371 void wxGenericTreeCtrl::RefreshSelected()
3373 if (m_freezeCount
) return;
3375 // TODO: this is awfully inefficient, we should keep the list of all
3376 // selected items internally, should be much faster
3378 RefreshSelectedUnder(m_anchor
);
3381 void wxGenericTreeCtrl::RefreshSelectedUnder(wxGenericTreeItem
*item
)
3383 if (m_freezeCount
) return;
3385 if ( item
->IsSelected() )
3388 const wxArrayGenericTreeItems
& children
= item
->GetChildren();
3389 size_t count
= children
.GetCount();
3390 for ( size_t n
= 0; n
< count
; n
++ )
3392 RefreshSelectedUnder(children
[n
]);
3396 void wxGenericTreeCtrl::Freeze()
3401 void wxGenericTreeCtrl::Thaw()
3403 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen tree control?") );
3405 if ( !--m_freezeCount
)
3411 // ----------------------------------------------------------------------------
3412 // changing colours: we need to refresh the tree control
3413 // ----------------------------------------------------------------------------
3415 bool wxGenericTreeCtrl::SetBackgroundColour(const wxColour
& colour
)
3417 if ( !wxWindow::SetBackgroundColour(colour
) )
3420 if (m_freezeCount
) return TRUE
;
3427 bool wxGenericTreeCtrl::SetForegroundColour(const wxColour
& colour
)
3429 if ( !wxWindow::SetForegroundColour(colour
) )
3432 if (m_freezeCount
) return TRUE
;
3439 // Process the tooltip event, to speed up event processing.
3440 // Doesn't actually get a tooltip.
3441 void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent
&event
)
3447 // NOTE: If using the wxListBox visual attributes works everywhere then this can
3448 // be removed, as well as the #else case below.
3449 #define _USE_VISATTR 0
3452 #include "wx/listbox.h"
3458 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
3460 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3464 // Use the same color scheme as wxListBox
3465 return wxListBox::GetClassDefaultAttributes(variant
);
3467 wxVisualAttributes attr
;
3468 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
3469 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
3470 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
3475 #endif // wxUSE_TREECTRL