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
);
91 // wxGenericTreeCtrl can use this one to abandon editing the given item,
92 // it's not an error to call it if this item is not being edited
93 void StopEditing(wxGenericTreeItem
*item
)
95 if ( item
== m_itemEdited
)
100 void OnChar( wxKeyEvent
&event
);
101 void OnKeyUp( wxKeyEvent
&event
);
102 void OnKillFocus( wxFocusEvent
&event
);
107 m_owner
->OnRenameCancelled(m_itemEdited
);
110 bool AcceptChanges();
114 wxGenericTreeCtrl
*m_owner
;
115 wxGenericTreeItem
*m_itemEdited
;
116 wxString m_startValue
;
119 DECLARE_EVENT_TABLE()
120 DECLARE_NO_COPY_CLASS(wxTreeTextCtrl
)
123 // timer used to clear wxGenericTreeCtrl::m_findPrefix if no key was pressed
124 // for a sufficiently long time
125 class WXDLLEXPORT wxTreeFindTimer
: public wxTimer
128 // reset the current prefix after half a second of inactivity
129 enum { DELAY
= 500 };
131 wxTreeFindTimer( wxGenericTreeCtrl
*owner
) { m_owner
= owner
; }
133 virtual void Notify() { m_owner
->m_findPrefix
.clear(); }
136 wxGenericTreeCtrl
*m_owner
;
138 DECLARE_NO_COPY_CLASS(wxTreeFindTimer
)
142 class WXDLLEXPORT wxGenericTreeItem
146 wxGenericTreeItem() { m_data
= NULL
; }
147 wxGenericTreeItem( wxGenericTreeItem
*parent
,
148 const wxString
& text
,
151 wxTreeItemData
*data
);
153 ~wxGenericTreeItem();
156 wxArrayGenericTreeItems
& GetChildren() { return m_children
; }
158 const wxString
& GetText() const { return m_text
; }
159 int GetImage(wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
160 { return m_images
[which
]; }
161 wxTreeItemData
*GetData() const { return m_data
; }
163 // returns the current image for the item (depending on its
164 // selected/expanded/whatever state)
165 int GetCurrentImage() const;
167 void SetText( const wxString
&text
);
168 void SetImage(int image
, wxTreeItemIcon which
) { m_images
[which
] = image
; }
169 void SetData(wxTreeItemData
*data
) { m_data
= data
; }
171 void SetHasPlus(bool has
= true) { m_hasPlus
= has
; }
173 void SetBold(bool bold
) { m_isBold
= bold
; }
175 int GetX() const { return m_x
; }
176 int GetY() const { return m_y
; }
178 void SetX(int x
) { m_x
= x
; }
179 void SetY(int y
) { m_y
= y
; }
181 int GetHeight() const { return m_height
; }
182 int GetWidth() const { return m_width
; }
184 void SetHeight(int h
) { m_height
= h
; }
185 void SetWidth(int w
) { m_width
= w
; }
187 wxGenericTreeItem
*GetParent() const { return m_parent
; }
190 // deletes all children notifying the treectrl about it if !NULL
192 void DeleteChildren(wxGenericTreeCtrl
*tree
= NULL
);
194 // get count of all children (and grand children if 'recursively')
195 size_t GetChildrenCount(bool recursively
= true) const;
197 void Insert(wxGenericTreeItem
*child
, size_t index
)
198 { m_children
.Insert(child
, index
); }
200 void GetSize( int &x
, int &y
, const wxGenericTreeCtrl
* );
202 // return the item at given position (or NULL if no item), onButton is
203 // true if the point belongs to the item's button, otherwise it lies
204 // on the item's label
205 wxGenericTreeItem
*HitTest( const wxPoint
& point
,
206 const wxGenericTreeCtrl
*,
210 void Expand() { m_isCollapsed
= false; }
211 void Collapse() { m_isCollapsed
= true; }
213 void SetHilight( bool set
= true ) { m_hasHilight
= set
; }
216 bool HasChildren() const { return !m_children
.IsEmpty(); }
217 bool IsSelected() const { return m_hasHilight
!= 0; }
218 bool IsExpanded() const { return !m_isCollapsed
; }
219 bool HasPlus() const { return m_hasPlus
|| HasChildren(); }
220 bool IsBold() const { return m_isBold
!= 0; }
223 // get them - may be NULL
224 wxTreeItemAttr
*GetAttributes() const { return m_attr
; }
225 // get them ensuring that the pointer is not NULL
226 wxTreeItemAttr
& Attr()
230 m_attr
= new wxTreeItemAttr
;
236 void SetAttributes(wxTreeItemAttr
*attr
)
238 if ( m_ownsAttr
) delete m_attr
;
242 // set them and delete when done
243 void AssignAttributes(wxTreeItemAttr
*attr
)
250 // since there can be very many of these, we save size by chosing
251 // the smallest representation for the elements and by ordering
252 // the members to avoid padding.
253 wxString m_text
; // label to be rendered for item
255 wxTreeItemData
*m_data
; // user-provided data
257 wxArrayGenericTreeItems m_children
; // list of children
258 wxGenericTreeItem
*m_parent
; // parent of this item
260 wxTreeItemAttr
*m_attr
; // attributes???
262 // tree ctrl images for the normal, selected, expanded and
263 // expanded+selected states
264 short m_images
[wxTreeItemIcon_Max
];
266 wxCoord m_x
; // (virtual) offset from top
267 wxCoord m_y
; // (virtual) offset from left
268 short m_width
; // width of this item
269 unsigned char m_height
; // height of this item
271 // use bitfields to save size
272 int m_isCollapsed
:1;
273 int m_hasHilight
:1; // same as focused
274 int m_hasPlus
:1; // used for item which doesn't have
275 // children but has a [+] button
276 int m_isBold
:1; // render the label in bold font
277 int m_ownsAttr
:1; // delete attribute when done
279 DECLARE_NO_COPY_CLASS(wxGenericTreeItem
)
282 // =============================================================================
284 // =============================================================================
286 // ----------------------------------------------------------------------------
288 // ----------------------------------------------------------------------------
290 // translate the key or mouse event flags to the type of selection we're
292 static void EventFlagsToSelType(long style
,
296 bool &extended_select
,
297 bool &unselect_others
)
299 is_multiple
= (style
& wxTR_MULTIPLE
) != 0;
300 extended_select
= shiftDown
&& is_multiple
;
301 unselect_others
= !(extended_select
|| (ctrlDown
&& is_multiple
));
304 // check if the given item is under another one
305 static bool IsDescendantOf(wxGenericTreeItem
*parent
, wxGenericTreeItem
*item
)
309 if ( item
== parent
)
311 // item is a descendant of parent
315 item
= item
->GetParent();
321 // -----------------------------------------------------------------------------
322 // wxTreeRenameTimer (internal)
323 // -----------------------------------------------------------------------------
325 wxTreeRenameTimer::wxTreeRenameTimer( wxGenericTreeCtrl
*owner
)
330 void wxTreeRenameTimer::Notify()
332 m_owner
->OnRenameTimer();
335 //-----------------------------------------------------------------------------
336 // wxTreeTextCtrl (internal)
337 //-----------------------------------------------------------------------------
339 BEGIN_EVENT_TABLE(wxTreeTextCtrl
,wxTextCtrl
)
340 EVT_CHAR (wxTreeTextCtrl::OnChar
)
341 EVT_KEY_UP (wxTreeTextCtrl::OnKeyUp
)
342 EVT_KILL_FOCUS (wxTreeTextCtrl::OnKillFocus
)
345 wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl
*owner
,
346 wxGenericTreeItem
*item
)
347 : m_itemEdited(item
), m_startValue(item
->GetText())
352 int w
= m_itemEdited
->GetWidth(),
353 h
= m_itemEdited
->GetHeight();
356 m_owner
->CalcScrolledPosition(item
->GetX(), item
->GetY(), &x
, &y
);
361 int image
= item
->GetCurrentImage();
362 if ( image
!= NO_IMAGE
)
364 if ( m_owner
->m_imageListNormal
)
366 m_owner
->m_imageListNormal
->GetSize( image
, image_w
, image_h
);
371 wxFAIL_MSG(_T("you must create an image list to use images!"));
375 // FIXME: what are all these hardcoded 4, 8 and 11s really?
379 (void)Create(m_owner
, wxID_ANY
, m_startValue
,
380 wxPoint(x
- 4, y
- 4), wxSize(w
+ 11, h
+ 8));
383 bool wxTreeTextCtrl::AcceptChanges()
385 const wxString value
= GetValue();
387 if ( value
== m_startValue
)
389 // nothing changed, always accept
393 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
395 // vetoed by the user
399 // accepted, do rename the item
400 m_owner
->SetItemText(m_itemEdited
, value
);
405 void wxTreeTextCtrl::Finish()
409 m_owner
->ResetTextControl();
411 wxPendingDelete
.Append(this);
415 m_owner
->SetFocus(); // This doesn't work. TODO.
419 void wxTreeTextCtrl::OnChar( wxKeyEvent
&event
)
421 switch ( event
.m_keyCode
)
424 if ( AcceptChanges() )
426 // Close the text control, changes were accepted
429 // else do nothing, do not accept and do not close
441 void wxTreeTextCtrl::OnKeyUp( wxKeyEvent
&event
)
445 // auto-grow the textctrl:
446 wxSize parentSize
= m_owner
->GetSize();
447 wxPoint myPos
= GetPosition();
448 wxSize mySize
= GetSize();
450 GetTextExtent(GetValue() + _T("M"), &sx
, &sy
);
451 if (myPos
.x
+ sx
> parentSize
.x
)
452 sx
= parentSize
.x
- myPos
.x
;
455 SetSize(sx
, wxDefaultCoord
);
461 void wxTreeTextCtrl::OnKillFocus( wxFocusEvent
&event
)
466 // We must finish regardless of success, otherwise we'll get
471 // We must let the native text control handle focus, too, otherwise
472 // it could have problems with the cursor (e.g., in wxGTK):
476 // -----------------------------------------------------------------------------
478 // -----------------------------------------------------------------------------
480 wxGenericTreeItem::wxGenericTreeItem(wxGenericTreeItem
*parent
,
481 const wxString
& text
,
482 int image
, int selImage
,
483 wxTreeItemData
*data
)
486 m_images
[wxTreeItemIcon_Normal
] = image
;
487 m_images
[wxTreeItemIcon_Selected
] = selImage
;
488 m_images
[wxTreeItemIcon_Expanded
] = NO_IMAGE
;
489 m_images
[wxTreeItemIcon_SelectedExpanded
] = NO_IMAGE
;
494 m_isCollapsed
= true;
495 m_hasHilight
= false;
501 m_attr
= (wxTreeItemAttr
*)NULL
;
504 // We don't know the height here yet.
509 wxGenericTreeItem::~wxGenericTreeItem()
513 if (m_ownsAttr
) delete m_attr
;
515 wxASSERT_MSG( m_children
.IsEmpty(),
516 wxT("please call DeleteChildren() before deleting the item") );
519 void wxGenericTreeItem::DeleteChildren(wxGenericTreeCtrl
*tree
)
521 size_t count
= m_children
.Count();
522 for ( size_t n
= 0; n
< count
; n
++ )
524 wxGenericTreeItem
*child
= m_children
[n
];
526 tree
->SendDeleteEvent(child
);
528 child
->DeleteChildren(tree
);
535 void wxGenericTreeItem::SetText( const wxString
&text
)
540 size_t wxGenericTreeItem::GetChildrenCount(bool recursively
) const
542 size_t count
= m_children
.Count();
546 size_t total
= count
;
547 for (size_t n
= 0; n
< count
; ++n
)
549 total
+= m_children
[n
]->GetChildrenCount();
555 void wxGenericTreeItem::GetSize( int &x
, int &y
,
556 const wxGenericTreeCtrl
*theButton
)
558 int bottomY
=m_y
+theButton
->GetLineHeight(this);
559 if ( y
< bottomY
) y
= bottomY
;
560 int width
= m_x
+ m_width
;
561 if ( x
< width
) x
= width
;
565 size_t count
= m_children
.Count();
566 for ( size_t n
= 0; n
< count
; ++n
)
568 m_children
[n
]->GetSize( x
, y
, theButton
);
573 wxGenericTreeItem
*wxGenericTreeItem::HitTest(const wxPoint
& point
,
574 const wxGenericTreeCtrl
*theCtrl
,
578 // for a hidden root node, don't evaluate it, but do evaluate children
579 if ( !(level
== 0 && theCtrl
->HasFlag(wxTR_HIDE_ROOT
)) )
582 int h
= theCtrl
->GetLineHeight(this);
583 if ((point
.y
> m_y
) && (point
.y
< m_y
+ h
))
585 int y_mid
= m_y
+ h
/2;
586 if (point
.y
< y_mid
)
587 flags
|= wxTREE_HITTEST_ONITEMUPPERPART
;
589 flags
|= wxTREE_HITTEST_ONITEMLOWERPART
;
591 int xCross
= m_x
- theCtrl
->GetSpacing();
593 // according to the drawing code the triangels are drawn
594 // at -4 , -4 from the position up to +10/+10 max
595 if ((point
.x
> xCross
-4) && (point
.x
< xCross
+10) &&
596 (point
.y
> y_mid
-4) && (point
.y
< y_mid
+10) &&
597 HasPlus() && theCtrl
->HasButtons() )
599 // 5 is the size of the plus sign
600 if ((point
.x
> xCross
-6) && (point
.x
< xCross
+6) &&
601 (point
.y
> y_mid
-6) && (point
.y
< y_mid
+6) &&
602 HasPlus() && theCtrl
->HasButtons() )
605 flags
|= wxTREE_HITTEST_ONITEMBUTTON
;
609 if ((point
.x
>= m_x
) && (point
.x
<= m_x
+m_width
))
614 // assuming every image (normal and selected) has the same size!
615 if ( (GetImage() != NO_IMAGE
) && theCtrl
->m_imageListNormal
)
616 theCtrl
->m_imageListNormal
->GetSize(GetImage(),
619 if ((image_w
!= -1) && (point
.x
<= m_x
+ image_w
+ 1))
620 flags
|= wxTREE_HITTEST_ONITEMICON
;
622 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
628 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
629 if (point
.x
> m_x
+m_width
)
630 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
635 // if children are expanded, fall through to evaluate them
636 if (m_isCollapsed
) return (wxGenericTreeItem
*) NULL
;
640 size_t count
= m_children
.Count();
641 for ( size_t n
= 0; n
< count
; n
++ )
643 wxGenericTreeItem
*res
= m_children
[n
]->HitTest( point
,
651 return (wxGenericTreeItem
*) NULL
;
654 int wxGenericTreeItem::GetCurrentImage() const
656 int image
= NO_IMAGE
;
661 image
= GetImage(wxTreeItemIcon_SelectedExpanded
);
664 if ( image
== NO_IMAGE
)
666 // we usually fall back to the normal item, but try just the
667 // expanded one (and not selected) first in this case
668 image
= GetImage(wxTreeItemIcon_Expanded
);
674 image
= GetImage(wxTreeItemIcon_Selected
);
677 // maybe it doesn't have the specific image we want,
678 // try the default one instead
679 if ( image
== NO_IMAGE
) image
= GetImage();
684 // -----------------------------------------------------------------------------
685 // wxGenericTreeCtrl implementation
686 // -----------------------------------------------------------------------------
688 IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl
, wxScrolledWindow
)
690 BEGIN_EVENT_TABLE(wxGenericTreeCtrl
,wxScrolledWindow
)
691 EVT_PAINT (wxGenericTreeCtrl::OnPaint
)
692 EVT_MOUSE_EVENTS (wxGenericTreeCtrl::OnMouse
)
693 EVT_CHAR (wxGenericTreeCtrl::OnChar
)
694 EVT_SET_FOCUS (wxGenericTreeCtrl::OnSetFocus
)
695 EVT_KILL_FOCUS (wxGenericTreeCtrl::OnKillFocus
)
696 EVT_TREE_ITEM_GETTOOLTIP(wxID_ANY
, wxGenericTreeCtrl::OnGetToolTip
)
699 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
701 * wxTreeCtrl has to be a real class or we have problems with
702 * the run-time information.
705 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxGenericTreeCtrl
)
708 // -----------------------------------------------------------------------------
709 // construction/destruction
710 // -----------------------------------------------------------------------------
712 void wxGenericTreeCtrl::Init()
714 m_current
= m_key_current
= m_anchor
= m_select_me
= (wxGenericTreeItem
*) NULL
;
722 m_hilightBrush
= new wxBrush
724 wxSystemSettings::GetColour
726 wxSYS_COLOUR_HIGHLIGHT
731 m_hilightUnfocusedBrush
= new wxBrush
733 wxSystemSettings::GetColour
735 wxSYS_COLOUR_BTNSHADOW
740 m_imageListNormal
= m_imageListButtons
=
741 m_imageListState
= (wxImageList
*) NULL
;
742 m_ownsImageListNormal
= m_ownsImageListButtons
=
743 m_ownsImageListState
= false;
746 m_isDragging
= false;
747 m_dropTarget
= m_oldSelection
= NULL
;
751 m_renameTimer
= NULL
;
756 m_lastOnSame
= false;
758 #if defined( __WXMAC__ ) && __WXMAC_CARBON__
759 m_normalFont
.MacCreateThemeFont( kThemeViewsFont
) ;
761 m_normalFont
= wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT
);
763 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
764 m_normalFont
.GetFamily(),
765 m_normalFont
.GetStyle(),
767 m_normalFont
.GetUnderlined(),
768 m_normalFont
.GetFaceName(),
769 m_normalFont
.GetEncoding());
772 bool wxGenericTreeCtrl::Create(wxWindow
*parent
,
777 const wxValidator
& wxVALIDATOR_PARAM(validator
),
778 const wxString
& name
)
782 wxGetOsVersion( &major
, &minor
);
784 style
&= ~wxTR_LINES_AT_ROOT
;
785 style
|= wxTR_NO_LINES
;
787 style
|= wxTR_ROW_LINES
;
790 wxScrolledWindow::Create( parent
, id
, pos
, size
,
791 style
|wxHSCROLL
|wxVSCROLL
, name
);
793 // If the tree display has no buttons, but does have
794 // connecting lines, we can use a narrower layout.
795 // It may not be a good idea to force this...
796 if (!HasButtons() && !HasFlag(wxTR_NO_LINES
))
803 SetValidator( validator
);
806 wxVisualAttributes attr
= GetDefaultAttributes();
807 SetOwnForegroundColour( attr
.colFg
);
808 SetOwnBackgroundColour( attr
.colBg
);
810 SetOwnFont(attr
.font
);
812 // m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86
813 m_dottedPen
= wxPen( wxT("grey"), 0, 0 );
820 wxGenericTreeCtrl::~wxGenericTreeCtrl()
822 delete m_hilightBrush
;
823 delete m_hilightUnfocusedBrush
;
827 delete m_renameTimer
;
830 if (m_ownsImageListNormal
)
831 delete m_imageListNormal
;
832 if (m_ownsImageListState
)
833 delete m_imageListState
;
834 if (m_ownsImageListButtons
)
835 delete m_imageListButtons
;
838 // -----------------------------------------------------------------------------
840 // -----------------------------------------------------------------------------
842 size_t wxGenericTreeCtrl::GetCount() const
850 size_t count
= m_anchor
->GetChildrenCount();
851 if ( !HasFlag(wxTR_HIDE_ROOT
) )
853 // take the root itself into account
860 void wxGenericTreeCtrl::SetIndent(unsigned int indent
)
862 m_indent
= (unsigned short) indent
;
866 void wxGenericTreeCtrl::SetSpacing(unsigned int spacing
)
868 m_spacing
= (unsigned short) spacing
;
873 wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
,
874 bool recursively
) const
876 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
878 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
881 void wxGenericTreeCtrl::SetWindowStyle(const long styles
)
883 if (!HasFlag(wxTR_HIDE_ROOT
) && (styles
& wxTR_HIDE_ROOT
))
885 // if we will hide the root, make sure children are visible
886 m_anchor
->SetHasPlus();
888 CalculatePositions();
891 // right now, just sets the styles. Eventually, we may
892 // want to update the inherited styles, but right now
893 // none of the parents has updatable styles
894 m_windowStyle
= styles
;
898 // -----------------------------------------------------------------------------
899 // functions to work with tree items
900 // -----------------------------------------------------------------------------
902 wxString
wxGenericTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
904 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
906 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetText();
909 int wxGenericTreeCtrl::GetItemImage(const wxTreeItemId
& item
,
910 wxTreeItemIcon which
) const
912 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
914 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetImage(which
);
917 wxTreeItemData
*wxGenericTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
919 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
921 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetData();
924 wxColour
wxGenericTreeCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
926 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
928 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
929 return pItem
->Attr().GetTextColour();
932 wxColour
wxGenericTreeCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
) const
934 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
936 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
937 return pItem
->Attr().GetBackgroundColour();
940 wxFont
wxGenericTreeCtrl::GetItemFont(const wxTreeItemId
& item
) const
942 wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") );
944 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
945 return pItem
->Attr().GetFont();
948 void wxGenericTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
950 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
953 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
954 pItem
->SetText(text
);
955 CalculateSize(pItem
, dc
);
959 void wxGenericTreeCtrl::SetItemImage(const wxTreeItemId
& item
,
961 wxTreeItemIcon which
)
963 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
965 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
966 pItem
->SetImage(image
, which
);
969 CalculateSize(pItem
, dc
);
973 void wxGenericTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
975 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
980 ((wxGenericTreeItem
*) item
.m_pItem
)->SetData(data
);
983 void wxGenericTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
985 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
987 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
988 pItem
->SetHasPlus(has
);
992 void wxGenericTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
994 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
996 // avoid redrawing the tree if no real change
997 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
998 if ( pItem
->IsBold() != bold
)
1000 pItem
->SetBold(bold
);
1005 void wxGenericTreeCtrl::SetItemTextColour(const wxTreeItemId
& item
,
1006 const wxColour
& col
)
1008 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1010 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1011 pItem
->Attr().SetTextColour(col
);
1015 void wxGenericTreeCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
1016 const wxColour
& col
)
1018 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1020 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1021 pItem
->Attr().SetBackgroundColour(col
);
1025 void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
)
1027 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1029 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1030 pItem
->Attr().SetFont(font
);
1034 bool wxGenericTreeCtrl::SetFont( const wxFont
&font
)
1036 wxScrolledWindow::SetFont(font
);
1038 m_normalFont
= font
;
1039 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
1040 m_normalFont
.GetFamily(),
1041 m_normalFont
.GetStyle(),
1043 m_normalFont
.GetUnderlined(),
1044 m_normalFont
.GetFaceName(),
1045 m_normalFont
.GetEncoding());
1051 // -----------------------------------------------------------------------------
1052 // item status inquiries
1053 // -----------------------------------------------------------------------------
1055 bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
1057 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1059 // An item is only visible if it's not a descendant of a collapsed item
1060 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1061 wxGenericTreeItem
* parent
= pItem
->GetParent();
1064 if (!parent
->IsExpanded())
1066 parent
= parent
->GetParent();
1070 GetViewStart(& startX
, & startY
);
1072 wxSize clientSize
= GetClientSize();
1075 if (!GetBoundingRect(item
, rect
))
1077 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
1079 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
1081 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
1087 bool wxGenericTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
1089 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1091 // consider that the item does have children if it has the "+" button: it
1092 // might not have them (if it had never been expanded yet) but then it
1093 // could have them as well and it's better to err on this side rather than
1094 // disabling some operations which are restricted to the items with
1095 // children for an item which does have them
1096 return ((wxGenericTreeItem
*) item
.m_pItem
)->HasPlus();
1099 bool wxGenericTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
1101 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1103 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsExpanded();
1106 bool wxGenericTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
1108 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1110 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsSelected();
1113 bool wxGenericTreeCtrl::IsBold(const wxTreeItemId
& item
) const
1115 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1117 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsBold();
1120 // -----------------------------------------------------------------------------
1122 // -----------------------------------------------------------------------------
1124 wxTreeItemId
wxGenericTreeCtrl::GetItemParent(const wxTreeItemId
& item
) const
1126 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1128 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetParent();
1131 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1132 wxTreeItemIdValue
& cookie
) const
1134 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1137 return GetNextChild(item
, cookie
);
1140 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1141 wxTreeItemIdValue
& cookie
) const
1143 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1145 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1147 // it's ok to cast cookie to size_t, we never have indices big enough to
1148 // overflow "void *"
1149 size_t *pIndex
= (size_t *)&cookie
;
1150 if ( *pIndex
< children
.Count() )
1152 return children
.Item((*pIndex
)++);
1156 // there are no more of them
1157 return wxTreeItemId();
1161 #if WXWIN_COMPATIBILITY_2_4
1163 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1166 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1169 return GetNextChild(item
, cookie
);
1172 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1175 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1177 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1178 if ( (size_t)cookie
< children
.Count() )
1180 return children
.Item((size_t)cookie
++);
1184 // there are no more of them
1185 return wxTreeItemId();
1189 #endif // WXWIN_COMPATIBILITY_2_4
1191 wxTreeItemId
wxGenericTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
1193 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1195 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1196 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
1199 wxTreeItemId
wxGenericTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
1201 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1203 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1204 wxGenericTreeItem
*parent
= i
->GetParent();
1205 if ( parent
== NULL
)
1207 // root item doesn't have any siblings
1208 return wxTreeItemId();
1211 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1212 int index
= siblings
.Index(i
);
1213 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1215 size_t n
= (size_t)(index
+ 1);
1216 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
1219 wxTreeItemId
wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
1221 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1223 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1224 wxGenericTreeItem
*parent
= i
->GetParent();
1225 if ( parent
== NULL
)
1227 // root item doesn't have any siblings
1228 return wxTreeItemId();
1231 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1232 int index
= siblings
.Index(i
);
1233 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1235 return index
== 0 ? wxTreeItemId()
1236 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
1239 // Only for internal use right now, but should probably be public
1240 wxTreeItemId
wxGenericTreeCtrl::GetNext(const wxTreeItemId
& item
) const
1242 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1244 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1246 // First see if there are any children.
1247 wxArrayGenericTreeItems
& children
= i
->GetChildren();
1248 if (children
.GetCount() > 0)
1250 return children
.Item(0);
1254 // Try a sibling of this or ancestor instead
1255 wxTreeItemId p
= item
;
1256 wxTreeItemId toFind
;
1259 toFind
= GetNextSibling(p
);
1260 p
= GetItemParent(p
);
1261 } while (p
.IsOk() && !toFind
.IsOk());
1266 wxTreeItemId
wxGenericTreeCtrl::GetFirstVisibleItem() const
1268 wxTreeItemId id
= GetRootItem();
1277 } while (id
.IsOk());
1279 return wxTreeItemId();
1282 wxTreeItemId
wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
1284 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1286 wxTreeItemId id
= item
;
1289 while (id
= GetNext(id
), id
.IsOk())
1295 return wxTreeItemId();
1298 wxTreeItemId
wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
1300 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1302 wxFAIL_MSG(wxT("not implemented"));
1304 return wxTreeItemId();
1307 // called by wxTextTreeCtrl when it marks itself for deletion
1308 void wxGenericTreeCtrl::ResetTextControl()
1313 // find the first item starting with the given prefix after the given item
1314 wxTreeItemId
wxGenericTreeCtrl::FindItem(const wxTreeItemId
& idParent
,
1315 const wxString
& prefixOrig
) const
1317 // match is case insensitive as this is more convenient to the user: having
1318 // to press Shift-letter to go to the item starting with a capital letter
1319 // would be too bothersome
1320 wxString prefix
= prefixOrig
.Lower();
1322 // determine the starting point: we shouldn't take the current item (this
1323 // allows to switch between two items starting with the same letter just by
1324 // pressing it) but we shouldn't jump to the next one if the user is
1325 // continuing to type as otherwise he might easily skip the item he wanted
1326 wxTreeItemId id
= idParent
;
1327 if ( prefix
.length() == 1 )
1332 // look for the item starting with the given prefix after it
1333 while ( id
.IsOk() && !GetItemText(id
).Lower().StartsWith(prefix
) )
1338 // if we haven't found anything...
1341 // ... wrap to the beginning
1343 if ( HasFlag(wxTR_HIDE_ROOT
) )
1345 // can't select virtual root
1349 // and try all the items (stop when we get to the one we started from)
1350 while ( id
!= idParent
&& !GetItemText(id
).Lower().StartsWith(prefix
) )
1359 // -----------------------------------------------------------------------------
1361 // -----------------------------------------------------------------------------
1363 wxTreeItemId
wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId
& parentId
,
1365 const wxString
& text
,
1366 int image
, int selImage
,
1367 wxTreeItemData
*data
)
1369 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1372 // should we give a warning here?
1373 return AddRoot(text
, image
, selImage
, data
);
1376 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1378 wxGenericTreeItem
*item
=
1379 new wxGenericTreeItem( parent
, text
, image
, selImage
, data
);
1383 data
->m_pItem
= item
;
1386 parent
->Insert( item
, previous
);
1391 wxTreeItemId
wxGenericTreeCtrl::AddRoot(const wxString
& text
,
1392 int image
, int selImage
,
1393 wxTreeItemData
*data
)
1395 wxCHECK_MSG( !m_anchor
, wxTreeItemId(), wxT("tree can have only one root") );
1397 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1399 m_anchor
= new wxGenericTreeItem((wxGenericTreeItem
*)NULL
, text
,
1400 image
, selImage
, data
);
1403 data
->m_pItem
= m_anchor
;
1406 if (HasFlag(wxTR_HIDE_ROOT
))
1408 // if root is hidden, make sure we can navigate
1410 m_anchor
->SetHasPlus();
1412 CalculatePositions();
1415 if (!HasFlag(wxTR_MULTIPLE
))
1417 m_current
= m_key_current
= m_anchor
;
1418 m_current
->SetHilight( true );
1424 wxTreeItemId
wxGenericTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
1425 const wxString
& text
,
1426 int image
, int selImage
,
1427 wxTreeItemData
*data
)
1429 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
1432 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1433 const wxTreeItemId
& idPrevious
,
1434 const wxString
& text
,
1435 int image
, int selImage
,
1436 wxTreeItemData
*data
)
1438 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1441 // should we give a warning here?
1442 return AddRoot(text
, image
, selImage
, data
);
1446 if (idPrevious
.IsOk())
1448 index
= parent
->GetChildren().Index((wxGenericTreeItem
*) idPrevious
.m_pItem
);
1449 wxASSERT_MSG( index
!= wxNOT_FOUND
,
1450 wxT("previous item in wxGenericTreeCtrl::InsertItem() is not a sibling") );
1453 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
1456 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1458 const wxString
& text
,
1459 int image
, int selImage
,
1460 wxTreeItemData
*data
)
1462 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1465 // should we give a warning here?
1466 return AddRoot(text
, image
, selImage
, data
);
1469 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
1472 wxTreeItemId
wxGenericTreeCtrl::AppendItem(const wxTreeItemId
& parentId
,
1473 const wxString
& text
,
1474 int image
, int selImage
,
1475 wxTreeItemData
*data
)
1477 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1480 // should we give a warning here?
1481 return AddRoot(text
, image
, selImage
, data
);
1484 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
1485 image
, selImage
, data
);
1488 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem
*item
)
1490 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, GetId() );
1491 event
.m_item
= item
;
1492 event
.SetEventObject( this );
1493 ProcessEvent( event
);
1496 void wxGenericTreeCtrl::DeleteChildren(const wxTreeItemId
& itemId
)
1498 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1500 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1501 item
->DeleteChildren(this);
1504 void wxGenericTreeCtrl::Delete(const wxTreeItemId
& itemId
)
1506 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1508 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1512 // can't delete the item being edited, cancel editing it first
1513 m_textCtrl
->StopEditing(item
);
1516 wxGenericTreeItem
*parent
= item
->GetParent();
1518 // don't keep stale pointers around!
1519 if ( IsDescendantOf(item
, m_key_current
) )
1521 // Don't silently change the selection:
1522 // do it properly in idle time, so event
1523 // handlers get called.
1525 // m_key_current = parent;
1526 m_key_current
= NULL
;
1529 // m_select_me records whether we need to select
1530 // a different item, in idle time.
1531 if ( m_select_me
&& IsDescendantOf(item
, m_select_me
) )
1533 m_select_me
= parent
;
1536 if ( IsDescendantOf(item
, m_current
) )
1538 // Don't silently change the selection:
1539 // do it properly in idle time, so event
1540 // handlers get called.
1542 // m_current = parent;
1544 m_select_me
= parent
;
1547 // remove the item from the tree
1550 parent
->GetChildren().Remove( item
); // remove by value
1552 else // deleting the root
1554 // nothing will be left in the tree
1558 // and delete all of its children and the item itself now
1559 item
->DeleteChildren(this);
1560 SendDeleteEvent(item
);
1564 void wxGenericTreeCtrl::DeleteAllItems()
1572 void wxGenericTreeCtrl::Expand(const wxTreeItemId
& itemId
)
1574 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1576 wxCHECK_RET( item
, _T("invalid item in wxGenericTreeCtrl::Expand") );
1577 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1578 _T("can't expand hidden root") );
1580 if ( !item
->HasPlus() )
1583 if ( item
->IsExpanded() )
1586 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, GetId() );
1587 event
.m_item
= item
;
1588 event
.SetEventObject( this );
1590 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1592 // cancelled by program
1597 CalculatePositions();
1599 RefreshSubtree(item
);
1601 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
1602 ProcessEvent( event
);
1605 void wxGenericTreeCtrl::ExpandAll(const wxTreeItemId
& item
)
1607 if ( !HasFlag(wxTR_HIDE_ROOT
) || item
!= GetRootItem())
1610 if ( !IsExpanded(item
) )
1614 wxTreeItemIdValue cookie
;
1615 wxTreeItemId child
= GetFirstChild(item
, cookie
);
1616 while ( child
.IsOk() )
1620 child
= GetNextChild(item
, cookie
);
1624 void wxGenericTreeCtrl::Collapse(const wxTreeItemId
& itemId
)
1626 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1627 _T("can't collapse hidden root") );
1629 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1631 if ( !item
->IsExpanded() )
1634 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, GetId() );
1635 event
.m_item
= item
;
1636 event
.SetEventObject( this );
1637 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1639 // cancelled by program
1645 #if 0 // TODO why should items be collapsed recursively?
1646 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1647 size_t count
= children
.Count();
1648 for ( size_t n
= 0; n
< count
; n
++ )
1650 Collapse(children
[n
]);
1654 CalculatePositions();
1656 RefreshSubtree(item
);
1658 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
1659 ProcessEvent( event
);
1662 void wxGenericTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
1665 DeleteChildren(item
);
1668 void wxGenericTreeCtrl::Toggle(const wxTreeItemId
& itemId
)
1670 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1672 if (item
->IsExpanded())
1678 void wxGenericTreeCtrl::Unselect()
1682 m_current
->SetHilight( false );
1683 RefreshLine( m_current
);
1690 void wxGenericTreeCtrl::UnselectAllChildren(wxGenericTreeItem
*item
)
1692 if (item
->IsSelected())
1694 item
->SetHilight(false);
1698 if (item
->HasChildren())
1700 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1701 size_t count
= children
.Count();
1702 for ( size_t n
= 0; n
< count
; ++n
)
1704 UnselectAllChildren(children
[n
]);
1709 void wxGenericTreeCtrl::UnselectAll()
1711 wxTreeItemId rootItem
= GetRootItem();
1713 // the tree might not have the root item at all
1716 UnselectAllChildren((wxGenericTreeItem
*) rootItem
.m_pItem
);
1720 // Recursive function !
1721 // To stop we must have crt_item<last_item
1723 // Tag all next children, when no more children,
1724 // Move to parent (not to tag)
1725 // Keep going... if we found last_item, we stop.
1726 bool wxGenericTreeCtrl::TagNextChildren(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1728 wxGenericTreeItem
*parent
= crt_item
->GetParent();
1730 if (parent
== NULL
) // This is root item
1731 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
1733 wxArrayGenericTreeItems
& children
= parent
->GetChildren();
1734 int index
= children
.Index(crt_item
);
1735 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1737 size_t count
= children
.Count();
1738 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
1740 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return true;
1743 return TagNextChildren(parent
, last_item
, select
);
1746 bool wxGenericTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1748 crt_item
->SetHilight(select
);
1749 RefreshLine(crt_item
);
1751 if (crt_item
==last_item
)
1754 if (crt_item
->HasChildren())
1756 wxArrayGenericTreeItems
& children
= crt_item
->GetChildren();
1757 size_t count
= children
.Count();
1758 for ( size_t n
= 0; n
< count
; ++n
)
1760 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
1768 void wxGenericTreeCtrl::SelectItemRange(wxGenericTreeItem
*item1
, wxGenericTreeItem
*item2
)
1772 // item2 is not necessary after item1
1773 // choice first' and 'last' between item1 and item2
1774 wxGenericTreeItem
*first
= (item1
->GetY()<item2
->GetY()) ? item1
: item2
;
1775 wxGenericTreeItem
*last
= (item1
->GetY()<item2
->GetY()) ? item2
: item1
;
1777 bool select
= m_current
->IsSelected();
1779 if ( TagAllChildrenUntilLast(first
,last
,select
) )
1782 TagNextChildren(first
,last
,select
);
1785 void wxGenericTreeCtrl::DoSelectItem(const wxTreeItemId
& itemId
,
1786 bool unselect_others
,
1787 bool extended_select
)
1789 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
1793 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
1794 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1796 //wxCHECK_RET( ( (!unselect_others) && is_single),
1797 // wxT("this is a single selection tree") );
1799 // to keep going anyhow !!!
1802 if (item
->IsSelected())
1803 return; // nothing to do
1804 unselect_others
= true;
1805 extended_select
= false;
1807 else if ( unselect_others
&& item
->IsSelected() )
1809 // selection change if there is more than one item currently selected
1810 wxArrayTreeItemIds selected_items
;
1811 if ( GetSelections(selected_items
) == 1 )
1815 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, GetId() );
1816 event
.m_item
= item
;
1817 event
.m_itemOld
= m_current
;
1818 event
.SetEventObject( this );
1819 // TODO : Here we don't send any selection mode yet !
1821 if ( GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed() )
1824 wxTreeItemId parent
= GetItemParent( itemId
);
1825 while (parent
.IsOk())
1827 if (!IsExpanded(parent
))
1830 parent
= GetItemParent( parent
);
1833 EnsureVisible( itemId
);
1836 if (unselect_others
)
1838 if (is_single
) Unselect(); // to speed up thing
1843 if (extended_select
)
1847 m_current
= m_key_current
= (wxGenericTreeItem
*) GetRootItem().m_pItem
;
1850 // don't change the mark (m_current)
1851 SelectItemRange(m_current
, item
);
1855 bool select
= true; // the default
1857 // Check if we need to toggle hilight (ctrl mode)
1858 if (!unselect_others
)
1859 select
=!item
->IsSelected();
1861 m_current
= m_key_current
= item
;
1862 m_current
->SetHilight(select
);
1863 RefreshLine( m_current
);
1866 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
1867 GetEventHandler()->ProcessEvent( event
);
1870 void wxGenericTreeCtrl::SelectItem(const wxTreeItemId
& itemId
, bool select
)
1874 DoSelectItem(itemId
);
1878 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1879 wxCHECK_RET( item
, wxT("SelectItem(): invalid tree item") );
1881 item
->SetHilight(false);
1886 void wxGenericTreeCtrl::FillArray(wxGenericTreeItem
*item
,
1887 wxArrayTreeItemIds
&array
) const
1889 if ( item
->IsSelected() )
1890 array
.Add(wxTreeItemId(item
));
1892 if ( item
->HasChildren() )
1894 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1895 size_t count
= children
.GetCount();
1896 for ( size_t n
= 0; n
< count
; ++n
)
1897 FillArray(children
[n
], array
);
1901 size_t wxGenericTreeCtrl::GetSelections(wxArrayTreeItemIds
&array
) const
1904 wxTreeItemId idRoot
= GetRootItem();
1905 if ( idRoot
.IsOk() )
1907 FillArray((wxGenericTreeItem
*) idRoot
.m_pItem
, array
);
1909 //else: the tree is empty, so no selections
1911 return array
.Count();
1914 void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
1916 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1918 if (!item
.IsOk()) return;
1920 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1922 // first expand all parent branches
1923 wxGenericTreeItem
*parent
= gitem
->GetParent();
1925 if ( HasFlag(wxTR_HIDE_ROOT
) )
1927 while ( parent
&& parent
!= m_anchor
)
1930 parent
= parent
->GetParent();
1938 parent
= parent
->GetParent();
1942 //if (parent) CalculatePositions();
1947 void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId
&item
)
1949 if (!item
.IsOk()) return;
1951 // We have to call this here because the label in
1952 // question might just have been added and no screen
1953 // update taken place.
1955 #if defined( __WXMSW__ ) || defined(__WXMAC__)
1960 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1962 // now scroll to the item
1963 int item_y
= gitem
->GetY();
1967 GetViewStart( &start_x
, &start_y
);
1968 start_y
*= PIXELS_PER_UNIT
;
1972 GetClientSize( &client_w
, &client_h
);
1974 if (item_y
< start_y
+3)
1979 m_anchor
->GetSize( x
, y
, this );
1980 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1981 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1982 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1983 // Item should appear at top
1984 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
1986 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
1991 m_anchor
->GetSize( x
, y
, this );
1992 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1993 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1994 item_y
+= PIXELS_PER_UNIT
+2;
1995 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1996 // Item should appear at bottom
1997 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
);
2001 // FIXME: tree sorting functions are not reentrant and not MT-safe!
2002 static wxGenericTreeCtrl
*s_treeBeingSorted
= NULL
;
2004 static int LINKAGEMODE
tree_ctrl_compare_func(wxGenericTreeItem
**item1
,
2005 wxGenericTreeItem
**item2
)
2007 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxGenericTreeCtrl::SortChildren()") );
2009 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
2012 int wxGenericTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
2013 const wxTreeItemId
& item2
)
2015 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
2018 void wxGenericTreeCtrl::SortChildren(const wxTreeItemId
& itemId
)
2020 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
2022 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
2024 wxCHECK_RET( !s_treeBeingSorted
,
2025 wxT("wxGenericTreeCtrl::SortChildren is not reentrant") );
2027 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2028 if ( children
.Count() > 1 )
2032 s_treeBeingSorted
= this;
2033 children
.Sort(tree_ctrl_compare_func
);
2034 s_treeBeingSorted
= NULL
;
2036 //else: don't make the tree dirty as nothing changed
2039 wxImageList
*wxGenericTreeCtrl::GetImageList() const
2041 return m_imageListNormal
;
2044 wxImageList
*wxGenericTreeCtrl::GetButtonsImageList() const
2046 return m_imageListButtons
;
2049 wxImageList
*wxGenericTreeCtrl::GetStateImageList() const
2051 return m_imageListState
;
2054 void wxGenericTreeCtrl::CalculateLineHeight()
2056 wxClientDC
dc(this);
2057 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
2059 if ( m_imageListNormal
)
2061 // Calculate a m_lineHeight value from the normal Image sizes.
2062 // May be toggle off. Then wxGenericTreeCtrl will spread when
2063 // necessary (which might look ugly).
2064 int n
= m_imageListNormal
->GetImageCount();
2065 for (int i
= 0; i
< n
; i
++)
2067 int width
= 0, height
= 0;
2068 m_imageListNormal
->GetSize(i
, width
, height
);
2069 if (height
> m_lineHeight
) m_lineHeight
= height
;
2073 if (m_imageListButtons
)
2075 // Calculate a m_lineHeight value from the Button image sizes.
2076 // May be toggle off. Then wxGenericTreeCtrl will spread when
2077 // necessary (which might look ugly).
2078 int n
= m_imageListButtons
->GetImageCount();
2079 for (int i
= 0; i
< n
; i
++)
2081 int width
= 0, height
= 0;
2082 m_imageListButtons
->GetSize(i
, width
, height
);
2083 if (height
> m_lineHeight
) m_lineHeight
= height
;
2087 if (m_lineHeight
< 30)
2088 m_lineHeight
+= 2; // at least 2 pixels
2090 m_lineHeight
+= m_lineHeight
/10; // otherwise 10% extra spacing
2093 void wxGenericTreeCtrl::SetImageList(wxImageList
*imageList
)
2095 if (m_ownsImageListNormal
) delete m_imageListNormal
;
2096 m_imageListNormal
= imageList
;
2097 m_ownsImageListNormal
= false;
2099 // Don't do any drawing if we're setting the list to NULL,
2100 // since we may be in the process of deleting the tree control.
2102 CalculateLineHeight();
2105 void wxGenericTreeCtrl::SetStateImageList(wxImageList
*imageList
)
2107 if (m_ownsImageListState
) delete m_imageListState
;
2108 m_imageListState
= imageList
;
2109 m_ownsImageListState
= false;
2112 void wxGenericTreeCtrl::SetButtonsImageList(wxImageList
*imageList
)
2114 if (m_ownsImageListButtons
) delete m_imageListButtons
;
2115 m_imageListButtons
= imageList
;
2116 m_ownsImageListButtons
= false;
2118 CalculateLineHeight();
2121 void wxGenericTreeCtrl::AssignImageList(wxImageList
*imageList
)
2123 SetImageList(imageList
);
2124 m_ownsImageListNormal
= true;
2127 void wxGenericTreeCtrl::AssignStateImageList(wxImageList
*imageList
)
2129 SetStateImageList(imageList
);
2130 m_ownsImageListState
= true;
2133 void wxGenericTreeCtrl::AssignButtonsImageList(wxImageList
*imageList
)
2135 SetButtonsImageList(imageList
);
2136 m_ownsImageListButtons
= true;
2139 // -----------------------------------------------------------------------------
2141 // -----------------------------------------------------------------------------
2143 void wxGenericTreeCtrl::AdjustMyScrollbars()
2148 m_anchor
->GetSize( x
, y
, this );
2149 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2150 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2151 int x_pos
= GetScrollPos( wxHORIZONTAL
);
2152 int y_pos
= GetScrollPos( wxVERTICAL
);
2153 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
2157 SetScrollbars( 0, 0, 0, 0 );
2161 int wxGenericTreeCtrl::GetLineHeight(wxGenericTreeItem
*item
) const
2163 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
2164 return item
->GetHeight();
2166 return m_lineHeight
;
2169 void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem
*item
, wxDC
& dc
)
2171 // TODO implement "state" icon on items
2173 wxTreeItemAttr
*attr
= item
->GetAttributes();
2174 if ( attr
&& attr
->HasFont() )
2175 dc
.SetFont(attr
->GetFont());
2176 else if (item
->IsBold())
2177 dc
.SetFont(m_boldFont
);
2179 long text_w
= 0, text_h
= 0;
2180 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
2182 int image_h
= 0, image_w
= 0;
2183 int image
= item
->GetCurrentImage();
2184 if ( image
!= NO_IMAGE
)
2186 if ( m_imageListNormal
)
2188 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
2197 int total_h
= GetLineHeight(item
);
2199 if ( item
->IsSelected() )
2201 // under mac selections are only a rectangle in case they don't have the focus
2205 dc
.SetBrush( *wxTRANSPARENT_BRUSH
) ;
2206 dc
.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
) , 1 , wxSOLID
) ) ;
2210 dc
.SetBrush( *m_hilightBrush
) ;
2213 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
2219 if ( attr
&& attr
->HasBackgroundColour() )
2220 colBg
= attr
->GetBackgroundColour();
2222 colBg
= m_backgroundColour
;
2223 dc
.SetBrush(wxBrush(colBg
, wxSOLID
));
2226 int offset
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0;
2228 if ( HasFlag(wxTR_FULL_ROW_HIGHLIGHT
) )
2232 DoGetPosition(&x
, &y
);
2234 dc
.DrawRectangle(x
, item
->GetY()+offset
, w
, total_h
-offset
);
2238 if ( item
->IsSelected() && image
!= NO_IMAGE
)
2240 // If it's selected, and there's an image, then we should
2241 // take care to leave the area under the image painted in the
2242 // background colour.
2243 dc
.DrawRectangle( item
->GetX() + image_w
- 2, item
->GetY()+offset
,
2244 item
->GetWidth() - image_w
+ 2, total_h
-offset
);
2248 dc
.DrawRectangle( item
->GetX()-2, item
->GetY()+offset
,
2249 item
->GetWidth()+2, total_h
-offset
);
2253 if ( image
!= NO_IMAGE
)
2255 dc
.SetClippingRegion( item
->GetX(), item
->GetY(), image_w
-2, total_h
);
2256 m_imageListNormal
->Draw( image
, dc
,
2258 item
->GetY() +((total_h
> image_h
)?((total_h
-image_h
)/2):0),
2259 wxIMAGELIST_DRAW_TRANSPARENT
);
2260 dc
.DestroyClippingRegion();
2263 dc
.SetBackgroundMode(wxTRANSPARENT
);
2264 int extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
2265 dc
.DrawText( item
->GetText(),
2266 (wxCoord
)(image_w
+ item
->GetX()),
2267 (wxCoord
)(item
->GetY() + extraH
));
2269 // restore normal font
2270 dc
.SetFont( m_normalFont
);
2273 // Now y stands for the top of the item, whereas it used to stand for middle !
2274 void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
2276 int x
= level
*m_indent
;
2277 if (!HasFlag(wxTR_HIDE_ROOT
))
2281 else if (level
== 0)
2283 // always expand hidden root
2285 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2286 int count
= children
.Count();
2292 PaintLevel(children
[n
], dc
, 1, y
);
2293 } while (++n
< count
);
2295 if (!HasFlag(wxTR_NO_LINES
) && HasFlag(wxTR_LINES_AT_ROOT
) && count
> 0)
2297 // draw line down to last child
2298 origY
+= GetLineHeight(children
[0])>>1;
2299 oldY
+= GetLineHeight(children
[n
-1])>>1;
2300 dc
.DrawLine(3, origY
, 3, oldY
);
2306 item
->SetX(x
+m_spacing
);
2309 int h
= GetLineHeight(item
);
2311 int y_mid
= y_top
+ (h
>>1);
2314 int exposed_x
= dc
.LogicalToDeviceX(0);
2315 int exposed_y
= dc
.LogicalToDeviceY(y_top
);
2317 if (IsExposed(exposed_x
, exposed_y
, 10000, h
)) // 10000 = very much
2321 // don't draw rect outline if we already have the
2322 // background color under Mac
2323 (item
->IsSelected() && m_hasFocus
) ? wxBLACK_PEN
:
2324 #endif // !__WXMAC__
2328 if ( item
->IsSelected() )
2330 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
2334 wxTreeItemAttr
*attr
= item
->GetAttributes();
2335 if (attr
&& attr
->HasTextColour())
2336 colText
= attr
->GetTextColour();
2338 colText
= GetForegroundColour();
2342 dc
.SetTextForeground(colText
);
2346 PaintItem(item
, dc
);
2348 if (HasFlag(wxTR_ROW_LINES
))
2350 // if the background colour is white, choose a
2351 // contrasting color for the lines
2352 dc
.SetPen(*((GetBackgroundColour() == *wxWHITE
)
2353 ? wxMEDIUM_GREY_PEN
: wxWHITE_PEN
));
2354 dc
.DrawLine(0, y_top
, 10000, y_top
);
2355 dc
.DrawLine(0, y
, 10000, y
);
2358 // restore DC objects
2359 dc
.SetBrush(*wxWHITE_BRUSH
);
2360 dc
.SetPen(m_dottedPen
);
2361 dc
.SetTextForeground(*wxBLACK
);
2363 if ( !HasFlag(wxTR_NO_LINES
) )
2365 // draw the horizontal line here
2367 if (x
> (signed)m_indent
)
2368 x_start
-= m_indent
;
2369 else if (HasFlag(wxTR_LINES_AT_ROOT
))
2371 dc
.DrawLine(x_start
, y_mid
, x
+ m_spacing
, y_mid
);
2374 // should the item show a button?
2375 if ( item
->HasPlus() && HasButtons() )
2377 if ( m_imageListButtons
)
2379 // draw the image button here
2382 int image
= item
->IsExpanded() ? wxTreeItemIcon_Expanded
2383 : wxTreeItemIcon_Normal
;
2384 if ( item
->IsSelected() )
2385 image
+= wxTreeItemIcon_Selected
- wxTreeItemIcon_Normal
;
2387 m_imageListButtons
->GetSize(image
, image_w
, image_h
);
2388 int xx
= x
- image_w
/2;
2389 int yy
= y_mid
- image_h
/2;
2391 wxDCClipper
clip(dc
, xx
, yy
, image_w
, image_h
);
2392 m_imageListButtons
->Draw(image
, dc
, xx
, yy
,
2393 wxIMAGELIST_DRAW_TRANSPARENT
);
2395 else // no custom buttons
2397 static const int wImage
= 9;
2398 static const int hImage
= 9;
2401 if (item
->IsExpanded())
2402 flag
|= wxCONTROL_EXPANDED
;
2403 if (item
== m_underMouse
)
2404 flag
|= wxCONTROL_CURRENT
;
2406 wxRendererNative::Get().DrawTreeItemButton
2410 wxRect(x
- wImage
/2,
2419 if (item
->IsExpanded())
2421 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2422 int count
= children
.Count();
2429 PaintLevel(children
[n
], dc
, level
, y
);
2430 } while (++n
< count
);
2432 if (!HasFlag(wxTR_NO_LINES
) && count
> 0)
2434 // draw line down to last child
2435 oldY
+= GetLineHeight(children
[n
-1])>>1;
2436 if (HasButtons()) y_mid
+= 5;
2438 // Only draw the portion of the line that is visible, in case it is huge
2439 wxCoord xOrigin
=0, yOrigin
=0, width
, height
;
2440 dc
.GetDeviceOrigin(&xOrigin
, &yOrigin
);
2441 yOrigin
= abs(yOrigin
);
2442 GetClientSize(&width
, &height
);
2444 // Move end points to the begining/end of the view?
2445 if (y_mid
< yOrigin
)
2447 if (oldY
> yOrigin
+ height
)
2448 oldY
= yOrigin
+ height
;
2450 // after the adjustments if y_mid is larger than oldY then the line
2451 // isn't visible at all so don't draw anything
2453 dc
.DrawLine(x
, y_mid
, x
, oldY
);
2459 void wxGenericTreeCtrl::DrawDropEffect(wxGenericTreeItem
*item
)
2463 if ( item
->HasPlus() )
2465 // it's a folder, indicate it by a border
2470 // draw a line under the drop target because the item will be
2472 DrawLine(item
, true /* below */);
2475 SetCursor(wxCURSOR_BULLSEYE
);
2480 SetCursor(wxCURSOR_NO_ENTRY
);
2484 void wxGenericTreeCtrl::DrawBorder(const wxTreeItemId
&item
)
2486 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2488 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2490 wxClientDC
dc(this);
2492 dc
.SetLogicalFunction(wxINVERT
);
2493 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2495 int w
= i
->GetWidth() + 2;
2496 int h
= GetLineHeight(i
) + 2;
2498 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
2501 void wxGenericTreeCtrl::DrawLine(const wxTreeItemId
&item
, bool below
)
2503 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2505 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2507 wxClientDC
dc(this);
2509 dc
.SetLogicalFunction(wxINVERT
);
2515 y
+= GetLineHeight(i
) - 1;
2518 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
2521 // -----------------------------------------------------------------------------
2522 // wxWidgets callbacks
2523 // -----------------------------------------------------------------------------
2525 void wxGenericTreeCtrl::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2533 dc
.SetFont( m_normalFont
);
2534 dc
.SetPen( m_dottedPen
);
2536 // this is now done dynamically
2537 //if(GetImageList() == NULL)
2538 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
2541 PaintLevel( m_anchor
, dc
, 0, y
);
2544 void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent
&event
)
2553 void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent
&event
)
2562 void wxGenericTreeCtrl::OnChar( wxKeyEvent
&event
)
2564 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, GetId() );
2565 te
.m_evtKey
= event
;
2566 te
.SetEventObject( this );
2567 if ( GetEventHandler()->ProcessEvent( te
) )
2569 // intercepted by the user code
2573 if ( (m_current
== 0) || (m_key_current
== 0) )
2579 // how should the selection work for this event?
2580 bool is_multiple
, extended_select
, unselect_others
;
2581 EventFlagsToSelType(GetWindowStyleFlag(),
2583 event
.ControlDown(),
2584 is_multiple
, extended_select
, unselect_others
);
2588 // * : Expand all/Collapse all
2589 // ' ' | return : activate
2590 // up : go up (not last children!)
2592 // left : go to parent
2593 // right : open if parent and go next
2594 // home : go to root
2595 // end : go to last item without opening parents
2596 // alnum : start or continue searching for the item with this prefix
2597 int keyCode
= event
.GetKeyCode();
2602 if (m_current
->HasPlus() && !IsExpanded(m_current
))
2610 if ( !IsExpanded(m_current
) )
2613 ExpandAll(m_current
);
2616 //else: fall through to Collapse() it
2620 if (IsExpanded(m_current
))
2622 Collapse(m_current
);
2628 if ( !event
.HasModifiers() )
2630 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
2631 event
.m_item
= m_current
;
2632 event
.SetEventObject( this );
2633 GetEventHandler()->ProcessEvent( event
);
2636 // in any case, also generate the normal key event for this key,
2637 // even if we generated the ACTIVATED event above: this is what
2638 // wxMSW does and it makes sense because you might not want to
2639 // process ACTIVATED event at all and handle Space and Return
2640 // directly (and differently) which would be impossible otherwise
2644 // up goes to the previous sibling or to the last
2645 // of its children if it's expanded
2648 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
2651 prev
= GetItemParent( m_key_current
);
2652 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2654 break; // don't go to root if it is hidden
2658 wxTreeItemIdValue cookie
;
2659 wxTreeItemId current
= m_key_current
;
2660 // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be?
2661 if (current
== GetFirstChild( prev
, cookie
))
2663 // otherwise we return to where we came from
2664 DoSelectItem( prev
, unselect_others
, extended_select
);
2665 m_key_current
= (wxGenericTreeItem
*) prev
.m_pItem
;
2672 while ( IsExpanded(prev
) && HasChildren(prev
) )
2674 wxTreeItemId child
= GetLastChild(prev
);
2681 DoSelectItem( prev
, unselect_others
, extended_select
);
2682 m_key_current
=(wxGenericTreeItem
*) prev
.m_pItem
;
2687 // left arrow goes to the parent
2690 wxTreeItemId prev
= GetItemParent( m_current
);
2691 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2693 // don't go to root if it is hidden
2694 prev
= GetPrevSibling( m_current
);
2698 DoSelectItem( prev
, unselect_others
, extended_select
);
2704 // this works the same as the down arrow except that we
2705 // also expand the item if it wasn't expanded yet
2711 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
2713 wxTreeItemIdValue cookie
;
2714 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
2715 DoSelectItem( child
, unselect_others
, extended_select
);
2716 m_key_current
=(wxGenericTreeItem
*) child
.m_pItem
;
2720 wxTreeItemId next
= GetNextSibling( m_key_current
);
2723 wxTreeItemId current
= m_key_current
;
2724 while (current
.IsOk() && !next
)
2726 current
= GetItemParent( current
);
2727 if (current
) next
= GetNextSibling( current
);
2732 DoSelectItem( next
, unselect_others
, extended_select
);
2733 m_key_current
=(wxGenericTreeItem
*) next
.m_pItem
;
2739 // <End> selects the last visible tree item
2742 wxTreeItemId last
= GetRootItem();
2744 while ( last
.IsOk() && IsExpanded(last
) )
2746 wxTreeItemId lastChild
= GetLastChild(last
);
2748 // it may happen if the item was expanded but then all of
2749 // its children have been deleted - so IsExpanded() returned
2750 // true, but GetLastChild() returned invalid item
2759 DoSelectItem( last
, unselect_others
, extended_select
);
2764 // <Home> selects the root item
2767 wxTreeItemId prev
= GetRootItem();
2771 if ( HasFlag(wxTR_HIDE_ROOT
) )
2773 wxTreeItemIdValue cookie
;
2774 prev
= GetFirstChild(prev
, cookie
);
2779 DoSelectItem( prev
, unselect_others
, extended_select
);
2784 // do not use wxIsalnum() here
2785 if ( !event
.HasModifiers() &&
2786 ((keyCode
>= '0' && keyCode
<= '9') ||
2787 (keyCode
>= 'a' && keyCode
<= 'z') ||
2788 (keyCode
>= 'A' && keyCode
<= 'Z' )))
2790 // find the next item starting with the given prefix
2791 wxChar ch
= (wxChar
)keyCode
;
2793 wxTreeItemId id
= FindItem(m_current
, m_findPrefix
+ ch
);
2804 // also start the timer to reset the current prefix if the user
2805 // doesn't press any more alnum keys soon -- we wouldn't want
2806 // to use this prefix for a new item search
2809 m_findTimer
= new wxTreeFindTimer(this);
2812 m_findTimer
->Start(wxTreeFindTimer::DELAY
, wxTIMER_ONE_SHOT
);
2821 wxTreeItemId
wxGenericTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
2823 // JACS: removed wxYieldIfNeeded() because it can cause the window
2824 // to be deleted from under us if a close window event is pending
2829 if (point
.x
<0) flags
|= wxTREE_HITTEST_TOLEFT
;
2830 if (point
.x
>w
) flags
|= wxTREE_HITTEST_TORIGHT
;
2831 if (point
.y
<0) flags
|= wxTREE_HITTEST_ABOVE
;
2832 if (point
.y
>h
) flags
|= wxTREE_HITTEST_BELOW
;
2833 if (flags
) return wxTreeItemId();
2835 if (m_anchor
== NULL
)
2837 flags
= wxTREE_HITTEST_NOWHERE
;
2838 return wxTreeItemId();
2841 wxGenericTreeItem
*hit
= m_anchor
->HitTest(CalcUnscrolledPosition(point
),
2845 flags
= wxTREE_HITTEST_NOWHERE
;
2846 return wxTreeItemId();
2851 // get the bounding rectangle of the item (or of its label only)
2852 bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId
& item
,
2854 bool WXUNUSED(textOnly
)) const
2856 wxCHECK_MSG( item
.IsOk(), false, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
2858 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2861 GetViewStart(& startX
, & startY
);
2863 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
2864 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
2865 rect
.width
= i
->GetWidth();
2866 //rect.height = i->GetHeight();
2867 rect
.height
= GetLineHeight(i
);
2872 void wxGenericTreeCtrl::Edit( const wxTreeItemId
& item
)
2874 wxCHECK_RET( item
.IsOk(), _T("can't edit an invalid item") );
2876 wxGenericTreeItem
*itemEdit
= (wxGenericTreeItem
*)item
.m_pItem
;
2878 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, GetId() );
2879 te
.m_item
= itemEdit
;
2880 te
.SetEventObject( this );
2881 if ( GetEventHandler()->ProcessEvent( te
) && !te
.IsAllowed() )
2887 // We have to call this here because the label in
2888 // question might just have been added and no screen
2889 // update taken place.
2891 #if defined( __WXMSW__ ) || defined(__WXMAC__)
2897 m_textCtrl
= new wxTreeTextCtrl(this, itemEdit
);
2899 m_textCtrl
->SetFocus();
2902 // returns a pointer to the text edit control if the item is being
2903 // edited, NULL otherwise (it's assumed that no more than one item may
2904 // be edited simultaneously)
2905 wxTextCtrl
* wxGenericTreeCtrl::GetEditControl() const
2910 bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem
*item
,
2911 const wxString
& value
)
2913 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2915 le
.SetEventObject( this );
2917 le
.m_editCancelled
= false;
2919 return !GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2922 void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem
*item
)
2924 // let owner know that the edit was cancelled
2925 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2927 le
.SetEventObject( this );
2928 le
.m_label
= wxEmptyString
;
2929 le
.m_editCancelled
= true;
2931 GetEventHandler()->ProcessEvent( le
);
2934 void wxGenericTreeCtrl::OnRenameTimer()
2939 void wxGenericTreeCtrl::OnMouse( wxMouseEvent
&event
)
2941 if ( !m_anchor
) return;
2943 wxPoint pt
= CalcUnscrolledPosition(event
.GetPosition());
2945 // Is the mouse over a tree item button?
2947 wxGenericTreeItem
*thisItem
= m_anchor
->HitTest(pt
, this, flags
, 0);
2948 wxGenericTreeItem
*underMouse
= thisItem
;
2950 bool underMouseChanged
= (underMouse
!= m_underMouse
) ;
2951 #endif // wxUSE_TOOLTIPS
2954 (flags
& wxTREE_HITTEST_ONITEMBUTTON
) &&
2955 (!event
.LeftIsDown()) &&
2957 (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2965 if (underMouse
!= m_underMouse
)
2969 // unhighlight old item
2970 wxGenericTreeItem
*tmp
= m_underMouse
;
2971 m_underMouse
= NULL
;
2975 m_underMouse
= underMouse
;
2977 RefreshLine( m_underMouse
);
2981 // Determines what item we are hovering over and need a tooltip for
2982 wxTreeItemId hoverItem
= thisItem
;
2984 // We do not want a tooltip if we are dragging, or if the rename timer is running
2985 if (underMouseChanged
&& hoverItem
.IsOk() && !m_isDragging
&& (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2987 // Ask the tree control what tooltip (if any) should be shown
2988 wxTreeEvent
hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP
, GetId());
2989 hevent
.m_item
= hoverItem
;
2990 hevent
.SetEventObject(this);
2992 if ( GetEventHandler()->ProcessEvent(hevent
) && hevent
.IsAllowed() )
2994 SetToolTip(hevent
.m_label
);
2999 // we process left mouse up event (enables in-place edit), right down
3000 // (pass to the user code), left dbl click (activate item) and
3001 // dragging/moving events for items drag-and-drop
3002 if ( !(event
.LeftDown() ||
3004 event
.RightDown() ||
3005 event
.LeftDClick() ||
3007 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
3016 wxGenericTreeItem
*item
= m_anchor
->HitTest(pt
, this, flags
, 0);
3018 if ( event
.Dragging() && !m_isDragging
)
3020 if (m_dragCount
== 0)
3025 if (m_dragCount
!= 3)
3027 // wait until user drags a bit further...
3031 wxEventType command
= event
.RightIsDown()
3032 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
3033 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
3035 wxTreeEvent
nevent( command
, GetId() );
3036 nevent
.m_item
= m_current
;
3037 nevent
.SetEventObject(this);
3039 // by default the dragging is not supported, the user code must
3040 // explicitly allow the event for it to take place
3043 if ( GetEventHandler()->ProcessEvent(nevent
) && nevent
.IsAllowed() )
3045 // we're going to drag this item
3046 m_isDragging
= true;
3048 // remember the old cursor because we will change it while
3050 m_oldCursor
= m_cursor
;
3052 // in a single selection control, hide the selection temporarily
3053 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
3055 m_oldSelection
= (wxGenericTreeItem
*) GetSelection().m_pItem
;
3057 if ( m_oldSelection
)
3059 m_oldSelection
->SetHilight(false);
3060 RefreshLine(m_oldSelection
);
3067 else if ( event
.Moving() )
3069 if ( item
!= m_dropTarget
)
3071 // unhighlight the previous drop target
3072 DrawDropEffect(m_dropTarget
);
3074 m_dropTarget
= item
;
3076 // highlight the current drop target if any
3077 DrawDropEffect(m_dropTarget
);
3079 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3086 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
3088 // erase the highlighting
3089 DrawDropEffect(m_dropTarget
);
3091 if ( m_oldSelection
)
3093 m_oldSelection
->SetHilight(true);
3094 RefreshLine(m_oldSelection
);
3095 m_oldSelection
= (wxGenericTreeItem
*)NULL
;
3098 // generate the drag end event
3099 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
, GetId());
3101 event
.m_item
= item
;
3102 event
.m_pointDrag
= pt
;
3103 event
.SetEventObject(this);
3105 (void)GetEventHandler()->ProcessEvent(event
);
3107 m_isDragging
= false;
3108 m_dropTarget
= (wxGenericTreeItem
*)NULL
;
3112 SetCursor(m_oldCursor
);
3114 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3122 // here we process only the messages which happen on tree items
3126 if (item
== NULL
) return; /* we hit the blank area */
3128 if ( event
.RightDown() )
3130 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
, GetId());
3131 nevent
.m_item
= item
;
3132 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3133 nevent
.SetEventObject(this);
3134 GetEventHandler()->ProcessEvent(nevent
);
3136 else if ( event
.LeftUp() )
3138 // this facilitates multiple-item drag-and-drop
3140 if (item
&& HasFlag(wxTR_MULTIPLE
))
3142 wxArrayTreeItemIds selections
;
3143 size_t count
= GetSelections(selections
);
3146 !event
.ControlDown() &&
3149 DoSelectItem(item
, true, false);
3155 if ( (item
== m_current
) &&
3156 (flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
3157 HasFlag(wxTR_EDIT_LABELS
) )
3159 if ( m_renameTimer
)
3161 if ( m_renameTimer
->IsRunning() )
3162 m_renameTimer
->Stop();
3166 m_renameTimer
= new wxTreeRenameTimer( this );
3169 m_renameTimer
->Start( wxTreeRenameTimer::DELAY
, true );
3172 m_lastOnSame
= false;
3175 else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
3177 if ( event
.LeftDown() )
3179 m_lastOnSame
= item
== m_current
;
3182 if ( flags
& wxTREE_HITTEST_ONITEMBUTTON
)
3184 // only toggle the item for a single click, double click on
3185 // the button doesn't do anything (it toggles the item twice)
3186 if ( event
.LeftDown() )
3191 // don't select the item if the button was clicked
3196 // clear the previously selected items, if the
3197 // user clicked outside of the present selection.
3198 // otherwise, perform the deselection on mouse-up.
3199 // this allows multiple drag and drop to work.
3201 if (!IsSelected(item
))
3203 // how should the selection work for this event?
3204 bool is_multiple
, extended_select
, unselect_others
;
3205 EventFlagsToSelType(GetWindowStyleFlag(),
3207 event
.ControlDown(),
3208 is_multiple
, extended_select
, unselect_others
);
3210 DoSelectItem(item
, unselect_others
, extended_select
);
3214 // For some reason, Windows isn't recognizing a left double-click,
3215 // so we need to simulate it here. Allow 200 milliseconds for now.
3216 if ( event
.LeftDClick() )
3218 // double clicking should not start editing the item label
3219 if ( m_renameTimer
)
3220 m_renameTimer
->Stop();
3222 m_lastOnSame
= false;
3224 // send activate event first
3225 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
3226 nevent
.m_item
= item
;
3227 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3228 nevent
.SetEventObject( this );
3229 if ( !GetEventHandler()->ProcessEvent( nevent
) )
3231 // if the user code didn't process the activate event,
3232 // handle it ourselves by toggling the item when it is
3234 if ( item
->HasPlus() )
3244 void wxGenericTreeCtrl::OnInternalIdle()
3246 wxWindow::OnInternalIdle();
3248 // Check if we need to select the root item
3249 // because nothing else has been selected.
3250 // Delaying it means that we can invoke event handlers
3251 // as required, when a first item is selected.
3252 if (!HasFlag(wxTR_MULTIPLE
) && !GetSelection().IsOk())
3255 SelectItem(m_select_me
);
3256 else if (GetRootItem().IsOk())
3257 SelectItem(GetRootItem());
3260 /* after all changes have been done to the tree control,
3261 * we actually redraw the tree when everything is over */
3263 if (!m_dirty
) return;
3264 if (m_freezeCount
) return;
3268 CalculatePositions();
3270 AdjustMyScrollbars();
3273 void wxGenericTreeCtrl::CalculateSize( wxGenericTreeItem
*item
, wxDC
&dc
)
3278 wxTreeItemAttr
*attr
= item
->GetAttributes();
3279 if ( attr
&& attr
->HasFont() )
3280 dc
.SetFont(attr
->GetFont());
3281 else if ( item
->IsBold() )
3282 dc
.SetFont(m_boldFont
);
3284 dc
.SetFont(m_normalFont
);
3286 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
3289 // restore normal font
3290 dc
.SetFont( m_normalFont
);
3294 int image
= item
->GetCurrentImage();
3295 if ( image
!= NO_IMAGE
)
3297 if ( m_imageListNormal
)
3299 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
3304 int total_h
= (image_h
> text_h
) ? image_h
: text_h
;
3307 total_h
+= 2; // at least 2 pixels
3309 total_h
+= total_h
/10; // otherwise 10% extra spacing
3311 item
->SetHeight(total_h
);
3312 if (total_h
>m_lineHeight
)
3313 m_lineHeight
=total_h
;
3315 item
->SetWidth(image_w
+text_w
+2);
3318 // -----------------------------------------------------------------------------
3319 // for developper : y is now the top of the level
3320 // not the middle of it !
3321 void wxGenericTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
3323 int x
= level
*m_indent
;
3324 if (!HasFlag(wxTR_HIDE_ROOT
))
3328 else if (level
== 0)
3330 // a hidden root is not evaluated, but its
3331 // children are always calculated
3335 CalculateSize( item
, dc
);
3338 item
->SetX( x
+m_spacing
);
3340 y
+= GetLineHeight(item
);
3342 if ( !item
->IsExpanded() )
3344 // we don't need to calculate collapsed branches
3349 wxArrayGenericTreeItems
& children
= item
->GetChildren();
3350 size_t n
, count
= children
.Count();
3352 for (n
= 0; n
< count
; ++n
)
3353 CalculateLevel( children
[n
], dc
, level
, y
); // recurse
3356 void wxGenericTreeCtrl::CalculatePositions()
3358 if ( !m_anchor
) return;
3360 wxClientDC
dc(this);
3363 dc
.SetFont( m_normalFont
);
3365 dc
.SetPen( m_dottedPen
);
3366 //if(GetImageList() == NULL)
3367 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
3370 CalculateLevel( m_anchor
, dc
, 0, y
); // start recursion
3373 void wxGenericTreeCtrl::RefreshSubtree(wxGenericTreeItem
*item
)
3375 if (m_dirty
) return;
3376 if (m_freezeCount
) return;
3378 wxSize client
= GetClientSize();
3381 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3382 rect
.width
= client
.x
;
3383 rect
.height
= client
.y
;
3385 Refresh(true, &rect
);
3387 AdjustMyScrollbars();
3390 void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
3392 if (m_dirty
) return;
3393 if (m_freezeCount
) return;
3396 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3397 rect
.width
= GetClientSize().x
;
3398 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
3400 Refresh(true, &rect
);
3403 void wxGenericTreeCtrl::RefreshSelected()
3405 if (m_freezeCount
) return;
3407 // TODO: this is awfully inefficient, we should keep the list of all
3408 // selected items internally, should be much faster
3410 RefreshSelectedUnder(m_anchor
);
3413 void wxGenericTreeCtrl::RefreshSelectedUnder(wxGenericTreeItem
*item
)
3415 if (m_freezeCount
) return;
3417 if ( item
->IsSelected() )
3420 const wxArrayGenericTreeItems
& children
= item
->GetChildren();
3421 size_t count
= children
.GetCount();
3422 for ( size_t n
= 0; n
< count
; n
++ )
3424 RefreshSelectedUnder(children
[n
]);
3428 void wxGenericTreeCtrl::Freeze()
3433 void wxGenericTreeCtrl::Thaw()
3435 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen tree control?") );
3437 if ( !--m_freezeCount
)
3443 // ----------------------------------------------------------------------------
3444 // changing colours: we need to refresh the tree control
3445 // ----------------------------------------------------------------------------
3447 bool wxGenericTreeCtrl::SetBackgroundColour(const wxColour
& colour
)
3449 if ( !wxWindow::SetBackgroundColour(colour
) )
3452 if (m_freezeCount
) return true;
3459 bool wxGenericTreeCtrl::SetForegroundColour(const wxColour
& colour
)
3461 if ( !wxWindow::SetForegroundColour(colour
) )
3464 if (m_freezeCount
) return true;
3471 // Process the tooltip event, to speed up event processing.
3472 // Doesn't actually get a tooltip.
3473 void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent
&event
)
3479 // NOTE: If using the wxListBox visual attributes works everywhere then this can
3480 // be removed, as well as the #else case below.
3481 #define _USE_VISATTR 0
3484 #include "wx/listbox.h"
3490 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
3492 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3496 // Use the same color scheme as wxListBox
3497 return wxListBox::GetClassDefaultAttributes(variant
);
3499 wxVisualAttributes attr
;
3500 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
3501 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
3502 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
3507 #endif // wxUSE_TREECTRL