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"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem
, wxObject
)
26 wxTreeItem::wxTreeItem()
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
,wxCommandEvent
)
44 wxTreeEvent::wxTreeEvent( wxEventType commandType
, int id
) :
45 wxCommandEvent( commandType
, id
)
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeItem
,wxObject
)
57 wxGenericTreeItem::wxGenericTreeItem( wxGenericTreeItem
*parent
)
64 wxGenericTreeItem::wxGenericTreeItem( wxGenericTreeItem
*parent
, const wxTreeItem
& item
, wxDC
*dc
)
72 void wxGenericTreeItem::SetItem( const wxTreeItem
&item
, wxDC
*dc
)
74 if ((item
.m_mask
& wxTREE_MASK_HANDLE
) == wxTREE_MASK_HANDLE
)
75 m_itemId
= item
.m_itemId
;
76 if ((item
.m_mask
& wxTREE_MASK_STATE
) == wxTREE_MASK_STATE
)
77 m_state
= item
.m_state
;
78 if ((item
.m_mask
& wxTREE_MASK_TEXT
) == wxTREE_MASK_TEXT
)
80 if ((item
.m_mask
& wxTREE_MASK_IMAGE
) == wxTREE_MASK_IMAGE
)
81 m_image
= item
.m_image
;
82 if ((item
.m_mask
& wxTREE_MASK_SELECTED_IMAGE
) == wxTREE_MASK_SELECTED_IMAGE
)
83 m_selectedImage
= item
.m_selectedImage
;
84 if ((item
.m_mask
& wxTREE_MASK_CHILDREN
) == wxTREE_MASK_CHILDREN
)
85 m_hasChildren
= (item
.m_children
> 0);
86 if ((item
.m_mask
& wxTREE_MASK_DATA
) == wxTREE_MASK_DATA
)
90 dc
->GetTextExtent( m_text
, &lw
, &lh
);
95 void wxGenericTreeItem::SetText( const wxString
&text
, wxDC
*dc
)
100 dc
->GetTextExtent( m_text
, &lw
, &lh
);
105 void wxGenericTreeItem::Reset()
111 m_selectedImage
= -1;
113 m_hasChildren
= FALSE
;
122 m_children
.DeleteContents( TRUE
);
123 m_isCollapsed
= TRUE
;
127 void wxGenericTreeItem::GetItem( wxTreeItem
&item
) const
129 if ((item
.m_mask
& wxTREE_MASK_STATE
) == wxTREE_MASK_STATE
)
130 item
.m_state
= m_state
;
131 if ((item
.m_mask
& wxTREE_MASK_TEXT
) == wxTREE_MASK_TEXT
)
132 item
.m_text
= m_text
;
133 if ((item
.m_mask
& wxTREE_MASK_IMAGE
) == wxTREE_MASK_IMAGE
)
134 item
.m_image
= m_image
;
135 if ((item
.m_mask
& wxTREE_MASK_SELECTED_IMAGE
) == wxTREE_MASK_SELECTED_IMAGE
)
136 item
.m_selectedImage
= m_selectedImage
;
137 if ((item
.m_mask
& wxTREE_MASK_CHILDREN
) == wxTREE_MASK_CHILDREN
)
138 item
.m_children
= (int)m_hasChildren
;
139 if ((item
.m_mask
& wxTREE_MASK_DATA
) == wxTREE_MASK_DATA
)
140 item
.m_data
= m_data
;
143 bool wxGenericTreeItem::HasChildren()
145 return m_hasChildren
;
148 bool wxGenericTreeItem::HasPlus()
150 if ( !HasChildren() )
153 return !IsExpanded();
156 int wxGenericTreeItem::NumberOfVisibleDescendents()
158 int ret
= m_children
.Number();
159 wxNode
*node
= m_children
.First();
162 wxGenericTreeItem
*item
= (wxGenericTreeItem
*)node
->Data();
163 ret
+= item
->NumberOfVisibleDescendents();
169 int wxGenericTreeItem::NumberOfVisibleChildren()
171 return m_isCollapsed
? 0 : m_children
.Number();
174 wxGenericTreeItem
*wxGenericTreeItem::FindItem( long itemId
) const
176 if (m_itemId
== itemId
) return (wxGenericTreeItem
*)(this);
177 wxNode
*node
= m_children
.First();
180 wxGenericTreeItem
*item
= (wxGenericTreeItem
*)node
->Data();
181 wxGenericTreeItem
*res
= item
->FindItem( itemId
);
182 if (res
) return (wxGenericTreeItem
*)(res
);
188 void wxGenericTreeItem::AddChild( wxGenericTreeItem
*child
)
190 m_children
.Append( child
);
193 void wxGenericTreeItem::SetCross( int x
, int y
)
199 void wxGenericTreeItem::GetSize( int &x
, int &y
)
201 if (y
< m_y
+ 10) y
= m_y
+10;
202 int width
= m_x
+ m_width
;
203 if (width
> x
) x
= width
;
204 wxNode
*node
= m_children
.First();
207 wxGenericTreeItem
*item
= (wxGenericTreeItem
*)node
->Data();
208 item
->GetSize( x
, y
);
213 long wxGenericTreeItem::HitTest( const wxPoint
& point
, int &flags
)
215 if ((point
.y
> m_y
) && (point
.y
< m_y
+m_height
))
217 if ((point
.x
> m_xCross
-5) &&
218 (point
.x
< m_xCross
+5) &&
219 (point
.y
> m_yCross
-5) &&
220 (point
.y
< m_yCross
+5) &&
223 flags
= wxTREE_HITTEST_ONITEMBUTTON
;
226 if ((point
.x
> m_x
) && (point
.x
< m_x
+m_width
))
228 flags
= wxTREE_HITTEST_ONITEMLABEL
;
233 flags
= wxTREE_HITTEST_ONITEMRIGHT
;
236 flags
= wxTREE_HITTEST_ONITEMINDENT
;
243 wxNode
*node
= m_children
.First();
246 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
247 long res
= child
->HitTest( point
, flags
);
248 if (res
!= -1) return res
;
256 void wxGenericTreeItem::PrepareEvent( wxTreeEvent
&event
)
258 event
.m_item
.m_itemId
= m_itemId
;
259 event
.m_item
.m_state
= m_state
;
260 event
.m_item
.m_text
= m_text
;
261 event
.m_item
.m_image
= m_image
;
262 event
.m_item
.m_selectedImage
= m_selectedImage
;
263 event
.m_item
.m_children
= (int)m_hasChildren
;
264 event
.m_item
.m_data
= m_data
;
267 event
.m_pointDrag
.x
= 0;
268 event
.m_pointDrag
.y
= 0;
271 void wxGenericTreeItem::SendKeyDown( wxWindow
*target
)
273 wxTreeEvent
event( wxEVT_COMMAND_TREE_KEY_DOWN
, target
->GetId() );
274 PrepareEvent( event
);
275 event
.SetEventObject( target
);
276 target
->ProcessEvent( event
);
279 void wxGenericTreeItem::SendSelected( wxWindow
*target
)
281 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGED
, target
->GetId() );
282 PrepareEvent( event
);
283 event
.SetEventObject( target
);
284 target
->ProcessEvent( event
);
287 void wxGenericTreeItem::SendDelete( wxWindow
*target
)
289 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, target
->GetId() );
290 PrepareEvent( event
);
291 event
.SetEventObject( target
);
292 target
->ProcessEvent( event
);
295 void wxGenericTreeItem::SendExpand( wxWindow
*target
)
297 m_isCollapsed
= FALSE
;
299 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, target
->GetId() );
300 event
.SetEventObject( target
);
301 PrepareEvent( event
);
302 target
->ProcessEvent( event
);
304 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
305 PrepareEvent( event
);
306 target
->ProcessEvent( event
);
309 void wxGenericTreeItem::SendCollapse( wxWindow
*target
)
311 m_isCollapsed
= TRUE
;
313 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, target
->GetId() );
314 event
.SetEventObject( target
);
315 PrepareEvent( event
);
316 target
->ProcessEvent( event
);
318 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
319 PrepareEvent( event
);
320 target
->ProcessEvent( event
);
323 void wxGenericTreeItem::SetHilight( bool set
)
328 bool wxGenericTreeItem::HasHilight()
333 //-----------------------------------------------------------------------------
335 //-----------------------------------------------------------------------------
337 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
,wxScrolledWindow
)
339 BEGIN_EVENT_TABLE(wxTreeCtrl
,wxScrolledWindow
)
340 EVT_PAINT (wxTreeCtrl::OnPaint
)
341 EVT_MOUSE_EVENTS (wxTreeCtrl::OnMouse
)
342 EVT_CHAR (wxTreeCtrl::OnChar
)
343 EVT_SET_FOCUS (wxTreeCtrl::OnSetFocus
)
344 EVT_KILL_FOCUS (wxTreeCtrl::OnKillFocus
)
347 wxTreeCtrl::wxTreeCtrl()
358 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
360 m_smallImageList
= NULL
;
363 wxTreeCtrl::wxTreeCtrl(wxWindow
*parent
, wxWindowID id
,
364 const wxPoint
& pos
, const wxSize
& size
,
365 long style
, const wxString
& name
)
376 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
378 m_smallImageList
= NULL
;
379 Create( parent
, id
, pos
, size
, style
, name
);
382 wxTreeCtrl::~wxTreeCtrl()
386 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
,
387 const wxPoint
& pos
, const wxSize
& size
,
388 long style
, 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();
446 if (!p
->HasChildren()) p
->m_hasChildren
= TRUE
;
449 GetClientSize( NULL
, &ch
);
454 rect
.x
= dc
.LogicalToDeviceX( 0 );
459 if (p
->m_children
.Number() == 1)
461 rect
.y
= dc
.LogicalToDeviceY( p
->m_y
);
465 wxNode
*node
= p
->m_children
.Member( new_child
)->Previous();
466 wxGenericTreeItem
* last_child
= (wxGenericTreeItem
*)node
->Data();
467 rect
.y
= dc
.LogicalToDeviceY( last_child
->m_y
);
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();
525 if (!p
->HasChildren()) p
->m_hasChildren
= TRUE
;
528 GetClientSize( NULL
, &ch
);
533 rect
.x
= dc
.LogicalToDeviceX( 0 );
538 if (p
->m_children
.Number() == 1)
540 rect
.y
= dc
.LogicalToDeviceY( p
->m_y
);
544 wxNode
*node
= p
->m_children
.Member( new_child
)->Previous();
545 wxGenericTreeItem
* last_child
= (wxGenericTreeItem
*)node
->Data();
546 rect
.y
= dc
.LogicalToDeviceY( last_child
->m_y
);
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 ( child
->IsExpanded() )
586 ExpandItem( child
->m_itemId
, wxTREE_EXPAND_COLLAPSE
);
590 CalculatePositions();
592 i
->SendCollapse( this );
596 case wxTREE_EXPAND_TOGGLE
:
598 if ( i
->IsExpanded() )
599 ExpandItem( item
, wxTREE_EXPAND_COLLAPSE
);
601 ExpandItem( item
, wxTREE_EXPAND_EXPAND
);
611 GetClientSize( &cw
, &ch
);
614 rect
.x
= dc
.LogicalToDeviceX( 0 );
616 rect
.y
= dc
.LogicalToDeviceY( i
->m_y
);
618 Refresh( TRUE
, &rect
);
620 AdjustMyScrollbars();
625 void wxTreeCtrl::DeleteItem( long item
)
627 wxGenericTreeItem
*pItem
= FindItem( item
);
628 wxCHECK_RET( pItem
!= NULL
, _("wxTreeCtrl::DeleteItem: no such pItem.") );
630 pItem
->m_parent
->m_children
.DeleteObject(pItem
);
635 void wxTreeCtrl::DeleteChildren( long item
)
637 wxGenericTreeItem
*pItem
= FindItem( item
);
638 wxCHECK_RET( pItem
!= NULL
, _("wxTreeCtrl::DeleteChildren: no such pItem.") );
640 pItem
->m_children
.Clear();
645 bool wxTreeCtrl::DeleteAllItems()
653 bool wxTreeCtrl::GetItem( wxTreeItem
&info
) const
655 wxGenericTreeItem
*i
= FindItem( info
.m_itemId
);
656 if (!i
) return FALSE
;
661 long wxTreeCtrl::GetItemData( long item
) const
663 wxGenericTreeItem
*i
= FindItem( item
);
668 wxString
wxTreeCtrl::GetItemText( long item
) const
670 wxGenericTreeItem
*i
= FindItem( item
);
675 int wxTreeCtrl::GetItemImage(long item
) const
677 wxGenericTreeItem
*i
= FindItem( item
);
678 return i
== 0 ? -1 : i
->GetImage();
681 long wxTreeCtrl::GetParent( long item
) const
683 wxGenericTreeItem
*i
= FindItem( item
);
687 return i
->m_parent
->m_itemId
;
690 long wxTreeCtrl::GetRootItem() const
692 if (m_anchor
) return m_anchor
->m_itemId
;
696 long wxTreeCtrl::GetSelection() const
698 return m_current
? m_current
->GetItemId() : -1;
701 bool wxTreeCtrl::SelectItem(long itemId
)
703 wxGenericTreeItem
*pItem
= FindItem(itemId
);
705 wxLogDebug(_("Can't select an item %d which doesn't exist."), itemId
);
715 void wxTreeCtrl::SelectItem(wxGenericTreeItem
*item
)
717 if (m_current
!= item
)
721 m_current
->SetHilight( FALSE
);
722 RefreshLine( m_current
);
725 m_current
->SetHilight( TRUE
);
726 RefreshLine( m_current
);
728 m_current
->SendSelected( this );
732 bool wxTreeCtrl::ItemHasChildren( long item
) const
734 wxGenericTreeItem
*i
= FindItem( item
);
735 if (!i
) return FALSE
;
736 return i
->m_hasChildren
;
739 void wxTreeCtrl::SetIndent( int indent
)
745 int wxTreeCtrl::GetIndent() const
750 bool wxTreeCtrl::SetItem( wxTreeItem
&info
)
752 wxGenericTreeItem
*i
= FindItem( info
.m_itemId
);
753 if (!i
) return FALSE
;
755 i
->SetItem( info
, &dc
);
760 bool wxTreeCtrl::SetItemData( long item
, long data
)
762 wxGenericTreeItem
*i
= FindItem( item
);
763 if (!i
) return FALSE
;
768 bool wxTreeCtrl::SetItemText( long item
, const wxString
&text
)
770 wxGenericTreeItem
*i
= FindItem( item
);
771 if (!i
) return FALSE
;
773 i
->SetText( text
, &dc
);
777 void wxTreeCtrl::SetItemImage(long item
, int image
, int imageSel
) const
779 wxGenericTreeItem
*i
= FindItem( item
);
782 i
->SetSelectedImage(imageSel
);
786 long wxTreeCtrl::HitTest( const wxPoint
& point
, int &flags
)
789 if (!m_anchor
) return -1;
790 return m_anchor
->HitTest( point
, flags
);
793 wxImageList
*wxTreeCtrl::GetImageList( int which
) const
795 if (which
== wxIMAGE_LIST_NORMAL
) return m_imageList
;
796 return m_smallImageList
;
799 void wxTreeCtrl::SetImageList( wxImageList
*imageList
, int which
)
801 if (which
== wxIMAGE_LIST_NORMAL
)
803 if (m_imageList
) delete m_imageList
;
804 m_imageList
= imageList
;
808 if (m_smallImageList
) delete m_smallImageList
;
809 m_smallImageList
= imageList
;
813 void wxTreeCtrl::AdjustMyScrollbars()
819 m_anchor
->GetSize( x
, y
);
821 int x_pos
= GetScrollPos( wxHORIZONTAL
);
822 int y_pos
= GetScrollPos( wxVERTICAL
);
823 SetScrollbars( 10, 10, x
/10, y
/10, x_pos
, y_pos
);
827 SetScrollbars( 0, 0, 0, 0 );
831 void wxTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
)
833 int horizX
= level
*m_indent
;
835 item
->m_x
= horizX
+33;
836 item
->m_y
= y
-m_lineHeight
/3;
837 item
->m_height
= m_lineHeight
;
839 item
->SetCross( horizX
+15, y
);
843 int exposed_x
= dc
.LogicalToDeviceX( 0 );
844 int exposed_y
= dc
.LogicalToDeviceY( item
->m_y
-2 );
846 if (IsExposed( exposed_x
, exposed_y
, 1000, m_lineHeight
+4 ))
849 int endX
= horizX
+ 10;
851 if (!item
->HasChildren()) endX
+= 20;
853 dc
.DrawLine( startX
, y
, endX
, y
);
855 if (item
->HasChildren())
857 dc
.DrawLine( horizX
+20, y
, horizX
+30, y
);
858 dc
.SetPen( *wxGREY_PEN
);
859 dc
.DrawRectangle( horizX
+10, y
-4, 11, 9 );
860 dc
.SetPen( *wxBLACK_PEN
);
861 dc
.DrawLine( horizX
+13, y
, horizX
+18, y
);
863 dc
.DrawLine( horizX
+15, y
-2, horizX
+15, y
+3 );
866 if (item
->HasHilight())
868 dc
.SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
869 dc
.SetBrush( *m_hilightBrush
);
871 dc
.GetTextExtent( item
->m_text
, &tw
, &th
);
874 dc
.SetPen( *wxBLACK_PEN
);
875 dc
.DrawRectangle( item
->m_x
-2, item
->m_y
-2, tw
+4, th
+4 );
879 dc
.SetPen( *wxTRANSPARENT_PEN
);
880 dc
.DrawRectangle( item
->m_x
-2, item
->m_y
-2, tw
+4, th
+4 );
882 dc
.DrawText( item
->m_text
, item
->m_x
, item
->m_y
);
884 dc
.SetPen( *wxBLACK_PEN
);
885 dc
.SetTextForeground( *wxBLACK
);
886 dc
.SetBrush( *wxWHITE_BRUSH
);
890 dc
.SetBrush( *wxWHITE_BRUSH
);
891 dc
.SetPen( *wxTRANSPARENT_PEN
);
893 dc
.GetTextExtent( item
->m_text
, &tw
, &th
);
894 dc
.DrawRectangle( item
->m_x
-2, item
->m_y
-2, tw
+4, th
+4 );
895 dc
.DrawText( item
->m_text
, item
->m_x
, item
->m_y
);
896 dc
.SetPen( *wxBLACK_PEN
);
900 if (item
->NumberOfVisibleChildren() == 0) return;
904 wxNode
*node
= item
->m_children
.First();
907 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
912 PaintLevel( child
, dc
, level
+1, y
);
917 dc
.DrawLine( horizX
+15, oldY
+5, horizX
+15, semiOldY
);
920 void wxTreeCtrl::OnPaint( const wxPaintEvent
&WXUNUSED(event
) )
922 if (!m_anchor
) return;
927 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
929 dc
.SetPen( m_dottedPen
);
930 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
932 int y
= m_lineHeight
/ 2 + 2;
933 PaintLevel( m_anchor
, dc
, 0, y
);
936 void wxTreeCtrl::OnSetFocus( const wxFocusEvent
&WXUNUSED(event
) )
939 if (m_current
) RefreshLine( m_current
);
942 void wxTreeCtrl::OnKillFocus( const wxFocusEvent
&WXUNUSED(event
) )
945 if (m_current
) RefreshLine( m_current
);
948 void wxTreeCtrl::OnChar( wxKeyEvent
&event
)
953 void wxTreeCtrl::OnMouse( const wxMouseEvent
&event
)
955 if (!event
.LeftDown() &&
956 !event
.LeftDClick()) return;
960 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
961 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
964 long id
= HitTest( wxPoint(x
,y
), flag
);
967 wxGenericTreeItem
*item
= FindItem( id
);
970 if ((flag
!= wxTREE_HITTEST_ONITEMBUTTON
) &&
971 (flag
!= wxTREE_HITTEST_ONITEMLABEL
)) return;
975 if (event
.LeftDClick())
976 m_current
->SendKeyDown( this );
978 if (flag
== wxTREE_HITTEST_ONITEMBUTTON
)
980 ExpandItem( item
->m_itemId
, wxTREE_EXPAND_TOGGLE
);
985 void wxTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
)
987 int horizX
= level
*m_indent
;
989 item
->m_x
= horizX
+33;
990 item
->m_y
= y
-m_lineHeight
/3-2;
991 item
->m_height
= m_lineHeight
;
993 if (item
->NumberOfVisibleChildren() == 0) return;
995 wxNode
*node
= item
->m_children
.First();
998 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
1001 CalculateLevel( child
, dc
, level
+1, y
);
1003 node
= node
->Next();
1007 void wxTreeCtrl::CalculatePositions()
1012 wxClientDC
dc(this);
1015 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
1017 dc
.SetPen( m_dottedPen
);
1018 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
1020 int y
= m_lineHeight
/ 2 + 2;
1021 CalculateLevel( m_anchor
, dc
, 0, y
);
1024 wxGenericTreeItem
*wxTreeCtrl::FindItem( long itemId
) const
1026 if (!m_anchor
) return NULL
;
1027 return m_anchor
->FindItem( itemId
);
1030 void wxTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
1033 wxClientDC
dc(this);
1036 rect
.x
= dc
.LogicalToDeviceX( item
->m_x
-2 );
1037 rect
.y
= dc
.LogicalToDeviceY( item
->m_y
-2 );
1039 rect
.height
= dc
.GetCharHeight()+6;
1040 Refresh( TRUE
, &rect
);