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
);
539 if (child
== tree
->m_select_me
)
540 tree
->m_select_me
= NULL
;
547 void wxGenericTreeItem::SetText( const wxString
&text
)
552 size_t wxGenericTreeItem::GetChildrenCount(bool recursively
) const
554 size_t count
= m_children
.Count();
558 size_t total
= count
;
559 for (size_t n
= 0; n
< count
; ++n
)
561 total
+= m_children
[n
]->GetChildrenCount();
567 void wxGenericTreeItem::GetSize( int &x
, int &y
,
568 const wxGenericTreeCtrl
*theButton
)
570 int bottomY
=m_y
+theButton
->GetLineHeight(this);
571 if ( y
< bottomY
) y
= bottomY
;
572 int width
= m_x
+ m_width
;
573 if ( x
< width
) x
= width
;
577 size_t count
= m_children
.Count();
578 for ( size_t n
= 0; n
< count
; ++n
)
580 m_children
[n
]->GetSize( x
, y
, theButton
);
585 wxGenericTreeItem
*wxGenericTreeItem::HitTest(const wxPoint
& point
,
586 const wxGenericTreeCtrl
*theCtrl
,
590 // for a hidden root node, don't evaluate it, but do evaluate children
591 if ( !(level
== 0 && theCtrl
->HasFlag(wxTR_HIDE_ROOT
)) )
594 int h
= theCtrl
->GetLineHeight(this);
595 if ((point
.y
> m_y
) && (point
.y
< m_y
+ h
))
597 int y_mid
= m_y
+ h
/2;
598 if (point
.y
< y_mid
)
599 flags
|= wxTREE_HITTEST_ONITEMUPPERPART
;
601 flags
|= wxTREE_HITTEST_ONITEMLOWERPART
;
603 int xCross
= m_x
- theCtrl
->GetSpacing();
605 // according to the drawing code the triangels are drawn
606 // at -4 , -4 from the position up to +10/+10 max
607 if ((point
.x
> xCross
-4) && (point
.x
< xCross
+10) &&
608 (point
.y
> y_mid
-4) && (point
.y
< y_mid
+10) &&
609 HasPlus() && theCtrl
->HasButtons() )
611 // 5 is the size of the plus sign
612 if ((point
.x
> xCross
-6) && (point
.x
< xCross
+6) &&
613 (point
.y
> y_mid
-6) && (point
.y
< y_mid
+6) &&
614 HasPlus() && theCtrl
->HasButtons() )
617 flags
|= wxTREE_HITTEST_ONITEMBUTTON
;
621 if ((point
.x
>= m_x
) && (point
.x
<= m_x
+m_width
))
626 // assuming every image (normal and selected) has the same size!
627 if ( (GetImage() != NO_IMAGE
) && theCtrl
->m_imageListNormal
)
628 theCtrl
->m_imageListNormal
->GetSize(GetImage(),
631 if ((image_w
!= -1) && (point
.x
<= m_x
+ image_w
+ 1))
632 flags
|= wxTREE_HITTEST_ONITEMICON
;
634 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
640 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
641 if (point
.x
> m_x
+m_width
)
642 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
647 // if children are expanded, fall through to evaluate them
648 if (m_isCollapsed
) return (wxGenericTreeItem
*) NULL
;
652 size_t count
= m_children
.Count();
653 for ( size_t n
= 0; n
< count
; n
++ )
655 wxGenericTreeItem
*res
= m_children
[n
]->HitTest( point
,
663 return (wxGenericTreeItem
*) NULL
;
666 int wxGenericTreeItem::GetCurrentImage() const
668 int image
= NO_IMAGE
;
673 image
= GetImage(wxTreeItemIcon_SelectedExpanded
);
676 if ( image
== NO_IMAGE
)
678 // we usually fall back to the normal item, but try just the
679 // expanded one (and not selected) first in this case
680 image
= GetImage(wxTreeItemIcon_Expanded
);
686 image
= GetImage(wxTreeItemIcon_Selected
);
689 // maybe it doesn't have the specific image we want,
690 // try the default one instead
691 if ( image
== NO_IMAGE
) image
= GetImage();
696 // -----------------------------------------------------------------------------
697 // wxGenericTreeCtrl implementation
698 // -----------------------------------------------------------------------------
700 IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl
, wxScrolledWindow
)
702 BEGIN_EVENT_TABLE(wxGenericTreeCtrl
,wxScrolledWindow
)
703 EVT_PAINT (wxGenericTreeCtrl::OnPaint
)
704 EVT_MOUSE_EVENTS (wxGenericTreeCtrl::OnMouse
)
705 EVT_CHAR (wxGenericTreeCtrl::OnChar
)
706 EVT_SET_FOCUS (wxGenericTreeCtrl::OnSetFocus
)
707 EVT_KILL_FOCUS (wxGenericTreeCtrl::OnKillFocus
)
708 EVT_TREE_ITEM_GETTOOLTIP(wxID_ANY
, wxGenericTreeCtrl::OnGetToolTip
)
711 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
713 * wxTreeCtrl has to be a real class or we have problems with
714 * the run-time information.
717 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxGenericTreeCtrl
)
720 // -----------------------------------------------------------------------------
721 // construction/destruction
722 // -----------------------------------------------------------------------------
724 void wxGenericTreeCtrl::Init()
726 m_current
= m_key_current
= m_anchor
= m_select_me
= (wxGenericTreeItem
*) NULL
;
734 m_hilightBrush
= new wxBrush
736 wxSystemSettings::GetColour
738 wxSYS_COLOUR_HIGHLIGHT
743 m_hilightUnfocusedBrush
= new wxBrush
745 wxSystemSettings::GetColour
747 wxSYS_COLOUR_BTNSHADOW
752 m_imageListNormal
= m_imageListButtons
=
753 m_imageListState
= (wxImageList
*) NULL
;
754 m_ownsImageListNormal
= m_ownsImageListButtons
=
755 m_ownsImageListState
= false;
758 m_isDragging
= false;
759 m_dropTarget
= m_oldSelection
= NULL
;
763 m_renameTimer
= NULL
;
768 m_lastOnSame
= false;
770 #ifdef __WXMAC_CARBON__
771 m_normalFont
.MacCreateThemeFont( kThemeViewsFont
) ;
773 m_normalFont
= wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT
);
775 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
776 m_normalFont
.GetFamily(),
777 m_normalFont
.GetStyle(),
779 m_normalFont
.GetUnderlined(),
780 m_normalFont
.GetFaceName(),
781 m_normalFont
.GetEncoding());
784 bool wxGenericTreeCtrl::Create(wxWindow
*parent
,
789 const wxValidator
& wxVALIDATOR_PARAM(validator
),
790 const wxString
& name
)
794 wxGetOsVersion( &major
, &minor
);
796 style
&= ~wxTR_LINES_AT_ROOT
;
797 style
|= wxTR_NO_LINES
;
799 style
|= wxTR_ROW_LINES
;
802 wxScrolledWindow::Create( parent
, id
, pos
, size
,
803 style
|wxHSCROLL
|wxVSCROLL
, name
);
805 // If the tree display has no buttons, but does have
806 // connecting lines, we can use a narrower layout.
807 // It may not be a good idea to force this...
808 if (!HasButtons() && !HasFlag(wxTR_NO_LINES
))
815 SetValidator( validator
);
818 wxVisualAttributes attr
= GetDefaultAttributes();
819 SetOwnForegroundColour( attr
.colFg
);
820 SetOwnBackgroundColour( attr
.colBg
);
822 SetOwnFont(attr
.font
);
824 // m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86
825 m_dottedPen
= wxPen( wxT("grey"), 0, 0 );
832 wxGenericTreeCtrl::~wxGenericTreeCtrl()
834 delete m_hilightBrush
;
835 delete m_hilightUnfocusedBrush
;
839 delete m_renameTimer
;
842 if (m_ownsImageListNormal
)
843 delete m_imageListNormal
;
844 if (m_ownsImageListState
)
845 delete m_imageListState
;
846 if (m_ownsImageListButtons
)
847 delete m_imageListButtons
;
850 // -----------------------------------------------------------------------------
852 // -----------------------------------------------------------------------------
854 size_t wxGenericTreeCtrl::GetCount() const
862 size_t count
= m_anchor
->GetChildrenCount();
863 if ( !HasFlag(wxTR_HIDE_ROOT
) )
865 // take the root itself into account
872 void wxGenericTreeCtrl::SetIndent(unsigned int indent
)
874 m_indent
= (unsigned short) indent
;
878 void wxGenericTreeCtrl::SetSpacing(unsigned int spacing
)
880 m_spacing
= (unsigned short) spacing
;
885 wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
,
886 bool recursively
) const
888 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
890 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
893 void wxGenericTreeCtrl::SetWindowStyle(const long styles
)
895 if (!HasFlag(wxTR_HIDE_ROOT
) && (styles
& wxTR_HIDE_ROOT
))
897 // if we will hide the root, make sure children are visible
898 m_anchor
->SetHasPlus();
900 CalculatePositions();
903 // right now, just sets the styles. Eventually, we may
904 // want to update the inherited styles, but right now
905 // none of the parents has updatable styles
906 m_windowStyle
= styles
;
910 // -----------------------------------------------------------------------------
911 // functions to work with tree items
912 // -----------------------------------------------------------------------------
914 wxString
wxGenericTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
916 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
918 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetText();
921 int wxGenericTreeCtrl::GetItemImage(const wxTreeItemId
& item
,
922 wxTreeItemIcon which
) const
924 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
926 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetImage(which
);
929 wxTreeItemData
*wxGenericTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
931 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
933 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetData();
936 wxColour
wxGenericTreeCtrl::GetItemTextColour(const wxTreeItemId
& item
) const
938 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
940 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
941 return pItem
->Attr().GetTextColour();
944 wxColour
wxGenericTreeCtrl::GetItemBackgroundColour(const wxTreeItemId
& item
) const
946 wxCHECK_MSG( item
.IsOk(), wxNullColour
, wxT("invalid tree item") );
948 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
949 return pItem
->Attr().GetBackgroundColour();
952 wxFont
wxGenericTreeCtrl::GetItemFont(const wxTreeItemId
& item
) const
954 wxCHECK_MSG( item
.IsOk(), wxNullFont
, wxT("invalid tree item") );
956 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
957 return pItem
->Attr().GetFont();
960 void wxGenericTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
962 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
965 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
966 pItem
->SetText(text
);
967 CalculateSize(pItem
, dc
);
971 void wxGenericTreeCtrl::SetItemImage(const wxTreeItemId
& item
,
973 wxTreeItemIcon which
)
975 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
977 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
978 pItem
->SetImage(image
, which
);
981 CalculateSize(pItem
, dc
);
985 void wxGenericTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
987 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
992 ((wxGenericTreeItem
*) item
.m_pItem
)->SetData(data
);
995 void wxGenericTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
997 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
999 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1000 pItem
->SetHasPlus(has
);
1004 void wxGenericTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
1006 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1008 // avoid redrawing the tree if no real change
1009 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1010 if ( pItem
->IsBold() != bold
)
1012 pItem
->SetBold(bold
);
1017 void wxGenericTreeCtrl::SetItemTextColour(const wxTreeItemId
& item
,
1018 const wxColour
& col
)
1020 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1022 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1023 pItem
->Attr().SetTextColour(col
);
1027 void wxGenericTreeCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
1028 const wxColour
& col
)
1030 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1032 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1033 pItem
->Attr().SetBackgroundColour(col
);
1037 void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
)
1039 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1041 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1042 pItem
->Attr().SetFont(font
);
1046 bool wxGenericTreeCtrl::SetFont( const wxFont
&font
)
1048 wxScrolledWindow::SetFont(font
);
1050 m_normalFont
= font
;
1051 m_boldFont
= wxFont(m_normalFont
.GetPointSize(),
1052 m_normalFont
.GetFamily(),
1053 m_normalFont
.GetStyle(),
1055 m_normalFont
.GetUnderlined(),
1056 m_normalFont
.GetFaceName(),
1057 m_normalFont
.GetEncoding());
1063 // -----------------------------------------------------------------------------
1064 // item status inquiries
1065 // -----------------------------------------------------------------------------
1067 bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
1069 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1071 // An item is only visible if it's not a descendant of a collapsed item
1072 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
1073 wxGenericTreeItem
* parent
= pItem
->GetParent();
1076 if (!parent
->IsExpanded())
1078 parent
= parent
->GetParent();
1082 GetViewStart(& startX
, & startY
);
1084 wxSize clientSize
= GetClientSize();
1087 if (!GetBoundingRect(item
, rect
))
1089 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
1091 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
1093 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
1099 bool wxGenericTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
1101 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1103 // consider that the item does have children if it has the "+" button: it
1104 // might not have them (if it had never been expanded yet) but then it
1105 // could have them as well and it's better to err on this side rather than
1106 // disabling some operations which are restricted to the items with
1107 // children for an item which does have them
1108 return ((wxGenericTreeItem
*) item
.m_pItem
)->HasPlus();
1111 bool wxGenericTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
1113 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1115 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsExpanded();
1118 bool wxGenericTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
1120 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1122 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsSelected();
1125 bool wxGenericTreeCtrl::IsBold(const wxTreeItemId
& item
) const
1127 wxCHECK_MSG( item
.IsOk(), false, wxT("invalid tree item") );
1129 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsBold();
1132 // -----------------------------------------------------------------------------
1134 // -----------------------------------------------------------------------------
1136 wxTreeItemId
wxGenericTreeCtrl::GetItemParent(const wxTreeItemId
& item
) const
1138 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1140 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetParent();
1143 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1144 wxTreeItemIdValue
& cookie
) const
1146 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1149 return GetNextChild(item
, cookie
);
1152 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1153 wxTreeItemIdValue
& cookie
) const
1155 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1157 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1159 // it's ok to cast cookie to size_t, we never have indices big enough to
1160 // overflow "void *"
1161 size_t *pIndex
= (size_t *)&cookie
;
1162 if ( *pIndex
< children
.Count() )
1164 return children
.Item((*pIndex
)++);
1168 // there are no more of them
1169 return wxTreeItemId();
1173 #if WXWIN_COMPATIBILITY_2_4
1175 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
,
1178 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1181 return GetNextChild(item
, cookie
);
1184 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
,
1187 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1189 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1190 if ( (size_t)cookie
< children
.Count() )
1192 return children
.Item((size_t)cookie
++);
1196 // there are no more of them
1197 return wxTreeItemId();
1201 #endif // WXWIN_COMPATIBILITY_2_4
1203 wxTreeItemId
wxGenericTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
1205 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1207 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
1208 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
1211 wxTreeItemId
wxGenericTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
1213 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1215 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1216 wxGenericTreeItem
*parent
= i
->GetParent();
1217 if ( parent
== NULL
)
1219 // root item doesn't have any siblings
1220 return wxTreeItemId();
1223 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1224 int index
= siblings
.Index(i
);
1225 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1227 size_t n
= (size_t)(index
+ 1);
1228 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
1231 wxTreeItemId
wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
1233 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1235 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1236 wxGenericTreeItem
*parent
= i
->GetParent();
1237 if ( parent
== NULL
)
1239 // root item doesn't have any siblings
1240 return wxTreeItemId();
1243 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
1244 int index
= siblings
.Index(i
);
1245 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1247 return index
== 0 ? wxTreeItemId()
1248 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
1251 // Only for internal use right now, but should probably be public
1252 wxTreeItemId
wxGenericTreeCtrl::GetNext(const wxTreeItemId
& item
) const
1254 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1256 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1258 // First see if there are any children.
1259 wxArrayGenericTreeItems
& children
= i
->GetChildren();
1260 if (children
.GetCount() > 0)
1262 return children
.Item(0);
1266 // Try a sibling of this or ancestor instead
1267 wxTreeItemId p
= item
;
1268 wxTreeItemId toFind
;
1271 toFind
= GetNextSibling(p
);
1272 p
= GetItemParent(p
);
1273 } while (p
.IsOk() && !toFind
.IsOk());
1278 wxTreeItemId
wxGenericTreeCtrl::GetFirstVisibleItem() const
1280 wxTreeItemId id
= GetRootItem();
1289 } while (id
.IsOk());
1291 return wxTreeItemId();
1294 wxTreeItemId
wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
1296 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1298 wxTreeItemId id
= item
;
1301 while (id
= GetNext(id
), id
.IsOk())
1307 return wxTreeItemId();
1310 wxTreeItemId
wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
1312 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1314 wxFAIL_MSG(wxT("not implemented"));
1316 return wxTreeItemId();
1319 // called by wxTextTreeCtrl when it marks itself for deletion
1320 void wxGenericTreeCtrl::ResetTextControl()
1325 // find the first item starting with the given prefix after the given item
1326 wxTreeItemId
wxGenericTreeCtrl::FindItem(const wxTreeItemId
& idParent
,
1327 const wxString
& prefixOrig
) const
1329 // match is case insensitive as this is more convenient to the user: having
1330 // to press Shift-letter to go to the item starting with a capital letter
1331 // would be too bothersome
1332 wxString prefix
= prefixOrig
.Lower();
1334 // determine the starting point: we shouldn't take the current item (this
1335 // allows to switch between two items starting with the same letter just by
1336 // pressing it) but we shouldn't jump to the next one if the user is
1337 // continuing to type as otherwise he might easily skip the item he wanted
1338 wxTreeItemId id
= idParent
;
1339 if ( prefix
.length() == 1 )
1344 // look for the item starting with the given prefix after it
1345 while ( id
.IsOk() && !GetItemText(id
).Lower().StartsWith(prefix
) )
1350 // if we haven't found anything...
1353 // ... wrap to the beginning
1355 if ( HasFlag(wxTR_HIDE_ROOT
) )
1357 // can't select virtual root
1361 // and try all the items (stop when we get to the one we started from)
1362 while ( id
!= idParent
&& !GetItemText(id
).Lower().StartsWith(prefix
) )
1371 // -----------------------------------------------------------------------------
1373 // -----------------------------------------------------------------------------
1375 wxTreeItemId
wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId
& parentId
,
1377 const wxString
& text
,
1378 int image
, int selImage
,
1379 wxTreeItemData
*data
)
1381 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1384 // should we give a warning here?
1385 return AddRoot(text
, image
, selImage
, data
);
1388 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1390 wxGenericTreeItem
*item
=
1391 new wxGenericTreeItem( parent
, text
, image
, selImage
, data
);
1395 data
->m_pItem
= item
;
1398 parent
->Insert( item
, previous
);
1403 wxTreeItemId
wxGenericTreeCtrl::AddRoot(const wxString
& text
,
1404 int image
, int selImage
,
1405 wxTreeItemData
*data
)
1407 wxCHECK_MSG( !m_anchor
, wxTreeItemId(), wxT("tree can have only one root") );
1409 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1411 m_anchor
= new wxGenericTreeItem((wxGenericTreeItem
*)NULL
, text
,
1412 image
, selImage
, data
);
1415 data
->m_pItem
= m_anchor
;
1418 if (HasFlag(wxTR_HIDE_ROOT
))
1420 // if root is hidden, make sure we can navigate
1422 m_anchor
->SetHasPlus();
1424 CalculatePositions();
1427 if (!HasFlag(wxTR_MULTIPLE
))
1429 m_current
= m_key_current
= m_anchor
;
1430 m_current
->SetHilight( true );
1436 wxTreeItemId
wxGenericTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
1437 const wxString
& text
,
1438 int image
, int selImage
,
1439 wxTreeItemData
*data
)
1441 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
1444 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1445 const wxTreeItemId
& idPrevious
,
1446 const wxString
& text
,
1447 int image
, int selImage
,
1448 wxTreeItemData
*data
)
1450 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1453 // should we give a warning here?
1454 return AddRoot(text
, image
, selImage
, data
);
1458 if (idPrevious
.IsOk())
1460 index
= parent
->GetChildren().Index((wxGenericTreeItem
*) idPrevious
.m_pItem
);
1461 wxASSERT_MSG( index
!= wxNOT_FOUND
,
1462 wxT("previous item in wxGenericTreeCtrl::InsertItem() is not a sibling") );
1465 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
1468 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1470 const wxString
& text
,
1471 int image
, int selImage
,
1472 wxTreeItemData
*data
)
1474 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1477 // should we give a warning here?
1478 return AddRoot(text
, image
, selImage
, data
);
1481 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
1484 wxTreeItemId
wxGenericTreeCtrl::AppendItem(const wxTreeItemId
& parentId
,
1485 const wxString
& text
,
1486 int image
, int selImage
,
1487 wxTreeItemData
*data
)
1489 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1492 // should we give a warning here?
1493 return AddRoot(text
, image
, selImage
, data
);
1496 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
1497 image
, selImage
, data
);
1500 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem
*item
)
1502 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, GetId() );
1503 event
.m_item
= item
;
1504 event
.SetEventObject( this );
1505 ProcessEvent( event
);
1508 void wxGenericTreeCtrl::DeleteChildren(const wxTreeItemId
& itemId
)
1510 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1512 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1513 item
->DeleteChildren(this);
1516 void wxGenericTreeCtrl::Delete(const wxTreeItemId
& itemId
)
1518 m_dirty
= true; // do this first so stuff below doesn't cause flicker
1520 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1524 // can't delete the item being edited, cancel editing it first
1525 m_textCtrl
->StopEditing(item
);
1528 wxGenericTreeItem
*parent
= item
->GetParent();
1530 // don't keep stale pointers around!
1531 if ( IsDescendantOf(item
, m_key_current
) )
1533 // Don't silently change the selection:
1534 // do it properly in idle time, so event
1535 // handlers get called.
1537 // m_key_current = parent;
1538 m_key_current
= NULL
;
1541 // m_select_me records whether we need to select
1542 // a different item, in idle time.
1543 if ( m_select_me
&& IsDescendantOf(item
, m_select_me
) )
1545 m_select_me
= parent
;
1548 if ( IsDescendantOf(item
, m_current
) )
1550 // Don't silently change the selection:
1551 // do it properly in idle time, so event
1552 // handlers get called.
1554 // m_current = parent;
1556 m_select_me
= parent
;
1559 // remove the item from the tree
1562 parent
->GetChildren().Remove( item
); // remove by value
1564 else // deleting the root
1566 // nothing will be left in the tree
1570 // and delete all of its children and the item itself now
1571 item
->DeleteChildren(this);
1572 SendDeleteEvent(item
);
1574 if (item
== m_select_me
)
1580 void wxGenericTreeCtrl::DeleteAllItems()
1588 void wxGenericTreeCtrl::Expand(const wxTreeItemId
& itemId
)
1590 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1592 wxCHECK_RET( item
, _T("invalid item in wxGenericTreeCtrl::Expand") );
1593 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1594 _T("can't expand hidden root") );
1596 if ( !item
->HasPlus() )
1599 if ( item
->IsExpanded() )
1602 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, GetId() );
1603 event
.m_item
= item
;
1604 event
.SetEventObject( this );
1606 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1608 // cancelled by program
1613 CalculatePositions();
1615 RefreshSubtree(item
);
1617 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
1618 ProcessEvent( event
);
1621 void wxGenericTreeCtrl::ExpandAll(const wxTreeItemId
& item
)
1623 if ( !HasFlag(wxTR_HIDE_ROOT
) || item
!= GetRootItem())
1626 if ( !IsExpanded(item
) )
1630 wxTreeItemIdValue cookie
;
1631 wxTreeItemId child
= GetFirstChild(item
, cookie
);
1632 while ( child
.IsOk() )
1636 child
= GetNextChild(item
, cookie
);
1640 void wxGenericTreeCtrl::Collapse(const wxTreeItemId
& itemId
)
1642 wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT
) || itemId
!= GetRootItem(),
1643 _T("can't collapse hidden root") );
1645 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1647 if ( !item
->IsExpanded() )
1650 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, GetId() );
1651 event
.m_item
= item
;
1652 event
.SetEventObject( this );
1653 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1655 // cancelled by program
1661 #if 0 // TODO why should items be collapsed recursively?
1662 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1663 size_t count
= children
.Count();
1664 for ( size_t n
= 0; n
< count
; n
++ )
1666 Collapse(children
[n
]);
1670 CalculatePositions();
1672 RefreshSubtree(item
);
1674 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
1675 ProcessEvent( event
);
1678 void wxGenericTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
1681 DeleteChildren(item
);
1684 void wxGenericTreeCtrl::Toggle(const wxTreeItemId
& itemId
)
1686 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1688 if (item
->IsExpanded())
1694 void wxGenericTreeCtrl::Unselect()
1698 m_current
->SetHilight( false );
1699 RefreshLine( m_current
);
1706 void wxGenericTreeCtrl::UnselectAllChildren(wxGenericTreeItem
*item
)
1708 if (item
->IsSelected())
1710 item
->SetHilight(false);
1714 if (item
->HasChildren())
1716 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1717 size_t count
= children
.Count();
1718 for ( size_t n
= 0; n
< count
; ++n
)
1720 UnselectAllChildren(children
[n
]);
1725 void wxGenericTreeCtrl::UnselectAll()
1727 wxTreeItemId rootItem
= GetRootItem();
1729 // the tree might not have the root item at all
1732 UnselectAllChildren((wxGenericTreeItem
*) rootItem
.m_pItem
);
1736 // Recursive function !
1737 // To stop we must have crt_item<last_item
1739 // Tag all next children, when no more children,
1740 // Move to parent (not to tag)
1741 // Keep going... if we found last_item, we stop.
1742 bool wxGenericTreeCtrl::TagNextChildren(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1744 wxGenericTreeItem
*parent
= crt_item
->GetParent();
1746 if (parent
== NULL
) // This is root item
1747 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
1749 wxArrayGenericTreeItems
& children
= parent
->GetChildren();
1750 int index
= children
.Index(crt_item
);
1751 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1753 size_t count
= children
.Count();
1754 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
1756 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return true;
1759 return TagNextChildren(parent
, last_item
, select
);
1762 bool wxGenericTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1764 crt_item
->SetHilight(select
);
1765 RefreshLine(crt_item
);
1767 if (crt_item
==last_item
)
1770 if (crt_item
->HasChildren())
1772 wxArrayGenericTreeItems
& children
= crt_item
->GetChildren();
1773 size_t count
= children
.Count();
1774 for ( size_t n
= 0; n
< count
; ++n
)
1776 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
1784 void wxGenericTreeCtrl::SelectItemRange(wxGenericTreeItem
*item1
, wxGenericTreeItem
*item2
)
1788 // item2 is not necessary after item1
1789 // choice first' and 'last' between item1 and item2
1790 wxGenericTreeItem
*first
= (item1
->GetY()<item2
->GetY()) ? item1
: item2
;
1791 wxGenericTreeItem
*last
= (item1
->GetY()<item2
->GetY()) ? item2
: item1
;
1793 bool select
= m_current
->IsSelected();
1795 if ( TagAllChildrenUntilLast(first
,last
,select
) )
1798 TagNextChildren(first
,last
,select
);
1801 void wxGenericTreeCtrl::DoSelectItem(const wxTreeItemId
& itemId
,
1802 bool unselect_others
,
1803 bool extended_select
)
1805 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
1809 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
1810 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1812 //wxCHECK_RET( ( (!unselect_others) && is_single),
1813 // wxT("this is a single selection tree") );
1815 // to keep going anyhow !!!
1818 if (item
->IsSelected())
1819 return; // nothing to do
1820 unselect_others
= true;
1821 extended_select
= false;
1823 else if ( unselect_others
&& item
->IsSelected() )
1825 // selection change if there is more than one item currently selected
1826 wxArrayTreeItemIds selected_items
;
1827 if ( GetSelections(selected_items
) == 1 )
1831 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, GetId() );
1832 event
.m_item
= item
;
1833 event
.m_itemOld
= m_current
;
1834 event
.SetEventObject( this );
1835 // TODO : Here we don't send any selection mode yet !
1837 if ( GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed() )
1840 wxTreeItemId parent
= GetItemParent( itemId
);
1841 while (parent
.IsOk())
1843 if (!IsExpanded(parent
))
1846 parent
= GetItemParent( parent
);
1849 EnsureVisible( itemId
);
1852 if (unselect_others
)
1854 if (is_single
) Unselect(); // to speed up thing
1859 if (extended_select
)
1863 m_current
= m_key_current
= (wxGenericTreeItem
*) GetRootItem().m_pItem
;
1866 // don't change the mark (m_current)
1867 SelectItemRange(m_current
, item
);
1871 bool select
= true; // the default
1873 // Check if we need to toggle hilight (ctrl mode)
1874 if (!unselect_others
)
1875 select
=!item
->IsSelected();
1877 m_current
= m_key_current
= item
;
1878 m_current
->SetHilight(select
);
1879 RefreshLine( m_current
);
1882 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
1883 GetEventHandler()->ProcessEvent( event
);
1886 void wxGenericTreeCtrl::SelectItem(const wxTreeItemId
& itemId
, bool select
)
1890 DoSelectItem(itemId
);
1894 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1895 wxCHECK_RET( item
, wxT("SelectItem(): invalid tree item") );
1897 item
->SetHilight(false);
1902 void wxGenericTreeCtrl::FillArray(wxGenericTreeItem
*item
,
1903 wxArrayTreeItemIds
&array
) const
1905 if ( item
->IsSelected() )
1906 array
.Add(wxTreeItemId(item
));
1908 if ( item
->HasChildren() )
1910 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1911 size_t count
= children
.GetCount();
1912 for ( size_t n
= 0; n
< count
; ++n
)
1913 FillArray(children
[n
], array
);
1917 size_t wxGenericTreeCtrl::GetSelections(wxArrayTreeItemIds
&array
) const
1920 wxTreeItemId idRoot
= GetRootItem();
1921 if ( idRoot
.IsOk() )
1923 FillArray((wxGenericTreeItem
*) idRoot
.m_pItem
, array
);
1925 //else: the tree is empty, so no selections
1927 return array
.Count();
1930 void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
1932 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
1934 if (!item
.IsOk()) return;
1936 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1938 // first expand all parent branches
1939 wxGenericTreeItem
*parent
= gitem
->GetParent();
1941 if ( HasFlag(wxTR_HIDE_ROOT
) )
1943 while ( parent
&& parent
!= m_anchor
)
1946 parent
= parent
->GetParent();
1954 parent
= parent
->GetParent();
1958 //if (parent) CalculatePositions();
1963 void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId
&item
)
1965 if (!item
.IsOk()) return;
1967 // We have to call this here because the label in
1968 // question might just have been added and no screen
1969 // update taken place.
1971 #if defined( __WXMSW__ ) || defined(__WXMAC__)
1976 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1978 // now scroll to the item
1979 int item_y
= gitem
->GetY();
1983 GetViewStart( &start_x
, &start_y
);
1984 start_y
*= PIXELS_PER_UNIT
;
1988 GetClientSize( &client_w
, &client_h
);
1990 if (item_y
< start_y
+3)
1995 m_anchor
->GetSize( x
, y
, this );
1996 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1997 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1998 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1999 // Item should appear at top
2000 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
2002 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
2007 m_anchor
->GetSize( x
, y
, this );
2008 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2009 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2010 item_y
+= PIXELS_PER_UNIT
+2;
2011 int x_pos
= GetScrollPos( wxHORIZONTAL
);
2012 // Item should appear at bottom
2013 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
);
2017 // FIXME: tree sorting functions are not reentrant and not MT-safe!
2018 static wxGenericTreeCtrl
*s_treeBeingSorted
= NULL
;
2020 static int LINKAGEMODE
tree_ctrl_compare_func(wxGenericTreeItem
**item1
,
2021 wxGenericTreeItem
**item2
)
2023 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxGenericTreeCtrl::SortChildren()") );
2025 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
2028 int wxGenericTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
2029 const wxTreeItemId
& item2
)
2031 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
2034 void wxGenericTreeCtrl::SortChildren(const wxTreeItemId
& itemId
)
2036 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
2038 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
2040 wxCHECK_RET( !s_treeBeingSorted
,
2041 wxT("wxGenericTreeCtrl::SortChildren is not reentrant") );
2043 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2044 if ( children
.Count() > 1 )
2048 s_treeBeingSorted
= this;
2049 children
.Sort(tree_ctrl_compare_func
);
2050 s_treeBeingSorted
= NULL
;
2052 //else: don't make the tree dirty as nothing changed
2055 wxImageList
*wxGenericTreeCtrl::GetImageList() const
2057 return m_imageListNormal
;
2060 wxImageList
*wxGenericTreeCtrl::GetButtonsImageList() const
2062 return m_imageListButtons
;
2065 wxImageList
*wxGenericTreeCtrl::GetStateImageList() const
2067 return m_imageListState
;
2070 void wxGenericTreeCtrl::CalculateLineHeight()
2072 wxClientDC
dc(this);
2073 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
2075 if ( m_imageListNormal
)
2077 // Calculate a m_lineHeight value from the normal Image sizes.
2078 // May be toggle off. Then wxGenericTreeCtrl will spread when
2079 // necessary (which might look ugly).
2080 int n
= m_imageListNormal
->GetImageCount();
2081 for (int i
= 0; i
< n
; i
++)
2083 int width
= 0, height
= 0;
2084 m_imageListNormal
->GetSize(i
, width
, height
);
2085 if (height
> m_lineHeight
) m_lineHeight
= height
;
2089 if (m_imageListButtons
)
2091 // Calculate a m_lineHeight value from the Button image sizes.
2092 // May be toggle off. Then wxGenericTreeCtrl will spread when
2093 // necessary (which might look ugly).
2094 int n
= m_imageListButtons
->GetImageCount();
2095 for (int i
= 0; i
< n
; i
++)
2097 int width
= 0, height
= 0;
2098 m_imageListButtons
->GetSize(i
, width
, height
);
2099 if (height
> m_lineHeight
) m_lineHeight
= height
;
2103 if (m_lineHeight
< 30)
2104 m_lineHeight
+= 2; // at least 2 pixels
2106 m_lineHeight
+= m_lineHeight
/10; // otherwise 10% extra spacing
2109 void wxGenericTreeCtrl::SetImageList(wxImageList
*imageList
)
2111 if (m_ownsImageListNormal
) delete m_imageListNormal
;
2112 m_imageListNormal
= imageList
;
2113 m_ownsImageListNormal
= false;
2115 // Don't do any drawing if we're setting the list to NULL,
2116 // since we may be in the process of deleting the tree control.
2118 CalculateLineHeight();
2121 void wxGenericTreeCtrl::SetStateImageList(wxImageList
*imageList
)
2123 if (m_ownsImageListState
) delete m_imageListState
;
2124 m_imageListState
= imageList
;
2125 m_ownsImageListState
= false;
2128 void wxGenericTreeCtrl::SetButtonsImageList(wxImageList
*imageList
)
2130 if (m_ownsImageListButtons
) delete m_imageListButtons
;
2131 m_imageListButtons
= imageList
;
2132 m_ownsImageListButtons
= false;
2134 CalculateLineHeight();
2137 void wxGenericTreeCtrl::AssignImageList(wxImageList
*imageList
)
2139 SetImageList(imageList
);
2140 m_ownsImageListNormal
= true;
2143 void wxGenericTreeCtrl::AssignStateImageList(wxImageList
*imageList
)
2145 SetStateImageList(imageList
);
2146 m_ownsImageListState
= true;
2149 void wxGenericTreeCtrl::AssignButtonsImageList(wxImageList
*imageList
)
2151 SetButtonsImageList(imageList
);
2152 m_ownsImageListButtons
= true;
2155 // -----------------------------------------------------------------------------
2157 // -----------------------------------------------------------------------------
2159 void wxGenericTreeCtrl::AdjustMyScrollbars()
2164 m_anchor
->GetSize( x
, y
, this );
2165 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2166 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
2167 int x_pos
= GetScrollPos( wxHORIZONTAL
);
2168 int y_pos
= GetScrollPos( wxVERTICAL
);
2169 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
2173 SetScrollbars( 0, 0, 0, 0 );
2177 int wxGenericTreeCtrl::GetLineHeight(wxGenericTreeItem
*item
) const
2179 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
2180 return item
->GetHeight();
2182 return m_lineHeight
;
2185 void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem
*item
, wxDC
& dc
)
2187 // TODO implement "state" icon on items
2189 wxTreeItemAttr
*attr
= item
->GetAttributes();
2190 if ( attr
&& attr
->HasFont() )
2191 dc
.SetFont(attr
->GetFont());
2192 else if (item
->IsBold())
2193 dc
.SetFont(m_boldFont
);
2195 long text_w
= 0, text_h
= 0;
2196 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
2198 int image_h
= 0, image_w
= 0;
2199 int image
= item
->GetCurrentImage();
2200 if ( image
!= NO_IMAGE
)
2202 if ( m_imageListNormal
)
2204 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
2213 int total_h
= GetLineHeight(item
);
2215 if ( item
->IsSelected() )
2217 // under mac selections are only a rectangle in case they don't have the focus
2221 dc
.SetBrush( *wxTRANSPARENT_BRUSH
) ;
2222 dc
.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT
) , 1 , wxSOLID
) ) ;
2226 dc
.SetBrush( *m_hilightBrush
) ;
2229 dc
.SetBrush(*(m_hasFocus
? m_hilightBrush
: m_hilightUnfocusedBrush
));
2235 if ( attr
&& attr
->HasBackgroundColour() )
2236 colBg
= attr
->GetBackgroundColour();
2238 colBg
= m_backgroundColour
;
2239 dc
.SetBrush(wxBrush(colBg
, wxSOLID
));
2242 int offset
= HasFlag(wxTR_ROW_LINES
) ? 1 : 0;
2244 if ( HasFlag(wxTR_FULL_ROW_HIGHLIGHT
) )
2248 DoGetPosition(&x
, &y
);
2250 dc
.DrawRectangle(x
, item
->GetY()+offset
, w
, total_h
-offset
);
2254 if ( item
->IsSelected() && image
!= NO_IMAGE
)
2256 // If it's selected, and there's an image, then we should
2257 // take care to leave the area under the image painted in the
2258 // background colour.
2259 dc
.DrawRectangle( item
->GetX() + image_w
- 2, item
->GetY()+offset
,
2260 item
->GetWidth() - image_w
+ 2, total_h
-offset
);
2264 dc
.DrawRectangle( item
->GetX()-2, item
->GetY()+offset
,
2265 item
->GetWidth()+2, total_h
-offset
);
2269 if ( image
!= NO_IMAGE
)
2271 dc
.SetClippingRegion( item
->GetX(), item
->GetY(), image_w
-2, total_h
);
2272 m_imageListNormal
->Draw( image
, dc
,
2274 item
->GetY() +((total_h
> image_h
)?((total_h
-image_h
)/2):0),
2275 wxIMAGELIST_DRAW_TRANSPARENT
);
2276 dc
.DestroyClippingRegion();
2279 dc
.SetBackgroundMode(wxTRANSPARENT
);
2280 int extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
2281 dc
.DrawText( item
->GetText(),
2282 (wxCoord
)(image_w
+ item
->GetX()),
2283 (wxCoord
)(item
->GetY() + extraH
));
2285 // restore normal font
2286 dc
.SetFont( m_normalFont
);
2289 // Now y stands for the top of the item, whereas it used to stand for middle !
2290 void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
2292 int x
= level
*m_indent
;
2293 if (!HasFlag(wxTR_HIDE_ROOT
))
2297 else if (level
== 0)
2299 // always expand hidden root
2301 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2302 int count
= children
.Count();
2308 PaintLevel(children
[n
], dc
, 1, y
);
2309 } while (++n
< count
);
2311 if (!HasFlag(wxTR_NO_LINES
) && HasFlag(wxTR_LINES_AT_ROOT
) && count
> 0)
2313 // draw line down to last child
2314 origY
+= GetLineHeight(children
[0])>>1;
2315 oldY
+= GetLineHeight(children
[n
-1])>>1;
2316 dc
.DrawLine(3, origY
, 3, oldY
);
2322 item
->SetX(x
+m_spacing
);
2325 int h
= GetLineHeight(item
);
2327 int y_mid
= y_top
+ (h
>>1);
2330 int exposed_x
= dc
.LogicalToDeviceX(0);
2331 int exposed_y
= dc
.LogicalToDeviceY(y_top
);
2333 if (IsExposed(exposed_x
, exposed_y
, 10000, h
)) // 10000 = very much
2337 // don't draw rect outline if we already have the
2338 // background color under Mac
2339 (item
->IsSelected() && m_hasFocus
) ? wxBLACK_PEN
:
2340 #endif // !__WXMAC__
2344 if ( item
->IsSelected() )
2346 colText
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
2350 wxTreeItemAttr
*attr
= item
->GetAttributes();
2351 if (attr
&& attr
->HasTextColour())
2352 colText
= attr
->GetTextColour();
2354 colText
= GetForegroundColour();
2358 dc
.SetTextForeground(colText
);
2362 PaintItem(item
, dc
);
2364 if (HasFlag(wxTR_ROW_LINES
))
2366 // if the background colour is white, choose a
2367 // contrasting color for the lines
2368 dc
.SetPen(*((GetBackgroundColour() == *wxWHITE
)
2369 ? wxMEDIUM_GREY_PEN
: wxWHITE_PEN
));
2370 dc
.DrawLine(0, y_top
, 10000, y_top
);
2371 dc
.DrawLine(0, y
, 10000, y
);
2374 // restore DC objects
2375 dc
.SetBrush(*wxWHITE_BRUSH
);
2376 dc
.SetPen(m_dottedPen
);
2377 dc
.SetTextForeground(*wxBLACK
);
2379 if ( !HasFlag(wxTR_NO_LINES
) )
2381 // draw the horizontal line here
2383 if (x
> (signed)m_indent
)
2384 x_start
-= m_indent
;
2385 else if (HasFlag(wxTR_LINES_AT_ROOT
))
2387 dc
.DrawLine(x_start
, y_mid
, x
+ m_spacing
, y_mid
);
2390 // should the item show a button?
2391 if ( item
->HasPlus() && HasButtons() )
2393 if ( m_imageListButtons
)
2395 // draw the image button here
2398 int image
= item
->IsExpanded() ? wxTreeItemIcon_Expanded
2399 : wxTreeItemIcon_Normal
;
2400 if ( item
->IsSelected() )
2401 image
+= wxTreeItemIcon_Selected
- wxTreeItemIcon_Normal
;
2403 m_imageListButtons
->GetSize(image
, image_w
, image_h
);
2404 int xx
= x
- image_w
/2;
2405 int yy
= y_mid
- image_h
/2;
2407 wxDCClipper
clip(dc
, xx
, yy
, image_w
, image_h
);
2408 m_imageListButtons
->Draw(image
, dc
, xx
, yy
,
2409 wxIMAGELIST_DRAW_TRANSPARENT
);
2411 else // no custom buttons
2413 static const int wImage
= 9;
2414 static const int hImage
= 9;
2417 if (item
->IsExpanded())
2418 flag
|= wxCONTROL_EXPANDED
;
2419 if (item
== m_underMouse
)
2420 flag
|= wxCONTROL_CURRENT
;
2422 wxRendererNative::Get().DrawTreeItemButton
2426 wxRect(x
- wImage
/2,
2435 if (item
->IsExpanded())
2437 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2438 int count
= children
.Count();
2445 PaintLevel(children
[n
], dc
, level
, y
);
2446 } while (++n
< count
);
2448 if (!HasFlag(wxTR_NO_LINES
) && count
> 0)
2450 // draw line down to last child
2451 oldY
+= GetLineHeight(children
[n
-1])>>1;
2452 if (HasButtons()) y_mid
+= 5;
2454 // Only draw the portion of the line that is visible, in case it is huge
2455 wxCoord xOrigin
=0, yOrigin
=0, width
, height
;
2456 dc
.GetDeviceOrigin(&xOrigin
, &yOrigin
);
2457 yOrigin
= abs(yOrigin
);
2458 GetClientSize(&width
, &height
);
2460 // Move end points to the begining/end of the view?
2461 if (y_mid
< yOrigin
)
2463 if (oldY
> yOrigin
+ height
)
2464 oldY
= yOrigin
+ height
;
2466 // after the adjustments if y_mid is larger than oldY then the line
2467 // isn't visible at all so don't draw anything
2469 dc
.DrawLine(x
, y_mid
, x
, oldY
);
2475 void wxGenericTreeCtrl::DrawDropEffect(wxGenericTreeItem
*item
)
2479 if ( item
->HasPlus() )
2481 // it's a folder, indicate it by a border
2486 // draw a line under the drop target because the item will be
2488 DrawLine(item
, true /* below */);
2491 SetCursor(wxCURSOR_BULLSEYE
);
2496 SetCursor(wxCURSOR_NO_ENTRY
);
2500 void wxGenericTreeCtrl::DrawBorder(const wxTreeItemId
&item
)
2502 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2504 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2506 wxClientDC
dc(this);
2508 dc
.SetLogicalFunction(wxINVERT
);
2509 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2511 int w
= i
->GetWidth() + 2;
2512 int h
= GetLineHeight(i
) + 2;
2514 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
2517 void wxGenericTreeCtrl::DrawLine(const wxTreeItemId
&item
, bool below
)
2519 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
2521 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2523 wxClientDC
dc(this);
2525 dc
.SetLogicalFunction(wxINVERT
);
2531 y
+= GetLineHeight(i
) - 1;
2534 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
2537 // -----------------------------------------------------------------------------
2538 // wxWidgets callbacks
2539 // -----------------------------------------------------------------------------
2541 void wxGenericTreeCtrl::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2549 dc
.SetFont( m_normalFont
);
2550 dc
.SetPen( m_dottedPen
);
2552 // this is now done dynamically
2553 //if(GetImageList() == NULL)
2554 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
2557 PaintLevel( m_anchor
, dc
, 0, y
);
2560 void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent
&event
)
2569 void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent
&event
)
2578 void wxGenericTreeCtrl::OnChar( wxKeyEvent
&event
)
2580 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, GetId() );
2581 te
.m_evtKey
= event
;
2582 te
.SetEventObject( this );
2583 if ( GetEventHandler()->ProcessEvent( te
) )
2585 // intercepted by the user code
2589 if ( (m_current
== 0) || (m_key_current
== 0) )
2595 // how should the selection work for this event?
2596 bool is_multiple
, extended_select
, unselect_others
;
2597 EventFlagsToSelType(GetWindowStyleFlag(),
2599 event
.ControlDown(),
2600 is_multiple
, extended_select
, unselect_others
);
2604 // * : Expand all/Collapse all
2605 // ' ' | return : activate
2606 // up : go up (not last children!)
2608 // left : go to parent
2609 // right : open if parent and go next
2610 // home : go to root
2611 // end : go to last item without opening parents
2612 // alnum : start or continue searching for the item with this prefix
2613 int keyCode
= event
.GetKeyCode();
2618 if (m_current
->HasPlus() && !IsExpanded(m_current
))
2626 if ( !IsExpanded(m_current
) )
2629 ExpandAll(m_current
);
2632 //else: fall through to Collapse() it
2636 if (IsExpanded(m_current
))
2638 Collapse(m_current
);
2644 if ( !event
.HasModifiers() )
2646 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
2647 event
.m_item
= m_current
;
2648 event
.SetEventObject( this );
2649 GetEventHandler()->ProcessEvent( event
);
2652 // in any case, also generate the normal key event for this key,
2653 // even if we generated the ACTIVATED event above: this is what
2654 // wxMSW does and it makes sense because you might not want to
2655 // process ACTIVATED event at all and handle Space and Return
2656 // directly (and differently) which would be impossible otherwise
2660 // up goes to the previous sibling or to the last
2661 // of its children if it's expanded
2664 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
2667 prev
= GetItemParent( m_key_current
);
2668 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2670 break; // don't go to root if it is hidden
2674 wxTreeItemIdValue cookie
;
2675 wxTreeItemId current
= m_key_current
;
2676 // TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be?
2677 if (current
== GetFirstChild( prev
, cookie
))
2679 // otherwise we return to where we came from
2680 DoSelectItem( prev
, unselect_others
, extended_select
);
2681 m_key_current
= (wxGenericTreeItem
*) prev
.m_pItem
;
2688 while ( IsExpanded(prev
) && HasChildren(prev
) )
2690 wxTreeItemId child
= GetLastChild(prev
);
2697 DoSelectItem( prev
, unselect_others
, extended_select
);
2698 m_key_current
=(wxGenericTreeItem
*) prev
.m_pItem
;
2703 // left arrow goes to the parent
2706 wxTreeItemId prev
= GetItemParent( m_current
);
2707 if ((prev
== GetRootItem()) && HasFlag(wxTR_HIDE_ROOT
))
2709 // don't go to root if it is hidden
2710 prev
= GetPrevSibling( m_current
);
2714 DoSelectItem( prev
, unselect_others
, extended_select
);
2720 // this works the same as the down arrow except that we
2721 // also expand the item if it wasn't expanded yet
2727 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
2729 wxTreeItemIdValue cookie
;
2730 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
2731 DoSelectItem( child
, unselect_others
, extended_select
);
2732 m_key_current
=(wxGenericTreeItem
*) child
.m_pItem
;
2736 wxTreeItemId next
= GetNextSibling( m_key_current
);
2739 wxTreeItemId current
= m_key_current
;
2740 while (current
.IsOk() && !next
)
2742 current
= GetItemParent( current
);
2743 if (current
) next
= GetNextSibling( current
);
2748 DoSelectItem( next
, unselect_others
, extended_select
);
2749 m_key_current
=(wxGenericTreeItem
*) next
.m_pItem
;
2755 // <End> selects the last visible tree item
2758 wxTreeItemId last
= GetRootItem();
2760 while ( last
.IsOk() && IsExpanded(last
) )
2762 wxTreeItemId lastChild
= GetLastChild(last
);
2764 // it may happen if the item was expanded but then all of
2765 // its children have been deleted - so IsExpanded() returned
2766 // true, but GetLastChild() returned invalid item
2775 DoSelectItem( last
, unselect_others
, extended_select
);
2780 // <Home> selects the root item
2783 wxTreeItemId prev
= GetRootItem();
2787 if ( HasFlag(wxTR_HIDE_ROOT
) )
2789 wxTreeItemIdValue cookie
;
2790 prev
= GetFirstChild(prev
, cookie
);
2795 DoSelectItem( prev
, unselect_others
, extended_select
);
2800 // do not use wxIsalnum() here
2801 if ( !event
.HasModifiers() &&
2802 ((keyCode
>= '0' && keyCode
<= '9') ||
2803 (keyCode
>= 'a' && keyCode
<= 'z') ||
2804 (keyCode
>= 'A' && keyCode
<= 'Z' )))
2806 // find the next item starting with the given prefix
2807 wxChar ch
= (wxChar
)keyCode
;
2809 wxTreeItemId id
= FindItem(m_current
, m_findPrefix
+ ch
);
2820 // also start the timer to reset the current prefix if the user
2821 // doesn't press any more alnum keys soon -- we wouldn't want
2822 // to use this prefix for a new item search
2825 m_findTimer
= new wxTreeFindTimer(this);
2828 m_findTimer
->Start(wxTreeFindTimer::DELAY
, wxTIMER_ONE_SHOT
);
2837 wxTreeItemId
wxGenericTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
2839 // JACS: removed wxYieldIfNeeded() because it can cause the window
2840 // to be deleted from under us if a close window event is pending
2845 if (point
.x
<0) flags
|= wxTREE_HITTEST_TOLEFT
;
2846 if (point
.x
>w
) flags
|= wxTREE_HITTEST_TORIGHT
;
2847 if (point
.y
<0) flags
|= wxTREE_HITTEST_ABOVE
;
2848 if (point
.y
>h
) flags
|= wxTREE_HITTEST_BELOW
;
2849 if (flags
) return wxTreeItemId();
2851 if (m_anchor
== NULL
)
2853 flags
= wxTREE_HITTEST_NOWHERE
;
2854 return wxTreeItemId();
2857 wxGenericTreeItem
*hit
= m_anchor
->HitTest(CalcUnscrolledPosition(point
),
2861 flags
= wxTREE_HITTEST_NOWHERE
;
2862 return wxTreeItemId();
2867 // get the bounding rectangle of the item (or of its label only)
2868 bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId
& item
,
2870 bool WXUNUSED(textOnly
)) const
2872 wxCHECK_MSG( item
.IsOk(), false, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
2874 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2877 GetViewStart(& startX
, & startY
);
2879 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
2880 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
2881 rect
.width
= i
->GetWidth();
2882 //rect.height = i->GetHeight();
2883 rect
.height
= GetLineHeight(i
);
2888 void wxGenericTreeCtrl::Edit( const wxTreeItemId
& item
)
2890 wxCHECK_RET( item
.IsOk(), _T("can't edit an invalid item") );
2892 wxGenericTreeItem
*itemEdit
= (wxGenericTreeItem
*)item
.m_pItem
;
2894 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, GetId() );
2895 te
.m_item
= itemEdit
;
2896 te
.SetEventObject( this );
2897 if ( GetEventHandler()->ProcessEvent( te
) && !te
.IsAllowed() )
2903 // We have to call this here because the label in
2904 // question might just have been added and no screen
2905 // update taken place.
2907 #if defined( __WXMSW__ ) || defined(__WXMAC__)
2913 m_textCtrl
= new wxTreeTextCtrl(this, itemEdit
);
2915 m_textCtrl
->SetFocus();
2918 // returns a pointer to the text edit control if the item is being
2919 // edited, NULL otherwise (it's assumed that no more than one item may
2920 // be edited simultaneously)
2921 wxTextCtrl
* wxGenericTreeCtrl::GetEditControl() const
2926 bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem
*item
,
2927 const wxString
& value
)
2929 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2931 le
.SetEventObject( this );
2933 le
.m_editCancelled
= false;
2935 return !GetEventHandler()->ProcessEvent( le
) || le
.IsAllowed();
2938 void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem
*item
)
2940 // let owner know that the edit was cancelled
2941 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2943 le
.SetEventObject( this );
2944 le
.m_label
= wxEmptyString
;
2945 le
.m_editCancelled
= true;
2947 GetEventHandler()->ProcessEvent( le
);
2950 void wxGenericTreeCtrl::OnRenameTimer()
2955 void wxGenericTreeCtrl::OnMouse( wxMouseEvent
&event
)
2957 if ( !m_anchor
) return;
2959 wxPoint pt
= CalcUnscrolledPosition(event
.GetPosition());
2961 // Is the mouse over a tree item button?
2963 wxGenericTreeItem
*thisItem
= m_anchor
->HitTest(pt
, this, flags
, 0);
2964 wxGenericTreeItem
*underMouse
= thisItem
;
2966 bool underMouseChanged
= (underMouse
!= m_underMouse
) ;
2967 #endif // wxUSE_TOOLTIPS
2970 (flags
& wxTREE_HITTEST_ONITEMBUTTON
) &&
2971 (!event
.LeftIsDown()) &&
2973 (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
2981 if (underMouse
!= m_underMouse
)
2985 // unhighlight old item
2986 wxGenericTreeItem
*tmp
= m_underMouse
;
2987 m_underMouse
= NULL
;
2991 m_underMouse
= underMouse
;
2993 RefreshLine( m_underMouse
);
2997 // Determines what item we are hovering over and need a tooltip for
2998 wxTreeItemId hoverItem
= thisItem
;
3000 // We do not want a tooltip if we are dragging, or if the rename timer is running
3001 if (underMouseChanged
&& hoverItem
.IsOk() && !m_isDragging
&& (!m_renameTimer
|| !m_renameTimer
->IsRunning()))
3003 // Ask the tree control what tooltip (if any) should be shown
3004 wxTreeEvent
hevent(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP
, GetId());
3005 hevent
.m_item
= hoverItem
;
3006 hevent
.SetEventObject(this);
3008 if ( GetEventHandler()->ProcessEvent(hevent
) && hevent
.IsAllowed() )
3010 SetToolTip(hevent
.m_label
);
3015 // we process left mouse up event (enables in-place edit), right down
3016 // (pass to the user code), left dbl click (activate item) and
3017 // dragging/moving events for items drag-and-drop
3018 if ( !(event
.LeftDown() ||
3020 event
.RightDown() ||
3021 event
.LeftDClick() ||
3023 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
3032 wxGenericTreeItem
*item
= m_anchor
->HitTest(pt
, this, flags
, 0);
3034 if ( event
.Dragging() && !m_isDragging
)
3036 if (m_dragCount
== 0)
3041 if (m_dragCount
!= 3)
3043 // wait until user drags a bit further...
3047 wxEventType command
= event
.RightIsDown()
3048 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
3049 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
3051 wxTreeEvent
nevent( command
, GetId() );
3052 nevent
.m_item
= m_current
;
3053 nevent
.SetEventObject(this);
3055 // by default the dragging is not supported, the user code must
3056 // explicitly allow the event for it to take place
3059 if ( GetEventHandler()->ProcessEvent(nevent
) && nevent
.IsAllowed() )
3061 // we're going to drag this item
3062 m_isDragging
= true;
3064 // remember the old cursor because we will change it while
3066 m_oldCursor
= m_cursor
;
3068 // in a single selection control, hide the selection temporarily
3069 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
3071 m_oldSelection
= (wxGenericTreeItem
*) GetSelection().m_pItem
;
3073 if ( m_oldSelection
)
3075 m_oldSelection
->SetHilight(false);
3076 RefreshLine(m_oldSelection
);
3083 else if ( event
.Moving() )
3085 if ( item
!= m_dropTarget
)
3087 // unhighlight the previous drop target
3088 DrawDropEffect(m_dropTarget
);
3090 m_dropTarget
= item
;
3092 // highlight the current drop target if any
3093 DrawDropEffect(m_dropTarget
);
3095 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3102 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
3104 // erase the highlighting
3105 DrawDropEffect(m_dropTarget
);
3107 if ( m_oldSelection
)
3109 m_oldSelection
->SetHilight(true);
3110 RefreshLine(m_oldSelection
);
3111 m_oldSelection
= (wxGenericTreeItem
*)NULL
;
3114 // generate the drag end event
3115 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
, GetId());
3117 event
.m_item
= item
;
3118 event
.m_pointDrag
= pt
;
3119 event
.SetEventObject(this);
3121 (void)GetEventHandler()->ProcessEvent(event
);
3123 m_isDragging
= false;
3124 m_dropTarget
= (wxGenericTreeItem
*)NULL
;
3128 SetCursor(m_oldCursor
);
3130 #if defined( __WXMSW__ ) || defined(__WXMAC__)
3138 // If we got to this point, we are not dragging or moving the mouse.
3139 // Because the code in carbon/toplevel.cpp will only set focus to the tree
3140 // if we skip for EVT_LEFT_DOWN, we MUST skip this event here for focus to work.
3141 // We skip even if we didn't hit an item because we still should
3142 // restore focus to the tree control even if we didn't exactly hit an item.
3143 if ( event
.LeftDown() )
3148 // here we process only the messages which happen on tree items
3152 if (item
== NULL
) return; /* we hit the blank area */
3154 if ( event
.RightDown() )
3156 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
, GetId());
3157 nevent
.m_item
= item
;
3158 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3159 nevent
.SetEventObject(this);
3160 GetEventHandler()->ProcessEvent(nevent
);
3162 else if ( event
.LeftUp() )
3164 // this facilitates multiple-item drag-and-drop
3166 if (item
&& HasFlag(wxTR_MULTIPLE
))
3168 wxArrayTreeItemIds selections
;
3169 size_t count
= GetSelections(selections
);
3172 !event
.ControlDown() &&
3175 DoSelectItem(item
, true, false);
3181 if ( (item
== m_current
) &&
3182 (flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
3183 HasFlag(wxTR_EDIT_LABELS
) )
3185 if ( m_renameTimer
)
3187 if ( m_renameTimer
->IsRunning() )
3188 m_renameTimer
->Stop();
3192 m_renameTimer
= new wxTreeRenameTimer( this );
3195 m_renameTimer
->Start( wxTreeRenameTimer::DELAY
, true );
3198 m_lastOnSame
= false;
3201 else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
3203 if ( event
.LeftDown() )
3205 m_lastOnSame
= item
== m_current
;
3208 if ( flags
& wxTREE_HITTEST_ONITEMBUTTON
)
3210 // only toggle the item for a single click, double click on
3211 // the button doesn't do anything (it toggles the item twice)
3212 if ( event
.LeftDown() )
3217 // don't select the item if the button was clicked
3222 // clear the previously selected items, if the
3223 // user clicked outside of the present selection.
3224 // otherwise, perform the deselection on mouse-up.
3225 // this allows multiple drag and drop to work.
3227 if (!IsSelected(item
))
3229 // how should the selection work for this event?
3230 bool is_multiple
, extended_select
, unselect_others
;
3231 EventFlagsToSelType(GetWindowStyleFlag(),
3233 event
.ControlDown(),
3234 is_multiple
, extended_select
, unselect_others
);
3236 DoSelectItem(item
, unselect_others
, extended_select
);
3240 // For some reason, Windows isn't recognizing a left double-click,
3241 // so we need to simulate it here. Allow 200 milliseconds for now.
3242 if ( event
.LeftDClick() )
3244 // double clicking should not start editing the item label
3245 if ( m_renameTimer
)
3246 m_renameTimer
->Stop();
3248 m_lastOnSame
= false;
3250 // send activate event first
3251 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
3252 nevent
.m_item
= item
;
3253 nevent
.m_pointDrag
= CalcScrolledPosition(pt
);
3254 nevent
.SetEventObject( this );
3255 if ( !GetEventHandler()->ProcessEvent( nevent
) )
3257 // if the user code didn't process the activate event,
3258 // handle it ourselves by toggling the item when it is
3260 if ( item
->HasPlus() )
3270 void wxGenericTreeCtrl::OnInternalIdle()
3272 wxWindow::OnInternalIdle();
3274 // Check if we need to select the root item
3275 // because nothing else has been selected.
3276 // Delaying it means that we can invoke event handlers
3277 // as required, when a first item is selected.
3278 if (!HasFlag(wxTR_MULTIPLE
) && !GetSelection().IsOk())
3281 SelectItem(m_select_me
);
3282 else if (GetRootItem().IsOk())
3283 SelectItem(GetRootItem());
3286 /* after all changes have been done to the tree control,
3287 * we actually redraw the tree when everything is over */
3289 if (!m_dirty
) return;
3290 if (m_freezeCount
) return;
3294 CalculatePositions();
3296 AdjustMyScrollbars();
3299 void wxGenericTreeCtrl::CalculateSize( wxGenericTreeItem
*item
, wxDC
&dc
)
3304 wxTreeItemAttr
*attr
= item
->GetAttributes();
3305 if ( attr
&& attr
->HasFont() )
3306 dc
.SetFont(attr
->GetFont());
3307 else if ( item
->IsBold() )
3308 dc
.SetFont(m_boldFont
);
3310 dc
.SetFont(m_normalFont
);
3312 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
3315 // restore normal font
3316 dc
.SetFont( m_normalFont
);
3320 int image
= item
->GetCurrentImage();
3321 if ( image
!= NO_IMAGE
)
3323 if ( m_imageListNormal
)
3325 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
3330 int total_h
= (image_h
> text_h
) ? image_h
: text_h
;
3333 total_h
+= 2; // at least 2 pixels
3335 total_h
+= total_h
/10; // otherwise 10% extra spacing
3337 item
->SetHeight(total_h
);
3338 if (total_h
>m_lineHeight
)
3339 m_lineHeight
=total_h
;
3341 item
->SetWidth(image_w
+text_w
+2);
3344 // -----------------------------------------------------------------------------
3345 // for developper : y is now the top of the level
3346 // not the middle of it !
3347 void wxGenericTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
3349 int x
= level
*m_indent
;
3350 if (!HasFlag(wxTR_HIDE_ROOT
))
3354 else if (level
== 0)
3356 // a hidden root is not evaluated, but its
3357 // children are always calculated
3361 CalculateSize( item
, dc
);
3364 item
->SetX( x
+m_spacing
);
3366 y
+= GetLineHeight(item
);
3368 if ( !item
->IsExpanded() )
3370 // we don't need to calculate collapsed branches
3375 wxArrayGenericTreeItems
& children
= item
->GetChildren();
3376 size_t n
, count
= children
.Count();
3378 for (n
= 0; n
< count
; ++n
)
3379 CalculateLevel( children
[n
], dc
, level
, y
); // recurse
3382 void wxGenericTreeCtrl::CalculatePositions()
3384 if ( !m_anchor
) return;
3386 wxClientDC
dc(this);
3389 dc
.SetFont( m_normalFont
);
3391 dc
.SetPen( m_dottedPen
);
3392 //if(GetImageList() == NULL)
3393 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
3396 CalculateLevel( m_anchor
, dc
, 0, y
); // start recursion
3399 void wxGenericTreeCtrl::RefreshSubtree(wxGenericTreeItem
*item
)
3401 if (m_dirty
) return;
3402 if (m_freezeCount
) return;
3404 wxSize client
= GetClientSize();
3407 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3408 rect
.width
= client
.x
;
3409 rect
.height
= client
.y
;
3411 Refresh(true, &rect
);
3413 AdjustMyScrollbars();
3416 void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
3418 if (m_dirty
) return;
3419 if (m_freezeCount
) return;
3422 CalcScrolledPosition(0, item
->GetY(), NULL
, &rect
.y
);
3423 rect
.width
= GetClientSize().x
;
3424 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
3426 Refresh(true, &rect
);
3429 void wxGenericTreeCtrl::RefreshSelected()
3431 if (m_freezeCount
) return;
3433 // TODO: this is awfully inefficient, we should keep the list of all
3434 // selected items internally, should be much faster
3436 RefreshSelectedUnder(m_anchor
);
3439 void wxGenericTreeCtrl::RefreshSelectedUnder(wxGenericTreeItem
*item
)
3441 if (m_freezeCount
) return;
3443 if ( item
->IsSelected() )
3446 const wxArrayGenericTreeItems
& children
= item
->GetChildren();
3447 size_t count
= children
.GetCount();
3448 for ( size_t n
= 0; n
< count
; n
++ )
3450 RefreshSelectedUnder(children
[n
]);
3454 void wxGenericTreeCtrl::Freeze()
3459 void wxGenericTreeCtrl::Thaw()
3461 wxCHECK_RET( m_freezeCount
> 0, _T("thawing unfrozen tree control?") );
3463 if ( !--m_freezeCount
)
3469 // ----------------------------------------------------------------------------
3470 // changing colours: we need to refresh the tree control
3471 // ----------------------------------------------------------------------------
3473 bool wxGenericTreeCtrl::SetBackgroundColour(const wxColour
& colour
)
3475 if ( !wxWindow::SetBackgroundColour(colour
) )
3478 if (m_freezeCount
) return true;
3485 bool wxGenericTreeCtrl::SetForegroundColour(const wxColour
& colour
)
3487 if ( !wxWindow::SetForegroundColour(colour
) )
3490 if (m_freezeCount
) return true;
3497 // Process the tooltip event, to speed up event processing.
3498 // Doesn't actually get a tooltip.
3499 void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent
&event
)
3505 wxSize
wxGenericTreeCtrl::DoGetBestSize() const
3507 // something is better than nothing...
3508 // 100x80 is what the MSW version will get from the default
3509 // wxControl::DoGetBestSize
3510 return wxSize(100,80);
3514 // NOTE: If using the wxListBox visual attributes works everywhere then this can
3515 // be removed, as well as the #else case below.
3516 #define _USE_VISATTR 0
3519 #include "wx/listbox.h"
3525 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
3527 wxGenericTreeCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
3531 // Use the same color scheme as wxListBox
3532 return wxListBox::GetClassDefaultAttributes(variant
);
3534 wxVisualAttributes attr
;
3535 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
3536 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
3537 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
3542 #endif // wxUSE_TREECTRL