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, Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // =============================================================================
14 // =============================================================================
16 // -----------------------------------------------------------------------------
18 // -----------------------------------------------------------------------------
21 #pragma implementation "treectlg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #include "wx/generic/treectlg.h"
32 #include "wx/imaglist.h"
33 #include "wx/settings.h"
36 #include "wx/dynarray.h"
37 #include "wx/arrimpl.cpp"
38 #include "wx/dcclient.h"
39 #include "wx/msgdlg.h"
41 // -----------------------------------------------------------------------------
43 // -----------------------------------------------------------------------------
45 class WXDLLEXPORT wxGenericTreeItem
;
47 WX_DEFINE_ARRAY(wxGenericTreeItem
*, wxArrayGenericTreeItems
);
48 //WX_DEFINE_OBJARRAY(wxArrayTreeItemIds);
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 static const int NO_IMAGE
= -1;
56 #define PIXELS_PER_UNIT 10
58 // -----------------------------------------------------------------------------
60 // -----------------------------------------------------------------------------
62 // timer used for enabling in-place edit
63 class WXDLLEXPORT wxTreeRenameTimer
: public wxTimer
66 wxTreeRenameTimer( wxGenericTreeCtrl
*owner
);
71 wxGenericTreeCtrl
*m_owner
;
74 // control used for in-place edit
75 class WXDLLEXPORT wxTreeTextCtrl
: public wxTextCtrl
79 wxTreeTextCtrl( wxWindow
*parent
,
83 wxGenericTreeCtrl
*owner
,
84 const wxString
&value
= wxEmptyString
,
85 const wxPoint
&pos
= wxDefaultPosition
,
86 const wxSize
&size
= wxDefaultSize
,
87 int style
= wxSIMPLE_BORDER
,
88 const wxValidator
& validator
= wxDefaultValidator
,
89 const wxString
&name
= wxTextCtrlNameStr
);
91 void OnChar( wxKeyEvent
&event
);
92 void OnKillFocus( wxFocusEvent
&event
);
97 wxGenericTreeCtrl
*m_owner
;
98 wxString m_startValue
;
100 DECLARE_EVENT_TABLE()
101 DECLARE_DYNAMIC_CLASS(wxTreeTextCtrl
);
105 class WXDLLEXPORT wxGenericTreeItem
109 wxGenericTreeItem() { m_data
= NULL
; }
110 wxGenericTreeItem( wxGenericTreeItem
*parent
,
111 const wxString
& text
,
113 int image
, int selImage
,
114 wxTreeItemData
*data
);
116 ~wxGenericTreeItem();
119 wxArrayGenericTreeItems
& GetChildren() { return m_children
; }
121 const wxString
& GetText() const { return m_text
; }
122 int GetImage(wxTreeItemIcon which
= wxTreeItemIcon_Normal
) const
123 { return m_images
[which
]; }
124 wxTreeItemData
*GetData() const { return m_data
; }
126 // returns the current image for the item (depending on its
127 // selected/expanded/whatever state)
128 int GetCurrentImage() const;
130 void SetText( const wxString
&text
);
131 void SetImage(int image
, wxTreeItemIcon which
) { m_images
[which
] = image
; }
132 void SetData(wxTreeItemData
*data
) { m_data
= data
; }
134 void SetHasPlus(bool has
= TRUE
) { m_hasPlus
= has
; }
136 void SetBold(bool bold
) { m_isBold
= bold
; }
138 int GetX() const { return m_x
; }
139 int GetY() const { return m_y
; }
141 void SetX(int x
) { m_x
= x
; }
142 void SetY(int y
) { m_y
= y
; }
144 int GetHeight() const { return m_height
; }
145 int GetWidth() const { return m_width
; }
147 void SetHeight(int h
) { m_height
= h
; }
148 void SetWidth(int w
) { m_width
= w
; }
151 wxGenericTreeItem
*GetParent() const { return m_parent
; }
154 // deletes all children notifying the treectrl about it if !NULL
156 void DeleteChildren(wxGenericTreeCtrl
*tree
= NULL
);
157 // FIXME don't know what is it for
160 // get count of all children (and grand children if 'recursively')
161 size_t GetChildrenCount(bool recursively
= TRUE
) const;
163 void Insert(wxGenericTreeItem
*child
, size_t index
)
164 { m_children
.Insert(child
, index
); }
166 void SetCross( int x
, int y
);
167 void GetSize( int &x
, int &y
, const wxGenericTreeCtrl
* );
169 // return the item at given position (or NULL if no item), onButton is
170 // TRUE if the point belongs to the item's button, otherwise it lies
171 // on the button's label
172 wxGenericTreeItem
*HitTest( const wxPoint
& point
, const wxGenericTreeCtrl
*, int &flags
);
174 void Expand() { m_isCollapsed
= FALSE
; }
175 void Collapse() { m_isCollapsed
= TRUE
; }
177 void SetHilight( bool set
= TRUE
) { m_hasHilight
= set
; }
180 bool HasChildren() const { return !m_children
.IsEmpty(); }
181 bool IsSelected() const { return m_hasHilight
; }
182 bool IsExpanded() const { return !m_isCollapsed
; }
183 bool HasPlus() const { return m_hasPlus
|| HasChildren(); }
184 bool IsBold() const { return m_isBold
; }
187 // get them - may be NULL
188 wxTreeItemAttr
*GetAttributes() const { return m_attr
; }
189 // get them ensuring that the pointer is not NULL
190 wxTreeItemAttr
& Attr()
193 m_attr
= new wxTreeItemAttr
;
201 // tree ctrl images for the normal, selected, expanded and
202 // expanded+selected states
203 int m_images
[wxTreeItemIcon_Max
];
205 wxTreeItemData
*m_data
;
207 // use bitfields to save size
208 int m_isCollapsed
:1;
209 int m_hasHilight
:1; // same as focused
210 int m_hasPlus
:1; // used for item which doesn't have
211 // children but has a [+] button
212 int m_isBold
:1; // render the label in bold font
215 wxCoord m_height
, m_width
;
216 int m_xCross
, m_yCross
;
219 wxArrayGenericTreeItems m_children
;
220 wxGenericTreeItem
*m_parent
;
222 wxTreeItemAttr
*m_attr
;
225 // =============================================================================
227 // =============================================================================
229 // ----------------------------------------------------------------------------
231 // ----------------------------------------------------------------------------
233 // translate the key or mouse event flags to the type of selection we're
235 static void EventFlagsToSelType(long style
,
239 bool &extended_select
,
240 bool &unselect_others
)
242 is_multiple
= (style
& wxTR_MULTIPLE
) != 0;
243 extended_select
= shiftDown
&& is_multiple
;
244 unselect_others
= !(extended_select
|| (ctrlDown
&& is_multiple
));
247 // -----------------------------------------------------------------------------
248 // wxTreeRenameTimer (internal)
249 // -----------------------------------------------------------------------------
251 wxTreeRenameTimer::wxTreeRenameTimer( wxGenericTreeCtrl
*owner
)
256 void wxTreeRenameTimer::Notify()
258 m_owner
->OnRenameTimer();
261 //-----------------------------------------------------------------------------
262 // wxTreeTextCtrl (internal)
263 //-----------------------------------------------------------------------------
265 IMPLEMENT_DYNAMIC_CLASS(wxTreeTextCtrl
,wxTextCtrl
);
267 BEGIN_EVENT_TABLE(wxTreeTextCtrl
,wxTextCtrl
)
268 EVT_CHAR (wxTreeTextCtrl::OnChar
)
269 EVT_KILL_FOCUS (wxTreeTextCtrl::OnKillFocus
)
272 wxTreeTextCtrl::wxTreeTextCtrl( wxWindow
*parent
,
276 wxGenericTreeCtrl
*owner
,
277 const wxString
&value
,
281 const wxValidator
& validator
,
282 const wxString
&name
)
283 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
289 (*m_res
) = wxEmptyString
;
290 m_startValue
= value
;
293 void wxTreeTextCtrl::OnChar( wxKeyEvent
&event
)
295 if (event
.m_keyCode
== WXK_RETURN
)
298 (*m_res
) = GetValue();
300 if (!wxPendingDelete
.Member(this))
301 wxPendingDelete
.Append(this);
303 if ((*m_accept
) && ((*m_res
) != m_startValue
))
304 m_owner
->OnRenameAccept();
308 if (event
.m_keyCode
== WXK_ESCAPE
)
313 if (!wxPendingDelete
.Member(this))
314 wxPendingDelete
.Append(this);
321 void wxTreeTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
323 if (!wxPendingDelete
.Member(this))
324 wxPendingDelete
.Append(this);
326 if ((*m_accept
) && ((*m_res
) != m_startValue
))
327 m_owner
->OnRenameAccept();
331 // -----------------------------------------------------------------------------
333 // -----------------------------------------------------------------------------
335 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxNotifyEvent
)
337 wxTreeEvent::wxTreeEvent( wxEventType commandType
, int id
)
338 : wxNotifyEvent( commandType
, id
)
341 m_itemOld
= (wxGenericTreeItem
*)NULL
;
345 // -----------------------------------------------------------------------------
347 // -----------------------------------------------------------------------------
349 wxGenericTreeItem::wxGenericTreeItem(wxGenericTreeItem
*parent
,
350 const wxString
& text
,
352 int image
, int selImage
,
353 wxTreeItemData
*data
)
356 m_images
[wxTreeItemIcon_Normal
] = image
;
357 m_images
[wxTreeItemIcon_Selected
] = selImage
;
358 m_images
[wxTreeItemIcon_Expanded
] = NO_IMAGE
;
359 m_images
[wxTreeItemIcon_SelectedExpanded
] = NO_IMAGE
;
363 m_xCross
= m_yCross
= 0;
367 m_isCollapsed
= TRUE
;
368 m_hasHilight
= FALSE
;
374 m_attr
= (wxTreeItemAttr
*)NULL
;
376 // We don't know the height here yet.
381 wxGenericTreeItem::~wxGenericTreeItem()
387 wxASSERT_MSG( m_children
.IsEmpty(),
388 wxT("please call DeleteChildren() before deleting the item") );
391 void wxGenericTreeItem::DeleteChildren(wxGenericTreeCtrl
*tree
)
393 size_t count
= m_children
.Count();
394 for ( size_t n
= 0; n
< count
; n
++ )
396 wxGenericTreeItem
*child
= m_children
[n
];
398 tree
->SendDeleteEvent(child
);
400 child
->DeleteChildren(tree
);
407 void wxGenericTreeItem::SetText( const wxString
&text
)
412 void wxGenericTreeItem::Reset()
415 for ( int i
= 0; i
< wxTreeItemIcon_Max
; i
++ )
417 m_images
[i
] = NO_IMAGE
;
422 m_height
= m_width
= 0;
429 m_isCollapsed
= TRUE
;
431 m_parent
= (wxGenericTreeItem
*)NULL
;
434 size_t wxGenericTreeItem::GetChildrenCount(bool recursively
) const
436 size_t count
= m_children
.Count();
440 size_t total
= count
;
441 for (size_t n
= 0; n
< count
; ++n
)
443 total
+= m_children
[n
]->GetChildrenCount();
449 void wxGenericTreeItem::SetCross( int x
, int y
)
455 void wxGenericTreeItem::GetSize( int &x
, int &y
, const wxGenericTreeCtrl
*theTree
)
457 int bottomY
=m_y
+theTree
->GetLineHeight(this);
458 if ( y
< bottomY
) y
= bottomY
;
459 int width
= m_x
+ m_width
;
460 if ( x
< width
) x
= width
;
464 size_t count
= m_children
.Count();
465 for ( size_t n
= 0; n
< count
; ++n
)
467 m_children
[n
]->GetSize( x
, y
, theTree
);
472 wxGenericTreeItem
*wxGenericTreeItem::HitTest( const wxPoint
& point
,
473 const wxGenericTreeCtrl
*theTree
,
476 if ((point
.y
> m_y
) && (point
.y
< m_y
+ theTree
->GetLineHeight(this)))
478 if (point
.y
< m_y
+theTree
->GetLineHeight(this)/2 )
479 flags
|= wxTREE_HITTEST_ONITEMUPPERPART
;
481 flags
|= wxTREE_HITTEST_ONITEMLOWERPART
;
483 // 5 is the size of the plus sign
484 if ((point
.x
> m_xCross
-5) && (point
.x
< m_xCross
+5) &&
485 (point
.y
> m_yCross
-5) && (point
.y
< m_yCross
+5) &&
486 (IsExpanded() || HasPlus()))
488 flags
|=wxTREE_HITTEST_ONITEMBUTTON
;
492 if ((point
.x
>= m_x
) && (point
.x
<= m_x
+m_width
))
497 // assuming every image (normal and selected ) has the same size !
498 if ( (GetImage() != NO_IMAGE
) && theTree
->m_imageListNormal
)
499 theTree
->m_imageListNormal
->GetSize(GetImage(), image_w
, image_h
);
501 if ((image_w
!= -1) && (point
.x
<= m_x
+ image_w
+ 1))
502 flags
|= wxTREE_HITTEST_ONITEMICON
;
504 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
510 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
511 if (point
.x
> m_x
+m_width
)
512 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
520 size_t count
= m_children
.Count();
521 for ( size_t n
= 0; n
< count
; n
++ )
523 wxGenericTreeItem
*res
= m_children
[n
]->HitTest( point
, theTree
, flags
);
530 flags
|=wxTREE_HITTEST_NOWHERE
;
532 return (wxGenericTreeItem
*) NULL
;
535 int wxGenericTreeItem::GetCurrentImage() const
537 int image
= NO_IMAGE
;
542 image
= GetImage(wxTreeItemIcon_SelectedExpanded
);
545 if ( image
== NO_IMAGE
)
547 // we usually fall back to the normal item, but try just the
548 // expanded one (and not selected) first in this case
549 image
= GetImage(wxTreeItemIcon_Expanded
);
555 image
= GetImage(wxTreeItemIcon_Selected
);
558 // may be it doesn't have the specific image we want, try the default one
560 if ( image
== NO_IMAGE
)
568 // -----------------------------------------------------------------------------
569 // wxGenericTreeCtrl implementation
570 // -----------------------------------------------------------------------------
572 IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl
, wxScrolledWindow
)
574 BEGIN_EVENT_TABLE(wxGenericTreeCtrl
,wxScrolledWindow
)
575 EVT_PAINT (wxGenericTreeCtrl::OnPaint
)
576 EVT_MOUSE_EVENTS (wxGenericTreeCtrl::OnMouse
)
577 EVT_CHAR (wxGenericTreeCtrl::OnChar
)
578 EVT_SET_FOCUS (wxGenericTreeCtrl::OnSetFocus
)
579 EVT_KILL_FOCUS (wxGenericTreeCtrl::OnKillFocus
)
580 EVT_IDLE (wxGenericTreeCtrl::OnIdle
)
583 #if !defined(__WXMSW__) || defined(__WIN16__)
585 * wxTreeCtrl has to be a real class or we have problems with
586 * the run-time information.
589 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxGenericTreeCtrl
)
592 // -----------------------------------------------------------------------------
593 // construction/destruction
594 // -----------------------------------------------------------------------------
596 void wxGenericTreeCtrl::Init()
600 m_anchor
= (wxGenericTreeItem
*) NULL
;
610 m_hilightBrush
= new wxBrush
612 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
),
617 m_imageListState
= (wxImageList
*) NULL
;
620 m_isDragging
= FALSE
;
622 m_oldSelection
= (wxGenericTreeItem
*)NULL
;
624 m_renameTimer
= new wxTreeRenameTimer( this );
625 m_lastOnSame
= FALSE
;
627 m_normalFont
= wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT
);
628 m_boldFont
= wxFont( m_normalFont
.GetPointSize(),
629 m_normalFont
.GetFamily(),
630 m_normalFont
.GetStyle(),
632 m_normalFont
.GetUnderlined());
635 bool wxGenericTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
,
636 const wxPoint
& pos
, const wxSize
& size
,
638 const wxValidator
&validator
,
639 const wxString
& name
)
641 wxScrolledWindow::Create( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
);
644 SetValidator( validator
);
647 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
648 // m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86
649 m_dottedPen
= wxPen( "grey", 0, 0 );
654 wxGenericTreeCtrl::~wxGenericTreeCtrl()
656 wxDELETE( m_hilightBrush
);
660 delete m_renameTimer
;
663 // -----------------------------------------------------------------------------
665 // -----------------------------------------------------------------------------
667 size_t wxGenericTreeCtrl::GetCount() const
669 return m_anchor
== NULL
? 0u : m_anchor
->GetChildrenCount();
672 void wxGenericTreeCtrl::SetIndent(unsigned int indent
)
678 void wxGenericTreeCtrl::SetSpacing(unsigned int spacing
)
684 size_t wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId
& item
, bool recursively
)
686 wxCHECK_MSG( item
.IsOk(), 0u, wxT("invalid tree item") );
688 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildrenCount(recursively
);
691 // -----------------------------------------------------------------------------
692 // functions to work with tree items
693 // -----------------------------------------------------------------------------
695 wxString
wxGenericTreeCtrl::GetItemText(const wxTreeItemId
& item
) const
697 wxCHECK_MSG( item
.IsOk(), wxT(""), wxT("invalid tree item") );
699 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetText();
702 int wxGenericTreeCtrl::GetItemImage(const wxTreeItemId
& item
,
703 wxTreeItemIcon which
) const
705 wxCHECK_MSG( item
.IsOk(), -1, wxT("invalid tree item") );
707 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetImage(which
);
710 wxTreeItemData
*wxGenericTreeCtrl::GetItemData(const wxTreeItemId
& item
) const
712 wxCHECK_MSG( item
.IsOk(), NULL
, wxT("invalid tree item") );
714 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetData();
717 void wxGenericTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
)
719 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
722 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
723 pItem
->SetText(text
);
724 CalculateSize(pItem
, dc
);
728 void wxGenericTreeCtrl::SetItemImage(const wxTreeItemId
& item
,
730 wxTreeItemIcon which
)
732 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
734 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
735 pItem
->SetImage(image
, which
);
738 CalculateSize(pItem
, dc
);
742 void wxGenericTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
)
744 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
746 ((wxGenericTreeItem
*) item
.m_pItem
)->SetData(data
);
749 void wxGenericTreeCtrl::SetItemHasChildren(const wxTreeItemId
& item
, bool has
)
751 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
753 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
754 pItem
->SetHasPlus(has
);
758 void wxGenericTreeCtrl::SetItemBold(const wxTreeItemId
& item
, bool bold
)
760 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
762 // avoid redrawing the tree if no real change
763 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
764 if ( pItem
->IsBold() != bold
)
766 pItem
->SetBold(bold
);
771 void wxGenericTreeCtrl::SetItemTextColour(const wxTreeItemId
& item
,
774 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
776 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
777 pItem
->Attr().SetTextColour(col
);
781 void wxGenericTreeCtrl::SetItemBackgroundColour(const wxTreeItemId
& item
,
784 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
786 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
787 pItem
->Attr().SetBackgroundColour(col
);
791 void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId
& item
, const wxFont
& font
)
793 wxCHECK_RET( item
.IsOk(), wxT("invalid tree item") );
795 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
796 pItem
->Attr().SetFont(font
);
800 // -----------------------------------------------------------------------------
801 // item status inquiries
802 // -----------------------------------------------------------------------------
804 bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId
& item
) const
806 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
808 // An item is only visible if it's not a descendant of a collapsed item
809 wxGenericTreeItem
*pItem
= (wxGenericTreeItem
*) item
.m_pItem
;
810 wxGenericTreeItem
* parent
= pItem
->GetParent();
813 if (!parent
->IsExpanded())
815 parent
= parent
->GetParent();
819 GetViewStart(& startX
, & startY
);
821 wxSize clientSize
= GetClientSize();
824 if (!GetBoundingRect(item
, rect
))
826 if (rect
.GetWidth() == 0 || rect
.GetHeight() == 0)
828 if (rect
.GetBottom() < 0 || rect
.GetTop() > clientSize
.y
)
830 if (rect
.GetRight() < 0 || rect
.GetLeft() > clientSize
.x
)
836 bool wxGenericTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const
838 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
840 return !((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren().IsEmpty();
843 bool wxGenericTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const
845 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
847 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsExpanded();
850 bool wxGenericTreeCtrl::IsSelected(const wxTreeItemId
& item
) const
852 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
854 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsSelected();
857 bool wxGenericTreeCtrl::IsBold(const wxTreeItemId
& item
) const
859 wxCHECK_MSG( item
.IsOk(), FALSE
, wxT("invalid tree item") );
861 return ((wxGenericTreeItem
*) item
.m_pItem
)->IsBold();
864 // -----------------------------------------------------------------------------
866 // -----------------------------------------------------------------------------
868 wxTreeItemId
wxGenericTreeCtrl::GetParent(const wxTreeItemId
& item
) const
870 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
872 return ((wxGenericTreeItem
*) item
.m_pItem
)->GetParent();
875 wxTreeItemId
wxGenericTreeCtrl::GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const
877 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
880 return GetNextChild(item
, cookie
);
883 wxTreeItemId
wxGenericTreeCtrl::GetNextChild(const wxTreeItemId
& item
, long& cookie
) const
885 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
887 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
888 if ( (size_t)cookie
< children
.Count() )
890 return children
.Item((size_t)cookie
++);
894 // there are no more of them
895 return wxTreeItemId();
899 wxTreeItemId
wxGenericTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
901 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
903 wxArrayGenericTreeItems
& children
= ((wxGenericTreeItem
*) item
.m_pItem
)->GetChildren();
904 return (children
.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children
.Last()));
907 wxTreeItemId
wxGenericTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const
909 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
911 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
912 wxGenericTreeItem
*parent
= i
->GetParent();
913 if ( parent
== NULL
)
915 // root item doesn't have any siblings
916 return wxTreeItemId();
919 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
920 int index
= siblings
.Index(i
);
921 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
923 size_t n
= (size_t)(index
+ 1);
924 return n
== siblings
.Count() ? wxTreeItemId() : wxTreeItemId(siblings
[n
]);
927 wxTreeItemId
wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const
929 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
931 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
932 wxGenericTreeItem
*parent
= i
->GetParent();
933 if ( parent
== NULL
)
935 // root item doesn't have any siblings
936 return wxTreeItemId();
939 wxArrayGenericTreeItems
& siblings
= parent
->GetChildren();
940 int index
= siblings
.Index(i
);
941 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
943 return index
== 0 ? wxTreeItemId()
944 : wxTreeItemId(siblings
[(size_t)(index
- 1)]);
947 // Only for internal use right now, but should probably be public
948 wxTreeItemId
wxGenericTreeCtrl::GetNext(const wxTreeItemId
& item
) const
950 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
952 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
954 // First see if there are any children.
955 wxArrayGenericTreeItems
& children
= i
->GetChildren();
956 if (children
.GetCount() > 0)
958 return children
.Item(0);
962 // Try a sibling of this or ancestor instead
963 wxTreeItemId p
= item
;
967 toFind
= GetNextSibling(p
);
969 } while (p
.IsOk() && !toFind
.IsOk());
974 wxTreeItemId
wxGenericTreeCtrl::GetPrev(const wxTreeItemId
& item
) const
976 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
978 wxFAIL_MSG(wxT("not implemented"));
980 return wxTreeItemId();
983 wxTreeItemId
wxGenericTreeCtrl::GetFirstVisibleItem() const
985 wxTreeItemId id
= GetRootItem();
996 return wxTreeItemId();
999 wxTreeItemId
wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const
1001 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1003 wxTreeItemId id
= item
;
1008 if (id
.IsOk() && IsVisible(id
))
1011 return wxTreeItemId();
1014 wxTreeItemId
wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const
1016 wxCHECK_MSG( item
.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
1018 wxFAIL_MSG(wxT("not implemented"));
1020 return wxTreeItemId();
1023 // -----------------------------------------------------------------------------
1025 // -----------------------------------------------------------------------------
1027 wxTreeItemId
wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId
& parentId
,
1029 const wxString
& text
,
1030 int image
, int selImage
,
1031 wxTreeItemData
*data
)
1033 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1036 // should we give a warning here?
1037 return AddRoot(text
, image
, selImage
, data
);
1040 wxClientDC
dc(this);
1041 wxGenericTreeItem
*item
=
1042 new wxGenericTreeItem( parent
, text
, dc
, image
, selImage
, data
);
1046 data
->m_pItem
= (long) item
;
1049 parent
->Insert( item
, previous
);
1056 wxTreeItemId
wxGenericTreeCtrl::AddRoot(const wxString
& text
,
1057 int image
, int selImage
,
1058 wxTreeItemData
*data
)
1060 wxCHECK_MSG( !m_anchor
, wxTreeItemId(), wxT("tree can have only one root") );
1062 wxClientDC
dc(this);
1063 m_anchor
= new wxGenericTreeItem((wxGenericTreeItem
*)NULL
, text
, dc
,
1064 image
, selImage
, data
);
1067 data
->m_pItem
= (long) m_anchor
;
1070 if (!HasFlag(wxTR_MULTIPLE
))
1072 m_current
= m_key_current
= m_anchor
;
1073 m_current
->SetHilight( TRUE
);
1081 wxTreeItemId
wxGenericTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
1082 const wxString
& text
,
1083 int image
, int selImage
,
1084 wxTreeItemData
*data
)
1086 return DoInsertItem(parent
, 0u, text
, image
, selImage
, data
);
1089 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1090 const wxTreeItemId
& idPrevious
,
1091 const wxString
& text
,
1092 int image
, int selImage
,
1093 wxTreeItemData
*data
)
1095 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1098 // should we give a warning here?
1099 return AddRoot(text
, image
, selImage
, data
);
1102 int index
= parent
->GetChildren().Index((wxGenericTreeItem
*) idPrevious
.m_pItem
);
1103 wxASSERT_MSG( index
!= wxNOT_FOUND
,
1104 wxT("previous item in wxGenericTreeCtrl::InsertItem() is not a sibling") );
1106 return DoInsertItem(parentId
, (size_t)++index
, text
, image
, selImage
, data
);
1109 wxTreeItemId
wxGenericTreeCtrl::InsertItem(const wxTreeItemId
& parentId
,
1111 const wxString
& text
,
1112 int image
, int selImage
,
1113 wxTreeItemData
*data
)
1115 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1118 // should we give a warning here?
1119 return AddRoot(text
, image
, selImage
, data
);
1122 return DoInsertItem(parentId
, before
, text
, image
, selImage
, data
);
1125 wxTreeItemId
wxGenericTreeCtrl::AppendItem(const wxTreeItemId
& parentId
,
1126 const wxString
& text
,
1127 int image
, int selImage
,
1128 wxTreeItemData
*data
)
1130 wxGenericTreeItem
*parent
= (wxGenericTreeItem
*) parentId
.m_pItem
;
1133 // should we give a warning here?
1134 return AddRoot(text
, image
, selImage
, data
);
1137 return DoInsertItem( parent
, parent
->GetChildren().Count(), text
,
1138 image
, selImage
, data
);
1141 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem
*item
)
1143 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, GetId() );
1144 event
.m_item
= (long) item
;
1145 event
.SetEventObject( this );
1146 ProcessEvent( event
);
1149 void wxGenericTreeCtrl::DeleteChildren(const wxTreeItemId
& itemId
)
1151 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1152 item
->DeleteChildren(this);
1157 void wxGenericTreeCtrl::Delete(const wxTreeItemId
& itemId
)
1159 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1161 // don't stay with invalid m_key_current or we will crash in the next call
1163 bool changeKeyCurrent
= FALSE
;
1164 wxGenericTreeItem
*itemKey
= m_key_current
;
1165 while ( itemKey
&& !changeKeyCurrent
)
1167 if ( itemKey
== item
)
1169 // m_key_current is a descendant of the item being deleted
1170 changeKeyCurrent
= TRUE
;
1174 itemKey
= itemKey
->GetParent();
1178 wxGenericTreeItem
*parent
= item
->GetParent();
1181 parent
->GetChildren().Remove( item
); // remove by value
1184 if ( changeKeyCurrent
)
1186 // may be NULL or not
1187 m_key_current
= parent
;
1190 item
->DeleteChildren(this);
1191 SendDeleteEvent(item
);
1197 void wxGenericTreeCtrl::DeleteAllItems()
1201 m_anchor
->DeleteChildren(this);
1210 void wxGenericTreeCtrl::Expand(const wxTreeItemId
& itemId
)
1212 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1214 wxCHECK_RET( item
, _T("invalid item in wxGenericTreeCtrl::Expand") );
1216 if ( !item
->HasPlus() )
1219 if ( item
->IsExpanded() )
1222 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, GetId() );
1223 event
.m_item
= (long) item
;
1224 event
.SetEventObject( this );
1226 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1228 // cancelled by program
1233 CalculatePositions();
1235 RefreshSubtree(item
);
1237 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
1238 ProcessEvent( event
);
1241 void wxGenericTreeCtrl::ExpandAll(const wxTreeItemId
& item
)
1244 if ( IsExpanded(item
) )
1247 wxTreeItemId child
= GetFirstChild(item
, cookie
);
1248 while ( child
.IsOk() )
1252 child
= GetNextChild(item
, cookie
);
1257 void wxGenericTreeCtrl::Collapse(const wxTreeItemId
& itemId
)
1259 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1261 if ( !item
->IsExpanded() )
1264 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, GetId() );
1265 event
.m_item
= (long) item
;
1266 event
.SetEventObject( this );
1267 if ( ProcessEvent( event
) && !event
.IsAllowed() )
1269 // cancelled by program
1275 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1276 size_t count
= children
.Count();
1277 for ( size_t n
= 0; n
< count
; n
++ )
1279 Collapse(children
[n
]);
1282 CalculatePositions();
1284 RefreshSubtree(item
);
1286 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
1287 ProcessEvent( event
);
1290 void wxGenericTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
)
1293 DeleteChildren(item
);
1296 void wxGenericTreeCtrl::Toggle(const wxTreeItemId
& itemId
)
1298 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1300 if (item
->IsExpanded())
1306 void wxGenericTreeCtrl::Unselect()
1310 m_current
->SetHilight( FALSE
);
1311 RefreshLine( m_current
);
1315 void wxGenericTreeCtrl::UnselectAllChildren(wxGenericTreeItem
*item
)
1317 if (item
->IsSelected())
1319 item
->SetHilight(FALSE
);
1323 if (item
->HasChildren())
1325 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1326 size_t count
= children
.Count();
1327 for ( size_t n
= 0; n
< count
; ++n
)
1329 UnselectAllChildren(children
[n
]);
1334 void wxGenericTreeCtrl::UnselectAll()
1336 UnselectAllChildren((wxGenericTreeItem
*) GetRootItem().m_pItem
);
1339 // Recursive function !
1340 // To stop we must have crt_item<last_item
1342 // Tag all next children, when no more children,
1343 // Move to parent (not to tag)
1344 // Keep going... if we found last_item, we stop.
1345 bool wxGenericTreeCtrl::TagNextChildren(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1347 wxGenericTreeItem
*parent
= crt_item
->GetParent();
1349 if (parent
== NULL
) // This is root item
1350 return TagAllChildrenUntilLast(crt_item
, last_item
, select
);
1352 wxArrayGenericTreeItems
& children
= parent
->GetChildren();
1353 int index
= children
.Index(crt_item
);
1354 wxASSERT( index
!= wxNOT_FOUND
); // I'm not a child of my parent?
1356 size_t count
= children
.Count();
1357 for (size_t n
=(size_t)(index
+1); n
<count
; ++n
)
1359 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
)) return TRUE
;
1362 return TagNextChildren(parent
, last_item
, select
);
1365 bool wxGenericTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem
*crt_item
, wxGenericTreeItem
*last_item
, bool select
)
1367 crt_item
->SetHilight(select
);
1368 RefreshLine(crt_item
);
1370 if (crt_item
==last_item
)
1373 if (crt_item
->HasChildren())
1375 wxArrayGenericTreeItems
& children
= crt_item
->GetChildren();
1376 size_t count
= children
.Count();
1377 for ( size_t n
= 0; n
< count
; ++n
)
1379 if (TagAllChildrenUntilLast(children
[n
], last_item
, select
))
1387 void wxGenericTreeCtrl::SelectItemRange(wxGenericTreeItem
*item1
, wxGenericTreeItem
*item2
)
1389 // item2 is not necessary after item1
1390 wxGenericTreeItem
*first
=NULL
, *last
=NULL
;
1392 // choice first' and 'last' between item1 and item2
1393 if (item1
->GetY()<item2
->GetY())
1404 bool select
= m_current
->IsSelected();
1406 if ( TagAllChildrenUntilLast(first
,last
,select
) )
1409 TagNextChildren(first
,last
,select
);
1412 void wxGenericTreeCtrl::SelectItem(const wxTreeItemId
& itemId
,
1413 bool unselect_others
,
1414 bool extended_select
)
1416 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
1418 bool is_single
=!(GetWindowStyleFlag() & wxTR_MULTIPLE
);
1419 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1421 //wxCHECK_RET( ( (!unselect_others) && is_single),
1422 // wxT("this is a single selection tree") );
1424 // to keep going anyhow !!!
1427 if (item
->IsSelected())
1428 return; // nothing to do
1429 unselect_others
= TRUE
;
1430 extended_select
= FALSE
;
1432 else if ( unselect_others
&& item
->IsSelected() )
1434 // selection change if there is more than one item currently selected
1435 wxArrayTreeItemIds selected_items
;
1436 if ( GetSelections(selected_items
) == 1 )
1440 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGING
, GetId() );
1441 event
.m_item
= (long) item
;
1442 event
.m_itemOld
= (long) m_current
;
1443 event
.SetEventObject( this );
1444 // TODO : Here we don't send any selection mode yet !
1446 if ( GetEventHandler()->ProcessEvent( event
) && !event
.IsAllowed() )
1450 if (unselect_others
)
1452 if (is_single
) Unselect(); // to speed up thing
1457 if (extended_select
)
1462 m_key_current
= (wxGenericTreeItem
*) GetRootItem().m_pItem
;
1465 // don't change the mark (m_current)
1466 SelectItemRange(m_current
, item
);
1470 bool select
=TRUE
; // the default
1472 // Check if we need to toggle hilight (ctrl mode)
1473 if (!unselect_others
)
1474 select
=!item
->IsSelected();
1476 m_current
= m_key_current
= item
;
1477 m_current
->SetHilight(select
);
1478 RefreshLine( m_current
);
1481 event
.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED
);
1482 GetEventHandler()->ProcessEvent( event
);
1485 void wxGenericTreeCtrl::FillArray(wxGenericTreeItem
*item
,
1486 wxArrayTreeItemIds
&array
) const
1488 if ( item
->IsSelected() )
1489 array
.Add(wxTreeItemId(item
));
1491 if ( item
->HasChildren() )
1493 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1494 size_t count
= children
.GetCount();
1495 for ( size_t n
= 0; n
< count
; ++n
)
1496 FillArray(children
[n
], array
);
1500 size_t wxGenericTreeCtrl::GetSelections(wxArrayTreeItemIds
&array
) const
1503 wxTreeItemId idRoot
= GetRootItem();
1504 if ( idRoot
.IsOk() )
1506 FillArray((wxGenericTreeItem
*) idRoot
.m_pItem
, array
);
1508 //else: the tree is empty, so no selections
1510 return array
.Count();
1513 void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId
& item
)
1515 if (!item
.IsOk()) return;
1517 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1519 // first expand all parent branches
1520 wxGenericTreeItem
*parent
= gitem
->GetParent();
1524 parent
= parent
->GetParent();
1527 //if (parent) CalculatePositions();
1532 void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId
&item
)
1534 if (!item
.IsOk()) return;
1536 // We have to call this here because the label in
1537 // question might just have been added and no screen
1538 // update taken place.
1539 if (m_dirty
) wxYield();
1541 wxGenericTreeItem
*gitem
= (wxGenericTreeItem
*) item
.m_pItem
;
1543 // now scroll to the item
1544 int item_y
= gitem
->GetY();
1548 ViewStart( &start_x
, &start_y
);
1549 start_y
*= PIXELS_PER_UNIT
;
1553 GetClientSize( &client_w
, &client_h
);
1555 if (item_y
< start_y
+3)
1560 m_anchor
->GetSize( x
, y
, this );
1561 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1562 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1563 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1564 // Item should appear at top
1565 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, item_y
/PIXELS_PER_UNIT
);
1567 else if (item_y
+GetLineHeight(gitem
) > start_y
+client_h
)
1572 m_anchor
->GetSize( x
, y
, this );
1573 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1574 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1575 item_y
+= PIXELS_PER_UNIT
+2;
1576 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1577 // Item should appear at bottom
1578 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
);
1582 // FIXME: tree sorting functions are not reentrant and not MT-safe!
1583 static wxGenericTreeCtrl
*s_treeBeingSorted
= NULL
;
1585 static int LINKAGEMODE
tree_ctrl_compare_func(wxGenericTreeItem
**item1
,
1586 wxGenericTreeItem
**item2
)
1588 wxCHECK_MSG( s_treeBeingSorted
, 0, wxT("bug in wxGenericTreeCtrl::SortChildren()") );
1590 return s_treeBeingSorted
->OnCompareItems(*item1
, *item2
);
1593 int wxGenericTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
1594 const wxTreeItemId
& item2
)
1596 return wxStrcmp(GetItemText(item1
), GetItemText(item2
));
1599 void wxGenericTreeCtrl::SortChildren(const wxTreeItemId
& itemId
)
1601 wxCHECK_RET( itemId
.IsOk(), wxT("invalid tree item") );
1603 wxGenericTreeItem
*item
= (wxGenericTreeItem
*) itemId
.m_pItem
;
1605 wxCHECK_RET( !s_treeBeingSorted
,
1606 wxT("wxGenericTreeCtrl::SortChildren is not reentrant") );
1608 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1609 if ( children
.Count() > 1 )
1611 s_treeBeingSorted
= this;
1612 children
.Sort(tree_ctrl_compare_func
);
1613 s_treeBeingSorted
= NULL
;
1617 //else: don't make the tree dirty as nothing changed
1620 wxImageList
*wxGenericTreeCtrl::GetImageList() const
1622 return m_imageListNormal
;
1625 wxImageList
*wxGenericTreeCtrl::GetStateImageList() const
1627 return m_imageListState
;
1630 void wxGenericTreeCtrl::SetImageList(wxImageList
*imageList
)
1632 m_imageListNormal
= imageList
;
1634 if ( !m_imageListNormal
)
1637 // Calculate a m_lineHeight value from the image sizes.
1638 // May be toggle off. Then wxGenericTreeCtrl will spread when
1639 // necessary (which might look ugly).
1640 wxClientDC
dc(this);
1641 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
1642 int width
= 0, height
= 0,
1643 n
= m_imageListNormal
->GetImageCount();
1645 for (int i
= 0; i
< n
; i
++)
1647 m_imageListNormal
->GetSize(i
, width
, height
);
1648 if (height
> m_lineHeight
) m_lineHeight
= height
;
1651 if (m_lineHeight
< 40)
1652 m_lineHeight
+= 2; // at least 2 pixels
1654 m_lineHeight
+= m_lineHeight
/10; // otherwise 10% extra spacing
1657 void wxGenericTreeCtrl::SetStateImageList(wxImageList
*imageList
)
1659 m_imageListState
= imageList
;
1662 // -----------------------------------------------------------------------------
1664 // -----------------------------------------------------------------------------
1666 void wxGenericTreeCtrl::AdjustMyScrollbars()
1672 m_anchor
->GetSize( x
, y
, this );
1673 y
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1674 x
+= PIXELS_PER_UNIT
+2; // one more scrollbar unit + 2 pixels
1675 int x_pos
= GetScrollPos( wxHORIZONTAL
);
1676 int y_pos
= GetScrollPos( wxVERTICAL
);
1677 SetScrollbars( PIXELS_PER_UNIT
, PIXELS_PER_UNIT
, x
/PIXELS_PER_UNIT
, y
/PIXELS_PER_UNIT
, x_pos
, y_pos
);
1681 SetScrollbars( 0, 0, 0, 0 );
1685 int wxGenericTreeCtrl::GetLineHeight(wxGenericTreeItem
*item
) const
1687 if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HEIGHT
)
1688 return item
->GetHeight();
1690 return m_lineHeight
;
1693 void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem
*item
, wxDC
& dc
)
1695 wxTreeItemAttr
*attr
= item
->GetAttributes();
1696 if ( attr
&& attr
->HasFont() )
1697 dc
.SetFont(attr
->GetFont());
1698 else if (item
->IsBold())
1699 dc
.SetFont(m_boldFont
);
1703 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
1707 int image
= item
->GetCurrentImage();
1708 if ( image
!= NO_IMAGE
)
1710 if ( m_imageListNormal
)
1712 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
1721 int total_h
= GetLineHeight(item
);
1723 if (item
->IsSelected())
1724 dc
.SetBrush(*m_hilightBrush
);
1728 if ( attr
&& attr
->HasBackgroundColour() )
1729 colBg
= attr
->GetBackgroundColour();
1731 colBg
= m_backgroundColour
;
1732 dc
.SetBrush(wxBrush(colBg
, wxSOLID
));
1735 dc
.DrawRectangle( item
->GetX()-2, item
->GetY(), item
->GetWidth()+2, total_h
);
1737 if ( image
!= NO_IMAGE
)
1739 dc
.SetClippingRegion( item
->GetX(), item
->GetY(), image_w
-2, total_h
);
1740 m_imageListNormal
->Draw( image
, dc
,
1742 item
->GetY() +((total_h
> image_h
)?((total_h
-image_h
)/2):0),
1743 wxIMAGELIST_DRAW_TRANSPARENT
);
1744 dc
.DestroyClippingRegion();
1747 dc
.SetBackgroundMode(wxTRANSPARENT
);
1748 int extraH
= (total_h
> text_h
) ? (total_h
- text_h
)/2 : 0;
1749 dc
.DrawText( item
->GetText(),
1750 (wxCoord
)(image_w
+ item
->GetX()),
1751 (wxCoord
)(item
->GetY() + extraH
));
1753 // restore normal font
1754 dc
.SetFont( m_normalFont
);
1757 // Now y stands for the top of the item, whereas it used to stand for middle !
1758 void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
1760 int horizX
= level
*m_indent
;
1762 item
->SetX( horizX
+m_indent
+m_spacing
);
1766 y
+=GetLineHeight(item
)/2;
1768 item
->SetCross( horizX
+m_indent
, y
);
1770 int exposed_x
= dc
.LogicalToDeviceX( 0 );
1771 int exposed_y
= dc
.LogicalToDeviceY( item
->GetY() );
1773 bool drawLines
= ((GetWindowStyle() & wxTR_NO_LINES
) == 0);
1775 if (IsExposed( exposed_x
, exposed_y
, 10000, GetLineHeight(item
) )) // 10000 = very much
1777 int startX
= horizX
;
1778 int endX
= horizX
+ (m_indent
-5);
1780 // if (!item->HasChildren()) endX += (m_indent+5);
1781 if (!item
->HasChildren()) endX
+= 20;
1784 dc
.DrawLine( startX
, y
, endX
, y
);
1786 if (item
->HasPlus())
1789 dc
.DrawLine( horizX
+(m_indent
+5), y
, horizX
+(m_indent
+15), y
);
1790 dc
.SetPen( *wxGREY_PEN
);
1791 dc
.SetBrush( *wxWHITE_BRUSH
);
1792 dc
.DrawRectangle( horizX
+(m_indent
-5), y
-4, 11, 9 );
1794 dc
.SetPen( *wxBLACK_PEN
);
1795 dc
.DrawLine( horizX
+(m_indent
-2), y
, horizX
+(m_indent
+3), y
);
1796 if (!item
->IsExpanded())
1797 dc
.DrawLine( horizX
+m_indent
, y
-2, horizX
+m_indent
, y
+3 );
1799 dc
.SetPen( m_dottedPen
);
1802 wxPen
*pen
= wxTRANSPARENT_PEN
;
1805 if ( item
->IsSelected() )
1807 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1815 wxTreeItemAttr
*attr
= item
->GetAttributes();
1816 if ( attr
&& attr
->HasTextColour() )
1817 colText
= attr
->GetTextColour();
1819 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
);
1823 dc
.SetTextForeground(colText
);
1827 PaintItem(item
, dc
);
1829 // restore DC objects
1830 dc
.SetBrush( *wxWHITE_BRUSH
);
1831 dc
.SetPen( m_dottedPen
);
1832 dc
.SetTextForeground( *wxBLACK
);
1835 y
= oldY
+GetLineHeight(item
);
1837 if (item
->IsExpanded())
1839 oldY
+=GetLineHeight(item
)/2;
1842 wxArrayGenericTreeItems
& children
= item
->GetChildren();
1843 size_t n
, count
= children
.Count();
1844 for ( n
= 0; n
< count
; ++n
)
1847 PaintLevel( children
[n
], dc
, level
+1, y
);
1850 // it may happen that the item is expanded but has no items (when you
1851 // delete all its children for example) - don't draw the vertical line
1855 semiOldY
+=GetLineHeight(children
[--n
])/2;
1857 dc
.DrawLine( horizX
+m_indent
, oldY
+5, horizX
+m_indent
, semiOldY
);
1862 void wxGenericTreeCtrl::DrawDropEffect(wxGenericTreeItem
*item
)
1866 if ( item
->HasPlus() )
1868 // it's a folder, indicate it by a border
1873 // draw a line under the drop target because the item will be
1875 DrawLine(item
, TRUE
/* below */);
1878 SetCursor(wxCURSOR_BULLSEYE
);
1883 SetCursor(wxCURSOR_NO_ENTRY
);
1887 void wxGenericTreeCtrl::DrawBorder(const wxTreeItemId
&item
)
1889 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
1891 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1893 wxClientDC
dc(this);
1895 dc
.SetLogicalFunction(wxINVERT
);
1896 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1898 int w
= i
->GetWidth() + 2;
1899 int h
= GetLineHeight(i
) + 2;
1901 dc
.DrawRectangle( i
->GetX() - 1, i
->GetY() - 1, w
, h
);
1904 void wxGenericTreeCtrl::DrawLine(const wxTreeItemId
&item
, bool below
)
1906 wxCHECK_RET( item
.IsOk(), _T("invalid item in wxGenericTreeCtrl::DrawLine") );
1908 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
1910 wxClientDC
dc(this);
1912 dc
.SetLogicalFunction(wxINVERT
);
1918 y
+= GetLineHeight(i
) - 1;
1921 dc
.DrawLine( x
, y
, x
+ i
->GetWidth(), y
);
1924 // -----------------------------------------------------------------------------
1925 // wxWindows callbacks
1926 // -----------------------------------------------------------------------------
1928 void wxGenericTreeCtrl::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1936 dc
.SetFont( m_normalFont
);
1937 dc
.SetPen( m_dottedPen
);
1939 // this is now done dynamically
1940 //if(GetImageList() == NULL)
1941 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
1944 PaintLevel( m_anchor
, dc
, 0, y
);
1947 void wxGenericTreeCtrl::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1951 if (m_current
) RefreshLine( m_current
);
1954 void wxGenericTreeCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1958 if (m_current
) RefreshLine( m_current
);
1961 void wxGenericTreeCtrl::OnChar( wxKeyEvent
&event
)
1963 wxTreeEvent
te( wxEVT_COMMAND_TREE_KEY_DOWN
, GetId() );
1964 te
.m_code
= (int)event
.KeyCode();
1965 te
.SetEventObject( this );
1966 GetEventHandler()->ProcessEvent( te
);
1968 if ( (m_current
== 0) || (m_key_current
== 0) )
1974 // how should the selection work for this event?
1975 bool is_multiple
, extended_select
, unselect_others
;
1976 EventFlagsToSelType(GetWindowStyleFlag(),
1978 event
.ControlDown(),
1979 is_multiple
, extended_select
, unselect_others
);
1983 // * : Expand all/Collapse all
1984 // ' ' | return : activate
1985 // up : go up (not last children!)
1987 // left : go to parent
1988 // right : open if parent and go next
1989 // home : go to root
1990 // end : go to last item without opening parents
1991 switch (event
.KeyCode())
1995 if (m_current
->HasPlus() && !IsExpanded(m_current
))
2003 if ( !IsExpanded(m_current
) )
2006 ExpandAll(m_current
);
2009 //else: fall through to Collapse() it
2013 if (IsExpanded(m_current
))
2015 Collapse(m_current
);
2022 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
2023 event
.m_item
= (long) m_current
;
2025 event
.SetEventObject( this );
2026 GetEventHandler()->ProcessEvent( event
);
2030 // up goes to the previous sibling or to the last of its children if
2034 wxTreeItemId prev
= GetPrevSibling( m_key_current
);
2037 prev
= GetParent( m_key_current
);
2041 wxTreeItemId current
= m_key_current
;
2042 if (current
== GetFirstChild( prev
, cockie
))
2044 // otherwise we return to where we came from
2045 SelectItem( prev
, unselect_others
, extended_select
);
2046 m_key_current
= (wxGenericTreeItem
*) prev
.m_pItem
;
2047 EnsureVisible( prev
);
2054 while ( IsExpanded(prev
) && HasChildren(prev
) )
2056 wxTreeItemId child
= GetLastChild(prev
);
2063 SelectItem( prev
, unselect_others
, extended_select
);
2064 m_key_current
=(wxGenericTreeItem
*) prev
.m_pItem
;
2065 EnsureVisible( prev
);
2070 // left arrow goes to the parent
2073 wxTreeItemId prev
= GetParent( m_current
);
2076 EnsureVisible( prev
);
2077 SelectItem( prev
, unselect_others
, extended_select
);
2083 // this works the same as the down arrow except that we also expand the
2084 // item if it wasn't expanded yet
2090 if (IsExpanded(m_key_current
) && HasChildren(m_key_current
))
2093 wxTreeItemId child
= GetFirstChild( m_key_current
, cookie
);
2094 SelectItem( child
, unselect_others
, extended_select
);
2095 m_key_current
=(wxGenericTreeItem
*) child
.m_pItem
;
2096 EnsureVisible( child
);
2100 wxTreeItemId next
= GetNextSibling( m_key_current
);
2103 wxTreeItemId current
= m_key_current
;
2104 while (current
&& !next
)
2106 current
= GetParent( current
);
2107 if (current
) next
= GetNextSibling( current
);
2112 SelectItem( next
, unselect_others
, extended_select
);
2113 m_key_current
=(wxGenericTreeItem
*) next
.m_pItem
;
2114 EnsureVisible( next
);
2120 // <End> selects the last visible tree item
2123 wxTreeItemId last
= GetRootItem();
2125 while ( last
.IsOk() && IsExpanded(last
) )
2127 wxTreeItemId lastChild
= GetLastChild(last
);
2129 // it may happen if the item was expanded but then all of
2130 // its children have been deleted - so IsExpanded() returned
2131 // TRUE, but GetLastChild() returned invalid item
2140 EnsureVisible( last
);
2141 SelectItem( last
, unselect_others
, extended_select
);
2146 // <Home> selects the root item
2149 wxTreeItemId prev
= GetRootItem();
2152 EnsureVisible( prev
);
2153 SelectItem( prev
, unselect_others
, extended_select
);
2163 wxTreeItemId
wxGenericTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
2165 // We have to call this here because the label in
2166 // question might just have been added and no screen
2167 // update taken place.
2168 if (m_dirty
) wxYield();
2170 wxClientDC
dc(this);
2172 wxCoord x
= dc
.DeviceToLogicalX( point
.x
);
2173 wxCoord y
= dc
.DeviceToLogicalY( point
.y
);
2178 if (point
.x
<0) flags
|=wxTREE_HITTEST_TOLEFT
;
2179 if (point
.x
>w
) flags
|=wxTREE_HITTEST_TORIGHT
;
2180 if (point
.y
<0) flags
|=wxTREE_HITTEST_ABOVE
;
2181 if (point
.y
>h
) flags
|=wxTREE_HITTEST_BELOW
;
2183 return m_anchor
->HitTest( wxPoint(x
, y
), this, flags
);
2186 // get the bounding rectangle of the item (or of its label only)
2187 bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId
& item
,
2189 bool textOnly
) const
2191 wxCHECK_MSG( item
.IsOk(), FALSE
, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
2193 wxGenericTreeItem
*i
= (wxGenericTreeItem
*) item
.m_pItem
;
2196 GetViewStart(& startX
, & startY
);
2198 rect
.x
= i
->GetX() - startX
*PIXELS_PER_UNIT
;
2199 rect
.y
= i
->GetY() - startY
*PIXELS_PER_UNIT
;
2200 rect
.width
= i
->GetWidth();
2201 //rect.height = i->GetHeight();
2202 rect
.height
= GetLineHeight(i
);
2209 void wxGenericTreeCtrl::Edit( const wxTreeItemId
& item
)
2211 if (!item
.IsOk()) return;
2213 m_currentEdit
= (wxGenericTreeItem
*) item
.m_pItem
;
2215 wxTreeEvent
te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
, GetId() );
2216 te
.m_item
= (long) m_currentEdit
;
2217 te
.SetEventObject( this );
2218 GetEventHandler()->ProcessEvent( te
);
2220 if (!te
.IsAllowed()) return;
2222 // We have to call this here because the label in
2223 // question might just have been added and no screen
2224 // update taken place.
2225 if (m_dirty
) wxYield();
2227 wxString s
= m_currentEdit
->GetText();
2228 int x
= m_currentEdit
->GetX();
2229 int y
= m_currentEdit
->GetY();
2230 int w
= m_currentEdit
->GetWidth();
2231 int h
= m_currentEdit
->GetHeight();
2236 int image
= m_currentEdit
->GetCurrentImage();
2237 if ( image
!= NO_IMAGE
)
2239 if ( m_imageListNormal
)
2241 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
2246 wxFAIL_MSG(_T("you must create an image list to use images!"));
2250 w
-= image_w
+ 4; // I don't know why +4 is needed
2252 wxClientDC
dc(this);
2254 x
= dc
.LogicalToDeviceX( x
);
2255 y
= dc
.LogicalToDeviceY( y
);
2257 wxTreeTextCtrl
*text
= new wxTreeTextCtrl(
2258 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
2262 void wxGenericTreeCtrl::OnRenameTimer()
2267 void wxGenericTreeCtrl::OnRenameAccept()
2269 wxTreeEvent
le( wxEVT_COMMAND_TREE_END_LABEL_EDIT
, GetId() );
2270 le
.m_item
= (long) m_currentEdit
;
2271 le
.SetEventObject( this );
2272 le
.m_label
= m_renameRes
;
2273 GetEventHandler()->ProcessEvent( le
);
2275 if (!le
.IsAllowed()) return;
2277 SetItemText( m_currentEdit
, m_renameRes
);
2280 void wxGenericTreeCtrl::OnMouse( wxMouseEvent
&event
)
2282 if ( !m_anchor
) return;
2284 // we process left mouse up event (enables in-place edit), right down
2285 // (pass to the user code), left dbl click (activate item) and
2286 // dragging/moving events for items drag-and-drop
2287 if ( !(event
.LeftDown() ||
2289 event
.RightDown() ||
2290 event
.LeftDClick() ||
2292 ((event
.Moving() || event
.RightUp()) && m_isDragging
)) )
2299 wxClientDC
dc(this);
2301 wxCoord x
= dc
.DeviceToLogicalX( event
.GetX() );
2302 wxCoord y
= dc
.DeviceToLogicalY( event
.GetY() );
2305 wxGenericTreeItem
*item
= m_anchor
->HitTest( wxPoint(x
,y
), this, flags
);
2307 if ( event
.Dragging() && !m_isDragging
)
2309 if (m_dragCount
== 0)
2310 m_dragStart
= wxPoint(x
,y
);
2314 if (m_dragCount
!= 3)
2316 // wait until user drags a bit further...
2320 wxEventType command
= event
.RightIsDown()
2321 ? wxEVT_COMMAND_TREE_BEGIN_RDRAG
2322 : wxEVT_COMMAND_TREE_BEGIN_DRAG
;
2324 wxTreeEvent
nevent( command
, GetId() );
2325 nevent
.m_item
= (long) m_current
;
2326 nevent
.SetEventObject(this);
2328 // by default the dragging is not supported, the user code must
2329 // explicitly allow the event for it to take place
2332 if ( GetEventHandler()->ProcessEvent(nevent
) && nevent
.IsAllowed() )
2334 // we're going to drag this item
2335 m_isDragging
= TRUE
;
2337 // remember the old cursor because we will change it while
2339 m_oldCursor
= m_cursor
;
2341 // in a single selection control, hide the selection temporarily
2342 if ( !(GetWindowStyleFlag() & wxTR_MULTIPLE
) )
2344 m_oldSelection
= (wxGenericTreeItem
*) GetSelection().m_pItem
;
2346 if ( m_oldSelection
)
2348 m_oldSelection
->SetHilight(FALSE
);
2349 RefreshLine(m_oldSelection
);
2356 else if ( event
.Moving() )
2358 if ( item
!= m_dropTarget
)
2360 // unhighlight the previous drop target
2361 DrawDropEffect(m_dropTarget
);
2363 m_dropTarget
= item
;
2365 // highlight the current drop target if any
2366 DrawDropEffect(m_dropTarget
);
2371 else if ( (event
.LeftUp() || event
.RightUp()) && m_isDragging
)
2373 // erase the highlighting
2374 DrawDropEffect(m_dropTarget
);
2376 // generate the drag end event
2377 wxTreeEvent
event(wxEVT_COMMAND_TREE_END_DRAG
, GetId());
2379 event
.m_item
= (long) item
;
2380 event
.m_pointDrag
= wxPoint(x
, y
);
2381 event
.SetEventObject(this);
2383 (void)GetEventHandler()->ProcessEvent(event
);
2385 m_isDragging
= FALSE
;
2386 m_dropTarget
= (wxGenericTreeItem
*)NULL
;
2388 if ( m_oldSelection
)
2390 m_oldSelection
->SetHilight(TRUE
);
2391 RefreshLine(m_oldSelection
);
2392 m_oldSelection
= (wxGenericTreeItem
*)NULL
;
2397 SetCursor(m_oldCursor
);
2403 // here we process only the messages which happen on tree items
2407 if (item
== NULL
) return; /* we hit the blank area */
2409 if ( event
.RightDown() )
2411 wxTreeEvent
nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
, GetId());
2412 nevent
.m_item
= (long) item
;
2414 nevent
.SetEventObject(this);
2415 GetEventHandler()->ProcessEvent(nevent
);
2417 else if ( event
.LeftUp() )
2421 if ( (item
== m_current
) &&
2422 (flags
& wxTREE_HITTEST_ONITEMLABEL
) &&
2423 HasFlag(wxTR_EDIT_LABELS
) )
2425 if ( m_renameTimer
->IsRunning() )
2426 m_renameTimer
->Stop();
2428 m_renameTimer
->Start( 100, TRUE
);
2431 m_lastOnSame
= FALSE
;
2436 if ( event
.LeftDown() )
2438 m_lastOnSame
= item
== m_current
;
2441 // how should the selection work for this event?
2442 bool is_multiple
, extended_select
, unselect_others
;
2443 EventFlagsToSelType(GetWindowStyleFlag(),
2445 event
.ControlDown(),
2446 is_multiple
, extended_select
, unselect_others
);
2448 if ( (flags
& wxTREE_HITTEST_ONITEMBUTTON
) && event
.LeftDown() )
2455 SelectItem(item
, unselect_others
, extended_select
);
2457 if ( event
.LeftDClick() )
2459 // double clicking should not start editing the item label
2460 m_renameTimer
->Stop();
2461 m_lastOnSame
= FALSE
;
2463 wxTreeEvent
nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED
, GetId() );
2464 nevent
.m_item
= (long) item
;
2466 nevent
.SetEventObject( this );
2467 GetEventHandler()->ProcessEvent( nevent
);
2473 void wxGenericTreeCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2475 /* after all changes have been done to the tree control,
2476 * we actually redraw the tree when everything is over */
2483 CalculatePositions();
2485 AdjustMyScrollbars();
2488 void wxGenericTreeCtrl::CalculateSize( wxGenericTreeItem
*item
, wxDC
&dc
)
2494 dc
.SetFont(m_boldFont
);
2496 dc
.GetTextExtent( item
->GetText(), &text_w
, &text_h
);
2499 // restore normal font
2500 dc
.SetFont( m_normalFont
);
2504 int image
= item
->GetCurrentImage();
2505 if ( image
!= NO_IMAGE
)
2507 if ( m_imageListNormal
)
2509 m_imageListNormal
->GetSize( image
, image_w
, image_h
);
2514 int total_h
= (image_h
> text_h
) ? image_h
: text_h
;
2517 total_h
+= 2; // at least 2 pixels
2519 total_h
+= total_h
/10; // otherwise 10% extra spacing
2521 item
->SetHeight(total_h
);
2522 if (total_h
>m_lineHeight
)
2523 m_lineHeight
=total_h
;
2525 item
->SetWidth(image_w
+text_w
+2);
2528 // -----------------------------------------------------------------------------
2529 // for developper : y is now the top of the level
2530 // not the middle of it !
2531 void wxGenericTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxDC
&dc
, int level
, int &y
)
2533 int horizX
= level
*m_indent
;
2535 CalculateSize( item
, dc
);
2538 item
->SetX( horizX
+m_indent
+m_spacing
);
2540 y
+=GetLineHeight(item
);
2542 if ( !item
->IsExpanded() )
2544 // we dont need to calculate collapsed branches
2548 wxArrayGenericTreeItems
& children
= item
->GetChildren();
2549 size_t n
, count
= children
.Count();
2550 for (n
= 0; n
< count
; ++n
)
2551 CalculateLevel( children
[n
], dc
, level
+1, y
); // recurse
2554 void wxGenericTreeCtrl::CalculatePositions()
2556 if ( !m_anchor
) return;
2558 wxClientDC
dc(this);
2561 dc
.SetFont( m_normalFont
);
2563 dc
.SetPen( m_dottedPen
);
2564 //if(GetImageList() == NULL)
2565 // m_lineHeight = (int)(dc.GetCharHeight() + 4);
2568 CalculateLevel( m_anchor
, dc
, 0, y
); // start recursion
2571 void wxGenericTreeCtrl::RefreshSubtree(wxGenericTreeItem
*item
)
2573 if (m_dirty
) return;
2575 wxClientDC
dc(this);
2580 GetClientSize( &cw
, &ch
);
2583 rect
.x
= dc
.LogicalToDeviceX( 0 );
2585 rect
.y
= dc
.LogicalToDeviceY( item
->GetY() );
2588 Refresh( TRUE
, &rect
);
2590 AdjustMyScrollbars();
2593 void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
2595 if (m_dirty
) return;
2597 wxClientDC
dc(this);
2602 GetClientSize( &cw
, &ch
);
2605 rect
.x
= dc
.LogicalToDeviceX( 0 );
2606 rect
.y
= dc
.LogicalToDeviceY( item
->GetY() );
2608 rect
.height
= GetLineHeight(item
); //dc.GetCharHeight() + 6;
2610 Refresh( TRUE
, &rect
);