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 ((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
.SetEventObject( target
);
296 PrepareEvent( event
);
297 target
->ProcessEvent( event
);
299 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
300 PrepareEvent( event
);
301 target
->ProcessEvent( event
);
304 void wxGenericTreeItem::SendCollapse( wxWindow
*target
)
306 m_isCollapsed
= TRUE
;
308 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, target
->GetId() );
309 event
.SetEventObject( target
);
310 PrepareEvent( event
);
311 target
->ProcessEvent( event
);
313 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
314 PrepareEvent( event
);
315 target
->ProcessEvent( event
);
318 void wxGenericTreeItem::SetHilight( bool set
)
323 bool wxGenericTreeItem::HasHilight()
328 //-----------------------------------------------------------------------------
330 //-----------------------------------------------------------------------------
332 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
,wxScrolledWindow
)
334 BEGIN_EVENT_TABLE(wxTreeCtrl
,wxScrolledWindow
)
335 EVT_PAINT (wxTreeCtrl::OnPaint
)
336 EVT_MOUSE_EVENTS (wxTreeCtrl::OnMouse
)
337 EVT_CHAR (wxTreeCtrl::OnChar
)
338 EVT_SET_FOCUS (wxTreeCtrl::OnSetFocus
)
339 EVT_KILL_FOCUS (wxTreeCtrl::OnKillFocus
)
342 wxTreeCtrl::wxTreeCtrl()
354 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
357 wxTreeCtrl::wxTreeCtrl(wxWindow
*parent
, wxWindowID id
,
358 const wxPoint
& pos
, const wxSize
& size
,
359 long style
, const wxString
& name
)
371 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
372 Create( parent
, id
, pos
, size
, style
, name
);
375 wxTreeCtrl::~wxTreeCtrl()
377 if (m_dc
) delete m_dc
;
380 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
,
381 const wxPoint
& pos
, const wxSize
& size
,
382 long style
, const wxString
& name
)
384 wxScrolledWindow::Create( parent
, id
, pos
, size
, style
, name
);
385 SetBackgroundColour( *wxWHITE
);
386 m_dottedPen
= wxPen( *wxBLACK
, 0, 0 );
390 int wxTreeCtrl::GetCount() const
392 if (!m_anchor
) return 0;
393 return m_anchor
->NumberOfVisibleDescendents();
396 long wxTreeCtrl::InsertItem( long parent
, const wxString
& label
, int image
,
397 int selImage
, long WXUNUSED(insertAfter
) )
399 wxGenericTreeItem
*p
= NULL
;
402 if (m_anchor
) return -1;
406 p
= FindItem( parent
);
411 item
.m_mask
= wxTREE_MASK_HANDLE
;
412 item
.m_itemId
= m_lastId
;
413 if (!label
.IsNull() || (label
== ""))
416 item
.m_mask
|= wxTREE_MASK_TEXT
;
420 item
.m_image
= image
;
421 item
.m_mask
|= wxTREE_MASK_IMAGE
;
425 item
.m_selectedImage
= selImage
;
426 item
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
430 wxGenericTreeItem
*new_child
= new wxGenericTreeItem( p
, item
, &dc
);
432 p
->AddChild( new_child
);
434 m_anchor
= new_child
;
438 CalculatePositions();
441 GetClientSize( NULL
, &ch
);
444 rect
.x
= 0; rect
.y
= 0;
445 rect
.width
= 10000; rect
.height
= ch
;
448 if (p
->m_children
.Number() == 1)
450 rect
.y
= dc
.LogicalToDeviceY( p
->m_y
);
454 wxNode
*node
= p
->m_children
.Member( new_child
)->Previous();
455 wxGenericTreeItem
* last_child
= (wxGenericTreeItem
*)node
->Data();
456 rect
.y
= dc
.LogicalToDeviceY( last_child
->m_y
);
461 dc
.GetDeviceOrigin( &doX
, &doY
);
462 rect
.height
= ch
-rect
.y
-doY
;
464 AdjustMyScrollbars();
466 if (rect
.height
> 0) Refresh( FALSE
, &rect
);
470 AdjustMyScrollbars();
478 long wxTreeCtrl::InsertItem( long parent
, wxTreeItem
&info
, long WXUNUSED(insertAfter
) )
480 int oldMask
= info
.m_mask
;
481 wxGenericTreeItem
*p
= NULL
;
484 if (m_anchor
) return -1;
488 p
= FindItem( parent
);
491 printf( "TreeItem not found.\n" );
496 if ((info
.m_mask
& wxTREE_MASK_HANDLE
) == 0)
499 info
.m_itemId
= m_lastId
;
500 info
.m_mask
|= wxTREE_MASK_HANDLE
;
509 wxGenericTreeItem
*new_child
= new wxGenericTreeItem( p
, info
, &dc
);
511 p
->AddChild( new_child
);
513 m_anchor
= new_child
;
517 CalculatePositions();
520 GetClientSize( NULL
, &ch
);
523 rect
.x
= 0; rect
.y
= 0;
524 rect
.width
= 10000; rect
.height
= ch
;
527 if (p
->m_children
.Number() == 1)
529 rect
.y
= dc
.LogicalToDeviceY( p
->m_y
);
533 wxNode
*node
= p
->m_children
.Member( new_child
)->Previous();
534 wxGenericTreeItem
* last_child
= (wxGenericTreeItem
*)node
->Data();
535 rect
.y
= dc
.LogicalToDeviceY( last_child
->m_y
);
540 dc
.GetDeviceOrigin( &doX
, &doY
);
541 rect
.height
= ch
-rect
.y
-doY
;
543 AdjustMyScrollbars();
545 if (rect
.height
> 0) Refresh( FALSE
, &rect
);
549 AdjustMyScrollbars();
554 info
.m_mask
= oldMask
;
558 bool wxTreeCtrl::ExpandItem( long item
, int action
)
560 wxGenericTreeItem
*i
= FindItem( item
);
566 case wxTREE_EXPAND_EXPAND
:
568 i
->SendExpand( this );
572 case wxTREE_EXPAND_COLLAPSE_RESET
:
573 case wxTREE_EXPAND_COLLAPSE
:
575 wxNode
*node
= i
->m_children
.First();
578 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
579 if ( child
->IsExpanded() )
580 ExpandItem( child
->m_itemId
, wxTREE_EXPAND_COLLAPSE
);
584 i
->SendCollapse( this );
588 case wxTREE_EXPAND_TOGGLE
:
590 if ( i
->IsExpanded() )
591 ExpandItem( item
, wxTREE_EXPAND_COLLAPSE
);
593 ExpandItem( item
, wxTREE_EXPAND_EXPAND
);
600 GetClientSize( &cw
, &ch
);
606 rect
.y
= dc
.LogicalToDeviceY( i
->m_y
);
609 dc
.GetDeviceOrigin( NULL
, &doY
);
610 rect
.height
= ch
-rect
.y
-doY
;
611 Refresh( TRUE
, &rect
);
613 AdjustMyScrollbars();
618 void wxTreeCtrl::DeleteItem( long item
)
620 wxGenericTreeItem
*pItem
= FindItem( item
);
621 wxCHECK_RET( pItem
!= NULL
, "wxTreeCtrl::DeleteItem: no such pItem." );
623 pItem
->m_parent
->m_children
.DeleteObject(pItem
);
628 void wxTreeCtrl::DeleteChildren( long item
)
630 wxGenericTreeItem
*pItem
= FindItem( item
);
631 wxCHECK_RET( pItem
!= NULL
, "wxTreeCtrl::DeleteChildren: no such pItem." );
633 pItem
->m_children
.Clear();
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
;
782 item
->m_x
= horizX
+33;
783 item
->m_y
= y
-m_lineHeight
/3;
784 item
->m_height
= m_lineHeight
;
786 item
->SetCross( horizX
+15, y
);
790 if (IsExposed( 0, item
->m_y
-2, 10000, m_lineHeight
+4 ))
793 int endX
= horizX
+ 10;
795 if (!item
->HasChildren()) endX
+= 20;
796 dc
.DrawLine( startX
, y
, endX
, y
);
798 if (item
->HasChildren())
800 dc
.DrawLine( horizX
+20, y
, horizX
+30, y
);
801 dc
.SetPen( *wxGREY_PEN
);
802 dc
.DrawRectangle( horizX
+10, y
-4, 11, 9 );
803 dc
.SetPen( *wxBLACK_PEN
);
804 dc
.DrawLine( horizX
+13, y
, horizX
+18, y
);
806 dc
.DrawLine( horizX
+15, y
-2, horizX
+15, y
+3 );
809 if (item
->HasHilight())
811 dc
.SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
812 dc
.SetBrush( *m_hilightBrush
);
814 dc
.SetPen( *wxBLACK_PEN
);
816 dc
.SetPen( *wxWHITE_PEN
);
818 dc
.GetTextExtent( item
->m_text
, &tw
, &th
);
819 dc
.DrawRectangle( item
->m_x
-2, item
->m_y
-2, tw
+4, th
+4 );
820 dc
.DrawText( item
->m_text
, item
->m_x
, item
->m_y
);
822 dc
.SetPen( *wxBLACK_PEN
);
823 dc
.SetTextForeground( *wxBLACK
);
824 dc
.SetBrush( *wxWHITE_BRUSH
);
828 dc
.SetPen( *wxWHITE_PEN
);
830 dc
.GetTextExtent( item
->m_text
, &tw
, &th
);
831 dc
.DrawRectangle( item
->m_x
-2, item
->m_y
-2, tw
+4, th
+4 );
832 dc
.DrawText( item
->m_text
, item
->m_x
, item
->m_y
);
833 dc
.SetPen( *wxBLACK_PEN
);
837 if (item
->NumberOfVisibleChildren() == 0) return;
839 wxNode
*node
= item
->m_children
.First();
842 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
845 PaintLevel( child
, dc
, level
+1, y
);
850 dc
.DrawLine( horizX
+15, oldY
+5, horizX
+15, y
);
853 void wxTreeCtrl::OnPaint( const wxPaintEvent
&WXUNUSED(event
) )
855 if (!m_anchor
) return;
859 m_dc
= new wxPaintDC(this);
863 m_dc
->SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
865 m_dc
->SetPen( m_dottedPen
);
866 m_lineHeight
= (int)(m_dc
->GetCharHeight() + 4);
868 int y
= m_lineHeight
/ 2 + 2;
869 PaintLevel( m_anchor
, *m_dc
, 0, y
);
872 void wxTreeCtrl::OnSetFocus( const wxFocusEvent
&WXUNUSED(event
) )
875 if (m_current
) RefreshLine( m_current
);
878 void wxTreeCtrl::OnKillFocus( const wxFocusEvent
&WXUNUSED(event
) )
881 if (m_current
) RefreshLine( m_current
);
884 void wxTreeCtrl::OnChar( wxKeyEvent
&event
)
889 void wxTreeCtrl::OnMouse( const wxMouseEvent
&event
)
891 if (!event
.LeftDown() &&
892 !event
.LeftDClick()) return;
896 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
897 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
900 long id
= HitTest( wxPoint(x
,y
), flag
);
903 wxGenericTreeItem
*item
= FindItem( id
);
906 if ((flag
!= wxTREE_HITTEST_ONITEMBUTTON
) &&
907 (flag
!= wxTREE_HITTEST_ONITEMLABEL
)) return;
909 if (m_current
!= item
)
913 m_current
->SetHilight( FALSE
);
914 RefreshLine( m_current
);
917 m_current
->SetHilight( TRUE
);
918 RefreshLine( m_current
);
919 m_current
->SendSelected( this );
922 if (event
.LeftDClick())
923 m_current
->SendKeyDown( this );
925 if (flag
== wxTREE_HITTEST_ONITEMBUTTON
)
927 ExpandItem( item
->m_itemId
, wxTREE_EXPAND_TOGGLE
);
932 void wxTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
)
934 int horizX
= level
*m_indent
;
936 item
->m_x
= horizX
+33;
937 item
->m_y
= y
-m_lineHeight
/3-2;
938 item
->m_height
= m_lineHeight
;
940 if (item
->NumberOfVisibleChildren() == 0) return;
942 wxNode
*node
= item
->m_children
.First();
945 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
948 CalculateLevel( child
, dc
, level
+1, y
);
954 void wxTreeCtrl::CalculatePositions()
962 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
964 dc
.SetPen( m_dottedPen
);
965 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
967 int y
= m_lineHeight
/ 2 + 2;
968 CalculateLevel( m_anchor
, dc
, 0, y
);
971 wxGenericTreeItem
*wxTreeCtrl::FindItem( long itemId
) const
973 if (!m_anchor
) return NULL
;
974 return m_anchor
->FindItem( itemId
);
977 void wxTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
983 rect
.x
= dc
.LogicalToDeviceX( item
->m_x
-2 );
984 rect
.y
= dc
.LogicalToDeviceY( item
->m_y
-2 );
986 rect
.height
= dc
.GetCharHeight()+4;
987 Refresh( TRUE
, &rect
);