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 int m_images
[wxTreeItemIcon_Max
];
266 wxCoord m_x
; // (virtual) offset from top
267 wxCoord m_y
; // (virtual) offset from left
268 int m_width
; // width of this item
269 int 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 wxSize bs
= DoGetBestSize() ;
380 // edit control height
383 int diff
= h
- ( bs
.y
- 8 ) ;
389 (void)Create(m_owner
, wxID_ANY
, m_startValue
,
390 wxPoint(x
- 4, y
- 4), wxSize(w
+ 11, h
+ 8));
393 bool wxTreeTextCtrl::AcceptChanges()
395 const wxString value
= GetValue();
397 if ( value
== m_startValue
)
399 // nothing changed, always accept
403 if ( !m_owner
->OnRenameAccept(m_itemEdited
, value
) )
405 // vetoed by the user
409 // accepted, do rename the item
410 m_owner
->SetItemText(m_itemEdited
, value
);
415 void wxTreeTextCtrl::Finish()
419 m_owner
->ResetTextControl();
421 wxPendingDelete
.Append(this);
425 m_owner
->SetFocus(); // This doesn't work. TODO.
429 void wxTreeTextCtrl::OnChar( wxKeyEvent
&event
)
431 switch ( event
.m_keyCode
)
434 if ( AcceptChanges() )
436 // Close the text control, changes were accepted
439 // else do nothing, do not accept and do not close
451 void wxTreeTextCtrl::OnKeyUp( wxKeyEvent
&event
)
455 // auto-grow the textctrl:
456 wxSize parentSize
= m_owner
->GetSize();
457 wxPoint myPos
= GetPosition();
458 wxSize mySize
= GetSize();
460 GetTextExtent(GetValue() + _T("M"), &sx
, &sy
);
461 if (myPos
.x
+ sx
> parentSize
.x
)
462 sx
= parentSize
.x
- myPos
.x
;
465 SetSize(sx
, wxDefaultCoord
);
471 void wxTreeTextCtrl::OnKillFocus( wxFocusEvent
&event
)
476 // We must finish regardless of success, otherwise we'll get
481 // We must let the native text control handle focus, too, otherwise
482 // it could have problems with the cursor (e.g., in wxGTK):
486 // -----------------------------------------------------------------------------
488 // -----------------------------------------------------------------------------
490 wxGenericTreeItem::wxGenericTreeItem(wxGenericTreeItem
*parent
,
491 const wxString
& text
,
492 int image
, int selImage
,
493 wxTreeItemData
*data
)
496 m_images
[wxTreeItemIcon_Normal
] = image
;
497 m_images
[wxTreeItemIcon_Selected
] = selImage
;
498 m_images
[wxTreeItemIcon_Expanded
] = NO_IMAGE
;
499 m_images
[wxTreeItemIcon_SelectedExpanded
] = NO_IMAGE
;
504 m_isCollapsed
= true;
505 m_hasHilight
= false;
511 m_attr
= (wxTreeItemAttr
*)NULL
;
514 // We don't know the height here yet.
519 wxGenericTreeItem::~wxGenericTreeItem()
523 if (m_ownsAttr
) delete m_attr
;
525 wxASSERT_MSG( m_children
.IsEmpty(),
526 wxT("please call DeleteChildren() before deleting the item") );
529 void wxGenericTreeItem::DeleteChildren(wxGenericTreeCtrl
*tree
)
531 size_t count
= m_children
.Count();
532 for ( size_t n
= 0; n
< count
; n
++ )
534 wxGenericTreeItem
*child
= m_children
[n
];
536 tree
->SendDeleteEvent(child
);
538 child
->DeleteChildren(tree
);
545 void wxGenericTreeItem::SetText( const wxString
&text
)
550 size_t wxGenericTreeItem::GetChildrenCount(bool recursively
) const
552 size_t count
= m_children
.Count();
556 size_t total
= count
;
557 for (size_t n
= 0; n
< count
; ++n
)
559 total
+= m_children
[n
]->GetChildrenCount();
565 void wxGenericTreeItem::GetSize( int &x
, int &y
,
566 const wxGenericTreeCtrl
*theButton
)
568 int bottomY
=m_y
+theButton
->GetLineHeight(this);
569 if ( y
< bottomY
) y
= bottomY
;
570 int width
= m_x
+ m_width
;
571 if ( x
< width
) x
= width
;
575 size_t count
= m_children
.Count();
576 for ( size_t n
= 0; n
< count
; ++n
)
578 m_children
[n
]->GetSize( x
, y
, theButton
);
583 wxGenericTreeItem
*wxGenericTreeItem::HitTest(const wxPoint
& point
,
584 const wxGenericTreeCtrl
*theCtrl
,
588 // for a hidden root node, don't evaluate it, but do evaluate children
589 if ( !(level
== 0 && theCtrl
->HasFlag(wxTR_HIDE_ROOT
)) )
592 int h
= theCtrl
->GetLineHeight(this);
593 if ((point
.y
> m_y
) && (point
.y
< m_y
+ h
))
595 int y_mid
= m_y
+ h
/2;
596 if (point
.y
< y_mid
)
597 flags
|= wxTREE_HITTEST_ONITEMUPPERPART
;
599 flags
|= wxTREE_HITTEST_ONITEMLOWERPART
;
601 int xCross
= m_x
- theCtrl
->GetSpacing();
603 // according to the drawing code the triangels are drawn
604 // at -4 , -4 from the position up to +10/+10 max
605 if ((point
.x
> xCross
-4) && (point
.x
< xCross
+10) &&
606 (point
.y
> y_mid
-4) && (point
.y
< y_mid
+10) &&
607 HasPlus() && theCtrl
->HasButtons() )
609 // 5 is the size of the plus sign
610 if ((point
.x
> xCross
-6) && (point
.x
< xCross
+6) &&
611 (point
.y
> y_mid
-6) && (point
.y
< y_mid
+6) &&
612 HasPlus() && theCtrl
->HasButtons() )
615 flags
|= wxTREE_HITTEST_ONITEMBUTTON
;
619 if ((point
.x
>= m_x
) && (point
.x
<= m_x
+m_width
))
624 // assuming every image (normal and selected) has the same size!
625 if ( (GetImage() != NO_IMAGE
) && theCtrl
->m_imageListNormal
)
626 theCtrl
->m_imageListNormal
->GetSize(GetImage(),
629 if ((image_w
!= -1) && (point
.x
<= m_x
+ image_w
+ 1))
630 flags
|= wxTREE_HITTEST_ONITEMICON
;
632 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
638 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
639 if (point
.x
> m_x
+m_width
)
640 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
645 // if children are expanded, fall through to evaluate them
646 if (m_isCollapsed
) return (wxGenericTreeItem
*) NULL
;
650 size_t count
= m_children
.Count();
651 for ( size_t n
= 0; n
< count
; n
++ )
653 wxGenericTreeItem
*res
= m_children
[n
]->HitTest( point
,
661 return (wxGenericTreeItem
*) NULL
;
664 int wxGenericTreeItem::GetCurrentImage() const
666 int image
= NO_IMAGE
;
671 image
= GetImage(wxTreeItemIcon_SelectedExpanded
);
674 if ( image
== NO_IMAGE
)
676 // we usually fall back to the normal item, but try just the
677 // expanded one (and not selected) first in this case
678 image
= GetImage(wxTreeItemIcon_Expanded
);
684 image
= GetImage(wxTreeItemIcon_Selected
);
687 // maybe it doesn't have the specific image we want,
688 // try the default one instead
689 if ( image
== NO_IMAGE
) image
= GetImage();
694 // -----------------------------------------------------------------------------
695 // wxGenericTreeCtrl implementation
696 // -----------------------------------------------------------------------------
698 IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl
, wxScrolledWindow
)
700 BEGIN_EVENT_TABLE(wxGenericTreeCtrl
,wxScrolledWindow
)
701 EVT_PAINT (wxGenericTreeCtrl::OnPaint
)
702 EVT_MOUSE_EVENTS (wxGenericTreeCtrl::OnMouse
)
703 EVT_CHAR (wxGenericTreeCtrl::OnChar
)
704 EVT_SET_FOCUS (wxGenericTreeCtrl::OnSetFocus
)
705 EVT_KILL_FOCUS (wxGenericTreeCtrl::OnKillFocus
)
706 EVT_TREE_ITEM_GETTOOLTIP(wxID_ANY
, wxGenericTreeCtrl::OnGetToolTip
)
709 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
711 * wxTreeCtrl has to be a real class or we have problems with
712 * the run-time information.
715 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxGenericTreeCtrl
)
718 // -----------------------------------------------------------------------------
719 // construction/destruction
720 // -----------------------------------------------------------------------------
722 void wxGenericTreeCtrl::Init()
724 m_current
= m_key_current
= m_anchor
= m_select_me
= (wxGenericTreeItem
*) NULL
;
732 m_hilightBrush
= new wxBrush
734 wxSystemSettings::GetColour
736 wxSYS_COLOUR_HIGHLIGHT
741 m_hilightUnfocusedBrush
= new wxBrush
743 wxSystemSettings::GetColour
745 wxSYS_COLOUR_BTNSHADOW
750 m_imageListNormal
= m_imageListButtons
=
751 m_imageListState
= (wxImageList
*) NULL
;
752 m_ownsImageListNormal
= m_ownsImageListButtons
=
753 m_ownsImageListState
= false;
756 m_isDragging
= false;
757 m_dropTarget
= m_oldSelection
= NULL
;
761 m_renameTimer
= NULL
;
766 m_lastOnSame
= false;
768 #ifdef __WXMAC_CARBON__
769 m_normalFont
.MacCreateThemeFont( kThemeViewsFont
) ;
771 m_normalFont
= wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT
);
773 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
774 m_normalFont
.GetFamily(),
775 m_normalFont
.GetStyle(),
777 m_normalFont
.GetUnderlined(),
778 m_normalFont
.GetFaceName(),
779 m_normalFont
.GetEncoding());
782 bool wxGenericTreeCtrl::Create(wxWindow
*parent
,
787 const wxValidator
& wxVALIDATOR_PARAM(validator
),
788 const wxString
& name
)
792 wxGetOsVersion( &major
, &minor
);
794 style
&= ~wxTR_LINES_AT_ROOT
;
795 style
|= wxTR_NO_LINES
;
797 style
|= wxTR_ROW_LINES
;
800 wxScrolledWindow::Create( parent
, id
, pos
, size
,
801 style
|wxHSCROLL
|wxVSCROLL
, name
);
803 // If the tree display has no buttons, but does have
804 // connecting lines, we can use a narrower layout.
805 // It may not be a good idea to force this...
806 if (!HasButtons() && !HasFlag(wxTR_NO_LINES
))
813 SetValidator( validator
);
816 wxVisualAttributes attr
= GetDefaultAttributes();
817 SetOwnForegroundColour( attr
.colFg
);
818 SetOwnBackgroundColour( attr
.colBg
);
820 SetOwnFont(attr
.font
);
822 // m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86
823 m_dottedPen
= wxPen( wxT("grey"), 0, 0 );
830 wxGenericTreeCtrl::~wxGenericTreeCtrl()
832 delete m_hilightBrush
;
833 delete m_hilightUnfocusedBrush
;
837 delete m_renameTimer
;
840 if (m_ownsImageListNormal
)
841 delete m_imageListNormal
;
842 if (m_ownsImageListState
)
843 delete m_imageListState
;
844 if (m_ownsImageListButtons
)
845 delete m_imageListButtons
;
848 // -----------------------------------------------------------------------------
850 // -----------------------------------------------------------------------------
852 size_t wxGenericTreeCtrl::GetCount() const
860 size_t count
= m_anchor
->GetChildrenCount();
861 if ( !HasFlag(wxTR_HIDE_ROOT
) )
863 // take the root itself into account
870 void wxGenericTreeCtrl::SetIndent(unsigned int indent
)
872 m_indent
= (unsigned short) indent
;
876 void wxGenericTreeCtrl::SetSpacing(unsigned int spacing
)
878 m_spacing
= (unsigned short) spacing
;
883 wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
,
884 bool recursively
) const
886 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
888 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
891 void wxGenericTreeCtrl::SetWindowStyle(const long styles
)
893 if (!HasFlag(wxTR_HIDE_ROOT
) && (styles
& wxTR_HIDE_ROOT
))
895 // if we will hide the root, make sure children are visible
896 m_anchor
->SetHasPlus();
898 CalculatePositions();
901 // right now, just sets the styles. Eventually, we may
902 // want to update the inherited styles, but right now
903 // none of the parents has updatable styles
904 m_windowStyle
= styles
;
908 // -----------------------------------------------------------------------------
909 // functions to work with tree items
910 // -----------------------------------------------------------------------------
912 wxString
wxGenericTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
914 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
916 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetText();
919 int wxGenericTreeCtrl::GetItemImage(const wxTreeItemId
& item
,
920 wxTreeItemIcon which
) const
922 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
924 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetImage(which
);
927 wxTreeItemData
*wxGenericTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
929 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
931 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetData();
934 wxColour
wxGenericTreeCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
936 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
938 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
939 return pItem
->Attr().GetTextColour();
942 wxColour
wxGenericTreeCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
) const
944 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
946 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
947 return pItem
->Attr().GetBackgroundColour();
950 wxFont
wxGenericTreeCtrl::GetItemFont(const wxTreeItemId
& item
) const
952 wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") );
954 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
955 return pItem
->Attr().GetFont();
958 void wxGenericTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
960 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
963 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
964 pItem
->SetText(text
);
965 CalculateSize(pItem
, dc
);
969 void wxGenericTreeCtrl::SetItemImage(const wxTreeItemId
& item
,
971 wxTreeItemIcon which
)
973 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
975 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
976 pItem
->SetImage(image
, which
);
979 CalculateSize(pItem
, dc
);
983 void wxGenericTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
985 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
990 ((wxGenericTreeItem
*) item
.m_pItem
)->SetData(data
);
993 void wxGenericTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
995 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
997 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
998 pItem
->SetHasPlus(has
);
1002 void wxGenericTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
1004 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1006 // avoid redrawing the tree if no real change
1007 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1008 if ( pItem
->IsBold() != bold
)
1010 pItem
->SetBold(bold
);
1015 void wxGenericTreeCtrl::SetItemTextColour(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().SetTextColour(col
);
1025 void wxGenericTreeCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
1026 const wxColour
& col
)
1028 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1030 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1031 pItem
->Attr().SetBackgroundColour(col
);
1035 void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
)
1037 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1039 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1040 pItem
->Attr().SetFont(font
);
1044 bool wxGenericTreeCtrl::SetFont( const wxFont
&font
)
1046 wxScrolledWindow::SetFont(font
);
1048 m_normalFont
= font
;
1049 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
1050 m_normalFont
.GetFamily(),
1051 m_normalFont
.GetStyle(),
1053 m_normalFont
.GetUnderlined(),
1054 m_normalFont
.GetFaceName(),
1055 m_normalFont
.GetEncoding());
1061 // -----------------------------------------------------------------------------
1062 // item status inquiries
1063 // -----------------------------------------------------------------------------
1065 bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
1067 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1069 // An item is only visible if it's not a descendant of a collapsed item
1070 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1071 wxGenericTreeItem
* parent
= pItem
->GetParent();
1074 if (!parent
->IsExpanded())
1076 parent
= parent
->GetParent();
1080 GetViewStart(& startX
, & startY
);
1082 wxSize clientSize
= GetClientSize();
1085 if (!GetBoundingRect(item
, rect
))
1087 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
1089 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
1091 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
1097 bool wxGenericTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
1099 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1101 // consider that the item does have children if it has the "+" button: it
1102 // might not have them (if it had never been expanded yet) but then it
1103 // could have them as well and it's better to err on this side rather than
1104 // disabling some operations which are restricted to the items with
1105 // children for an item which does have them
1106 return ((wxGenericTreeItem
*) item
.m_pItem
)->HasPlus();
1109 bool wxGenericTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
1111 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1113 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsExpanded();
1116 bool wxGenericTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
1118 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1120 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsSelected();
1123 bool wxGenericTreeCtrl::IsBold(const wxTreeItemId
& item
) const
1125 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1127 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsBold();
1130 // -----------------------------------------------------------------------------
1132 // -----------------------------------------------------------------------------
1134 wxTreeItemId
wxGenericTreeCtrl::GetItemParent(const wxTreeItemId
& item
) const
1136 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1138 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetParent();
1141 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1142 wxTreeItemIdValue
& cookie
) const
1144 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1147 return GetNextChild(item
, cookie
);
1150 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1151 wxTreeItemIdValue
& cookie
) const
1153 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1155 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1157 // it's ok to cast cookie to size_t, we never have indices big enough to
1158 // overflow "void *"
1159 size_t *pIndex
= (size_t *)&cookie
;
1160 if ( *pIndex
< children
.Count() )
1162 return children
.Item((*pIndex
)++);
1166 // there are no more of them
1167 return wxTreeItemId();
1171 #if WXWIN_COMPATIBILITY_2_4
1173 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1176 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1179 return GetNextChild(item
, cookie
);
1182 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1185 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1187 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1188 if ( (size_t)cookie
< children
.Count() )
1190 return children
.Item((size_t)cookie
++);
1194 // there are no more of them
1195 return wxTreeItemId();
1199 #endif // WXWIN_COMPATIBILITY_2_4
1201 wxTreeItemId
wxGenericTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
1203 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1205 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1206 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
1209 wxTreeItemId
wxGenericTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
1211 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1213 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1214 wxGenericTreeItem
*parent
= i
->GetParent();
1215 if ( parent
== NULL
)
1217 // root item doesn't have any siblings
1218 return wxTreeItemId();
1221 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1222 int index
= siblings
.Index(i
);
1223 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1225 size_t n
= (size_t)(index
+ 1);
1226 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
1229 wxTreeItemId
wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
1231 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1233 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1234 wxGenericTreeItem
*parent
= i
->GetParent();
1235 if ( parent
== NULL
)
1237 // root item doesn't have any siblings
1238 return wxTreeItemId();
1241 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1242 int index
= siblings
.Index(i
);
1243 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1245 return index
== 0 ? wxTreeItemId()
1246 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
1249 // Only for internal use right now, but should probably be public
1250 wxTreeItemId
wxGenericTreeCtrl::GetNext(const wxTreeItemId
& item
) const
1252 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1254 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1256 // First see if there are any children.
1257 wxArrayGenericTreeItems
& children
= i
->GetChildren();
1258 if (children
.GetCount() > 0)
1260 return children
.Item(0);
1264 // Try a sibling of this or ancestor instead
1265 wxTreeItemId p
= item
;
1266 wxTreeItemId toFind
;
1269 toFind
= GetNextSibling(p
);
1270 p
= GetItemParent(p
);
1271 } while (p
.IsOk() && !toFind
.IsOk());
1276 wxTreeItemId
wxGenericTreeCtrl::GetFirstVisibleItem() const
1278 wxTreeItemId id
= GetRootItem();
1287 } while (id
.IsOk());
1289 return wxTreeItemId();
1292 wxTreeItemId
wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
1294 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1296 wxTreeItemId id
= item
;
1299 while (id
= GetNext(id
), id
.IsOk())
1305 return wxTreeItemId();
1308 wxTreeItemId
wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
1310 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1312 wxFAIL_MSG(wxT("not implemented"));
1314 return wxTreeItemId();
1317 // called by wxTextTreeCtrl when it marks itself for deletion
1318 void wxGenericTreeCtrl::ResetTextControl()
1323 // find the first item starting with the given prefix after the given item
1324 wxTreeItemId
wxGenericTreeCtrl::FindItem(const wxTreeItemId
& idParent
,
1325 const wxString
& prefixOrig
) const
1327 // match is case insensitive as this is more convenient to the user: having
1328 // to press Shift-letter to go to the item starting with a capital letter
1329 // would be too bothersome
1330 wxString prefix
= prefixOrig
.Lower();
1332 // determine the starting point: we shouldn't take the current item (this
1333 // allows to switch between two items starting with the same letter just by
1334 // pressing it) but we shouldn't jump to the next one if the user is
1335 // continuing to type as otherwise he might easily skip the item he wanted
1336 wxTreeItemId id
= idParent
;
1337 if ( prefix
.length() == 1 )
1342 // look for the item starting with the given prefix after it
1343 while ( id
.IsOk() && !GetItemText(id
).Lower().StartsWith(prefix
) )
1348 // if we haven't found anything...
1351 // ... wrap to the beginning
1353 if ( HasFlag(wxTR_HIDE_ROOT
) )
1355 // can't select virtual root
1359 // and try all the items (stop when we get to the one we started from)
1360 while ( id
!= idParent
&& !GetItemText(id
).Lower().StartsWith(prefix
) )
1369 // -----------------------------------------------------------------------------
1371 // -----------------------------------------------------------------------------
1373 wxTreeItemId
wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId
& parentId
,
1375 const wxString
& text
,
1376 int image
, int selImage
,
1377 wxTreeItemData
*data
)
1379 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1382 // should we give a warning here?
1383 return AddRoot(text
, image
, selImage
, data
);
1386 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1388 wxGenericTreeItem
*item
=
1389 new wxGenericTreeItem( parent
, text
, image
, selImage
, data
);
1393 data
->m_pItem
= item
;
1396 parent
->Insert( item
, previous
);
1401 wxTreeItemId
wxGenericTreeCtrl::AddRoot(const wxString
& text
,
1402 int image
, int selImage
,
1403 wxTreeItemData
*data
)
1405 wxCHECK_MSG( !m_anchor
, wxTreeItemId(), wxT("tree can have only one root") );
1407 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1409 m_anchor
= new wxGenericTreeItem((wxGenericTreeItem
*)NULL
, text
,
1410 image
, selImage
, data
);
1413 data
->m_pItem
= m_anchor
;
1416 if (HasFlag(wxTR_HIDE_ROOT
))
1418 // if root is hidden, make sure we can navigate
1420 m_anchor
->SetHasPlus();
1422 CalculatePositions();
1425 if (!HasFlag(wxTR_MULTIPLE
))
1427 m_current
= m_key_current
= m_anchor
;
1428 m_current
->SetHilight( true );
1434 wxTreeItemId
wxGenericTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
1435 const wxString
& text
,
1436 int image
, int selImage
,
1437 wxTreeItemData
*data
)
1439 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
1442 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1443 const wxTreeItemId
& idPrevious
,
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
);
1456 if (idPrevious
.IsOk())
1458 index
= parent
->GetChildren().Index((wxGenericTreeItem
*) idPrevious
.m_pItem
);
1459 wxASSERT_MSG( index
!= wxNOT_FOUND
,
1460 wxT("previous item in wxGenericTreeCtrl::InsertItem() is not a sibling") );
1463 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
1466 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1468 const wxString
& text
,
1469 int image
, int selImage
,
1470 wxTreeItemData
*data
)
1472 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1475 // should we give a warning here?
1476 return AddRoot(text
, image
, selImage
, data
);
1479 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
1482 wxTreeItemId
wxGenericTreeCtrl::AppendItem(const wxTreeItemId
& parentId
,
1483 const wxString
& text
,
1484 int image
, int selImage
,
1485 wxTreeItemData
*data
)
1487 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1490 // should we give a warning here?
1491 return AddRoot(text
, image
, selImage
, data
);
1494 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
1495 image
, selImage
, data
);
1498 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem
*item
)
1500 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, GetId() );
1501 event
.m_item
= item
;
1502 event
.SetEventObject( this );
1503 ProcessEvent( event
);
1506 void wxGenericTreeCtrl::DeleteChildren(const wxTreeItemId
& itemId
)
1508 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1510 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1511 item
->DeleteChildren(this);
1514 void wxGenericTreeCtrl::Delete(const wxTreeItemId
& itemId
)
1516 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1518 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1522 // can't delete the item being edited, cancel editing it first
1523 m_textCtrl
->StopEditing(item
);
1526 wxGenericTreeItem
*parent
= item
->GetParent();
1528 // don't keep stale pointers around!
1529 if ( IsDescendantOf(item
, m_key_current
) )
1531 // Don't silently change the selection:
1532 // do it properly in idle time, so event
1533 // handlers get called.
1535 // m_key_current = parent;
1536 m_key_current
= NULL
;
1539 // m_select_me records whether we need to select
1540 // a different item, in idle time.
1541 if ( m_select_me
&& IsDescendantOf(item
, m_select_me
) )
1543 m_select_me
= parent
;
1546 if ( IsDescendantOf(item
, m_current
) )
1548 // Don't silently change the selection:
1549 // do it properly in idle time, so event
1550 // handlers get called.
1552 // m_current = parent;
1554 m_select_me
= parent
;
1557 // remove the item from the tree
1560 parent
->GetChildren().Remove( item
); // remove by value
1562 else // deleting the root
1564 // nothing will be left in the tree
1568 // and delete all of its children and the item itself now
1569 item
->DeleteChildren(this);
1570 SendDeleteEvent(item
);
1574 void wxGenericTreeCtrl::DeleteAllItems()
1582 void wxGenericTreeCtrl::Expand(const wxTreeItemId
& itemId
)
1584 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1586 wxCHECK_RET( item
, _T("invalid item in wxGenericTreeCtrl::Expand") );
1587 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1588 _T("can't expand hidden root") );
1590 if ( !item
->HasPlus() )
1593 if ( item
->IsExpanded() )
1596 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, GetId() );
1597 event
.m_item
= item
;
1598 event
.SetEventObject( this );
1600 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1602 // cancelled by program
1607 CalculatePositions();
1609 RefreshSubtree(item
);
1611 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
1612 ProcessEvent( event
);
1615 void wxGenericTreeCtrl::ExpandAll(const wxTreeItemId
& item
)
1617 if ( !HasFlag(wxTR_HIDE_ROOT
) || item
!= GetRootItem())
1620 if ( !IsExpanded(item
) )
1624 wxTreeItemIdValue cookie
;
1625 wxTreeItemId child
= GetFirstChild(item
, cookie
);
1626 while ( child
.IsOk() )
1630 child
= GetNextChild(item
, cookie
);
1634 void wxGenericTreeCtrl::Collapse(const wxTreeItemId
& itemId
)
1636 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1637 _T("can't collapse hidden root") );
1639 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1641 if ( !item
->IsExpanded() )
1644 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, GetId() );
1645 event
.m_item
= item
;
1646 event
.SetEventObject( this );
1647 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1649 // cancelled by program
1655 #if 0 // TODO why should items be collapsed recursively?
1656 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1657 size_t count
= children
.Count();
1658 for ( size_t n
= 0; n
< count
; n
++ )
1660 Collapse(children
[n
]);
1664 CalculatePositions();
1666 RefreshSubtree(item
);
1668 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
1669 ProcessEvent( event
);
1672 void wxGenericTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
1675 DeleteChildren(item
);
1678 void wxGenericTreeCtrl::Toggle(const wxTreeItemId
& itemId
)
1680 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1682 if (item
->IsExpanded())
1688 void wxGenericTreeCtrl::Unselect()
1692 m_current
->SetHilight( false );
1693 RefreshLine( m_current
);
1700 void wxGenericTreeCtrl::UnselectAllChildren(wxGenericTreeItem
*item
)
1702 if (item
->IsSelected())
1704 item
->SetHilight(false);
1708 if (item
->HasChildren())
1710 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1711 size_t count
= children
.Count();
1712 for ( size_t n
= 0; n
< count
; ++n
)
1714 UnselectAllChildren(children
[n
]);
1719 void wxGenericTreeCtrl::UnselectAll()
1721 wxTreeItemId rootItem
= GetRootItem();
1723 // the tree might not have the root item at all
1726 UnselectAllChildren((wxGenericTreeItem
*) rootItem
.m_pItem
);
1730 // Recursive function !
1731 // To stop we must have crt_item<last_item
1733 // Tag all next children, when no more children,
1734 // Move to parent (not to tag)
1735 // Keep going... if we found last_item, we stop.
1736 bool wxGenericTreeCtrl::TagNextChildren(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1738 wxGenericTreeItem
*parent
= crt_item
->GetParent();
1740 if (parent
== NULL
) // This is root item
1741 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
1743 wxArrayGenericTreeItems
& children
= parent
->GetChildren();
1744 int index
= children
.Index(crt_item
);
1745 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1747 size_t count
= children
.Count();
1748 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
1750 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return true;
1753 return TagNextChildren(parent
, last_item
, select
);
1756 bool wxGenericTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1758 crt_item
->SetHilight(select
);
1759 RefreshLine(crt_item
);
1761 if (crt_item
==last_item
)
1764 if (crt_item
->HasChildren())
1766 wxArrayGenericTreeItems
& children
= crt_item
->GetChildren();
1767 size_t count
= children
.Count();
1768 for ( size_t n
= 0; n
< count
; ++n
)
1770 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
1778 void wxGenericTreeCtrl::SelectItemRange(wxGenericTreeItem
*item1
, wxGenericTreeItem
*item2
)
1782 // item2 is not necessary after item1
1783 // choice first' and 'last' between item1 and item2
1784 wxGenericTreeItem
*first
= (item1
->GetY()<item2
->GetY()) ? item1
: item2
;
1785 wxGenericTreeItem
*last
= (item1
->GetY()<item2
->GetY()) ? item2
: item1
;
1787 bool select
= m_current
->IsSelected();
1789 if ( TagAllChildrenUntilLast(first
,last
,select
) )
1792 TagNextChildren(first
,last
,select
);
1795 void wxGenericTreeCtrl::DoSelectItem(const wxTreeItemId
& itemId
,
1796 bool unselect_others
,
1797 bool extended_select
)
1799 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
1803 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
1804 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1806 //wxCHECK_RET( ( (!unselect_others) && is_single),
1807 // wxT("this is a single selection tree") );
1809 // to keep going anyhow !!!
1812 if (item
->IsSelected())
1813 return; // nothing to do
1814 unselect_others
= true;
1815 extended_select
= false;
1817 else if ( unselect_others
&& item
->IsSelected() )
1819 // selection change if there is more than one item currently selected
1820 wxArrayTreeItemIds selected_items
;
1821 if ( GetSelections(selected_items
) == 1 )
1825 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, GetId() );
1826 event
.m_item
= item
;
1827 event
.m_itemOld
= m_current
;
1828 event
.SetEventObject( this );
1829 // TODO : Here we don't send any selection mode yet !
1831 if ( GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed() )
1834 wxTreeItemId parent
= GetItemParent( itemId
);
1835 while (parent
.IsOk())
1837 if (!IsExpanded(parent
))
1840 parent
= GetItemParent( parent
);
1843 EnsureVisible( itemId
);
1846 if (unselect_others
)
1848 if (is_single
) Unselect(); // to speed up thing
1853 if (extended_select
)
1857 m_current
= m_key_current
= (wxGenericTreeItem
*) GetRootItem().m_pItem
;
1860 // don't change the mark (m_current)
1861 SelectItemRange(m_current
, item
);
1865 bool select
= true; // the default
1867 // Check if we need to toggle hilight (ctrl mode)
1868 if (!unselect_others
)
1869 select
=!item
->IsSelected();
1871 m_current
= m_key_current
= item
;
1872 m_current
->SetHilight(select
);
1873 RefreshLine( m_current
);
1876 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
1877 GetEventHandler()->ProcessEvent( event
);
1880 void wxGenericTreeCtrl::SelectItem(const wxTreeItemId
& itemId
, bool select
)
1884 DoSelectItem(itemId
);
1888 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1889 wxCHECK_RET( item
, wxT("SelectItem(): invalid tree item") );
1891 item
->SetHilight(false);
1896 void wxGenericTreeCtrl::FillArray(wxGenericTreeItem
*item
,
1897 wxArrayTreeItemIds
&array
) const
1899 if ( item
->IsSelected() )
1900 array
.Add(wxTreeItemId(item
));
1902 if ( item
->HasChildren() )
1904 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1905 size_t count
= children
.GetCount();
1906 for ( size_t n
= 0; n
< count
; ++n
)
1907 FillArray(children
[n
], array
);
1911 size_t wxGenericTreeCtrl::GetSelections(wxArrayTreeItemIds
&array
) const
1914 wxTreeItemId idRoot
= GetRootItem();
1915 if ( idRoot
.IsOk() )
1917 FillArray((wxGenericTreeItem
*) idRoot
.m_pItem
, array
);
1919 //else: the tree is empty, so no selections
1921 return array
.Count();
1924 void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
1926 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1928 if (!item
.IsOk()) return;
1930 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1932 // first expand all parent branches
1933 wxGenericTreeItem
*parent
= gitem
->GetParent();
1935 if ( HasFlag(wxTR_HIDE_ROOT
) )
1937 while ( parent
&& parent
!= m_anchor
)
1940 parent
= parent
->GetParent();
1948 parent
= parent
->GetParent();
1952 //if (parent) CalculatePositions();
1957 void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId
&item
)
1959 if (!item
.IsOk()) return;
1961 // We have to call this here because the label in
1962 // question might just have been added and no screen
1963 // update taken place.
1965 #if defined( __WXMSW__ ) || defined(__WXMAC__)
1970 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1972 // now scroll to the item
1973 int item_y
= gitem
->GetY();
1977 GetViewStart( &start_x
, &start_y
);
1978 start_y
*= PIXELS_PER_UNIT
;
1982 GetClientSize( &client_w
, &client_h
);
1984 if (item_y
< start_y
+3)
1989 m_anchor
->GetSize( x
, y
, this );
1990 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1991 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1992 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1993 // Item should appear at top
1994 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
1996 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
2001 m_anchor
->GetSize( x
, y
, this );
2002 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2003 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2004 item_y
+= PIXELS_PER_UNIT
+2;
2005 int x_pos
= GetScrollPos( wxHORIZONTAL
);
2006 // Item should appear at bottom
2007 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
);
2011 // FIXME: tree sorting functions are not reentrant and not MT-safe!
2012 static wxGenericTreeCtrl
*s_treeBeingSorted
= NULL
;
2014 static int LINKAGEMODE
tree_ctrl_compare_func(wxGenericTreeItem
**item1
,
2015 wxGenericTreeItem
**item2
)
2017 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxGenericTreeCtrl::SortChildren()") );
2019 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
2022 int wxGenericTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
2023 const wxTreeItemId
& item2
)
2025 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
2028 void wxGenericTreeCtrl::SortChildren(const wxTreeItemId
& itemId
)
2030 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
2032 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
2034 wxCHECK_RET( !s_treeBeingSorted
,
2035 wxT("wxGenericTreeCtrl::SortChildren is not reentrant") );
2037 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2038 if ( children
.Count() > 1 )
2042 s_treeBeingSorted
= this;
2043 children
.Sort(tree_ctrl_compare_func
);
2044 s_treeBeingSorted
= NULL
;
2046 //else: don't make the tree dirty as nothing changed
2049 wxImageList
*wxGenericTreeCtrl::GetImageList() const
2051 return m_imageListNormal
;
2054 wxImageList
*wxGenericTreeCtrl::GetButtonsImageList() const
2056 return m_imageListButtons
;
2059 wxImageList
*wxGenericTreeCtrl::GetStateImageList() const
2061 return m_imageListState
;
2064 void wxGenericTreeCtrl::CalculateLineHeight()
2066 wxClientDC
dc(this);
2067 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
2069 if ( m_imageListNormal
)
2071 // Calculate a m_lineHeight value from the normal Image sizes.
2072 // May be toggle off. Then wxGenericTreeCtrl will spread when
2073 // necessary (which might look ugly).
2074 int n
= m_imageListNormal
->GetImageCount();
2075 for (int i
= 0; i
< n
; i
++)
2077 int width
= 0, height
= 0;
2078 m_imageListNormal
->GetSize(i
, width
, height
);
2079 if (height
> m_lineHeight
) m_lineHeight
= height
;
2083 if (m_imageListButtons
)
2085 // Calculate a m_lineHeight value from the Button image sizes.
2086 // May be toggle off. Then wxGenericTreeCtrl will spread when
2087 // necessary (which might look ugly).
2088 int n
= m_imageListButtons
->GetImageCount();
2089 for (int i
= 0; i
< n
; i
++)
2091 int width
= 0, height
= 0;
2092 m_imageListButtons
->GetSize(i
, width
, height
);
2093 if (height
> m_lineHeight
) m_lineHeight
= height
;
2097 if (m_lineHeight
< 30)
2098 m_lineHeight
+= 2; // at least 2 pixels
2100 m_lineHeight
+= m_lineHeight
/10; // otherwise 10% extra spacing
2103 void wxGenericTreeCtrl::SetImageList(wxImageList
*imageList
)
2105 if (m_ownsImageListNormal
) delete m_imageListNormal
;
2106 m_imageListNormal
= imageList
;
2107 m_ownsImageListNormal
= false;
2109 // Don't do any drawing if we're setting the list to NULL,
2110 // since we may be in the process of deleting the tree control.
2112 CalculateLineHeight();
2115 void wxGenericTreeCtrl::SetStateImageList(wxImageList
*imageList
)
2117 if (m_ownsImageListState
) delete m_imageListState
;
2118 m_imageListState
= imageList
;
2119 m_ownsImageListState
= false;
2122 void wxGenericTreeCtrl::SetButtonsImageList(wxImageList
*imageList
)
2124 if (m_ownsImageListButtons
) delete m_imageListButtons
;
2125 m_imageListButtons
= imageList
;
2126 m_ownsImageListButtons
= false;
2128 CalculateLineHeight();
2131 void wxGenericTreeCtrl::AssignImageList(wxImageList
*imageList
)
2133 SetImageList(imageList
);
2134 m_ownsImageListNormal
= true;
2137 void wxGenericTreeCtrl::AssignStateImageList(wxImageList
*imageList
)
2139 SetStateImageList(imageList
);
2140 m_ownsImageListState
= true;
2143 void wxGenericTreeCtrl::AssignButtonsImageList(wxImageList
*imageList
)
2145 SetButtonsImageList(imageList
);
2146 m_ownsImageListButtons
= true;
2149 // -----------------------------------------------------------------------------
2151 // -----------------------------------------------------------------------------
2153 void wxGenericTreeCtrl::AdjustMyScrollbars()
2158 m_anchor
->GetSize( x
, y
, this );
2159 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2160 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2161 int x_pos
= GetScrollPos( wxHORIZONTAL
);
2162 int y_pos
= GetScrollPos( wxVERTICAL
);
2163 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
2167 SetScrollbars( 0, 0, 0, 0 );
2171 int wxGenericTreeCtrl::GetLineHeight(wxGenericTreeItem
*item
) const
2173 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
2174 return item
->GetHeight();
2176 return m_lineHeight
;
2179 void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem
*item
, wxDC
& dc
)
2181 // TODO implement "state" icon on items
2183 wxTreeItemAttr
*attr
= item
->GetAttributes();
2184 if ( attr
&& attr
->HasFont() )
2185 dc
.SetFont(attr
->GetFont());
2186 else if (item
->IsBold())
2187 dc
.SetFont(m_boldFont
);
2189 long text_w
= 0, text_h
= 0;
2190 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
2192 int image_h
= 0, image_w
= 0;
2193 int image
= item
->GetCurrentImage();
2194 if ( image
!= NO_IMAGE
)
2196 if ( m_imageListNormal
)
2198 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
2207 int total_h
= GetLineHeight(item
);
2209 if ( item
->IsSelected() )
2211 // under mac selections are only a rectangle in case they don't have the focus
2215 dc
.SetBrush( *wxTRANSPARENT_BRUSH
) ;
2216 dc
.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
) , 1 , wxSOLID
) ) ;
2220 dc
.SetBrush( *m_hilightBrush
) ;
2223 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
2229 if ( attr
&& attr
->HasBackgroundColour() )
2230 colBg
= attr
->GetBackgroundColour();
2232 colBg
= m_backgroundColour
;
2233 dc
.SetBrush(wxBrush(colBg
, wxSOLID
));
2236 int offset
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0;
2238 if ( HasFlag(wxTR_FULL_ROW_HIGHLIGHT
) )
2242 DoGetPosition(&x
, &y
);
2244 dc
.DrawRectangle(x
, item
->GetY()+offset
, w
, total_h
-offset
);
2248 if ( item
->IsSelected() && image
!= NO_IMAGE
)
2250 // If it's selected, and there's an image, then we should
2251 // take care to leave the area under the image painted in the
2252 // background colour.
2253 dc
.DrawRectangle( item
->GetX() + image_w
- 2, item
->GetY()+offset
,
2254 item
->GetWidth() - image_w
+ 2, total_h
-offset
);
2258 dc
.DrawRectangle( item
->GetX()-2, item
->GetY()+offset
,
2259 item
->GetWidth()+2, total_h
-offset
);
2263 if ( image
!= NO_IMAGE
)
2265 dc
.SetClippingRegion( item
->GetX(), item
->GetY(), image_w
-2, total_h
);
2266 m_imageListNormal
->Draw( image
, dc
,
2268 item
->GetY() +((total_h
> image_h
)?((total_h
-image_h
)/2):0),
2269 wxIMAGELIST_DRAW_TRANSPARENT
);
2270 dc
.DestroyClippingRegion();
2273 dc
.SetBackgroundMode(wxTRANSPARENT
);
2274 int extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
2275 dc
.DrawText( item
->GetText(),
2276 (wxCoord
)(image_w
+ item
->GetX()),
2277 (wxCoord
)(item
->GetY() + extraH
));
2279 // restore normal font
2280 dc
.SetFont( m_normalFont
);
2283 // Now y stands for the top of the item, whereas it used to stand for middle !
2284 void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
2286 int x
= level
*m_indent
;
2287 if (!HasFlag(wxTR_HIDE_ROOT
))
2291 else if (level
== 0)
2293 // always expand hidden root
2295 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2296 int count
= children
.Count();
2302 PaintLevel(children
[n
], dc
, 1, y
);
2303 } while (++n
< count
);
2305 if (!HasFlag(wxTR_NO_LINES
) && HasFlag(wxTR_LINES_AT_ROOT
) && count
> 0)
2307 // draw line down to last child
2308 origY
+= GetLineHeight(children
[0])>>1;
2309 oldY
+= GetLineHeight(children
[n
-1])>>1;
2310 dc
.DrawLine(3, origY
, 3, oldY
);
2316 item
->SetX(x
+m_spacing
);
2319 int h
= GetLineHeight(item
);
2321 int y_mid
= y_top
+ (h
>>1);
2324 int exposed_x
= dc
.LogicalToDeviceX(0);
2325 int exposed_y
= dc
.LogicalToDeviceY(y_top
);
2327 if (IsExposed(exposed_x
, exposed_y
, 10000, h
)) // 10000 = very much
2331 // don't draw rect outline if we already have the
2332 // background color under Mac
2333 (item
->IsSelected() && m_hasFocus
) ? wxBLACK_PEN
:
2334 #endif // !__WXMAC__
2338 if ( item
->IsSelected() )
2340 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
2344 wxTreeItemAttr
*attr
= item
->GetAttributes();
2345 if (attr
&& attr
->HasTextColour())
2346 colText
= attr
->GetTextColour();
2348 colText
= GetForegroundColour();
2352 dc
.SetTextForeground(colText
);
2356 PaintItem(item
, dc
);
2358 if (HasFlag(wxTR_ROW_LINES
))
2360 // if the background colour is white, choose a
2361 // contrasting color for the lines
2362 dc
.SetPen(*((GetBackgroundColour() == *wxWHITE
)
2363 ? wxMEDIUM_GREY_PEN
: wxWHITE_PEN
));
2364 dc
.DrawLine(0, y_top
, 10000, y_top
);
2365 dc
.DrawLine(0, y
, 10000, y
);
2368 // restore DC objects
2369 dc
.SetBrush(*wxWHITE_BRUSH
);
2370 dc
.SetPen(m_dottedPen
);
2371 dc
.SetTextForeground(*wxBLACK
);
2373 if ( !HasFlag(wxTR_NO_LINES
) )
2375 // draw the horizontal line here
2377 if (x
> (signed)m_indent
)
2378 x_start
-= m_indent
;
2379 else if (HasFlag(wxTR_LINES_AT_ROOT
))
2381 dc
.DrawLine(x_start
, y_mid
, x
+ m_spacing
, y_mid
);
2384 // should the item show a button?
2385 if ( item
->HasPlus() && HasButtons() )
2387 if ( m_imageListButtons
)
2389 // draw the image button here
2392 int image
= item
->IsExpanded() ? wxTreeItemIcon_Expanded
2393 : wxTreeItemIcon_Normal
;
2394 if ( item
->IsSelected() )
2395 image
+= wxTreeItemIcon_Selected
- wxTreeItemIcon_Normal
;
2397 m_imageListButtons
->GetSize(image
, image_w
, image_h
);
2398 int xx
= x
- image_w
/2;
2399 int yy
= y_mid
- image_h
/2;
2401 wxDCClipper
clip(dc
, xx
, yy
, image_w
, image_h
);
2402 m_imageListButtons
->Draw(image
, dc
, xx
, yy
,
2403 wxIMAGELIST_DRAW_TRANSPARENT
);
2405 else // no custom buttons
2407 static const int wImage
= 9;
2408 static const int hImage
= 9;
2411 if (item
->IsExpanded())
2412 flag
|= wxCONTROL_EXPANDED
;
2413 if (item
== m_underMouse
)
2414 flag
|= wxCONTROL_CURRENT
;
2416 wxRendererNative::Get().DrawTreeItemButton
2420 wxRect(x
- wImage
/2,
2429 if (item
->IsExpanded())
2431 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2432 int count
= children
.Count();
2439 PaintLevel(children
[n
], dc
, level
, y
);
2440 } while (++n
< count
);
2442 if (!HasFlag(wxTR_NO_LINES
) && count
> 0)
2444 // draw line down to last child
2445 oldY
+= GetLineHeight(children
[n
-1])>>1;
2446 if (HasButtons()) y_mid
+= 5;
2448 // Only draw the portion of the line that is visible, in case it is huge
2449 wxCoord xOrigin
=0, yOrigin
=0, width
, height
;
2450 dc
.GetDeviceOrigin(&xOrigin
, &yOrigin
);
2451 yOrigin
= abs(yOrigin
);
2452 GetClientSize(&width
, &height
);
2454 // Move end points to the begining/end of the view?
2455 if (y_mid
< yOrigin
)
2457 if (oldY
> yOrigin
+ height
)
2458 oldY
= yOrigin
+ height
;
2460 // after the adjustments if y_mid is larger than oldY then the line
2461 // isn't visible at all so don't draw anything
2463 dc
.DrawLine(x
, y_mid
, x
, oldY
);
2469 void wxGenericTreeCtrl::DrawDropEffect(wxGenericTreeItem
*item
)
2473 if ( item
->HasPlus() )
2475 // it's a folder, indicate it by a border
2480 // draw a line under the drop target because the item will be
2482 DrawLine(item
, true /* below */);
2485 SetCursor(wxCURSOR_BULLSEYE
);
2490 SetCursor(wxCURSOR_NO_ENTRY
);
2494 void wxGenericTreeCtrl::DrawBorder(const wxTreeItemId
&item
)
2496 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2498 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2500 wxClientDC
dc(this);
2502 dc
.SetLogicalFunction(wxINVERT
);
2503 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2505 int w
= i
->GetWidth() + 2;
2506 int h
= GetLineHeight(i
) + 2;
2508 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
2511 void wxGenericTreeCtrl::DrawLine(const wxTreeItemId
&item
, bool below
)
2513 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2515 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2517 wxClientDC
dc(this);
2519 dc
.SetLogicalFunction(wxINVERT
);
2525 y
+= GetLineHeight(i
) - 1;
2528 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
2531 // -----------------------------------------------------------------------------
2532 // wxWidgets callbacks
2533 // -----------------------------------------------------------------------------
2535 void wxGenericTreeCtrl::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2543 dc
.SetFont( m_normalFont
);
2544 dc
.SetPen( m_dottedPen
);
2546 // this is now done dynamically
2547 //if(GetImageList() == NULL)
2548 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
2551 PaintLevel( m_anchor
, dc
, 0, y
);
2554 void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent
&event
)
2563 void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent
&event
)
2572 void wxGenericTreeCtrl::OnChar( wxKeyEvent
&event
)
2574 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, GetId() );
2575 te
.m_evtKey
= event
;
2576 te
.SetEventObject( this );
2577 if ( GetEventHandler()->ProcessEvent( te
) )
2579 // intercepted by the user code
2583 if ( (m_current
== 0) || (m_key_current
== 0) )
2589 // how should the selection work for this event?
2590 bool is_multiple
, extended_select
, unselect_others
;
2591 EventFlagsToSelType(GetWindowStyleFlag(),
2593 event
.ControlDown(),
2594 is_multiple
, extended_select
, unselect_others
);
2598 // * : Expand all/Collapse all
2599 // ' ' | return : activate
2600 // up : go up (not last children!)
2602 // left : go to parent
2603 // right : open if parent and go next
2604 // home : go to root
2605 // end : go to last item without opening parents
2606 // alnum : start or continue searching for the item with this prefix
2607 int keyCode
= event
.GetKeyCode();
2612 if (m_current
->HasPlus() && !IsExpanded(m_current
))
2620 if ( !IsExpanded(m_current
) )
2623 ExpandAll(m_current
);
2626 //else: fall through to Collapse() it
2630 if (IsExpanded(m_current
))
2632 Collapse(m_current
);
2638 if ( !event
.HasModifiers() )
2640 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
2641 event
.m_item
= m_current
;
2642 event
.SetEventObject( this );
2643 GetEventHandler()->ProcessEvent( event
);
2646 // in any case, also generate the normal key event for this key,
2647 // even if we generated the ACTIVATED event above: this is what
2648 // wxMSW does and it makes sense because you might not want to
2649 // process ACTIVATED event at all and handle Space and Return
2650 // directly (and differently) which would be impossible otherwise
2654 // up goes to the previous sibling or to the last
2655 // of its children if it's expanded
2658 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
2661 prev
= GetItemParent( m_key_current
);
2662 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2664 break; // don't go to root if it is hidden
2668 wxTreeItemIdValue cookie
;
2669 wxTreeItemId current
= m_key_current
;
2670 // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be?
2671 if (current
== GetFirstChild( prev
, cookie
))
2673 // otherwise we return to where we came from
2674 DoSelectItem( prev
, unselect_others
, extended_select
);
2675 m_key_current
= (wxGenericTreeItem
*) prev
.m_pItem
;
2682 while ( IsExpanded(prev
) && HasChildren(prev
) )
2684 wxTreeItemId child
= GetLastChild(prev
);
2691 DoSelectItem( prev
, unselect_others
, extended_select
);
2692 m_key_current
=(wxGenericTreeItem
*) prev
.m_pItem
;
2697 // left arrow goes to the parent
2700 wxTreeItemId prev
= GetItemParent( m_current
);
2701 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2703 // don't go to root if it is hidden
2704 prev
= GetPrevSibling( m_current
);
2708 DoSelectItem( prev
, unselect_others
, extended_select
);
2714 // this works the same as the down arrow except that we
2715 // also expand the item if it wasn't expanded yet
2721 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
2723 wxTreeItemIdValue cookie
;
2724 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
2725 DoSelectItem( child
, unselect_others
, extended_select
);
2726 m_key_current
=(wxGenericTreeItem
*) child
.m_pItem
;
2730 wxTreeItemId next
= GetNextSibling( m_key_current
);
2733 wxTreeItemId current
= m_key_current
;
2734 while (current
.IsOk() && !next
)
2736 current
= GetItemParent( current
);
2737 if (current
) next
= GetNextSibling( current
);
2742 DoSelectItem( next
, unselect_others
, extended_select
);
2743 m_key_current
=(wxGenericTreeItem
*) next
.m_pItem
;
2749 // <End> selects the last visible tree item
2752 wxTreeItemId last
= GetRootItem();
2754 while ( last
.IsOk() && IsExpanded(last
) )
2756 wxTreeItemId lastChild
= GetLastChild(last
);
2758 // it may happen if the item was expanded but then all of
2759 // its children have been deleted - so IsExpanded() returned
2760 // true, but GetLastChild() returned invalid item
2769 DoSelectItem( last
, unselect_others
, extended_select
);
2774 // <Home> selects the root item
2777 wxTreeItemId prev
= GetRootItem();
2781 if ( HasFlag(wxTR_HIDE_ROOT
) )
2783 wxTreeItemIdValue cookie
;
2784 prev
= GetFirstChild(prev
, cookie
);
2789 DoSelectItem( prev
, unselect_others
, extended_select
);
2794 // do not use wxIsalnum() here
2795 if ( !event
.HasModifiers() &&
2796 ((keyCode
>= '0' && keyCode
<= '9') ||
2797 (keyCode
>= 'a' && keyCode
<= 'z') ||
2798 (keyCode
>= 'A' && keyCode
<= 'Z' )))
2800 // find the next item starting with the given prefix
2801 wxChar ch
= (wxChar
)keyCode
;
2803 wxTreeItemId id
= FindItem(m_current
, m_findPrefix
+ ch
);
2814 // also start the timer to reset the current prefix if the user
2815 // doesn't press any more alnum keys soon -- we wouldn't want
2816 // to use this prefix for a new item search
2819 m_findTimer
= new wxTreeFindTimer(this);
2822 m_findTimer
->Start(wxTreeFindTimer::DELAY
, wxTIMER_ONE_SHOT
);
2831 wxTreeItemId
wxGenericTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
2833 // JACS: removed wxYieldIfNeeded() because it can cause the window
2834 // to be deleted from under us if a close window event is pending
2839 if (point
.x
<0) flags
|= wxTREE_HITTEST_TOLEFT
;
2840 if (point
.x
>w
) flags
|= wxTREE_HITTEST_TORIGHT
;
2841 if (point
.y
<0) flags
|= wxTREE_HITTEST_ABOVE
;
2842 if (point
.y
>h
) flags
|= wxTREE_HITTEST_BELOW
;
2843 if (flags
) return wxTreeItemId();
2845 if (m_anchor
== NULL
)
2847 flags
= wxTREE_HITTEST_NOWHERE
;
2848 return wxTreeItemId();
2851 wxGenericTreeItem
*hit
= m_anchor
->HitTest(CalcUnscrolledPosition(point
),
2855 flags
= wxTREE_HITTEST_NOWHERE
;
2856 return wxTreeItemId();
2861 // get the bounding rectangle of the item (or of its label only)
2862 bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId
& item
,
2864 bool WXUNUSED(textOnly
)) const
2866 wxCHECK_MSG( item
.IsOk(), false, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
2868 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2871 GetViewStart(& startX
, & startY
);
2873 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
2874 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
2875 rect
.width
= i
->GetWidth();
2876 //rect.height = i->GetHeight();
2877 rect
.height
= GetLineHeight(i
);
2882 void wxGenericTreeCtrl::Edit( const wxTreeItemId
& item
)
2884 wxCHECK_RET( item
.IsOk(), _T("can't edit an invalid item") );
2886 wxGenericTreeItem
*itemEdit
= (wxGenericTreeItem
*)item
.m_pItem
;
2888 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, GetId() );
2889 te
.m_item
= itemEdit
;
2890 te
.SetEventObject( this );
2891 if ( GetEventHandler()->ProcessEvent( te
) && !te
.IsAllowed() )
2897 // We have to call this here because the label in
2898 // question might just have been added and no screen
2899 // update taken place.
2901 #if defined( __WXMSW__ ) || defined(__WXMAC__)
2907 m_textCtrl
= new wxTreeTextCtrl(this, itemEdit
);
2909 m_textCtrl
->SetFocus();
2912 // returns a pointer to the text edit control if the item is being
2913 // edited, NULL otherwise (it's assumed that no more than one item may
2914 // be edited simultaneously)
2915 wxTextCtrl
* wxGenericTreeCtrl::GetEditControl() const
2920 bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem
*item
,
2921 const wxString
& value
)
2923 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2925 le
.SetEventObject( this );
2927 le
.m_editCancelled
= false;
2929 return !GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2932 void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem
*item
)
2934 // let owner know that the edit was cancelled
2935 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2937 le
.SetEventObject( this );
2938 le
.m_label
= wxEmptyString
;
2939 le
.m_editCancelled
= true;
2941 GetEventHandler()->ProcessEvent( le
);
2944 void wxGenericTreeCtrl::OnRenameTimer()
2949 void wxGenericTreeCtrl::OnMouse( wxMouseEvent
&event
)
2951 if ( !m_anchor
) return;
2953 wxPoint pt
= CalcUnscrolledPosition(event
.GetPosition());
2955 // Is the mouse over a tree item button?
2957 wxGenericTreeItem
*thisItem
= m_anchor
->HitTest(pt
, this, flags
, 0);
2958 wxGenericTreeItem
*underMouse
= thisItem
;
2960 bool underMouseChanged
= (underMouse
!= m_underMouse
) ;
2961 #endif // wxUSE_TOOLTIPS
2964 (flags
& wxTREE_HITTEST_ONITEMBUTTON
) &&
2965 (!event
.LeftIsDown()) &&
2967 (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2975 if (underMouse
!= m_underMouse
)
2979 // unhighlight old item
2980 wxGenericTreeItem
*tmp
= m_underMouse
;
2981 m_underMouse
= NULL
;
2985 m_underMouse
= underMouse
;
2987 RefreshLine( m_underMouse
);
2991 // Determines what item we are hovering over and need a tooltip for
2992 wxTreeItemId hoverItem
= thisItem
;
2994 // We do not want a tooltip if we are dragging, or if the rename timer is running
2995 if (underMouseChanged
&& hoverItem
.IsOk() && !m_isDragging
&& (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2997 // Ask the tree control what tooltip (if any) should be shown
2998 wxTreeEvent
hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP
, GetId());
2999 hevent
.m_item
= hoverItem
;
3000 hevent
.SetEventObject(this);
3002 if ( GetEventHandler()->ProcessEvent(hevent
) && hevent
.IsAllowed() )
3004 SetToolTip(hevent
.m_label
);
3009 // we process left mouse up event (enables in-place edit), right down
3010 // (pass to the user code), left dbl click (activate item) and
3011 // dragging/moving events for items drag-and-drop
3012 if ( !(event
.LeftDown() ||
3014 event
.RightDown() ||
3015 event
.LeftDClick() ||
3017 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
3026 wxGenericTreeItem
*item
= m_anchor
->HitTest(pt
, this, flags
, 0);
3028 if ( event
.Dragging() && !m_isDragging
)
3030 if (m_dragCount
== 0)
3035 if (m_dragCount
!= 3)
3037 // wait until user drags a bit further...
3041 wxEventType command
= event
.RightIsDown()
3042 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
3043 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
3045 wxTreeEvent
nevent( command
, GetId() );
3046 nevent
.m_item
= m_current
;
3047 nevent
.SetEventObject(this);
3049 // by default the dragging is not supported, the user code must
3050 // explicitly allow the event for it to take place
3053 if ( GetEventHandler()->ProcessEvent(nevent
) && nevent
.IsAllowed() )
3055 // we're going to drag this item
3056 m_isDragging
= true;
3058 // remember the old cursor because we will change it while
3060 m_oldCursor
= m_cursor
;
3062 // in a single selection control, hide the selection temporarily
3063 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
3065 m_oldSelection
= (wxGenericTreeItem
*) GetSelection().m_pItem
;
3067 if ( m_oldSelection
)
3069 m_oldSelection
->SetHilight(false);
3070 RefreshLine(m_oldSelection
);
3077 else if ( event
.Moving() )
3079 if ( item
!= m_dropTarget
)
3081 // unhighlight the previous drop target
3082 DrawDropEffect(m_dropTarget
);
3084 m_dropTarget
= item
;
3086 // highlight the current drop target if any
3087 DrawDropEffect(m_dropTarget
);
3089 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3096 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
3098 // erase the highlighting
3099 DrawDropEffect(m_dropTarget
);
3101 if ( m_oldSelection
)
3103 m_oldSelection
->SetHilight(true);
3104 RefreshLine(m_oldSelection
);
3105 m_oldSelection
= (wxGenericTreeItem
*)NULL
;
3108 // generate the drag end event
3109 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
, GetId());
3111 event
.m_item
= item
;
3112 event
.m_pointDrag
= pt
;
3113 event
.SetEventObject(this);
3115 (void)GetEventHandler()->ProcessEvent(event
);
3117 m_isDragging
= false;
3118 m_dropTarget
= (wxGenericTreeItem
*)NULL
;
3122 SetCursor(m_oldCursor
);
3124 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3132 // If we got to this point, we are not dragging or moving the mouse.
3133 // Because the code in carbon/toplevel.cpp will only set focus to the tree
3134 // if we skip for EVT_LEFT_DOWN, we MUST skip this event here for focus to work.
3135 // We skip even if we didn't hit an item because we still should
3136 // restore focus to the tree control even if we didn't exactly hit an item.
3137 if ( event
.LeftDown() )
3142 // here we process only the messages which happen on tree items
3146 if (item
== NULL
) return; /* we hit the blank area */
3148 if ( event
.RightDown() )
3150 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
, GetId());
3151 nevent
.m_item
= item
;
3152 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3153 nevent
.SetEventObject(this);
3154 GetEventHandler()->ProcessEvent(nevent
);
3156 else if ( event
.LeftUp() )
3158 // this facilitates multiple-item drag-and-drop
3160 if (item
&& HasFlag(wxTR_MULTIPLE
))
3162 wxArrayTreeItemIds selections
;
3163 size_t count
= GetSelections(selections
);
3166 !event
.ControlDown() &&
3169 DoSelectItem(item
, true, false);
3175 if ( (item
== m_current
) &&
3176 (flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
3177 HasFlag(wxTR_EDIT_LABELS
) )
3179 if ( m_renameTimer
)
3181 if ( m_renameTimer
->IsRunning() )
3182 m_renameTimer
->Stop();
3186 m_renameTimer
= new wxTreeRenameTimer( this );
3189 m_renameTimer
->Start( wxTreeRenameTimer::DELAY
, true );
3192 m_lastOnSame
= false;
3195 else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
3197 if ( event
.LeftDown() )
3199 m_lastOnSame
= item
== m_current
;
3202 if ( flags
& wxTREE_HITTEST_ONITEMBUTTON
)
3204 // only toggle the item for a single click, double click on
3205 // the button doesn't do anything (it toggles the item twice)
3206 if ( event
.LeftDown() )
3211 // don't select the item if the button was clicked
3216 // clear the previously selected items, if the
3217 // user clicked outside of the present selection.
3218 // otherwise, perform the deselection on mouse-up.
3219 // this allows multiple drag and drop to work.
3221 if (!IsSelected(item
))
3223 // how should the selection work for this event?
3224 bool is_multiple
, extended_select
, unselect_others
;
3225 EventFlagsToSelType(GetWindowStyleFlag(),
3227 event
.ControlDown(),
3228 is_multiple
, extended_select
, unselect_others
);
3230 DoSelectItem(item
, unselect_others
, extended_select
);
3234 // For some reason, Windows isn't recognizing a left double-click,
3235 // so we need to simulate it here. Allow 200 milliseconds for now.
3236 if ( event
.LeftDClick() )
3238 // double clicking should not start editing the item label
3239 if ( m_renameTimer
)
3240 m_renameTimer
->Stop();
3242 m_lastOnSame
= false;
3244 // send activate event first
3245 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
3246 nevent
.m_item
= item
;
3247 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3248 nevent
.SetEventObject( this );
3249 if ( !GetEventHandler()->ProcessEvent( nevent
) )
3251 // if the user code didn't process the activate event,
3252 // handle it ourselves by toggling the item when it is
3254 if ( item
->HasPlus() )
3264 void wxGenericTreeCtrl::OnInternalIdle()
3266 wxWindow::OnInternalIdle();
3268 // Check if we need to select the root item
3269 // because nothing else has been selected.
3270 // Delaying it means that we can invoke event handlers
3271 // as required, when a first item is selected.
3272 if (!HasFlag(wxTR_MULTIPLE
) && !GetSelection().IsOk())
3275 SelectItem(m_select_me
);
3276 else if (GetRootItem().IsOk())
3277 SelectItem(GetRootItem());
3280 /* after all changes have been done to the tree control,
3281 * we actually redraw the tree when everything is over */
3283 if (!m_dirty
) return;
3284 if (m_freezeCount
) return;
3288 CalculatePositions();
3290 AdjustMyScrollbars();
3293 void wxGenericTreeCtrl::CalculateSize( wxGenericTreeItem
*item
, wxDC
&dc
)
3298 wxTreeItemAttr
*attr
= item
->GetAttributes();
3299 if ( attr
&& attr
->HasFont() )
3300 dc
.SetFont(attr
->GetFont());
3301 else if ( item
->IsBold() )
3302 dc
.SetFont(m_boldFont
);
3304 dc
.SetFont(m_normalFont
);
3306 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
3309 // restore normal font
3310 dc
.SetFont( m_normalFont
);
3314 int image
= item
->GetCurrentImage();
3315 if ( image
!= NO_IMAGE
)
3317 if ( m_imageListNormal
)
3319 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
3324 int total_h
= (image_h
> text_h
) ? image_h
: text_h
;
3327 total_h
+= 2; // at least 2 pixels
3329 total_h
+= total_h
/10; // otherwise 10% extra spacing
3331 item
->SetHeight(total_h
);
3332 if (total_h
>m_lineHeight
)
3333 m_lineHeight
=total_h
;
3335 item
->SetWidth(image_w
+text_w
+2);
3338 // -----------------------------------------------------------------------------
3339 // for developper : y is now the top of the level
3340 // not the middle of it !
3341 void wxGenericTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
3343 int x
= level
*m_indent
;
3344 if (!HasFlag(wxTR_HIDE_ROOT
))
3348 else if (level
== 0)
3350 // a hidden root is not evaluated, but its
3351 // children are always calculated
3355 CalculateSize( item
, dc
);
3358 item
->SetX( x
+m_spacing
);
3360 y
+= GetLineHeight(item
);
3362 if ( !item
->IsExpanded() )
3364 // we don't need to calculate collapsed branches
3369 wxArrayGenericTreeItems
& children
= item
->GetChildren();
3370 size_t n
, count
= children
.Count();
3372 for (n
= 0; n
< count
; ++n
)
3373 CalculateLevel( children
[n
], dc
, level
, y
); // recurse
3376 void wxGenericTreeCtrl::CalculatePositions()
3378 if ( !m_anchor
) return;
3380 wxClientDC
dc(this);
3383 dc
.SetFont( m_normalFont
);
3385 dc
.SetPen( m_dottedPen
);
3386 //if(GetImageList() == NULL)
3387 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
3390 CalculateLevel( m_anchor
, dc
, 0, y
); // start recursion
3393 void wxGenericTreeCtrl::RefreshSubtree(wxGenericTreeItem
*item
)
3395 if (m_dirty
) return;
3396 if (m_freezeCount
) return;
3398 wxSize client
= GetClientSize();
3401 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3402 rect
.width
= client
.x
;
3403 rect
.height
= client
.y
;
3405 Refresh(true, &rect
);
3407 AdjustMyScrollbars();
3410 void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
3412 if (m_dirty
) return;
3413 if (m_freezeCount
) return;
3416 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3417 rect
.width
= GetClientSize().x
;
3418 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
3420 Refresh(true, &rect
);
3423 void wxGenericTreeCtrl::RefreshSelected()
3425 if (m_freezeCount
) return;
3427 // TODO: this is awfully inefficient, we should keep the list of all
3428 // selected items internally, should be much faster
3430 RefreshSelectedUnder(m_anchor
);
3433 void wxGenericTreeCtrl::RefreshSelectedUnder(wxGenericTreeItem
*item
)
3435 if (m_freezeCount
) return;
3437 if ( item
->IsSelected() )
3440 const wxArrayGenericTreeItems
& children
= item
->GetChildren();
3441 size_t count
= children
.GetCount();
3442 for ( size_t n
= 0; n
< count
; n
++ )
3444 RefreshSelectedUnder(children
[n
]);
3448 void wxGenericTreeCtrl::Freeze()
3453 void wxGenericTreeCtrl::Thaw()
3455 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen tree control?") );
3457 if ( !--m_freezeCount
)
3463 // ----------------------------------------------------------------------------
3464 // changing colours: we need to refresh the tree control
3465 // ----------------------------------------------------------------------------
3467 bool wxGenericTreeCtrl::SetBackgroundColour(const wxColour
& colour
)
3469 if ( !wxWindow::SetBackgroundColour(colour
) )
3472 if (m_freezeCount
) return true;
3479 bool wxGenericTreeCtrl::SetForegroundColour(const wxColour
& colour
)
3481 if ( !wxWindow::SetForegroundColour(colour
) )
3484 if (m_freezeCount
) return true;
3491 // Process the tooltip event, to speed up event processing.
3492 // Doesn't actually get a tooltip.
3493 void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent
&event
)
3499 wxSize
wxGenericTreeCtrl::DoGetBestSize() const
3501 // something is better than nothing...
3502 // 100x80 is what the MSW version will get from the default
3503 // wxControl::DoGetBestSize
3504 return wxSize(100,80);
3508 // NOTE: If using the wxListBox visual attributes works everywhere then this can
3509 // be removed, as well as the #else case below.
3510 #define _USE_VISATTR 0
3513 #include "wx/listbox.h"
3519 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
3521 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3525 // Use the same color scheme as wxListBox
3526 return wxListBox::GetClassDefaultAttributes(variant
);
3528 wxVisualAttributes attr
;
3529 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
3530 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
3531 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
3536 #endif // wxUSE_TREECTRL