1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "treectrl.h"
15 #include "wx/treectrl.h"
16 #include "wx/settings.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem
, wxObject
)
24 wxTreeItem::wxTreeItem()
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
,wxCommandEvent
)
42 wxTreeEvent::wxTreeEvent( wxEventType commandType
, int id
) :
43 wxCommandEvent( commandType
, id
)
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
53 IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeItem
,wxObject
)
55 wxGenericTreeItem::wxGenericTreeItem( wxGenericTreeItem
*parent
)
62 wxGenericTreeItem::wxGenericTreeItem( wxGenericTreeItem
*parent
, const wxTreeItem
& item
, wxDC
*dc
)
70 void wxGenericTreeItem::SetItem( const wxTreeItem
&item
, wxDC
*dc
)
72 if ((item
.m_mask
& wxTREE_MASK_HANDLE
) == wxTREE_MASK_HANDLE
)
73 m_itemId
= item
.m_itemId
;
74 if ((item
.m_mask
& wxTREE_MASK_STATE
) == wxTREE_MASK_STATE
)
75 m_state
= item
.m_state
;
76 if ((item
.m_mask
& wxTREE_MASK_TEXT
) == wxTREE_MASK_TEXT
)
78 if ((item
.m_mask
& wxTREE_MASK_IMAGE
) == wxTREE_MASK_IMAGE
)
79 m_image
= item
.m_image
;
80 if ((item
.m_mask
& wxTREE_MASK_SELECTED_IMAGE
) == wxTREE_MASK_SELECTED_IMAGE
)
81 m_selectedImage
= item
.m_selectedImage
;
82 if ((item
.m_mask
& wxTREE_MASK_CHILDREN
) == wxTREE_MASK_CHILDREN
)
83 m_hasChildren
= (item
.m_children
> 0);
84 if ((item
.m_mask
& wxTREE_MASK_DATA
) == wxTREE_MASK_DATA
)
88 dc
->GetTextExtent( m_text
, &lw
, &lh
);
93 void wxGenericTreeItem::SetText( const wxString
&text
, wxDC
*dc
)
98 dc
->GetTextExtent( m_text
, &lw
, &lh
);
103 void wxGenericTreeItem::Reset()
109 m_selectedImage
= -1;
111 m_hasChildren
= FALSE
;
120 m_children
.DeleteContents( TRUE
);
121 m_isCollapsed
= TRUE
;
125 void wxGenericTreeItem::GetItem( wxTreeItem
&item
) const
127 if ((item
.m_mask
& wxTREE_MASK_STATE
) == wxTREE_MASK_STATE
)
128 item
.m_state
= m_state
;
129 if ((item
.m_mask
& wxTREE_MASK_TEXT
) == wxTREE_MASK_TEXT
)
130 item
.m_text
= m_text
;
131 if ((item
.m_mask
& wxTREE_MASK_IMAGE
) == wxTREE_MASK_IMAGE
)
132 item
.m_image
= m_image
;
133 if ((item
.m_mask
& wxTREE_MASK_SELECTED_IMAGE
) == wxTREE_MASK_SELECTED_IMAGE
)
134 item
.m_selectedImage
= m_selectedImage
;
135 if ((item
.m_mask
& wxTREE_MASK_CHILDREN
) == wxTREE_MASK_CHILDREN
)
136 item
.m_children
= (int)m_hasChildren
;
137 if ((item
.m_mask
& wxTREE_MASK_DATA
) == wxTREE_MASK_DATA
)
138 item
.m_data
= m_data
;
141 bool wxGenericTreeItem::HasChildren()
143 return m_hasChildren
;
146 bool wxGenericTreeItem::HasPlus()
148 if ( !HasChildren() )
151 return !IsExpanded();
154 int wxGenericTreeItem::NumberOfVisibleDescendents()
156 int ret
= m_children
.Number();
157 wxNode
*node
= m_children
.First();
160 wxGenericTreeItem
*item
= (wxGenericTreeItem
*)node
->Data();
161 ret
+= item
->NumberOfVisibleDescendents();
167 int wxGenericTreeItem::NumberOfVisibleChildren()
169 return m_isCollapsed
? 0 : m_children
.Number();
172 wxGenericTreeItem
*wxGenericTreeItem::FindItem( long itemId
) const
174 if (m_itemId
== itemId
) return (wxGenericTreeItem
*)(this);
175 wxNode
*node
= m_children
.First();
178 wxGenericTreeItem
*item
= (wxGenericTreeItem
*)node
->Data();
179 wxGenericTreeItem
*res
= item
->FindItem( itemId
);
180 if (res
) return (wxGenericTreeItem
*)(res
);
186 void wxGenericTreeItem::AddChild( wxGenericTreeItem
*child
)
188 m_children
.Append( child
);
191 void wxGenericTreeItem::SetCross( int x
, int y
)
197 void wxGenericTreeItem::GetSize( int &x
, int &y
)
199 if (y
< m_y
+ 10) y
= m_y
+10;
200 int width
= m_x
+ m_width
;
201 if (width
> x
) x
= width
;
202 wxNode
*node
= m_children
.First();
205 wxGenericTreeItem
*item
= (wxGenericTreeItem
*)node
->Data();
206 item
->GetSize( x
, y
);
211 long wxGenericTreeItem::HitTest( const wxPoint
& point
, int &flags
)
213 if (m_parent
&& ((point
.y
> m_y
) && (point
.y
< m_y
+m_height
)))
215 if ((point
.x
> m_xCross
-5) &&
216 (point
.x
< m_xCross
+5) &&
217 (point
.y
> m_yCross
-5) &&
218 (point
.y
< m_yCross
+5) &&
221 flags
= wxTREE_HITTEST_ONITEMBUTTON
;
224 if ((point
.x
> m_x
) && (point
.x
< m_x
+m_width
))
226 flags
= wxTREE_HITTEST_ONITEMLABEL
;
231 flags
= wxTREE_HITTEST_ONITEMRIGHT
;
234 flags
= wxTREE_HITTEST_ONITEMINDENT
;
239 wxNode
*node
= m_children
.First();
242 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
243 long res
= child
->HitTest( point
, flags
);
244 if (res
!= -1) return res
;
251 void wxGenericTreeItem::PrepareEvent( wxTreeEvent
&event
)
253 event
.m_item
.m_itemId
= m_itemId
;
254 event
.m_item
.m_state
= m_state
;
255 event
.m_item
.m_text
= m_text
;
256 event
.m_item
.m_image
= m_image
;
257 event
.m_item
.m_selectedImage
= m_selectedImage
;
258 event
.m_item
.m_children
= (int)m_hasChildren
;
259 event
.m_item
.m_data
= m_data
;
262 event
.m_pointDrag
.x
= 0;
263 event
.m_pointDrag
.y
= 0;
266 void wxGenericTreeItem::SendKeyDown( wxWindow
*target
)
268 wxTreeEvent
event( wxEVT_COMMAND_TREE_KEY_DOWN
, target
->GetId() );
269 PrepareEvent( event
);
270 event
.SetEventObject( target
);
271 target
->ProcessEvent( event
);
274 void wxGenericTreeItem::SendSelected( wxWindow
*target
)
276 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGED
, target
->GetId() );
277 PrepareEvent( event
);
278 event
.SetEventObject( target
);
279 target
->ProcessEvent( event
);
282 void wxGenericTreeItem::SendDelete( wxWindow
*target
)
284 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, target
->GetId() );
285 PrepareEvent( event
);
286 event
.SetEventObject( target
);
287 target
->ProcessEvent( event
);
290 void wxGenericTreeItem::SendExpand( wxWindow
*target
)
292 m_isCollapsed
= FALSE
;
294 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, target
->GetId() );
295 event
.SetCode(wxTREE_EXPAND_EXPAND
);
296 event
.SetEventObject( target
);
297 PrepareEvent( event
);
298 target
->ProcessEvent( event
);
300 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
301 PrepareEvent( event
);
302 target
->ProcessEvent( event
);
305 void wxGenericTreeItem::SendCollapse( wxWindow
*target
)
307 m_isCollapsed
= TRUE
;
309 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, target
->GetId() );
310 event
.SetCode(wxTREE_EXPAND_COLLAPSE
);
311 event
.SetEventObject( target
);
312 PrepareEvent( event
);
313 target
->ProcessEvent( event
);
315 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
316 PrepareEvent( event
);
317 target
->ProcessEvent( event
);
320 void wxGenericTreeItem::SetHilight( bool set
)
325 bool wxGenericTreeItem::HasHilight()
330 //-----------------------------------------------------------------------------
332 //-----------------------------------------------------------------------------
334 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
,wxScrolledWindow
337 BEGIN_EVENT_TABLE(wxTreeCtrl
,wxScrolledWindow
)
338 EVT_PAINT (wxTreeCtrl::OnPaint
)
339 EVT_MOUSE_EVENTS (wxTreeCtrl::OnMouse
)
340 EVT_CHAR (wxTreeCtrl::OnChar
)
341 EVT_SET_FOCUS (wxTreeCtrl::OnSetFocus
)
342 EVT_KILL_FOCUS (wxTreeCtrl::OnKillFocus
)
345 wxTreeCtrl::wxTreeCtrl()
357 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
360 wxTreeCtrl::wxTreeCtrl(wxWindow
*parent
, wxWindowID id
,
363 long style
, const wxString
& name
)
375 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
376 Create( parent
, id
, pos
, size
, style
, name
);
379 wxTreeCtrl::~wxTreeCtrl()
381 if (m_dc
) delete m_dc
;
384 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
,
388 , const wxString
& name
)
390 wxScrolledWindow::Create( parent
, id
, pos
, size
, style
, name
);
391 SetBackgroundColour( *wxWHITE
);
392 m_dottedPen
= wxPen( *wxBLACK
, 0, 0 );
396 int wxTreeCtrl::GetCount() const
398 if (!m_anchor
) return 0;
399 return m_anchor
->NumberOfVisibleDescendents();
402 long wxTreeCtrl::InsertItem( long parent
, const wxString
& label
, int image
,
403 int selImage
, long WXUNUSED(insertAfter
) )
405 wxGenericTreeItem
*p
= NULL
;
408 if (m_anchor
) return -1;
412 p
= FindItem( parent
);
417 item
.m_mask
= wxTREE_MASK_HANDLE
;
418 item
.m_itemId
= m_lastId
;
419 if (!label
.IsNull() || (label
== ""))
422 item
.m_mask
|= wxTREE_MASK_TEXT
;
426 item
.m_image
= image
;
427 item
.m_mask
|= wxTREE_MASK_IMAGE
;
431 item
.m_selectedImage
= selImage
;
432 item
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
436 wxGenericTreeItem
*new_child
= new wxGenericTreeItem( p
, item
, &dc
);
438 p
->AddChild( new_child
);
440 m_anchor
= new_child
;
444 CalculatePositions();
447 GetClientSize( NULL
, &ch
);
450 rect
.x
= 0; rect
.y
= 0;
451 rect
.width
= 10000; rect
.height
= ch
;
454 if (p
->m_children
.Number() == 1)
456 rect
.y
= dc
.LogicalToDeviceY( p
->m_y
);
460 wxNode
*node
= p
->m_children
.Member( new_child
)->Previous();
461 wxGenericTreeItem
* last_child
= (wxGenericTreeItem
*)node
->Data();
462 rect
.y
= dc
.LogicalToDeviceY( last_child
->m_y
);
467 dc
.GetDeviceOrigin( &doX
, &doY
);
468 rect
.height
= ch
-rect
.y
-doY
;
470 AdjustMyScrollbars();
472 if (rect
.height
> 0) Refresh( FALSE
, &rect
);
476 AdjustMyScrollbars();
484 long wxTreeCtrl::InsertItem( long parent
, wxTreeItem
&info
, long WXUNUSED(insertAfter
) )
486 int oldMask
= info
.m_mask
;
487 wxGenericTreeItem
*p
= NULL
;
490 if (m_anchor
) return -1;
494 p
= FindItem( parent
);
497 printf( "TreeItem not found.\n" );
502 if ((info
.m_mask
& wxTREE_MASK_HANDLE
) == 0)
505 info
.m_itemId
= m_lastId
;
506 info
.m_mask
|= wxTREE_MASK_HANDLE
;
515 wxGenericTreeItem
*new_child
= new wxGenericTreeItem( p
, info
, &dc
);
517 p
->AddChild( new_child
);
519 m_anchor
= new_child
;
523 CalculatePositions();
526 GetClientSize( NULL
, &ch
);
529 rect
.x
= 0; rect
.y
= 0;
530 rect
.width
= 10000; rect
.height
= ch
;
533 if (p
->m_children
.Number() == 1)
535 rect
.y
= dc
.LogicalToDeviceY( p
->m_y
);
539 wxNode
*node
= p
->m_children
.Member( new_child
)->Previous();
540 wxGenericTreeItem
* last_child
= (wxGenericTreeItem
*)node
->Data();
541 rect
.y
= dc
.LogicalToDeviceY( last_child
->m_y
);
546 dc
.GetDeviceOrigin( &doX
, &doY
);
547 rect
.height
= ch
-rect
.y
-doY
;
549 AdjustMyScrollbars();
551 if (rect
.height
> 0) Refresh( FALSE
, &rect
);
555 AdjustMyScrollbars();
560 info
.m_mask
= oldMask
;
564 bool wxTreeCtrl::ExpandItem( long item
, int action
)
566 wxGenericTreeItem
*i
= FindItem( item
);
572 case wxTREE_EXPAND_EXPAND
:
574 i
->SendExpand( this );
578 case wxTREE_EXPAND_COLLAPSE_RESET
:
579 case wxTREE_EXPAND_COLLAPSE
:
581 wxNode
*node
= i
->m_children
.First();
584 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
585 #if 0 // VZ: don't delete items when the branch is collapsed
586 child
->SendDelete( this );
588 node
= i
->m_children
.First();
590 if ( child
->IsExpanded() )
591 ExpandItem( child
->m_itemId
, wxTREE_EXPAND_COLLAPSE
);
596 i
->SendCollapse( this );
600 case wxTREE_EXPAND_TOGGLE
:
602 if ( i
->IsExpanded() )
603 ExpandItem( item
, wxTREE_EXPAND_COLLAPSE
);
605 ExpandItem( item
, wxTREE_EXPAND_EXPAND
);
612 GetClientSize( &cw
, &ch
);
618 rect
.y
= dc
.LogicalToDeviceY( i
->m_y
);
621 dc
.GetDeviceOrigin( NULL
, &doY
);
622 rect
.height
= ch
-rect
.y
-doY
;
623 Refresh( TRUE
, &rect
);
625 AdjustMyScrollbars();
630 void wxTreeCtrl::DeleteItem( long item
)
632 wxGenericTreeItem
*pItem
= FindItem( item
);
633 wxCHECK_RET( pItem
!= NULL
, "wxTreeCtrl::DeleteItem: no such pItem." );
634 pItem
->m_parent
->m_children
.DeleteObject(pItem
);
638 bool wxTreeCtrl::DeleteAllItems()
646 bool wxTreeCtrl::GetItem( wxTreeItem
&info
) const
648 wxGenericTreeItem
*i
= FindItem( info
.m_itemId
);
649 if (!i
) return FALSE
;
654 long wxTreeCtrl::GetItemData( long item
) const
656 wxGenericTreeItem
*i
= FindItem( item
);
661 wxString
wxTreeCtrl::GetItemText( long item
) const
663 wxGenericTreeItem
*i
= FindItem( item
);
668 int wxTreeCtrl::GetItemImage(long item
) const
670 wxGenericTreeItem
*i
= FindItem( item
);
671 return i
== 0 ? -1 : i
->GetImage();
674 long wxTreeCtrl::GetParent( long item
) const
676 wxGenericTreeItem
*i
= FindItem( item
);
680 return i
->m_parent
->m_itemId
;
683 long wxTreeCtrl::GetRootItem() const
685 if (m_anchor
) return m_anchor
->m_itemId
;
689 long wxTreeCtrl::GetSelection() const
694 bool wxTreeCtrl::SelectItem( long WXUNUSED(item
) ) const
699 bool wxTreeCtrl::ItemHasChildren( long item
) const
701 wxGenericTreeItem
*i
= FindItem( item
);
702 if (!i
) return FALSE
;
703 return i
->m_hasChildren
;
706 void wxTreeCtrl::SetIndent( int indent
)
712 int wxTreeCtrl::GetIndent() const
717 bool wxTreeCtrl::SetItem( wxTreeItem
&info
)
719 wxGenericTreeItem
*i
= FindItem( info
.m_itemId
);
720 if (!i
) return FALSE
;
722 i
->SetItem( info
, &dc
);
727 bool wxTreeCtrl::SetItemData( long item
, long data
)
729 wxGenericTreeItem
*i
= FindItem( item
);
730 if (!i
) return FALSE
;
735 bool wxTreeCtrl::SetItemText( long item
, const wxString
&text
)
737 wxGenericTreeItem
*i
= FindItem( item
);
738 if (!i
) return FALSE
;
740 i
->SetText( text
, &dc
);
744 void wxTreeCtrl::SetItemImage(long item
, int image
, int imageSel
) const
746 wxGenericTreeItem
*i
= FindItem( item
);
749 i
->SetSelectedImage(imageSel
);
753 long wxTreeCtrl::HitTest( const wxPoint
& point
, int &flags
)
756 if (!m_anchor
) return -1;
757 return m_anchor
->HitTest( point
, flags
);
760 void wxTreeCtrl::AdjustMyScrollbars()
766 m_anchor
->GetSize( x
, y
);
768 int x_pos
= GetScrollPos( wxHORIZONTAL
);
769 int y_pos
= GetScrollPos( wxVERTICAL
);
770 SetScrollbars( 10, 10, x
/10, y
/10, x_pos
, y_pos
);
774 SetScrollbars( 0, 0, 0, 0 );
778 void wxTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
)
780 int horizX
= level
*m_indent
+10;
782 wxNode
*node
= item
->m_children
.First();
785 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
786 dc
.SetPen( m_dottedPen
);
788 child
->SetCross( horizX
+15, y
);
792 if (level
!= 0) oldY
-= (m_lineHeight
-5);
793 dc
.DrawLine( horizX
, oldY
, horizX
, y
);
796 child
->m_x
= horizX
+33;
797 child
->m_y
= y
-m_lineHeight
/3;
798 child
->m_height
= m_lineHeight
;
800 if (IsExposed( 0, child
->m_y
-2, 10000, m_lineHeight
+4 ))
805 if (!(node
->Previous()) && (level
== 0))
807 if (!child
->HasChildren())
809 dc
.DrawLine( startX
, y
, endX
, y
);
811 if (child
->HasChildren())
813 dc
.DrawLine( horizX
+20, y
, horizX
+30, y
);
814 dc
.SetPen( *wxGREY_PEN
);
815 dc
.DrawRectangle( horizX
+10, y
-4, 11, 9 );
816 dc
.SetPen( *wxBLACK_PEN
);
817 dc
.DrawLine( horizX
+13, y
, horizX
+17, y
);
818 if (child
->HasPlus())
819 dc
.DrawLine( horizX
+15, y
-2, horizX
+15, y
+2 );
822 if (child
->HasHilight())
824 dc
.SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
825 #if 0 // VZ: this code leaves horizontal stripes when item is unselected
826 dc
.SetBrush( *m_hilightBrush
);
828 dc
.SetPen( wxBLACK_PEN
);
830 dc
.SetPen( wxTRANSPARENT_PEN
);
832 dc
.GetTextExtent( child
->m_text
, &tw
, &th
);
833 dc
.DrawRectangle( child
->m_x
-2, child
->m_y
-2, tw
+4, th
+4 );
835 int modeOld
= dc
.GetBackgroundMode();
836 dc
.SetTextBackground( *wxBLACK
);
837 dc
.SetBackgroundMode(wxSOLID
);
840 dc
.DrawText( child
->m_text
, child
->m_x
, child
->m_y
);
842 #if 0 // VZ: same as above
843 dc
.SetPen( *wxBLACK_PEN
);
845 dc
.SetBackgroundMode(modeOld
);
846 dc
.SetTextBackground( *wxWHITE
);
847 dc
.SetBrush( *wxWHITE_BRUSH
);
849 dc
.SetTextForeground( *wxBLACK
);
852 dc
.DrawText( child
->m_text
, child
->m_x
, child
->m_y
);
856 if ( child
->IsExpanded() && child
->NumberOfVisibleChildren() > 0)
857 PaintLevel( child
, dc
, level
+1, y
);
862 void wxTreeCtrl::OnPaint( const wxPaintEvent
&WXUNUSED(event
) )
864 if (!m_anchor
) return;
868 m_dc
= new wxPaintDC(this);
872 m_dc
->SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
874 m_dc
->SetPen( m_dottedPen
);
875 m_lineHeight
= (int)(m_dc
->GetCharHeight() + 4);
877 int y
= m_lineHeight
/ 2 + 2;
878 PaintLevel( m_anchor
, *m_dc
, 0, y
);
881 void wxTreeCtrl::OnSetFocus( const wxFocusEvent
&WXUNUSED(event
) )
884 if (m_current
) RefreshLine( m_current
);
887 void wxTreeCtrl::OnKillFocus( const wxFocusEvent
&WXUNUSED(event
) )
890 if (m_current
) RefreshLine( m_current
);
893 void wxTreeCtrl::OnChar( wxKeyEvent
&event
)
898 void wxTreeCtrl::OnMouse( const wxMouseEvent
&event
)
900 if (!event
.LeftDown() &&
901 !event
.LeftDClick()) return;
905 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
906 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
909 long id
= HitTest( wxPoint(x
,y
), flag
);
912 wxGenericTreeItem
*item
= FindItem( id
);
915 if ((flag
!= wxTREE_HITTEST_ONITEMBUTTON
) &&
916 (flag
!= wxTREE_HITTEST_ONITEMLABEL
)) return;
918 if (m_current
!= item
)
922 m_current
->SetHilight( FALSE
);
923 RefreshLine( m_current
);
926 m_current
->SetHilight( TRUE
);
927 RefreshLine( m_current
);
928 m_current
->SendSelected( this );
931 if (event
.LeftDClick())
932 m_current
->SendKeyDown( this );
934 if (flag
== wxTREE_HITTEST_ONITEMBUTTON
)
936 ExpandItem( item
->m_itemId
, wxTREE_EXPAND_TOGGLE
);
941 void wxTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
)
943 int horizX
= level
*m_indent
+10;
944 wxNode
*node
= item
->m_children
.First();
947 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
948 dc
.SetPen( m_dottedPen
);
953 if (!node
->Previous() && (level
== 0))
955 if (!child
->HasChildren())
958 child
->m_x
= horizX
+33;
959 child
->m_y
= y
-m_lineHeight
/3-2;
960 child
->m_height
= m_lineHeight
;
963 if ( child
->IsExpanded() && child
->NumberOfVisibleChildren() > 0 )
964 CalculateLevel( child
, dc
, level
+1, y
);
970 void wxTreeCtrl::CalculatePositions()
978 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
980 dc
.SetPen( m_dottedPen
);
981 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
983 int y
= m_lineHeight
/ 2 + 2;
984 CalculateLevel( m_anchor
, dc
, 0, y
);
987 wxGenericTreeItem
*wxTreeCtrl::FindItem( long itemId
) const
989 if (!m_anchor
) return NULL
;
990 return m_anchor
->FindItem( itemId
);
993 void wxTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
999 rect
.x
= dc
.LogicalToDeviceX( item
->m_x
-2 );
1000 rect
.y
= dc
.LogicalToDeviceY( item
->m_y
-2 );
1002 rect
.height
= dc
.GetCharHeight()+4;
1003 Refresh( TRUE
, &rect
);