1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/datavgen.cpp
3 // Purpose: wxDataViewCtrl generic implementation
4 // Author: Robert Roebling
5 // Modified by: Francesco Montorsi, Guru Kathiresan, Bo Yang
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_DATAVIEWCTRL
20 #include "wx/dataview.h"
22 #ifdef wxUSE_GENERICDATAVIEWCTRL
26 #include "wx/msw/private.h"
27 #include "wx/msw/wrapwin.h"
28 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/msgdlg.h"
36 #include "wx/dcscreen.h"
40 #include "wx/stockitem.h"
41 #include "wx/calctrl.h"
42 #include "wx/popupwin.h"
43 #include "wx/renderer.h"
44 #include "wx/dcbuffer.h"
47 #include "wx/listimpl.cpp"
48 #include "wx/imaglist.h"
49 #include "wx/headerctrl.h"
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
58 static const int SCROLL_UNIT_X
= 15;
60 // the cell padding on the left/right
61 static const int PADDING_RIGHTLEFT
= 3;
63 // the expander space margin
64 static const int EXPANDER_MARGIN
= 4;
67 static const int EXPANDER_OFFSET
= 4;
69 static const int EXPANDER_OFFSET
= 1;
72 // Below is the compare stuff.
73 // For the generic implementation, both the leaf nodes and the nodes are sorted for
74 // fast search when needed
75 static wxDataViewModel
* g_model
;
76 static int g_column
= -2;
77 static bool g_asending
= true;
79 //-----------------------------------------------------------------------------
80 // wxDataViewHeaderWindow
81 //-----------------------------------------------------------------------------
83 class wxDataViewHeaderWindow
: public wxHeaderCtrl
86 wxDataViewHeaderWindow(wxDataViewCtrl
*parent
)
87 : wxHeaderCtrl(parent
)
91 wxDataViewCtrl
*GetOwner() const
92 { return static_cast<wxDataViewCtrl
*>(GetParent()); }
95 // implement/override wxHeaderCtrl functions by forwarding them to the main
97 virtual const wxHeaderColumn
& GetColumn(unsigned int idx
) const
99 return *(GetOwner()->GetColumn(idx
));
102 // FIXME: currently unused
103 virtual bool UpdateColumnWidthToFit(unsigned int idx
, int widthTitle
)
105 wxDataViewCtrl
* const owner
= GetOwner();
107 int widthContents
= owner
->GetBestColumnWidth(idx
);
108 owner
->GetColumn(idx
)->SetWidth(wxMax(widthTitle
, widthContents
));
109 owner
->OnColumnChange(idx
);
115 bool SendEvent(wxEventType type
, unsigned int n
)
117 wxDataViewCtrl
* const owner
= GetOwner();
118 wxDataViewEvent
event(type
, owner
->GetId());
120 event
.SetEventObject(owner
);
122 event
.SetDataViewColumn(owner
->GetColumn(n
));
123 event
.SetModel(owner
->GetModel());
125 // for events created by wxDataViewHeaderWindow the
126 // row / value fields are not valid
127 return owner
->GetEventHandler()->ProcessEvent(event
);
130 void OnClick(wxHeaderCtrlEvent
& event
)
132 const unsigned idx
= event
.GetColumn();
134 if ( SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, idx
) )
137 // default handling for the column click is to sort by this column or
138 // toggle its sort order
139 wxDataViewCtrl
* const owner
= GetOwner();
140 wxDataViewColumn
* const col
= owner
->GetColumn(idx
);
141 if ( !col
->IsSortable() )
143 // no default handling for non-sortable columns
148 if ( col
->IsSortKey() )
150 // already using this column for sorting, just change the order
151 col
->ToggleSortOrder();
153 else // not using this column for sorting yet
155 // first unset the old sort column if any
156 int oldSortKey
= owner
->GetSortingColumnIndex();
157 if ( oldSortKey
!= wxNOT_FOUND
)
159 owner
->GetColumn(oldSortKey
)->UnsetAsSortKey();
160 owner
->OnColumnChange(oldSortKey
);
163 owner
->SetSortingColumnIndex(idx
);
167 wxDataViewModel
* const model
= owner
->GetModel();
171 owner
->OnColumnChange(idx
);
174 void OnRClick(wxHeaderCtrlEvent
& event
)
176 if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
181 void OnResize(wxHeaderCtrlEvent
& event
)
183 wxDataViewCtrl
* const owner
= GetOwner();
185 const unsigned col
= event
.GetColumn();
186 owner
->GetColumn(col
)->SetWidth(event
.GetWidth());
187 GetOwner()->OnColumnChange(col
);
190 void OnEndReorder(wxHeaderCtrlEvent
& event
)
192 wxDataViewCtrl
* const owner
= GetOwner();
193 owner
->ColumnMoved(owner
->GetColumn(event
.GetColumn()),
194 event
.GetNewOrder());
197 DECLARE_EVENT_TABLE()
198 wxDECLARE_NO_COPY_CLASS(wxDataViewHeaderWindow
);
201 BEGIN_EVENT_TABLE(wxDataViewHeaderWindow
, wxHeaderCtrl
)
202 EVT_HEADER_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnClick
)
203 EVT_HEADER_RIGHT_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnRClick
)
205 EVT_HEADER_RESIZING(wxID_ANY
, wxDataViewHeaderWindow::OnResize
)
206 EVT_HEADER_END_RESIZE(wxID_ANY
, wxDataViewHeaderWindow::OnResize
)
208 EVT_HEADER_END_REORDER(wxID_ANY
, wxDataViewHeaderWindow::OnEndReorder
)
211 //-----------------------------------------------------------------------------
212 // wxDataViewRenameTimer
213 //-----------------------------------------------------------------------------
215 class wxDataViewRenameTimer
: public wxTimer
218 wxDataViewMainWindow
*m_owner
;
221 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
225 //-----------------------------------------------------------------------------
226 // wxDataViewTreeNode
227 //-----------------------------------------------------------------------------
229 class wxDataViewTreeNode
;
230 WX_DEFINE_ARRAY( wxDataViewTreeNode
*, wxDataViewTreeNodes
);
231 WX_DEFINE_ARRAY( void* , wxDataViewTreeLeaves
);
233 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
,
234 wxDataViewTreeNode
** node2
);
235 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
);
237 class wxDataViewTreeNode
240 wxDataViewTreeNode( wxDataViewTreeNode
* parent
= NULL
)
247 m_hasChildren
= false;
251 ~wxDataViewTreeNode()
255 wxDataViewTreeNode
* GetParent() const { return m_parent
; }
256 void SetParent( wxDataViewTreeNode
* parent
) { m_parent
= parent
; }
257 wxDataViewTreeNodes
& GetNodes() { return m_nodes
; }
258 wxDataViewTreeLeaves
& GetChildren() { return m_leaves
; }
260 void AddNode( wxDataViewTreeNode
* node
)
262 m_leaves
.Add( node
->GetItem().GetID() );
264 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
267 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
269 void AddLeaf( void * leaf
)
271 m_leaves
.Add( leaf
);
273 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
276 wxDataViewItem
& GetItem() { return m_item
; }
277 const wxDataViewItem
& GetItem() const { return m_item
; }
278 void SetItem( const wxDataViewItem
& item
) { m_item
= item
; }
280 unsigned int GetChildrenNumber() const { return m_leaves
.GetCount(); }
281 unsigned int GetNodeNumber() const { return m_nodes
.GetCount(); }
282 int GetIndentLevel() const
285 const wxDataViewTreeNode
* node
= this;
286 while( node
->GetParent()->GetParent() != NULL
)
288 node
= node
->GetParent();
301 int len
= m_nodes
.GetCount();
303 for ( int i
= 0;i
< len
; i
++)
304 sum
+= m_nodes
[i
]->GetSubTreeCount();
306 sum
+= m_leaves
.GetCount();
309 ChangeSubTreeCount(-sum
);
315 ChangeSubTreeCount(sum
);
318 bool HasChildren() const { return m_hasChildren
; }
319 void SetHasChildren( bool has
){ m_hasChildren
= has
; }
321 void SetSubTreeCount( int num
) { m_subTreeCount
= num
; }
322 int GetSubTreeCount() const { return m_subTreeCount
; }
323 void ChangeSubTreeCount( int num
)
327 m_subTreeCount
+= num
;
329 m_parent
->ChangeSubTreeCount(num
);
336 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
337 int len
= m_nodes
.GetCount();
338 for (int i
= 0; i
< len
; i
++)
339 m_nodes
[i
]->Resort();
340 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
345 wxDataViewTreeNode
*m_parent
;
346 wxDataViewTreeNodes m_nodes
;
347 wxDataViewTreeLeaves m_leaves
;
348 wxDataViewItem m_item
;
354 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
,
355 wxDataViewTreeNode
** node2
)
357 return g_model
->Compare( (*node1
)->GetItem(), (*node2
)->GetItem(), g_column
, g_asending
);
360 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
)
362 return g_model
->Compare( *id1
, *id2
, g_column
, g_asending
);
366 //-----------------------------------------------------------------------------
367 // wxDataViewMainWindow
368 //-----------------------------------------------------------------------------
370 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
,
372 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
373 WX_DEFINE_LIST(ItemList
)
375 class wxDataViewMainWindow
: public wxWindow
378 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
380 const wxPoint
&pos
= wxDefaultPosition
,
381 const wxSize
&size
= wxDefaultSize
,
382 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
383 virtual ~wxDataViewMainWindow();
385 bool IsVirtualList() const { return m_root
== NULL
; }
387 // notifications from wxDataViewModel
388 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
389 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
390 bool ItemChanged( const wxDataViewItem
&item
);
391 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
395 if (!IsVirtualList())
405 g_model
= GetOwner()->GetModel();
406 wxDataViewColumn
* col
= GetOwner()->GetSortingColumn();
409 if (g_model
->HasDefaultCompare())
417 g_column
= col
->GetModelColumn();
418 g_asending
= col
->IsSortOrderAscending();
421 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
422 wxDataViewCtrl
*GetOwner() { return m_owner
; }
423 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
425 #if wxUSE_DRAG_AND_DROP
426 wxBitmap
CreateItemBitmap( unsigned int row
, int &indent
);
427 #endif // wxUSE_DRAG_AND_DROP
428 void OnPaint( wxPaintEvent
&event
);
429 void OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
);
430 void OnChar( wxKeyEvent
&event
);
431 void OnMouse( wxMouseEvent
&event
);
432 void OnSetFocus( wxFocusEvent
&event
);
433 void OnKillFocus( wxFocusEvent
&event
);
435 void UpdateDisplay();
436 void RecalculateDisplay();
437 void OnInternalIdle();
439 void OnRenameTimer();
441 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
442 void ScrollTo( int rows
, int column
);
444 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
445 void ChangeCurrentRow( unsigned int row
);
447 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
448 bool IsEmpty() { return GetRowCount() == 0; }
450 int GetCountPerPage() const;
451 int GetEndOfLastCol() const;
452 unsigned int GetFirstVisibleRow() const;
454 // I change this method to un const because in the tree view,
455 // the displaying number of the tree are changing along with the
456 // expanding/collapsing of the tree nodes
457 unsigned int GetLastVisibleRow();
458 unsigned int GetRowCount();
460 wxDataViewItem
GetSelection() const;
461 wxDataViewSelection
GetSelections(){ return m_selection
; }
462 void SetSelections( const wxDataViewSelection
& sel
)
463 { m_selection
= sel
; UpdateDisplay(); }
464 void Select( const wxArrayInt
& aSelections
);
465 void SelectAllRows( bool on
);
466 void SelectRow( unsigned int row
, bool on
);
467 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
468 void ReverseRowSelection( unsigned int row
);
469 bool IsRowSelected( unsigned int row
);
470 void SendSelectionChangedEvent( const wxDataViewItem
& item
);
472 void RefreshRow( unsigned int row
);
473 void RefreshRows( unsigned int from
, unsigned int to
);
474 void RefreshRowsAfter( unsigned int firstRow
);
476 // returns the colour to be used for drawing the rules
477 wxColour
GetRuleColour() const
479 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
482 wxRect
GetLineRect( unsigned int row
) const;
484 int GetLineStart( unsigned int row
) const; // row * m_lineHeight in fixed mode
485 int GetLineHeight( unsigned int row
) const; // m_lineHeight in fixed mode
486 int GetLineAt( unsigned int y
) const; // y / m_lineHeight in fixed mode
488 // Some useful functions for row and item mapping
489 wxDataViewItem
GetItemByRow( unsigned int row
) const;
490 int GetRowByItem( const wxDataViewItem
& item
) const;
492 // Methods for building the mapping tree
493 void BuildTree( wxDataViewModel
* model
);
495 void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
);
496 wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
);
498 void Expand( unsigned int row
);
499 void Collapse( unsigned int row
);
500 bool IsExpanded( unsigned int row
) const;
501 bool HasChildren( unsigned int row
) const;
503 #if wxUSE_DRAG_AND_DROP
504 bool EnableDragSource( const wxDataFormat
&format
);
505 bool EnableDropTarget( const wxDataFormat
&format
);
507 void RemoveDropHint();
508 wxDragResult
OnDragOver( wxDataFormat format
, wxCoord x
, wxCoord y
, wxDragResult def
);
509 bool OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
);
510 wxDragResult
OnData( wxDataFormat format
, wxCoord x
, wxCoord y
, wxDragResult def
);
512 #endif // wxUSE_DRAG_AND_DROP
515 wxDataViewTreeNode
* GetTreeNodeByRow( unsigned int row
) const;
516 // We did not need this temporarily
517 // wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
519 int RecalculateCount();
521 wxDataViewEvent
SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
);
523 wxDataViewTreeNode
* FindNode( const wxDataViewItem
& item
);
526 wxDataViewCtrl
*m_owner
;
530 wxDataViewColumn
*m_currentCol
;
531 unsigned int m_currentRow
;
532 wxDataViewSelection m_selection
;
534 wxDataViewRenameTimer
*m_renameTimer
;
539 #if wxUSE_DRAG_AND_DROP
544 wxDataFormat m_dragFormat
;
547 wxDataFormat m_dropFormat
;
549 unsigned int m_dropHintLine
;
550 #endif // wxUSE_DRAG_AND_DROP
552 // for double click logic
553 unsigned int m_lineLastClicked
,
554 m_lineBeforeLastClicked
,
555 m_lineSelectSingleOnUp
;
557 // the pen used to draw horiz/vertical rules
560 // the pen used to draw the expander and the lines
563 // This is the tree structure of the model
564 wxDataViewTreeNode
* m_root
;
567 // This is the tree node under the cursor
568 wxDataViewTreeNode
* m_underMouse
;
571 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
572 DECLARE_EVENT_TABLE()
575 // ---------------------------------------------------------
576 // wxGenericDataViewModelNotifier
577 // ---------------------------------------------------------
579 class wxGenericDataViewModelNotifier
: public wxDataViewModelNotifier
582 wxGenericDataViewModelNotifier( wxDataViewMainWindow
*mainWindow
)
583 { m_mainWindow
= mainWindow
; }
585 virtual bool ItemAdded( const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
586 { return m_mainWindow
->ItemAdded( parent
, item
); }
587 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
588 { return m_mainWindow
->ItemDeleted( parent
, item
); }
589 virtual bool ItemChanged( const wxDataViewItem
& item
)
590 { return m_mainWindow
->ItemChanged(item
); }
591 virtual bool ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
592 { return m_mainWindow
->ValueChanged( item
, col
); }
593 virtual bool Cleared()
594 { return m_mainWindow
->Cleared(); }
595 virtual void Resort()
596 { m_mainWindow
->Resort(); }
598 wxDataViewMainWindow
*m_mainWindow
;
601 // ---------------------------------------------------------
602 // wxDataViewRenderer
603 // ---------------------------------------------------------
605 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
607 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
608 wxDataViewCellMode mode
,
610 wxDataViewRendererBase( varianttype
, mode
, align
)
617 wxDataViewRenderer::~wxDataViewRenderer()
623 wxDC
*wxDataViewRenderer::GetDC()
627 if (GetOwner() == NULL
)
629 if (GetOwner()->GetOwner() == NULL
)
631 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
637 void wxDataViewRenderer::SetAlignment( int align
)
642 int wxDataViewRenderer::GetAlignment() const
647 int wxDataViewRenderer::CalculateAlignment() const
649 if (m_align
== wxDVR_DEFAULT_ALIGNMENT
)
651 if (GetOwner() == NULL
)
652 return wxALIGN_LEFT
| wxALIGN_CENTRE_VERTICAL
;
654 return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
660 // ---------------------------------------------------------
661 // wxDataViewCustomRenderer
662 // ---------------------------------------------------------
664 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
666 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
667 wxDataViewCellMode mode
, int align
) :
668 wxDataViewRenderer( varianttype
, mode
, align
)
672 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
,
673 wxRect cell
, wxDC
*dc
, int state
)
675 wxColour col
= state
& wxDATAVIEW_CELL_SELECTED
676 ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
)
677 : GetOwner()->GetOwner()->GetForegroundColour();
679 wxDataViewItemAttr attr
;
681 RenderText(*dc
, cell
, text
, &attr
, state
, xoffset
);
685 wxDataViewCustomRenderer::RenderText(wxDC
& dc
,
687 const wxString
& text
,
688 const wxDataViewItemAttr
*attr
,
692 wxDCTextColourChanger
changeFg(dc
);
693 if ( attr
&& attr
->HasColour() )
694 changeFg
.Set(attr
->GetColour());
696 wxDCFontChanger
changeFont(dc
);
697 if ( attr
&& attr
->HasFont() )
699 wxFont
font(dc
.GetFont());
700 if ( attr
->GetBold() )
702 if ( attr
->GetItalic() )
705 changeFont
.Set(font
);
710 rect
.y
+ ((rect
.height
- dc
.GetCharHeight()) / 2));
713 // ---------------------------------------------------------
714 // wxDataViewTextRenderer
715 // ---------------------------------------------------------
717 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
719 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
720 wxDataViewCellMode mode
, int align
) :
721 wxDataViewCustomRenderer( varianttype
, mode
, align
)
725 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
727 m_text
= value
.GetString();
732 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
737 bool wxDataViewTextRenderer::HasEditorCtrl() const
742 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
743 wxRect labelRect
, const wxVariant
&value
)
745 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, value
,
746 wxPoint(labelRect
.x
,labelRect
.y
),
747 wxSize(labelRect
.width
,labelRect
.height
) );
749 // select the text in the control an place the cursor at the end
750 ctrl
->SetInsertionPointEnd();
756 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
758 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
759 value
= text
->GetValue();
764 wxDataViewTextRenderer::RenderWithAttr(wxDC
& dc
,
766 const wxDataViewItemAttr
*attr
,
769 RenderText(dc
, rect
, m_text
, attr
, state
);
773 wxSize
wxDataViewTextRenderer::GetSize() const
775 const wxDataViewCtrl
*view
= GetView();
777 return view
->wxWindowBase::GetTextExtent( m_text
);
778 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
781 // ---------------------------------------------------------
782 // wxDataViewBitmapRenderer
783 // ---------------------------------------------------------
785 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
787 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
788 wxDataViewCellMode mode
, int align
) :
789 wxDataViewCustomRenderer( varianttype
, mode
, align
)
793 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
795 if (value
.GetType() == wxT("wxBitmap"))
797 if (value
.GetType() == wxT("wxIcon"))
803 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
808 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
811 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
812 else if (m_icon
.Ok())
813 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
818 wxSize
wxDataViewBitmapRenderer::GetSize() const
821 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
822 else if (m_icon
.Ok())
823 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
825 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
828 // ---------------------------------------------------------
829 // wxDataViewToggleRenderer
830 // ---------------------------------------------------------
832 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
834 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
835 wxDataViewCellMode mode
, int align
) :
836 wxDataViewCustomRenderer( varianttype
, mode
, align
)
841 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
843 m_toggle
= value
.GetBool();
848 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
853 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
857 flags
|= wxCONTROL_CHECKED
;
858 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
859 flags
|= wxCONTROL_DISABLED
;
861 wxRendererNative::Get().DrawCheckBox(
862 GetOwner()->GetOwner(),
870 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
871 wxDataViewModel
*model
,
872 const wxDataViewItem
& item
, unsigned int col
)
874 bool value
= !m_toggle
;
875 wxVariant variant
= value
;
876 model
->SetValue( variant
, item
, col
);
877 model
->ValueChanged( item
, col
);
881 wxSize
wxDataViewToggleRenderer::GetSize() const
883 // the window parameter is not used by GetCheckBoxSize() so it's
885 return wxRendererNative::Get().GetCheckBoxSize(NULL
);
888 // ---------------------------------------------------------
889 // wxDataViewProgressRenderer
890 // ---------------------------------------------------------
892 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
894 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
895 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
896 wxDataViewCustomRenderer( varianttype
, mode
, align
)
902 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
906 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
908 m_value
= (long) value
;
910 if (m_value
< 0) m_value
= 0;
911 if (m_value
> 100) m_value
= 100;
916 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
918 value
= (long) m_value
;
922 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
924 double pct
= (double)m_value
/ 100.0;
926 bar
.width
= (int)(cell
.width
* pct
);
927 dc
->SetPen( *wxTRANSPARENT_PEN
);
928 dc
->SetBrush( *wxBLUE_BRUSH
);
929 dc
->DrawRectangle( bar
);
931 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
932 dc
->SetPen( *wxBLACK_PEN
);
933 dc
->DrawRectangle( cell
);
938 wxSize
wxDataViewProgressRenderer::GetSize() const
940 return wxSize(40,12);
943 // ---------------------------------------------------------
944 // wxDataViewDateRenderer
945 // ---------------------------------------------------------
947 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
949 #if wxUSE_DATE_RENDERER_POPUP
951 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
954 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
955 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
) :
956 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
),
961 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
962 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
963 sizer
->Add( m_cal
, 1, wxGROW
);
968 void OnCalendar( wxCalendarEvent
&event
);
970 wxCalendarCtrl
*m_cal
;
971 wxDataViewModel
*m_model
;
973 const wxDataViewItem
& m_item
;
976 virtual void OnDismiss()
981 DECLARE_EVENT_TABLE()
984 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
985 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
988 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
990 wxDateTime date
= event
.GetDate();
991 wxVariant value
= date
;
992 m_model
->SetValue( value
, m_item
, m_col
);
993 m_model
->ValueChanged( m_item
, m_col
);
997 #endif // wxUSE_DATE_RENDERER_POPUP
999 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1001 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1002 wxDataViewCellMode mode
, int align
) :
1003 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1007 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1009 m_date
= value
.GetDateTime();
1014 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1020 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1022 wxString tmp
= m_date
.FormatDate();
1023 RenderText( tmp
, 0, cell
, dc
, state
);
1027 wxSize
wxDataViewDateRenderer::GetSize() const
1029 const wxDataViewCtrl
* view
= GetView();
1030 wxString tmp
= m_date
.FormatDate();
1032 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1033 return wxSize(x
,y
+d
);
1036 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
1037 const wxDataViewItem
& item
, unsigned int col
)
1040 model
->GetValue( variant
, item
, col
);
1041 wxDateTime value
= variant
.GetDateTime();
1043 #if wxUSE_DATE_RENDERER_POPUP
1044 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1045 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1046 wxPoint pos
= wxGetMousePosition();
1049 popup
->Popup( popup
->m_cal
);
1050 #else // !wxUSE_DATE_RENDERER_POPUP
1051 wxMessageBox(value
.Format());
1052 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
1056 // ---------------------------------------------------------
1057 // wxDataViewIconTextRenderer
1058 // ---------------------------------------------------------
1060 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1062 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1063 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1064 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1067 SetAlignment(align
);
1070 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1074 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1080 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1085 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1088 const wxIcon
&icon
= m_value
.GetIcon();
1091 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ ((cell
.height
- icon
.GetHeight()) / 2));
1092 xoffset
= icon
.GetWidth()+4;
1095 RenderText( m_value
.GetText(), xoffset
, cell
, dc
, state
);
1100 wxSize
wxDataViewIconTextRenderer::GetSize() const
1102 const wxDataViewCtrl
*view
= GetView();
1103 if (!m_value
.GetText().empty())
1106 view
->GetTextExtent( m_value
.GetText(), &x
, &y
);
1108 if (m_value
.GetIcon().IsOk())
1109 x
+= m_value
.GetIcon().GetWidth() + 4;
1110 return wxSize( x
, y
);
1112 return wxSize(80,20);
1115 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1117 wxDataViewIconText iconText
;
1120 wxString text
= iconText
.GetText();
1122 // adjust the label rect to take the width of the icon into account
1123 if (iconText
.GetIcon().IsOk())
1125 int w
= iconText
.GetIcon().GetWidth() + 4;
1127 labelRect
.width
-= w
;
1130 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, text
,
1131 wxPoint(labelRect
.x
,labelRect
.y
),
1132 wxSize(labelRect
.width
,labelRect
.height
) );
1134 // select the text in the control an place the cursor at the end
1135 ctrl
->SetInsertionPointEnd();
1141 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
& value
)
1143 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
1145 wxDataViewIconText
iconText(text
->GetValue(), m_value
.GetIcon());
1150 //-----------------------------------------------------------------------------
1151 // wxDataViewDropTarget
1152 //-----------------------------------------------------------------------------
1154 #if wxUSE_DRAG_AND_DROP
1156 class wxBitmapCanvas
: public wxWindow
1159 wxBitmapCanvas( wxWindow
*parent
, const wxBitmap
&bitmap
, const wxSize
&size
) :
1160 wxWindow( parent
, wxID_ANY
, wxPoint(0,0), size
)
1163 Connect( wxEVT_PAINT
, wxPaintEventHandler(wxBitmapCanvas::OnPaint
) );
1166 void OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1169 dc
.DrawBitmap( m_bitmap
, 0, 0);
1175 class wxDataViewDropSource
: public wxDropSource
1178 wxDataViewDropSource( wxDataViewMainWindow
*win
, unsigned int row
) :
1186 ~wxDataViewDropSource()
1191 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
) )
1193 wxPoint pos
= wxGetMousePosition();
1197 int liney
= m_win
->GetLineStart( m_row
);
1199 m_win
->GetOwner()->CalcUnscrolledPosition( 0, liney
, NULL
, &liney
);
1200 m_win
->ClientToScreen( &linex
, &liney
);
1201 m_dist_x
= pos
.x
- linex
;
1202 m_dist_y
= pos
.y
- liney
;
1205 wxBitmap ib
= m_win
->CreateItemBitmap( m_row
, indent
);
1207 m_hint
= new wxFrame( m_win
->GetParent(), wxID_ANY
, wxEmptyString
,
1208 wxPoint(pos
.x
- m_dist_x
, pos
.y
+ 5 ),
1210 wxFRAME_TOOL_WINDOW
|
1211 wxFRAME_FLOAT_ON_PARENT
|
1212 wxFRAME_NO_TASKBAR
|
1214 new wxBitmapCanvas( m_hint
, ib
, ib
.GetSize() );
1219 m_hint
->Move( pos
.x
- m_dist_x
, pos
.y
+ 5 );
1220 m_hint
->SetTransparent( 128 );
1226 wxDataViewMainWindow
*m_win
;
1229 int m_dist_x
,m_dist_y
;
1233 class wxDataViewDropTarget
: public wxDropTarget
1236 wxDataViewDropTarget( wxDataObject
*obj
, wxDataViewMainWindow
*win
) :
1242 virtual wxDragResult
OnDragOver( wxCoord x
, wxCoord y
, wxDragResult def
)
1244 wxDataFormat format
= GetMatchingPair();
1245 if (format
== wxDF_INVALID
)
1247 return m_win
->OnDragOver( format
, x
, y
, def
);
1250 virtual bool OnDrop( wxCoord x
, wxCoord y
)
1252 wxDataFormat format
= GetMatchingPair();
1253 if (format
== wxDF_INVALID
)
1255 return m_win
->OnDrop( format
, x
, y
);
1258 virtual wxDragResult
OnData( wxCoord x
, wxCoord y
, wxDragResult def
)
1260 wxDataFormat format
= GetMatchingPair();
1261 if (format
== wxDF_INVALID
)
1265 return m_win
->OnData( format
, x
, y
, def
);
1268 virtual void OnLeave()
1269 { m_win
->OnLeave(); }
1271 wxDataViewMainWindow
*m_win
;
1274 #endif // wxUSE_DRAG_AND_DROP
1276 //-----------------------------------------------------------------------------
1277 // wxDataViewRenameTimer
1278 //-----------------------------------------------------------------------------
1280 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1285 void wxDataViewRenameTimer::Notify()
1287 m_owner
->OnRenameTimer();
1290 //-----------------------------------------------------------------------------
1291 // wxDataViewMainWindow
1292 //-----------------------------------------------------------------------------
1294 // The tree building helper, declared firstly
1295 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
1296 wxDataViewTreeNode
* node
);
1298 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1300 if (row1
> row2
) return 1;
1301 if (row1
== row2
) return 0;
1305 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1307 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1308 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1309 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1310 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1311 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1312 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1315 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1316 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1317 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
1318 m_selection( wxDataViewSelectionCmp
)
1323 m_lastOnSame
= false;
1324 m_renameTimer
= new wxDataViewRenameTimer( this );
1326 // TODO: user better initial values/nothing selected
1327 m_currentCol
= NULL
;
1330 m_lineHeight
= wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
1332 #if wxUSE_DRAG_AND_DROP
1334 m_dragStart
= wxPoint(0,0);
1336 m_dragEnabled
= false;
1337 m_dropEnabled
= false;
1339 m_dropHintLine
= (unsigned int) -1;
1340 #endif // wxUSE_DRAG_AND_DROP
1342 m_lineLastClicked
= (unsigned int) -1;
1343 m_lineBeforeLastClicked
= (unsigned int) -1;
1344 m_lineSelectSingleOnUp
= (unsigned int) -1;
1348 SetBackgroundColour( *wxWHITE
);
1350 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1352 m_penRule
= wxPen(GetRuleColour());
1354 // compose a pen whichcan draw black lines
1355 // TODO: maybe there is something system colour to use
1356 m_penExpander
= wxPen(wxColour(0,0,0));
1358 m_root
= new wxDataViewTreeNode( NULL
);
1359 m_root
->SetHasChildren(true);
1361 // Make m_count = -1 will cause the class recaculate the real displaying number of rows.
1363 m_underMouse
= NULL
;
1367 wxDataViewMainWindow::~wxDataViewMainWindow()
1370 delete m_renameTimer
;
1374 #if wxUSE_DRAG_AND_DROP
1375 bool wxDataViewMainWindow::EnableDragSource( const wxDataFormat
&format
)
1377 m_dragFormat
= format
;
1378 m_dragEnabled
= format
!= wxDF_INVALID
;
1383 bool wxDataViewMainWindow::EnableDropTarget( const wxDataFormat
&format
)
1385 m_dropFormat
= format
;
1386 m_dropEnabled
= format
!= wxDF_INVALID
;
1389 SetDropTarget( new wxDataViewDropTarget( new wxCustomDataObject( format
), this ) );
1394 void wxDataViewMainWindow::RemoveDropHint()
1399 RefreshRow( m_dropHintLine
);
1400 m_dropHintLine
= (unsigned int) -1;
1404 wxDragResult
wxDataViewMainWindow::OnDragOver( wxDataFormat format
, wxCoord x
,
1405 wxCoord y
, wxDragResult def
)
1409 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1410 unsigned int row
= GetLineAt( yy
);
1412 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1418 wxDataViewItem item
= GetItemByRow( row
);
1420 wxDataViewModel
*model
= GetOwner()->GetModel();
1422 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1423 event
.SetEventObject( m_owner
);
1424 event
.SetItem( item
);
1425 event
.SetModel( model
);
1426 event
.SetDataFormat( format
);
1427 if (!m_owner
->HandleWindowEvent( event
))
1433 if (!event
.IsAllowed())
1440 if (m_dropHint
&& (row
!= m_dropHintLine
))
1441 RefreshRow( m_dropHintLine
);
1443 m_dropHintLine
= row
;
1449 bool wxDataViewMainWindow::OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
)
1455 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1456 unsigned int row
= GetLineAt( yy
);
1458 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1461 wxDataViewItem item
= GetItemByRow( row
);
1463 wxDataViewModel
*model
= GetOwner()->GetModel();
1465 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1466 event
.SetEventObject( m_owner
);
1467 event
.SetItem( item
);
1468 event
.SetModel( model
);
1469 event
.SetDataFormat( format
);
1470 if (!m_owner
->HandleWindowEvent( event
))
1473 if (!event
.IsAllowed())
1479 wxDragResult
wxDataViewMainWindow::OnData( wxDataFormat format
, wxCoord x
, wxCoord y
,
1484 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1485 unsigned int row
= GetLineAt( yy
);
1487 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1490 wxDataViewItem item
= GetItemByRow( row
);
1492 wxDataViewModel
*model
= GetOwner()->GetModel();
1494 wxCustomDataObject
*obj
= (wxCustomDataObject
*) GetDropTarget()->GetDataObject();
1496 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
1497 event
.SetEventObject( m_owner
);
1498 event
.SetItem( item
);
1499 event
.SetModel( model
);
1500 event
.SetDataFormat( format
);
1501 event
.SetDataSize( obj
->GetSize() );
1502 event
.SetDataBuffer( obj
->GetData() );
1503 if (!m_owner
->HandleWindowEvent( event
))
1506 if (!event
.IsAllowed())
1512 void wxDataViewMainWindow::OnLeave()
1517 wxBitmap
wxDataViewMainWindow::CreateItemBitmap( unsigned int row
, int &indent
)
1519 int height
= GetLineHeight( row
);
1521 unsigned int cols
= GetOwner()->GetColumnCount();
1523 for (col
= 0; col
< cols
; col
++)
1525 wxDataViewColumn
*column
= GetOwner()->GetColumnAt(col
);
1526 if (column
->IsHidden())
1527 continue; // skip it!
1528 width
+= column
->GetWidth();
1532 if (!IsVirtualList())
1534 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
1535 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
1536 indent
= indent
+ m_lineHeight
;
1537 // try to use the m_lineHeight as the expander space
1539 if(!node
->HasChildren())
1544 wxBitmap
bitmap( width
, height
);
1545 wxMemoryDC
dc( bitmap
);
1546 dc
.SetFont( GetFont() );
1547 dc
.SetPen( *wxBLACK_PEN
);
1548 dc
.SetBrush( *wxWHITE_BRUSH
);
1549 dc
.DrawRectangle( 0,0,width
,height
);
1551 wxDataViewModel
*model
= m_owner
->GetModel();
1553 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1556 // TODO-RTL: last column for RTL support
1557 expander
= GetOwner()->GetColumnAt( 0 );
1558 GetOwner()->SetExpanderColumn(expander
);
1563 for (col
= 0; col
< cols
; col
++)
1565 wxDataViewColumn
*column
= GetOwner()->GetColumnAt( col
);
1566 wxDataViewRenderer
*cell
= column
->GetRenderer();
1568 if (column
->IsHidden())
1569 continue; // skip it!
1571 width
= column
->GetWidth();
1573 if (column
== expander
)
1577 wxDataViewItem item
= GetItemByRow( row
);
1578 model
->GetValue( value
, item
, column
->GetModelColumn());
1579 cell
->SetValue( value
);
1581 wxSize size
= cell
->GetSize();
1582 size
.x
= wxMin( 2*PADDING_RIGHTLEFT
+ size
.x
, width
);
1584 wxRect
item_rect(x
, 0, size
.x
, size
.y
);
1586 int align
= cell
->CalculateAlignment();
1587 // horizontal alignment:
1589 if (align
& wxALIGN_CENTER_HORIZONTAL
)
1590 item_rect
.x
= x
+ (width
/ 2) - (size
.x
/ 2);
1591 else if (align
& wxALIGN_RIGHT
)
1592 item_rect
.x
= x
+ width
- size
.x
;
1593 // else: wxALIGN_LEFT is the default
1595 // vertical alignment:
1597 if (align
& wxALIGN_CENTER_VERTICAL
)
1598 item_rect
.y
= (height
/ 2) - (size
.y
/ 2);
1599 else if (align
& wxALIGN_BOTTOM
)
1600 item_rect
.y
= height
- size
.y
;
1601 // else: wxALIGN_TOP is the default
1604 item_rect
.x
+= PADDING_RIGHTLEFT
;
1605 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
1607 // dc.SetClippingRegion( item_rect );
1608 wxDataViewItemAttr attr
;
1610 hasAttr
= model
->GetAttr(item
, column
->GetModelColumn(), attr
);
1611 cell
->RenderWithAttr(dc
, item_rect
, hasAttr
? &attr
: NULL
, 0);
1612 // dc.DestroyClippingRegion();
1620 #endif // wxUSE_DRAG_AND_DROP
1623 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1625 wxDataViewModel
*model
= GetOwner()->GetModel();
1626 wxAutoBufferedPaintDC
dc( this );
1629 dc
.SetBrush(GetOwner()->GetBackgroundColour());
1630 dc
.SetPen( *wxTRANSPARENT_PEN
);
1631 dc
.DrawRectangle(GetClientSize());
1635 GetOwner()->PrepareDC( dc
);
1636 dc
.SetFont( GetFont() );
1638 wxRect update
= GetUpdateRegion().GetBox();
1639 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1641 // compute which items needs to be redrawn
1642 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
1643 unsigned int item_count
=
1644 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
1645 (int)(GetRowCount( ) - item_start
));
1646 unsigned int item_last
= item_start
+ item_count
;
1647 // Get the parent of DataViewCtrl
1648 wxWindow
*parent
= GetParent()->GetParent();
1649 wxDataViewEvent
cache_event(wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, parent
->GetId());
1650 cache_event
.SetEventObject(GetParent());
1651 cache_event
.SetCache(item_start
, item_last
- 1);
1652 parent
->ProcessWindowEvent(cache_event
);
1654 // compute which columns needs to be redrawn
1655 unsigned int cols
= GetOwner()->GetColumnCount();
1656 unsigned int col_start
= 0;
1657 unsigned int x_start
;
1658 for (x_start
= 0; col_start
< cols
; col_start
++)
1660 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_start
);
1661 if (col
->IsHidden())
1662 continue; // skip it!
1664 unsigned int w
= col
->GetWidth();
1665 if (x_start
+w
>= (unsigned int)update
.x
)
1671 unsigned int col_last
= col_start
;
1672 unsigned int x_last
= x_start
;
1673 for (; col_last
< cols
; col_last
++)
1675 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_last
);
1676 if (col
->IsHidden())
1677 continue; // skip it!
1679 if (x_last
> (unsigned int)update
.GetRight())
1682 x_last
+= col
->GetWidth();
1685 // Draw horizontal rules if required
1686 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1688 dc
.SetPen(m_penRule
);
1689 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1691 for (unsigned int i
= item_start
; i
<= item_last
; i
++)
1693 int y
= GetLineStart( i
);
1694 dc
.DrawLine(x_start
, y
, x_last
, y
);
1698 // Draw vertical rules if required
1699 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1701 dc
.SetPen(m_penRule
);
1702 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1705 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1707 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(i
);
1708 if (col
->IsHidden())
1709 continue; // skip it
1711 dc
.DrawLine(x
, GetLineStart( item_start
),
1712 x
, GetLineStart( item_last
) );
1714 x
+= col
->GetWidth();
1717 // Draw last vertical rule
1718 dc
.DrawLine(x
, GetLineStart( item_start
),
1719 x
, GetLineStart( item_last
) );
1722 // redraw the background for the items which are selected/current
1723 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1725 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1726 if (selected
|| item
== m_currentRow
)
1728 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
1729 if (item
== m_currentRow
)
1730 flags
|= wxCONTROL_CURRENT
;
1732 flags
|= wxCONTROL_FOCUSED
;
1734 wxRect
rect( x_start
, GetLineStart( item
), x_last
, GetLineHeight( item
) );
1735 wxRendererNative::Get().DrawItemSelectionRect
1745 #if wxUSE_DRAG_AND_DROP
1748 wxRect
rect( x_start
, GetLineStart( m_dropHintLine
),
1749 x_last
, GetLineHeight( m_dropHintLine
) );
1750 dc
.SetPen( *wxBLACK_PEN
);
1751 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1752 dc
.DrawRectangle( rect
);
1754 #endif // wxUSE_DRAG_AND_DROP
1756 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1759 // TODO-RTL: last column for RTL support
1760 expander
= GetOwner()->GetColumnAt( 0 );
1761 GetOwner()->SetExpanderColumn(expander
);
1764 // redraw all cells for all rows which must be repainted and all columns
1766 cell_rect
.x
= x_start
;
1767 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1769 wxDataViewColumn
*col
= GetOwner()->GetColumnAt( i
);
1770 wxDataViewRenderer
*cell
= col
->GetRenderer();
1771 cell_rect
.width
= col
->GetWidth();
1773 if (col
->IsHidden())
1774 continue; // skip it!
1776 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1778 // get the cell value and set it into the renderer
1780 wxDataViewTreeNode
*node
= NULL
;
1781 wxDataViewItem dataitem
;
1783 if (!IsVirtualList())
1785 node
= GetTreeNodeByRow(item
);
1789 dataitem
= node
->GetItem();
1791 if ((i
> 0) && model
->IsContainer(dataitem
) &&
1792 !model
->HasContainerColumns(dataitem
))
1797 dataitem
= wxDataViewItem( wxUIntToPtr(item
+1) );
1800 model
->GetValue( value
, dataitem
, col
->GetModelColumn());
1801 cell
->SetValue( value
);
1804 cell_rect
.y
= GetLineStart( item
);
1805 cell_rect
.height
= GetLineHeight( item
);
1807 // Draw the expander here.
1809 if ((!IsVirtualList()) && (col
== expander
))
1811 indent
= node
->GetIndentLevel();
1813 // Calculate the indent first
1814 indent
= cell_rect
.x
+ GetOwner()->GetIndent() * indent
;
1816 int expander_width
= m_lineHeight
- 2*EXPANDER_MARGIN
;
1818 // change the cell_rect.x to the appropriate pos
1819 int expander_x
= indent
+ EXPANDER_MARGIN
;
1820 int expander_y
= cell_rect
.y
+ EXPANDER_MARGIN
+ (GetLineHeight(item
) / 2)
1821 - (expander_width
/2) - EXPANDER_OFFSET
;
1823 indent
= indent
+ m_lineHeight
;
1824 // try to use the m_lineHeight as the expander space
1826 dc
.SetPen( m_penExpander
);
1827 dc
.SetBrush( wxNullBrush
);
1828 if( node
->HasChildren() )
1830 wxRect
rect( expander_x
, expander_y
, expander_width
, expander_width
);
1832 if (m_underMouse
== node
)
1834 flag
|= wxCONTROL_CURRENT
;
1836 if( node
->IsOpen() )
1837 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
,
1838 flag
|wxCONTROL_EXPANDED
);
1840 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
1843 // force the expander column to left-center align
1844 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
1846 if (node
&& !node
->HasChildren())
1848 // Yes, if the node does not have any child, it must be a leaf which
1849 // mean that it is a temporarily created by GetTreeNodeByRow
1853 // cannot be bigger than allocated space
1854 wxSize size
= cell
->GetSize();
1856 // Because of the tree structure indent, here we should minus the width
1857 // of the cell for drawing
1858 size
.x
= wxMin( size
.x
+ 2*PADDING_RIGHTLEFT
, cell_rect
.width
- indent
);
1859 // size.y = wxMin( size.y, cell_rect.height );
1860 size
.y
= cell_rect
.height
;
1862 wxRect
item_rect(cell_rect
.GetTopLeft(), size
);
1863 int align
= cell
->CalculateAlignment();
1865 // horizontal alignment:
1866 item_rect
.x
= cell_rect
.x
;
1867 if (align
& wxALIGN_CENTER_HORIZONTAL
)
1868 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
1869 else if (align
& wxALIGN_RIGHT
)
1870 item_rect
.x
= cell_rect
.x
+ cell_rect
.width
- size
.x
;
1871 // else: wxALIGN_LEFT is the default
1873 // vertical alignment:
1874 item_rect
.y
= cell_rect
.y
;
1875 if (align
& wxALIGN_CENTER_VERTICAL
)
1876 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
1877 else if (align
& wxALIGN_BOTTOM
)
1878 item_rect
.y
= cell_rect
.y
+ cell_rect
.height
- size
.y
;
1879 // else: wxALIGN_TOP is the default
1882 item_rect
.x
+= PADDING_RIGHTLEFT
;
1883 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
1885 // Here we add the tree indent
1886 item_rect
.x
+= indent
;
1889 if (m_hasFocus
&& (m_selection
.Index(item
) != wxNOT_FOUND
))
1890 state
|= wxDATAVIEW_CELL_SELECTED
;
1892 // TODO: it would be much more efficient to create a clipping
1893 // region for the entire column being rendered (in the OnPaint
1894 // of wxDataViewMainWindow) instead of a single clip region for
1895 // each cell. However it would mean that each renderer should
1896 // respect the given wxRect's top & bottom coords, eventually
1897 // violating only the left & right coords - however the user can
1898 // make its own renderer and thus we cannot be sure of that.
1899 dc
.SetClippingRegion( item_rect
);
1901 wxDataViewItemAttr attr
;
1903 hasAttr
= model
->GetAttr(dataitem
, col
->GetModelColumn(), attr
);
1904 cell
->RenderWithAttr(dc
, item_rect
, hasAttr
? &attr
: NULL
, state
);
1906 dc
.DestroyClippingRegion();
1909 cell_rect
.x
+= cell_rect
.width
;
1913 void wxDataViewMainWindow::OnRenameTimer()
1915 // We have to call this here because changes may just have
1916 // been made and no screen update taken place.
1919 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
1920 // (needs to be tested!)
1924 wxDataViewItem item
= GetItemByRow( m_currentRow
);
1926 wxRect labelRect
= GetItemRect(item
, m_currentCol
);
1928 m_currentCol
->GetRenderer()->StartEditing( item
, labelRect
);
1931 //-----------------------------------------------------------------------------
1932 // Helper class for do operation on the tree node
1933 //-----------------------------------------------------------------------------
1938 virtual ~DoJob() { }
1940 // The return value control how the tree-walker tranverse the tree
1941 // 0: Job done, stop tranverse and return
1942 // 1: Ignore the current node's subtree and continue
1943 // 2: Job not done, continue
1944 enum { OK
= 0 , IGR
= 1, CONT
= 2 };
1945 virtual int operator() ( wxDataViewTreeNode
* node
) = 0;
1946 virtual int operator() ( void * n
) = 0;
1949 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
1954 switch( func( node
) )
1965 wxDataViewTreeNodes nodes
= node
->GetNodes();
1966 wxDataViewTreeLeaves leaves
= node
->GetChildren();
1968 int len_nodes
= nodes
.GetCount();
1969 int len
= leaves
.GetCount();
1970 int i
= 0, nodes_i
= 0;
1972 for(; i
< len
; i
++ )
1974 void * n
= leaves
[i
];
1975 if( nodes_i
< len_nodes
&& n
== nodes
[nodes_i
]->GetItem().GetID() )
1977 wxDataViewTreeNode
* nd
= nodes
[nodes_i
];
1980 if( Walker( nd
, func
) )
1999 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
2001 if (IsVirtualList())
2003 wxDataViewVirtualListModel
*list_model
=
2004 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
2005 m_count
= list_model
->GetCount();
2012 wxDataViewTreeNode
* node
;
2013 node
= FindNode(parent
);
2018 node
->SetHasChildren( true );
2020 if( g_model
->IsContainer( item
) )
2022 wxDataViewTreeNode
* newnode
= new wxDataViewTreeNode( node
);
2023 newnode
->SetItem(item
);
2024 newnode
->SetHasChildren( true );
2025 node
->AddNode( newnode
);
2028 node
->AddLeaf( item
.GetID() );
2030 node
->ChangeSubTreeCount(1);
2038 static void DestroyTreeHelper( wxDataViewTreeNode
* node
);
2040 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
2041 const wxDataViewItem
& item
)
2043 if (IsVirtualList())
2045 wxDataViewVirtualListModel
*list_model
=
2046 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
2047 m_count
= list_model
->GetCount();
2049 if( m_currentRow
> GetRowCount() )
2050 m_currentRow
= m_count
- 1;
2052 // TODO: why empty the entire selection?
2053 m_selection
.Empty();
2060 wxDataViewTreeNode
* node
= FindNode(parent
);
2062 wxCHECK_MSG( node
!= NULL
, false, "item not found" );
2063 wxCHECK_MSG( node
->GetChildren().Index( item
.GetID() ) != wxNOT_FOUND
,
2064 false, "item not found" );
2067 node
->GetChildren().Remove( item
.GetID() );
2068 // Manipolate selection
2069 if( m_selection
.GetCount() > 1 )
2071 m_selection
.Empty();
2073 bool isContainer
= false;
2074 wxDataViewTreeNodes nds
= node
->GetNodes();
2075 for (size_t i
= 0; i
< nds
.GetCount(); i
++)
2077 if (nds
[i
]->GetItem() == item
)
2085 wxDataViewTreeNode
* n
= NULL
;
2086 wxDataViewTreeNodes nodes
= node
->GetNodes();
2087 int len
= nodes
.GetCount();
2088 for( int i
= 0; i
< len
; i
++)
2090 if( nodes
[i
]->GetItem() == item
)
2097 wxCHECK_MSG( n
!= NULL
, false, "item not found" );
2099 node
->GetNodes().Remove( n
);
2100 sub
-= n
->GetSubTreeCount();
2101 ::DestroyTreeHelper(n
);
2103 // Make the row number invalid and get a new valid one when user call GetRowCount
2105 node
->ChangeSubTreeCount(sub
);
2107 // Change the current row to the last row if the current exceed the max row number
2108 if( m_currentRow
> GetRowCount() )
2109 m_currentRow
= m_count
- 1;
2116 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
2122 wxWindow
*parent
= GetParent();
2123 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2124 le
.SetEventObject(parent
);
2125 le
.SetModel(GetOwner()->GetModel());
2127 parent
->GetEventHandler()->ProcessEvent(le
);
2132 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
2134 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
2135 /*#define MAX_VIRTUAL_WIDTH 100000
2137 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
2138 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2139 Refresh( true, &rect );
2147 wxWindow
*parent
= GetParent();
2148 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2149 le
.SetEventObject(parent
);
2150 le
.SetModel(GetOwner()->GetModel());
2153 le
.SetDataViewColumn(GetOwner()->GetColumn(col
));
2154 parent
->GetEventHandler()->ProcessEvent(le
);
2159 bool wxDataViewMainWindow::Cleared()
2164 BuildTree( GetOwner()->GetModel() );
2171 void wxDataViewMainWindow::UpdateDisplay()
2176 void wxDataViewMainWindow::OnInternalIdle()
2178 wxWindow::OnInternalIdle();
2182 RecalculateDisplay();
2187 void wxDataViewMainWindow::RecalculateDisplay()
2189 wxDataViewModel
*model
= GetOwner()->GetModel();
2196 int width
= GetEndOfLastCol();
2197 int height
= GetLineStart( GetRowCount() );
2199 SetVirtualSize( width
, height
);
2200 GetOwner()->SetScrollRate( 10, m_lineHeight
);
2205 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2207 wxWindow::ScrollWindow( dx
, dy
, rect
);
2209 if (GetOwner()->m_headerArea
)
2210 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
2213 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
2216 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
2217 int sy
= GetLineStart( rows
)/y
;
2221 wxRect rect
= GetClientRect();
2225 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
2226 for (x_start
= 0; colnum
< column
; colnum
++)
2228 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(colnum
);
2229 if (col
->IsHidden())
2230 continue; // skip it!
2232 w
= col
->GetWidth();
2236 int x_end
= x_start
+ w
;
2237 xe
= xx
+ rect
.width
;
2240 sx
= ( xx
+ x_end
- xe
)/x
;
2247 m_owner
->Scroll( sx
, sy
);
2250 int wxDataViewMainWindow::GetCountPerPage() const
2252 wxSize size
= GetClientSize();
2253 return size
.y
/ m_lineHeight
;
2256 int wxDataViewMainWindow::GetEndOfLastCol() const
2260 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2262 const wxDataViewColumn
*c
=
2263 const_cast<wxDataViewCtrl
*>(GetOwner())->GetColumnAt( i
);
2266 width
+= c
->GetWidth();
2271 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2275 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2277 return GetLineAt( y
);
2280 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
2282 wxSize client_size
= GetClientSize();
2283 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2284 &client_size
.x
, &client_size
.y
);
2286 // we should deal with the pixel here
2287 unsigned int row
= GetLineAt(client_size
.y
) - 1;
2289 return wxMin( GetRowCount()-1, row
);
2292 unsigned int wxDataViewMainWindow::GetRowCount()
2294 if ( m_count
== -1 )
2296 m_count
= RecalculateCount();
2302 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
2309 void wxDataViewMainWindow::SelectAllRows( bool on
)
2316 m_selection
.Clear();
2317 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2318 m_selection
.Add( i
);
2323 unsigned int first_visible
= GetFirstVisibleRow();
2324 unsigned int last_visible
= GetLastVisibleRow();
2326 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2328 unsigned int row
= m_selection
[i
];
2329 if ((row
>= first_visible
) && (row
<= last_visible
))
2332 m_selection
.Clear();
2336 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
2338 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2342 m_selection
.Add( row
);
2350 m_selection
.Remove( row
);
2356 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2360 unsigned int tmp
= from
;
2366 for (i
= from
; i
<= to
; i
++)
2368 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2371 m_selection
.Add( i
);
2376 m_selection
.Remove( i
);
2379 RefreshRows( from
, to
);
2382 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2384 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2386 int n
= aSelections
[i
];
2388 m_selection
.Add( n
);
2393 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2395 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2396 m_selection
.Add( row
);
2398 m_selection
.Remove( row
);
2402 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2404 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2407 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
2409 wxWindow
*parent
= GetParent();
2410 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
2412 le
.SetEventObject(parent
);
2413 le
.SetModel(GetOwner()->GetModel());
2416 parent
->GetEventHandler()->ProcessEvent(le
);
2419 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2421 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
2422 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2424 wxSize client_size
= GetClientSize();
2425 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2426 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2427 if (intersect_rect
.width
> 0)
2428 Refresh( true, &intersect_rect
);
2431 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2435 unsigned int tmp
= to
;
2440 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
2441 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2443 wxSize client_size
= GetClientSize();
2444 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2445 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2446 if (intersect_rect
.width
> 0)
2447 Refresh( true, &intersect_rect
);
2450 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2452 wxSize client_size
= GetClientSize();
2453 int start
= GetLineStart( firstRow
);
2454 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
2455 if (start
> client_size
.y
) return;
2457 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
2459 Refresh( true, &rect
);
2462 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2464 wxCHECK_RET( newCurrent
< GetRowCount(),
2465 wxT("invalid item index in OnArrowChar()") );
2467 // if there is no selection, we cannot move it anywhere
2468 if (!HasCurrentRow())
2471 unsigned int oldCurrent
= m_currentRow
;
2473 // in single selection we just ignore Shift as we can't select several
2475 if ( event
.ShiftDown() && !IsSingleSel() )
2477 RefreshRow( oldCurrent
);
2479 ChangeCurrentRow( newCurrent
);
2481 // select all the items between the old and the new one
2482 if ( oldCurrent
> newCurrent
)
2484 newCurrent
= oldCurrent
;
2485 oldCurrent
= m_currentRow
;
2488 SelectRows( oldCurrent
, newCurrent
, true );
2489 if (oldCurrent
!=newCurrent
)
2490 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
2494 RefreshRow( oldCurrent
);
2496 // all previously selected items are unselected unless ctrl is held
2497 if ( !event
.ControlDown() )
2498 SelectAllRows(false);
2500 ChangeCurrentRow( newCurrent
);
2502 if ( !event
.ControlDown() )
2504 SelectRow( m_currentRow
, true );
2505 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
2508 RefreshRow( m_currentRow
);
2511 GetOwner()->EnsureVisible( m_currentRow
, -1 );
2514 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2518 rect
.y
= GetLineStart( row
);
2519 rect
.width
= GetEndOfLastCol();
2520 rect
.height
= GetLineHeight( row
);
2525 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2527 const wxDataViewModel
*model
= GetOwner()->GetModel();
2529 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2531 // TODO make more efficient
2536 for (r
= 0; r
< row
; r
++)
2538 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2539 if (!node
) return start
;
2541 wxDataViewItem item
= node
->GetItem();
2543 if (node
&& !node
->HasChildren())
2545 // Yes, if the node does not have any child, it must be a leaf which
2546 // mean that it is a temporarily created by GetTreeNodeByRow
2550 unsigned int cols
= GetOwner()->GetColumnCount();
2552 int height
= m_lineHeight
;
2553 for (col
= 0; col
< cols
; col
++)
2555 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2556 if (column
->IsHidden())
2557 continue; // skip it!
2560 model
->IsContainer(item
) &&
2561 !model
->HasContainerColumns(item
))
2562 continue; // skip it!
2565 model
->GetValue( value
, item
, column
->GetModelColumn() );
2567 wxDataViewRenderer
*renderer
=
2568 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2569 renderer
->SetValue( value
);
2570 height
= wxMax( height
, renderer
->GetSize().y
);
2580 return row
* m_lineHeight
;
2584 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
2586 const wxDataViewModel
*model
= GetOwner()->GetModel();
2588 // check for the easy case first
2589 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
2590 return y
/ m_lineHeight
;
2592 // TODO make more efficient
2593 unsigned int row
= 0;
2594 unsigned int yy
= 0;
2597 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2600 // not really correct...
2601 return row
+ ((y
-yy
) / m_lineHeight
);
2604 wxDataViewItem item
= node
->GetItem();
2606 if (node
&& !node
->HasChildren())
2608 // Yes, if the node does not have any child, it must be a leaf which
2609 // mean that it is a temporarily created by GetTreeNodeByRow
2613 unsigned int cols
= GetOwner()->GetColumnCount();
2615 int height
= m_lineHeight
;
2616 for (col
= 0; col
< cols
; col
++)
2618 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2619 if (column
->IsHidden())
2620 continue; // skip it!
2623 model
->IsContainer(item
) &&
2624 !model
->HasContainerColumns(item
))
2625 continue; // skip it!
2628 model
->GetValue( value
, item
, column
->GetModelColumn() );
2630 wxDataViewRenderer
*renderer
=
2631 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2632 renderer
->SetValue( value
);
2633 height
= wxMax( height
, renderer
->GetSize().y
);
2644 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
2646 const wxDataViewModel
*model
= GetOwner()->GetModel();
2648 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2650 wxASSERT( !IsVirtualList() );
2652 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2653 // wxASSERT( node );
2654 if (!node
) return m_lineHeight
;
2656 wxDataViewItem item
= node
->GetItem();
2658 if (node
&& !node
->HasChildren())
2660 // Yes, if the node does not have any child, it must be a leaf which
2661 // mean that it is a temporarily created by GetTreeNodeByRow
2665 int height
= m_lineHeight
;
2667 unsigned int cols
= GetOwner()->GetColumnCount();
2669 for (col
= 0; col
< cols
; col
++)
2671 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2672 if (column
->IsHidden())
2673 continue; // skip it!
2676 model
->IsContainer(item
) &&
2677 !model
->HasContainerColumns(item
))
2678 continue; // skip it!
2681 model
->GetValue( value
, item
, column
->GetModelColumn() );
2683 wxDataViewRenderer
*renderer
=
2684 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2685 renderer
->SetValue( value
);
2686 height
= wxMax( height
, renderer
->GetSize().y
);
2693 return m_lineHeight
;
2697 class RowToItemJob
: public DoJob
2700 RowToItemJob( unsigned int row
, int current
)
2701 { this->row
= row
; this->current
= current
; }
2702 virtual ~RowToItemJob() {}
2704 virtual int operator() ( wxDataViewTreeNode
* node
)
2707 if( current
== static_cast<int>(row
))
2709 ret
= node
->GetItem();
2713 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2715 current
+= node
->GetSubTreeCount();
2720 // If the current has no child node, we can find the desired item of the row
2722 // This if can speed up finding in some case, and will has a very good effect
2723 // when it comes to list view
2724 if( node
->GetNodes().GetCount() == 0)
2726 int index
= static_cast<int>(row
) - current
- 1;
2727 ret
= node
->GetChildren().Item( index
);
2734 virtual int operator() ( void * n
)
2737 if( current
== static_cast<int>(row
))
2739 ret
= wxDataViewItem( n
);
2745 wxDataViewItem
GetResult() const
2754 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
2756 if (IsVirtualList())
2758 return wxDataViewItem( wxUIntToPtr(row
+1) );
2762 RowToItemJob
job( row
, -2 );
2763 Walker( m_root
, job
);
2764 return job
.GetResult();
2768 class RowToTreeNodeJob
: public DoJob
2771 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
2774 this->current
= current
;
2778 virtual ~RowToTreeNodeJob(){ }
2780 virtual int operator() ( wxDataViewTreeNode
* node
)
2783 if( current
== static_cast<int>(row
))
2789 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2791 current
+= node
->GetSubTreeCount();
2798 // If the current node has no children, we can find the desired item of the
2799 // row number directly.
2800 // This if can speed up finding in some case, and will have a very good
2801 // effect for list views.
2802 if( node
->GetNodes().GetCount() == 0)
2804 int index
= static_cast<int>(row
) - current
- 1;
2805 void * n
= node
->GetChildren().Item( index
);
2806 ret
= new wxDataViewTreeNode( parent
);
2807 ret
->SetItem( wxDataViewItem( n
));
2808 ret
->SetHasChildren(false);
2815 virtual int operator() ( void * n
)
2818 if( current
== static_cast<int>(row
))
2820 ret
= new wxDataViewTreeNode( parent
);
2821 ret
->SetItem( wxDataViewItem( n
));
2822 ret
->SetHasChildren(false);
2829 wxDataViewTreeNode
* GetResult() const
2835 wxDataViewTreeNode
* ret
;
2836 wxDataViewTreeNode
* parent
;
2839 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
2841 wxASSERT( !IsVirtualList() );
2843 RowToTreeNodeJob
job( row
, -2, m_root
);
2844 Walker( m_root
, job
);
2845 return job
.GetResult();
2848 wxDataViewEvent
wxDataViewMainWindow::SendExpanderEvent( wxEventType type
,
2849 const wxDataViewItem
& item
)
2851 wxWindow
*parent
= GetParent();
2852 wxDataViewEvent
le(type
, parent
->GetId());
2854 le
.SetEventObject(parent
);
2855 le
.SetModel(GetOwner()->GetModel());
2858 parent
->GetEventHandler()->ProcessEvent(le
);
2862 bool wxDataViewMainWindow::IsExpanded( unsigned int row
) const
2864 if (IsVirtualList())
2867 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2871 if (!node
->HasChildren())
2877 return node
->IsOpen();
2880 bool wxDataViewMainWindow::HasChildren( unsigned int row
) const
2882 if (IsVirtualList())
2885 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2889 if (!node
->HasChildren())
2898 void wxDataViewMainWindow::Expand( unsigned int row
)
2900 if (IsVirtualList())
2903 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2907 if (!node
->HasChildren())
2913 if (!node
->IsOpen())
2916 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, node
->GetItem());
2918 // Check if the user prevent expanding
2919 if( e
.GetSkipped() )
2924 // build the children of current node
2925 if( node
->GetChildrenNumber() == 0 )
2928 ::BuildTreeHelper(GetOwner()->GetModel(), node
->GetItem(), node
);
2931 // By expanding the node all row indices that are currently in the selection list
2932 // and are greater than our node have become invalid. So we have to correct that now.
2933 const unsigned rowAdjustment
= node
->GetSubTreeCount();
2934 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2936 const unsigned testRow
= m_selection
[i
];
2937 // all rows above us are not affected, so skip them
2941 m_selection
[i
] += rowAdjustment
;
2944 if(m_currentRow
> row
)
2945 ChangeCurrentRow(m_currentRow
+ rowAdjustment
);
2949 // Send the expanded event
2950 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
2954 void wxDataViewMainWindow::Collapse(unsigned int row
)
2956 if (IsVirtualList())
2959 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
2963 if (!node
->HasChildren())
2972 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem());
2973 if( e
.GetSkipped() )
2976 // Find out if there are selected items below the current node.
2977 bool selectCollapsingRow
= false;
2978 const unsigned rowAdjustment
= node
->GetSubTreeCount();
2979 unsigned maxRowToBeTested
= row
+ rowAdjustment
;
2980 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2982 const unsigned testRow
= m_selection
[i
];
2983 if(testRow
> row
&& testRow
<= maxRowToBeTested
)
2985 selectCollapsingRow
= true;
2986 // get out as soon as we have found a node that is selected
2993 // If the node to be closed has selected items the user won't see those any longer.
2994 // We select the collapsing node in this case.
2995 if(selectCollapsingRow
)
2997 SelectAllRows(false);
2998 ChangeCurrentRow(row
);
2999 SelectRow(row
, true);
3000 SendSelectionChangedEvent(GetItemByRow(row
));
3004 // if there were no selected items below our node we still need to "fix" the
3005 // selection list to adjust for the changing of the row indices.
3006 // We actually do the opposite of what we are doing in Expand().
3007 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3009 const unsigned testRow
= m_selection
[i
];
3010 // all rows above us are not affected, so skip them
3014 m_selection
[i
] -= rowAdjustment
;
3017 // if the "current row" is being collapsed away we change it to the current row ;-)
3018 if(m_currentRow
> row
&& m_currentRow
<= maxRowToBeTested
)
3019 ChangeCurrentRow(row
);
3020 else if(m_currentRow
> row
)
3021 ChangeCurrentRow(m_currentRow
- rowAdjustment
);
3026 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,node
->GetItem());
3030 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
3032 wxDataViewModel
* model
= GetOwner()->GetModel();
3039 // Compose the a parent-chain of the finding item
3041 list
.DeleteContents( true );
3042 wxDataViewItem
it( item
);
3045 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3046 list
.Insert( pItem
);
3047 it
= model
->GetParent( it
);
3050 // Find the item along the parent-chain.
3051 // This algorithm is designed to speed up the node-finding method
3052 wxDataViewTreeNode
* node
= m_root
;
3053 for( ItemList::const_iterator iter
= list
.begin(); iter
!=list
.end(); iter
++ )
3055 if( node
->HasChildren() )
3057 if( node
->GetChildrenNumber() == 0 )
3060 ::BuildTreeHelper(model
, node
->GetItem(), node
);
3063 wxDataViewTreeNodes nodes
= node
->GetNodes();
3067 for (i
= 0; i
< nodes
.GetCount(); i
++)
3069 if (nodes
[i
]->GetItem() == (**iter
))
3071 if (nodes
[i
]->GetItem() == item
)
3088 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
3089 wxDataViewColumn
* &column
)
3091 wxDataViewColumn
*col
= NULL
;
3092 unsigned int cols
= GetOwner()->GetColumnCount();
3093 unsigned int colnum
= 0;
3095 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
3096 for (unsigned x_start
= 0; colnum
< cols
; colnum
++)
3098 col
= GetOwner()->GetColumnAt(colnum
);
3099 if (col
->IsHidden())
3100 continue; // skip it!
3102 unsigned int w
= col
->GetWidth();
3103 if (x_start
+w
>= (unsigned int)x
)
3110 item
= GetItemByRow( GetLineAt( y
) );
3113 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
,
3114 const wxDataViewColumn
* column
)
3119 unsigned int cols
= GetOwner()->GetColumnCount();
3120 // If column is null the loop will compute the combined width of all columns.
3121 // Otherwise, it will compute the x position of the column we are looking for.
3122 for (unsigned int i
= 0; i
< cols
; i
++)
3124 wxDataViewColumn
* col
= GetOwner()->GetColumnAt( i
);
3129 if (col
->IsHidden())
3130 continue; // skip it!
3132 xpos
+= col
->GetWidth();
3133 width
+= col
->GetWidth();
3138 // If we have a column, we need can get its width directly.
3139 if(column
->IsHidden())
3142 width
= column
->GetWidth();
3147 // If we have no column, we reset the x position back to zero.
3151 // we have to take an expander column into account and compute its indentation
3152 // to get the correct x position where the actual text is
3154 int row
= GetRowByItem(item
);
3155 if (!IsVirtualList() && (column
== 0 || GetOwner()->GetExpanderColumn() == column
) )
3157 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3158 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
3159 indent
= indent
+ m_lineHeight
; // use m_lineHeight as the width of the expander
3161 if(!node
->HasChildren())
3165 wxRect
itemRect( xpos
+ indent
,
3166 GetLineStart( row
),
3168 GetLineHeight( row
) );
3170 GetOwner()->CalcScrolledPosition( itemRect
.x
, itemRect
.y
,
3171 &itemRect
.x
, &itemRect
.y
);
3176 int wxDataViewMainWindow::RecalculateCount()
3178 if (IsVirtualList())
3180 wxDataViewVirtualListModel
*list_model
=
3181 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
3183 return list_model
->GetCount();
3187 return m_root
->GetSubTreeCount();
3191 class ItemToRowJob
: public DoJob
3194 ItemToRowJob(const wxDataViewItem
& item_
, ItemList::const_iterator iter
)
3201 // Maybe binary search will help to speed up this process
3202 virtual int operator() ( wxDataViewTreeNode
* node
)
3205 if( node
->GetItem() == item
)
3210 if( node
->GetItem() == **m_iter
)
3217 ret
+= node
->GetSubTreeCount();
3223 virtual int operator() ( void * n
)
3226 if( n
== item
.GetID() )
3231 // the row number is begin from zero
3232 int GetResult() const
3236 ItemList::const_iterator m_iter
;
3237 wxDataViewItem item
;
3242 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
3244 const wxDataViewModel
* model
= GetOwner()->GetModel();
3248 if (IsVirtualList())
3250 return wxPtrToUInt( item
.GetID() ) -1;
3257 // Compose the a parent-chain of the finding item
3259 wxDataViewItem
* pItem
;
3260 list
.DeleteContents( true );
3261 wxDataViewItem
it( item
);
3264 pItem
= new wxDataViewItem( it
);
3265 list
.Insert( pItem
);
3266 it
= model
->GetParent( it
);
3268 pItem
= new wxDataViewItem( );
3269 list
.Insert( pItem
);
3271 ItemToRowJob
job( item
, list
.begin() );
3272 Walker(m_root
, job
);
3273 return job
.GetResult();
3277 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
3278 wxDataViewTreeNode
* node
)
3280 if( !model
->IsContainer( item
) )
3283 wxDataViewItemArray children
;
3284 unsigned int num
= model
->GetChildren( item
, children
);
3286 unsigned int index
= 0;
3287 while( index
< num
)
3289 if( model
->IsContainer( children
[index
] ) )
3291 wxDataViewTreeNode
* n
= new wxDataViewTreeNode( node
);
3292 n
->SetItem(children
[index
]);
3293 n
->SetHasChildren( true );
3298 node
->AddLeaf( children
[index
].GetID() );
3302 node
->SetSubTreeCount( num
);
3303 wxDataViewTreeNode
* n
= node
->GetParent();
3305 n
->ChangeSubTreeCount(num
);
3309 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
3313 if (GetOwner()->GetModel()->IsVirtualListModel())
3319 m_root
= new wxDataViewTreeNode( NULL
);
3320 m_root
->SetHasChildren(true);
3322 // First we define a invalid item to fetch the top-level elements
3323 wxDataViewItem item
;
3325 BuildTreeHelper( model
, item
, m_root
);
3329 static void DestroyTreeHelper( wxDataViewTreeNode
* node
)
3331 if( node
->GetNodeNumber() != 0 )
3333 int len
= node
->GetNodeNumber();
3334 wxDataViewTreeNodes
& nodes
= node
->GetNodes();
3335 for (int i
= 0; i
< len
; i
++)
3336 DestroyTreeHelper(nodes
[i
]);
3341 void wxDataViewMainWindow::DestroyTree()
3343 if (!IsVirtualList())
3345 ::DestroyTreeHelper(m_root
);
3351 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
3353 if ( GetParent()->HandleAsNavigationKey(event
) )
3356 // no item -> nothing to do
3357 if (!HasCurrentRow())
3363 // don't use m_linesPerPage directly as it might not be computed yet
3364 const int pageSize
= GetCountPerPage();
3365 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
3367 switch ( event
.GetKeyCode() )
3371 wxWindow
*parent
= GetParent();
3372 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
,
3374 le
.SetItem( GetItemByRow(m_currentRow
) );
3375 le
.SetEventObject(parent
);
3376 le
.SetModel(GetOwner()->GetModel());
3378 parent
->GetEventHandler()->ProcessEvent(le
);
3383 if ( m_currentRow
> 0 )
3384 OnArrowChar( m_currentRow
- 1, event
);
3388 if ( m_currentRow
< GetRowCount() - 1 )
3389 OnArrowChar( m_currentRow
+ 1, event
);
3391 // Add the process for tree expanding/collapsing
3394 if (IsVirtualList())
3397 wxDataViewTreeNode
* node
= GetTreeNodeByRow(m_currentRow
);
3401 if (node
->HasChildren() && node
->IsOpen())
3403 Collapse(m_currentRow
);
3405 else // if the node is already closed we move the selection to its parent
3407 wxDataViewTreeNode
*parent_node
= node
->GetParent();
3409 if(!node
->HasChildren())
3414 int parent
= GetRowByItem( parent_node
->GetItem() );
3417 unsigned int row
= m_currentRow
;
3418 SelectRow( row
, false);
3419 SelectRow( parent
, true );
3420 ChangeCurrentRow( parent
);
3421 GetOwner()->EnsureVisible( parent
, -1 );
3422 SendSelectionChangedEvent( parent_node
->GetItem() );
3430 if (!IsExpanded( m_currentRow
))
3431 Expand( m_currentRow
);
3434 unsigned int row
= m_currentRow
;
3435 SelectRow( row
, false );
3436 SelectRow( row
+ 1, true );
3437 ChangeCurrentRow( row
+ 1 );
3438 GetOwner()->EnsureVisible( row
+ 1, -1 );
3439 SendSelectionChangedEvent( GetItemByRow(row
+1) );
3446 OnArrowChar( GetRowCount() - 1, event
);
3451 OnArrowChar( 0, event
);
3456 int steps
= pageSize
- 1;
3457 int index
= m_currentRow
- steps
;
3461 OnArrowChar( index
, event
);
3467 int steps
= pageSize
- 1;
3468 unsigned int index
= m_currentRow
+ steps
;
3469 unsigned int count
= GetRowCount();
3470 if ( index
>= count
)
3473 OnArrowChar( index
, event
);
3479 if(m_selection
.size() == 1)
3481 // TODO: we need to revise that when we have a concept for a 'current column'
3482 GetOwner()->StartEditor(GetItemByRow(m_selection
[0]), 0);
3492 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
3494 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3496 // let the base handle mouse wheel events.
3501 int x
= event
.GetX();
3502 int y
= event
.GetY();
3503 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
3504 wxDataViewColumn
*col
= NULL
;
3507 unsigned int cols
= GetOwner()->GetColumnCount();
3509 for (i
= 0; i
< cols
; i
++)
3511 wxDataViewColumn
*c
= GetOwner()->GetColumnAt( i
);
3513 continue; // skip it!
3515 if (x
< xpos
+ c
->GetWidth())
3520 xpos
+= c
->GetWidth();
3525 wxDataViewRenderer
*cell
= col
->GetRenderer();
3526 unsigned int current
= GetLineAt( y
);
3527 if ((current
>= GetRowCount()) || (x
> GetEndOfLastCol()))
3529 // Unselect all if below the last row ?
3533 // Test whether the mouse is hovered on the tree item button
3534 bool hoverOverExpander
= false;
3535 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
3537 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3538 if( node
!=NULL
&& node
->HasChildren() )
3540 int indent
= node
->GetIndentLevel();
3541 indent
= GetOwner()->GetIndent()*indent
;
3543 // we make the rectangle we are looking in a bit bigger than the actual
3544 // visual expander so the user can hit that little thing reliably
3545 wxRect
rect( xpos
+ indent
,
3546 GetLineStart( current
) + (GetLineHeight(current
) - m_lineHeight
)/2,
3547 m_lineHeight
, m_lineHeight
);
3548 if( rect
.Contains(x
, y
) )
3550 // So the mouse is over the expander
3551 hoverOverExpander
= true;
3552 if (m_underMouse
&& m_underMouse
!= node
)
3554 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3555 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3557 if (m_underMouse
!= node
)
3559 // wxLogMessage("Do the row: %d", current);
3560 RefreshRow(current
);
3562 m_underMouse
= node
;
3565 if (node
!=NULL
&& !node
->HasChildren())
3568 if (!hoverOverExpander
)
3570 if (m_underMouse
!= NULL
)
3572 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3573 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3574 m_underMouse
= NULL
;
3578 wxDataViewModel
*model
= GetOwner()->GetModel();
3580 #if wxUSE_DRAG_AND_DROP
3581 if (event
.Dragging())
3583 if (m_dragCount
== 0)
3585 // we have to report the raw, physical coords as we want to be
3586 // able to call HitTest(event.m_pointDrag) from the user code to
3587 // get the item being dragged
3588 m_dragStart
= event
.GetPosition();
3593 if (m_dragCount
!= 3)
3596 if (event
.LeftIsDown())
3598 m_owner
->CalcUnscrolledPosition( m_dragStart
.x
, m_dragStart
.y
,
3599 &m_dragStart
.x
, &m_dragStart
.y
);
3600 unsigned int drag_item_row
= GetLineAt( m_dragStart
.y
);
3601 wxDataViewItem item
= GetItemByRow( drag_item_row
);
3603 // Notify cell about drag
3604 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3605 event
.SetEventObject( m_owner
);
3606 event
.SetItem( item
);
3607 event
.SetModel( model
);
3608 if (!m_owner
->HandleWindowEvent( event
))
3611 if (!event
.IsAllowed())
3614 wxDataObject
*obj
= event
.GetDataObject();
3618 wxDataViewDropSource
drag( this, drag_item_row
);
3619 drag
.SetData( *obj
);
3620 /* wxDragResult res = */ drag
.DoDragDrop();
3629 #endif // wxUSE_DRAG_AND_DROP
3631 bool simulateClick
= false;
3633 if (event
.ButtonDClick())
3635 m_renameTimer
->Stop();
3636 m_lastOnSame
= false;
3639 wxDataViewItem item
= GetItemByRow(current
);
3640 bool ignore_other_columns
=
3641 ((GetOwner()->GetExpanderColumn() != col
) &&
3642 (model
->IsContainer(item
)) &&
3643 (!model
->HasContainerColumns(item
)));
3645 if (event
.LeftDClick())
3647 if(hoverOverExpander
)
3649 // a double click on the expander will be converted into a "simulated" normal click
3650 simulateClick
= true;
3652 else if ( current
== m_lineLastClicked
)
3654 if ((!ignore_other_columns
) && (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
3657 model
->GetValue( value
, item
, col
->GetModelColumn() );
3658 cell
->SetValue( value
);
3659 wxRect
cell_rect( xpos
, GetLineStart( current
),
3660 col
->GetWidth(), GetLineHeight( current
) );
3661 cell
->Activate( cell_rect
, model
, item
, col
->GetModelColumn() );
3665 wxWindow
*parent
= GetParent();
3666 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3668 le
.SetEventObject(parent
);
3669 le
.SetModel(GetOwner()->GetModel());
3671 parent
->GetEventHandler()->ProcessEvent(le
);
3677 // The first click was on another item, so don't interpret this as
3678 // a double click, but as a simple click instead
3679 simulateClick
= true;
3683 if (event
.LeftUp() && !hoverOverExpander
)
3685 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
3687 // select single line
3688 SelectAllRows( false );
3689 SelectRow( m_lineSelectSingleOnUp
, true );
3690 SendSelectionChangedEvent( GetItemByRow(m_lineSelectSingleOnUp
) );
3693 // If the user click the expander, we do not do editing even if the column
3694 // with expander are editable
3695 if (m_lastOnSame
&& !ignore_other_columns
)
3697 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
3698 (cell
->GetMode() & wxDATAVIEW_CELL_EDITABLE
) )
3700 m_renameTimer
->Start( 100, true );
3704 m_lastOnSame
= false;
3705 m_lineSelectSingleOnUp
= (unsigned int)-1;
3707 else if(!event
.LeftUp())
3709 // This is necessary, because after a DnD operation in
3710 // from and to ourself, the up event is swallowed by the
3711 // DnD code. So on next non-up event (which means here and
3712 // now) m_lineSelectSingleOnUp should be reset.
3713 m_lineSelectSingleOnUp
= (unsigned int)-1;
3716 if (event
.RightDown())
3718 m_lineBeforeLastClicked
= m_lineLastClicked
;
3719 m_lineLastClicked
= current
;
3721 // If the item is already selected, do not update the selection.
3722 // Multi-selections should not be cleared if a selected item is clicked.
3723 if (!IsRowSelected(current
))
3725 SelectAllRows(false);
3726 ChangeCurrentRow(current
);
3727 SelectRow(m_currentRow
,true);
3728 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3731 else if (event
.RightUp())
3734 model
->GetValue( value
, item
, col
->GetModelColumn() );
3735 wxWindow
*parent
= GetParent();
3736 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
3738 le
.SetEventObject(parent
);
3739 le
.SetModel(GetOwner()->GetModel());
3741 parent
->GetEventHandler()->ProcessEvent(le
);
3743 else if (event
.MiddleDown())
3747 if((event
.LeftDown() || simulateClick
) && hoverOverExpander
)
3749 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3751 // hoverOverExpander being true tells us that our node must be
3752 // valid and have children.
3753 // So we don't need any extra checks.
3754 if( node
->IsOpen() )
3759 else if ((event
.LeftDown() || simulateClick
) && !hoverOverExpander
)
3763 m_lineBeforeLastClicked
= m_lineLastClicked
;
3764 m_lineLastClicked
= current
;
3766 unsigned int oldCurrentRow
= m_currentRow
;
3767 bool oldWasSelected
= IsRowSelected(m_currentRow
);
3769 bool cmdModifierDown
= event
.CmdDown();
3770 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3772 if ( IsSingleSel() || !IsRowSelected(current
) )
3774 SelectAllRows( false );
3775 ChangeCurrentRow(current
);
3776 SelectRow(m_currentRow
,true);
3777 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3779 else // multi sel & current is highlighted & no mod keys
3781 m_lineSelectSingleOnUp
= current
;
3782 ChangeCurrentRow(current
); // change focus
3785 else // multi sel & either ctrl or shift is down
3787 if (cmdModifierDown
)
3789 ChangeCurrentRow(current
);
3790 ReverseRowSelection(m_currentRow
);
3791 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3793 else if (event
.ShiftDown())
3795 ChangeCurrentRow(current
);
3797 unsigned int lineFrom
= oldCurrentRow
,
3800 if ( lineTo
< lineFrom
)
3803 lineFrom
= m_currentRow
;
3806 SelectRows(lineFrom
, lineTo
, true);
3807 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3809 else // !ctrl, !shift
3811 // test in the enclosing if should make it impossible
3812 wxFAIL_MSG( wxT("how did we get here?") );
3816 if (m_currentRow
!= oldCurrentRow
)
3817 RefreshRow( oldCurrentRow
);
3819 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
3821 // Update selection here...
3824 m_lastOnSame
= !simulateClick
&& ((col
== oldCurrentCol
) &&
3825 (current
== oldCurrentRow
)) && oldWasSelected
;
3827 // Call LeftClick after everything else as under GTK+
3828 if (cell
->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE
)
3830 // notify cell about right click
3832 model
->GetValue( value
, item
, col
->GetModelColumn() );
3833 cell
->SetValue( value
);
3834 wxRect
cell_rect( xpos
, GetLineStart( current
),
3835 col
->GetWidth(), GetLineHeight( current
) );
3836 /* ignore ret */ cell
->LeftClick( event
.GetPosition(), cell_rect
,
3837 model
, item
, col
->GetModelColumn());
3842 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
3846 if (HasCurrentRow())
3852 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
3856 if (HasCurrentRow())
3862 wxDataViewItem
wxDataViewMainWindow::GetSelection() const
3864 if( m_selection
.GetCount() != 1 )
3865 return wxDataViewItem();
3867 return GetItemByRow( m_selection
.Item(0));
3870 //-----------------------------------------------------------------------------
3872 //-----------------------------------------------------------------------------
3874 WX_DEFINE_LIST(wxDataViewColumnList
)
3876 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3877 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
3878 EVT_SIZE(wxDataViewCtrl::OnSize
)
3881 wxDataViewCtrl::~wxDataViewCtrl()
3884 GetModel()->RemoveNotifier( m_notifier
);
3889 void wxDataViewCtrl::Init()
3891 m_cols
.DeleteContents(true);
3894 // No sorting column at start
3895 m_sortingColumnIdx
= wxNOT_FOUND
;
3897 m_headerArea
= NULL
;
3900 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3901 const wxPoint
& pos
, const wxSize
& size
,
3902 long style
, const wxValidator
& validator
)
3904 // if ( (style & wxBORDER_MASK) == 0)
3905 // style |= wxBORDER_SUNKEN;
3909 if (!wxControl::Create( parent
, id
, pos
, size
,
3910 style
| wxScrolledWindowStyle
, validator
))
3913 SetInitialSize(size
);
3916 MacSetClipChildren( true );
3919 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
3921 if (HasFlag(wxDV_NO_HEADER
))
3922 m_headerArea
= NULL
;
3924 m_headerArea
= new wxDataViewHeaderWindow(this);
3926 SetTargetWindow( m_clientArea
);
3928 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
3930 sizer
->Add( m_headerArea
, 0, wxGROW
);
3931 sizer
->Add( m_clientArea
, 1, wxGROW
);
3937 wxBorder
wxDataViewCtrl::GetDefaultBorder() const
3939 return wxBORDER_THEME
;
3943 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
3947 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
3950 // we need to process arrows ourselves for scrolling
3951 if ( nMsg
== WM_GETDLGCODE
)
3953 rc
|= DLGC_WANTARROWS
;
3961 wxSize
wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
3963 wxSize newsize
= size
;
3964 if (!HasFlag(wxDV_NO_HEADER
) && (m_headerArea
))
3965 newsize
.y
-= m_headerArea
->GetSize().y
;
3970 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3972 // We need to override OnSize so that our scrolled
3973 // window a) does call Layout() to use sizers for
3974 // positioning the controls but b) does not query
3975 // the sizer for their size and use that for setting
3976 // the scrollable area as set that ourselves by
3977 // calling SetScrollbar() further down.
3984 void wxDataViewCtrl::SetFocus()
3987 m_clientArea
->SetFocus();
3990 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3992 if (!wxDataViewCtrlBase::AssociateModel( model
))
3995 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
3997 model
->AddNotifier( m_notifier
);
3999 m_clientArea
->DestroyTree();
4001 m_clientArea
->BuildTree(model
);
4003 m_clientArea
->UpdateDisplay();
4008 #if wxUSE_DRAG_AND_DROP
4010 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4012 return m_clientArea
->EnableDragSource( format
);
4015 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4017 return m_clientArea
->EnableDropTarget( format
);
4020 #endif // wxUSE_DRAG_AND_DROP
4022 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4024 if (!wxDataViewCtrlBase::AppendColumn(col
))
4027 m_cols
.Append( col
);
4028 OnColumnsCountChanged();
4032 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4034 if (!wxDataViewCtrlBase::PrependColumn(col
))
4037 m_cols
.Insert( col
);
4038 OnColumnsCountChanged();
4042 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4044 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4047 m_cols
.Insert( pos
, col
);
4048 OnColumnsCountChanged();
4052 void wxDataViewCtrl::OnColumnChange(unsigned int idx
)
4055 m_headerArea
->UpdateColumn(idx
);
4057 m_clientArea
->UpdateDisplay();
4060 void wxDataViewCtrl::OnColumnsCountChanged()
4063 m_headerArea
->SetColumnCount(GetColumnCount());
4065 m_clientArea
->UpdateDisplay();
4068 void wxDataViewCtrl::DoSetExpanderColumn()
4070 m_clientArea
->UpdateDisplay();
4073 void wxDataViewCtrl::DoSetIndent()
4075 m_clientArea
->UpdateDisplay();
4078 unsigned int wxDataViewCtrl::GetColumnCount() const
4080 return m_cols
.GetCount();
4083 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int idx
) const
4088 wxDataViewColumn
*wxDataViewCtrl::GetColumnAt(unsigned int pos
) const
4090 // columns can't be reordered if there is no header window which allows
4092 const unsigned idx
= m_headerArea
? m_headerArea
->GetColumnsOrder()[pos
]
4095 return GetColumn(idx
);
4098 int wxDataViewCtrl::GetColumnIndex(const wxDataViewColumn
*column
) const
4100 const unsigned count
= m_cols
.size();
4101 for ( unsigned n
= 0; n
< count
; n
++ )
4103 if ( m_cols
[n
] == column
)
4110 void wxDataViewCtrl::ColumnMoved(wxDataViewColumn
* WXUNUSED(col
),
4111 unsigned int WXUNUSED(new_pos
))
4113 // do _not_ reorder m_cols elements here, they should always be in the
4114 // order in which columns were added, we only display the columns in
4116 m_clientArea
->UpdateDisplay();
4119 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4121 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
4126 OnColumnsCountChanged();
4131 bool wxDataViewCtrl::ClearColumns()
4134 OnColumnsCountChanged();
4138 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4142 unsigned int len
= GetColumnCount();
4143 for ( unsigned int i
= 0; i
< len
; i
++ )
4145 wxDataViewColumn
* col
= GetColumnAt(i
);
4146 if (col
->IsHidden())
4148 ret
+= col
->GetWidth();
4151 CalcScrolledPosition( ret
, dummy
, &ret
, &dummy
);
4158 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4160 return m_sortingColumnIdx
== wxNOT_FOUND
? NULL
4161 : GetColumn(m_sortingColumnIdx
);
4164 // Selection code with wxDataViewItem as parameters
4165 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4167 return m_clientArea
->GetSelection();
4170 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4173 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4174 int len
= selection
.GetCount();
4175 for( int i
= 0; i
< len
; i
++)
4177 unsigned int row
= selection
[i
];
4178 sel
.Add( m_clientArea
->GetItemByRow( row
) );
4183 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4185 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4187 wxDataViewItem last_parent
;
4189 int len
= sel
.GetCount();
4190 for( int i
= 0; i
< len
; i
++ )
4192 wxDataViewItem item
= sel
[i
];
4193 wxDataViewItem parent
= GetModel()->GetParent( item
);
4196 if (parent
!= last_parent
)
4197 ExpandAncestors(item
);
4200 last_parent
= parent
;
4201 int row
= m_clientArea
->GetRowByItem( item
);
4203 selection
.Add( static_cast<unsigned int>(row
) );
4206 m_clientArea
->SetSelections( selection
);
4209 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4211 ExpandAncestors( item
);
4213 int row
= m_clientArea
->GetRowByItem( item
);
4216 // Unselect all rows before select another in the single select mode
4217 if (m_clientArea
->IsSingleSel())
4218 m_clientArea
->SelectAllRows(false);
4219 m_clientArea
->SelectRow(row
, true);
4223 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4225 int row
= m_clientArea
->GetRowByItem( item
);
4227 m_clientArea
->SelectRow(row
, false);
4230 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4232 int row
= m_clientArea
->GetRowByItem( item
);
4235 return m_clientArea
->IsRowSelected(row
);
4240 // Selection code with row number as parameter
4241 int wxDataViewCtrl::GetSelections( wxArrayInt
& sel
) const
4244 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4245 int len
= selection
.GetCount();
4246 for( int i
= 0; i
< len
; i
++)
4248 unsigned int row
= selection
[i
];
4254 void wxDataViewCtrl::SetSelections( const wxArrayInt
& sel
)
4256 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4257 int len
= sel
.GetCount();
4258 for( int i
= 0; i
< len
; i
++ )
4262 selection
.Add( static_cast<unsigned int>(row
) );
4264 m_clientArea
->SetSelections( selection
);
4267 void wxDataViewCtrl::Select( int row
)
4271 if (m_clientArea
->IsSingleSel())
4272 m_clientArea
->SelectAllRows(false);
4273 m_clientArea
->SelectRow( row
, true );
4277 void wxDataViewCtrl::Unselect( int row
)
4280 m_clientArea
->SelectRow(row
, false);
4283 bool wxDataViewCtrl::IsSelected( int row
) const
4286 return m_clientArea
->IsRowSelected(row
);
4290 void wxDataViewCtrl::SelectRange( int from
, int to
)
4293 for( int i
= from
; i
< to
; i
++ )
4295 m_clientArea
->Select(sel
);
4298 void wxDataViewCtrl::UnselectRange( int from
, int to
)
4300 wxDataViewSelection sel
= m_clientArea
->GetSelections();
4301 for( int i
= from
; i
< to
; i
++ )
4302 if( sel
.Index( i
) != wxNOT_FOUND
)
4304 m_clientArea
->SetSelections(sel
);
4307 void wxDataViewCtrl::SelectAll()
4309 m_clientArea
->SelectAllRows(true);
4312 void wxDataViewCtrl::UnselectAll()
4314 m_clientArea
->SelectAllRows(false);
4317 void wxDataViewCtrl::EnsureVisible( int row
, int column
)
4321 if( row
> (int) m_clientArea
->GetRowCount() )
4322 row
= m_clientArea
->GetRowCount();
4324 int first
= m_clientArea
->GetFirstVisibleRow();
4325 int last
= m_clientArea
->GetLastVisibleRow();
4327 m_clientArea
->ScrollTo( row
, column
);
4328 else if( row
> last
)
4329 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
4331 m_clientArea
->ScrollTo( first
, column
);
4334 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
4336 ExpandAncestors( item
);
4338 m_clientArea
->RecalculateDisplay();
4340 int row
= m_clientArea
->GetRowByItem(item
);
4343 if( column
== NULL
)
4344 EnsureVisible(row
, -1);
4346 EnsureVisible( row
, GetColumnIndex(column
) );
4351 void wxDataViewCtrl::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
4352 wxDataViewColumn
* &column
) const
4354 m_clientArea
->HitTest(point
, item
, column
);
4357 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
& item
,
4358 const wxDataViewColumn
* column
) const
4360 return m_clientArea
->GetItemRect(item
, column
);
4363 wxDataViewItem
wxDataViewCtrl::GetItemByRow( unsigned int row
) const
4365 return m_clientArea
->GetItemByRow( row
);
4368 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem
& item
) const
4370 return m_clientArea
->GetRowByItem( item
);
4373 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4375 int row
= m_clientArea
->GetRowByItem( item
);
4377 m_clientArea
->Expand(row
);
4380 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4382 int row
= m_clientArea
->GetRowByItem( item
);
4384 m_clientArea
->Collapse(row
);
4387 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4389 int row
= m_clientArea
->GetRowByItem( item
);
4391 return m_clientArea
->IsExpanded(row
);
4395 void wxDataViewCtrl::StartEditor( const wxDataViewItem
& item
, unsigned int column
)
4397 wxDataViewColumn
* col
= GetColumn( column
);
4401 wxRect itemRect
= GetItemRect(item
, col
);
4402 wxDataViewRenderer
* renderer
= col
->GetRenderer();
4403 renderer
->StartEditing(item
, itemRect
);
4406 #endif // !wxUSE_GENERICDATAVIEWCTRL
4408 #endif // wxUSE_DATAVIEWCTRL