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"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem
, wxObject
)
25 wxTreeItem::wxTreeItem()
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
,wxCommandEvent
)
43 wxTreeEvent::wxTreeEvent( wxEventType commandType
, int id
) :
44 wxCommandEvent( commandType
, id
)
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeItem
,wxObject
)
56 wxGenericTreeItem::wxGenericTreeItem( wxGenericTreeItem
*parent
)
63 wxGenericTreeItem::wxGenericTreeItem( wxGenericTreeItem
*parent
, const wxTreeItem
& item
, wxDC
*dc
)
71 void wxGenericTreeItem::SetItem( const wxTreeItem
&item
, wxDC
*dc
)
73 if ((item
.m_mask
& wxTREE_MASK_HANDLE
) == wxTREE_MASK_HANDLE
)
74 m_itemId
= item
.m_itemId
;
75 if ((item
.m_mask
& wxTREE_MASK_STATE
) == wxTREE_MASK_STATE
)
76 m_state
= item
.m_state
;
77 if ((item
.m_mask
& wxTREE_MASK_TEXT
) == wxTREE_MASK_TEXT
)
79 if ((item
.m_mask
& wxTREE_MASK_IMAGE
) == wxTREE_MASK_IMAGE
)
80 m_image
= item
.m_image
;
81 if ((item
.m_mask
& wxTREE_MASK_SELECTED_IMAGE
) == wxTREE_MASK_SELECTED_IMAGE
)
82 m_selectedImage
= item
.m_selectedImage
;
83 if ((item
.m_mask
& wxTREE_MASK_CHILDREN
) == wxTREE_MASK_CHILDREN
)
84 m_hasChildren
= (item
.m_children
> 0);
85 if ((item
.m_mask
& wxTREE_MASK_DATA
) == wxTREE_MASK_DATA
)
89 dc
->GetTextExtent( m_text
, &lw
, &lh
);
94 void wxGenericTreeItem::SetText( const wxString
&text
, wxDC
*dc
)
99 dc
->GetTextExtent( m_text
, &lw
, &lh
);
104 void wxGenericTreeItem::Reset()
110 m_selectedImage
= -1;
112 m_hasChildren
= FALSE
;
121 m_children
.DeleteContents( TRUE
);
122 m_isCollapsed
= TRUE
;
126 void wxGenericTreeItem::GetItem( wxTreeItem
&item
) const
128 if ((item
.m_mask
& wxTREE_MASK_STATE
) == wxTREE_MASK_STATE
)
129 item
.m_state
= m_state
;
130 if ((item
.m_mask
& wxTREE_MASK_TEXT
) == wxTREE_MASK_TEXT
)
131 item
.m_text
= m_text
;
132 if ((item
.m_mask
& wxTREE_MASK_IMAGE
) == wxTREE_MASK_IMAGE
)
133 item
.m_image
= m_image
;
134 if ((item
.m_mask
& wxTREE_MASK_SELECTED_IMAGE
) == wxTREE_MASK_SELECTED_IMAGE
)
135 item
.m_selectedImage
= m_selectedImage
;
136 if ((item
.m_mask
& wxTREE_MASK_CHILDREN
) == wxTREE_MASK_CHILDREN
)
137 item
.m_children
= (int)m_hasChildren
;
138 if ((item
.m_mask
& wxTREE_MASK_DATA
) == wxTREE_MASK_DATA
)
139 item
.m_data
= m_data
;
142 bool wxGenericTreeItem::HasChildren()
144 return m_hasChildren
;
147 bool wxGenericTreeItem::HasPlus()
149 if ( !HasChildren() )
152 return !IsExpanded();
155 int wxGenericTreeItem::NumberOfVisibleDescendents()
157 int ret
= m_children
.Number();
158 wxNode
*node
= m_children
.First();
161 wxGenericTreeItem
*item
= (wxGenericTreeItem
*)node
->Data();
162 ret
+= item
->NumberOfVisibleDescendents();
168 int wxGenericTreeItem::NumberOfVisibleChildren()
170 return m_isCollapsed
? 0 : m_children
.Number();
173 wxGenericTreeItem
*wxGenericTreeItem::FindItem( long itemId
) const
175 if (m_itemId
== itemId
) return (wxGenericTreeItem
*)(this);
176 wxNode
*node
= m_children
.First();
179 wxGenericTreeItem
*item
= (wxGenericTreeItem
*)node
->Data();
180 wxGenericTreeItem
*res
= item
->FindItem( itemId
);
181 if (res
) return (wxGenericTreeItem
*)(res
);
187 void wxGenericTreeItem::AddChild( wxGenericTreeItem
*child
)
189 m_children
.Append( child
);
192 void wxGenericTreeItem::SetCross( int x
, int y
)
198 void wxGenericTreeItem::GetSize( int &x
, int &y
)
200 if (y
< m_y
+ 10) y
= m_y
+10;
201 int width
= m_x
+ m_width
;
202 if (width
> x
) x
= width
;
203 wxNode
*node
= m_children
.First();
206 wxGenericTreeItem
*item
= (wxGenericTreeItem
*)node
->Data();
207 item
->GetSize( x
, y
);
212 long wxGenericTreeItem::HitTest( const wxPoint
& point
, int &flags
)
214 if ((point
.y
> m_y
) && (point
.y
< m_y
+m_height
))
216 if ((point
.x
> m_xCross
-5) &&
217 (point
.x
< m_xCross
+5) &&
218 (point
.y
> m_yCross
-5) &&
219 (point
.y
< m_yCross
+5) &&
222 flags
= wxTREE_HITTEST_ONITEMBUTTON
;
225 if ((point
.x
> m_x
) && (point
.x
< m_x
+m_width
))
227 flags
= wxTREE_HITTEST_ONITEMLABEL
;
232 flags
= wxTREE_HITTEST_ONITEMRIGHT
;
235 flags
= wxTREE_HITTEST_ONITEMINDENT
;
242 wxNode
*node
= m_children
.First();
245 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
246 long res
= child
->HitTest( point
, flags
);
247 if (res
!= -1) return res
;
255 void wxGenericTreeItem::PrepareEvent( wxTreeEvent
&event
)
257 event
.m_item
.m_itemId
= m_itemId
;
258 event
.m_item
.m_state
= m_state
;
259 event
.m_item
.m_text
= m_text
;
260 event
.m_item
.m_image
= m_image
;
261 event
.m_item
.m_selectedImage
= m_selectedImage
;
262 event
.m_item
.m_children
= (int)m_hasChildren
;
263 event
.m_item
.m_data
= m_data
;
266 event
.m_pointDrag
.x
= 0;
267 event
.m_pointDrag
.y
= 0;
270 void wxGenericTreeItem::SendKeyDown( wxWindow
*target
)
272 wxTreeEvent
event( wxEVT_COMMAND_TREE_KEY_DOWN
, target
->GetId() );
273 PrepareEvent( event
);
274 event
.SetEventObject( target
);
275 target
->ProcessEvent( event
);
278 void wxGenericTreeItem::SendSelected( wxWindow
*target
)
280 wxTreeEvent
event( wxEVT_COMMAND_TREE_SEL_CHANGED
, target
->GetId() );
281 PrepareEvent( event
);
282 event
.SetEventObject( target
);
283 target
->ProcessEvent( event
);
286 void wxGenericTreeItem::SendDelete( wxWindow
*target
)
288 wxTreeEvent
event( wxEVT_COMMAND_TREE_DELETE_ITEM
, target
->GetId() );
289 PrepareEvent( event
);
290 event
.SetEventObject( target
);
291 target
->ProcessEvent( event
);
294 void wxGenericTreeItem::SendExpand( wxWindow
*target
)
296 m_isCollapsed
= FALSE
;
298 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_EXPANDING
, target
->GetId() );
299 event
.SetEventObject( target
);
300 PrepareEvent( event
);
301 target
->ProcessEvent( event
);
303 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED
);
304 PrepareEvent( event
);
305 target
->ProcessEvent( event
);
308 void wxGenericTreeItem::SendCollapse( wxWindow
*target
)
310 m_isCollapsed
= TRUE
;
312 wxTreeEvent
event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, target
->GetId() );
313 event
.SetEventObject( target
);
314 PrepareEvent( event
);
315 target
->ProcessEvent( event
);
317 event
.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
318 PrepareEvent( event
);
319 target
->ProcessEvent( event
);
322 void wxGenericTreeItem::SetHilight( bool set
)
327 bool wxGenericTreeItem::HasHilight()
332 //-----------------------------------------------------------------------------
334 //-----------------------------------------------------------------------------
336 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
,wxScrolledWindow
)
338 BEGIN_EVENT_TABLE(wxTreeCtrl
,wxScrolledWindow
)
339 EVT_PAINT (wxTreeCtrl::OnPaint
)
340 EVT_MOUSE_EVENTS (wxTreeCtrl::OnMouse
)
341 EVT_CHAR (wxTreeCtrl::OnChar
)
342 EVT_SET_FOCUS (wxTreeCtrl::OnSetFocus
)
343 EVT_KILL_FOCUS (wxTreeCtrl::OnKillFocus
)
346 wxTreeCtrl::wxTreeCtrl()
357 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
359 m_smallImageList
= NULL
;
362 wxTreeCtrl::wxTreeCtrl(wxWindow
*parent
, wxWindowID id
,
363 const wxPoint
& pos
, const wxSize
& size
,
364 long style
, const wxString
& name
)
375 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
377 m_smallImageList
= NULL
;
378 Create( parent
, id
, pos
, size
, style
, name
);
381 wxTreeCtrl::~wxTreeCtrl()
385 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
,
386 const wxPoint
& pos
, const wxSize
& size
,
387 long style
, const wxString
& name
)
389 wxScrolledWindow::Create( parent
, id
, pos
, size
, style
, name
);
390 SetBackgroundColour( *wxWHITE
);
391 m_dottedPen
= wxPen( *wxBLACK
, 0, 0 );
395 int wxTreeCtrl::GetCount() const
397 if (!m_anchor
) return 0;
398 return m_anchor
->NumberOfVisibleDescendents();
401 long wxTreeCtrl::InsertItem( long parent
, const wxString
& label
, int image
,
402 int selImage
, long WXUNUSED(insertAfter
) )
404 wxGenericTreeItem
*p
= NULL
;
407 if (m_anchor
) return -1;
411 p
= FindItem( parent
);
416 item
.m_mask
= wxTREE_MASK_HANDLE
;
417 item
.m_itemId
= m_lastId
;
418 if (!label
.IsNull() || (label
== ""))
421 item
.m_mask
|= wxTREE_MASK_TEXT
;
425 item
.m_image
= image
;
426 item
.m_mask
|= wxTREE_MASK_IMAGE
;
430 item
.m_selectedImage
= selImage
;
431 item
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
435 wxGenericTreeItem
*new_child
= new wxGenericTreeItem( p
, item
, &dc
);
437 p
->AddChild( new_child
);
439 m_anchor
= new_child
;
443 CalculatePositions();
445 if (!p
->HasChildren()) p
->m_hasChildren
= TRUE
;
448 GetClientSize( NULL
, &ch
);
453 rect
.x
= dc
.LogicalToDeviceX( 0 );
458 if (p
->m_children
.Number() == 1)
460 rect
.y
= dc
.LogicalToDeviceY( p
->m_y
);
464 wxNode
*node
= p
->m_children
.Member( new_child
)->Previous();
465 wxGenericTreeItem
* last_child
= (wxGenericTreeItem
*)node
->Data();
466 rect
.y
= dc
.LogicalToDeviceY( last_child
->m_y
);
469 AdjustMyScrollbars();
471 if (rect
.height
> 0) Refresh( FALSE
, &rect
);
475 AdjustMyScrollbars();
483 long wxTreeCtrl::InsertItem( long parent
, wxTreeItem
&info
, long WXUNUSED(insertAfter
) )
485 int oldMask
= info
.m_mask
;
486 wxGenericTreeItem
*p
= NULL
;
489 if (m_anchor
) return -1;
493 p
= FindItem( parent
);
496 printf( "TreeItem not found.\n" );
501 if ((info
.m_mask
& wxTREE_MASK_HANDLE
) == 0)
504 info
.m_itemId
= m_lastId
;
505 info
.m_mask
|= wxTREE_MASK_HANDLE
;
514 wxGenericTreeItem
*new_child
= new wxGenericTreeItem( p
, info
, &dc
);
516 p
->AddChild( new_child
);
518 m_anchor
= new_child
;
522 CalculatePositions();
524 if (!p
->HasChildren()) p
->m_hasChildren
= TRUE
;
527 GetClientSize( NULL
, &ch
);
532 rect
.x
= dc
.LogicalToDeviceX( 0 );
537 if (p
->m_children
.Number() == 1)
539 rect
.y
= dc
.LogicalToDeviceY( p
->m_y
);
543 wxNode
*node
= p
->m_children
.Member( new_child
)->Previous();
544 wxGenericTreeItem
* last_child
= (wxGenericTreeItem
*)node
->Data();
545 rect
.y
= dc
.LogicalToDeviceY( last_child
->m_y
);
548 AdjustMyScrollbars();
550 if (rect
.height
> 0) Refresh( FALSE
, &rect
);
554 AdjustMyScrollbars();
559 info
.m_mask
= oldMask
;
563 bool wxTreeCtrl::ExpandItem( long item
, int action
)
565 wxGenericTreeItem
*i
= FindItem( item
);
571 case wxTREE_EXPAND_EXPAND
:
573 i
->SendExpand( this );
577 case wxTREE_EXPAND_COLLAPSE_RESET
:
578 case wxTREE_EXPAND_COLLAPSE
:
580 wxNode
*node
= i
->m_children
.First();
583 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
584 if ( child
->IsExpanded() )
585 ExpandItem( child
->m_itemId
, wxTREE_EXPAND_COLLAPSE
);
589 CalculatePositions();
591 i
->SendCollapse( this );
595 case wxTREE_EXPAND_TOGGLE
:
597 if ( i
->IsExpanded() )
598 ExpandItem( item
, wxTREE_EXPAND_COLLAPSE
);
600 ExpandItem( item
, wxTREE_EXPAND_EXPAND
);
610 GetClientSize( &cw
, &ch
);
613 rect
.x
= dc
.LogicalToDeviceX( 0 );
615 rect
.y
= dc
.LogicalToDeviceY( i
->m_y
);
617 Refresh( TRUE
, &rect
);
619 AdjustMyScrollbars();
624 void wxTreeCtrl::DeleteItem( long item
)
626 wxGenericTreeItem
*pItem
= FindItem( item
);
627 wxCHECK_RET( pItem
!= NULL
, "wxTreeCtrl::DeleteItem: no such pItem." );
629 pItem
->m_parent
->m_children
.DeleteObject(pItem
);
634 void wxTreeCtrl::DeleteChildren( long item
)
636 wxGenericTreeItem
*pItem
= FindItem( item
);
637 wxCHECK_RET( pItem
!= NULL
, "wxTreeCtrl::DeleteChildren: no such pItem." );
639 pItem
->m_children
.Clear();
644 bool wxTreeCtrl::DeleteAllItems()
652 bool wxTreeCtrl::GetItem( wxTreeItem
&info
) const
654 wxGenericTreeItem
*i
= FindItem( info
.m_itemId
);
655 if (!i
) return FALSE
;
660 long wxTreeCtrl::GetItemData( long item
) const
662 wxGenericTreeItem
*i
= FindItem( item
);
667 wxString
wxTreeCtrl::GetItemText( long item
) const
669 wxGenericTreeItem
*i
= FindItem( item
);
674 int wxTreeCtrl::GetItemImage(long item
) const
676 wxGenericTreeItem
*i
= FindItem( item
);
677 return i
== 0 ? -1 : i
->GetImage();
680 long wxTreeCtrl::GetParent( long item
) const
682 wxGenericTreeItem
*i
= FindItem( item
);
686 return i
->m_parent
->m_itemId
;
689 long wxTreeCtrl::GetRootItem() const
691 if (m_anchor
) return m_anchor
->m_itemId
;
695 long wxTreeCtrl::GetSelection() const
697 return m_current
? m_current
->GetItemId() : -1;
700 bool wxTreeCtrl::SelectItem(long itemId
)
702 wxGenericTreeItem
*pItem
= FindItem(itemId
);
704 wxLogDebug("Can't select an item %d which doesn't exist.", itemId
);
714 void wxTreeCtrl::SelectItem(wxGenericTreeItem
*item
, bool bDoEvents
)
716 if (m_current
!= item
)
720 m_current
->SetHilight( FALSE
);
721 RefreshLine( m_current
);
724 m_current
->SetHilight( TRUE
);
725 RefreshLine( m_current
);
727 if (bDoEvents
) m_current
->SendSelected( this );
731 bool wxTreeCtrl::ItemHasChildren( long item
) const
733 wxGenericTreeItem
*i
= FindItem( item
);
734 if (!i
) return FALSE
;
735 return i
->m_hasChildren
;
738 void wxTreeCtrl::SetIndent( int indent
)
744 int wxTreeCtrl::GetIndent() const
749 bool wxTreeCtrl::SetItem( wxTreeItem
&info
)
751 wxGenericTreeItem
*i
= FindItem( info
.m_itemId
);
752 if (!i
) return FALSE
;
754 i
->SetItem( info
, &dc
);
759 bool wxTreeCtrl::SetItemData( long item
, long data
)
761 wxGenericTreeItem
*i
= FindItem( item
);
762 if (!i
) return FALSE
;
767 bool wxTreeCtrl::SetItemText( long item
, const wxString
&text
)
769 wxGenericTreeItem
*i
= FindItem( item
);
770 if (!i
) return FALSE
;
772 i
->SetText( text
, &dc
);
776 void wxTreeCtrl::SetItemImage(long item
, int image
, int imageSel
) const
778 wxGenericTreeItem
*i
= FindItem( item
);
781 i
->SetSelectedImage(imageSel
);
785 long wxTreeCtrl::HitTest( const wxPoint
& point
, int &flags
)
788 if (!m_anchor
) return -1;
789 return m_anchor
->HitTest( point
, flags
);
792 wxImageList
*wxTreeCtrl::GetImageList( int which
) const
794 if (which
== wxIMAGE_LIST_NORMAL
) return m_imageList
;
795 return m_smallImageList
;
798 void wxTreeCtrl::SetImageList( wxImageList
*imageList
, int which
)
800 if (which
== wxIMAGE_LIST_NORMAL
)
802 if (m_imageList
) delete m_imageList
;
803 m_imageList
= imageList
;
807 if (m_smallImageList
) delete m_smallImageList
;
808 m_smallImageList
= imageList
;
812 void wxTreeCtrl::AdjustMyScrollbars()
818 m_anchor
->GetSize( x
, y
);
820 int x_pos
= GetScrollPos( wxHORIZONTAL
);
821 int y_pos
= GetScrollPos( wxVERTICAL
);
822 SetScrollbars( 10, 10, x
/10, y
/10, x_pos
, y_pos
);
826 SetScrollbars( 0, 0, 0, 0 );
830 void wxTreeCtrl::PaintLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
)
832 int horizX
= level
*m_indent
;
834 item
->m_x
= horizX
+33;
835 item
->m_y
= y
-m_lineHeight
/3;
836 item
->m_height
= m_lineHeight
;
838 item
->SetCross( horizX
+15, y
);
842 int exposed_x
= dc
.LogicalToDeviceX( 0 );
843 int exposed_y
= dc
.LogicalToDeviceY( item
->m_y
-2 );
845 if (IsExposed( exposed_x
, exposed_y
, 1000, m_lineHeight
+4 ))
848 int endX
= horizX
+ 10;
850 if (!item
->HasChildren()) endX
+= 20;
852 dc
.DrawLine( startX
, y
, endX
, y
);
854 if (item
->HasChildren())
856 dc
.DrawLine( horizX
+20, y
, horizX
+30, y
);
857 dc
.SetPen( *wxGREY_PEN
);
858 dc
.DrawRectangle( horizX
+10, y
-4, 11, 9 );
859 dc
.SetPen( *wxBLACK_PEN
);
860 dc
.DrawLine( horizX
+13, y
, horizX
+18, y
);
862 dc
.DrawLine( horizX
+15, y
-2, horizX
+15, y
+3 );
865 if (item
->HasHilight())
867 dc
.SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
868 dc
.SetBrush( *m_hilightBrush
);
870 dc
.GetTextExtent( item
->m_text
, &tw
, &th
);
873 dc
.SetPen( *wxBLACK_PEN
);
874 dc
.DrawRectangle( item
->m_x
-2, item
->m_y
-2, tw
+4, th
+4 );
878 dc
.SetPen( *wxTRANSPARENT_PEN
);
879 dc
.DrawRectangle( item
->m_x
-2, item
->m_y
-2, tw
+4, th
+4 );
881 dc
.DrawText( item
->m_text
, item
->m_x
, item
->m_y
);
883 dc
.SetPen( *wxBLACK_PEN
);
884 dc
.SetTextForeground( *wxBLACK
);
885 dc
.SetBrush( *wxWHITE_BRUSH
);
889 dc
.SetBrush( *wxWHITE_BRUSH
);
890 dc
.SetPen( *wxTRANSPARENT_PEN
);
892 dc
.GetTextExtent( item
->m_text
, &tw
, &th
);
893 dc
.DrawRectangle( item
->m_x
-2, item
->m_y
-2, tw
+4, th
+4 );
894 dc
.DrawText( item
->m_text
, item
->m_x
, item
->m_y
);
895 dc
.SetPen( *wxBLACK_PEN
);
899 if (item
->NumberOfVisibleChildren() == 0) return;
903 wxNode
*node
= item
->m_children
.First();
906 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
911 PaintLevel( child
, dc
, level
+1, y
);
916 dc
.DrawLine( horizX
+15, oldY
+5, horizX
+15, semiOldY
);
919 void wxTreeCtrl::OnPaint( const wxPaintEvent
&WXUNUSED(event
) )
921 if (!m_anchor
) return;
926 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
928 dc
.SetPen( m_dottedPen
);
929 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
931 int y
= m_lineHeight
/ 2 + 2;
932 PaintLevel( m_anchor
, dc
, 0, y
);
935 void wxTreeCtrl::OnSetFocus( const wxFocusEvent
&WXUNUSED(event
) )
938 if (m_current
) RefreshLine( m_current
);
941 void wxTreeCtrl::OnKillFocus( const wxFocusEvent
&WXUNUSED(event
) )
944 if (m_current
) RefreshLine( m_current
);
947 void wxTreeCtrl::OnChar( wxKeyEvent
&event
)
952 void wxTreeCtrl::OnMouse( const wxMouseEvent
&event
)
954 if (!event
.LeftDown() &&
955 !event
.LeftDClick()) return;
959 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
960 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
963 long id
= HitTest( wxPoint(x
,y
), flag
);
966 wxGenericTreeItem
*item
= FindItem( id
);
969 if ((flag
!= wxTREE_HITTEST_ONITEMBUTTON
) &&
970 (flag
!= wxTREE_HITTEST_ONITEMLABEL
)) return;
974 if (event
.LeftDClick())
975 m_current
->SendKeyDown( this );
977 if (flag
== wxTREE_HITTEST_ONITEMBUTTON
)
979 ExpandItem( item
->m_itemId
, wxTREE_EXPAND_TOGGLE
);
984 void wxTreeCtrl::CalculateLevel( wxGenericTreeItem
*item
, wxPaintDC
&dc
, int level
, int &y
)
986 int horizX
= level
*m_indent
;
988 item
->m_x
= horizX
+33;
989 item
->m_y
= y
-m_lineHeight
/3-2;
990 item
->m_height
= m_lineHeight
;
992 if (item
->NumberOfVisibleChildren() == 0) return;
994 wxNode
*node
= item
->m_children
.First();
997 wxGenericTreeItem
*child
= (wxGenericTreeItem
*)node
->Data();
1000 CalculateLevel( child
, dc
, level
+1, y
);
1002 node
= node
->Next();
1006 void wxTreeCtrl::CalculatePositions()
1011 wxClientDC
dc(this);
1014 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
1016 dc
.SetPen( m_dottedPen
);
1017 m_lineHeight
= (int)(dc
.GetCharHeight() + 4);
1019 int y
= m_lineHeight
/ 2 + 2;
1020 CalculateLevel( m_anchor
, dc
, 0, y
);
1023 wxGenericTreeItem
*wxTreeCtrl::FindItem( long itemId
) const
1025 if (!m_anchor
) return NULL
;
1026 return m_anchor
->FindItem( itemId
);
1029 void wxTreeCtrl::RefreshLine( wxGenericTreeItem
*item
)
1032 wxClientDC
dc(this);
1035 rect
.x
= dc
.LogicalToDeviceX( item
->m_x
-2 );
1036 rect
.y
= dc
.LogicalToDeviceY( item
->m_y
-2 );
1038 rect
.height
= dc
.GetCharHeight()+6;
1039 Refresh( TRUE
, &rect
);