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
)
615 m_ellipsizeMode
= wxELLIPSIZE_MIDDLE
;
618 wxDataViewRenderer::~wxDataViewRenderer()
625 wxDataViewRenderer::RenderWithAttr(wxDC
& dc
,
626 const wxRect
& cell_rect
,
628 const wxDataViewItemAttr
*WXUNUSED(attr
),
631 // adjust the rectangle ourselves to account for the alignment
633 wxRect item_rect
= cell_rect
;
636 const wxSize size
= GetSize();
638 // take alignment into account only if there is enough space, otherwise
639 // show as much contents as possible
641 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
642 // return hard-coded size which can be more than they need and if we
643 // trusted their GetSize() we'd draw the text out of cell bounds
646 if ( size
.x
< cell_rect
.width
)
648 if (align
& wxALIGN_CENTER_HORIZONTAL
)
649 item_rect
.x
+= (cell_rect
.width
- size
.x
)/2;
650 else if (align
& wxALIGN_RIGHT
)
651 item_rect
.x
+= cell_rect
.width
- size
.x
;
652 // else: wxALIGN_LEFT is the default
654 item_rect
.width
= size
.x
;
657 if ( size
.y
< cell_rect
.height
)
659 if (align
& wxALIGN_CENTER_VERTICAL
)
660 item_rect
.y
+= (cell_rect
.height
- size
.y
)/2;
661 else if (align
& wxALIGN_BOTTOM
)
662 item_rect
.y
+= cell_rect
.height
- size
.y
;
663 // else: wxALIGN_TOP is the default
665 item_rect
.height
= size
.y
;
669 return Render(item_rect
, &dc
, state
);
672 wxDC
*wxDataViewRenderer::GetDC()
676 if (GetOwner() == NULL
)
678 if (GetOwner()->GetOwner() == NULL
)
680 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
686 void wxDataViewRenderer::SetAlignment( int align
)
691 int wxDataViewRenderer::GetAlignment() const
696 int wxDataViewRenderer::CalculateAlignment() const
698 if (m_align
== wxDVR_DEFAULT_ALIGNMENT
)
700 if (GetOwner() == NULL
)
701 return wxALIGN_LEFT
| wxALIGN_CENTRE_VERTICAL
;
703 return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
709 // ---------------------------------------------------------
710 // wxDataViewCustomRenderer
711 // ---------------------------------------------------------
713 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
715 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
716 wxDataViewCellMode mode
, int align
) :
717 wxDataViewRenderer( varianttype
, mode
, align
)
722 wxDataViewCustomRenderer::RenderText(wxDC
& dc
,
725 const wxString
& text
,
726 const wxDataViewItemAttr
*attr
,
731 if ( attr
&& attr
->HasColour() )
732 col
= attr
->GetColour();
733 else if ( state
& wxDATAVIEW_CELL_SELECTED
)
734 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
735 else // use default foreground
736 col
= GetOwner()->GetOwner()->GetForegroundColour();
738 wxDCTextColourChanger
changeFg(dc
, col
);
740 wxDCFontChanger
changeFont(dc
);
741 if ( attr
&& attr
->HasFont() )
743 wxFont
font(dc
.GetFont());
744 if ( attr
->GetBold() )
746 if ( attr
->GetItalic() )
749 changeFont
.Set(font
);
752 wxRect rectText
= rect
;
753 rectText
.x
+= xoffset
;
754 rectText
.width
-= xoffset
;
756 // check if we want to ellipsize the text if it doesn't fit
757 wxString ellipsizedText
;
758 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
760 ellipsizedText
= wxControl::Ellipsize
766 wxELLIPSIZE_FLAGS_NONE
770 dc
.DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
774 // ---------------------------------------------------------
775 // wxDataViewTextRenderer
776 // ---------------------------------------------------------
778 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
780 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
781 wxDataViewCellMode mode
, int align
) :
782 wxDataViewCustomRenderer( varianttype
, mode
, align
)
786 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
788 m_text
= value
.GetString();
793 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
798 bool wxDataViewTextRenderer::HasEditorCtrl() const
803 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
804 wxRect labelRect
, const wxVariant
&value
)
806 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, value
,
807 wxPoint(labelRect
.x
,labelRect
.y
),
808 wxSize(labelRect
.width
,labelRect
.height
) );
810 // select the text in the control an place the cursor at the end
811 ctrl
->SetInsertionPointEnd();
817 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
819 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
820 value
= text
->GetValue();
825 wxDataViewTextRenderer::RenderWithAttr(wxDC
& dc
,
828 const wxDataViewItemAttr
*attr
,
831 RenderText(dc
, rect
, align
, m_text
, attr
, state
);
835 wxSize
wxDataViewTextRenderer::GetSize() const
837 const wxDataViewCtrl
*view
= GetView();
839 return view
->wxWindowBase::GetTextExtent( m_text
);
840 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
843 // ---------------------------------------------------------
844 // wxDataViewBitmapRenderer
845 // ---------------------------------------------------------
847 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
849 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
850 wxDataViewCellMode mode
, int align
) :
851 wxDataViewCustomRenderer( varianttype
, mode
, align
)
855 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
857 if (value
.GetType() == wxT("wxBitmap"))
859 if (value
.GetType() == wxT("wxIcon"))
865 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
870 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
873 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
874 else if (m_icon
.Ok())
875 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
880 wxSize
wxDataViewBitmapRenderer::GetSize() const
883 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
884 else if (m_icon
.Ok())
885 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
887 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
890 // ---------------------------------------------------------
891 // wxDataViewToggleRenderer
892 // ---------------------------------------------------------
894 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
896 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
897 wxDataViewCellMode mode
, int align
) :
898 wxDataViewCustomRenderer( varianttype
, mode
, align
)
903 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
905 m_toggle
= value
.GetBool();
910 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
915 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
919 flags
|= wxCONTROL_CHECKED
;
920 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
921 flags
|= wxCONTROL_DISABLED
;
923 wxRendererNative::Get().DrawCheckBox(
924 GetOwner()->GetOwner(),
932 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
933 wxDataViewModel
*model
,
934 const wxDataViewItem
& item
, unsigned int col
)
936 bool value
= !m_toggle
;
937 wxVariant variant
= value
;
938 model
->SetValue( variant
, item
, col
);
939 model
->ValueChanged( item
, col
);
943 wxSize
wxDataViewToggleRenderer::GetSize() const
945 // the window parameter is not used by GetCheckBoxSize() so it's
947 return wxRendererNative::Get().GetCheckBoxSize(NULL
);
950 // ---------------------------------------------------------
951 // wxDataViewProgressRenderer
952 // ---------------------------------------------------------
954 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
956 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
957 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
958 wxDataViewCustomRenderer( varianttype
, mode
, align
)
964 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
966 m_value
= (long) value
;
968 if (m_value
< 0) m_value
= 0;
969 if (m_value
> 100) m_value
= 100;
974 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
976 value
= (long) m_value
;
980 bool wxDataViewProgressRenderer::RenderWithAttr(wxDC
& dc
,
983 const wxDataViewItemAttr
*attr
,
986 // deflat the rect to leave a small border between bars in adjacent rows
987 wxRect bar
= rect
.Deflate(0, 1);
989 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
990 dc
.SetPen( *wxBLACK_PEN
);
991 dc
.DrawRectangle( bar
);
993 bar
.width
= (int)(bar
.width
* m_value
/ 100.);
994 dc
.SetPen( *wxTRANSPARENT_PEN
);
995 dc
.SetBrush( attr
&& attr
->HasColour() ? wxBrush(attr
->GetColour())
997 dc
.DrawRectangle( bar
);
1002 wxSize
wxDataViewProgressRenderer::GetSize() const
1004 return wxSize(40,12);
1007 // ---------------------------------------------------------
1008 // wxDataViewDateRenderer
1009 // ---------------------------------------------------------
1011 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
1013 #if wxUSE_DATE_RENDERER_POPUP
1015 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1018 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1019 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
) :
1020 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
),
1025 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
1026 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1027 sizer
->Add( m_cal
, 1, wxGROW
);
1032 void OnCalendar( wxCalendarEvent
&event
);
1034 wxCalendarCtrl
*m_cal
;
1035 wxDataViewModel
*m_model
;
1037 const wxDataViewItem
& m_item
;
1040 virtual void OnDismiss()
1045 DECLARE_EVENT_TABLE()
1048 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1049 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
1052 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1054 wxDateTime date
= event
.GetDate();
1055 wxVariant value
= date
;
1056 m_model
->SetValue( value
, m_item
, m_col
);
1057 m_model
->ValueChanged( m_item
, m_col
);
1061 #endif // wxUSE_DATE_RENDERER_POPUP
1063 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1065 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1066 wxDataViewCellMode mode
, int align
) :
1067 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1071 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1073 m_date
= value
.GetDateTime();
1078 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1084 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1086 wxString tmp
= m_date
.FormatDate();
1087 RenderText( tmp
, 0, cell
, dc
, state
);
1091 wxSize
wxDataViewDateRenderer::GetSize() const
1093 const wxDataViewCtrl
* view
= GetView();
1094 wxString tmp
= m_date
.FormatDate();
1096 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1097 return wxSize(x
,y
+d
);
1100 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
1101 const wxDataViewItem
& item
, unsigned int col
)
1104 model
->GetValue( variant
, item
, col
);
1105 wxDateTime value
= variant
.GetDateTime();
1107 #if wxUSE_DATE_RENDERER_POPUP
1108 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1109 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1110 wxPoint pos
= wxGetMousePosition();
1113 popup
->Popup( popup
->m_cal
);
1114 #else // !wxUSE_DATE_RENDERER_POPUP
1115 wxMessageBox(value
.Format());
1116 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
1120 // ---------------------------------------------------------
1121 // wxDataViewIconTextRenderer
1122 // ---------------------------------------------------------
1124 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1126 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1127 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1128 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1131 SetAlignment(align
);
1134 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1140 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1146 wxDataViewIconTextRenderer::RenderWithAttr(wxDC
& dc
,
1149 const wxDataViewItemAttr
*attr
,
1154 const wxIcon
& icon
= m_value
.GetIcon();
1157 dc
.DrawIcon(icon
, rect
.x
, rect
.y
+ (rect
.height
- icon
.GetHeight())/2);
1158 xoffset
= icon
.GetWidth()+4;
1161 RenderText(dc
, rect
, align
, m_value
.GetText(), attr
, state
, xoffset
);
1166 wxSize
wxDataViewIconTextRenderer::GetSize() const
1168 const wxDataViewCtrl
*view
= GetView();
1169 if (!m_value
.GetText().empty())
1172 view
->GetTextExtent( m_value
.GetText(), &x
, &y
);
1174 if (m_value
.GetIcon().IsOk())
1175 x
+= m_value
.GetIcon().GetWidth() + 4;
1176 return wxSize( x
, y
);
1178 return wxSize(80,20);
1181 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1183 wxDataViewIconText iconText
;
1186 wxString text
= iconText
.GetText();
1188 // adjust the label rect to take the width of the icon into account
1189 if (iconText
.GetIcon().IsOk())
1191 int w
= iconText
.GetIcon().GetWidth() + 4;
1193 labelRect
.width
-= w
;
1196 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, text
,
1197 wxPoint(labelRect
.x
,labelRect
.y
),
1198 wxSize(labelRect
.width
,labelRect
.height
) );
1200 // select the text in the control an place the cursor at the end
1201 ctrl
->SetInsertionPointEnd();
1207 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
& value
)
1209 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
1211 wxDataViewIconText
iconText(text
->GetValue(), m_value
.GetIcon());
1216 //-----------------------------------------------------------------------------
1217 // wxDataViewDropTarget
1218 //-----------------------------------------------------------------------------
1220 #if wxUSE_DRAG_AND_DROP
1222 class wxBitmapCanvas
: public wxWindow
1225 wxBitmapCanvas( wxWindow
*parent
, const wxBitmap
&bitmap
, const wxSize
&size
) :
1226 wxWindow( parent
, wxID_ANY
, wxPoint(0,0), size
)
1229 Connect( wxEVT_PAINT
, wxPaintEventHandler(wxBitmapCanvas::OnPaint
) );
1232 void OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1235 dc
.DrawBitmap( m_bitmap
, 0, 0);
1241 class wxDataViewDropSource
: public wxDropSource
1244 wxDataViewDropSource( wxDataViewMainWindow
*win
, unsigned int row
) :
1252 ~wxDataViewDropSource()
1257 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
) )
1259 wxPoint pos
= wxGetMousePosition();
1263 int liney
= m_win
->GetLineStart( m_row
);
1265 m_win
->GetOwner()->CalcUnscrolledPosition( 0, liney
, NULL
, &liney
);
1266 m_win
->ClientToScreen( &linex
, &liney
);
1267 m_dist_x
= pos
.x
- linex
;
1268 m_dist_y
= pos
.y
- liney
;
1271 wxBitmap ib
= m_win
->CreateItemBitmap( m_row
, indent
);
1273 m_hint
= new wxFrame( m_win
->GetParent(), wxID_ANY
, wxEmptyString
,
1274 wxPoint(pos
.x
- m_dist_x
, pos
.y
+ 5 ),
1276 wxFRAME_TOOL_WINDOW
|
1277 wxFRAME_FLOAT_ON_PARENT
|
1278 wxFRAME_NO_TASKBAR
|
1280 new wxBitmapCanvas( m_hint
, ib
, ib
.GetSize() );
1285 m_hint
->Move( pos
.x
- m_dist_x
, pos
.y
+ 5 );
1286 m_hint
->SetTransparent( 128 );
1292 wxDataViewMainWindow
*m_win
;
1295 int m_dist_x
,m_dist_y
;
1299 class wxDataViewDropTarget
: public wxDropTarget
1302 wxDataViewDropTarget( wxDataObject
*obj
, wxDataViewMainWindow
*win
) :
1308 virtual wxDragResult
OnDragOver( wxCoord x
, wxCoord y
, wxDragResult def
)
1310 wxDataFormat format
= GetMatchingPair();
1311 if (format
== wxDF_INVALID
)
1313 return m_win
->OnDragOver( format
, x
, y
, def
);
1316 virtual bool OnDrop( wxCoord x
, wxCoord y
)
1318 wxDataFormat format
= GetMatchingPair();
1319 if (format
== wxDF_INVALID
)
1321 return m_win
->OnDrop( format
, x
, y
);
1324 virtual wxDragResult
OnData( wxCoord x
, wxCoord y
, wxDragResult def
)
1326 wxDataFormat format
= GetMatchingPair();
1327 if (format
== wxDF_INVALID
)
1331 return m_win
->OnData( format
, x
, y
, def
);
1334 virtual void OnLeave()
1335 { m_win
->OnLeave(); }
1337 wxDataViewMainWindow
*m_win
;
1340 #endif // wxUSE_DRAG_AND_DROP
1342 //-----------------------------------------------------------------------------
1343 // wxDataViewRenameTimer
1344 //-----------------------------------------------------------------------------
1346 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1351 void wxDataViewRenameTimer::Notify()
1353 m_owner
->OnRenameTimer();
1356 //-----------------------------------------------------------------------------
1357 // wxDataViewMainWindow
1358 //-----------------------------------------------------------------------------
1360 // The tree building helper, declared firstly
1361 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
1362 wxDataViewTreeNode
* node
);
1364 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1366 if (row1
> row2
) return 1;
1367 if (row1
== row2
) return 0;
1371 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1373 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1374 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1375 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1376 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1377 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1378 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1381 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1382 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1383 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
1384 m_selection( wxDataViewSelectionCmp
)
1389 m_lastOnSame
= false;
1390 m_renameTimer
= new wxDataViewRenameTimer( this );
1392 // TODO: user better initial values/nothing selected
1393 m_currentCol
= NULL
;
1396 m_lineHeight
= wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
1398 #if wxUSE_DRAG_AND_DROP
1400 m_dragStart
= wxPoint(0,0);
1402 m_dragEnabled
= false;
1403 m_dropEnabled
= false;
1405 m_dropHintLine
= (unsigned int) -1;
1406 #endif // wxUSE_DRAG_AND_DROP
1408 m_lineLastClicked
= (unsigned int) -1;
1409 m_lineBeforeLastClicked
= (unsigned int) -1;
1410 m_lineSelectSingleOnUp
= (unsigned int) -1;
1414 SetBackgroundColour( *wxWHITE
);
1416 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1418 m_penRule
= wxPen(GetRuleColour());
1420 // compose a pen whichcan draw black lines
1421 // TODO: maybe there is something system colour to use
1422 m_penExpander
= wxPen(wxColour(0,0,0));
1424 m_root
= new wxDataViewTreeNode( NULL
);
1425 m_root
->SetHasChildren(true);
1427 // Make m_count = -1 will cause the class recaculate the real displaying number of rows.
1429 m_underMouse
= NULL
;
1433 wxDataViewMainWindow::~wxDataViewMainWindow()
1436 delete m_renameTimer
;
1440 #if wxUSE_DRAG_AND_DROP
1441 bool wxDataViewMainWindow::EnableDragSource( const wxDataFormat
&format
)
1443 m_dragFormat
= format
;
1444 m_dragEnabled
= format
!= wxDF_INVALID
;
1449 bool wxDataViewMainWindow::EnableDropTarget( const wxDataFormat
&format
)
1451 m_dropFormat
= format
;
1452 m_dropEnabled
= format
!= wxDF_INVALID
;
1455 SetDropTarget( new wxDataViewDropTarget( new wxCustomDataObject( format
), this ) );
1460 void wxDataViewMainWindow::RemoveDropHint()
1465 RefreshRow( m_dropHintLine
);
1466 m_dropHintLine
= (unsigned int) -1;
1470 wxDragResult
wxDataViewMainWindow::OnDragOver( wxDataFormat format
, wxCoord x
,
1471 wxCoord y
, wxDragResult def
)
1475 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1476 unsigned int row
= GetLineAt( yy
);
1478 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1484 wxDataViewItem item
= GetItemByRow( row
);
1486 wxDataViewModel
*model
= GetOwner()->GetModel();
1488 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1489 event
.SetEventObject( m_owner
);
1490 event
.SetItem( item
);
1491 event
.SetModel( model
);
1492 event
.SetDataFormat( format
);
1493 if (!m_owner
->HandleWindowEvent( event
))
1499 if (!event
.IsAllowed())
1506 if (m_dropHint
&& (row
!= m_dropHintLine
))
1507 RefreshRow( m_dropHintLine
);
1509 m_dropHintLine
= row
;
1515 bool wxDataViewMainWindow::OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
)
1521 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1522 unsigned int row
= GetLineAt( yy
);
1524 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1527 wxDataViewItem item
= GetItemByRow( row
);
1529 wxDataViewModel
*model
= GetOwner()->GetModel();
1531 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1532 event
.SetEventObject( m_owner
);
1533 event
.SetItem( item
);
1534 event
.SetModel( model
);
1535 event
.SetDataFormat( format
);
1536 if (!m_owner
->HandleWindowEvent( event
))
1539 if (!event
.IsAllowed())
1545 wxDragResult
wxDataViewMainWindow::OnData( wxDataFormat format
, wxCoord x
, wxCoord y
,
1550 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1551 unsigned int row
= GetLineAt( yy
);
1553 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1556 wxDataViewItem item
= GetItemByRow( row
);
1558 wxDataViewModel
*model
= GetOwner()->GetModel();
1560 wxCustomDataObject
*obj
= (wxCustomDataObject
*) GetDropTarget()->GetDataObject();
1562 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
1563 event
.SetEventObject( m_owner
);
1564 event
.SetItem( item
);
1565 event
.SetModel( model
);
1566 event
.SetDataFormat( format
);
1567 event
.SetDataSize( obj
->GetSize() );
1568 event
.SetDataBuffer( obj
->GetData() );
1569 if (!m_owner
->HandleWindowEvent( event
))
1572 if (!event
.IsAllowed())
1578 void wxDataViewMainWindow::OnLeave()
1583 wxBitmap
wxDataViewMainWindow::CreateItemBitmap( unsigned int row
, int &indent
)
1585 int height
= GetLineHeight( row
);
1587 unsigned int cols
= GetOwner()->GetColumnCount();
1589 for (col
= 0; col
< cols
; col
++)
1591 wxDataViewColumn
*column
= GetOwner()->GetColumnAt(col
);
1592 if (column
->IsHidden())
1593 continue; // skip it!
1594 width
+= column
->GetWidth();
1598 if (!IsVirtualList())
1600 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
1601 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
1602 indent
= indent
+ m_lineHeight
;
1603 // try to use the m_lineHeight as the expander space
1605 if(!node
->HasChildren())
1610 wxBitmap
bitmap( width
, height
);
1611 wxMemoryDC
dc( bitmap
);
1612 dc
.SetFont( GetFont() );
1613 dc
.SetPen( *wxBLACK_PEN
);
1614 dc
.SetBrush( *wxWHITE_BRUSH
);
1615 dc
.DrawRectangle( 0,0,width
,height
);
1617 wxDataViewModel
*model
= m_owner
->GetModel();
1619 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1622 // TODO-RTL: last column for RTL support
1623 expander
= GetOwner()->GetColumnAt( 0 );
1624 GetOwner()->SetExpanderColumn(expander
);
1629 for (col
= 0; col
< cols
; col
++)
1631 wxDataViewColumn
*column
= GetOwner()->GetColumnAt( col
);
1632 wxDataViewRenderer
*cell
= column
->GetRenderer();
1634 if (column
->IsHidden())
1635 continue; // skip it!
1637 width
= column
->GetWidth();
1639 if (column
== expander
)
1643 wxDataViewItem item
= GetItemByRow( row
);
1644 model
->GetValue( value
, item
, column
->GetModelColumn());
1645 cell
->SetValue( value
);
1647 wxRect
item_rect(x
, 0, width
, height
);
1648 item_rect
.Deflate(PADDING_RIGHTLEFT
, 0);
1650 // dc.SetClippingRegion( item_rect );
1651 wxDataViewItemAttr attr
;
1653 hasAttr
= model
->GetAttr(item
, column
->GetModelColumn(), attr
);
1654 cell
->RenderWithAttr(dc
, item_rect
, cell
->CalculateAlignment(),
1655 hasAttr
? &attr
: NULL
, 0);
1656 // dc.DestroyClippingRegion();
1664 #endif // wxUSE_DRAG_AND_DROP
1667 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1669 wxDataViewModel
*model
= GetOwner()->GetModel();
1670 wxAutoBufferedPaintDC
dc( this );
1673 dc
.SetBrush(GetOwner()->GetBackgroundColour());
1674 dc
.SetPen( *wxTRANSPARENT_PEN
);
1675 dc
.DrawRectangle(GetClientSize());
1679 GetOwner()->PrepareDC( dc
);
1680 dc
.SetFont( GetFont() );
1682 wxRect update
= GetUpdateRegion().GetBox();
1683 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1685 // compute which items needs to be redrawn
1686 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
1687 unsigned int item_count
=
1688 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
1689 (int)(GetRowCount( ) - item_start
));
1690 unsigned int item_last
= item_start
+ item_count
;
1691 // Get the parent of DataViewCtrl
1692 wxWindow
*parent
= GetParent()->GetParent();
1693 wxDataViewEvent
cache_event(wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, parent
->GetId());
1694 cache_event
.SetEventObject(GetParent());
1695 cache_event
.SetCache(item_start
, item_last
- 1);
1696 parent
->ProcessWindowEvent(cache_event
);
1698 // compute which columns needs to be redrawn
1699 unsigned int cols
= GetOwner()->GetColumnCount();
1700 unsigned int col_start
= 0;
1701 unsigned int x_start
;
1702 for (x_start
= 0; col_start
< cols
; col_start
++)
1704 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_start
);
1705 if (col
->IsHidden())
1706 continue; // skip it!
1708 unsigned int w
= col
->GetWidth();
1709 if (x_start
+w
>= (unsigned int)update
.x
)
1715 unsigned int col_last
= col_start
;
1716 unsigned int x_last
= x_start
;
1717 for (; col_last
< cols
; col_last
++)
1719 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_last
);
1720 if (col
->IsHidden())
1721 continue; // skip it!
1723 if (x_last
> (unsigned int)update
.GetRight())
1726 x_last
+= col
->GetWidth();
1729 // Draw horizontal rules if required
1730 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1732 dc
.SetPen(m_penRule
);
1733 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1735 for (unsigned int i
= item_start
; i
<= item_last
; i
++)
1737 int y
= GetLineStart( i
);
1738 dc
.DrawLine(x_start
, y
, x_last
, y
);
1742 // Draw vertical rules if required
1743 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1745 dc
.SetPen(m_penRule
);
1746 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1749 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1751 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(i
);
1752 if (col
->IsHidden())
1753 continue; // skip it
1755 dc
.DrawLine(x
, GetLineStart( item_start
),
1756 x
, GetLineStart( item_last
) );
1758 x
+= col
->GetWidth();
1761 // Draw last vertical rule
1762 dc
.DrawLine(x
, GetLineStart( item_start
),
1763 x
, GetLineStart( item_last
) );
1766 // redraw the background for the items which are selected/current
1767 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1769 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1770 if (selected
|| item
== m_currentRow
)
1772 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
1773 if (item
== m_currentRow
)
1774 flags
|= wxCONTROL_CURRENT
;
1776 flags
|= wxCONTROL_FOCUSED
;
1778 wxRect
rect( x_start
, GetLineStart( item
), x_last
, GetLineHeight( item
) );
1779 wxRendererNative::Get().DrawItemSelectionRect
1789 #if wxUSE_DRAG_AND_DROP
1792 wxRect
rect( x_start
, GetLineStart( m_dropHintLine
),
1793 x_last
, GetLineHeight( m_dropHintLine
) );
1794 dc
.SetPen( *wxBLACK_PEN
);
1795 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1796 dc
.DrawRectangle( rect
);
1798 #endif // wxUSE_DRAG_AND_DROP
1800 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1803 // TODO-RTL: last column for RTL support
1804 expander
= GetOwner()->GetColumnAt( 0 );
1805 GetOwner()->SetExpanderColumn(expander
);
1808 // redraw all cells for all rows which must be repainted and all columns
1810 cell_rect
.x
= x_start
;
1811 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1813 wxDataViewColumn
*col
= GetOwner()->GetColumnAt( i
);
1814 wxDataViewRenderer
*cell
= col
->GetRenderer();
1815 cell_rect
.width
= col
->GetWidth();
1817 if (col
->IsHidden())
1818 continue; // skip it!
1820 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1822 // get the cell value and set it into the renderer
1824 wxDataViewTreeNode
*node
= NULL
;
1825 wxDataViewItem dataitem
;
1827 if (!IsVirtualList())
1829 node
= GetTreeNodeByRow(item
);
1833 dataitem
= node
->GetItem();
1835 if ((i
> 0) && model
->IsContainer(dataitem
) &&
1836 !model
->HasContainerColumns(dataitem
))
1841 dataitem
= wxDataViewItem( wxUIntToPtr(item
+1) );
1844 model
->GetValue( value
, dataitem
, col
->GetModelColumn());
1845 cell
->SetValue( value
);
1848 cell_rect
.y
= GetLineStart( item
);
1849 cell_rect
.height
= GetLineHeight( item
);
1851 // Draw the expander here.
1853 if ((!IsVirtualList()) && (col
== expander
))
1855 indent
= node
->GetIndentLevel();
1857 // Calculate the indent first
1858 indent
= cell_rect
.x
+ GetOwner()->GetIndent() * indent
;
1860 int expander_width
= m_lineHeight
- 2*EXPANDER_MARGIN
;
1862 // change the cell_rect.x to the appropriate pos
1863 int expander_x
= indent
+ EXPANDER_MARGIN
;
1864 int expander_y
= cell_rect
.y
+ EXPANDER_MARGIN
+ (GetLineHeight(item
) / 2)
1865 - (expander_width
/2) - EXPANDER_OFFSET
;
1867 indent
= indent
+ m_lineHeight
;
1868 // try to use the m_lineHeight as the expander space
1870 dc
.SetPen( m_penExpander
);
1871 dc
.SetBrush( wxNullBrush
);
1872 if( node
->HasChildren() )
1874 wxRect
rect( expander_x
, expander_y
, expander_width
, expander_width
);
1876 if (m_underMouse
== node
)
1878 flag
|= wxCONTROL_CURRENT
;
1880 if( node
->IsOpen() )
1881 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
,
1882 flag
|wxCONTROL_EXPANDED
);
1884 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
1887 // force the expander column to left-center align
1888 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
1890 if (node
&& !node
->HasChildren())
1892 // Yes, if the node does not have any child, it must be a leaf which
1893 // mean that it is a temporarily created by GetTreeNodeByRow
1897 wxRect item_rect
= cell_rect
;
1898 item_rect
.Deflate(PADDING_RIGHTLEFT
, 0);
1900 // account for the tree indent (harmless if we're not indented)
1901 item_rect
.x
+= indent
;
1902 item_rect
.width
-= indent
;
1905 if (m_hasFocus
&& (m_selection
.Index(item
) != wxNOT_FOUND
))
1906 state
|= wxDATAVIEW_CELL_SELECTED
;
1908 // TODO: it would be much more efficient to create a clipping
1909 // region for the entire column being rendered (in the OnPaint
1910 // of wxDataViewMainWindow) instead of a single clip region for
1911 // each cell. However it would mean that each renderer should
1912 // respect the given wxRect's top & bottom coords, eventually
1913 // violating only the left & right coords - however the user can
1914 // make its own renderer and thus we cannot be sure of that.
1915 wxDCClipper
clip(dc
, item_rect
);
1917 wxDataViewItemAttr attr
;
1919 hasAttr
= model
->GetAttr(dataitem
, col
->GetModelColumn(), attr
);
1920 cell
->RenderWithAttr(dc
, item_rect
, cell
->CalculateAlignment(),
1921 hasAttr
? &attr
: NULL
, state
);
1924 cell_rect
.x
+= cell_rect
.width
;
1928 void wxDataViewMainWindow::OnRenameTimer()
1930 // We have to call this here because changes may just have
1931 // been made and no screen update taken place.
1934 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
1935 // (needs to be tested!)
1939 wxDataViewItem item
= GetItemByRow( m_currentRow
);
1941 wxRect labelRect
= GetItemRect(item
, m_currentCol
);
1943 m_currentCol
->GetRenderer()->StartEditing( item
, labelRect
);
1946 //-----------------------------------------------------------------------------
1947 // Helper class for do operation on the tree node
1948 //-----------------------------------------------------------------------------
1953 virtual ~DoJob() { }
1955 // The return value control how the tree-walker tranverse the tree
1956 // 0: Job done, stop tranverse and return
1957 // 1: Ignore the current node's subtree and continue
1958 // 2: Job not done, continue
1959 enum { OK
= 0 , IGR
= 1, CONT
= 2 };
1960 virtual int operator() ( wxDataViewTreeNode
* node
) = 0;
1961 virtual int operator() ( void * n
) = 0;
1964 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
1969 switch( func( node
) )
1980 wxDataViewTreeNodes nodes
= node
->GetNodes();
1981 wxDataViewTreeLeaves leaves
= node
->GetChildren();
1983 int len_nodes
= nodes
.GetCount();
1984 int len
= leaves
.GetCount();
1985 int i
= 0, nodes_i
= 0;
1987 for(; i
< len
; i
++ )
1989 void * n
= leaves
[i
];
1990 if( nodes_i
< len_nodes
&& n
== nodes
[nodes_i
]->GetItem().GetID() )
1992 wxDataViewTreeNode
* nd
= nodes
[nodes_i
];
1995 if( Walker( nd
, func
) )
2014 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
2016 if (IsVirtualList())
2018 wxDataViewVirtualListModel
*list_model
=
2019 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
2020 m_count
= list_model
->GetCount();
2027 wxDataViewTreeNode
* node
;
2028 node
= FindNode(parent
);
2033 node
->SetHasChildren( true );
2035 if( g_model
->IsContainer( item
) )
2037 wxDataViewTreeNode
* newnode
= new wxDataViewTreeNode( node
);
2038 newnode
->SetItem(item
);
2039 newnode
->SetHasChildren( true );
2040 node
->AddNode( newnode
);
2043 node
->AddLeaf( item
.GetID() );
2045 node
->ChangeSubTreeCount(1);
2053 static void DestroyTreeHelper( wxDataViewTreeNode
* node
);
2055 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
2056 const wxDataViewItem
& item
)
2058 if (IsVirtualList())
2060 wxDataViewVirtualListModel
*list_model
=
2061 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
2062 m_count
= list_model
->GetCount();
2064 if( m_currentRow
> GetRowCount() )
2065 m_currentRow
= m_count
- 1;
2067 // TODO: why empty the entire selection?
2068 m_selection
.Empty();
2075 wxDataViewTreeNode
* node
= FindNode(parent
);
2077 wxCHECK_MSG( node
!= NULL
, false, "item not found" );
2078 wxCHECK_MSG( node
->GetChildren().Index( item
.GetID() ) != wxNOT_FOUND
,
2079 false, "item not found" );
2082 node
->GetChildren().Remove( item
.GetID() );
2083 // Manipolate selection
2084 if( m_selection
.GetCount() > 1 )
2086 m_selection
.Empty();
2088 bool isContainer
= false;
2089 wxDataViewTreeNodes nds
= node
->GetNodes();
2090 for (size_t i
= 0; i
< nds
.GetCount(); i
++)
2092 if (nds
[i
]->GetItem() == item
)
2100 wxDataViewTreeNode
* n
= NULL
;
2101 wxDataViewTreeNodes nodes
= node
->GetNodes();
2102 int len
= nodes
.GetCount();
2103 for( int i
= 0; i
< len
; i
++)
2105 if( nodes
[i
]->GetItem() == item
)
2112 wxCHECK_MSG( n
!= NULL
, false, "item not found" );
2114 node
->GetNodes().Remove( n
);
2115 sub
-= n
->GetSubTreeCount();
2116 ::DestroyTreeHelper(n
);
2118 // Make the row number invalid and get a new valid one when user call GetRowCount
2120 node
->ChangeSubTreeCount(sub
);
2122 // Change the current row to the last row if the current exceed the max row number
2123 if( m_currentRow
> GetRowCount() )
2124 m_currentRow
= m_count
- 1;
2131 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
2137 wxWindow
*parent
= GetParent();
2138 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2139 le
.SetEventObject(parent
);
2140 le
.SetModel(GetOwner()->GetModel());
2142 parent
->GetEventHandler()->ProcessEvent(le
);
2147 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
2149 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
2150 /*#define MAX_VIRTUAL_WIDTH 100000
2152 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
2153 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2154 Refresh( true, &rect );
2162 wxWindow
*parent
= GetParent();
2163 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2164 le
.SetEventObject(parent
);
2165 le
.SetModel(GetOwner()->GetModel());
2168 le
.SetDataViewColumn(GetOwner()->GetColumn(col
));
2169 parent
->GetEventHandler()->ProcessEvent(le
);
2174 bool wxDataViewMainWindow::Cleared()
2179 BuildTree( GetOwner()->GetModel() );
2186 void wxDataViewMainWindow::UpdateDisplay()
2191 void wxDataViewMainWindow::OnInternalIdle()
2193 wxWindow::OnInternalIdle();
2197 RecalculateDisplay();
2202 void wxDataViewMainWindow::RecalculateDisplay()
2204 wxDataViewModel
*model
= GetOwner()->GetModel();
2211 int width
= GetEndOfLastCol();
2212 int height
= GetLineStart( GetRowCount() );
2214 SetVirtualSize( width
, height
);
2215 GetOwner()->SetScrollRate( 10, m_lineHeight
);
2220 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2222 wxWindow::ScrollWindow( dx
, dy
, rect
);
2224 if (GetOwner()->m_headerArea
)
2225 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
2228 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
2231 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
2232 int sy
= GetLineStart( rows
)/y
;
2236 wxRect rect
= GetClientRect();
2240 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
2241 for (x_start
= 0; colnum
< column
; colnum
++)
2243 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(colnum
);
2244 if (col
->IsHidden())
2245 continue; // skip it!
2247 w
= col
->GetWidth();
2251 int x_end
= x_start
+ w
;
2252 xe
= xx
+ rect
.width
;
2255 sx
= ( xx
+ x_end
- xe
)/x
;
2262 m_owner
->Scroll( sx
, sy
);
2265 int wxDataViewMainWindow::GetCountPerPage() const
2267 wxSize size
= GetClientSize();
2268 return size
.y
/ m_lineHeight
;
2271 int wxDataViewMainWindow::GetEndOfLastCol() const
2275 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2277 const wxDataViewColumn
*c
=
2278 const_cast<wxDataViewCtrl
*>(GetOwner())->GetColumnAt( i
);
2281 width
+= c
->GetWidth();
2286 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2290 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2292 return GetLineAt( y
);
2295 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
2297 wxSize client_size
= GetClientSize();
2298 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2299 &client_size
.x
, &client_size
.y
);
2301 // we should deal with the pixel here
2302 unsigned int row
= GetLineAt(client_size
.y
) - 1;
2304 return wxMin( GetRowCount()-1, row
);
2307 unsigned int wxDataViewMainWindow::GetRowCount()
2309 if ( m_count
== -1 )
2311 m_count
= RecalculateCount();
2317 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
2324 void wxDataViewMainWindow::SelectAllRows( bool on
)
2331 m_selection
.Clear();
2332 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2333 m_selection
.Add( i
);
2338 unsigned int first_visible
= GetFirstVisibleRow();
2339 unsigned int last_visible
= GetLastVisibleRow();
2341 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2343 unsigned int row
= m_selection
[i
];
2344 if ((row
>= first_visible
) && (row
<= last_visible
))
2347 m_selection
.Clear();
2351 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
2353 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2357 m_selection
.Add( row
);
2365 m_selection
.Remove( row
);
2371 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2375 unsigned int tmp
= from
;
2381 for (i
= from
; i
<= to
; i
++)
2383 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2386 m_selection
.Add( i
);
2391 m_selection
.Remove( i
);
2394 RefreshRows( from
, to
);
2397 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2399 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2401 int n
= aSelections
[i
];
2403 m_selection
.Add( n
);
2408 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2410 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2411 m_selection
.Add( row
);
2413 m_selection
.Remove( row
);
2417 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2419 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2422 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
2424 wxWindow
*parent
= GetParent();
2425 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
2427 le
.SetEventObject(parent
);
2428 le
.SetModel(GetOwner()->GetModel());
2431 parent
->GetEventHandler()->ProcessEvent(le
);
2434 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2436 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
2437 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2439 wxSize client_size
= GetClientSize();
2440 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2441 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2442 if (intersect_rect
.width
> 0)
2443 Refresh( true, &intersect_rect
);
2446 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2450 unsigned int tmp
= to
;
2455 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
2456 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2458 wxSize client_size
= GetClientSize();
2459 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2460 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2461 if (intersect_rect
.width
> 0)
2462 Refresh( true, &intersect_rect
);
2465 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2467 wxSize client_size
= GetClientSize();
2468 int start
= GetLineStart( firstRow
);
2469 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
2470 if (start
> client_size
.y
) return;
2472 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
2474 Refresh( true, &rect
);
2477 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2479 wxCHECK_RET( newCurrent
< GetRowCount(),
2480 wxT("invalid item index in OnArrowChar()") );
2482 // if there is no selection, we cannot move it anywhere
2483 if (!HasCurrentRow())
2486 unsigned int oldCurrent
= m_currentRow
;
2488 // in single selection we just ignore Shift as we can't select several
2490 if ( event
.ShiftDown() && !IsSingleSel() )
2492 RefreshRow( oldCurrent
);
2494 ChangeCurrentRow( newCurrent
);
2496 // select all the items between the old and the new one
2497 if ( oldCurrent
> newCurrent
)
2499 newCurrent
= oldCurrent
;
2500 oldCurrent
= m_currentRow
;
2503 SelectRows( oldCurrent
, newCurrent
, true );
2504 if (oldCurrent
!=newCurrent
)
2505 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
2509 RefreshRow( oldCurrent
);
2511 // all previously selected items are unselected unless ctrl is held
2512 if ( !event
.ControlDown() )
2513 SelectAllRows(false);
2515 ChangeCurrentRow( newCurrent
);
2517 if ( !event
.ControlDown() )
2519 SelectRow( m_currentRow
, true );
2520 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
2523 RefreshRow( m_currentRow
);
2526 GetOwner()->EnsureVisible( m_currentRow
, -1 );
2529 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2533 rect
.y
= GetLineStart( row
);
2534 rect
.width
= GetEndOfLastCol();
2535 rect
.height
= GetLineHeight( row
);
2540 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2542 const wxDataViewModel
*model
= GetOwner()->GetModel();
2544 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2546 // TODO make more efficient
2551 for (r
= 0; r
< row
; r
++)
2553 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2554 if (!node
) return start
;
2556 wxDataViewItem item
= node
->GetItem();
2558 if (node
&& !node
->HasChildren())
2560 // Yes, if the node does not have any child, it must be a leaf which
2561 // mean that it is a temporarily created by GetTreeNodeByRow
2565 unsigned int cols
= GetOwner()->GetColumnCount();
2567 int height
= m_lineHeight
;
2568 for (col
= 0; col
< cols
; col
++)
2570 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2571 if (column
->IsHidden())
2572 continue; // skip it!
2575 model
->IsContainer(item
) &&
2576 !model
->HasContainerColumns(item
))
2577 continue; // skip it!
2580 model
->GetValue( value
, item
, column
->GetModelColumn() );
2582 wxDataViewRenderer
*renderer
=
2583 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2584 renderer
->SetValue( value
);
2585 height
= wxMax( height
, renderer
->GetSize().y
);
2595 return row
* m_lineHeight
;
2599 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
2601 const wxDataViewModel
*model
= GetOwner()->GetModel();
2603 // check for the easy case first
2604 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
2605 return y
/ m_lineHeight
;
2607 // TODO make more efficient
2608 unsigned int row
= 0;
2609 unsigned int yy
= 0;
2612 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2615 // not really correct...
2616 return row
+ ((y
-yy
) / m_lineHeight
);
2619 wxDataViewItem item
= node
->GetItem();
2621 if (node
&& !node
->HasChildren())
2623 // Yes, if the node does not have any child, it must be a leaf which
2624 // mean that it is a temporarily created by GetTreeNodeByRow
2628 unsigned int cols
= GetOwner()->GetColumnCount();
2630 int height
= m_lineHeight
;
2631 for (col
= 0; col
< cols
; col
++)
2633 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2634 if (column
->IsHidden())
2635 continue; // skip it!
2638 model
->IsContainer(item
) &&
2639 !model
->HasContainerColumns(item
))
2640 continue; // skip it!
2643 model
->GetValue( value
, item
, column
->GetModelColumn() );
2645 wxDataViewRenderer
*renderer
=
2646 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2647 renderer
->SetValue( value
);
2648 height
= wxMax( height
, renderer
->GetSize().y
);
2659 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
2661 const wxDataViewModel
*model
= GetOwner()->GetModel();
2663 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2665 wxASSERT( !IsVirtualList() );
2667 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2668 // wxASSERT( node );
2669 if (!node
) return m_lineHeight
;
2671 wxDataViewItem item
= node
->GetItem();
2673 if (node
&& !node
->HasChildren())
2675 // Yes, if the node does not have any child, it must be a leaf which
2676 // mean that it is a temporarily created by GetTreeNodeByRow
2680 int height
= m_lineHeight
;
2682 unsigned int cols
= GetOwner()->GetColumnCount();
2684 for (col
= 0; col
< cols
; col
++)
2686 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2687 if (column
->IsHidden())
2688 continue; // skip it!
2691 model
->IsContainer(item
) &&
2692 !model
->HasContainerColumns(item
))
2693 continue; // skip it!
2696 model
->GetValue( value
, item
, column
->GetModelColumn() );
2698 wxDataViewRenderer
*renderer
=
2699 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2700 renderer
->SetValue( value
);
2701 height
= wxMax( height
, renderer
->GetSize().y
);
2708 return m_lineHeight
;
2712 class RowToItemJob
: public DoJob
2715 RowToItemJob( unsigned int row
, int current
)
2716 { this->row
= row
; this->current
= current
; }
2717 virtual ~RowToItemJob() {}
2719 virtual int operator() ( wxDataViewTreeNode
* node
)
2722 if( current
== static_cast<int>(row
))
2724 ret
= node
->GetItem();
2728 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2730 current
+= node
->GetSubTreeCount();
2735 // If the current has no child node, we can find the desired item of the row
2737 // This if can speed up finding in some case, and will has a very good effect
2738 // when it comes to list view
2739 if( node
->GetNodes().GetCount() == 0)
2741 int index
= static_cast<int>(row
) - current
- 1;
2742 ret
= node
->GetChildren().Item( index
);
2749 virtual int operator() ( void * n
)
2752 if( current
== static_cast<int>(row
))
2754 ret
= wxDataViewItem( n
);
2760 wxDataViewItem
GetResult() const
2769 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
2771 if (IsVirtualList())
2773 return wxDataViewItem( wxUIntToPtr(row
+1) );
2777 RowToItemJob
job( row
, -2 );
2778 Walker( m_root
, job
);
2779 return job
.GetResult();
2783 class RowToTreeNodeJob
: public DoJob
2786 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
2789 this->current
= current
;
2793 virtual ~RowToTreeNodeJob(){ }
2795 virtual int operator() ( wxDataViewTreeNode
* node
)
2798 if( current
== static_cast<int>(row
))
2804 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2806 current
+= node
->GetSubTreeCount();
2813 // If the current node has no children, we can find the desired item of the
2814 // row number directly.
2815 // This if can speed up finding in some case, and will have a very good
2816 // effect for list views.
2817 if( node
->GetNodes().GetCount() == 0)
2819 int index
= static_cast<int>(row
) - current
- 1;
2820 void * n
= node
->GetChildren().Item( index
);
2821 ret
= new wxDataViewTreeNode( parent
);
2822 ret
->SetItem( wxDataViewItem( n
));
2823 ret
->SetHasChildren(false);
2830 virtual int operator() ( void * n
)
2833 if( current
== static_cast<int>(row
))
2835 ret
= new wxDataViewTreeNode( parent
);
2836 ret
->SetItem( wxDataViewItem( n
));
2837 ret
->SetHasChildren(false);
2844 wxDataViewTreeNode
* GetResult() const
2850 wxDataViewTreeNode
* ret
;
2851 wxDataViewTreeNode
* parent
;
2854 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
2856 wxASSERT( !IsVirtualList() );
2858 RowToTreeNodeJob
job( row
, -2, m_root
);
2859 Walker( m_root
, job
);
2860 return job
.GetResult();
2863 wxDataViewEvent
wxDataViewMainWindow::SendExpanderEvent( wxEventType type
,
2864 const wxDataViewItem
& item
)
2866 wxWindow
*parent
= GetParent();
2867 wxDataViewEvent
le(type
, parent
->GetId());
2869 le
.SetEventObject(parent
);
2870 le
.SetModel(GetOwner()->GetModel());
2873 parent
->GetEventHandler()->ProcessEvent(le
);
2877 bool wxDataViewMainWindow::IsExpanded( unsigned int row
) const
2879 if (IsVirtualList())
2882 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2886 if (!node
->HasChildren())
2892 return node
->IsOpen();
2895 bool wxDataViewMainWindow::HasChildren( unsigned int row
) const
2897 if (IsVirtualList())
2900 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2904 if (!node
->HasChildren())
2913 void wxDataViewMainWindow::Expand( unsigned int row
)
2915 if (IsVirtualList())
2918 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2922 if (!node
->HasChildren())
2928 if (!node
->IsOpen())
2931 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, node
->GetItem());
2933 // Check if the user prevent expanding
2934 if( e
.GetSkipped() )
2939 // build the children of current node
2940 if( node
->GetChildrenNumber() == 0 )
2943 ::BuildTreeHelper(GetOwner()->GetModel(), node
->GetItem(), node
);
2946 // By expanding the node all row indices that are currently in the selection list
2947 // and are greater than our node have become invalid. So we have to correct that now.
2948 const unsigned rowAdjustment
= node
->GetSubTreeCount();
2949 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2951 const unsigned testRow
= m_selection
[i
];
2952 // all rows above us are not affected, so skip them
2956 m_selection
[i
] += rowAdjustment
;
2959 if(m_currentRow
> row
)
2960 ChangeCurrentRow(m_currentRow
+ rowAdjustment
);
2964 // Send the expanded event
2965 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
2969 void wxDataViewMainWindow::Collapse(unsigned int row
)
2971 if (IsVirtualList())
2974 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
2978 if (!node
->HasChildren())
2987 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem());
2988 if( e
.GetSkipped() )
2991 // Find out if there are selected items below the current node.
2992 bool selectCollapsingRow
= false;
2993 const unsigned rowAdjustment
= node
->GetSubTreeCount();
2994 unsigned maxRowToBeTested
= row
+ rowAdjustment
;
2995 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2997 const unsigned testRow
= m_selection
[i
];
2998 if(testRow
> row
&& testRow
<= maxRowToBeTested
)
3000 selectCollapsingRow
= true;
3001 // get out as soon as we have found a node that is selected
3008 // If the node to be closed has selected items the user won't see those any longer.
3009 // We select the collapsing node in this case.
3010 if(selectCollapsingRow
)
3012 SelectAllRows(false);
3013 ChangeCurrentRow(row
);
3014 SelectRow(row
, true);
3015 SendSelectionChangedEvent(GetItemByRow(row
));
3019 // if there were no selected items below our node we still need to "fix" the
3020 // selection list to adjust for the changing of the row indices.
3021 // We actually do the opposite of what we are doing in Expand().
3022 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3024 const unsigned testRow
= m_selection
[i
];
3025 // all rows above us are not affected, so skip them
3029 m_selection
[i
] -= rowAdjustment
;
3032 // if the "current row" is being collapsed away we change it to the current row ;-)
3033 if(m_currentRow
> row
&& m_currentRow
<= maxRowToBeTested
)
3034 ChangeCurrentRow(row
);
3035 else if(m_currentRow
> row
)
3036 ChangeCurrentRow(m_currentRow
- rowAdjustment
);
3041 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,node
->GetItem());
3045 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
3047 wxDataViewModel
* model
= GetOwner()->GetModel();
3054 // Compose the a parent-chain of the finding item
3056 list
.DeleteContents( true );
3057 wxDataViewItem
it( item
);
3060 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3061 list
.Insert( pItem
);
3062 it
= model
->GetParent( it
);
3065 // Find the item along the parent-chain.
3066 // This algorithm is designed to speed up the node-finding method
3067 wxDataViewTreeNode
* node
= m_root
;
3068 for( ItemList::const_iterator iter
= list
.begin(); iter
!=list
.end(); iter
++ )
3070 if( node
->HasChildren() )
3072 if( node
->GetChildrenNumber() == 0 )
3075 ::BuildTreeHelper(model
, node
->GetItem(), node
);
3078 wxDataViewTreeNodes nodes
= node
->GetNodes();
3082 for (i
= 0; i
< nodes
.GetCount(); i
++)
3084 if (nodes
[i
]->GetItem() == (**iter
))
3086 if (nodes
[i
]->GetItem() == item
)
3103 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
3104 wxDataViewColumn
* &column
)
3106 wxDataViewColumn
*col
= NULL
;
3107 unsigned int cols
= GetOwner()->GetColumnCount();
3108 unsigned int colnum
= 0;
3110 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
3111 for (unsigned x_start
= 0; colnum
< cols
; colnum
++)
3113 col
= GetOwner()->GetColumnAt(colnum
);
3114 if (col
->IsHidden())
3115 continue; // skip it!
3117 unsigned int w
= col
->GetWidth();
3118 if (x_start
+w
>= (unsigned int)x
)
3125 item
= GetItemByRow( GetLineAt( y
) );
3128 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
,
3129 const wxDataViewColumn
* column
)
3134 unsigned int cols
= GetOwner()->GetColumnCount();
3135 // If column is null the loop will compute the combined width of all columns.
3136 // Otherwise, it will compute the x position of the column we are looking for.
3137 for (unsigned int i
= 0; i
< cols
; i
++)
3139 wxDataViewColumn
* col
= GetOwner()->GetColumnAt( i
);
3144 if (col
->IsHidden())
3145 continue; // skip it!
3147 xpos
+= col
->GetWidth();
3148 width
+= col
->GetWidth();
3153 // If we have a column, we need can get its width directly.
3154 if(column
->IsHidden())
3157 width
= column
->GetWidth();
3162 // If we have no column, we reset the x position back to zero.
3166 // we have to take an expander column into account and compute its indentation
3167 // to get the correct x position where the actual text is
3169 int row
= GetRowByItem(item
);
3170 if (!IsVirtualList() && (column
== 0 || GetOwner()->GetExpanderColumn() == column
) )
3172 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3173 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
3174 indent
= indent
+ m_lineHeight
; // use m_lineHeight as the width of the expander
3176 if(!node
->HasChildren())
3180 wxRect
itemRect( xpos
+ indent
,
3181 GetLineStart( row
),
3183 GetLineHeight( row
) );
3185 GetOwner()->CalcScrolledPosition( itemRect
.x
, itemRect
.y
,
3186 &itemRect
.x
, &itemRect
.y
);
3191 int wxDataViewMainWindow::RecalculateCount()
3193 if (IsVirtualList())
3195 wxDataViewVirtualListModel
*list_model
=
3196 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
3198 return list_model
->GetCount();
3202 return m_root
->GetSubTreeCount();
3206 class ItemToRowJob
: public DoJob
3209 ItemToRowJob(const wxDataViewItem
& item_
, ItemList::const_iterator iter
)
3216 // Maybe binary search will help to speed up this process
3217 virtual int operator() ( wxDataViewTreeNode
* node
)
3220 if( node
->GetItem() == item
)
3225 if( node
->GetItem() == **m_iter
)
3232 ret
+= node
->GetSubTreeCount();
3238 virtual int operator() ( void * n
)
3241 if( n
== item
.GetID() )
3246 // the row number is begin from zero
3247 int GetResult() const
3251 ItemList::const_iterator m_iter
;
3252 wxDataViewItem item
;
3257 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
3259 const wxDataViewModel
* model
= GetOwner()->GetModel();
3263 if (IsVirtualList())
3265 return wxPtrToUInt( item
.GetID() ) -1;
3272 // Compose the a parent-chain of the finding item
3274 wxDataViewItem
* pItem
;
3275 list
.DeleteContents( true );
3276 wxDataViewItem
it( item
);
3279 pItem
= new wxDataViewItem( it
);
3280 list
.Insert( pItem
);
3281 it
= model
->GetParent( it
);
3283 pItem
= new wxDataViewItem( );
3284 list
.Insert( pItem
);
3286 ItemToRowJob
job( item
, list
.begin() );
3287 Walker(m_root
, job
);
3288 return job
.GetResult();
3292 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
3293 wxDataViewTreeNode
* node
)
3295 if( !model
->IsContainer( item
) )
3298 wxDataViewItemArray children
;
3299 unsigned int num
= model
->GetChildren( item
, children
);
3301 unsigned int index
= 0;
3302 while( index
< num
)
3304 if( model
->IsContainer( children
[index
] ) )
3306 wxDataViewTreeNode
* n
= new wxDataViewTreeNode( node
);
3307 n
->SetItem(children
[index
]);
3308 n
->SetHasChildren( true );
3313 node
->AddLeaf( children
[index
].GetID() );
3317 node
->SetSubTreeCount( num
);
3318 wxDataViewTreeNode
* n
= node
->GetParent();
3320 n
->ChangeSubTreeCount(num
);
3324 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
3328 if (GetOwner()->GetModel()->IsVirtualListModel())
3334 m_root
= new wxDataViewTreeNode( NULL
);
3335 m_root
->SetHasChildren(true);
3337 // First we define a invalid item to fetch the top-level elements
3338 wxDataViewItem item
;
3340 BuildTreeHelper( model
, item
, m_root
);
3344 static void DestroyTreeHelper( wxDataViewTreeNode
* node
)
3346 if( node
->GetNodeNumber() != 0 )
3348 int len
= node
->GetNodeNumber();
3349 wxDataViewTreeNodes
& nodes
= node
->GetNodes();
3350 for (int i
= 0; i
< len
; i
++)
3351 DestroyTreeHelper(nodes
[i
]);
3356 void wxDataViewMainWindow::DestroyTree()
3358 if (!IsVirtualList())
3360 ::DestroyTreeHelper(m_root
);
3366 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
3368 if ( GetParent()->HandleAsNavigationKey(event
) )
3371 // no item -> nothing to do
3372 if (!HasCurrentRow())
3378 // don't use m_linesPerPage directly as it might not be computed yet
3379 const int pageSize
= GetCountPerPage();
3380 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
3382 switch ( event
.GetKeyCode() )
3386 wxWindow
*parent
= GetParent();
3387 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
,
3389 le
.SetItem( GetItemByRow(m_currentRow
) );
3390 le
.SetEventObject(parent
);
3391 le
.SetModel(GetOwner()->GetModel());
3393 parent
->GetEventHandler()->ProcessEvent(le
);
3398 if ( m_currentRow
> 0 )
3399 OnArrowChar( m_currentRow
- 1, event
);
3403 if ( m_currentRow
< GetRowCount() - 1 )
3404 OnArrowChar( m_currentRow
+ 1, event
);
3406 // Add the process for tree expanding/collapsing
3409 if (IsVirtualList())
3412 wxDataViewTreeNode
* node
= GetTreeNodeByRow(m_currentRow
);
3416 if (node
->HasChildren() && node
->IsOpen())
3418 Collapse(m_currentRow
);
3420 else // if the node is already closed we move the selection to its parent
3422 wxDataViewTreeNode
*parent_node
= node
->GetParent();
3424 if(!node
->HasChildren())
3429 int parent
= GetRowByItem( parent_node
->GetItem() );
3432 unsigned int row
= m_currentRow
;
3433 SelectRow( row
, false);
3434 SelectRow( parent
, true );
3435 ChangeCurrentRow( parent
);
3436 GetOwner()->EnsureVisible( parent
, -1 );
3437 SendSelectionChangedEvent( parent_node
->GetItem() );
3445 if (!IsExpanded( m_currentRow
))
3446 Expand( m_currentRow
);
3449 unsigned int row
= m_currentRow
;
3450 SelectRow( row
, false );
3451 SelectRow( row
+ 1, true );
3452 ChangeCurrentRow( row
+ 1 );
3453 GetOwner()->EnsureVisible( row
+ 1, -1 );
3454 SendSelectionChangedEvent( GetItemByRow(row
+1) );
3461 OnArrowChar( GetRowCount() - 1, event
);
3466 OnArrowChar( 0, event
);
3471 int steps
= pageSize
- 1;
3472 int index
= m_currentRow
- steps
;
3476 OnArrowChar( index
, event
);
3482 int steps
= pageSize
- 1;
3483 unsigned int index
= m_currentRow
+ steps
;
3484 unsigned int count
= GetRowCount();
3485 if ( index
>= count
)
3488 OnArrowChar( index
, event
);
3494 if(m_selection
.size() == 1)
3496 // TODO: we need to revise that when we have a concept for a 'current column'
3497 GetOwner()->StartEditor(GetItemByRow(m_selection
[0]), 0);
3507 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
3509 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3511 // let the base handle mouse wheel events.
3516 int x
= event
.GetX();
3517 int y
= event
.GetY();
3518 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
3519 wxDataViewColumn
*col
= NULL
;
3522 unsigned int cols
= GetOwner()->GetColumnCount();
3524 for (i
= 0; i
< cols
; i
++)
3526 wxDataViewColumn
*c
= GetOwner()->GetColumnAt( i
);
3528 continue; // skip it!
3530 if (x
< xpos
+ c
->GetWidth())
3535 xpos
+= c
->GetWidth();
3540 wxDataViewRenderer
*cell
= col
->GetRenderer();
3541 unsigned int current
= GetLineAt( y
);
3542 if ((current
>= GetRowCount()) || (x
> GetEndOfLastCol()))
3544 // Unselect all if below the last row ?
3548 // Test whether the mouse is hovered on the tree item button
3549 bool hoverOverExpander
= false;
3550 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
3552 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3553 if( node
!=NULL
&& node
->HasChildren() )
3555 int indent
= node
->GetIndentLevel();
3556 indent
= GetOwner()->GetIndent()*indent
;
3558 // we make the rectangle we are looking in a bit bigger than the actual
3559 // visual expander so the user can hit that little thing reliably
3560 wxRect
rect( xpos
+ indent
,
3561 GetLineStart( current
) + (GetLineHeight(current
) - m_lineHeight
)/2,
3562 m_lineHeight
, m_lineHeight
);
3563 if( rect
.Contains(x
, y
) )
3565 // So the mouse is over the expander
3566 hoverOverExpander
= true;
3567 if (m_underMouse
&& m_underMouse
!= node
)
3569 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3570 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3572 if (m_underMouse
!= node
)
3574 // wxLogMessage("Do the row: %d", current);
3575 RefreshRow(current
);
3577 m_underMouse
= node
;
3580 if (node
!=NULL
&& !node
->HasChildren())
3583 if (!hoverOverExpander
)
3585 if (m_underMouse
!= NULL
)
3587 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3588 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3589 m_underMouse
= NULL
;
3593 wxDataViewModel
*model
= GetOwner()->GetModel();
3595 #if wxUSE_DRAG_AND_DROP
3596 if (event
.Dragging())
3598 if (m_dragCount
== 0)
3600 // we have to report the raw, physical coords as we want to be
3601 // able to call HitTest(event.m_pointDrag) from the user code to
3602 // get the item being dragged
3603 m_dragStart
= event
.GetPosition();
3608 if (m_dragCount
!= 3)
3611 if (event
.LeftIsDown())
3613 m_owner
->CalcUnscrolledPosition( m_dragStart
.x
, m_dragStart
.y
,
3614 &m_dragStart
.x
, &m_dragStart
.y
);
3615 unsigned int drag_item_row
= GetLineAt( m_dragStart
.y
);
3616 wxDataViewItem item
= GetItemByRow( drag_item_row
);
3618 // Notify cell about drag
3619 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3620 event
.SetEventObject( m_owner
);
3621 event
.SetItem( item
);
3622 event
.SetModel( model
);
3623 if (!m_owner
->HandleWindowEvent( event
))
3626 if (!event
.IsAllowed())
3629 wxDataObject
*obj
= event
.GetDataObject();
3633 wxDataViewDropSource
drag( this, drag_item_row
);
3634 drag
.SetData( *obj
);
3635 /* wxDragResult res = */ drag
.DoDragDrop();
3644 #endif // wxUSE_DRAG_AND_DROP
3646 bool simulateClick
= false;
3648 if (event
.ButtonDClick())
3650 m_renameTimer
->Stop();
3651 m_lastOnSame
= false;
3654 wxDataViewItem item
= GetItemByRow(current
);
3655 bool ignore_other_columns
=
3656 ((GetOwner()->GetExpanderColumn() != col
) &&
3657 (model
->IsContainer(item
)) &&
3658 (!model
->HasContainerColumns(item
)));
3660 if (event
.LeftDClick())
3662 if(hoverOverExpander
)
3664 // a double click on the expander will be converted into a "simulated" normal click
3665 simulateClick
= true;
3667 else if ( current
== m_lineLastClicked
)
3669 if ((!ignore_other_columns
) && (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
3672 model
->GetValue( value
, item
, col
->GetModelColumn() );
3673 cell
->SetValue( value
);
3674 wxRect
cell_rect( xpos
, GetLineStart( current
),
3675 col
->GetWidth(), GetLineHeight( current
) );
3676 cell
->Activate( cell_rect
, model
, item
, col
->GetModelColumn() );
3680 wxWindow
*parent
= GetParent();
3681 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3683 le
.SetEventObject(parent
);
3684 le
.SetModel(GetOwner()->GetModel());
3686 parent
->GetEventHandler()->ProcessEvent(le
);
3692 // The first click was on another item, so don't interpret this as
3693 // a double click, but as a simple click instead
3694 simulateClick
= true;
3698 if (event
.LeftUp() && !hoverOverExpander
)
3700 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
3702 // select single line
3703 SelectAllRows( false );
3704 SelectRow( m_lineSelectSingleOnUp
, true );
3705 SendSelectionChangedEvent( GetItemByRow(m_lineSelectSingleOnUp
) );
3708 // If the user click the expander, we do not do editing even if the column
3709 // with expander are editable
3710 if (m_lastOnSame
&& !ignore_other_columns
)
3712 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
3713 (cell
->GetMode() & wxDATAVIEW_CELL_EDITABLE
) )
3715 m_renameTimer
->Start( 100, true );
3719 m_lastOnSame
= false;
3720 m_lineSelectSingleOnUp
= (unsigned int)-1;
3722 else if(!event
.LeftUp())
3724 // This is necessary, because after a DnD operation in
3725 // from and to ourself, the up event is swallowed by the
3726 // DnD code. So on next non-up event (which means here and
3727 // now) m_lineSelectSingleOnUp should be reset.
3728 m_lineSelectSingleOnUp
= (unsigned int)-1;
3731 if (event
.RightDown())
3733 m_lineBeforeLastClicked
= m_lineLastClicked
;
3734 m_lineLastClicked
= current
;
3736 // If the item is already selected, do not update the selection.
3737 // Multi-selections should not be cleared if a selected item is clicked.
3738 if (!IsRowSelected(current
))
3740 SelectAllRows(false);
3741 ChangeCurrentRow(current
);
3742 SelectRow(m_currentRow
,true);
3743 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3746 else if (event
.RightUp())
3749 model
->GetValue( value
, item
, col
->GetModelColumn() );
3750 wxWindow
*parent
= GetParent();
3751 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
3753 le
.SetEventObject(parent
);
3754 le
.SetModel(GetOwner()->GetModel());
3756 parent
->GetEventHandler()->ProcessEvent(le
);
3758 else if (event
.MiddleDown())
3762 if((event
.LeftDown() || simulateClick
) && hoverOverExpander
)
3764 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3766 // hoverOverExpander being true tells us that our node must be
3767 // valid and have children.
3768 // So we don't need any extra checks.
3769 if( node
->IsOpen() )
3774 else if ((event
.LeftDown() || simulateClick
) && !hoverOverExpander
)
3778 m_lineBeforeLastClicked
= m_lineLastClicked
;
3779 m_lineLastClicked
= current
;
3781 unsigned int oldCurrentRow
= m_currentRow
;
3782 bool oldWasSelected
= IsRowSelected(m_currentRow
);
3784 bool cmdModifierDown
= event
.CmdDown();
3785 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3787 if ( IsSingleSel() || !IsRowSelected(current
) )
3789 SelectAllRows( false );
3790 ChangeCurrentRow(current
);
3791 SelectRow(m_currentRow
,true);
3792 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3794 else // multi sel & current is highlighted & no mod keys
3796 m_lineSelectSingleOnUp
= current
;
3797 ChangeCurrentRow(current
); // change focus
3800 else // multi sel & either ctrl or shift is down
3802 if (cmdModifierDown
)
3804 ChangeCurrentRow(current
);
3805 ReverseRowSelection(m_currentRow
);
3806 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3808 else if (event
.ShiftDown())
3810 ChangeCurrentRow(current
);
3812 unsigned int lineFrom
= oldCurrentRow
,
3815 if ( lineTo
< lineFrom
)
3818 lineFrom
= m_currentRow
;
3821 SelectRows(lineFrom
, lineTo
, true);
3822 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3824 else // !ctrl, !shift
3826 // test in the enclosing if should make it impossible
3827 wxFAIL_MSG( wxT("how did we get here?") );
3831 if (m_currentRow
!= oldCurrentRow
)
3832 RefreshRow( oldCurrentRow
);
3834 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
3836 // Update selection here...
3839 m_lastOnSame
= !simulateClick
&& ((col
== oldCurrentCol
) &&
3840 (current
== oldCurrentRow
)) && oldWasSelected
;
3842 // Call LeftClick after everything else as under GTK+
3843 if (cell
->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE
)
3845 // notify cell about right click
3847 model
->GetValue( value
, item
, col
->GetModelColumn() );
3848 cell
->SetValue( value
);
3849 wxRect
cell_rect( xpos
, GetLineStart( current
),
3850 col
->GetWidth(), GetLineHeight( current
) );
3851 /* ignore ret */ cell
->LeftClick( event
.GetPosition(), cell_rect
,
3852 model
, item
, col
->GetModelColumn());
3857 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
3861 if (HasCurrentRow())
3867 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
3871 if (HasCurrentRow())
3877 wxDataViewItem
wxDataViewMainWindow::GetSelection() const
3879 if( m_selection
.GetCount() != 1 )
3880 return wxDataViewItem();
3882 return GetItemByRow( m_selection
.Item(0));
3885 //-----------------------------------------------------------------------------
3887 //-----------------------------------------------------------------------------
3889 WX_DEFINE_LIST(wxDataViewColumnList
)
3891 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3892 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
3893 EVT_SIZE(wxDataViewCtrl::OnSize
)
3896 wxDataViewCtrl::~wxDataViewCtrl()
3899 GetModel()->RemoveNotifier( m_notifier
);
3904 void wxDataViewCtrl::Init()
3906 m_cols
.DeleteContents(true);
3909 // No sorting column at start
3910 m_sortingColumnIdx
= wxNOT_FOUND
;
3912 m_headerArea
= NULL
;
3915 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3916 const wxPoint
& pos
, const wxSize
& size
,
3917 long style
, const wxValidator
& validator
)
3919 // if ( (style & wxBORDER_MASK) == 0)
3920 // style |= wxBORDER_SUNKEN;
3924 if (!wxControl::Create( parent
, id
, pos
, size
,
3925 style
| wxScrolledWindowStyle
, validator
))
3928 SetInitialSize(size
);
3931 MacSetClipChildren( true );
3934 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
3936 if (HasFlag(wxDV_NO_HEADER
))
3937 m_headerArea
= NULL
;
3939 m_headerArea
= new wxDataViewHeaderWindow(this);
3941 SetTargetWindow( m_clientArea
);
3943 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
3945 sizer
->Add( m_headerArea
, 0, wxGROW
);
3946 sizer
->Add( m_clientArea
, 1, wxGROW
);
3952 wxBorder
wxDataViewCtrl::GetDefaultBorder() const
3954 return wxBORDER_THEME
;
3958 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
3962 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
3965 // we need to process arrows ourselves for scrolling
3966 if ( nMsg
== WM_GETDLGCODE
)
3968 rc
|= DLGC_WANTARROWS
;
3976 wxSize
wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
3978 wxSize newsize
= size
;
3979 if (!HasFlag(wxDV_NO_HEADER
) && (m_headerArea
))
3980 newsize
.y
-= m_headerArea
->GetSize().y
;
3985 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3987 // We need to override OnSize so that our scrolled
3988 // window a) does call Layout() to use sizers for
3989 // positioning the controls but b) does not query
3990 // the sizer for their size and use that for setting
3991 // the scrollable area as set that ourselves by
3992 // calling SetScrollbar() further down.
3999 void wxDataViewCtrl::SetFocus()
4002 m_clientArea
->SetFocus();
4005 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4007 if (!wxDataViewCtrlBase::AssociateModel( model
))
4010 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
4012 model
->AddNotifier( m_notifier
);
4014 m_clientArea
->DestroyTree();
4016 m_clientArea
->BuildTree(model
);
4018 m_clientArea
->UpdateDisplay();
4023 #if wxUSE_DRAG_AND_DROP
4025 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4027 return m_clientArea
->EnableDragSource( format
);
4030 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4032 return m_clientArea
->EnableDropTarget( format
);
4035 #endif // wxUSE_DRAG_AND_DROP
4037 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4039 if (!wxDataViewCtrlBase::AppendColumn(col
))
4042 m_cols
.Append( col
);
4043 OnColumnsCountChanged();
4047 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4049 if (!wxDataViewCtrlBase::PrependColumn(col
))
4052 m_cols
.Insert( col
);
4053 OnColumnsCountChanged();
4057 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4059 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4062 m_cols
.Insert( pos
, col
);
4063 OnColumnsCountChanged();
4067 void wxDataViewCtrl::OnColumnChange(unsigned int idx
)
4070 m_headerArea
->UpdateColumn(idx
);
4072 m_clientArea
->UpdateDisplay();
4075 void wxDataViewCtrl::OnColumnsCountChanged()
4078 m_headerArea
->SetColumnCount(GetColumnCount());
4080 m_clientArea
->UpdateDisplay();
4083 void wxDataViewCtrl::DoSetExpanderColumn()
4085 m_clientArea
->UpdateDisplay();
4088 void wxDataViewCtrl::DoSetIndent()
4090 m_clientArea
->UpdateDisplay();
4093 unsigned int wxDataViewCtrl::GetColumnCount() const
4095 return m_cols
.GetCount();
4098 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int idx
) const
4103 wxDataViewColumn
*wxDataViewCtrl::GetColumnAt(unsigned int pos
) const
4105 // columns can't be reordered if there is no header window which allows
4107 const unsigned idx
= m_headerArea
? m_headerArea
->GetColumnsOrder()[pos
]
4110 return GetColumn(idx
);
4113 int wxDataViewCtrl::GetColumnIndex(const wxDataViewColumn
*column
) const
4115 const unsigned count
= m_cols
.size();
4116 for ( unsigned n
= 0; n
< count
; n
++ )
4118 if ( m_cols
[n
] == column
)
4125 void wxDataViewCtrl::ColumnMoved(wxDataViewColumn
* WXUNUSED(col
),
4126 unsigned int WXUNUSED(new_pos
))
4128 // do _not_ reorder m_cols elements here, they should always be in the
4129 // order in which columns were added, we only display the columns in
4131 m_clientArea
->UpdateDisplay();
4134 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4136 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
4141 OnColumnsCountChanged();
4146 bool wxDataViewCtrl::ClearColumns()
4149 OnColumnsCountChanged();
4153 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4157 unsigned int len
= GetColumnCount();
4158 for ( unsigned int i
= 0; i
< len
; i
++ )
4160 wxDataViewColumn
* col
= GetColumnAt(i
);
4161 if (col
->IsHidden())
4163 ret
+= col
->GetWidth();
4166 CalcScrolledPosition( ret
, dummy
, &ret
, &dummy
);
4173 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4175 return m_sortingColumnIdx
== wxNOT_FOUND
? NULL
4176 : GetColumn(m_sortingColumnIdx
);
4179 // Selection code with wxDataViewItem as parameters
4180 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4182 return m_clientArea
->GetSelection();
4185 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4188 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4189 int len
= selection
.GetCount();
4190 for( int i
= 0; i
< len
; i
++)
4192 unsigned int row
= selection
[i
];
4193 sel
.Add( m_clientArea
->GetItemByRow( row
) );
4198 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4200 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4202 wxDataViewItem last_parent
;
4204 int len
= sel
.GetCount();
4205 for( int i
= 0; i
< len
; i
++ )
4207 wxDataViewItem item
= sel
[i
];
4208 wxDataViewItem parent
= GetModel()->GetParent( item
);
4211 if (parent
!= last_parent
)
4212 ExpandAncestors(item
);
4215 last_parent
= parent
;
4216 int row
= m_clientArea
->GetRowByItem( item
);
4218 selection
.Add( static_cast<unsigned int>(row
) );
4221 m_clientArea
->SetSelections( selection
);
4224 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4226 ExpandAncestors( item
);
4228 int row
= m_clientArea
->GetRowByItem( item
);
4231 // Unselect all rows before select another in the single select mode
4232 if (m_clientArea
->IsSingleSel())
4233 m_clientArea
->SelectAllRows(false);
4234 m_clientArea
->SelectRow(row
, true);
4238 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4240 int row
= m_clientArea
->GetRowByItem( item
);
4242 m_clientArea
->SelectRow(row
, false);
4245 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4247 int row
= m_clientArea
->GetRowByItem( item
);
4250 return m_clientArea
->IsRowSelected(row
);
4255 // Selection code with row number as parameter
4256 int wxDataViewCtrl::GetSelections( wxArrayInt
& sel
) const
4259 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4260 int len
= selection
.GetCount();
4261 for( int i
= 0; i
< len
; i
++)
4263 unsigned int row
= selection
[i
];
4269 void wxDataViewCtrl::SetSelections( const wxArrayInt
& sel
)
4271 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4272 int len
= sel
.GetCount();
4273 for( int i
= 0; i
< len
; i
++ )
4277 selection
.Add( static_cast<unsigned int>(row
) );
4279 m_clientArea
->SetSelections( selection
);
4282 void wxDataViewCtrl::Select( int row
)
4286 if (m_clientArea
->IsSingleSel())
4287 m_clientArea
->SelectAllRows(false);
4288 m_clientArea
->SelectRow( row
, true );
4292 void wxDataViewCtrl::Unselect( int row
)
4295 m_clientArea
->SelectRow(row
, false);
4298 bool wxDataViewCtrl::IsSelected( int row
) const
4301 return m_clientArea
->IsRowSelected(row
);
4305 void wxDataViewCtrl::SelectRange( int from
, int to
)
4308 for( int i
= from
; i
< to
; i
++ )
4310 m_clientArea
->Select(sel
);
4313 void wxDataViewCtrl::UnselectRange( int from
, int to
)
4315 wxDataViewSelection sel
= m_clientArea
->GetSelections();
4316 for( int i
= from
; i
< to
; i
++ )
4317 if( sel
.Index( i
) != wxNOT_FOUND
)
4319 m_clientArea
->SetSelections(sel
);
4322 void wxDataViewCtrl::SelectAll()
4324 m_clientArea
->SelectAllRows(true);
4327 void wxDataViewCtrl::UnselectAll()
4329 m_clientArea
->SelectAllRows(false);
4332 void wxDataViewCtrl::EnsureVisible( int row
, int column
)
4336 if( row
> (int) m_clientArea
->GetRowCount() )
4337 row
= m_clientArea
->GetRowCount();
4339 int first
= m_clientArea
->GetFirstVisibleRow();
4340 int last
= m_clientArea
->GetLastVisibleRow();
4342 m_clientArea
->ScrollTo( row
, column
);
4343 else if( row
> last
)
4344 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
4346 m_clientArea
->ScrollTo( first
, column
);
4349 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
4351 ExpandAncestors( item
);
4353 m_clientArea
->RecalculateDisplay();
4355 int row
= m_clientArea
->GetRowByItem(item
);
4358 if( column
== NULL
)
4359 EnsureVisible(row
, -1);
4361 EnsureVisible( row
, GetColumnIndex(column
) );
4366 void wxDataViewCtrl::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
4367 wxDataViewColumn
* &column
) const
4369 m_clientArea
->HitTest(point
, item
, column
);
4372 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
& item
,
4373 const wxDataViewColumn
* column
) const
4375 return m_clientArea
->GetItemRect(item
, column
);
4378 wxDataViewItem
wxDataViewCtrl::GetItemByRow( unsigned int row
) const
4380 return m_clientArea
->GetItemByRow( row
);
4383 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem
& item
) const
4385 return m_clientArea
->GetRowByItem( item
);
4388 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4390 int row
= m_clientArea
->GetRowByItem( item
);
4392 m_clientArea
->Expand(row
);
4395 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4397 int row
= m_clientArea
->GetRowByItem( item
);
4399 m_clientArea
->Collapse(row
);
4402 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4404 int row
= m_clientArea
->GetRowByItem( item
);
4406 return m_clientArea
->IsExpanded(row
);
4410 void wxDataViewCtrl::StartEditor( const wxDataViewItem
& item
, unsigned int column
)
4412 wxDataViewColumn
* col
= GetColumn( column
);
4416 wxRect itemRect
= GetItemRect(item
, col
);
4417 wxDataViewRenderer
* renderer
= col
->GetRenderer();
4418 renderer
->StartEditing(item
, itemRect
);
4421 #endif // !wxUSE_GENERICDATAVIEWCTRL
4423 #endif // wxUSE_DATAVIEWCTRL