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
,
730 // override custom foreground with the standard one for the selected items
731 // because we currently don't allow changing the selection background and
732 // custom colours may be unreadable on it
734 if ( state
& wxDATAVIEW_CELL_SELECTED
)
735 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
736 else if ( attr
&& attr
->HasColour() )
737 col
= attr
->GetColour();
738 else // use default foreground
739 col
= GetOwner()->GetOwner()->GetForegroundColour();
741 wxDCTextColourChanger
changeFg(dc
, col
);
743 wxDCFontChanger
changeFont(dc
);
744 if ( attr
&& attr
->HasFont() )
746 wxFont
font(dc
.GetFont());
747 if ( attr
->GetBold() )
749 if ( attr
->GetItalic() )
752 changeFont
.Set(font
);
755 wxRect rectText
= rect
;
756 rectText
.x
+= xoffset
;
757 rectText
.width
-= xoffset
;
759 // check if we want to ellipsize the text if it doesn't fit
760 wxString ellipsizedText
;
761 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
763 ellipsizedText
= wxControl::Ellipsize
769 wxELLIPSIZE_FLAGS_NONE
773 dc
.DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
777 // ---------------------------------------------------------
778 // wxDataViewTextRenderer
779 // ---------------------------------------------------------
781 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
783 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
784 wxDataViewCellMode mode
, int align
) :
785 wxDataViewCustomRenderer( varianttype
, mode
, align
)
789 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
791 m_text
= value
.GetString();
796 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
801 bool wxDataViewTextRenderer::HasEditorCtrl() const
806 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
807 wxRect labelRect
, const wxVariant
&value
)
809 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, value
,
810 wxPoint(labelRect
.x
,labelRect
.y
),
811 wxSize(labelRect
.width
,labelRect
.height
) );
813 // select the text in the control an place the cursor at the end
814 ctrl
->SetInsertionPointEnd();
820 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
822 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
823 value
= text
->GetValue();
828 wxDataViewTextRenderer::RenderWithAttr(wxDC
& dc
,
831 const wxDataViewItemAttr
*attr
,
834 RenderText(dc
, rect
, align
, m_text
, attr
, state
);
838 wxSize
wxDataViewTextRenderer::GetSize() const
840 const wxDataViewCtrl
*view
= GetView();
842 return view
->wxWindowBase::GetTextExtent( m_text
);
843 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
846 // ---------------------------------------------------------
847 // wxDataViewBitmapRenderer
848 // ---------------------------------------------------------
850 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
852 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
853 wxDataViewCellMode mode
, int align
) :
854 wxDataViewCustomRenderer( varianttype
, mode
, align
)
858 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
860 if (value
.GetType() == wxT("wxBitmap"))
862 if (value
.GetType() == wxT("wxIcon"))
868 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
873 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
876 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
877 else if (m_icon
.Ok())
878 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
883 wxSize
wxDataViewBitmapRenderer::GetSize() const
886 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
887 else if (m_icon
.Ok())
888 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
890 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
893 // ---------------------------------------------------------
894 // wxDataViewToggleRenderer
895 // ---------------------------------------------------------
897 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
899 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
900 wxDataViewCellMode mode
, int align
) :
901 wxDataViewCustomRenderer( varianttype
, mode
, align
)
906 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
908 m_toggle
= value
.GetBool();
913 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
918 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
922 flags
|= wxCONTROL_CHECKED
;
923 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
924 flags
|= wxCONTROL_DISABLED
;
926 wxRendererNative::Get().DrawCheckBox(
927 GetOwner()->GetOwner(),
935 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
936 wxDataViewModel
*model
,
937 const wxDataViewItem
& item
, unsigned int col
)
939 model
->ChangeValue(!m_toggle
, 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 m_model
->ChangeValue( event
.GetDate(), m_item
, m_col
);
1058 #endif // wxUSE_DATE_RENDERER_POPUP
1060 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1062 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1063 wxDataViewCellMode mode
, int align
) :
1064 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1068 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1070 m_date
= value
.GetDateTime();
1075 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1081 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1083 wxString tmp
= m_date
.FormatDate();
1084 RenderText( tmp
, 0, cell
, dc
, state
);
1088 wxSize
wxDataViewDateRenderer::GetSize() const
1090 const wxDataViewCtrl
* view
= GetView();
1091 wxString tmp
= m_date
.FormatDate();
1093 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1094 return wxSize(x
,y
+d
);
1097 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
1098 const wxDataViewItem
& item
, unsigned int col
)
1101 model
->GetValue( variant
, item
, col
);
1102 wxDateTime value
= variant
.GetDateTime();
1104 #if wxUSE_DATE_RENDERER_POPUP
1105 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1106 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1107 wxPoint pos
= wxGetMousePosition();
1110 popup
->Popup( popup
->m_cal
);
1111 #else // !wxUSE_DATE_RENDERER_POPUP
1112 wxMessageBox(value
.Format());
1113 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
1117 // ---------------------------------------------------------
1118 // wxDataViewIconTextRenderer
1119 // ---------------------------------------------------------
1121 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1123 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1124 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1125 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1128 SetAlignment(align
);
1131 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1137 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1143 wxDataViewIconTextRenderer::RenderWithAttr(wxDC
& dc
,
1146 const wxDataViewItemAttr
*attr
,
1151 const wxIcon
& icon
= m_value
.GetIcon();
1154 dc
.DrawIcon(icon
, rect
.x
, rect
.y
+ (rect
.height
- icon
.GetHeight())/2);
1155 xoffset
= icon
.GetWidth()+4;
1158 RenderText(dc
, rect
, align
, m_value
.GetText(), attr
, state
, xoffset
);
1163 wxSize
wxDataViewIconTextRenderer::GetSize() const
1165 const wxDataViewCtrl
*view
= GetView();
1166 if (!m_value
.GetText().empty())
1169 view
->GetTextExtent( m_value
.GetText(), &x
, &y
);
1171 if (m_value
.GetIcon().IsOk())
1172 x
+= m_value
.GetIcon().GetWidth() + 4;
1173 return wxSize( x
, y
);
1175 return wxSize(80,20);
1178 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1180 wxDataViewIconText iconText
;
1183 wxString text
= iconText
.GetText();
1185 // adjust the label rect to take the width of the icon into account
1186 if (iconText
.GetIcon().IsOk())
1188 int w
= iconText
.GetIcon().GetWidth() + 4;
1190 labelRect
.width
-= w
;
1193 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, text
,
1194 wxPoint(labelRect
.x
,labelRect
.y
),
1195 wxSize(labelRect
.width
,labelRect
.height
) );
1197 // select the text in the control an place the cursor at the end
1198 ctrl
->SetInsertionPointEnd();
1204 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
& value
)
1206 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
1208 wxDataViewIconText
iconText(text
->GetValue(), m_value
.GetIcon());
1213 //-----------------------------------------------------------------------------
1214 // wxDataViewDropTarget
1215 //-----------------------------------------------------------------------------
1217 #if wxUSE_DRAG_AND_DROP
1219 class wxBitmapCanvas
: public wxWindow
1222 wxBitmapCanvas( wxWindow
*parent
, const wxBitmap
&bitmap
, const wxSize
&size
) :
1223 wxWindow( parent
, wxID_ANY
, wxPoint(0,0), size
)
1226 Connect( wxEVT_PAINT
, wxPaintEventHandler(wxBitmapCanvas::OnPaint
) );
1229 void OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1232 dc
.DrawBitmap( m_bitmap
, 0, 0);
1238 class wxDataViewDropSource
: public wxDropSource
1241 wxDataViewDropSource( wxDataViewMainWindow
*win
, unsigned int row
) :
1249 ~wxDataViewDropSource()
1254 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
) )
1256 wxPoint pos
= wxGetMousePosition();
1260 int liney
= m_win
->GetLineStart( m_row
);
1262 m_win
->GetOwner()->CalcUnscrolledPosition( 0, liney
, NULL
, &liney
);
1263 m_win
->ClientToScreen( &linex
, &liney
);
1264 m_dist_x
= pos
.x
- linex
;
1265 m_dist_y
= pos
.y
- liney
;
1268 wxBitmap ib
= m_win
->CreateItemBitmap( m_row
, indent
);
1270 m_hint
= new wxFrame( m_win
->GetParent(), wxID_ANY
, wxEmptyString
,
1271 wxPoint(pos
.x
- m_dist_x
, pos
.y
+ 5 ),
1273 wxFRAME_TOOL_WINDOW
|
1274 wxFRAME_FLOAT_ON_PARENT
|
1275 wxFRAME_NO_TASKBAR
|
1277 new wxBitmapCanvas( m_hint
, ib
, ib
.GetSize() );
1282 m_hint
->Move( pos
.x
- m_dist_x
, pos
.y
+ 5 );
1283 m_hint
->SetTransparent( 128 );
1289 wxDataViewMainWindow
*m_win
;
1292 int m_dist_x
,m_dist_y
;
1296 class wxDataViewDropTarget
: public wxDropTarget
1299 wxDataViewDropTarget( wxDataObject
*obj
, wxDataViewMainWindow
*win
) :
1305 virtual wxDragResult
OnDragOver( wxCoord x
, wxCoord y
, wxDragResult def
)
1307 wxDataFormat format
= GetMatchingPair();
1308 if (format
== wxDF_INVALID
)
1310 return m_win
->OnDragOver( format
, x
, y
, def
);
1313 virtual bool OnDrop( wxCoord x
, wxCoord y
)
1315 wxDataFormat format
= GetMatchingPair();
1316 if (format
== wxDF_INVALID
)
1318 return m_win
->OnDrop( format
, x
, y
);
1321 virtual wxDragResult
OnData( wxCoord x
, wxCoord y
, wxDragResult def
)
1323 wxDataFormat format
= GetMatchingPair();
1324 if (format
== wxDF_INVALID
)
1328 return m_win
->OnData( format
, x
, y
, def
);
1331 virtual void OnLeave()
1332 { m_win
->OnLeave(); }
1334 wxDataViewMainWindow
*m_win
;
1337 #endif // wxUSE_DRAG_AND_DROP
1339 //-----------------------------------------------------------------------------
1340 // wxDataViewRenameTimer
1341 //-----------------------------------------------------------------------------
1343 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1348 void wxDataViewRenameTimer::Notify()
1350 m_owner
->OnRenameTimer();
1353 //-----------------------------------------------------------------------------
1354 // wxDataViewMainWindow
1355 //-----------------------------------------------------------------------------
1357 // The tree building helper, declared firstly
1358 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
1359 wxDataViewTreeNode
* node
);
1361 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1363 if (row1
> row2
) return 1;
1364 if (row1
== row2
) return 0;
1368 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1370 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1371 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1372 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1373 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1374 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1375 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1378 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1379 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1380 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
1381 m_selection( wxDataViewSelectionCmp
)
1386 m_lastOnSame
= false;
1387 m_renameTimer
= new wxDataViewRenameTimer( this );
1389 // TODO: user better initial values/nothing selected
1390 m_currentCol
= NULL
;
1393 m_lineHeight
= wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
1395 #if wxUSE_DRAG_AND_DROP
1397 m_dragStart
= wxPoint(0,0);
1399 m_dragEnabled
= false;
1400 m_dropEnabled
= false;
1402 m_dropHintLine
= (unsigned int) -1;
1403 #endif // wxUSE_DRAG_AND_DROP
1405 m_lineLastClicked
= (unsigned int) -1;
1406 m_lineBeforeLastClicked
= (unsigned int) -1;
1407 m_lineSelectSingleOnUp
= (unsigned int) -1;
1411 SetBackgroundColour( *wxWHITE
);
1413 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1415 m_penRule
= wxPen(GetRuleColour());
1417 // compose a pen whichcan draw black lines
1418 // TODO: maybe there is something system colour to use
1419 m_penExpander
= wxPen(wxColour(0,0,0));
1421 m_root
= new wxDataViewTreeNode( NULL
);
1422 m_root
->SetHasChildren(true);
1424 // Make m_count = -1 will cause the class recaculate the real displaying number of rows.
1426 m_underMouse
= NULL
;
1430 wxDataViewMainWindow::~wxDataViewMainWindow()
1433 delete m_renameTimer
;
1437 #if wxUSE_DRAG_AND_DROP
1438 bool wxDataViewMainWindow::EnableDragSource( const wxDataFormat
&format
)
1440 m_dragFormat
= format
;
1441 m_dragEnabled
= format
!= wxDF_INVALID
;
1446 bool wxDataViewMainWindow::EnableDropTarget( const wxDataFormat
&format
)
1448 m_dropFormat
= format
;
1449 m_dropEnabled
= format
!= wxDF_INVALID
;
1452 SetDropTarget( new wxDataViewDropTarget( new wxCustomDataObject( format
), this ) );
1457 void wxDataViewMainWindow::RemoveDropHint()
1462 RefreshRow( m_dropHintLine
);
1463 m_dropHintLine
= (unsigned int) -1;
1467 wxDragResult
wxDataViewMainWindow::OnDragOver( wxDataFormat format
, wxCoord x
,
1468 wxCoord y
, wxDragResult def
)
1472 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1473 unsigned int row
= GetLineAt( yy
);
1475 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1481 wxDataViewItem item
= GetItemByRow( row
);
1483 wxDataViewModel
*model
= GetOwner()->GetModel();
1485 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1486 event
.SetEventObject( m_owner
);
1487 event
.SetItem( item
);
1488 event
.SetModel( model
);
1489 event
.SetDataFormat( format
);
1490 if (!m_owner
->HandleWindowEvent( event
))
1496 if (!event
.IsAllowed())
1503 if (m_dropHint
&& (row
!= m_dropHintLine
))
1504 RefreshRow( m_dropHintLine
);
1506 m_dropHintLine
= row
;
1512 bool wxDataViewMainWindow::OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
)
1518 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1519 unsigned int row
= GetLineAt( yy
);
1521 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1524 wxDataViewItem item
= GetItemByRow( row
);
1526 wxDataViewModel
*model
= GetOwner()->GetModel();
1528 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1529 event
.SetEventObject( m_owner
);
1530 event
.SetItem( item
);
1531 event
.SetModel( model
);
1532 event
.SetDataFormat( format
);
1533 if (!m_owner
->HandleWindowEvent( event
))
1536 if (!event
.IsAllowed())
1542 wxDragResult
wxDataViewMainWindow::OnData( wxDataFormat format
, wxCoord x
, wxCoord y
,
1547 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1548 unsigned int row
= GetLineAt( yy
);
1550 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1553 wxDataViewItem item
= GetItemByRow( row
);
1555 wxDataViewModel
*model
= GetOwner()->GetModel();
1557 wxCustomDataObject
*obj
= (wxCustomDataObject
*) GetDropTarget()->GetDataObject();
1559 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
1560 event
.SetEventObject( m_owner
);
1561 event
.SetItem( item
);
1562 event
.SetModel( model
);
1563 event
.SetDataFormat( format
);
1564 event
.SetDataSize( obj
->GetSize() );
1565 event
.SetDataBuffer( obj
->GetData() );
1566 if (!m_owner
->HandleWindowEvent( event
))
1569 if (!event
.IsAllowed())
1575 void wxDataViewMainWindow::OnLeave()
1580 wxBitmap
wxDataViewMainWindow::CreateItemBitmap( unsigned int row
, int &indent
)
1582 int height
= GetLineHeight( row
);
1584 unsigned int cols
= GetOwner()->GetColumnCount();
1586 for (col
= 0; col
< cols
; col
++)
1588 wxDataViewColumn
*column
= GetOwner()->GetColumnAt(col
);
1589 if (column
->IsHidden())
1590 continue; // skip it!
1591 width
+= column
->GetWidth();
1595 if (!IsVirtualList())
1597 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
1598 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
1599 indent
= indent
+ m_lineHeight
;
1600 // try to use the m_lineHeight as the expander space
1602 if(!node
->HasChildren())
1607 wxBitmap
bitmap( width
, height
);
1608 wxMemoryDC
dc( bitmap
);
1609 dc
.SetFont( GetFont() );
1610 dc
.SetPen( *wxBLACK_PEN
);
1611 dc
.SetBrush( *wxWHITE_BRUSH
);
1612 dc
.DrawRectangle( 0,0,width
,height
);
1614 wxDataViewModel
*model
= m_owner
->GetModel();
1616 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1619 // TODO-RTL: last column for RTL support
1620 expander
= GetOwner()->GetColumnAt( 0 );
1621 GetOwner()->SetExpanderColumn(expander
);
1626 for (col
= 0; col
< cols
; col
++)
1628 wxDataViewColumn
*column
= GetOwner()->GetColumnAt( col
);
1629 wxDataViewRenderer
*cell
= column
->GetRenderer();
1631 if (column
->IsHidden())
1632 continue; // skip it!
1634 width
= column
->GetWidth();
1636 if (column
== expander
)
1640 wxDataViewItem item
= GetItemByRow( row
);
1641 model
->GetValue( value
, item
, column
->GetModelColumn());
1642 cell
->SetValue( value
);
1644 wxRect
item_rect(x
, 0, width
, height
);
1645 item_rect
.Deflate(PADDING_RIGHTLEFT
, 0);
1647 // dc.SetClippingRegion( item_rect );
1648 wxDataViewItemAttr attr
;
1650 hasAttr
= model
->GetAttr(item
, column
->GetModelColumn(), attr
);
1651 cell
->RenderWithAttr(dc
, item_rect
, cell
->CalculateAlignment(),
1652 hasAttr
? &attr
: NULL
, 0);
1653 // dc.DestroyClippingRegion();
1661 #endif // wxUSE_DRAG_AND_DROP
1664 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1666 wxDataViewModel
*model
= GetOwner()->GetModel();
1667 wxAutoBufferedPaintDC
dc( this );
1670 dc
.SetBrush(GetOwner()->GetBackgroundColour());
1671 dc
.SetPen( *wxTRANSPARENT_PEN
);
1672 dc
.DrawRectangle(GetClientSize());
1676 GetOwner()->PrepareDC( dc
);
1677 dc
.SetFont( GetFont() );
1679 wxRect update
= GetUpdateRegion().GetBox();
1680 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1682 // compute which items needs to be redrawn
1683 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
1684 unsigned int item_count
=
1685 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
1686 (int)(GetRowCount( ) - item_start
));
1687 unsigned int item_last
= item_start
+ item_count
;
1688 // Get the parent of DataViewCtrl
1689 wxWindow
*parent
= GetParent()->GetParent();
1690 wxDataViewEvent
cache_event(wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, parent
->GetId());
1691 cache_event
.SetEventObject(GetParent());
1692 cache_event
.SetCache(item_start
, item_last
- 1);
1693 parent
->ProcessWindowEvent(cache_event
);
1695 // compute which columns needs to be redrawn
1696 unsigned int cols
= GetOwner()->GetColumnCount();
1697 unsigned int col_start
= 0;
1698 unsigned int x_start
;
1699 for (x_start
= 0; col_start
< cols
; col_start
++)
1701 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_start
);
1702 if (col
->IsHidden())
1703 continue; // skip it!
1705 unsigned int w
= col
->GetWidth();
1706 if (x_start
+w
>= (unsigned int)update
.x
)
1712 unsigned int col_last
= col_start
;
1713 unsigned int x_last
= x_start
;
1714 for (; col_last
< cols
; col_last
++)
1716 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_last
);
1717 if (col
->IsHidden())
1718 continue; // skip it!
1720 if (x_last
> (unsigned int)update
.GetRight())
1723 x_last
+= col
->GetWidth();
1726 // Draw horizontal rules if required
1727 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1729 dc
.SetPen(m_penRule
);
1730 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1732 for (unsigned int i
= item_start
; i
<= item_last
; i
++)
1734 int y
= GetLineStart( i
);
1735 dc
.DrawLine(x_start
, y
, x_last
, y
);
1739 // Draw vertical rules if required
1740 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1742 dc
.SetPen(m_penRule
);
1743 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1746 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1748 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(i
);
1749 if (col
->IsHidden())
1750 continue; // skip it
1752 dc
.DrawLine(x
, GetLineStart( item_start
),
1753 x
, GetLineStart( item_last
) );
1755 x
+= col
->GetWidth();
1758 // Draw last vertical rule
1759 dc
.DrawLine(x
, GetLineStart( item_start
),
1760 x
, GetLineStart( item_last
) );
1763 // redraw the background for the items which are selected/current
1764 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1766 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1767 if (selected
|| item
== m_currentRow
)
1769 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
1770 if (item
== m_currentRow
)
1771 flags
|= wxCONTROL_CURRENT
;
1773 flags
|= wxCONTROL_FOCUSED
;
1775 wxRect
rect( x_start
, GetLineStart( item
), x_last
, GetLineHeight( item
) );
1776 wxRendererNative::Get().DrawItemSelectionRect
1786 #if wxUSE_DRAG_AND_DROP
1789 wxRect
rect( x_start
, GetLineStart( m_dropHintLine
),
1790 x_last
, GetLineHeight( m_dropHintLine
) );
1791 dc
.SetPen( *wxBLACK_PEN
);
1792 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1793 dc
.DrawRectangle( rect
);
1795 #endif // wxUSE_DRAG_AND_DROP
1797 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1800 // TODO-RTL: last column for RTL support
1801 expander
= GetOwner()->GetColumnAt( 0 );
1802 GetOwner()->SetExpanderColumn(expander
);
1805 // redraw all cells for all rows which must be repainted and all columns
1807 cell_rect
.x
= x_start
;
1808 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1810 wxDataViewColumn
*col
= GetOwner()->GetColumnAt( i
);
1811 wxDataViewRenderer
*cell
= col
->GetRenderer();
1812 cell_rect
.width
= col
->GetWidth();
1814 if (col
->IsHidden())
1815 continue; // skip it!
1817 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1819 // get the cell value and set it into the renderer
1821 wxDataViewTreeNode
*node
= NULL
;
1822 wxDataViewItem dataitem
;
1824 if (!IsVirtualList())
1826 node
= GetTreeNodeByRow(item
);
1830 dataitem
= node
->GetItem();
1832 if ((i
> 0) && model
->IsContainer(dataitem
) &&
1833 !model
->HasContainerColumns(dataitem
))
1838 dataitem
= wxDataViewItem( wxUIntToPtr(item
+1) );
1841 model
->GetValue( value
, dataitem
, col
->GetModelColumn());
1842 cell
->SetValue( value
);
1845 cell_rect
.y
= GetLineStart( item
);
1846 cell_rect
.height
= GetLineHeight( item
);
1848 // Draw the expander here.
1850 if ((!IsVirtualList()) && (col
== expander
))
1852 indent
= node
->GetIndentLevel();
1854 // Calculate the indent first
1855 indent
= cell_rect
.x
+ GetOwner()->GetIndent() * indent
;
1857 int expander_width
= m_lineHeight
- 2*EXPANDER_MARGIN
;
1859 // change the cell_rect.x to the appropriate pos
1860 int expander_x
= indent
+ EXPANDER_MARGIN
;
1861 int expander_y
= cell_rect
.y
+ EXPANDER_MARGIN
+ (GetLineHeight(item
) / 2)
1862 - (expander_width
/2) - EXPANDER_OFFSET
;
1864 indent
= indent
+ m_lineHeight
;
1865 // try to use the m_lineHeight as the expander space
1867 dc
.SetPen( m_penExpander
);
1868 dc
.SetBrush( wxNullBrush
);
1869 if( node
->HasChildren() )
1871 wxRect
rect( expander_x
, expander_y
, expander_width
, expander_width
);
1873 if (m_underMouse
== node
)
1875 flag
|= wxCONTROL_CURRENT
;
1877 if( node
->IsOpen() )
1878 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
,
1879 flag
|wxCONTROL_EXPANDED
);
1881 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
1884 // force the expander column to left-center align
1885 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
1887 if (node
&& !node
->HasChildren())
1889 // Yes, if the node does not have any child, it must be a leaf which
1890 // mean that it is a temporarily created by GetTreeNodeByRow
1894 wxRect item_rect
= cell_rect
;
1895 item_rect
.Deflate(PADDING_RIGHTLEFT
, 0);
1897 // account for the tree indent (harmless if we're not indented)
1898 item_rect
.x
+= indent
;
1899 item_rect
.width
-= indent
;
1902 if (m_hasFocus
&& (m_selection
.Index(item
) != wxNOT_FOUND
))
1903 state
|= wxDATAVIEW_CELL_SELECTED
;
1905 // TODO: it would be much more efficient to create a clipping
1906 // region for the entire column being rendered (in the OnPaint
1907 // of wxDataViewMainWindow) instead of a single clip region for
1908 // each cell. However it would mean that each renderer should
1909 // respect the given wxRect's top & bottom coords, eventually
1910 // violating only the left & right coords - however the user can
1911 // make its own renderer and thus we cannot be sure of that.
1912 wxDCClipper
clip(dc
, item_rect
);
1914 wxDataViewItemAttr attr
;
1916 hasAttr
= model
->GetAttr(dataitem
, col
->GetModelColumn(), attr
);
1917 cell
->RenderWithAttr(dc
, item_rect
, cell
->CalculateAlignment(),
1918 hasAttr
? &attr
: NULL
, state
);
1921 cell_rect
.x
+= cell_rect
.width
;
1925 void wxDataViewMainWindow::OnRenameTimer()
1927 // We have to call this here because changes may just have
1928 // been made and no screen update taken place.
1931 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
1932 // (needs to be tested!)
1936 wxDataViewItem item
= GetItemByRow( m_currentRow
);
1938 wxRect labelRect
= GetItemRect(item
, m_currentCol
);
1940 m_currentCol
->GetRenderer()->StartEditing( item
, labelRect
);
1943 //-----------------------------------------------------------------------------
1944 // Helper class for do operation on the tree node
1945 //-----------------------------------------------------------------------------
1950 virtual ~DoJob() { }
1952 // The return value control how the tree-walker tranverse the tree
1953 // 0: Job done, stop tranverse and return
1954 // 1: Ignore the current node's subtree and continue
1955 // 2: Job not done, continue
1956 enum { OK
= 0 , IGR
= 1, CONT
= 2 };
1957 virtual int operator() ( wxDataViewTreeNode
* node
) = 0;
1958 virtual int operator() ( void * n
) = 0;
1961 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
1966 switch( func( node
) )
1977 wxDataViewTreeNodes nodes
= node
->GetNodes();
1978 wxDataViewTreeLeaves leaves
= node
->GetChildren();
1980 int len_nodes
= nodes
.GetCount();
1981 int len
= leaves
.GetCount();
1982 int i
= 0, nodes_i
= 0;
1984 for(; i
< len
; i
++ )
1986 void * n
= leaves
[i
];
1987 if( nodes_i
< len_nodes
&& n
== nodes
[nodes_i
]->GetItem().GetID() )
1989 wxDataViewTreeNode
* nd
= nodes
[nodes_i
];
1992 if( Walker( nd
, func
) )
2011 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
2013 if (IsVirtualList())
2015 wxDataViewVirtualListModel
*list_model
=
2016 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
2017 m_count
= list_model
->GetCount();
2024 wxDataViewTreeNode
* node
;
2025 node
= FindNode(parent
);
2030 node
->SetHasChildren( true );
2032 if( g_model
->IsContainer( item
) )
2034 wxDataViewTreeNode
* newnode
= new wxDataViewTreeNode( node
);
2035 newnode
->SetItem(item
);
2036 newnode
->SetHasChildren( true );
2037 node
->AddNode( newnode
);
2040 node
->AddLeaf( item
.GetID() );
2042 node
->ChangeSubTreeCount(1);
2050 static void DestroyTreeHelper( wxDataViewTreeNode
* node
);
2052 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
2053 const wxDataViewItem
& item
)
2055 if (IsVirtualList())
2057 wxDataViewVirtualListModel
*list_model
=
2058 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
2059 m_count
= list_model
->GetCount();
2061 if( m_currentRow
> GetRowCount() )
2062 m_currentRow
= m_count
- 1;
2064 // TODO: why empty the entire selection?
2065 m_selection
.Empty();
2072 wxDataViewTreeNode
* node
= FindNode(parent
);
2074 wxCHECK_MSG( node
!= NULL
, false, "item not found" );
2075 wxCHECK_MSG( node
->GetChildren().Index( item
.GetID() ) != wxNOT_FOUND
,
2076 false, "item not found" );
2079 node
->GetChildren().Remove( item
.GetID() );
2080 // Manipolate selection
2081 if( m_selection
.GetCount() > 1 )
2083 m_selection
.Empty();
2085 bool isContainer
= false;
2086 wxDataViewTreeNodes nds
= node
->GetNodes();
2087 for (size_t i
= 0; i
< nds
.GetCount(); i
++)
2089 if (nds
[i
]->GetItem() == item
)
2097 wxDataViewTreeNode
* n
= NULL
;
2098 wxDataViewTreeNodes nodes
= node
->GetNodes();
2099 int len
= nodes
.GetCount();
2100 for( int i
= 0; i
< len
; i
++)
2102 if( nodes
[i
]->GetItem() == item
)
2109 wxCHECK_MSG( n
!= NULL
, false, "item not found" );
2111 node
->GetNodes().Remove( n
);
2112 sub
-= n
->GetSubTreeCount();
2113 ::DestroyTreeHelper(n
);
2115 // Make the row number invalid and get a new valid one when user call GetRowCount
2117 node
->ChangeSubTreeCount(sub
);
2119 // Change the current row to the last row if the current exceed the max row number
2120 if( m_currentRow
> GetRowCount() )
2121 m_currentRow
= m_count
- 1;
2128 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
2134 wxWindow
*parent
= GetParent();
2135 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2136 le
.SetEventObject(parent
);
2137 le
.SetModel(GetOwner()->GetModel());
2139 parent
->GetEventHandler()->ProcessEvent(le
);
2144 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
2146 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
2147 /*#define MAX_VIRTUAL_WIDTH 100000
2149 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
2150 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2151 Refresh( true, &rect );
2159 wxWindow
*parent
= GetParent();
2160 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2161 le
.SetEventObject(parent
);
2162 le
.SetModel(GetOwner()->GetModel());
2165 le
.SetDataViewColumn(GetOwner()->GetColumn(col
));
2166 parent
->GetEventHandler()->ProcessEvent(le
);
2171 bool wxDataViewMainWindow::Cleared()
2176 BuildTree( GetOwner()->GetModel() );
2183 void wxDataViewMainWindow::UpdateDisplay()
2188 void wxDataViewMainWindow::OnInternalIdle()
2190 wxWindow::OnInternalIdle();
2194 RecalculateDisplay();
2199 void wxDataViewMainWindow::RecalculateDisplay()
2201 wxDataViewModel
*model
= GetOwner()->GetModel();
2208 int width
= GetEndOfLastCol();
2209 int height
= GetLineStart( GetRowCount() );
2211 SetVirtualSize( width
, height
);
2212 GetOwner()->SetScrollRate( 10, m_lineHeight
);
2217 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2219 wxWindow::ScrollWindow( dx
, dy
, rect
);
2221 if (GetOwner()->m_headerArea
)
2222 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
2225 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
2228 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
2229 int sy
= GetLineStart( rows
)/y
;
2233 wxRect rect
= GetClientRect();
2237 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
2238 for (x_start
= 0; colnum
< column
; colnum
++)
2240 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(colnum
);
2241 if (col
->IsHidden())
2242 continue; // skip it!
2244 w
= col
->GetWidth();
2248 int x_end
= x_start
+ w
;
2249 xe
= xx
+ rect
.width
;
2252 sx
= ( xx
+ x_end
- xe
)/x
;
2259 m_owner
->Scroll( sx
, sy
);
2262 int wxDataViewMainWindow::GetCountPerPage() const
2264 wxSize size
= GetClientSize();
2265 return size
.y
/ m_lineHeight
;
2268 int wxDataViewMainWindow::GetEndOfLastCol() const
2272 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2274 const wxDataViewColumn
*c
=
2275 const_cast<wxDataViewCtrl
*>(GetOwner())->GetColumnAt( i
);
2278 width
+= c
->GetWidth();
2283 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2287 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2289 return GetLineAt( y
);
2292 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
2294 wxSize client_size
= GetClientSize();
2295 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2296 &client_size
.x
, &client_size
.y
);
2298 // we should deal with the pixel here
2299 unsigned int row
= GetLineAt(client_size
.y
) - 1;
2301 return wxMin( GetRowCount()-1, row
);
2304 unsigned int wxDataViewMainWindow::GetRowCount()
2306 if ( m_count
== -1 )
2308 m_count
= RecalculateCount();
2314 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
2321 void wxDataViewMainWindow::SelectAllRows( bool on
)
2328 m_selection
.Clear();
2329 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2330 m_selection
.Add( i
);
2335 unsigned int first_visible
= GetFirstVisibleRow();
2336 unsigned int last_visible
= GetLastVisibleRow();
2338 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2340 unsigned int row
= m_selection
[i
];
2341 if ((row
>= first_visible
) && (row
<= last_visible
))
2344 m_selection
.Clear();
2348 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
2350 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2354 m_selection
.Add( row
);
2362 m_selection
.Remove( row
);
2368 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2372 unsigned int tmp
= from
;
2378 for (i
= from
; i
<= to
; i
++)
2380 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2383 m_selection
.Add( i
);
2388 m_selection
.Remove( i
);
2391 RefreshRows( from
, to
);
2394 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2396 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2398 int n
= aSelections
[i
];
2400 m_selection
.Add( n
);
2405 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2407 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2408 m_selection
.Add( row
);
2410 m_selection
.Remove( row
);
2414 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2416 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2419 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
2421 wxWindow
*parent
= GetParent();
2422 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
2424 le
.SetEventObject(parent
);
2425 le
.SetModel(GetOwner()->GetModel());
2428 parent
->GetEventHandler()->ProcessEvent(le
);
2431 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2433 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
2434 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2436 wxSize client_size
= GetClientSize();
2437 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2438 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2439 if (intersect_rect
.width
> 0)
2440 Refresh( true, &intersect_rect
);
2443 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2447 unsigned int tmp
= to
;
2452 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
2453 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2455 wxSize client_size
= GetClientSize();
2456 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2457 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2458 if (intersect_rect
.width
> 0)
2459 Refresh( true, &intersect_rect
);
2462 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2464 wxSize client_size
= GetClientSize();
2465 int start
= GetLineStart( firstRow
);
2466 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
2467 if (start
> client_size
.y
) return;
2469 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
2471 Refresh( true, &rect
);
2474 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2476 wxCHECK_RET( newCurrent
< GetRowCount(),
2477 wxT("invalid item index in OnArrowChar()") );
2479 // if there is no selection, we cannot move it anywhere
2480 if (!HasCurrentRow())
2483 unsigned int oldCurrent
= m_currentRow
;
2485 // in single selection we just ignore Shift as we can't select several
2487 if ( event
.ShiftDown() && !IsSingleSel() )
2489 RefreshRow( oldCurrent
);
2491 ChangeCurrentRow( newCurrent
);
2493 // select all the items between the old and the new one
2494 if ( oldCurrent
> newCurrent
)
2496 newCurrent
= oldCurrent
;
2497 oldCurrent
= m_currentRow
;
2500 SelectRows( oldCurrent
, newCurrent
, true );
2501 if (oldCurrent
!=newCurrent
)
2502 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
2506 RefreshRow( oldCurrent
);
2508 // all previously selected items are unselected unless ctrl is held
2509 if ( !event
.ControlDown() )
2510 SelectAllRows(false);
2512 ChangeCurrentRow( newCurrent
);
2514 if ( !event
.ControlDown() )
2516 SelectRow( m_currentRow
, true );
2517 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
2520 RefreshRow( m_currentRow
);
2523 GetOwner()->EnsureVisible( m_currentRow
, -1 );
2526 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2530 rect
.y
= GetLineStart( row
);
2531 rect
.width
= GetEndOfLastCol();
2532 rect
.height
= GetLineHeight( row
);
2537 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2539 const wxDataViewModel
*model
= GetOwner()->GetModel();
2541 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2543 // TODO make more efficient
2548 for (r
= 0; r
< row
; r
++)
2550 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2551 if (!node
) return start
;
2553 wxDataViewItem item
= node
->GetItem();
2555 if (node
&& !node
->HasChildren())
2557 // Yes, if the node does not have any child, it must be a leaf which
2558 // mean that it is a temporarily created by GetTreeNodeByRow
2562 unsigned int cols
= GetOwner()->GetColumnCount();
2564 int height
= m_lineHeight
;
2565 for (col
= 0; col
< cols
; col
++)
2567 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2568 if (column
->IsHidden())
2569 continue; // skip it!
2572 model
->IsContainer(item
) &&
2573 !model
->HasContainerColumns(item
))
2574 continue; // skip it!
2577 model
->GetValue( value
, item
, column
->GetModelColumn() );
2579 wxDataViewRenderer
*renderer
=
2580 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2581 renderer
->SetValue( value
);
2582 height
= wxMax( height
, renderer
->GetSize().y
);
2592 return row
* m_lineHeight
;
2596 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
2598 const wxDataViewModel
*model
= GetOwner()->GetModel();
2600 // check for the easy case first
2601 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
2602 return y
/ m_lineHeight
;
2604 // TODO make more efficient
2605 unsigned int row
= 0;
2606 unsigned int yy
= 0;
2609 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2612 // not really correct...
2613 return row
+ ((y
-yy
) / m_lineHeight
);
2616 wxDataViewItem item
= node
->GetItem();
2618 if (node
&& !node
->HasChildren())
2620 // Yes, if the node does not have any child, it must be a leaf which
2621 // mean that it is a temporarily created by GetTreeNodeByRow
2625 unsigned int cols
= GetOwner()->GetColumnCount();
2627 int height
= m_lineHeight
;
2628 for (col
= 0; col
< cols
; col
++)
2630 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2631 if (column
->IsHidden())
2632 continue; // skip it!
2635 model
->IsContainer(item
) &&
2636 !model
->HasContainerColumns(item
))
2637 continue; // skip it!
2640 model
->GetValue( value
, item
, column
->GetModelColumn() );
2642 wxDataViewRenderer
*renderer
=
2643 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2644 renderer
->SetValue( value
);
2645 height
= wxMax( height
, renderer
->GetSize().y
);
2656 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
2658 const wxDataViewModel
*model
= GetOwner()->GetModel();
2660 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2662 wxASSERT( !IsVirtualList() );
2664 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2665 // wxASSERT( node );
2666 if (!node
) return m_lineHeight
;
2668 wxDataViewItem item
= node
->GetItem();
2670 if (node
&& !node
->HasChildren())
2672 // Yes, if the node does not have any child, it must be a leaf which
2673 // mean that it is a temporarily created by GetTreeNodeByRow
2677 int height
= m_lineHeight
;
2679 unsigned int cols
= GetOwner()->GetColumnCount();
2681 for (col
= 0; col
< cols
; col
++)
2683 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2684 if (column
->IsHidden())
2685 continue; // skip it!
2688 model
->IsContainer(item
) &&
2689 !model
->HasContainerColumns(item
))
2690 continue; // skip it!
2693 model
->GetValue( value
, item
, column
->GetModelColumn() );
2695 wxDataViewRenderer
*renderer
=
2696 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2697 renderer
->SetValue( value
);
2698 height
= wxMax( height
, renderer
->GetSize().y
);
2705 return m_lineHeight
;
2709 class RowToItemJob
: public DoJob
2712 RowToItemJob( unsigned int row
, int current
)
2713 { this->row
= row
; this->current
= current
; }
2714 virtual ~RowToItemJob() {}
2716 virtual int operator() ( wxDataViewTreeNode
* node
)
2719 if( current
== static_cast<int>(row
))
2721 ret
= node
->GetItem();
2725 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2727 current
+= node
->GetSubTreeCount();
2732 // If the current has no child node, we can find the desired item of the row
2734 // This if can speed up finding in some case, and will has a very good effect
2735 // when it comes to list view
2736 if( node
->GetNodes().GetCount() == 0)
2738 int index
= static_cast<int>(row
) - current
- 1;
2739 ret
= node
->GetChildren().Item( index
);
2746 virtual int operator() ( void * n
)
2749 if( current
== static_cast<int>(row
))
2751 ret
= wxDataViewItem( n
);
2757 wxDataViewItem
GetResult() const
2766 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
2768 if (IsVirtualList())
2770 return wxDataViewItem( wxUIntToPtr(row
+1) );
2774 RowToItemJob
job( row
, -2 );
2775 Walker( m_root
, job
);
2776 return job
.GetResult();
2780 class RowToTreeNodeJob
: public DoJob
2783 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
2786 this->current
= current
;
2790 virtual ~RowToTreeNodeJob(){ }
2792 virtual int operator() ( wxDataViewTreeNode
* node
)
2795 if( current
== static_cast<int>(row
))
2801 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2803 current
+= node
->GetSubTreeCount();
2810 // If the current node has no children, we can find the desired item of the
2811 // row number directly.
2812 // This if can speed up finding in some case, and will have a very good
2813 // effect for list views.
2814 if( node
->GetNodes().GetCount() == 0)
2816 int index
= static_cast<int>(row
) - current
- 1;
2817 void * n
= node
->GetChildren().Item( index
);
2818 ret
= new wxDataViewTreeNode( parent
);
2819 ret
->SetItem( wxDataViewItem( n
));
2820 ret
->SetHasChildren(false);
2827 virtual int operator() ( void * n
)
2830 if( current
== static_cast<int>(row
))
2832 ret
= new wxDataViewTreeNode( parent
);
2833 ret
->SetItem( wxDataViewItem( n
));
2834 ret
->SetHasChildren(false);
2841 wxDataViewTreeNode
* GetResult() const
2847 wxDataViewTreeNode
* ret
;
2848 wxDataViewTreeNode
* parent
;
2851 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
2853 wxASSERT( !IsVirtualList() );
2855 RowToTreeNodeJob
job( row
, -2, m_root
);
2856 Walker( m_root
, job
);
2857 return job
.GetResult();
2860 wxDataViewEvent
wxDataViewMainWindow::SendExpanderEvent( wxEventType type
,
2861 const wxDataViewItem
& item
)
2863 wxWindow
*parent
= GetParent();
2864 wxDataViewEvent
le(type
, parent
->GetId());
2866 le
.SetEventObject(parent
);
2867 le
.SetModel(GetOwner()->GetModel());
2870 parent
->GetEventHandler()->ProcessEvent(le
);
2874 bool wxDataViewMainWindow::IsExpanded( unsigned int row
) const
2876 if (IsVirtualList())
2879 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2883 if (!node
->HasChildren())
2889 return node
->IsOpen();
2892 bool wxDataViewMainWindow::HasChildren( unsigned int row
) const
2894 if (IsVirtualList())
2897 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2901 if (!node
->HasChildren())
2910 void wxDataViewMainWindow::Expand( unsigned int row
)
2912 if (IsVirtualList())
2915 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2919 if (!node
->HasChildren())
2925 if (!node
->IsOpen())
2928 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, node
->GetItem());
2930 // Check if the user prevent expanding
2931 if( e
.GetSkipped() )
2936 // build the children of current node
2937 if( node
->GetChildrenNumber() == 0 )
2940 ::BuildTreeHelper(GetOwner()->GetModel(), node
->GetItem(), node
);
2943 // By expanding the node all row indices that are currently in the selection list
2944 // and are greater than our node have become invalid. So we have to correct that now.
2945 const unsigned rowAdjustment
= node
->GetSubTreeCount();
2946 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2948 const unsigned testRow
= m_selection
[i
];
2949 // all rows above us are not affected, so skip them
2953 m_selection
[i
] += rowAdjustment
;
2956 if(m_currentRow
> row
)
2957 ChangeCurrentRow(m_currentRow
+ rowAdjustment
);
2961 // Send the expanded event
2962 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
2966 void wxDataViewMainWindow::Collapse(unsigned int row
)
2968 if (IsVirtualList())
2971 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
2975 if (!node
->HasChildren())
2984 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem());
2985 if( e
.GetSkipped() )
2988 // Find out if there are selected items below the current node.
2989 bool selectCollapsingRow
= false;
2990 const unsigned rowAdjustment
= node
->GetSubTreeCount();
2991 unsigned maxRowToBeTested
= row
+ rowAdjustment
;
2992 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2994 const unsigned testRow
= m_selection
[i
];
2995 if(testRow
> row
&& testRow
<= maxRowToBeTested
)
2997 selectCollapsingRow
= true;
2998 // get out as soon as we have found a node that is selected
3005 // If the node to be closed has selected items the user won't see those any longer.
3006 // We select the collapsing node in this case.
3007 if(selectCollapsingRow
)
3009 SelectAllRows(false);
3010 ChangeCurrentRow(row
);
3011 SelectRow(row
, true);
3012 SendSelectionChangedEvent(GetItemByRow(row
));
3016 // if there were no selected items below our node we still need to "fix" the
3017 // selection list to adjust for the changing of the row indices.
3018 // We actually do the opposite of what we are doing in Expand().
3019 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3021 const unsigned testRow
= m_selection
[i
];
3022 // all rows above us are not affected, so skip them
3026 m_selection
[i
] -= rowAdjustment
;
3029 // if the "current row" is being collapsed away we change it to the current row ;-)
3030 if(m_currentRow
> row
&& m_currentRow
<= maxRowToBeTested
)
3031 ChangeCurrentRow(row
);
3032 else if(m_currentRow
> row
)
3033 ChangeCurrentRow(m_currentRow
- rowAdjustment
);
3038 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,node
->GetItem());
3042 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
3044 wxDataViewModel
* model
= GetOwner()->GetModel();
3051 // Compose the a parent-chain of the finding item
3053 list
.DeleteContents( true );
3054 wxDataViewItem
it( item
);
3057 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3058 list
.Insert( pItem
);
3059 it
= model
->GetParent( it
);
3062 // Find the item along the parent-chain.
3063 // This algorithm is designed to speed up the node-finding method
3064 wxDataViewTreeNode
* node
= m_root
;
3065 for( ItemList::const_iterator iter
= list
.begin(); iter
!=list
.end(); iter
++ )
3067 if( node
->HasChildren() )
3069 if( node
->GetChildrenNumber() == 0 )
3072 ::BuildTreeHelper(model
, node
->GetItem(), node
);
3075 wxDataViewTreeNodes nodes
= node
->GetNodes();
3079 for (i
= 0; i
< nodes
.GetCount(); i
++)
3081 if (nodes
[i
]->GetItem() == (**iter
))
3083 if (nodes
[i
]->GetItem() == item
)
3100 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
3101 wxDataViewColumn
* &column
)
3103 wxDataViewColumn
*col
= NULL
;
3104 unsigned int cols
= GetOwner()->GetColumnCount();
3105 unsigned int colnum
= 0;
3107 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
3108 for (unsigned x_start
= 0; colnum
< cols
; colnum
++)
3110 col
= GetOwner()->GetColumnAt(colnum
);
3111 if (col
->IsHidden())
3112 continue; // skip it!
3114 unsigned int w
= col
->GetWidth();
3115 if (x_start
+w
>= (unsigned int)x
)
3122 item
= GetItemByRow( GetLineAt( y
) );
3125 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
,
3126 const wxDataViewColumn
* column
)
3131 unsigned int cols
= GetOwner()->GetColumnCount();
3132 // If column is null the loop will compute the combined width of all columns.
3133 // Otherwise, it will compute the x position of the column we are looking for.
3134 for (unsigned int i
= 0; i
< cols
; i
++)
3136 wxDataViewColumn
* col
= GetOwner()->GetColumnAt( i
);
3141 if (col
->IsHidden())
3142 continue; // skip it!
3144 xpos
+= col
->GetWidth();
3145 width
+= col
->GetWidth();
3150 // If we have a column, we need can get its width directly.
3151 if(column
->IsHidden())
3154 width
= column
->GetWidth();
3159 // If we have no column, we reset the x position back to zero.
3163 // we have to take an expander column into account and compute its indentation
3164 // to get the correct x position where the actual text is
3166 int row
= GetRowByItem(item
);
3167 if (!IsVirtualList() && (column
== 0 || GetOwner()->GetExpanderColumn() == column
) )
3169 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3170 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
3171 indent
= indent
+ m_lineHeight
; // use m_lineHeight as the width of the expander
3173 if(!node
->HasChildren())
3177 wxRect
itemRect( xpos
+ indent
,
3178 GetLineStart( row
),
3180 GetLineHeight( row
) );
3182 GetOwner()->CalcScrolledPosition( itemRect
.x
, itemRect
.y
,
3183 &itemRect
.x
, &itemRect
.y
);
3188 int wxDataViewMainWindow::RecalculateCount()
3190 if (IsVirtualList())
3192 wxDataViewVirtualListModel
*list_model
=
3193 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
3195 return list_model
->GetCount();
3199 return m_root
->GetSubTreeCount();
3203 class ItemToRowJob
: public DoJob
3206 ItemToRowJob(const wxDataViewItem
& item_
, ItemList::const_iterator iter
)
3213 // Maybe binary search will help to speed up this process
3214 virtual int operator() ( wxDataViewTreeNode
* node
)
3217 if( node
->GetItem() == item
)
3222 if( node
->GetItem() == **m_iter
)
3229 ret
+= node
->GetSubTreeCount();
3235 virtual int operator() ( void * n
)
3238 if( n
== item
.GetID() )
3243 // the row number is begin from zero
3244 int GetResult() const
3248 ItemList::const_iterator m_iter
;
3249 wxDataViewItem item
;
3254 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
3256 const wxDataViewModel
* model
= GetOwner()->GetModel();
3260 if (IsVirtualList())
3262 return wxPtrToUInt( item
.GetID() ) -1;
3269 // Compose the a parent-chain of the finding item
3271 wxDataViewItem
* pItem
;
3272 list
.DeleteContents( true );
3273 wxDataViewItem
it( item
);
3276 pItem
= new wxDataViewItem( it
);
3277 list
.Insert( pItem
);
3278 it
= model
->GetParent( it
);
3280 pItem
= new wxDataViewItem( );
3281 list
.Insert( pItem
);
3283 ItemToRowJob
job( item
, list
.begin() );
3284 Walker(m_root
, job
);
3285 return job
.GetResult();
3289 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
3290 wxDataViewTreeNode
* node
)
3292 if( !model
->IsContainer( item
) )
3295 wxDataViewItemArray children
;
3296 unsigned int num
= model
->GetChildren( item
, children
);
3298 unsigned int index
= 0;
3299 while( index
< num
)
3301 if( model
->IsContainer( children
[index
] ) )
3303 wxDataViewTreeNode
* n
= new wxDataViewTreeNode( node
);
3304 n
->SetItem(children
[index
]);
3305 n
->SetHasChildren( true );
3310 node
->AddLeaf( children
[index
].GetID() );
3314 node
->SetSubTreeCount( num
);
3315 wxDataViewTreeNode
* n
= node
->GetParent();
3317 n
->ChangeSubTreeCount(num
);
3321 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
3325 if (GetOwner()->GetModel()->IsVirtualListModel())
3331 m_root
= new wxDataViewTreeNode( NULL
);
3332 m_root
->SetHasChildren(true);
3334 // First we define a invalid item to fetch the top-level elements
3335 wxDataViewItem item
;
3337 BuildTreeHelper( model
, item
, m_root
);
3341 static void DestroyTreeHelper( wxDataViewTreeNode
* node
)
3343 if( node
->GetNodeNumber() != 0 )
3345 int len
= node
->GetNodeNumber();
3346 wxDataViewTreeNodes
& nodes
= node
->GetNodes();
3347 for (int i
= 0; i
< len
; i
++)
3348 DestroyTreeHelper(nodes
[i
]);
3353 void wxDataViewMainWindow::DestroyTree()
3355 if (!IsVirtualList())
3357 ::DestroyTreeHelper(m_root
);
3363 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
3365 if ( GetParent()->HandleAsNavigationKey(event
) )
3368 // no item -> nothing to do
3369 if (!HasCurrentRow())
3375 // don't use m_linesPerPage directly as it might not be computed yet
3376 const int pageSize
= GetCountPerPage();
3377 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
3379 switch ( event
.GetKeyCode() )
3383 wxWindow
*parent
= GetParent();
3384 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
,
3386 le
.SetItem( GetItemByRow(m_currentRow
) );
3387 le
.SetEventObject(parent
);
3388 le
.SetModel(GetOwner()->GetModel());
3390 parent
->GetEventHandler()->ProcessEvent(le
);
3395 if ( m_currentRow
> 0 )
3396 OnArrowChar( m_currentRow
- 1, event
);
3400 if ( m_currentRow
< GetRowCount() - 1 )
3401 OnArrowChar( m_currentRow
+ 1, event
);
3403 // Add the process for tree expanding/collapsing
3406 if (IsVirtualList())
3409 wxDataViewTreeNode
* node
= GetTreeNodeByRow(m_currentRow
);
3413 if (node
->HasChildren() && node
->IsOpen())
3415 Collapse(m_currentRow
);
3417 else // if the node is already closed we move the selection to its parent
3419 wxDataViewTreeNode
*parent_node
= node
->GetParent();
3421 if(!node
->HasChildren())
3426 int parent
= GetRowByItem( parent_node
->GetItem() );
3429 unsigned int row
= m_currentRow
;
3430 SelectRow( row
, false);
3431 SelectRow( parent
, true );
3432 ChangeCurrentRow( parent
);
3433 GetOwner()->EnsureVisible( parent
, -1 );
3434 SendSelectionChangedEvent( parent_node
->GetItem() );
3442 if (!IsExpanded( m_currentRow
))
3443 Expand( m_currentRow
);
3446 unsigned int row
= m_currentRow
;
3447 SelectRow( row
, false );
3448 SelectRow( row
+ 1, true );
3449 ChangeCurrentRow( row
+ 1 );
3450 GetOwner()->EnsureVisible( row
+ 1, -1 );
3451 SendSelectionChangedEvent( GetItemByRow(row
+1) );
3458 OnArrowChar( GetRowCount() - 1, event
);
3463 OnArrowChar( 0, event
);
3468 int steps
= pageSize
- 1;
3469 int index
= m_currentRow
- steps
;
3473 OnArrowChar( index
, event
);
3479 int steps
= pageSize
- 1;
3480 unsigned int index
= m_currentRow
+ steps
;
3481 unsigned int count
= GetRowCount();
3482 if ( index
>= count
)
3485 OnArrowChar( index
, event
);
3491 if(m_selection
.size() == 1)
3493 // TODO: we need to revise that when we have a concept for a 'current column'
3494 GetOwner()->StartEditor(GetItemByRow(m_selection
[0]), 0);
3504 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
3506 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3508 // let the base handle mouse wheel events.
3513 int x
= event
.GetX();
3514 int y
= event
.GetY();
3515 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
3516 wxDataViewColumn
*col
= NULL
;
3519 unsigned int cols
= GetOwner()->GetColumnCount();
3521 for (i
= 0; i
< cols
; i
++)
3523 wxDataViewColumn
*c
= GetOwner()->GetColumnAt( i
);
3525 continue; // skip it!
3527 if (x
< xpos
+ c
->GetWidth())
3532 xpos
+= c
->GetWidth();
3537 wxDataViewRenderer
*cell
= col
->GetRenderer();
3538 unsigned int current
= GetLineAt( y
);
3539 if ((current
>= GetRowCount()) || (x
> GetEndOfLastCol()))
3541 // Unselect all if below the last row ?
3545 // Test whether the mouse is hovered on the tree item button
3546 bool hoverOverExpander
= false;
3547 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
3549 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3550 if( node
!=NULL
&& node
->HasChildren() )
3552 int indent
= node
->GetIndentLevel();
3553 indent
= GetOwner()->GetIndent()*indent
;
3555 // we make the rectangle we are looking in a bit bigger than the actual
3556 // visual expander so the user can hit that little thing reliably
3557 wxRect
rect( xpos
+ indent
,
3558 GetLineStart( current
) + (GetLineHeight(current
) - m_lineHeight
)/2,
3559 m_lineHeight
, m_lineHeight
);
3560 if( rect
.Contains(x
, y
) )
3562 // So the mouse is over the expander
3563 hoverOverExpander
= true;
3564 if (m_underMouse
&& m_underMouse
!= node
)
3566 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3567 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3569 if (m_underMouse
!= node
)
3571 // wxLogMessage("Do the row: %d", current);
3572 RefreshRow(current
);
3574 m_underMouse
= node
;
3577 if (node
!=NULL
&& !node
->HasChildren())
3580 if (!hoverOverExpander
)
3582 if (m_underMouse
!= NULL
)
3584 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3585 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3586 m_underMouse
= NULL
;
3590 wxDataViewModel
*model
= GetOwner()->GetModel();
3592 #if wxUSE_DRAG_AND_DROP
3593 if (event
.Dragging())
3595 if (m_dragCount
== 0)
3597 // we have to report the raw, physical coords as we want to be
3598 // able to call HitTest(event.m_pointDrag) from the user code to
3599 // get the item being dragged
3600 m_dragStart
= event
.GetPosition();
3605 if (m_dragCount
!= 3)
3608 if (event
.LeftIsDown())
3610 m_owner
->CalcUnscrolledPosition( m_dragStart
.x
, m_dragStart
.y
,
3611 &m_dragStart
.x
, &m_dragStart
.y
);
3612 unsigned int drag_item_row
= GetLineAt( m_dragStart
.y
);
3613 wxDataViewItem item
= GetItemByRow( drag_item_row
);
3615 // Notify cell about drag
3616 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3617 event
.SetEventObject( m_owner
);
3618 event
.SetItem( item
);
3619 event
.SetModel( model
);
3620 if (!m_owner
->HandleWindowEvent( event
))
3623 if (!event
.IsAllowed())
3626 wxDataObject
*obj
= event
.GetDataObject();
3630 wxDataViewDropSource
drag( this, drag_item_row
);
3631 drag
.SetData( *obj
);
3632 /* wxDragResult res = */ drag
.DoDragDrop();
3641 #endif // wxUSE_DRAG_AND_DROP
3643 bool simulateClick
= false;
3645 if (event
.ButtonDClick())
3647 m_renameTimer
->Stop();
3648 m_lastOnSame
= false;
3651 wxDataViewItem item
= GetItemByRow(current
);
3652 bool ignore_other_columns
=
3653 ((GetOwner()->GetExpanderColumn() != col
) &&
3654 (model
->IsContainer(item
)) &&
3655 (!model
->HasContainerColumns(item
)));
3657 if (event
.LeftDClick())
3659 if(hoverOverExpander
)
3661 // a double click on the expander will be converted into a "simulated" normal click
3662 simulateClick
= true;
3664 else if ( current
== m_lineLastClicked
)
3666 if ((!ignore_other_columns
) && (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
3669 model
->GetValue( value
, item
, col
->GetModelColumn() );
3670 cell
->SetValue( value
);
3671 wxRect
cell_rect( xpos
, GetLineStart( current
),
3672 col
->GetWidth(), GetLineHeight( current
) );
3673 cell
->Activate( cell_rect
, model
, item
, col
->GetModelColumn() );
3677 wxWindow
*parent
= GetParent();
3678 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3680 le
.SetEventObject(parent
);
3681 le
.SetModel(GetOwner()->GetModel());
3683 parent
->GetEventHandler()->ProcessEvent(le
);
3689 // The first click was on another item, so don't interpret this as
3690 // a double click, but as a simple click instead
3691 simulateClick
= true;
3695 if (event
.LeftUp() && !hoverOverExpander
)
3697 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
3699 // select single line
3700 SelectAllRows( false );
3701 SelectRow( m_lineSelectSingleOnUp
, true );
3702 SendSelectionChangedEvent( GetItemByRow(m_lineSelectSingleOnUp
) );
3705 // If the user click the expander, we do not do editing even if the column
3706 // with expander are editable
3707 if (m_lastOnSame
&& !ignore_other_columns
)
3709 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
3710 (cell
->GetMode() & wxDATAVIEW_CELL_EDITABLE
) )
3712 m_renameTimer
->Start( 100, true );
3716 m_lastOnSame
= false;
3717 m_lineSelectSingleOnUp
= (unsigned int)-1;
3719 else if(!event
.LeftUp())
3721 // This is necessary, because after a DnD operation in
3722 // from and to ourself, the up event is swallowed by the
3723 // DnD code. So on next non-up event (which means here and
3724 // now) m_lineSelectSingleOnUp should be reset.
3725 m_lineSelectSingleOnUp
= (unsigned int)-1;
3728 if (event
.RightDown())
3730 m_lineBeforeLastClicked
= m_lineLastClicked
;
3731 m_lineLastClicked
= current
;
3733 // If the item is already selected, do not update the selection.
3734 // Multi-selections should not be cleared if a selected item is clicked.
3735 if (!IsRowSelected(current
))
3737 SelectAllRows(false);
3738 ChangeCurrentRow(current
);
3739 SelectRow(m_currentRow
,true);
3740 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3743 else if (event
.RightUp())
3746 model
->GetValue( value
, item
, col
->GetModelColumn() );
3747 wxWindow
*parent
= GetParent();
3748 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
3750 le
.SetEventObject(parent
);
3751 le
.SetModel(GetOwner()->GetModel());
3753 parent
->GetEventHandler()->ProcessEvent(le
);
3755 else if (event
.MiddleDown())
3759 if((event
.LeftDown() || simulateClick
) && hoverOverExpander
)
3761 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3763 // hoverOverExpander being true tells us that our node must be
3764 // valid and have children.
3765 // So we don't need any extra checks.
3766 if( node
->IsOpen() )
3771 else if ((event
.LeftDown() || simulateClick
) && !hoverOverExpander
)
3775 m_lineBeforeLastClicked
= m_lineLastClicked
;
3776 m_lineLastClicked
= current
;
3778 unsigned int oldCurrentRow
= m_currentRow
;
3779 bool oldWasSelected
= IsRowSelected(m_currentRow
);
3781 bool cmdModifierDown
= event
.CmdDown();
3782 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3784 if ( IsSingleSel() || !IsRowSelected(current
) )
3786 SelectAllRows( false );
3787 ChangeCurrentRow(current
);
3788 SelectRow(m_currentRow
,true);
3789 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3791 else // multi sel & current is highlighted & no mod keys
3793 m_lineSelectSingleOnUp
= current
;
3794 ChangeCurrentRow(current
); // change focus
3797 else // multi sel & either ctrl or shift is down
3799 if (cmdModifierDown
)
3801 ChangeCurrentRow(current
);
3802 ReverseRowSelection(m_currentRow
);
3803 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3805 else if (event
.ShiftDown())
3807 ChangeCurrentRow(current
);
3809 unsigned int lineFrom
= oldCurrentRow
,
3812 if ( lineTo
< lineFrom
)
3815 lineFrom
= m_currentRow
;
3818 SelectRows(lineFrom
, lineTo
, true);
3819 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3821 else // !ctrl, !shift
3823 // test in the enclosing if should make it impossible
3824 wxFAIL_MSG( wxT("how did we get here?") );
3828 if (m_currentRow
!= oldCurrentRow
)
3829 RefreshRow( oldCurrentRow
);
3831 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
3833 // Update selection here...
3836 m_lastOnSame
= !simulateClick
&& ((col
== oldCurrentCol
) &&
3837 (current
== oldCurrentRow
)) && oldWasSelected
;
3839 // Call LeftClick after everything else as under GTK+
3840 if (cell
->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE
)
3842 // notify cell about right click
3844 model
->GetValue( value
, item
, col
->GetModelColumn() );
3845 cell
->SetValue( value
);
3846 wxRect
cell_rect( xpos
, GetLineStart( current
),
3847 col
->GetWidth(), GetLineHeight( current
) );
3848 /* ignore ret */ cell
->LeftClick( event
.GetPosition(), cell_rect
,
3849 model
, item
, col
->GetModelColumn());
3854 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
3858 if (HasCurrentRow())
3864 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
3868 if (HasCurrentRow())
3874 wxDataViewItem
wxDataViewMainWindow::GetSelection() const
3876 if( m_selection
.GetCount() != 1 )
3877 return wxDataViewItem();
3879 return GetItemByRow( m_selection
.Item(0));
3882 //-----------------------------------------------------------------------------
3884 //-----------------------------------------------------------------------------
3886 WX_DEFINE_LIST(wxDataViewColumnList
)
3888 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3889 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
3890 EVT_SIZE(wxDataViewCtrl::OnSize
)
3893 wxDataViewCtrl::~wxDataViewCtrl()
3896 GetModel()->RemoveNotifier( m_notifier
);
3901 void wxDataViewCtrl::Init()
3903 m_cols
.DeleteContents(true);
3906 // No sorting column at start
3907 m_sortingColumnIdx
= wxNOT_FOUND
;
3909 m_headerArea
= NULL
;
3912 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3913 const wxPoint
& pos
, const wxSize
& size
,
3914 long style
, const wxValidator
& validator
)
3916 // if ( (style & wxBORDER_MASK) == 0)
3917 // style |= wxBORDER_SUNKEN;
3921 if (!wxControl::Create( parent
, id
, pos
, size
,
3922 style
| wxScrolledWindowStyle
, validator
))
3925 SetInitialSize(size
);
3928 MacSetClipChildren( true );
3931 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
3933 if (HasFlag(wxDV_NO_HEADER
))
3934 m_headerArea
= NULL
;
3936 m_headerArea
= new wxDataViewHeaderWindow(this);
3938 SetTargetWindow( m_clientArea
);
3940 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
3942 sizer
->Add( m_headerArea
, 0, wxGROW
);
3943 sizer
->Add( m_clientArea
, 1, wxGROW
);
3949 wxBorder
wxDataViewCtrl::GetDefaultBorder() const
3951 return wxBORDER_THEME
;
3955 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
3959 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
3962 // we need to process arrows ourselves for scrolling
3963 if ( nMsg
== WM_GETDLGCODE
)
3965 rc
|= DLGC_WANTARROWS
;
3973 wxSize
wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
3975 wxSize newsize
= size
;
3976 if (!HasFlag(wxDV_NO_HEADER
) && (m_headerArea
))
3977 newsize
.y
-= m_headerArea
->GetSize().y
;
3982 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3984 // We need to override OnSize so that our scrolled
3985 // window a) does call Layout() to use sizers for
3986 // positioning the controls but b) does not query
3987 // the sizer for their size and use that for setting
3988 // the scrollable area as set that ourselves by
3989 // calling SetScrollbar() further down.
3996 void wxDataViewCtrl::SetFocus()
3999 m_clientArea
->SetFocus();
4002 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4004 if (!wxDataViewCtrlBase::AssociateModel( model
))
4007 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
4009 model
->AddNotifier( m_notifier
);
4011 m_clientArea
->DestroyTree();
4013 m_clientArea
->BuildTree(model
);
4015 m_clientArea
->UpdateDisplay();
4020 #if wxUSE_DRAG_AND_DROP
4022 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4024 return m_clientArea
->EnableDragSource( format
);
4027 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4029 return m_clientArea
->EnableDropTarget( format
);
4032 #endif // wxUSE_DRAG_AND_DROP
4034 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4036 if (!wxDataViewCtrlBase::AppendColumn(col
))
4039 m_cols
.Append( col
);
4040 OnColumnsCountChanged();
4044 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4046 if (!wxDataViewCtrlBase::PrependColumn(col
))
4049 m_cols
.Insert( col
);
4050 OnColumnsCountChanged();
4054 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4056 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4059 m_cols
.Insert( pos
, col
);
4060 OnColumnsCountChanged();
4064 void wxDataViewCtrl::OnColumnChange(unsigned int idx
)
4067 m_headerArea
->UpdateColumn(idx
);
4069 m_clientArea
->UpdateDisplay();
4072 void wxDataViewCtrl::OnColumnsCountChanged()
4075 m_headerArea
->SetColumnCount(GetColumnCount());
4077 m_clientArea
->UpdateDisplay();
4080 void wxDataViewCtrl::DoSetExpanderColumn()
4082 m_clientArea
->UpdateDisplay();
4085 void wxDataViewCtrl::DoSetIndent()
4087 m_clientArea
->UpdateDisplay();
4090 unsigned int wxDataViewCtrl::GetColumnCount() const
4092 return m_cols
.GetCount();
4095 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int idx
) const
4100 wxDataViewColumn
*wxDataViewCtrl::GetColumnAt(unsigned int pos
) const
4102 // columns can't be reordered if there is no header window which allows
4104 const unsigned idx
= m_headerArea
? m_headerArea
->GetColumnsOrder()[pos
]
4107 return GetColumn(idx
);
4110 int wxDataViewCtrl::GetColumnIndex(const wxDataViewColumn
*column
) const
4112 const unsigned count
= m_cols
.size();
4113 for ( unsigned n
= 0; n
< count
; n
++ )
4115 if ( m_cols
[n
] == column
)
4122 void wxDataViewCtrl::ColumnMoved(wxDataViewColumn
* WXUNUSED(col
),
4123 unsigned int WXUNUSED(new_pos
))
4125 // do _not_ reorder m_cols elements here, they should always be in the
4126 // order in which columns were added, we only display the columns in
4128 m_clientArea
->UpdateDisplay();
4131 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4133 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
4138 OnColumnsCountChanged();
4143 bool wxDataViewCtrl::ClearColumns()
4146 OnColumnsCountChanged();
4150 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4154 unsigned int len
= GetColumnCount();
4155 for ( unsigned int i
= 0; i
< len
; i
++ )
4157 wxDataViewColumn
* col
= GetColumnAt(i
);
4158 if (col
->IsHidden())
4160 ret
+= col
->GetWidth();
4163 CalcScrolledPosition( ret
, dummy
, &ret
, &dummy
);
4170 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4172 return m_sortingColumnIdx
== wxNOT_FOUND
? NULL
4173 : GetColumn(m_sortingColumnIdx
);
4176 // Selection code with wxDataViewItem as parameters
4177 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4179 return m_clientArea
->GetSelection();
4182 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4185 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4186 int len
= selection
.GetCount();
4187 for( int i
= 0; i
< len
; i
++)
4189 unsigned int row
= selection
[i
];
4190 sel
.Add( m_clientArea
->GetItemByRow( row
) );
4195 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4197 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4199 wxDataViewItem last_parent
;
4201 int len
= sel
.GetCount();
4202 for( int i
= 0; i
< len
; i
++ )
4204 wxDataViewItem item
= sel
[i
];
4205 wxDataViewItem parent
= GetModel()->GetParent( item
);
4208 if (parent
!= last_parent
)
4209 ExpandAncestors(item
);
4212 last_parent
= parent
;
4213 int row
= m_clientArea
->GetRowByItem( item
);
4215 selection
.Add( static_cast<unsigned int>(row
) );
4218 m_clientArea
->SetSelections( selection
);
4221 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4223 ExpandAncestors( item
);
4225 int row
= m_clientArea
->GetRowByItem( item
);
4228 // Unselect all rows before select another in the single select mode
4229 if (m_clientArea
->IsSingleSel())
4230 m_clientArea
->SelectAllRows(false);
4231 m_clientArea
->SelectRow(row
, true);
4235 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4237 int row
= m_clientArea
->GetRowByItem( item
);
4239 m_clientArea
->SelectRow(row
, false);
4242 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4244 int row
= m_clientArea
->GetRowByItem( item
);
4247 return m_clientArea
->IsRowSelected(row
);
4252 // Selection code with row number as parameter
4253 int wxDataViewCtrl::GetSelections( wxArrayInt
& sel
) const
4256 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4257 int len
= selection
.GetCount();
4258 for( int i
= 0; i
< len
; i
++)
4260 unsigned int row
= selection
[i
];
4266 void wxDataViewCtrl::SetSelections( const wxArrayInt
& sel
)
4268 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4269 int len
= sel
.GetCount();
4270 for( int i
= 0; i
< len
; i
++ )
4274 selection
.Add( static_cast<unsigned int>(row
) );
4276 m_clientArea
->SetSelections( selection
);
4279 void wxDataViewCtrl::Select( int row
)
4283 if (m_clientArea
->IsSingleSel())
4284 m_clientArea
->SelectAllRows(false);
4285 m_clientArea
->SelectRow( row
, true );
4289 void wxDataViewCtrl::Unselect( int row
)
4292 m_clientArea
->SelectRow(row
, false);
4295 bool wxDataViewCtrl::IsSelected( int row
) const
4298 return m_clientArea
->IsRowSelected(row
);
4302 void wxDataViewCtrl::SelectRange( int from
, int to
)
4305 for( int i
= from
; i
< to
; i
++ )
4307 m_clientArea
->Select(sel
);
4310 void wxDataViewCtrl::UnselectRange( int from
, int to
)
4312 wxDataViewSelection sel
= m_clientArea
->GetSelections();
4313 for( int i
= from
; i
< to
; i
++ )
4314 if( sel
.Index( i
) != wxNOT_FOUND
)
4316 m_clientArea
->SetSelections(sel
);
4319 void wxDataViewCtrl::SelectAll()
4321 m_clientArea
->SelectAllRows(true);
4324 void wxDataViewCtrl::UnselectAll()
4326 m_clientArea
->SelectAllRows(false);
4329 void wxDataViewCtrl::EnsureVisible( int row
, int column
)
4333 if( row
> (int) m_clientArea
->GetRowCount() )
4334 row
= m_clientArea
->GetRowCount();
4336 int first
= m_clientArea
->GetFirstVisibleRow();
4337 int last
= m_clientArea
->GetLastVisibleRow();
4339 m_clientArea
->ScrollTo( row
, column
);
4340 else if( row
> last
)
4341 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
4343 m_clientArea
->ScrollTo( first
, column
);
4346 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
4348 ExpandAncestors( item
);
4350 m_clientArea
->RecalculateDisplay();
4352 int row
= m_clientArea
->GetRowByItem(item
);
4355 if( column
== NULL
)
4356 EnsureVisible(row
, -1);
4358 EnsureVisible( row
, GetColumnIndex(column
) );
4363 void wxDataViewCtrl::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
4364 wxDataViewColumn
* &column
) const
4366 m_clientArea
->HitTest(point
, item
, column
);
4369 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
& item
,
4370 const wxDataViewColumn
* column
) const
4372 return m_clientArea
->GetItemRect(item
, column
);
4375 wxDataViewItem
wxDataViewCtrl::GetItemByRow( unsigned int row
) const
4377 return m_clientArea
->GetItemByRow( row
);
4380 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem
& item
) const
4382 return m_clientArea
->GetRowByItem( item
);
4385 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4387 int row
= m_clientArea
->GetRowByItem( item
);
4389 m_clientArea
->Expand(row
);
4392 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4394 int row
= m_clientArea
->GetRowByItem( item
);
4396 m_clientArea
->Collapse(row
);
4399 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4401 int row
= m_clientArea
->GetRowByItem( item
);
4403 return m_clientArea
->IsExpanded(row
);
4407 void wxDataViewCtrl::StartEditor( const wxDataViewItem
& item
, unsigned int column
)
4409 wxDataViewColumn
* col
= GetColumn( column
);
4413 wxRect itemRect
= GetItemRect(item
, col
);
4414 wxDataViewRenderer
* renderer
= col
->GetRenderer();
4415 renderer
->StartEditing(item
, itemRect
);
4418 #endif // !wxUSE_GENERICDATAVIEWCTRL
4420 #endif // wxUSE_DATAVIEWCTRL