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
)
619 wxDataViewRenderer::~wxDataViewRenderer()
625 wxDC
*wxDataViewRenderer::GetDC()
629 if (GetOwner() == NULL
)
631 if (GetOwner()->GetOwner() == NULL
)
633 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
639 void wxDataViewRenderer::SetAlignment( int align
)
644 int wxDataViewRenderer::GetAlignment() const
649 int wxDataViewRenderer::CalculateAlignment() const
651 if (m_align
== wxDVR_DEFAULT_ALIGNMENT
)
653 if (GetOwner() == NULL
)
654 return wxALIGN_LEFT
| wxALIGN_CENTRE_VERTICAL
;
656 return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
662 // ---------------------------------------------------------
663 // wxDataViewCustomRenderer
664 // ---------------------------------------------------------
666 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
668 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
669 wxDataViewCellMode mode
, int align
) :
670 wxDataViewRenderer( varianttype
, mode
, align
)
674 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
,
675 wxRect cell
, wxDC
*dc
, int state
)
677 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
678 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
679 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
680 view
->GetForegroundColour();
681 dc
->SetTextForeground(col
);
684 cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
687 // ---------------------------------------------------------
688 // wxDataViewTextRenderer
689 // ---------------------------------------------------------
691 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
693 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
694 wxDataViewCellMode mode
, int align
) :
695 wxDataViewCustomRenderer( varianttype
, mode
, align
)
699 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
701 m_text
= value
.GetString();
706 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
711 bool wxDataViewTextRenderer::HasEditorCtrl() const
716 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
717 wxRect labelRect
, const wxVariant
&value
)
719 return new wxTextCtrl( parent
, wxID_ANY
, value
,
720 wxPoint(labelRect
.x
,labelRect
.y
),
721 wxSize(labelRect
.width
,labelRect
.height
) );
724 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
726 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
727 value
= text
->GetValue();
731 bool wxDataViewTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
733 RenderText( m_text
, 0, cell
, dc
, state
);
737 wxSize
wxDataViewTextRenderer::GetSize() const
739 const wxDataViewCtrl
*view
= GetView();
741 return view
->wxWindowBase::GetTextExtent( m_text
);
742 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
745 // ---------------------------------------------------------
746 // wxDataViewTextRendererAttr
747 // ---------------------------------------------------------
749 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
, wxDataViewTextRenderer
)
751 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
752 wxDataViewCellMode mode
, int align
) :
753 wxDataViewTextRenderer( varianttype
, mode
, align
)
758 bool wxDataViewTextRendererAttr::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
765 if (m_attr
.HasColour())
767 colour
= dc
->GetTextForeground();
768 dc
->SetTextForeground( m_attr
.GetColour() );
771 if (m_attr
.GetBold() || m_attr
.GetItalic())
773 font
= dc
->GetFont();
774 wxFont myfont
= font
;
775 if (m_attr
.GetBold())
776 myfont
.SetWeight( wxFONTWEIGHT_BOLD
);
777 if (m_attr
.GetItalic())
778 myfont
.SetStyle( wxFONTSTYLE_ITALIC
);
779 dc
->SetFont( myfont
);
783 dc
->DrawText( m_text
, cell
.x
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
788 if (m_attr
.HasColour())
789 dc
->SetTextForeground( colour
);
791 if (m_attr
.GetBold() || m_attr
.GetItalic())
799 // ---------------------------------------------------------
800 // wxDataViewBitmapRenderer
801 // ---------------------------------------------------------
803 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
805 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
806 wxDataViewCellMode mode
, int align
) :
807 wxDataViewCustomRenderer( varianttype
, mode
, align
)
811 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
813 if (value
.GetType() == wxT("wxBitmap"))
815 if (value
.GetType() == wxT("wxIcon"))
821 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
826 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
829 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
830 else if (m_icon
.Ok())
831 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
836 wxSize
wxDataViewBitmapRenderer::GetSize() const
839 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
840 else if (m_icon
.Ok())
841 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
843 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
846 // ---------------------------------------------------------
847 // wxDataViewToggleRenderer
848 // ---------------------------------------------------------
850 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
852 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
853 wxDataViewCellMode mode
, int align
) :
854 wxDataViewCustomRenderer( varianttype
, mode
, align
)
859 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
861 m_toggle
= value
.GetBool();
866 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
871 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
875 flags
|= wxCONTROL_CHECKED
;
876 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
877 flags
|= wxCONTROL_DISABLED
;
879 wxRendererNative::Get().DrawCheckBox(
880 GetOwner()->GetOwner(),
888 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
889 wxDataViewModel
*model
,
890 const wxDataViewItem
& item
, unsigned int col
)
892 bool value
= !m_toggle
;
893 wxVariant variant
= value
;
894 model
->SetValue( variant
, item
, col
);
895 model
->ValueChanged( item
, col
);
899 wxSize
wxDataViewToggleRenderer::GetSize() const
901 // the window parameter is not used by GetCheckBoxSize() so it's
903 return wxRendererNative::Get().GetCheckBoxSize(NULL
);
906 // ---------------------------------------------------------
907 // wxDataViewProgressRenderer
908 // ---------------------------------------------------------
910 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
912 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
913 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
914 wxDataViewCustomRenderer( varianttype
, mode
, align
)
920 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
924 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
926 m_value
= (long) value
;
928 if (m_value
< 0) m_value
= 0;
929 if (m_value
> 100) m_value
= 100;
934 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
936 value
= (long) m_value
;
940 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
942 double pct
= (double)m_value
/ 100.0;
944 bar
.width
= (int)(cell
.width
* pct
);
945 dc
->SetPen( *wxTRANSPARENT_PEN
);
946 dc
->SetBrush( *wxBLUE_BRUSH
);
947 dc
->DrawRectangle( bar
);
949 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
950 dc
->SetPen( *wxBLACK_PEN
);
951 dc
->DrawRectangle( cell
);
956 wxSize
wxDataViewProgressRenderer::GetSize() const
958 return wxSize(40,12);
961 // ---------------------------------------------------------
962 // wxDataViewDateRenderer
963 // ---------------------------------------------------------
965 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
967 #if wxUSE_DATE_RENDERER_POPUP
969 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
972 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
973 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
) :
974 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
),
979 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
980 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
981 sizer
->Add( m_cal
, 1, wxGROW
);
986 void OnCalendar( wxCalendarEvent
&event
);
988 wxCalendarCtrl
*m_cal
;
989 wxDataViewModel
*m_model
;
991 const wxDataViewItem
& m_item
;
994 virtual void OnDismiss()
999 DECLARE_EVENT_TABLE()
1002 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1003 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
1006 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1008 wxDateTime date
= event
.GetDate();
1009 wxVariant value
= date
;
1010 m_model
->SetValue( value
, m_item
, m_col
);
1011 m_model
->ValueChanged( m_item
, m_col
);
1015 #endif // wxUSE_DATE_RENDERER_POPUP
1017 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1019 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1020 wxDataViewCellMode mode
, int align
) :
1021 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1025 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1027 m_date
= value
.GetDateTime();
1032 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1038 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1040 wxString tmp
= m_date
.FormatDate();
1041 RenderText( tmp
, 0, cell
, dc
, state
);
1045 wxSize
wxDataViewDateRenderer::GetSize() const
1047 const wxDataViewCtrl
* view
= GetView();
1048 wxString tmp
= m_date
.FormatDate();
1050 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1051 return wxSize(x
,y
+d
);
1054 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
1055 const wxDataViewItem
& item
, unsigned int col
)
1058 model
->GetValue( variant
, item
, col
);
1059 wxDateTime value
= variant
.GetDateTime();
1061 #if wxUSE_DATE_RENDERER_POPUP
1062 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1063 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1064 wxPoint pos
= wxGetMousePosition();
1067 popup
->Popup( popup
->m_cal
);
1068 #else // !wxUSE_DATE_RENDERER_POPUP
1069 wxMessageBox(value
.Format());
1070 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
1074 // ---------------------------------------------------------
1075 // wxDataViewIconTextRenderer
1076 // ---------------------------------------------------------
1078 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1080 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1081 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1082 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1085 SetAlignment(align
);
1088 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1092 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1098 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1103 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1106 const wxIcon
&icon
= m_value
.GetIcon();
1109 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ ((cell
.height
- icon
.GetHeight()) / 2));
1110 xoffset
= icon
.GetWidth()+4;
1113 RenderText( m_value
.GetText(), xoffset
, cell
, dc
, state
);
1118 wxSize
wxDataViewIconTextRenderer::GetSize() const
1120 const wxDataViewCtrl
*view
= GetView();
1121 if (!m_value
.GetText().empty())
1124 view
->GetTextExtent( m_value
.GetText(), &x
, &y
);
1126 if (m_value
.GetIcon().IsOk())
1127 x
+= m_value
.GetIcon().GetWidth() + 4;
1128 return wxSize( x
, y
);
1130 return wxSize(80,20);
1133 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1135 wxDataViewIconText iconText
;
1138 wxString text
= iconText
.GetText();
1140 // adjust the label rect to take the width of the icon into account
1141 if (iconText
.GetIcon().IsOk())
1143 int w
= iconText
.GetIcon().GetWidth() + 4;
1145 labelRect
.width
-= w
;
1148 return new wxTextCtrl( parent
, wxID_ANY
, text
,
1149 wxPoint(labelRect
.x
,labelRect
.y
),
1150 wxSize(labelRect
.width
,labelRect
.height
) );
1153 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
& value
)
1155 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
1157 wxDataViewIconText
iconText(text
->GetValue(), m_value
.GetIcon());
1162 //-----------------------------------------------------------------------------
1163 // wxDataViewDropTarget
1164 //-----------------------------------------------------------------------------
1166 #if wxUSE_DRAG_AND_DROP
1168 class wxBitmapCanvas
: public wxWindow
1171 wxBitmapCanvas( wxWindow
*parent
, const wxBitmap
&bitmap
, const wxSize
&size
) :
1172 wxWindow( parent
, wxID_ANY
, wxPoint(0,0), size
)
1175 Connect( wxEVT_PAINT
, wxPaintEventHandler(wxBitmapCanvas::OnPaint
) );
1178 void OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1181 dc
.DrawBitmap( m_bitmap
, 0, 0);
1187 class wxDataViewDropSource
: public wxDropSource
1190 wxDataViewDropSource( wxDataViewMainWindow
*win
, unsigned int row
) :
1198 ~wxDataViewDropSource()
1203 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
) )
1205 wxPoint pos
= wxGetMousePosition();
1209 int liney
= m_win
->GetLineStart( m_row
);
1211 m_win
->GetOwner()->CalcUnscrolledPosition( 0, liney
, NULL
, &liney
);
1212 m_win
->ClientToScreen( &linex
, &liney
);
1213 m_dist_x
= pos
.x
- linex
;
1214 m_dist_y
= pos
.y
- liney
;
1217 wxBitmap ib
= m_win
->CreateItemBitmap( m_row
, indent
);
1219 m_hint
= new wxFrame( m_win
->GetParent(), wxID_ANY
, wxEmptyString
,
1220 wxPoint(pos
.x
- m_dist_x
, pos
.y
+ 5 ),
1222 wxFRAME_TOOL_WINDOW
|
1223 wxFRAME_FLOAT_ON_PARENT
|
1224 wxFRAME_NO_TASKBAR
|
1226 new wxBitmapCanvas( m_hint
, ib
, ib
.GetSize() );
1231 m_hint
->Move( pos
.x
- m_dist_x
, pos
.y
+ 5 );
1232 m_hint
->SetTransparent( 128 );
1238 wxDataViewMainWindow
*m_win
;
1241 int m_dist_x
,m_dist_y
;
1245 class wxDataViewDropTarget
: public wxDropTarget
1248 wxDataViewDropTarget( wxDataObject
*obj
, wxDataViewMainWindow
*win
) :
1254 virtual wxDragResult
OnDragOver( wxCoord x
, wxCoord y
, wxDragResult def
)
1256 wxDataFormat format
= GetMatchingPair();
1257 if (format
== wxDF_INVALID
)
1259 return m_win
->OnDragOver( format
, x
, y
, def
);
1262 virtual bool OnDrop( wxCoord x
, wxCoord y
)
1264 wxDataFormat format
= GetMatchingPair();
1265 if (format
== wxDF_INVALID
)
1267 return m_win
->OnDrop( format
, x
, y
);
1270 virtual wxDragResult
OnData( wxCoord x
, wxCoord y
, wxDragResult def
)
1272 wxDataFormat format
= GetMatchingPair();
1273 if (format
== wxDF_INVALID
)
1277 return m_win
->OnData( format
, x
, y
, def
);
1280 virtual void OnLeave()
1281 { m_win
->OnLeave(); }
1283 wxDataViewMainWindow
*m_win
;
1286 #endif // wxUSE_DRAG_AND_DROP
1288 //-----------------------------------------------------------------------------
1289 // wxDataViewRenameTimer
1290 //-----------------------------------------------------------------------------
1292 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1297 void wxDataViewRenameTimer::Notify()
1299 m_owner
->OnRenameTimer();
1302 //-----------------------------------------------------------------------------
1303 // wxDataViewMainWindow
1304 //-----------------------------------------------------------------------------
1306 // The tree building helper, declared firstly
1307 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
1308 wxDataViewTreeNode
* node
);
1310 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1312 if (row1
> row2
) return 1;
1313 if (row1
== row2
) return 0;
1317 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1319 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1320 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1321 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1322 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1323 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1324 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1327 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1328 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1329 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
1330 m_selection( wxDataViewSelectionCmp
)
1335 m_lastOnSame
= false;
1336 m_renameTimer
= new wxDataViewRenameTimer( this );
1338 // TODO: user better initial values/nothing selected
1339 m_currentCol
= NULL
;
1342 m_lineHeight
= wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
1344 #if wxUSE_DRAG_AND_DROP
1346 m_dragStart
= wxPoint(0,0);
1348 m_dragEnabled
= false;
1349 m_dropEnabled
= false;
1351 m_dropHintLine
= (unsigned int) -1;
1352 #endif // wxUSE_DRAG_AND_DROP
1354 m_lineLastClicked
= (unsigned int) -1;
1355 m_lineBeforeLastClicked
= (unsigned int) -1;
1356 m_lineSelectSingleOnUp
= (unsigned int) -1;
1360 SetBackgroundColour( *wxWHITE
);
1362 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1364 m_penRule
= wxPen(GetRuleColour());
1366 // compose a pen whichcan draw black lines
1367 // TODO: maybe there is something system colour to use
1368 m_penExpander
= wxPen(wxColour(0,0,0));
1370 m_root
= new wxDataViewTreeNode( NULL
);
1371 m_root
->SetHasChildren(true);
1373 // Make m_count = -1 will cause the class recaculate the real displaying number of rows.
1375 m_underMouse
= NULL
;
1379 wxDataViewMainWindow::~wxDataViewMainWindow()
1382 delete m_renameTimer
;
1386 #if wxUSE_DRAG_AND_DROP
1387 bool wxDataViewMainWindow::EnableDragSource( const wxDataFormat
&format
)
1389 m_dragFormat
= format
;
1390 m_dragEnabled
= format
!= wxDF_INVALID
;
1395 bool wxDataViewMainWindow::EnableDropTarget( const wxDataFormat
&format
)
1397 m_dropFormat
= format
;
1398 m_dropEnabled
= format
!= wxDF_INVALID
;
1401 SetDropTarget( new wxDataViewDropTarget( new wxCustomDataObject( format
), this ) );
1406 void wxDataViewMainWindow::RemoveDropHint()
1411 RefreshRow( m_dropHintLine
);
1412 m_dropHintLine
= (unsigned int) -1;
1416 wxDragResult
wxDataViewMainWindow::OnDragOver( wxDataFormat format
, wxCoord x
,
1417 wxCoord y
, wxDragResult def
)
1421 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1422 unsigned int row
= GetLineAt( yy
);
1424 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1430 wxDataViewItem item
= GetItemByRow( row
);
1432 wxDataViewModel
*model
= GetOwner()->GetModel();
1434 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1435 event
.SetEventObject( m_owner
);
1436 event
.SetItem( item
);
1437 event
.SetModel( model
);
1438 event
.SetDataFormat( format
);
1439 if (!m_owner
->HandleWindowEvent( event
))
1445 if (!event
.IsAllowed())
1452 if (m_dropHint
&& (row
!= m_dropHintLine
))
1453 RefreshRow( m_dropHintLine
);
1455 m_dropHintLine
= row
;
1461 bool wxDataViewMainWindow::OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
)
1467 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1468 unsigned int row
= GetLineAt( yy
);
1470 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1473 wxDataViewItem item
= GetItemByRow( row
);
1475 wxDataViewModel
*model
= GetOwner()->GetModel();
1477 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1478 event
.SetEventObject( m_owner
);
1479 event
.SetItem( item
);
1480 event
.SetModel( model
);
1481 event
.SetDataFormat( format
);
1482 if (!m_owner
->HandleWindowEvent( event
))
1485 if (!event
.IsAllowed())
1491 wxDragResult
wxDataViewMainWindow::OnData( wxDataFormat format
, wxCoord x
, wxCoord y
,
1496 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1497 unsigned int row
= GetLineAt( yy
);
1499 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1502 wxDataViewItem item
= GetItemByRow( row
);
1504 wxDataViewModel
*model
= GetOwner()->GetModel();
1506 wxCustomDataObject
*obj
= (wxCustomDataObject
*) GetDropTarget()->GetDataObject();
1508 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
1509 event
.SetEventObject( m_owner
);
1510 event
.SetItem( item
);
1511 event
.SetModel( model
);
1512 event
.SetDataFormat( format
);
1513 event
.SetDataSize( obj
->GetSize() );
1514 event
.SetDataBuffer( obj
->GetData() );
1515 if (!m_owner
->HandleWindowEvent( event
))
1518 if (!event
.IsAllowed())
1524 void wxDataViewMainWindow::OnLeave()
1529 wxBitmap
wxDataViewMainWindow::CreateItemBitmap( unsigned int row
, int &indent
)
1531 int height
= GetLineHeight( row
);
1533 unsigned int cols
= GetOwner()->GetColumnCount();
1535 for (col
= 0; col
< cols
; col
++)
1537 wxDataViewColumn
*column
= GetOwner()->GetColumnAt(col
);
1538 if (column
->IsHidden())
1539 continue; // skip it!
1540 width
+= column
->GetWidth();
1544 if (!IsVirtualList())
1546 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
1547 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
1548 indent
= indent
+ m_lineHeight
;
1549 // try to use the m_lineHeight as the expander space
1551 if(!node
->HasChildren())
1556 wxBitmap
bitmap( width
, height
);
1557 wxMemoryDC
dc( bitmap
);
1558 dc
.SetFont( GetFont() );
1559 dc
.SetPen( *wxBLACK_PEN
);
1560 dc
.SetBrush( *wxWHITE_BRUSH
);
1561 dc
.DrawRectangle( 0,0,width
,height
);
1563 wxDataViewModel
*model
= m_owner
->GetModel();
1565 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1568 // TODO-RTL: last column for RTL support
1569 expander
= GetOwner()->GetColumnAt( 0 );
1570 GetOwner()->SetExpanderColumn(expander
);
1575 for (col
= 0; col
< cols
; col
++)
1577 wxDataViewColumn
*column
= GetOwner()->GetColumnAt( col
);
1578 wxDataViewRenderer
*cell
= column
->GetRenderer();
1580 if (column
->IsHidden())
1581 continue; // skip it!
1583 width
= column
->GetWidth();
1585 if (column
== expander
)
1589 wxDataViewItem item
= GetItemByRow( row
);
1590 model
->GetValue( value
, item
, column
->GetModelColumn());
1591 cell
->SetValue( value
);
1593 if (cell
->GetWantsAttr())
1595 wxDataViewItemAttr attr
;
1596 bool ret
= model
->GetAttr( item
, column
->GetModelColumn(), attr
);
1598 cell
->SetAttr( attr
);
1599 cell
->SetHasAttr( ret
);
1602 wxSize size
= cell
->GetSize();
1603 size
.x
= wxMin( 2*PADDING_RIGHTLEFT
+ size
.x
, width
);
1605 wxRect
item_rect(x
, 0, size
.x
, size
.y
);
1607 int align
= cell
->CalculateAlignment();
1608 // horizontal alignment:
1610 if (align
& wxALIGN_CENTER_HORIZONTAL
)
1611 item_rect
.x
= x
+ (width
/ 2) - (size
.x
/ 2);
1612 else if (align
& wxALIGN_RIGHT
)
1613 item_rect
.x
= x
+ width
- size
.x
;
1614 // else: wxALIGN_LEFT is the default
1616 // vertical alignment:
1618 if (align
& wxALIGN_CENTER_VERTICAL
)
1619 item_rect
.y
= (height
/ 2) - (size
.y
/ 2);
1620 else if (align
& wxALIGN_BOTTOM
)
1621 item_rect
.y
= height
- size
.y
;
1622 // else: wxALIGN_TOP is the default
1625 item_rect
.x
+= PADDING_RIGHTLEFT
;
1626 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
1628 // dc.SetClippingRegion( item_rect );
1629 cell
->Render( item_rect
, &dc
, 0 );
1630 // dc.DestroyClippingRegion();
1638 #endif // wxUSE_DRAG_AND_DROP
1641 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1643 wxDataViewModel
*model
= GetOwner()->GetModel();
1644 wxAutoBufferedPaintDC
dc( this );
1647 dc
.SetPen( *wxTRANSPARENT_PEN
);
1648 dc
.SetBrush( wxBrush( GetBackgroundColour()) );
1649 dc
.SetBrush( *wxWHITE_BRUSH
);
1650 wxSize
size( GetClientSize() );
1651 dc
.DrawRectangle( 0,0,size
.x
,size
.y
);
1655 GetOwner()->PrepareDC( dc
);
1656 dc
.SetFont( GetFont() );
1658 wxRect update
= GetUpdateRegion().GetBox();
1659 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1661 // compute which items needs to be redrawn
1662 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
1663 unsigned int item_count
=
1664 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
1665 (int)(GetRowCount( ) - item_start
));
1666 unsigned int item_last
= item_start
+ item_count
;
1668 // compute which columns needs to be redrawn
1669 unsigned int cols
= GetOwner()->GetColumnCount();
1670 unsigned int col_start
= 0;
1671 unsigned int x_start
;
1672 for (x_start
= 0; col_start
< cols
; col_start
++)
1674 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_start
);
1675 if (col
->IsHidden())
1676 continue; // skip it!
1678 unsigned int w
= col
->GetWidth();
1679 if (x_start
+w
>= (unsigned int)update
.x
)
1685 unsigned int col_last
= col_start
;
1686 unsigned int x_last
= x_start
;
1687 for (; col_last
< cols
; col_last
++)
1689 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_last
);
1690 if (col
->IsHidden())
1691 continue; // skip it!
1693 if (x_last
> (unsigned int)update
.GetRight())
1696 x_last
+= col
->GetWidth();
1699 // Draw horizontal rules if required
1700 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1702 dc
.SetPen(m_penRule
);
1703 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1705 for (unsigned int i
= item_start
; i
<= item_last
; i
++)
1707 int y
= GetLineStart( i
);
1708 dc
.DrawLine(x_start
, y
, x_last
, y
);
1712 // Draw vertical rules if required
1713 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1715 dc
.SetPen(m_penRule
);
1716 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1719 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1721 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(i
);
1722 if (col
->IsHidden())
1723 continue; // skip it
1725 dc
.DrawLine(x
, GetLineStart( item_start
),
1726 x
, GetLineStart( item_last
) );
1728 x
+= col
->GetWidth();
1731 // Draw last vertical rule
1732 dc
.DrawLine(x
, GetLineStart( item_start
),
1733 x
, GetLineStart( item_last
) );
1736 // redraw the background for the items which are selected/current
1737 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1739 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1740 if (selected
|| item
== m_currentRow
)
1742 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
1743 if (item
== m_currentRow
)
1744 flags
|= wxCONTROL_CURRENT
;
1746 flags
|= wxCONTROL_FOCUSED
;
1748 wxRect
rect( x_start
, GetLineStart( item
), x_last
, GetLineHeight( item
) );
1749 wxRendererNative::Get().DrawItemSelectionRect
1759 #if wxUSE_DRAG_AND_DROP
1762 wxRect
rect( x_start
, GetLineStart( m_dropHintLine
),
1763 x_last
, GetLineHeight( m_dropHintLine
) );
1764 dc
.SetPen( *wxBLACK_PEN
);
1765 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1766 dc
.DrawRectangle( rect
);
1768 #endif // wxUSE_DRAG_AND_DROP
1770 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1773 // TODO-RTL: last column for RTL support
1774 expander
= GetOwner()->GetColumnAt( 0 );
1775 GetOwner()->SetExpanderColumn(expander
);
1778 // redraw all cells for all rows which must be repainted and all columns
1780 cell_rect
.x
= x_start
;
1781 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1783 wxDataViewColumn
*col
= GetOwner()->GetColumnAt( i
);
1784 wxDataViewRenderer
*cell
= col
->GetRenderer();
1785 cell_rect
.width
= col
->GetWidth();
1787 if (col
->IsHidden())
1788 continue; // skip it!
1790 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1792 // get the cell value and set it into the renderer
1794 wxDataViewTreeNode
*node
= NULL
;
1795 wxDataViewItem dataitem
;
1797 if (!IsVirtualList())
1799 node
= GetTreeNodeByRow(item
);
1803 dataitem
= node
->GetItem();
1805 if ((i
> 0) && model
->IsContainer(dataitem
) &&
1806 !model
->HasContainerColumns(dataitem
))
1811 dataitem
= wxDataViewItem( wxUIntToPtr(item
) );
1814 model
->GetValue( value
, dataitem
, col
->GetModelColumn());
1815 cell
->SetValue( value
);
1817 if (cell
->GetWantsAttr())
1819 wxDataViewItemAttr attr
;
1820 bool ret
= model
->GetAttr( dataitem
, col
->GetModelColumn(), attr
);
1822 cell
->SetAttr( attr
);
1823 cell
->SetHasAttr( ret
);
1827 cell_rect
.y
= GetLineStart( item
);
1828 cell_rect
.height
= GetLineHeight( item
);
1830 // Draw the expander here.
1832 if ((!IsVirtualList()) && (col
== expander
))
1834 indent
= node
->GetIndentLevel();
1836 // Calculate the indent first
1837 indent
= cell_rect
.x
+ GetOwner()->GetIndent() * indent
;
1839 int expander_width
= m_lineHeight
- 2*EXPANDER_MARGIN
;
1841 // change the cell_rect.x to the appropriate pos
1842 int expander_x
= indent
+ EXPANDER_MARGIN
;
1843 int expander_y
= cell_rect
.y
+ EXPANDER_MARGIN
+ (GetLineHeight(item
) / 2)
1844 - (expander_width
/2) - EXPANDER_OFFSET
;
1846 indent
= indent
+ m_lineHeight
;
1847 // try to use the m_lineHeight as the expander space
1849 dc
.SetPen( m_penExpander
);
1850 dc
.SetBrush( wxNullBrush
);
1851 if( node
->HasChildren() )
1853 wxRect
rect( expander_x
, expander_y
, expander_width
, expander_width
);
1855 if (m_underMouse
== node
)
1857 flag
|= wxCONTROL_CURRENT
;
1859 if( node
->IsOpen() )
1860 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
,
1861 flag
|wxCONTROL_EXPANDED
);
1863 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
1866 // force the expander column to left-center align
1867 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
1869 if (node
&& !node
->HasChildren())
1871 // Yes, if the node does not have any child, it must be a leaf which
1872 // mean that it is a temporarily created by GetTreeNodeByRow
1876 // cannot be bigger than allocated space
1877 wxSize size
= cell
->GetSize();
1879 // Because of the tree structure indent, here we should minus the width
1880 // of the cell for drawing
1881 size
.x
= wxMin( size
.x
+ 2*PADDING_RIGHTLEFT
, cell_rect
.width
- indent
);
1882 // size.y = wxMin( size.y, cell_rect.height );
1883 size
.y
= cell_rect
.height
;
1885 wxRect
item_rect(cell_rect
.GetTopLeft(), size
);
1886 int align
= cell
->CalculateAlignment();
1888 // horizontal alignment:
1889 item_rect
.x
= cell_rect
.x
;
1890 if (align
& wxALIGN_CENTER_HORIZONTAL
)
1891 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
1892 else if (align
& wxALIGN_RIGHT
)
1893 item_rect
.x
= cell_rect
.x
+ cell_rect
.width
- size
.x
;
1894 // else: wxALIGN_LEFT is the default
1896 // vertical alignment:
1897 item_rect
.y
= cell_rect
.y
;
1898 if (align
& wxALIGN_CENTER_VERTICAL
)
1899 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
1900 else if (align
& wxALIGN_BOTTOM
)
1901 item_rect
.y
= cell_rect
.y
+ cell_rect
.height
- size
.y
;
1902 // else: wxALIGN_TOP is the default
1905 item_rect
.x
+= PADDING_RIGHTLEFT
;
1906 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
1908 // Here we add the tree indent
1909 item_rect
.x
+= indent
;
1912 if (m_hasFocus
&& (m_selection
.Index(item
) != wxNOT_FOUND
))
1913 state
|= wxDATAVIEW_CELL_SELECTED
;
1915 // TODO: it would be much more efficient to create a clipping
1916 // region for the entire column being rendered (in the OnPaint
1917 // of wxDataViewMainWindow) instead of a single clip region for
1918 // each cell. However it would mean that each renderer should
1919 // respect the given wxRect's top & bottom coords, eventually
1920 // violating only the left & right coords - however the user can
1921 // make its own renderer and thus we cannot be sure of that.
1922 dc
.SetClippingRegion( item_rect
);
1923 cell
->Render( item_rect
, &dc
, state
);
1924 dc
.DestroyClippingRegion();
1927 cell_rect
.x
+= cell_rect
.width
;
1931 void wxDataViewMainWindow::OnRenameTimer()
1933 // We have to call this here because changes may just have
1934 // been made and no screen update taken place.
1937 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
1938 // (needs to be tested!)
1943 unsigned int cols
= GetOwner()->GetColumnCount();
1945 for (i
= 0; i
< cols
; i
++)
1947 wxDataViewColumn
*c
= GetOwner()->GetColumnAt( i
);
1949 continue; // skip it!
1951 if (c
== m_currentCol
)
1953 xpos
+= c
->GetWidth();
1956 // we have to take an expander column into account and compute its indentation
1957 // to get the editor at the correct x position where the actual text is
1959 if (!IsVirtualList() && GetOwner()->GetExpanderColumn() == m_currentCol
)
1961 wxDataViewTreeNode
* node
= GetTreeNodeByRow(m_currentRow
);
1962 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
1963 indent
= indent
+ m_lineHeight
;
1965 if(!node
->HasChildren())
1969 wxRect
labelRect( xpos
+ indent
,
1970 GetLineStart( m_currentRow
),
1971 m_currentCol
->GetWidth() - indent
,
1972 GetLineHeight( m_currentRow
) );
1974 GetOwner()->CalcScrolledPosition( labelRect
.x
, labelRect
.y
,
1975 &labelRect
.x
, &labelRect
.y
);
1977 wxDataViewItem item
= GetItemByRow( m_currentRow
);
1978 m_currentCol
->GetRenderer()->StartEditing( item
, labelRect
);
1981 //-----------------------------------------------------------------------------
1982 // Helper class for do operation on the tree node
1983 //-----------------------------------------------------------------------------
1988 virtual ~DoJob() { }
1990 // The return value control how the tree-walker tranverse the tree
1991 // 0: Job done, stop tranverse and return
1992 // 1: Ignore the current node's subtree and continue
1993 // 2: Job not done, continue
1994 enum { OK
= 0 , IGR
= 1, CONT
= 2 };
1995 virtual int operator() ( wxDataViewTreeNode
* node
) = 0;
1996 virtual int operator() ( void * n
) = 0;
1999 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
2004 switch( func( node
) )
2015 wxDataViewTreeNodes nodes
= node
->GetNodes();
2016 wxDataViewTreeLeaves leaves
= node
->GetChildren();
2018 int len_nodes
= nodes
.GetCount();
2019 int len
= leaves
.GetCount();
2020 int i
= 0, nodes_i
= 0;
2022 for(; i
< len
; i
++ )
2024 void * n
= leaves
[i
];
2025 if( nodes_i
< len_nodes
&& n
== nodes
[nodes_i
]->GetItem().GetID() )
2027 wxDataViewTreeNode
* nd
= nodes
[nodes_i
];
2030 if( Walker( nd
, func
) )
2049 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
2060 wxDataViewTreeNode
* node
;
2061 node
= FindNode(parent
);
2066 node
->SetHasChildren( true );
2068 if( g_model
->IsContainer( item
) )
2070 wxDataViewTreeNode
* newnode
= new wxDataViewTreeNode( node
);
2071 newnode
->SetItem(item
);
2072 newnode
->SetHasChildren( true );
2073 node
->AddNode( newnode
);
2076 node
->AddLeaf( item
.GetID() );
2078 node
->ChangeSubTreeCount(1);
2086 static void DestroyTreeHelper( wxDataViewTreeNode
* node
);
2088 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
2089 const wxDataViewItem
& item
)
2094 if( m_currentRow
> GetRowCount() )
2095 m_currentRow
= m_count
- 1;
2097 m_selection
.Empty();
2104 wxDataViewTreeNode
* node
= FindNode(parent
);
2106 wxCHECK_MSG( node
!= NULL
, false, "item not found" );
2107 wxCHECK_MSG( node
->GetChildren().Index( item
.GetID() ) != wxNOT_FOUND
,
2108 false, "item not found" );
2111 node
->GetChildren().Remove( item
.GetID() );
2112 // Manipolate selection
2113 if( m_selection
.GetCount() > 1 )
2115 m_selection
.Empty();
2117 bool isContainer
= false;
2118 wxDataViewTreeNodes nds
= node
->GetNodes();
2119 for (size_t i
= 0; i
< nds
.GetCount(); i
++)
2121 if (nds
[i
]->GetItem() == item
)
2129 wxDataViewTreeNode
* n
= NULL
;
2130 wxDataViewTreeNodes nodes
= node
->GetNodes();
2131 int len
= nodes
.GetCount();
2132 for( int i
= 0; i
< len
; i
++)
2134 if( nodes
[i
]->GetItem() == item
)
2141 wxCHECK_MSG( n
!= NULL
, false, "item not found" );
2143 node
->GetNodes().Remove( n
);
2144 sub
-= n
->GetSubTreeCount();
2145 ::DestroyTreeHelper(n
);
2147 // Make the row number invalid and get a new valid one when user call GetRowCount
2149 node
->ChangeSubTreeCount(sub
);
2151 // Change the current row to the last row if the current exceed the max row number
2152 if( m_currentRow
> GetRowCount() )
2153 m_currentRow
= m_count
- 1;
2160 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
2166 wxWindow
*parent
= GetParent();
2167 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2168 le
.SetEventObject(parent
);
2169 le
.SetModel(GetOwner()->GetModel());
2171 parent
->GetEventHandler()->ProcessEvent(le
);
2176 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
2178 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
2179 /*#define MAX_VIRTUAL_WIDTH 100000
2181 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
2182 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2183 Refresh( true, &rect );
2191 wxWindow
*parent
= GetParent();
2192 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2193 le
.SetEventObject(parent
);
2194 le
.SetModel(GetOwner()->GetModel());
2197 le
.SetDataViewColumn(GetOwner()->GetColumn(col
));
2198 parent
->GetEventHandler()->ProcessEvent(le
);
2203 bool wxDataViewMainWindow::Cleared()
2208 BuildTree( GetOwner()->GetModel() );
2215 void wxDataViewMainWindow::UpdateDisplay()
2220 void wxDataViewMainWindow::OnInternalIdle()
2222 wxWindow::OnInternalIdle();
2226 RecalculateDisplay();
2231 void wxDataViewMainWindow::RecalculateDisplay()
2233 wxDataViewModel
*model
= GetOwner()->GetModel();
2240 int width
= GetEndOfLastCol();
2241 int height
= GetLineStart( GetRowCount() );
2243 SetVirtualSize( width
, height
);
2244 GetOwner()->SetScrollRate( 10, m_lineHeight
);
2249 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2251 wxWindow::ScrollWindow( dx
, dy
, rect
);
2253 if (GetOwner()->m_headerArea
)
2254 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
2257 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
2260 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
2261 int sy
= GetLineStart( rows
)/y
;
2265 wxRect rect
= GetClientRect();
2269 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
2270 for (x_start
= 0; colnum
< column
; colnum
++)
2272 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(colnum
);
2273 if (col
->IsHidden())
2274 continue; // skip it!
2276 w
= col
->GetWidth();
2280 int x_end
= x_start
+ w
;
2281 xe
= xx
+ rect
.width
;
2284 sx
= ( xx
+ x_end
- xe
)/x
;
2291 m_owner
->Scroll( sx
, sy
);
2294 int wxDataViewMainWindow::GetCountPerPage() const
2296 wxSize size
= GetClientSize();
2297 return size
.y
/ m_lineHeight
;
2300 int wxDataViewMainWindow::GetEndOfLastCol() const
2304 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2306 const wxDataViewColumn
*c
=
2307 const_cast<wxDataViewCtrl
*>(GetOwner())->GetColumnAt( i
);
2310 width
+= c
->GetWidth();
2315 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2319 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2321 return GetLineAt( y
);
2324 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
2326 wxSize client_size
= GetClientSize();
2327 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2328 &client_size
.x
, &client_size
.y
);
2330 // we should deal with the pixel here
2331 unsigned int row
= GetLineAt(client_size
.y
) - 1;
2333 return wxMin( GetRowCount()-1, row
);
2336 unsigned int wxDataViewMainWindow::GetRowCount()
2338 if ( m_count
== -1 )
2340 m_count
= RecalculateCount();
2346 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
2353 void wxDataViewMainWindow::SelectAllRows( bool on
)
2360 m_selection
.Clear();
2361 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2362 m_selection
.Add( i
);
2367 unsigned int first_visible
= GetFirstVisibleRow();
2368 unsigned int last_visible
= GetLastVisibleRow();
2370 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2372 unsigned int row
= m_selection
[i
];
2373 if ((row
>= first_visible
) && (row
<= last_visible
))
2376 m_selection
.Clear();
2380 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
2382 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2386 m_selection
.Add( row
);
2394 m_selection
.Remove( row
);
2400 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2404 unsigned int tmp
= from
;
2410 for (i
= from
; i
<= to
; i
++)
2412 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2415 m_selection
.Add( i
);
2420 m_selection
.Remove( i
);
2423 RefreshRows( from
, to
);
2426 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2428 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2430 int n
= aSelections
[i
];
2432 m_selection
.Add( n
);
2437 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2439 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2440 m_selection
.Add( row
);
2442 m_selection
.Remove( row
);
2446 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2448 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2451 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
2453 wxWindow
*parent
= GetParent();
2454 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
2456 le
.SetEventObject(parent
);
2457 le
.SetModel(GetOwner()->GetModel());
2460 parent
->GetEventHandler()->ProcessEvent(le
);
2463 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2465 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
2466 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2468 wxSize client_size
= GetClientSize();
2469 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2470 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2471 if (intersect_rect
.width
> 0)
2472 Refresh( true, &intersect_rect
);
2475 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2479 unsigned int tmp
= to
;
2484 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
2485 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2487 wxSize client_size
= GetClientSize();
2488 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2489 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2490 if (intersect_rect
.width
> 0)
2491 Refresh( true, &intersect_rect
);
2494 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2496 wxSize client_size
= GetClientSize();
2497 int start
= GetLineStart( firstRow
);
2498 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
2499 if (start
> client_size
.y
) return;
2501 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
2503 Refresh( true, &rect
);
2506 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2508 wxCHECK_RET( newCurrent
< GetRowCount(),
2509 _T("invalid item index in OnArrowChar()") );
2511 // if there is no selection, we cannot move it anywhere
2512 if (!HasCurrentRow())
2515 unsigned int oldCurrent
= m_currentRow
;
2517 // in single selection we just ignore Shift as we can't select several
2519 if ( event
.ShiftDown() && !IsSingleSel() )
2521 RefreshRow( oldCurrent
);
2523 ChangeCurrentRow( newCurrent
);
2525 // select all the items between the old and the new one
2526 if ( oldCurrent
> newCurrent
)
2528 newCurrent
= oldCurrent
;
2529 oldCurrent
= m_currentRow
;
2532 SelectRows( oldCurrent
, newCurrent
, true );
2533 if (oldCurrent
!=newCurrent
)
2534 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
2538 RefreshRow( oldCurrent
);
2540 // all previously selected items are unselected unless ctrl is held
2541 if ( !event
.ControlDown() )
2542 SelectAllRows(false);
2544 ChangeCurrentRow( newCurrent
);
2546 if ( !event
.ControlDown() )
2548 SelectRow( m_currentRow
, true );
2549 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
2552 RefreshRow( m_currentRow
);
2555 GetOwner()->EnsureVisible( m_currentRow
, -1 );
2558 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2562 rect
.y
= GetLineStart( row
);
2563 rect
.width
= GetEndOfLastCol();
2564 rect
.height
= GetLineHeight( row
);
2569 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2571 const wxDataViewModel
*model
= GetOwner()->GetModel();
2573 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2575 // TODO make more efficient
2580 for (r
= 0; r
< row
; r
++)
2582 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2583 if (!node
) return start
;
2585 wxDataViewItem item
= node
->GetItem();
2587 if (node
&& !node
->HasChildren())
2589 // Yes, if the node does not have any child, it must be a leaf which
2590 // mean that it is a temporarily created by GetTreeNodeByRow
2594 unsigned int cols
= GetOwner()->GetColumnCount();
2596 int height
= m_lineHeight
;
2597 for (col
= 0; col
< cols
; col
++)
2599 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2600 if (column
->IsHidden())
2601 continue; // skip it!
2604 model
->IsContainer(item
) &&
2605 !model
->HasContainerColumns(item
))
2606 continue; // skip it!
2609 model
->GetValue( value
, item
, column
->GetModelColumn() );
2611 wxDataViewRenderer
*renderer
=
2612 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2613 renderer
->SetValue( value
);
2614 height
= wxMax( height
, renderer
->GetSize().y
);
2624 return row
* m_lineHeight
;
2628 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
2630 const wxDataViewModel
*model
= GetOwner()->GetModel();
2632 // check for the easy case first
2633 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
2634 return y
/ m_lineHeight
;
2636 // TODO make more efficient
2637 unsigned int row
= 0;
2638 unsigned int yy
= 0;
2641 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2644 // not really correct...
2645 return row
+ ((y
-yy
) / m_lineHeight
);
2648 wxDataViewItem item
= node
->GetItem();
2650 if (node
&& !node
->HasChildren())
2652 // Yes, if the node does not have any child, it must be a leaf which
2653 // mean that it is a temporarily created by GetTreeNodeByRow
2657 unsigned int cols
= GetOwner()->GetColumnCount();
2659 int height
= m_lineHeight
;
2660 for (col
= 0; col
< cols
; col
++)
2662 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2663 if (column
->IsHidden())
2664 continue; // skip it!
2667 model
->IsContainer(item
) &&
2668 !model
->HasContainerColumns(item
))
2669 continue; // skip it!
2672 model
->GetValue( value
, item
, column
->GetModelColumn() );
2674 wxDataViewRenderer
*renderer
=
2675 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2676 renderer
->SetValue( value
);
2677 height
= wxMax( height
, renderer
->GetSize().y
);
2688 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
2690 const wxDataViewModel
*model
= GetOwner()->GetModel();
2692 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2694 wxASSERT( !IsVirtualList() );
2696 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2697 // wxASSERT( node );
2698 if (!node
) return m_lineHeight
;
2700 wxDataViewItem item
= node
->GetItem();
2702 if (node
&& !node
->HasChildren())
2704 // Yes, if the node does not have any child, it must be a leaf which
2705 // mean that it is a temporarily created by GetTreeNodeByRow
2709 int height
= m_lineHeight
;
2711 unsigned int cols
= GetOwner()->GetColumnCount();
2713 for (col
= 0; col
< cols
; col
++)
2715 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2716 if (column
->IsHidden())
2717 continue; // skip it!
2720 model
->IsContainer(item
) &&
2721 !model
->HasContainerColumns(item
))
2722 continue; // skip it!
2725 model
->GetValue( value
, item
, column
->GetModelColumn() );
2727 wxDataViewRenderer
*renderer
=
2728 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2729 renderer
->SetValue( value
);
2730 height
= wxMax( height
, renderer
->GetSize().y
);
2737 return m_lineHeight
;
2741 class RowToItemJob
: public DoJob
2744 RowToItemJob( unsigned int row
, int current
)
2745 { this->row
= row
; this->current
= current
; }
2746 virtual ~RowToItemJob() {}
2748 virtual int operator() ( wxDataViewTreeNode
* node
)
2751 if( current
== static_cast<int>(row
))
2753 ret
= node
->GetItem();
2757 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2759 current
+= node
->GetSubTreeCount();
2764 // If the current has no child node, we can find the desired item of the row
2766 // This if can speed up finding in some case, and will has a very good effect
2767 // when it comes to list view
2768 if( node
->GetNodes().GetCount() == 0)
2770 int index
= static_cast<int>(row
) - current
- 1;
2771 ret
= node
->GetChildren().Item( index
);
2778 virtual int operator() ( void * n
)
2781 if( current
== static_cast<int>(row
))
2783 ret
= wxDataViewItem( n
);
2789 wxDataViewItem
GetResult() const
2798 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
2802 return wxDataViewItem( wxUIntToPtr(row
) );
2806 RowToItemJob
job( row
, -2 );
2807 Walker( m_root
, job
);
2808 return job
.GetResult();
2812 class RowToTreeNodeJob
: public DoJob
2815 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
2818 this->current
= current
;
2822 virtual ~RowToTreeNodeJob(){ }
2824 virtual int operator() ( wxDataViewTreeNode
* node
)
2827 if( current
== static_cast<int>(row
))
2833 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2835 current
+= node
->GetSubTreeCount();
2842 // If the current node has no children, we can find the desired item of the
2843 // row number directly.
2844 // This if can speed up finding in some case, and will have a very good
2845 // effect for list views.
2846 if( node
->GetNodes().GetCount() == 0)
2848 int index
= static_cast<int>(row
) - current
- 1;
2849 void * n
= node
->GetChildren().Item( index
);
2850 ret
= new wxDataViewTreeNode( parent
);
2851 ret
->SetItem( wxDataViewItem( n
));
2852 ret
->SetHasChildren(false);
2859 virtual int operator() ( void * n
)
2862 if( current
== static_cast<int>(row
))
2864 ret
= new wxDataViewTreeNode( parent
);
2865 ret
->SetItem( wxDataViewItem( n
));
2866 ret
->SetHasChildren(false);
2873 wxDataViewTreeNode
* GetResult() const
2879 wxDataViewTreeNode
* ret
;
2880 wxDataViewTreeNode
* parent
;
2883 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
2885 wxASSERT( !IsVirtualList() );
2887 RowToTreeNodeJob
job( row
, -2, m_root
);
2888 Walker( m_root
, job
);
2889 return job
.GetResult();
2892 wxDataViewEvent
wxDataViewMainWindow::SendExpanderEvent( wxEventType type
,
2893 const wxDataViewItem
& item
)
2895 wxWindow
*parent
= GetParent();
2896 wxDataViewEvent
le(type
, parent
->GetId());
2898 le
.SetEventObject(parent
);
2899 le
.SetModel(GetOwner()->GetModel());
2902 parent
->GetEventHandler()->ProcessEvent(le
);
2906 bool wxDataViewMainWindow::IsExpanded( unsigned int row
) const
2908 if (IsVirtualList())
2911 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2915 if (!node
->HasChildren())
2921 return node
->IsOpen();
2924 bool wxDataViewMainWindow::HasChildren( unsigned int row
) const
2926 if (IsVirtualList())
2929 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2933 if (!node
->HasChildren())
2942 void wxDataViewMainWindow::Expand( unsigned int row
)
2944 if (IsVirtualList())
2947 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2951 if (!node
->HasChildren())
2957 if (!node
->IsOpen())
2960 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, node
->GetItem());
2962 // Check if the user prevent expanding
2963 if( e
.GetSkipped() )
2968 // build the children of current node
2969 if( node
->GetChildrenNumber() == 0 )
2972 ::BuildTreeHelper(GetOwner()->GetModel(), node
->GetItem(), node
);
2975 // By expanding the node all row indices that are currently in the selection list
2976 // and are greater than our node have become invalid. So we have to correct that now.
2977 const unsigned rowAdjustment
= node
->GetSubTreeCount();
2978 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2980 const unsigned testRow
= m_selection
[i
];
2981 // all rows above us are not affected, so skip them
2985 m_selection
[i
] += rowAdjustment
;
2988 if(m_currentRow
> row
)
2989 ChangeCurrentRow(m_currentRow
+ rowAdjustment
);
2993 // Send the expanded event
2994 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
2998 void wxDataViewMainWindow::Collapse(unsigned int row
)
3000 if (IsVirtualList())
3003 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
3007 if (!node
->HasChildren())
3016 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem());
3017 if( e
.GetSkipped() )
3020 // Find out if there are selected items below the current node.
3021 bool selectCollapsingRow
= false;
3022 const unsigned rowAdjustment
= node
->GetSubTreeCount();
3023 unsigned maxRowToBeTested
= row
+ rowAdjustment
;
3024 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3026 const unsigned testRow
= m_selection
[i
];
3027 if(testRow
> row
&& testRow
<= maxRowToBeTested
)
3029 selectCollapsingRow
= true;
3030 // get out as soon as we have found a node that is selected
3037 // If the node to be closed has selected items the user won't see those any longer.
3038 // We select the collapsing node in this case.
3039 if(selectCollapsingRow
)
3041 SelectAllRows(false);
3042 ChangeCurrentRow(row
);
3043 SelectRow(row
, true);
3044 SendSelectionChangedEvent(GetItemByRow(row
));
3048 // if there were no selected items below our node we still need to "fix" the
3049 // selection list to adjust for the changing of the row indices.
3050 // We actually do the opposite of what we are doing in Expand().
3051 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3053 const unsigned testRow
= m_selection
[i
];
3054 // all rows above us are not affected, so skip them
3058 m_selection
[i
] -= rowAdjustment
;
3061 // if the "current row" is being collapsed away we change it to the current row ;-)
3062 if(m_currentRow
> row
&& m_currentRow
<= maxRowToBeTested
)
3063 ChangeCurrentRow(row
);
3064 else if(m_currentRow
> row
)
3065 ChangeCurrentRow(m_currentRow
- rowAdjustment
);
3070 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,node
->GetItem());
3074 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
3076 wxDataViewModel
* model
= GetOwner()->GetModel();
3083 // Compose the a parent-chain of the finding item
3085 list
.DeleteContents( true );
3086 wxDataViewItem
it( item
);
3089 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3090 list
.Insert( pItem
);
3091 it
= model
->GetParent( it
);
3094 // Find the item along the parent-chain.
3095 // This algorithm is designed to speed up the node-finding method
3096 wxDataViewTreeNode
* node
= m_root
;
3097 for( ItemList::const_iterator iter
= list
.begin(); iter
!=list
.end(); iter
++ )
3099 if( node
->HasChildren() )
3101 if( node
->GetChildrenNumber() == 0 )
3104 ::BuildTreeHelper(model
, node
->GetItem(), node
);
3107 wxDataViewTreeNodes nodes
= node
->GetNodes();
3111 for (i
= 0; i
< nodes
.GetCount(); i
++)
3113 if (nodes
[i
]->GetItem() == (**iter
))
3115 if (nodes
[i
]->GetItem() == item
)
3132 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
3133 wxDataViewColumn
* &column
)
3135 wxDataViewColumn
*col
= NULL
;
3136 unsigned int cols
= GetOwner()->GetColumnCount();
3137 unsigned int colnum
= 0;
3139 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
3140 for (unsigned x_start
= 0; colnum
< cols
; colnum
++)
3142 col
= GetOwner()->GetColumnAt(colnum
);
3143 if (col
->IsHidden())
3144 continue; // skip it!
3146 unsigned int w
= col
->GetWidth();
3147 if (x_start
+w
>= (unsigned int)x
)
3154 item
= GetItemByRow( GetLineAt( y
) );
3157 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
,
3158 const wxDataViewColumn
* column
)
3163 unsigned int cols
= GetOwner()->GetColumnCount();
3164 // If column is null the loop will compute the combined width of all columns.
3165 // Otherwise, it will compute the x position of the column we are looking for.
3166 for (unsigned int i
= 0; i
< cols
; i
++)
3168 wxDataViewColumn
* col
= GetOwner()->GetColumnAt( i
);
3173 if (col
->IsHidden())
3174 continue; // skip it!
3176 xpos
+= col
->GetWidth();
3177 width
+= col
->GetWidth();
3182 // If we have a column, we need can get its width directly.
3183 if(column
->IsHidden())
3186 width
= column
->GetWidth();
3191 // If we have no column, we reset the x position back to zero.
3195 // we have to take an expander column into account and compute its indentation
3196 // to get the correct x position where the actual text is
3198 int row
= GetRowByItem(item
);
3199 if (!IsVirtualList() && (column
== 0 || GetOwner()->GetExpanderColumn() == column
) )
3201 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3202 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
3203 indent
= indent
+ m_lineHeight
; // use m_lineHeight as the width of the expander
3205 if(!node
->HasChildren())
3209 wxRect
itemRect( xpos
+ indent
,
3210 GetLineStart( row
),
3212 GetLineHeight( row
) );
3214 GetOwner()->CalcScrolledPosition( itemRect
.x
, itemRect
.y
,
3215 &itemRect
.x
, &itemRect
.y
);
3220 int wxDataViewMainWindow::RecalculateCount()
3224 wxDataViewIndexListModel
*list_model
=
3225 (wxDataViewIndexListModel
*) GetOwner()->GetModel();
3227 return list_model
->GetLastIndex() + 1;
3229 return list_model
->GetLastIndex() - 1;
3234 return m_root
->GetSubTreeCount();
3238 class ItemToRowJob
: public DoJob
3241 ItemToRowJob(const wxDataViewItem
& item_
, ItemList::const_iterator iter
)
3248 // Maybe binary search will help to speed up this process
3249 virtual int operator() ( wxDataViewTreeNode
* node
)
3252 if( node
->GetItem() == item
)
3257 if( node
->GetItem() == **m_iter
)
3264 ret
+= node
->GetSubTreeCount();
3270 virtual int operator() ( void * n
)
3273 if( n
== item
.GetID() )
3278 // the row number is begin from zero
3279 int GetResult() const
3283 ItemList::const_iterator m_iter
;
3284 wxDataViewItem item
;
3289 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
3291 const wxDataViewModel
* model
= GetOwner()->GetModel();
3297 return wxPtrToUInt( item
.GetID() );
3304 // Compose the a parent-chain of the finding item
3306 wxDataViewItem
* pItem
;
3307 list
.DeleteContents( true );
3308 wxDataViewItem
it( item
);
3311 pItem
= new wxDataViewItem( it
);
3312 list
.Insert( pItem
);
3313 it
= model
->GetParent( it
);
3315 pItem
= new wxDataViewItem( );
3316 list
.Insert( pItem
);
3318 ItemToRowJob
job( item
, list
.begin() );
3319 Walker(m_root
, job
);
3320 return job
.GetResult();
3324 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
3325 wxDataViewTreeNode
* node
)
3327 if( !model
->IsContainer( item
) )
3330 wxDataViewItemArray children
;
3331 unsigned int num
= model
->GetChildren( item
, children
);
3333 unsigned int index
= 0;
3334 while( index
< num
)
3336 if( model
->IsContainer( children
[index
] ) )
3338 wxDataViewTreeNode
* n
= new wxDataViewTreeNode( node
);
3339 n
->SetItem(children
[index
]);
3340 n
->SetHasChildren( true );
3345 node
->AddLeaf( children
[index
].GetID() );
3349 node
->SetSubTreeCount( num
);
3350 wxDataViewTreeNode
* n
= node
->GetParent();
3352 n
->ChangeSubTreeCount(num
);
3356 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
3360 if (GetOwner()->GetModel()->IsVirtualListModel())
3366 m_root
= new wxDataViewTreeNode( NULL
);
3367 m_root
->SetHasChildren(true);
3369 // First we define a invalid item to fetch the top-level elements
3370 wxDataViewItem item
;
3372 BuildTreeHelper( model
, item
, m_root
);
3376 static void DestroyTreeHelper( wxDataViewTreeNode
* node
)
3378 if( node
->GetNodeNumber() != 0 )
3380 int len
= node
->GetNodeNumber();
3381 wxDataViewTreeNodes
& nodes
= node
->GetNodes();
3382 for (int i
= 0; i
< len
; i
++)
3383 DestroyTreeHelper(nodes
[i
]);
3388 void wxDataViewMainWindow::DestroyTree()
3390 if (!IsVirtualList())
3392 ::DestroyTreeHelper(m_root
);
3398 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
3400 if ( GetParent()->HandleAsNavigationKey(event
) )
3403 // no item -> nothing to do
3404 if (!HasCurrentRow())
3410 // don't use m_linesPerPage directly as it might not be computed yet
3411 const int pageSize
= GetCountPerPage();
3412 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3414 switch ( event
.GetKeyCode() )
3418 if (m_currentRow
>= 0)
3420 wxWindow
*parent
= GetParent();
3421 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3422 le
.SetItem( GetItemByRow(m_currentRow
) );
3423 le
.SetEventObject(parent
);
3424 le
.SetModel(GetOwner()->GetModel());
3426 parent
->GetEventHandler()->ProcessEvent(le
);
3431 if ( m_currentRow
> 0 )
3432 OnArrowChar( m_currentRow
- 1, event
);
3436 if ( m_currentRow
< GetRowCount() - 1 )
3437 OnArrowChar( m_currentRow
+ 1, event
);
3439 // Add the process for tree expanding/collapsing
3442 if (IsVirtualList())
3445 wxDataViewTreeNode
* node
= GetTreeNodeByRow(m_currentRow
);
3449 if (node
->HasChildren())
3451 Collapse(m_currentRow
);
3455 wxDataViewTreeNode
*parent_node
= node
->GetParent();
3459 int parent
= GetRowByItem( parent_node
->GetItem() );
3462 unsigned int row
= m_currentRow
;
3463 SelectRow( row
, false);
3464 SelectRow( parent
, true );
3465 ChangeCurrentRow( parent
);
3466 SendSelectionChangedEvent( parent_node
->GetItem() );
3474 if (!IsExpanded( m_currentRow
))
3475 Expand( m_currentRow
);
3478 unsigned int row
= m_currentRow
;
3479 SelectRow( row
, false );
3480 SelectRow( row
+ 1, true );
3481 ChangeCurrentRow( row
+ 1 );
3482 SendSelectionChangedEvent( GetItemByRow(row
+1) );
3489 OnArrowChar( GetRowCount() - 1, event
);
3494 OnArrowChar( 0, event
);
3499 int steps
= pageSize
- 1;
3500 int index
= m_currentRow
- steps
;
3504 OnArrowChar( index
, event
);
3510 int steps
= pageSize
- 1;
3511 unsigned int index
= m_currentRow
+ steps
;
3512 unsigned int count
= GetRowCount();
3513 if ( index
>= count
)
3516 OnArrowChar( index
, event
);
3525 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
3527 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3529 // let the base handle mouse wheel events.
3534 int x
= event
.GetX();
3535 int y
= event
.GetY();
3536 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
3537 wxDataViewColumn
*col
= NULL
;
3540 unsigned int cols
= GetOwner()->GetColumnCount();
3542 for (i
= 0; i
< cols
; i
++)
3544 wxDataViewColumn
*c
= GetOwner()->GetColumnAt( i
);
3546 continue; // skip it!
3548 if (x
< xpos
+ c
->GetWidth())
3553 xpos
+= c
->GetWidth();
3558 wxDataViewRenderer
*cell
= col
->GetRenderer();
3559 unsigned int current
= GetLineAt( y
);
3560 if ((current
>= GetRowCount()) || (x
> GetEndOfLastCol()))
3562 // Unselect all if below the last row ?
3566 // Test whether the mouse is hovered on the tree item button
3567 bool hoverOverExpander
= false;
3568 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
3570 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3571 if( node
!=NULL
&& node
->HasChildren() )
3573 int indent
= node
->GetIndentLevel();
3574 indent
= GetOwner()->GetIndent()*indent
;
3576 // we make the rectangle we are looking in a bit bigger than the actual
3577 // visual expander so the user can hit that little thing reliably
3578 wxRect
rect( xpos
+ indent
,
3579 GetLineStart( current
) + (GetLineHeight(current
) - m_lineHeight
)/2,
3580 m_lineHeight
, m_lineHeight
);
3581 if( rect
.Contains(x
, y
) )
3583 // So the mouse is over the expander
3584 hoverOverExpander
= true;
3585 if (m_underMouse
&& m_underMouse
!= node
)
3587 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3588 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3590 if (m_underMouse
!= node
)
3592 // wxLogMessage("Do the row: %d", current);
3593 RefreshRow(current
);
3595 m_underMouse
= node
;
3598 if (node
!=NULL
&& !node
->HasChildren())
3601 if (!hoverOverExpander
)
3603 if (m_underMouse
!= NULL
)
3605 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3606 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3607 m_underMouse
= NULL
;
3611 wxDataViewModel
*model
= GetOwner()->GetModel();
3613 #if wxUSE_DRAG_AND_DROP
3614 if (event
.Dragging())
3616 if (m_dragCount
== 0)
3618 // we have to report the raw, physical coords as we want to be
3619 // able to call HitTest(event.m_pointDrag) from the user code to
3620 // get the item being dragged
3621 m_dragStart
= event
.GetPosition();
3626 if (m_dragCount
!= 3)
3629 if (event
.LeftIsDown())
3631 m_owner
->CalcUnscrolledPosition( m_dragStart
.x
, m_dragStart
.y
,
3632 &m_dragStart
.x
, &m_dragStart
.y
);
3633 unsigned int drag_item_row
= GetLineAt( m_dragStart
.y
);
3634 wxDataViewItem item
= GetItemByRow( drag_item_row
);
3636 // Notify cell about drag
3637 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3638 event
.SetEventObject( m_owner
);
3639 event
.SetItem( item
);
3640 event
.SetModel( model
);
3641 if (!m_owner
->HandleWindowEvent( event
))
3644 if (!event
.IsAllowed())
3647 wxDataObject
*obj
= event
.GetDataObject();
3651 wxDataViewDropSource
drag( this, drag_item_row
);
3652 drag
.SetData( *obj
);
3653 /* wxDragResult res = */ drag
.DoDragDrop();
3662 #endif // wxUSE_DRAG_AND_DROP
3664 bool simulateClick
= false;
3666 if (event
.ButtonDClick())
3668 m_renameTimer
->Stop();
3669 m_lastOnSame
= false;
3672 wxDataViewItem item
= GetItemByRow(current
);
3673 bool ignore_other_columns
=
3674 ((GetOwner()->GetExpanderColumn() != col
) &&
3675 (model
->IsContainer(item
)) &&
3676 (!model
->HasContainerColumns(item
)));
3678 if (event
.LeftDClick())
3680 if(hoverOverExpander
)
3682 // a double click on the expander will be converted into a "simulated" normal click
3683 simulateClick
= true;
3685 else if ( current
== m_lineLastClicked
)
3687 if ((!ignore_other_columns
) && (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
3690 model
->GetValue( value
, item
, col
->GetModelColumn() );
3691 cell
->SetValue( value
);
3692 wxRect
cell_rect( xpos
, GetLineStart( current
),
3693 col
->GetWidth(), GetLineHeight( current
) );
3694 cell
->Activate( cell_rect
, model
, item
, col
->GetModelColumn() );
3698 wxWindow
*parent
= GetParent();
3699 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3701 le
.SetEventObject(parent
);
3702 le
.SetModel(GetOwner()->GetModel());
3704 parent
->GetEventHandler()->ProcessEvent(le
);
3710 // The first click was on another item, so don't interpret this as
3711 // a double click, but as a simple click instead
3712 simulateClick
= true;
3716 if (event
.LeftUp() && !hoverOverExpander
)
3718 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
3720 // select single line
3721 SelectAllRows( false );
3722 SelectRow( m_lineSelectSingleOnUp
, true );
3723 SendSelectionChangedEvent( GetItemByRow(m_lineSelectSingleOnUp
) );
3726 // If the user click the expander, we do not do editing even if the column
3727 // with expander are editable
3728 if (m_lastOnSame
&& !ignore_other_columns
)
3730 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
3731 (cell
->GetMode() & wxDATAVIEW_CELL_EDITABLE
) )
3733 m_renameTimer
->Start( 100, true );
3737 m_lastOnSame
= false;
3738 m_lineSelectSingleOnUp
= (unsigned int)-1;
3740 else if(!event
.LeftUp())
3742 // This is necessary, because after a DnD operation in
3743 // from and to ourself, the up event is swallowed by the
3744 // DnD code. So on next non-up event (which means here and
3745 // now) m_lineSelectSingleOnUp should be reset.
3746 m_lineSelectSingleOnUp
= (unsigned int)-1;
3749 if (event
.RightDown())
3751 m_lineBeforeLastClicked
= m_lineLastClicked
;
3752 m_lineLastClicked
= current
;
3754 // If the item is already selected, do not update the selection.
3755 // Multi-selections should not be cleared if a selected item is clicked.
3756 if (!IsRowSelected(current
))
3758 SelectAllRows(false);
3759 ChangeCurrentRow(current
);
3760 SelectRow(m_currentRow
,true);
3761 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3765 model
->GetValue( value
, item
, col
->GetModelColumn() );
3766 wxWindow
*parent
= GetParent();
3767 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
3769 le
.SetEventObject(parent
);
3770 le
.SetModel(GetOwner()->GetModel());
3772 parent
->GetEventHandler()->ProcessEvent(le
);
3774 else if (event
.MiddleDown())
3778 if((event
.LeftDown() || simulateClick
) && hoverOverExpander
)
3780 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3782 // hoverOverExpander being true tells us that our node must be
3783 // valid and have children.
3784 // So we don't need any extra checks.
3785 if( node
->IsOpen() )
3790 else if ((event
.LeftDown() || simulateClick
) && !hoverOverExpander
)
3794 m_lineBeforeLastClicked
= m_lineLastClicked
;
3795 m_lineLastClicked
= current
;
3797 unsigned int oldCurrentRow
= m_currentRow
;
3798 bool oldWasSelected
= IsRowSelected(m_currentRow
);
3800 bool cmdModifierDown
= event
.CmdDown();
3801 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3803 if ( IsSingleSel() || !IsRowSelected(current
) )
3805 SelectAllRows( false );
3806 ChangeCurrentRow(current
);
3807 SelectRow(m_currentRow
,true);
3808 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3810 else // multi sel & current is highlighted & no mod keys
3812 m_lineSelectSingleOnUp
= current
;
3813 ChangeCurrentRow(current
); // change focus
3816 else // multi sel & either ctrl or shift is down
3818 if (cmdModifierDown
)
3820 ChangeCurrentRow(current
);
3821 ReverseRowSelection(m_currentRow
);
3822 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3824 else if (event
.ShiftDown())
3826 ChangeCurrentRow(current
);
3828 unsigned int lineFrom
= oldCurrentRow
,
3831 if ( lineTo
< lineFrom
)
3834 lineFrom
= m_currentRow
;
3837 SelectRows(lineFrom
, lineTo
, true);
3838 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3840 else // !ctrl, !shift
3842 // test in the enclosing if should make it impossible
3843 wxFAIL_MSG( _T("how did we get here?") );
3847 if (m_currentRow
!= oldCurrentRow
)
3848 RefreshRow( oldCurrentRow
);
3850 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
3852 // Update selection here...
3855 m_lastOnSame
= !simulateClick
&& ((col
== oldCurrentCol
) &&
3856 (current
== oldCurrentRow
)) && oldWasSelected
;
3858 // Call LeftClick after everything else as under GTK+
3859 if (cell
->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE
)
3861 // notify cell about right click
3863 model
->GetValue( value
, item
, col
->GetModelColumn() );
3864 cell
->SetValue( value
);
3865 wxRect
cell_rect( xpos
, GetLineStart( current
),
3866 col
->GetWidth(), GetLineHeight( current
) );
3867 /* ignore ret */ cell
->LeftClick( event
.GetPosition(), cell_rect
,
3868 model
, item
, col
->GetModelColumn());
3873 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
3877 if (HasCurrentRow())
3883 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
3887 if (HasCurrentRow())
3893 wxDataViewItem
wxDataViewMainWindow::GetSelection() const
3895 if( m_selection
.GetCount() != 1 )
3896 return wxDataViewItem();
3898 return GetItemByRow( m_selection
.Item(0));
3901 //-----------------------------------------------------------------------------
3903 //-----------------------------------------------------------------------------
3905 WX_DEFINE_LIST(wxDataViewColumnList
)
3907 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3908 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
3909 EVT_SIZE(wxDataViewCtrl::OnSize
)
3912 wxDataViewCtrl::~wxDataViewCtrl()
3915 GetModel()->RemoveNotifier( m_notifier
);
3920 void wxDataViewCtrl::Init()
3922 m_cols
.DeleteContents(true);
3925 // No sorting column at start
3926 m_sortingColumnIdx
= wxNOT_FOUND
;
3928 m_headerArea
= NULL
;
3931 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3932 const wxPoint
& pos
, const wxSize
& size
,
3933 long style
, const wxValidator
& validator
)
3935 // if ( (style & wxBORDER_MASK) == 0)
3936 // style |= wxBORDER_SUNKEN;
3940 if (!wxControl::Create( parent
, id
, pos
, size
,
3941 style
| wxScrolledWindowStyle
, validator
))
3944 SetInitialSize(size
);
3947 MacSetClipChildren( true );
3950 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
3952 if (HasFlag(wxDV_NO_HEADER
))
3953 m_headerArea
= NULL
;
3955 m_headerArea
= new wxDataViewHeaderWindow(this);
3957 SetTargetWindow( m_clientArea
);
3959 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
3961 sizer
->Add( m_headerArea
, 0, wxGROW
);
3962 sizer
->Add( m_clientArea
, 1, wxGROW
);
3968 wxBorder
wxDataViewCtrl::GetDefaultBorder() const
3970 return wxBORDER_THEME
;
3974 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
3978 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
3981 // we need to process arrows ourselves for scrolling
3982 if ( nMsg
== WM_GETDLGCODE
)
3984 rc
|= DLGC_WANTARROWS
;
3992 wxSize
wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
3994 wxSize newsize
= size
;
3995 if (!HasFlag(wxDV_NO_HEADER
) && (m_headerArea
))
3996 newsize
.y
-= m_headerArea
->GetSize().y
;
4001 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
4003 // We need to override OnSize so that our scrolled
4004 // window a) does call Layout() to use sizers for
4005 // positioning the controls but b) does not query
4006 // the sizer for their size and use that for setting
4007 // the scrollable area as set that ourselves by
4008 // calling SetScrollbar() further down.
4015 void wxDataViewCtrl::SetFocus()
4018 m_clientArea
->SetFocus();
4021 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4023 if (!wxDataViewCtrlBase::AssociateModel( model
))
4026 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
4028 model
->AddNotifier( m_notifier
);
4030 m_clientArea
->DestroyTree();
4032 m_clientArea
->BuildTree(model
);
4034 m_clientArea
->UpdateDisplay();
4039 #if wxUSE_DRAG_AND_DROP
4041 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4043 return m_clientArea
->EnableDragSource( format
);
4046 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4048 return m_clientArea
->EnableDropTarget( format
);
4051 #endif // wxUSE_DRAG_AND_DROP
4053 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4055 if (!wxDataViewCtrlBase::AppendColumn(col
))
4058 m_cols
.Append( col
);
4059 OnColumnsCountChanged();
4063 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4065 if (!wxDataViewCtrlBase::PrependColumn(col
))
4068 m_cols
.Insert( col
);
4069 OnColumnsCountChanged();
4073 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4075 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4078 m_cols
.Insert( pos
, col
);
4079 OnColumnsCountChanged();
4083 void wxDataViewCtrl::OnColumnChange(unsigned int idx
)
4086 m_headerArea
->UpdateColumn(idx
);
4088 m_clientArea
->UpdateDisplay();
4091 void wxDataViewCtrl::OnColumnsCountChanged()
4094 m_headerArea
->SetColumnCount(GetColumnCount());
4096 m_clientArea
->UpdateDisplay();
4099 void wxDataViewCtrl::DoSetExpanderColumn()
4101 m_clientArea
->UpdateDisplay();
4104 void wxDataViewCtrl::DoSetIndent()
4106 m_clientArea
->UpdateDisplay();
4109 unsigned int wxDataViewCtrl::GetColumnCount() const
4111 return m_cols
.GetCount();
4114 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int idx
) const
4119 wxDataViewColumn
*wxDataViewCtrl::GetColumnAt(unsigned int pos
) const
4121 // columns can't be reordered if there is no header window which allows
4123 const unsigned idx
= m_headerArea
? m_headerArea
->GetColumnsOrder()[pos
]
4126 return GetColumn(idx
);
4129 int wxDataViewCtrl::GetColumnIndex(const wxDataViewColumn
*column
) const
4131 const unsigned count
= m_cols
.size();
4132 for ( unsigned n
= 0; n
< count
; n
++ )
4134 if ( m_cols
[n
] == column
)
4141 void wxDataViewCtrl::ColumnMoved(wxDataViewColumn
* WXUNUSED(col
),
4142 unsigned int WXUNUSED(new_pos
))
4144 // do _not_ reorder m_cols elements here, they should always be in the
4145 // order in which columns were added, we only display the columns in
4147 m_clientArea
->UpdateDisplay();
4150 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4152 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
4157 OnColumnsCountChanged();
4162 bool wxDataViewCtrl::ClearColumns()
4165 OnColumnsCountChanged();
4169 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4173 unsigned int len
= GetColumnCount();
4174 for ( unsigned int i
= 0; i
< len
; i
++ )
4176 wxDataViewColumn
* col
= GetColumnAt(i
);
4177 if (col
->IsHidden())
4179 ret
+= col
->GetWidth();
4182 CalcScrolledPosition( ret
, dummy
, &ret
, &dummy
);
4189 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4191 return m_sortingColumnIdx
== wxNOT_FOUND
? NULL
4192 : GetColumn(m_sortingColumnIdx
);
4195 // Selection code with wxDataViewItem as parameters
4196 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4198 return m_clientArea
->GetSelection();
4201 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4204 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4205 int len
= selection
.GetCount();
4206 for( int i
= 0; i
< len
; i
++)
4208 unsigned int row
= selection
[i
];
4209 sel
.Add( m_clientArea
->GetItemByRow( row
) );
4214 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4216 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4218 wxDataViewItem last_parent
;
4220 int len
= sel
.GetCount();
4221 for( int i
= 0; i
< len
; i
++ )
4223 wxDataViewItem item
= sel
[i
];
4224 wxDataViewItem parent
= GetModel()->GetParent( item
);
4227 if (parent
!= last_parent
)
4228 ExpandAncestors(item
);
4231 last_parent
= parent
;
4232 int row
= m_clientArea
->GetRowByItem( item
);
4234 selection
.Add( static_cast<unsigned int>(row
) );
4237 m_clientArea
->SetSelections( selection
);
4240 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4242 ExpandAncestors( item
);
4244 int row
= m_clientArea
->GetRowByItem( item
);
4247 // Unselect all rows before select another in the single select mode
4248 if (m_clientArea
->IsSingleSel())
4249 m_clientArea
->SelectAllRows(false);
4250 m_clientArea
->SelectRow(row
, true);
4254 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4256 int row
= m_clientArea
->GetRowByItem( item
);
4258 m_clientArea
->SelectRow(row
, false);
4261 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4263 int row
= m_clientArea
->GetRowByItem( item
);
4266 return m_clientArea
->IsRowSelected(row
);
4271 // Selection code with row number as parameter
4272 int wxDataViewCtrl::GetSelections( wxArrayInt
& sel
) const
4275 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4276 int len
= selection
.GetCount();
4277 for( int i
= 0; i
< len
; i
++)
4279 unsigned int row
= selection
[i
];
4285 void wxDataViewCtrl::SetSelections( const wxArrayInt
& sel
)
4287 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4288 int len
= sel
.GetCount();
4289 for( int i
= 0; i
< len
; i
++ )
4293 selection
.Add( static_cast<unsigned int>(row
) );
4295 m_clientArea
->SetSelections( selection
);
4298 void wxDataViewCtrl::Select( int row
)
4302 if (m_clientArea
->IsSingleSel())
4303 m_clientArea
->SelectAllRows(false);
4304 m_clientArea
->SelectRow( row
, true );
4308 void wxDataViewCtrl::Unselect( int row
)
4311 m_clientArea
->SelectRow(row
, false);
4314 bool wxDataViewCtrl::IsSelected( int row
) const
4317 return m_clientArea
->IsRowSelected(row
);
4321 void wxDataViewCtrl::SelectRange( int from
, int to
)
4324 for( int i
= from
; i
< to
; i
++ )
4326 m_clientArea
->Select(sel
);
4329 void wxDataViewCtrl::UnselectRange( int from
, int to
)
4331 wxDataViewSelection sel
= m_clientArea
->GetSelections();
4332 for( int i
= from
; i
< to
; i
++ )
4333 if( sel
.Index( i
) != wxNOT_FOUND
)
4335 m_clientArea
->SetSelections(sel
);
4338 void wxDataViewCtrl::SelectAll()
4340 m_clientArea
->SelectAllRows(true);
4343 void wxDataViewCtrl::UnselectAll()
4345 m_clientArea
->SelectAllRows(false);
4348 void wxDataViewCtrl::EnsureVisible( int row
, int column
)
4352 if( row
> (int) m_clientArea
->GetRowCount() )
4353 row
= m_clientArea
->GetRowCount();
4355 int first
= m_clientArea
->GetFirstVisibleRow();
4356 int last
= m_clientArea
->GetLastVisibleRow();
4358 m_clientArea
->ScrollTo( row
, column
);
4359 else if( row
> last
)
4360 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
4362 m_clientArea
->ScrollTo( first
, column
);
4365 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
4367 ExpandAncestors( item
);
4369 m_clientArea
->RecalculateDisplay();
4371 int row
= m_clientArea
->GetRowByItem(item
);
4374 if( column
== NULL
)
4375 EnsureVisible(row
, -1);
4377 EnsureVisible( row
, GetColumnIndex(column
) );
4382 void wxDataViewCtrl::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
4383 wxDataViewColumn
* &column
) const
4385 m_clientArea
->HitTest(point
, item
, column
);
4388 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
& item
,
4389 const wxDataViewColumn
* column
) const
4391 return m_clientArea
->GetItemRect(item
, column
);
4394 wxDataViewItem
wxDataViewCtrl::GetItemByRow( unsigned int row
) const
4396 return m_clientArea
->GetItemByRow( row
);
4399 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem
& item
) const
4401 return m_clientArea
->GetRowByItem( item
);
4404 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4406 int row
= m_clientArea
->GetRowByItem( item
);
4408 m_clientArea
->Expand(row
);
4411 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4413 int row
= m_clientArea
->GetRowByItem( item
);
4414 wxPrintf( "row %d\n", row
);
4416 m_clientArea
->Collapse(row
);
4419 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4421 int row
= m_clientArea
->GetRowByItem( item
);
4423 return m_clientArea
->IsExpanded(row
);
4427 void wxDataViewCtrl::StartEditor( const wxDataViewItem
& item
, unsigned int column
)
4429 wxDataViewColumn
* col
= GetColumn( column
);
4433 wxRect itemRect
= GetItemRect(item
, col
);
4434 wxDataViewRenderer
* renderer
= col
->GetRenderer();
4435 renderer
->StartEditing(item
, itemRect
);
4439 // !wxUSE_GENERICDATAVIEWCTRL
4442 // wxUSE_DATAVIEWCTRL