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 bool wxTreeCtrl::DeleteAllItems()
638 bool wxTreeCtrl::GetItem( wxTreeItem
&info
) const
640 wxGenericTreeItem
*i
= FindItem( info
.m_itemId
);
641 if (!i
) return FALSE
;
646 long wxTreeCtrl::GetItemData( long item
) const
648 wxGenericTreeItem
*i
= FindItem( item
);
653 wxString
wxTreeCtrl::GetItemText( long item
) const
655 wxGenericTreeItem
*i
= FindItem( item
);
660 int wxTreeCtrl::GetItemImage(long item
) const
662 wxGenericTreeItem
*i
= FindItem( item
);
663 return i
== 0 ? -1 : i
->GetImage();
666 long wxTreeCtrl::GetParent( long item
) const
668 wxGenericTreeItem
*i
= FindItem( item
);
672 return i
->m_parent
->m_itemId
;
675 long wxTreeCtrl::GetRootItem() const
677 if (m_anchor
) return m_anchor
->m_itemId
;
681 long wxTreeCtrl::GetSelection() const
686 bool wxTreeCtrl::SelectItem( long WXUNUSED(item
) ) const
691 bool wxTreeCtrl::ItemHasChildren( long item
) const
693 wxGenericTreeItem
*i
= FindItem( item
);
694 if (!i
) return FALSE
;
695 return i
->m_hasChildren
;
698 void wxTreeCtrl::SetIndent( int indent
)
704 int wxTreeCtrl::GetIndent() const
709 bool wxTreeCtrl::SetItem( wxTreeItem
&info
)
711 wxGenericTreeItem
*i
= FindItem( info
.m_itemId
);
712 if (!i
) return FALSE
;
714 i
->SetItem( info
, &dc
);
719 bool wxTreeCtrl::SetItemData( long item
, long data
)
721 wxGenericTreeItem
*i
= FindItem( item
);
722 if (!i
) return FALSE
;
727 bool wxTreeCtrl::SetItemText( long item
, const wxString
&text
)
729 wxGenericTreeItem
*i
= FindItem( item
);
730 if (!i
) return FALSE
;
732 i
->SetText( text
, &dc
);
736 void wxTreeCtrl::SetItemImage(long item
, int image
, int imageSel
) const
738 wxGenericTreeItem
*i
= FindItem( item
);
741 i
->SetSelectedImage(imageSel
);
745 long wxTreeCtrl::HitTest( const wxPoint
& point
, int &flags
)
748 if (!m_anchor
) return -1;
749 return m_anchor
->HitTest( point
, flags
);
752 void wxTreeCtrl::AdjustMyScrollbars()
758 m_anchor
->GetSize( x
, y
);
760 int x_pos
= GetScrollPos( wxHORIZONTAL
);
761 int y_pos
= GetScrollPos( wxVERTICAL
);
762 SetScrollbars( 10, 10, x
/10, y
/10, x_pos
, y_pos
);
766 SetScrollbars( 0, 0, 0, 0 );
770 void wxTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
)
772 int horizX
= level
*m_indent
+10;
774 wxNode
*node
= item
->m_children
.First();
777 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
778 dc
.SetPen( m_dottedPen
);
780 child
->SetCross( horizX
+15, y
);
784 if (level
!= 0) oldY
-= (m_lineHeight
-5);
785 dc
.DrawLine( horizX
, oldY
, horizX
, y
);
788 child
->m_x
= horizX
+33;
789 child
->m_y
= y
-m_lineHeight
/3;
790 child
->m_height
= m_lineHeight
;
792 if (IsExposed( 0, child
->m_y
-2, 10000, m_lineHeight
+4 ))
797 if (!(node
->Previous()) && (level
== 0))
799 if (!child
->HasChildren())
801 dc
.DrawLine( startX
, y
, endX
, y
);
803 if (child
->HasChildren())
805 dc
.DrawLine( horizX
+20, y
, horizX
+30, y
);
806 dc
.SetPen( *wxGREY_PEN
);
807 dc
.DrawRectangle( horizX
+10, y
-4, 11, 9 );
808 dc
.SetPen( *wxBLACK_PEN
);
809 dc
.DrawLine( horizX
+13, y
, horizX
+17, y
);
810 if (child
->HasPlus())
811 dc
.DrawLine( horizX
+15, y
-2, horizX
+15, y
+2 );
814 if (child
->HasHilight())
816 dc
.SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
817 #if 0 // VZ: this code leaves horizontal stripes when item is unselected
818 dc
.SetBrush( *m_hilightBrush
);
820 dc
.SetPen( wxBLACK_PEN
);
822 dc
.SetPen( wxTRANSPARENT_PEN
);
824 dc
.GetTextExtent( child
->m_text
, &tw
, &th
);
825 dc
.DrawRectangle( child
->m_x
-2, child
->m_y
-2, tw
+4, th
+4 );
827 int modeOld
= dc
.GetBackgroundMode();
828 dc
.SetTextBackground( *wxBLACK
);
829 dc
.SetBackgroundMode(wxSOLID
);
832 dc
.DrawText( child
->m_text
, child
->m_x
, child
->m_y
);
834 #if 0 // VZ: same as above
835 dc
.SetPen( *wxBLACK_PEN
);
837 dc
.SetBackgroundMode(modeOld
);
838 dc
.SetTextBackground( *wxWHITE
);
839 dc
.SetBrush( *wxWHITE_BRUSH
);
841 dc
.SetTextForeground( *wxBLACK
);
844 dc
.DrawText( child
->m_text
, child
->m_x
, child
->m_y
);
848 if ( child
->IsExpanded() && child
->NumberOfVisibleChildren() > 0)
849 PaintLevel( child
, dc
, level
+1, y
);
854 void wxTreeCtrl::OnPaint( const wxPaintEvent
&WXUNUSED(event
) )
856 if (!m_anchor
) return;
860 m_dc
= new wxPaintDC(this);
864 m_dc
->SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
866 m_dc
->SetPen( m_dottedPen
);
867 m_lineHeight
= (int)(m_dc
->GetCharHeight() + 4);
869 int y
= m_lineHeight
/ 2 + 2;
870 PaintLevel( m_anchor
, *m_dc
, 0, y
);
873 void wxTreeCtrl::OnSetFocus( const wxFocusEvent
&WXUNUSED(event
) )
876 if (m_current
) RefreshLine( m_current
);
879 void wxTreeCtrl::OnKillFocus( const wxFocusEvent
&WXUNUSED(event
) )
882 if (m_current
) RefreshLine( m_current
);
885 void wxTreeCtrl::OnChar( wxKeyEvent
&event
)
890 void wxTreeCtrl::OnMouse( const wxMouseEvent
&event
)
892 if (!event
.LeftDown() &&
893 !event
.LeftDClick()) return;
897 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
898 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
901 long id
= HitTest( wxPoint(x
,y
), flag
);
904 wxGenericTreeItem
*item
= FindItem( id
);
907 if ((flag
!= wxTREE_HITTEST_ONITEMBUTTON
) &&
908 (flag
!= wxTREE_HITTEST_ONITEMLABEL
)) return;
910 if (m_current
!= item
)
914 m_current
->SetHilight( FALSE
);
915 RefreshLine( m_current
);
918 m_current
->SetHilight( TRUE
);
919 RefreshLine( m_current
);
920 m_current
->SendSelected( this );
923 if (event
.LeftDClick())
924 m_current
->SendKeyDown( this );
926 if (flag
== wxTREE_HITTEST_ONITEMBUTTON
)
928 ExpandItem( item
->m_itemId
, wxTREE_EXPAND_TOGGLE
);
933 void wxTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
)
935 int horizX
= level
*m_indent
+10;
936 wxNode
*node
= item
->m_children
.First();
939 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
940 dc
.SetPen( m_dottedPen
);
945 if (!node
->Previous() && (level
== 0))
947 if (!child
->HasChildren())
950 child
->m_x
= horizX
+33;
951 child
->m_y
= y
-m_lineHeight
/3-2;
952 child
->m_height
= m_lineHeight
;
955 if ( child
->IsExpanded() && child
->NumberOfVisibleChildren() > 0 )
956 CalculateLevel( child
, dc
, level
+1, y
);
962 void wxTreeCtrl::CalculatePositions()
970 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
972 dc
.SetPen( m_dottedPen
);
973 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
975 int y
= m_lineHeight
/ 2 + 2;
976 CalculateLevel( m_anchor
, dc
, 0, y
);
979 wxGenericTreeItem
*wxTreeCtrl::FindItem( long itemId
) const
981 if (!m_anchor
) return NULL
;
982 return m_anchor
->FindItem( itemId
);
985 void wxTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
991 rect
.x
= dc
.LogicalToDeviceX( item
->m_x
-2 );
992 rect
.y
= dc
.LogicalToDeviceY( item
->m_y
-2 );
994 rect
.height
= dc
.GetCharHeight()+4;
995 Refresh( TRUE
, &rect
);