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 //-----------------------------------------------------------------------------
56 class wxDataViewColumn
;
57 class wxDataViewHeaderWindow
;
60 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
64 static const int SCROLL_UNIT_X
= 15;
66 // the cell padding on the left/right
67 static const int PADDING_RIGHTLEFT
= 3;
69 // the expander space margin
70 static const int EXPANDER_MARGIN
= 4;
73 static const int EXPANDER_OFFSET
= 4;
75 static const int EXPANDER_OFFSET
= 1;
78 // Below is the compare stuff.
79 // For the generic implementation, both the leaf nodes and the nodes are sorted for
80 // fast search when needed
81 static wxDataViewModel
* g_model
;
82 static int g_column
= -2;
83 static bool g_asending
= true;
85 //-----------------------------------------------------------------------------
87 //-----------------------------------------------------------------------------
89 void wxDataViewColumn::Init(int width
, wxAlignment align
, int flags
)
91 m_width
= width
== wxCOL_WIDTH_DEFAULT
? wxDVC_DEFAULT_WIDTH
: width
;
96 m_sortAscending
= true;
99 void wxDataViewColumn::UpdateDisplay()
103 int idx
= m_owner
->GetColumnIndex( this );
104 m_owner
->OnColumnChange( idx
);
108 //-----------------------------------------------------------------------------
109 // wxDataViewHeaderWindow
110 //-----------------------------------------------------------------------------
112 class wxDataViewHeaderWindow
: public wxHeaderCtrl
115 wxDataViewHeaderWindow(wxDataViewCtrl
*parent
)
116 : wxHeaderCtrl(parent
)
120 wxDataViewCtrl
*GetOwner() const
121 { return static_cast<wxDataViewCtrl
*>(GetParent()); }
124 // implement/override wxHeaderCtrl functions by forwarding them to the main
126 virtual const wxHeaderColumn
& GetColumn(unsigned int idx
) const
128 return *(GetOwner()->GetColumn(idx
));
131 // FIXME: currently unused
132 virtual bool UpdateColumnWidthToFit(unsigned int idx
, int widthTitle
)
134 wxDataViewCtrl
* const owner
= GetOwner();
136 int widthContents
= owner
->GetBestColumnWidth(idx
);
137 owner
->GetColumn(idx
)->SetWidth(wxMax(widthTitle
, widthContents
));
138 owner
->OnColumnChange(idx
);
144 bool SendEvent(wxEventType type
, unsigned int n
)
146 wxDataViewCtrl
* const owner
= GetOwner();
147 wxDataViewEvent
event(type
, owner
->GetId());
149 event
.SetEventObject(owner
);
151 event
.SetDataViewColumn(owner
->GetColumn(n
));
152 event
.SetModel(owner
->GetModel());
154 // for events created by wxDataViewHeaderWindow the
155 // row / value fields are not valid
156 return owner
->GetEventHandler()->ProcessEvent(event
);
159 void OnClick(wxHeaderCtrlEvent
& event
)
161 const unsigned idx
= event
.GetColumn();
163 if ( SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, idx
) )
166 // default handling for the column click is to sort by this column or
167 // toggle its sort order
168 wxDataViewCtrl
* const owner
= GetOwner();
169 wxDataViewColumn
* const col
= owner
->GetColumn(idx
);
170 if ( !col
->IsSortable() )
172 // no default handling for non-sortable columns
177 if ( col
->IsSortKey() )
179 // already using this column for sorting, just change the order
180 col
->ToggleSortOrder();
182 else // not using this column for sorting yet
184 // first unset the old sort column if any
185 int oldSortKey
= owner
->GetSortingColumnIndex();
186 if ( oldSortKey
!= wxNOT_FOUND
)
188 owner
->GetColumn(oldSortKey
)->UnsetAsSortKey();
189 owner
->OnColumnChange(oldSortKey
);
192 owner
->SetSortingColumnIndex(idx
);
196 wxDataViewModel
* const model
= owner
->GetModel();
200 owner
->OnColumnChange(idx
);
203 void OnRClick(wxHeaderCtrlEvent
& event
)
205 if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
210 void OnResize(wxHeaderCtrlEvent
& event
)
212 wxDataViewCtrl
* const owner
= GetOwner();
214 const unsigned col
= event
.GetColumn();
215 owner
->GetColumn(col
)->SetWidth(event
.GetWidth());
216 GetOwner()->OnColumnChange(col
);
219 void OnEndReorder(wxHeaderCtrlEvent
& event
)
221 wxDataViewCtrl
* const owner
= GetOwner();
222 owner
->ColumnMoved(owner
->GetColumn(event
.GetColumn()),
223 event
.GetNewOrder());
226 DECLARE_EVENT_TABLE()
227 wxDECLARE_NO_COPY_CLASS(wxDataViewHeaderWindow
);
230 BEGIN_EVENT_TABLE(wxDataViewHeaderWindow
, wxHeaderCtrl
)
231 EVT_HEADER_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnClick
)
232 EVT_HEADER_RIGHT_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnRClick
)
234 EVT_HEADER_RESIZING(wxID_ANY
, wxDataViewHeaderWindow::OnResize
)
235 EVT_HEADER_END_RESIZE(wxID_ANY
, wxDataViewHeaderWindow::OnResize
)
237 EVT_HEADER_END_REORDER(wxID_ANY
, wxDataViewHeaderWindow::OnEndReorder
)
240 //-----------------------------------------------------------------------------
241 // wxDataViewRenameTimer
242 //-----------------------------------------------------------------------------
244 class wxDataViewRenameTimer
: public wxTimer
247 wxDataViewMainWindow
*m_owner
;
250 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
254 //-----------------------------------------------------------------------------
255 // wxDataViewTreeNode
256 //-----------------------------------------------------------------------------
258 class wxDataViewTreeNode
;
259 WX_DEFINE_ARRAY( wxDataViewTreeNode
*, wxDataViewTreeNodes
);
260 WX_DEFINE_ARRAY( void* , wxDataViewTreeLeaves
);
262 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
,
263 wxDataViewTreeNode
** node2
);
264 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
);
266 class wxDataViewTreeNode
269 wxDataViewTreeNode( wxDataViewTreeNode
* parent
= NULL
)
276 m_hasChildren
= false;
280 ~wxDataViewTreeNode()
284 wxDataViewTreeNode
* GetParent() const { return m_parent
; }
285 void SetParent( wxDataViewTreeNode
* parent
) { m_parent
= parent
; }
286 wxDataViewTreeNodes
& GetNodes() { return m_nodes
; }
287 wxDataViewTreeLeaves
& GetChildren() { return m_leaves
; }
289 void AddNode( wxDataViewTreeNode
* node
)
291 m_leaves
.Add( node
->GetItem().GetID() );
293 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
296 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
298 void AddLeaf( void * leaf
)
300 m_leaves
.Add( leaf
);
302 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
305 wxDataViewItem
& GetItem() { return m_item
; }
306 const wxDataViewItem
& GetItem() const { return m_item
; }
307 void SetItem( const wxDataViewItem
& item
) { m_item
= item
; }
309 unsigned int GetChildrenNumber() const { return m_leaves
.GetCount(); }
310 unsigned int GetNodeNumber() const { return m_nodes
.GetCount(); }
311 int GetIndentLevel() const
314 const wxDataViewTreeNode
* node
= this;
315 while( node
->GetParent()->GetParent() != NULL
)
317 node
= node
->GetParent();
330 int len
= m_nodes
.GetCount();
332 for ( int i
= 0;i
< len
; i
++)
333 sum
+= m_nodes
[i
]->GetSubTreeCount();
335 sum
+= m_leaves
.GetCount();
338 ChangeSubTreeCount(-sum
);
344 ChangeSubTreeCount(sum
);
347 bool HasChildren() const { return m_hasChildren
; }
348 void SetHasChildren( bool has
){ m_hasChildren
= has
; }
350 void SetSubTreeCount( int num
) { m_subTreeCount
= num
; }
351 int GetSubTreeCount() const { return m_subTreeCount
; }
352 void ChangeSubTreeCount( int num
)
356 m_subTreeCount
+= num
;
358 m_parent
->ChangeSubTreeCount(num
);
365 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
366 int len
= m_nodes
.GetCount();
367 for (int i
= 0; i
< len
; i
++)
368 m_nodes
[i
]->Resort();
369 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
374 wxDataViewTreeNode
*m_parent
;
375 wxDataViewTreeNodes m_nodes
;
376 wxDataViewTreeLeaves m_leaves
;
377 wxDataViewItem m_item
;
383 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
,
384 wxDataViewTreeNode
** node2
)
386 return g_model
->Compare( (*node1
)->GetItem(), (*node2
)->GetItem(), g_column
, g_asending
);
389 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
)
391 return g_model
->Compare( *id1
, *id2
, g_column
, g_asending
);
395 //-----------------------------------------------------------------------------
396 // wxDataViewMainWindow
397 //-----------------------------------------------------------------------------
399 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
,
401 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
402 WX_DEFINE_LIST(ItemList
)
404 class wxDataViewMainWindow
: public wxWindow
407 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
409 const wxPoint
&pos
= wxDefaultPosition
,
410 const wxSize
&size
= wxDefaultSize
,
411 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
412 virtual ~wxDataViewMainWindow();
414 bool IsList() const { return GetOwner()->GetModel()->IsListModel(); }
415 bool IsVirtualList() const { return m_root
== NULL
; }
417 // notifications from wxDataViewModel
418 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
419 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
420 bool ItemChanged( const wxDataViewItem
&item
);
421 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
425 if (!IsVirtualList())
435 g_model
= GetOwner()->GetModel();
436 wxDataViewColumn
* col
= GetOwner()->GetSortingColumn();
439 if (g_model
->HasDefaultCompare())
447 g_column
= col
->GetModelColumn();
448 g_asending
= col
->IsSortOrderAscending();
451 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
452 wxDataViewCtrl
*GetOwner() { return m_owner
; }
453 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
455 #if wxUSE_DRAG_AND_DROP
456 wxBitmap
CreateItemBitmap( unsigned int row
, int &indent
);
457 #endif // wxUSE_DRAG_AND_DROP
458 void OnPaint( wxPaintEvent
&event
);
459 void OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
);
460 void OnChar( wxKeyEvent
&event
);
461 void OnMouse( wxMouseEvent
&event
);
462 void OnSetFocus( wxFocusEvent
&event
);
463 void OnKillFocus( wxFocusEvent
&event
);
465 void UpdateDisplay();
466 void RecalculateDisplay();
467 void OnInternalIdle();
469 void OnRenameTimer();
471 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
472 void ScrollTo( int rows
, int column
);
474 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
475 void ChangeCurrentRow( unsigned int row
);
477 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
478 bool IsEmpty() { return GetRowCount() == 0; }
480 int GetCountPerPage() const;
481 int GetEndOfLastCol() const;
482 unsigned int GetFirstVisibleRow() const;
484 // I change this method to un const because in the tree view,
485 // the displaying number of the tree are changing along with the
486 // expanding/collapsing of the tree nodes
487 unsigned int GetLastVisibleRow();
488 unsigned int GetRowCount();
490 wxDataViewItem
GetSelection() const;
491 wxDataViewSelection
GetSelections(){ return m_selection
; }
492 void SetSelections( const wxDataViewSelection
& sel
)
493 { m_selection
= sel
; UpdateDisplay(); }
494 void Select( const wxArrayInt
& aSelections
);
495 void SelectAllRows( bool on
);
496 void SelectRow( unsigned int row
, bool on
);
497 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
498 void ReverseRowSelection( unsigned int row
);
499 bool IsRowSelected( unsigned int row
);
500 void SendSelectionChangedEvent( const wxDataViewItem
& item
);
502 void RefreshRow( unsigned int row
);
503 void RefreshRows( unsigned int from
, unsigned int to
);
504 void RefreshRowsAfter( unsigned int firstRow
);
506 // returns the colour to be used for drawing the rules
507 wxColour
GetRuleColour() const
509 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
512 wxRect
GetLineRect( unsigned int row
) const;
514 int GetLineStart( unsigned int row
) const; // row * m_lineHeight in fixed mode
515 int GetLineHeight( unsigned int row
) const; // m_lineHeight in fixed mode
516 int GetLineAt( unsigned int y
) const; // y / m_lineHeight in fixed mode
518 // Some useful functions for row and item mapping
519 wxDataViewItem
GetItemByRow( unsigned int row
) const;
520 int GetRowByItem( const wxDataViewItem
& item
) const;
522 // Methods for building the mapping tree
523 void BuildTree( wxDataViewModel
* model
);
525 void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
);
526 wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
);
528 void Expand( unsigned int row
);
529 void Collapse( unsigned int row
);
530 bool IsExpanded( unsigned int row
) const;
531 bool HasChildren( unsigned int row
) const;
533 #if wxUSE_DRAG_AND_DROP
534 bool EnableDragSource( const wxDataFormat
&format
);
535 bool EnableDropTarget( const wxDataFormat
&format
);
537 void RemoveDropHint();
538 wxDragResult
OnDragOver( wxDataFormat format
, wxCoord x
, wxCoord y
, wxDragResult def
);
539 bool OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
);
540 wxDragResult
OnData( wxDataFormat format
, wxCoord x
, wxCoord y
, wxDragResult def
);
542 #endif // wxUSE_DRAG_AND_DROP
545 wxDataViewTreeNode
* GetTreeNodeByRow( unsigned int row
) const;
546 // We did not need this temporarily
547 // wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
549 int RecalculateCount();
551 wxDataViewEvent
SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
);
553 wxDataViewTreeNode
* FindNode( const wxDataViewItem
& item
);
556 wxDataViewCtrl
*m_owner
;
560 wxDataViewColumn
*m_currentCol
;
561 unsigned int m_currentRow
;
562 wxDataViewSelection m_selection
;
564 wxDataViewRenameTimer
*m_renameTimer
;
569 #if wxUSE_DRAG_AND_DROP
574 wxDataFormat m_dragFormat
;
577 wxDataFormat m_dropFormat
;
579 unsigned int m_dropHintLine
;
580 #endif // wxUSE_DRAG_AND_DROP
582 // for double click logic
583 unsigned int m_lineLastClicked
,
584 m_lineBeforeLastClicked
,
585 m_lineSelectSingleOnUp
;
587 // the pen used to draw horiz/vertical rules
590 // the pen used to draw the expander and the lines
593 // This is the tree structure of the model
594 wxDataViewTreeNode
* m_root
;
597 // This is the tree node under the cursor
598 wxDataViewTreeNode
* m_underMouse
;
601 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
602 DECLARE_EVENT_TABLE()
605 // ---------------------------------------------------------
606 // wxGenericDataViewModelNotifier
607 // ---------------------------------------------------------
609 class wxGenericDataViewModelNotifier
: public wxDataViewModelNotifier
612 wxGenericDataViewModelNotifier( wxDataViewMainWindow
*mainWindow
)
613 { m_mainWindow
= mainWindow
; }
615 virtual bool ItemAdded( const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
616 { return m_mainWindow
->ItemAdded( parent
, item
); }
617 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
618 { return m_mainWindow
->ItemDeleted( parent
, item
); }
619 virtual bool ItemChanged( const wxDataViewItem
& item
)
620 { return m_mainWindow
->ItemChanged(item
); }
621 virtual bool ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
622 { return m_mainWindow
->ValueChanged( item
, col
); }
623 virtual bool Cleared()
624 { return m_mainWindow
->Cleared(); }
625 virtual void Resort()
626 { m_mainWindow
->Resort(); }
628 wxDataViewMainWindow
*m_mainWindow
;
631 // ---------------------------------------------------------
632 // wxDataViewRenderer
633 // ---------------------------------------------------------
635 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
637 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
638 wxDataViewCellMode mode
,
640 wxDataViewCustomRendererBase( varianttype
, mode
, align
)
644 m_ellipsizeMode
= wxELLIPSIZE_MIDDLE
;
648 wxDataViewRenderer::~wxDataViewRenderer()
653 wxDC
*wxDataViewRenderer::GetDC()
657 if (GetOwner() == NULL
)
659 if (GetOwner()->GetOwner() == NULL
)
661 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
667 void wxDataViewRenderer::SetAlignment( int align
)
672 int wxDataViewRenderer::GetAlignment() const
677 // ---------------------------------------------------------
678 // wxDataViewCustomRenderer
679 // ---------------------------------------------------------
681 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
683 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
684 wxDataViewCellMode mode
, int align
) :
685 wxDataViewRenderer( varianttype
, mode
, align
)
689 // ---------------------------------------------------------
690 // wxDataViewTextRenderer
691 // ---------------------------------------------------------
693 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
695 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
696 wxDataViewCellMode mode
, int align
) :
697 wxDataViewRenderer( varianttype
, mode
, align
)
701 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
703 m_text
= value
.GetString();
708 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
713 bool wxDataViewTextRenderer::HasEditorCtrl() const
718 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
719 wxRect labelRect
, const wxVariant
&value
)
721 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, value
,
722 wxPoint(labelRect
.x
,labelRect
.y
),
723 wxSize(labelRect
.width
,labelRect
.height
) );
725 // select the text in the control an place the cursor at the end
726 ctrl
->SetInsertionPointEnd();
732 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
734 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
735 value
= text
->GetValue();
739 bool wxDataViewTextRenderer::Render(wxRect rect
, wxDC
*dc
, int state
)
741 RenderText(m_text
, 0, rect
, dc
, state
);
745 wxSize
wxDataViewTextRenderer::GetSize() const
747 const wxDataViewCtrl
*view
= GetView();
749 return view
->wxWindowBase::GetTextExtent( m_text
);
750 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
753 // ---------------------------------------------------------
754 // wxDataViewBitmapRenderer
755 // ---------------------------------------------------------
757 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
759 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
760 wxDataViewCellMode mode
, int align
) :
761 wxDataViewRenderer( varianttype
, mode
, align
)
765 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
767 if (value
.GetType() == wxT("wxBitmap"))
769 if (value
.GetType() == wxT("wxIcon"))
775 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
780 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
783 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
784 else if (m_icon
.Ok())
785 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
790 wxSize
wxDataViewBitmapRenderer::GetSize() const
793 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
794 else if (m_icon
.Ok())
795 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
797 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
800 // ---------------------------------------------------------
801 // wxDataViewToggleRenderer
802 // ---------------------------------------------------------
804 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
806 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
807 wxDataViewCellMode mode
, int align
) :
808 wxDataViewRenderer( varianttype
, mode
, align
)
813 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
815 m_toggle
= value
.GetBool();
820 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
825 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
829 flags
|= wxCONTROL_CHECKED
;
830 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
831 flags
|= wxCONTROL_DISABLED
;
833 // check boxes we draw must always have the same, standard size (if it's
834 // bigger than the cell size the checkbox will be truncated because the
835 // caller had set the clipping rectangle to prevent us from drawing outside
837 cell
.SetSize(GetSize());
839 wxRendererNative::Get().DrawCheckBox(
840 GetOwner()->GetOwner(),
848 void wxDataViewToggleRenderer::WXOnActivate(wxDataViewModel
*model
,
849 const wxVariant
& valueOld
,
850 const wxDataViewItem
& item
,
853 model
->ChangeValue(!valueOld
.GetBool(), item
, col
);
856 wxSize
wxDataViewToggleRenderer::GetSize() const
858 // the window parameter is not used by GetCheckBoxSize() so it's
860 return wxRendererNative::Get().GetCheckBoxSize(NULL
);
863 // ---------------------------------------------------------
864 // wxDataViewProgressRenderer
865 // ---------------------------------------------------------
867 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewRenderer
)
869 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
870 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
871 wxDataViewRenderer( varianttype
, mode
, align
)
877 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
879 m_value
= (long) value
;
881 if (m_value
< 0) m_value
= 0;
882 if (m_value
> 100) m_value
= 100;
887 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
889 value
= (long) m_value
;
894 wxDataViewProgressRenderer::Render(wxRect rect
, wxDC
*dc
, int WXUNUSED(state
))
896 // deflate the rect to leave a small border between bars in adjacent rows
897 wxRect bar
= rect
.Deflate(0, 1);
899 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
900 dc
->SetPen( *wxBLACK_PEN
);
901 dc
->DrawRectangle( bar
);
903 bar
.width
= (int)(bar
.width
* m_value
/ 100.);
904 dc
->SetPen( *wxTRANSPARENT_PEN
);
906 const wxDataViewItemAttr
& attr
= GetAttr();
907 dc
->SetBrush( attr
.HasColour() ? wxBrush(attr
.GetColour())
909 dc
->DrawRectangle( bar
);
914 wxSize
wxDataViewProgressRenderer::GetSize() const
916 return wxSize(40,12);
919 // ---------------------------------------------------------
920 // wxDataViewDateRenderer
921 // ---------------------------------------------------------
923 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
925 #if wxUSE_DATE_RENDERER_POPUP
927 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
930 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
931 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
) :
932 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
),
937 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
938 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
939 sizer
->Add( m_cal
, 1, wxGROW
);
944 void OnCalendar( wxCalendarEvent
&event
);
946 wxCalendarCtrl
*m_cal
;
947 wxDataViewModel
*m_model
;
949 const wxDataViewItem
& m_item
;
952 virtual void OnDismiss()
957 DECLARE_EVENT_TABLE()
960 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
961 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
964 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
966 m_model
->ChangeValue( event
.GetDate(), m_item
, m_col
);
970 #endif // wxUSE_DATE_RENDERER_POPUP
972 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewRenderer
)
974 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
975 wxDataViewCellMode mode
, int align
) :
976 wxDataViewRenderer( varianttype
, mode
, align
)
980 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
982 m_date
= value
.GetDateTime();
987 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
993 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
995 wxString tmp
= m_date
.FormatDate();
996 RenderText( tmp
, 0, cell
, dc
, state
);
1000 wxSize
wxDataViewDateRenderer::GetSize() const
1002 const wxDataViewCtrl
* view
= GetView();
1003 wxString tmp
= m_date
.FormatDate();
1005 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1006 return wxSize(x
,y
+d
);
1009 void wxDataViewDateRenderer::WXOnActivate(wxDataViewModel
*model
,
1010 const wxVariant
& valueOld
,
1011 const wxDataViewItem
& item
,
1014 wxDateTime dtOld
= valueOld
.GetDateTime();
1016 #if wxUSE_DATE_RENDERER_POPUP
1017 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1018 GetOwner()->GetOwner()->GetParent(), &dtOld
, model
, item
, col
);
1019 wxPoint pos
= wxGetMousePosition();
1022 popup
->Popup( popup
->m_cal
);
1023 #else // !wxUSE_DATE_RENDERER_POPUP
1024 wxMessageBox(dtOld
.Format());
1025 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
1028 // ---------------------------------------------------------
1029 // wxDataViewIconTextRenderer
1030 // ---------------------------------------------------------
1032 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewRenderer
)
1034 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1035 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1036 wxDataViewRenderer( varianttype
, mode
, align
)
1039 SetAlignment(align
);
1042 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1048 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1053 bool wxDataViewIconTextRenderer::Render(wxRect rect
, wxDC
*dc
, int state
)
1057 const wxIcon
& icon
= m_value
.GetIcon();
1060 dc
->DrawIcon(icon
, rect
.x
, rect
.y
+ (rect
.height
- icon
.GetHeight())/2);
1061 xoffset
= icon
.GetWidth()+4;
1064 RenderText(m_value
.GetText(), xoffset
, rect
, dc
, state
);
1069 wxSize
wxDataViewIconTextRenderer::GetSize() const
1071 const wxDataViewCtrl
*view
= GetView();
1072 if (!m_value
.GetText().empty())
1075 view
->GetTextExtent( m_value
.GetText(), &x
, &y
);
1077 if (m_value
.GetIcon().IsOk())
1078 x
+= m_value
.GetIcon().GetWidth() + 4;
1079 return wxSize( x
, y
);
1081 return wxSize(80,20);
1084 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1086 wxDataViewIconText iconText
;
1089 wxString text
= iconText
.GetText();
1091 // adjust the label rect to take the width of the icon into account
1092 if (iconText
.GetIcon().IsOk())
1094 int w
= iconText
.GetIcon().GetWidth() + 4;
1096 labelRect
.width
-= w
;
1099 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, text
,
1100 wxPoint(labelRect
.x
,labelRect
.y
),
1101 wxSize(labelRect
.width
,labelRect
.height
) );
1103 // select the text in the control an place the cursor at the end
1104 ctrl
->SetInsertionPointEnd();
1110 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
& value
)
1112 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
1114 wxDataViewIconText
iconText(text
->GetValue(), m_value
.GetIcon());
1119 //-----------------------------------------------------------------------------
1120 // wxDataViewDropTarget
1121 //-----------------------------------------------------------------------------
1123 #if wxUSE_DRAG_AND_DROP
1125 class wxBitmapCanvas
: public wxWindow
1128 wxBitmapCanvas( wxWindow
*parent
, const wxBitmap
&bitmap
, const wxSize
&size
) :
1129 wxWindow( parent
, wxID_ANY
, wxPoint(0,0), size
)
1132 Connect( wxEVT_PAINT
, wxPaintEventHandler(wxBitmapCanvas::OnPaint
) );
1135 void OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1138 dc
.DrawBitmap( m_bitmap
, 0, 0);
1144 class wxDataViewDropSource
: public wxDropSource
1147 wxDataViewDropSource( wxDataViewMainWindow
*win
, unsigned int row
) :
1155 ~wxDataViewDropSource()
1160 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
) )
1162 wxPoint pos
= wxGetMousePosition();
1166 int liney
= m_win
->GetLineStart( m_row
);
1168 m_win
->GetOwner()->CalcUnscrolledPosition( 0, liney
, NULL
, &liney
);
1169 m_win
->ClientToScreen( &linex
, &liney
);
1170 m_dist_x
= pos
.x
- linex
;
1171 m_dist_y
= pos
.y
- liney
;
1174 wxBitmap ib
= m_win
->CreateItemBitmap( m_row
, indent
);
1176 m_hint
= new wxFrame( m_win
->GetParent(), wxID_ANY
, wxEmptyString
,
1177 wxPoint(pos
.x
- m_dist_x
, pos
.y
+ 5 ),
1179 wxFRAME_TOOL_WINDOW
|
1180 wxFRAME_FLOAT_ON_PARENT
|
1181 wxFRAME_NO_TASKBAR
|
1183 new wxBitmapCanvas( m_hint
, ib
, ib
.GetSize() );
1188 m_hint
->Move( pos
.x
- m_dist_x
, pos
.y
+ 5 );
1189 m_hint
->SetTransparent( 128 );
1195 wxDataViewMainWindow
*m_win
;
1198 int m_dist_x
,m_dist_y
;
1202 class wxDataViewDropTarget
: public wxDropTarget
1205 wxDataViewDropTarget( wxDataObject
*obj
, wxDataViewMainWindow
*win
) :
1211 virtual wxDragResult
OnDragOver( wxCoord x
, wxCoord y
, wxDragResult def
)
1213 wxDataFormat format
= GetMatchingPair();
1214 if (format
== wxDF_INVALID
)
1216 return m_win
->OnDragOver( format
, x
, y
, def
);
1219 virtual bool OnDrop( wxCoord x
, wxCoord y
)
1221 wxDataFormat format
= GetMatchingPair();
1222 if (format
== wxDF_INVALID
)
1224 return m_win
->OnDrop( format
, x
, y
);
1227 virtual wxDragResult
OnData( wxCoord x
, wxCoord y
, wxDragResult def
)
1229 wxDataFormat format
= GetMatchingPair();
1230 if (format
== wxDF_INVALID
)
1234 return m_win
->OnData( format
, x
, y
, def
);
1237 virtual void OnLeave()
1238 { m_win
->OnLeave(); }
1240 wxDataViewMainWindow
*m_win
;
1243 #endif // wxUSE_DRAG_AND_DROP
1245 //-----------------------------------------------------------------------------
1246 // wxDataViewRenameTimer
1247 //-----------------------------------------------------------------------------
1249 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1254 void wxDataViewRenameTimer::Notify()
1256 m_owner
->OnRenameTimer();
1259 //-----------------------------------------------------------------------------
1260 // wxDataViewMainWindow
1261 //-----------------------------------------------------------------------------
1263 // The tree building helper, declared firstly
1264 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
1265 wxDataViewTreeNode
* node
);
1267 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1269 if (row1
> row2
) return 1;
1270 if (row1
== row2
) return 0;
1274 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1276 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1277 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1278 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1279 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1280 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1281 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1284 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1285 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1286 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
1287 m_selection( wxDataViewSelectionCmp
)
1292 m_lastOnSame
= false;
1293 m_renameTimer
= new wxDataViewRenameTimer( this );
1295 // TODO: user better initial values/nothing selected
1296 m_currentCol
= NULL
;
1299 m_lineHeight
= wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
1301 #if wxUSE_DRAG_AND_DROP
1303 m_dragStart
= wxPoint(0,0);
1305 m_dragEnabled
= false;
1306 m_dropEnabled
= false;
1308 m_dropHintLine
= (unsigned int) -1;
1309 #endif // wxUSE_DRAG_AND_DROP
1311 m_lineLastClicked
= (unsigned int) -1;
1312 m_lineBeforeLastClicked
= (unsigned int) -1;
1313 m_lineSelectSingleOnUp
= (unsigned int) -1;
1317 SetBackgroundColour( *wxWHITE
);
1319 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1321 m_penRule
= wxPen(GetRuleColour());
1323 // compose a pen whichcan draw black lines
1324 // TODO: maybe there is something system colour to use
1325 m_penExpander
= wxPen(wxColour(0,0,0));
1327 m_root
= new wxDataViewTreeNode( NULL
);
1328 m_root
->SetHasChildren(true);
1330 // Make m_count = -1 will cause the class recaculate the real displaying number of rows.
1332 m_underMouse
= NULL
;
1336 wxDataViewMainWindow::~wxDataViewMainWindow()
1339 delete m_renameTimer
;
1343 #if wxUSE_DRAG_AND_DROP
1344 bool wxDataViewMainWindow::EnableDragSource( const wxDataFormat
&format
)
1346 m_dragFormat
= format
;
1347 m_dragEnabled
= format
!= wxDF_INVALID
;
1352 bool wxDataViewMainWindow::EnableDropTarget( const wxDataFormat
&format
)
1354 m_dropFormat
= format
;
1355 m_dropEnabled
= format
!= wxDF_INVALID
;
1358 SetDropTarget( new wxDataViewDropTarget( new wxCustomDataObject( format
), this ) );
1363 void wxDataViewMainWindow::RemoveDropHint()
1368 RefreshRow( m_dropHintLine
);
1369 m_dropHintLine
= (unsigned int) -1;
1373 wxDragResult
wxDataViewMainWindow::OnDragOver( wxDataFormat format
, wxCoord x
,
1374 wxCoord y
, wxDragResult def
)
1378 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1379 unsigned int row
= GetLineAt( yy
);
1381 if ((row
>= GetRowCount()) || (xx
> GetEndOfLastCol()))
1387 wxDataViewItem item
= GetItemByRow( row
);
1389 wxDataViewModel
*model
= GetOwner()->GetModel();
1391 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1392 event
.SetEventObject( m_owner
);
1393 event
.SetItem( item
);
1394 event
.SetModel( model
);
1395 event
.SetDataFormat( format
);
1396 if (!m_owner
->HandleWindowEvent( event
))
1402 if (!event
.IsAllowed())
1409 if (m_dropHint
&& (row
!= m_dropHintLine
))
1410 RefreshRow( m_dropHintLine
);
1412 m_dropHintLine
= row
;
1418 bool wxDataViewMainWindow::OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
)
1424 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1425 unsigned int row
= GetLineAt( yy
);
1427 if ((row
>= GetRowCount()) || (xx
> GetEndOfLastCol()))
1430 wxDataViewItem item
= GetItemByRow( row
);
1432 wxDataViewModel
*model
= GetOwner()->GetModel();
1434 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1435 event
.SetEventObject( m_owner
);
1436 event
.SetItem( item
);
1437 event
.SetModel( model
);
1438 event
.SetDataFormat( format
);
1439 if (!m_owner
->HandleWindowEvent( event
))
1442 if (!event
.IsAllowed())
1448 wxDragResult
wxDataViewMainWindow::OnData( wxDataFormat format
, wxCoord x
, wxCoord y
,
1453 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1454 unsigned int row
= GetLineAt( yy
);
1456 if ((row
>= GetRowCount()) || (xx
> GetEndOfLastCol()))
1459 wxDataViewItem item
= GetItemByRow( row
);
1461 wxDataViewModel
*model
= GetOwner()->GetModel();
1463 wxCustomDataObject
*obj
= (wxCustomDataObject
*) GetDropTarget()->GetDataObject();
1465 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
1466 event
.SetEventObject( m_owner
);
1467 event
.SetItem( item
);
1468 event
.SetModel( model
);
1469 event
.SetDataFormat( format
);
1470 event
.SetDataSize( obj
->GetSize() );
1471 event
.SetDataBuffer( obj
->GetData() );
1472 if (!m_owner
->HandleWindowEvent( event
))
1475 if (!event
.IsAllowed())
1481 void wxDataViewMainWindow::OnLeave()
1486 wxBitmap
wxDataViewMainWindow::CreateItemBitmap( unsigned int row
, int &indent
)
1488 int height
= GetLineHeight( row
);
1490 unsigned int cols
= GetOwner()->GetColumnCount();
1492 for (col
= 0; col
< cols
; col
++)
1494 wxDataViewColumn
*column
= GetOwner()->GetColumnAt(col
);
1495 if (column
->IsHidden())
1496 continue; // skip it!
1497 width
+= column
->GetWidth();
1503 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
1504 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
1505 indent
= indent
+ m_lineHeight
;
1506 // try to use the m_lineHeight as the expander space
1508 if(!node
->HasChildren())
1513 wxBitmap
bitmap( width
, height
);
1514 wxMemoryDC
dc( bitmap
);
1515 dc
.SetFont( GetFont() );
1516 dc
.SetPen( *wxBLACK_PEN
);
1517 dc
.SetBrush( *wxWHITE_BRUSH
);
1518 dc
.DrawRectangle( 0,0,width
,height
);
1520 wxDataViewModel
*model
= m_owner
->GetModel();
1522 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1525 // TODO-RTL: last column for RTL support
1526 expander
= GetOwner()->GetColumnAt( 0 );
1527 GetOwner()->SetExpanderColumn(expander
);
1532 for (col
= 0; col
< cols
; col
++)
1534 wxDataViewColumn
*column
= GetOwner()->GetColumnAt( col
);
1535 wxDataViewRenderer
*cell
= column
->GetRenderer();
1537 if (column
->IsHidden())
1538 continue; // skip it!
1540 width
= column
->GetWidth();
1542 if (column
== expander
)
1546 wxDataViewItem item
= GetItemByRow( row
);
1547 model
->GetValue( value
, item
, column
->GetModelColumn());
1548 cell
->SetValue( value
);
1550 wxDataViewItemAttr attr
;
1551 model
->GetAttr(item
, column
->GetModelColumn(), attr
);
1552 cell
->SetAttr(attr
);
1554 wxRect
item_rect(x
, 0, width
, height
);
1555 item_rect
.Deflate(PADDING_RIGHTLEFT
, 0);
1557 // dc.SetClippingRegion( item_rect );
1558 cell
->WXCallRender(item_rect
, &dc
, 0);
1559 // dc.DestroyClippingRegion();
1567 #endif // wxUSE_DRAG_AND_DROP
1570 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1572 wxDataViewModel
*model
= GetOwner()->GetModel();
1573 wxAutoBufferedPaintDC
dc( this );
1576 dc
.SetBrush(GetOwner()->GetBackgroundColour());
1577 dc
.SetPen( *wxTRANSPARENT_PEN
);
1578 dc
.DrawRectangle(GetClientSize());
1582 GetOwner()->PrepareDC( dc
);
1583 dc
.SetFont( GetFont() );
1585 wxRect update
= GetUpdateRegion().GetBox();
1586 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1588 // compute which items needs to be redrawn
1589 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
1590 unsigned int item_count
=
1591 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
1592 (int)(GetRowCount( ) - item_start
));
1593 unsigned int item_last
= item_start
+ item_count
;
1594 // Get the parent of DataViewCtrl
1595 wxWindow
*parent
= GetParent()->GetParent();
1596 wxDataViewEvent
cache_event(wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, parent
->GetId());
1597 cache_event
.SetEventObject(GetParent());
1598 cache_event
.SetCache(item_start
, item_last
- 1);
1599 parent
->ProcessWindowEvent(cache_event
);
1601 // compute which columns needs to be redrawn
1602 unsigned int cols
= GetOwner()->GetColumnCount();
1605 // we assume that we have at least one column below and painting an
1606 // empty control is unnecessary anyhow
1610 unsigned int col_start
= 0;
1611 unsigned int x_start
;
1612 for (x_start
= 0; col_start
< cols
; col_start
++)
1614 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_start
);
1615 if (col
->IsHidden())
1616 continue; // skip it!
1618 unsigned int w
= col
->GetWidth();
1619 if (x_start
+w
>= (unsigned int)update
.x
)
1625 unsigned int col_last
= col_start
;
1626 unsigned int x_last
= x_start
;
1627 for (; col_last
< cols
; col_last
++)
1629 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_last
);
1630 if (col
->IsHidden())
1631 continue; // skip it!
1633 if (x_last
> (unsigned int)update
.GetRight())
1636 x_last
+= col
->GetWidth();
1639 // Draw horizontal rules if required
1640 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1642 dc
.SetPen(m_penRule
);
1643 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1645 for (unsigned int i
= item_start
; i
<= item_last
; i
++)
1647 int y
= GetLineStart( i
);
1648 dc
.DrawLine(x_start
, y
, x_last
, y
);
1652 // Draw vertical rules if required
1653 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1655 dc
.SetPen(m_penRule
);
1656 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1659 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1661 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(i
);
1662 if (col
->IsHidden())
1663 continue; // skip it
1665 dc
.DrawLine(x
, GetLineStart( item_start
),
1666 x
, GetLineStart( item_last
) );
1668 x
+= col
->GetWidth();
1671 // Draw last vertical rule
1672 dc
.DrawLine(x
, GetLineStart( item_start
),
1673 x
, GetLineStart( item_last
) );
1676 // redraw the background for the items which are selected/current
1677 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1679 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1680 if (selected
|| item
== m_currentRow
)
1682 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
1683 if (item
== m_currentRow
)
1684 flags
|= wxCONTROL_CURRENT
;
1686 flags
|= wxCONTROL_FOCUSED
;
1688 wxRect
rect( x_start
, GetLineStart( item
),
1689 x_last
- x_start
, GetLineHeight( item
) );
1690 wxRendererNative::Get().DrawItemSelectionRect
1700 #if wxUSE_DRAG_AND_DROP
1703 wxRect
rect( x_start
, GetLineStart( m_dropHintLine
),
1704 x_last
- x_start
, GetLineHeight( m_dropHintLine
) );
1705 dc
.SetPen( *wxBLACK_PEN
);
1706 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1707 dc
.DrawRectangle( rect
);
1709 #endif // wxUSE_DRAG_AND_DROP
1711 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1714 // TODO-RTL: last column for RTL support
1715 expander
= GetOwner()->GetColumnAt( 0 );
1716 GetOwner()->SetExpanderColumn(expander
);
1719 // redraw all cells for all rows which must be repainted and all columns
1721 cell_rect
.x
= x_start
;
1722 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1724 wxDataViewColumn
*col
= GetOwner()->GetColumnAt( i
);
1725 wxDataViewRenderer
*cell
= col
->GetRenderer();
1726 cell_rect
.width
= col
->GetWidth();
1728 if ( col
->IsHidden() || cell_rect
.width
<= 0 )
1729 continue; // skip it!
1731 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1733 // get the cell value and set it into the renderer
1735 wxDataViewTreeNode
*node
= NULL
;
1736 wxDataViewItem dataitem
;
1738 if (!IsVirtualList())
1740 node
= GetTreeNodeByRow(item
);
1744 dataitem
= node
->GetItem();
1746 if ((i
> 0) && model
->IsContainer(dataitem
) &&
1747 !model
->HasContainerColumns(dataitem
))
1752 dataitem
= wxDataViewItem( wxUIntToPtr(item
+1) );
1755 model
->GetValue( value
, dataitem
, col
->GetModelColumn());
1756 cell
->SetValue( value
);
1758 wxDataViewItemAttr attr
;
1759 model
->GetAttr(dataitem
, col
->GetModelColumn(), attr
);
1760 cell
->SetAttr(attr
);
1763 cell_rect
.y
= GetLineStart( item
);
1764 cell_rect
.height
= GetLineHeight( item
);
1766 // deal with the expander
1768 if ((!IsList()) && (col
== expander
))
1770 // Calculate the indent first
1771 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
1773 // we reserve m_lineHeight of horizontal space for the expander
1774 // but leave EXPANDER_MARGIN around the expander itself
1775 int exp_x
= cell_rect
.x
+ indent
+ EXPANDER_MARGIN
;
1777 indent
+= m_lineHeight
;
1779 // draw expander if needed and visible
1780 if ( node
->HasChildren() && exp_x
< cell_rect
.GetRight() )
1782 dc
.SetPen( m_penExpander
);
1783 dc
.SetBrush( wxNullBrush
);
1785 int exp_size
= m_lineHeight
- 2*EXPANDER_MARGIN
;
1786 int exp_y
= cell_rect
.y
+ (cell_rect
.height
- exp_size
)/2
1787 + EXPANDER_MARGIN
- EXPANDER_OFFSET
;
1789 const wxRect
rect(exp_x
, exp_y
, exp_size
, exp_size
);
1792 if ( m_underMouse
== node
)
1793 flag
|= wxCONTROL_CURRENT
;
1794 if ( node
->IsOpen() )
1795 flag
|= wxCONTROL_EXPANDED
;
1797 // ensure that we don't overflow the cell (which might
1798 // happen if the column is very narrow)
1799 wxDCClipper
clip(dc
, cell_rect
);
1801 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
1804 // force the expander column to left-center align
1805 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
1807 if (node
&& !node
->HasChildren())
1809 // Yes, if the node does not have any child, it must be a leaf which
1810 // mean that it is a temporarily created by GetTreeNodeByRow
1814 wxRect item_rect
= cell_rect
;
1815 item_rect
.Deflate(PADDING_RIGHTLEFT
, 0);
1817 // account for the tree indent (harmless if we're not indented)
1818 item_rect
.x
+= indent
;
1819 item_rect
.width
-= indent
;
1821 if ( item_rect
.width
<= 0 )
1825 if (m_hasFocus
&& (m_selection
.Index(item
) != wxNOT_FOUND
))
1826 state
|= wxDATAVIEW_CELL_SELECTED
;
1828 // TODO: it would be much more efficient to create a clipping
1829 // region for the entire column being rendered (in the OnPaint
1830 // of wxDataViewMainWindow) instead of a single clip region for
1831 // each cell. However it would mean that each renderer should
1832 // respect the given wxRect's top & bottom coords, eventually
1833 // violating only the left & right coords - however the user can
1834 // make its own renderer and thus we cannot be sure of that.
1835 wxDCClipper
clip(dc
, item_rect
);
1837 cell
->WXCallRender(item_rect
, &dc
, state
);
1840 cell_rect
.x
+= cell_rect
.width
;
1844 void wxDataViewMainWindow::OnRenameTimer()
1846 // We have to call this here because changes may just have
1847 // been made and no screen update taken place.
1850 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
1851 // (needs to be tested!)
1855 wxDataViewItem item
= GetItemByRow( m_currentRow
);
1857 wxRect labelRect
= GetItemRect(item
, m_currentCol
);
1859 m_currentCol
->GetRenderer()->StartEditing( item
, labelRect
);
1862 //-----------------------------------------------------------------------------
1863 // Helper class for do operation on the tree node
1864 //-----------------------------------------------------------------------------
1869 virtual ~DoJob() { }
1871 // The return value control how the tree-walker tranverse the tree
1872 // 0: Job done, stop tranverse and return
1873 // 1: Ignore the current node's subtree and continue
1874 // 2: Job not done, continue
1875 enum { OK
= 0 , IGR
= 1, CONT
= 2 };
1876 virtual int operator() ( wxDataViewTreeNode
* node
) = 0;
1877 virtual int operator() ( void * n
) = 0;
1880 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
1885 switch( func( node
) )
1896 wxDataViewTreeNodes nodes
= node
->GetNodes();
1897 wxDataViewTreeLeaves leaves
= node
->GetChildren();
1899 int len_nodes
= nodes
.GetCount();
1900 int len
= leaves
.GetCount();
1901 int i
= 0, nodes_i
= 0;
1903 for(; i
< len
; i
++ )
1905 void * n
= leaves
[i
];
1906 if( nodes_i
< len_nodes
&& n
== nodes
[nodes_i
]->GetItem().GetID() )
1908 wxDataViewTreeNode
* nd
= nodes
[nodes_i
];
1911 if( Walker( nd
, func
) )
1930 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
1932 if (IsVirtualList())
1934 wxDataViewVirtualListModel
*list_model
=
1935 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
1936 m_count
= list_model
->GetCount();
1943 wxDataViewTreeNode
* node
;
1944 node
= FindNode(parent
);
1949 node
->SetHasChildren( true );
1951 if( g_model
->IsContainer( item
) )
1953 wxDataViewTreeNode
* newnode
= new wxDataViewTreeNode( node
);
1954 newnode
->SetItem(item
);
1955 newnode
->SetHasChildren( true );
1956 node
->AddNode( newnode
);
1959 node
->AddLeaf( item
.GetID() );
1961 node
->ChangeSubTreeCount(1);
1969 static void DestroyTreeHelper( wxDataViewTreeNode
* node
);
1971 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
1972 const wxDataViewItem
& item
)
1974 if (IsVirtualList())
1976 wxDataViewVirtualListModel
*list_model
=
1977 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
1978 m_count
= list_model
->GetCount();
1980 if( m_currentRow
> GetRowCount() )
1981 m_currentRow
= m_count
- 1;
1983 // TODO: why empty the entire selection?
1984 m_selection
.Empty();
1991 wxDataViewTreeNode
* node
= FindNode(parent
);
1993 // Notice that it is possible that the item being deleted is not in the
1994 // tree at all, for example we could be deleting a never shown (because
1995 // collapsed) item in a tree model. So it's not an error if we don't know
1996 // about this item, just return without doing anything then.
1997 if ( !node
|| node
->GetChildren().Index(item
.GetID()) == wxNOT_FOUND
)
2001 node
->GetChildren().Remove( item
.GetID() );
2002 // Manipolate selection
2003 if( m_selection
.GetCount() > 1 )
2005 m_selection
.Empty();
2007 bool isContainer
= false;
2008 wxDataViewTreeNodes nds
= node
->GetNodes();
2009 for (size_t i
= 0; i
< nds
.GetCount(); i
++)
2011 if (nds
[i
]->GetItem() == item
)
2019 wxDataViewTreeNode
* n
= NULL
;
2020 wxDataViewTreeNodes nodes
= node
->GetNodes();
2021 int len
= nodes
.GetCount();
2022 for( int i
= 0; i
< len
; i
++)
2024 if( nodes
[i
]->GetItem() == item
)
2031 wxCHECK_MSG( n
!= NULL
, false, "item not found" );
2033 node
->GetNodes().Remove( n
);
2034 sub
-= n
->GetSubTreeCount();
2035 ::DestroyTreeHelper(n
);
2037 // Make the row number invalid and get a new valid one when user call GetRowCount
2039 node
->ChangeSubTreeCount(sub
);
2041 // Change the current row to the last row if the current exceed the max row number
2042 if( m_currentRow
> GetRowCount() )
2043 m_currentRow
= m_count
- 1;
2050 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
2056 wxWindow
*parent
= GetParent();
2057 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2058 le
.SetEventObject(parent
);
2059 le
.SetModel(GetOwner()->GetModel());
2061 parent
->GetEventHandler()->ProcessEvent(le
);
2066 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
2068 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
2069 /*#define MAX_VIRTUAL_WIDTH 100000
2071 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
2072 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2073 Refresh( true, &rect );
2081 wxWindow
*parent
= GetParent();
2082 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2083 le
.SetEventObject(parent
);
2084 le
.SetModel(GetOwner()->GetModel());
2087 le
.SetDataViewColumn(GetOwner()->GetColumn(col
));
2088 parent
->GetEventHandler()->ProcessEvent(le
);
2093 bool wxDataViewMainWindow::Cleared()
2098 BuildTree( GetOwner()->GetModel() );
2105 void wxDataViewMainWindow::UpdateDisplay()
2108 m_underMouse
= NULL
;
2111 void wxDataViewMainWindow::OnInternalIdle()
2113 wxWindow::OnInternalIdle();
2117 RecalculateDisplay();
2122 void wxDataViewMainWindow::RecalculateDisplay()
2124 wxDataViewModel
*model
= GetOwner()->GetModel();
2131 int width
= GetEndOfLastCol();
2132 int height
= GetLineStart( GetRowCount() );
2134 SetVirtualSize( width
, height
);
2135 GetOwner()->SetScrollRate( 10, m_lineHeight
);
2140 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2142 wxWindow::ScrollWindow( dx
, dy
, rect
);
2144 if (GetOwner()->m_headerArea
)
2145 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
2148 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
2151 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
2152 int sy
= GetLineStart( rows
)/y
;
2156 wxRect rect
= GetClientRect();
2160 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
2161 for (x_start
= 0; colnum
< column
; colnum
++)
2163 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(colnum
);
2164 if (col
->IsHidden())
2165 continue; // skip it!
2167 w
= col
->GetWidth();
2171 int x_end
= x_start
+ w
;
2172 xe
= xx
+ rect
.width
;
2175 sx
= ( xx
+ x_end
- xe
)/x
;
2182 m_owner
->Scroll( sx
, sy
);
2185 int wxDataViewMainWindow::GetCountPerPage() const
2187 wxSize size
= GetClientSize();
2188 return size
.y
/ m_lineHeight
;
2191 int wxDataViewMainWindow::GetEndOfLastCol() const
2195 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2197 const wxDataViewColumn
*c
=
2198 const_cast<wxDataViewCtrl
*>(GetOwner())->GetColumnAt( i
);
2201 width
+= c
->GetWidth();
2206 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2210 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2212 return GetLineAt( y
);
2215 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
2217 wxSize client_size
= GetClientSize();
2218 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2219 &client_size
.x
, &client_size
.y
);
2221 // we should deal with the pixel here
2222 unsigned int row
= GetLineAt(client_size
.y
) - 1;
2224 return wxMin( GetRowCount()-1, row
);
2227 unsigned int wxDataViewMainWindow::GetRowCount()
2229 if ( m_count
== -1 )
2231 m_count
= RecalculateCount();
2237 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
2244 void wxDataViewMainWindow::SelectAllRows( bool on
)
2251 m_selection
.Clear();
2252 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2253 m_selection
.Add( i
);
2258 unsigned int first_visible
= GetFirstVisibleRow();
2259 unsigned int last_visible
= GetLastVisibleRow();
2261 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2263 unsigned int row
= m_selection
[i
];
2264 if ((row
>= first_visible
) && (row
<= last_visible
))
2267 m_selection
.Clear();
2271 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
2273 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2277 m_selection
.Add( row
);
2285 m_selection
.Remove( row
);
2291 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2295 unsigned int tmp
= from
;
2301 for (i
= from
; i
<= to
; i
++)
2303 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2306 m_selection
.Add( i
);
2311 m_selection
.Remove( i
);
2314 RefreshRows( from
, to
);
2317 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2319 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2321 int n
= aSelections
[i
];
2323 m_selection
.Add( n
);
2328 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2330 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2331 m_selection
.Add( row
);
2333 m_selection
.Remove( row
);
2337 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2339 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2342 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
2344 wxWindow
*parent
= GetParent();
2345 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
2347 le
.SetEventObject(parent
);
2348 le
.SetModel(GetOwner()->GetModel());
2351 parent
->GetEventHandler()->ProcessEvent(le
);
2354 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2356 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
2357 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2359 wxSize client_size
= GetClientSize();
2360 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2361 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2362 if (intersect_rect
.width
> 0)
2363 Refresh( true, &intersect_rect
);
2366 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2370 unsigned int tmp
= to
;
2375 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
2376 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2378 wxSize client_size
= GetClientSize();
2379 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2380 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2381 if (intersect_rect
.width
> 0)
2382 Refresh( true, &intersect_rect
);
2385 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2387 wxSize client_size
= GetClientSize();
2388 int start
= GetLineStart( firstRow
);
2389 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
2390 if (start
> client_size
.y
) return;
2392 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
2394 Refresh( true, &rect
);
2397 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2399 wxCHECK_RET( newCurrent
< GetRowCount(),
2400 wxT("invalid item index in OnArrowChar()") );
2402 // if there is no selection, we cannot move it anywhere
2403 if (!HasCurrentRow())
2406 unsigned int oldCurrent
= m_currentRow
;
2408 // in single selection we just ignore Shift as we can't select several
2410 if ( event
.ShiftDown() && !IsSingleSel() )
2412 RefreshRow( oldCurrent
);
2414 ChangeCurrentRow( newCurrent
);
2416 // select all the items between the old and the new one
2417 if ( oldCurrent
> newCurrent
)
2419 newCurrent
= oldCurrent
;
2420 oldCurrent
= m_currentRow
;
2423 SelectRows( oldCurrent
, newCurrent
, true );
2424 if (oldCurrent
!=newCurrent
)
2425 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
2429 RefreshRow( oldCurrent
);
2431 // all previously selected items are unselected unless ctrl is held
2432 if ( !event
.ControlDown() )
2433 SelectAllRows(false);
2435 ChangeCurrentRow( newCurrent
);
2437 if ( !event
.ControlDown() )
2439 SelectRow( m_currentRow
, true );
2440 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
2443 RefreshRow( m_currentRow
);
2446 GetOwner()->EnsureVisible( m_currentRow
, -1 );
2449 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2453 rect
.y
= GetLineStart( row
);
2454 rect
.width
= GetEndOfLastCol();
2455 rect
.height
= GetLineHeight( row
);
2460 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2462 const wxDataViewModel
*model
= GetOwner()->GetModel();
2464 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2466 // TODO make more efficient
2471 for (r
= 0; r
< row
; r
++)
2473 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2474 if (!node
) return start
;
2476 wxDataViewItem item
= node
->GetItem();
2478 if (node
&& !node
->HasChildren())
2480 // Yes, if the node does not have any child, it must be a leaf which
2481 // mean that it is a temporarily created by GetTreeNodeByRow
2485 unsigned int cols
= GetOwner()->GetColumnCount();
2487 int height
= m_lineHeight
;
2488 for (col
= 0; col
< cols
; col
++)
2490 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2491 if (column
->IsHidden())
2492 continue; // skip it!
2495 model
->IsContainer(item
) &&
2496 !model
->HasContainerColumns(item
))
2497 continue; // skip it!
2500 model
->GetValue( value
, item
, column
->GetModelColumn() );
2502 wxDataViewRenderer
*renderer
=
2503 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2504 renderer
->SetValue( value
);
2505 height
= wxMax( height
, renderer
->GetSize().y
);
2515 return row
* m_lineHeight
;
2519 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
2521 const wxDataViewModel
*model
= GetOwner()->GetModel();
2523 // check for the easy case first
2524 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
2525 return y
/ m_lineHeight
;
2527 // TODO make more efficient
2528 unsigned int row
= 0;
2529 unsigned int yy
= 0;
2532 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2535 // not really correct...
2536 return row
+ ((y
-yy
) / m_lineHeight
);
2539 wxDataViewItem item
= node
->GetItem();
2541 if (node
&& !node
->HasChildren())
2543 // Yes, if the node does not have any child, it must be a leaf which
2544 // mean that it is a temporarily created by GetTreeNodeByRow
2548 unsigned int cols
= GetOwner()->GetColumnCount();
2550 int height
= m_lineHeight
;
2551 for (col
= 0; col
< cols
; col
++)
2553 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2554 if (column
->IsHidden())
2555 continue; // skip it!
2558 model
->IsContainer(item
) &&
2559 !model
->HasContainerColumns(item
))
2560 continue; // skip it!
2563 model
->GetValue( value
, item
, column
->GetModelColumn() );
2565 wxDataViewRenderer
*renderer
=
2566 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2567 renderer
->SetValue( value
);
2568 height
= wxMax( height
, renderer
->GetSize().y
);
2579 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
2581 const wxDataViewModel
*model
= GetOwner()->GetModel();
2583 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2585 wxASSERT( !IsVirtualList() );
2587 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2588 // wxASSERT( node );
2589 if (!node
) return m_lineHeight
;
2591 wxDataViewItem item
= node
->GetItem();
2593 if (node
&& !node
->HasChildren())
2595 // Yes, if the node does not have any child, it must be a leaf which
2596 // mean that it is a temporarily created by GetTreeNodeByRow
2600 int height
= m_lineHeight
;
2602 unsigned int cols
= GetOwner()->GetColumnCount();
2604 for (col
= 0; col
< cols
; col
++)
2606 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2607 if (column
->IsHidden())
2608 continue; // skip it!
2611 model
->IsContainer(item
) &&
2612 !model
->HasContainerColumns(item
))
2613 continue; // skip it!
2616 model
->GetValue( value
, item
, column
->GetModelColumn() );
2618 wxDataViewRenderer
*renderer
=
2619 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2620 renderer
->SetValue( value
);
2621 height
= wxMax( height
, renderer
->GetSize().y
);
2628 return m_lineHeight
;
2632 class RowToItemJob
: public DoJob
2635 RowToItemJob( unsigned int row
, int current
)
2636 { this->row
= row
; this->current
= current
; }
2637 virtual ~RowToItemJob() {}
2639 virtual int operator() ( wxDataViewTreeNode
* node
)
2642 if( current
== static_cast<int>(row
))
2644 ret
= node
->GetItem();
2648 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2650 current
+= node
->GetSubTreeCount();
2655 // If the current has no child node, we can find the desired item of the row
2657 // This if can speed up finding in some case, and will has a very good effect
2658 // when it comes to list view
2659 if( node
->GetNodes().GetCount() == 0)
2661 int index
= static_cast<int>(row
) - current
- 1;
2662 ret
= node
->GetChildren().Item( index
);
2669 virtual int operator() ( void * n
)
2672 if( current
== static_cast<int>(row
))
2674 ret
= wxDataViewItem( n
);
2680 wxDataViewItem
GetResult() const
2689 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
2691 if (IsVirtualList())
2693 return wxDataViewItem( wxUIntToPtr(row
+1) );
2697 RowToItemJob
job( row
, -2 );
2698 Walker( m_root
, job
);
2699 return job
.GetResult();
2703 class RowToTreeNodeJob
: public DoJob
2706 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
2709 this->current
= current
;
2713 virtual ~RowToTreeNodeJob(){ }
2715 virtual int operator() ( wxDataViewTreeNode
* node
)
2718 if( current
== static_cast<int>(row
))
2724 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2726 current
+= node
->GetSubTreeCount();
2733 // If the current node has no children, we can find the desired item of the
2734 // row number directly.
2735 // This if can speed up finding in some case, and will have a very good
2736 // effect for list views.
2737 if( node
->GetNodes().GetCount() == 0)
2739 int index
= static_cast<int>(row
) - current
- 1;
2740 void * n
= node
->GetChildren().Item( index
);
2741 ret
= new wxDataViewTreeNode( parent
);
2742 ret
->SetItem( wxDataViewItem( n
));
2743 ret
->SetHasChildren(false);
2750 virtual int operator() ( void * n
)
2753 if( current
== static_cast<int>(row
))
2755 ret
= new wxDataViewTreeNode( parent
);
2756 ret
->SetItem( wxDataViewItem( n
));
2757 ret
->SetHasChildren(false);
2764 wxDataViewTreeNode
* GetResult() const
2770 wxDataViewTreeNode
* ret
;
2771 wxDataViewTreeNode
* parent
;
2774 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
2776 wxASSERT( !IsVirtualList() );
2778 RowToTreeNodeJob
job( row
, -2, m_root
);
2779 Walker( m_root
, job
);
2780 return job
.GetResult();
2783 wxDataViewEvent
wxDataViewMainWindow::SendExpanderEvent( wxEventType type
,
2784 const wxDataViewItem
& item
)
2786 wxWindow
*parent
= GetParent();
2787 wxDataViewEvent
le(type
, parent
->GetId());
2789 le
.SetEventObject(parent
);
2790 le
.SetModel(GetOwner()->GetModel());
2793 parent
->GetEventHandler()->ProcessEvent(le
);
2797 bool wxDataViewMainWindow::IsExpanded( unsigned int row
) const
2802 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2806 if (!node
->HasChildren())
2812 return node
->IsOpen();
2815 bool wxDataViewMainWindow::HasChildren( unsigned int row
) const
2820 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2824 if (!node
->HasChildren())
2833 void wxDataViewMainWindow::Expand( unsigned int row
)
2838 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2842 if (!node
->HasChildren())
2848 if (!node
->IsOpen())
2851 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, node
->GetItem());
2853 // Check if the user prevent expanding
2854 if( e
.GetSkipped() )
2859 // build the children of current node
2860 if( node
->GetChildrenNumber() == 0 )
2863 ::BuildTreeHelper(GetOwner()->GetModel(), node
->GetItem(), node
);
2866 // By expanding the node all row indices that are currently in the selection list
2867 // and are greater than our node have become invalid. So we have to correct that now.
2868 const unsigned rowAdjustment
= node
->GetSubTreeCount();
2869 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2871 const unsigned testRow
= m_selection
[i
];
2872 // all rows above us are not affected, so skip them
2876 m_selection
[i
] += rowAdjustment
;
2879 if(m_currentRow
> row
)
2880 ChangeCurrentRow(m_currentRow
+ rowAdjustment
);
2884 // Send the expanded event
2885 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
2889 void wxDataViewMainWindow::Collapse(unsigned int row
)
2894 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
2898 if (!node
->HasChildren())
2907 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem());
2908 if( e
.GetSkipped() )
2911 // Find out if there are selected items below the current node.
2912 bool selectCollapsingRow
= false;
2913 const unsigned rowAdjustment
= node
->GetSubTreeCount();
2914 unsigned maxRowToBeTested
= row
+ rowAdjustment
;
2915 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2917 const unsigned testRow
= m_selection
[i
];
2918 if(testRow
> row
&& testRow
<= maxRowToBeTested
)
2920 selectCollapsingRow
= true;
2921 // get out as soon as we have found a node that is selected
2928 // If the node to be closed has selected items the user won't see those any longer.
2929 // We select the collapsing node in this case.
2930 if(selectCollapsingRow
)
2932 SelectAllRows(false);
2933 ChangeCurrentRow(row
);
2934 SelectRow(row
, true);
2935 SendSelectionChangedEvent(GetItemByRow(row
));
2939 // if there were no selected items below our node we still need to "fix" the
2940 // selection list to adjust for the changing of the row indices.
2941 // We actually do the opposite of what we are doing in Expand().
2942 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2944 const unsigned testRow
= m_selection
[i
];
2945 // all rows above us are not affected, so skip them
2949 m_selection
[i
] -= rowAdjustment
;
2952 // if the "current row" is being collapsed away we change it to the current row ;-)
2953 if(m_currentRow
> row
&& m_currentRow
<= maxRowToBeTested
)
2954 ChangeCurrentRow(row
);
2955 else if(m_currentRow
> row
)
2956 ChangeCurrentRow(m_currentRow
- rowAdjustment
);
2961 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,node
->GetItem());
2965 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
2967 wxDataViewModel
* model
= GetOwner()->GetModel();
2974 // Compose the a parent-chain of the finding item
2976 list
.DeleteContents( true );
2977 wxDataViewItem
it( item
);
2980 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2981 list
.Insert( pItem
);
2982 it
= model
->GetParent( it
);
2985 // Find the item along the parent-chain.
2986 // This algorithm is designed to speed up the node-finding method
2987 wxDataViewTreeNode
* node
= m_root
;
2988 for( ItemList::const_iterator iter
= list
.begin(); iter
!=list
.end(); iter
++ )
2990 if( node
->HasChildren() )
2992 if( node
->GetChildrenNumber() == 0 )
2995 ::BuildTreeHelper(model
, node
->GetItem(), node
);
2998 wxDataViewTreeNodes nodes
= node
->GetNodes();
3002 for (i
= 0; i
< nodes
.GetCount(); i
++)
3004 if (nodes
[i
]->GetItem() == (**iter
))
3006 if (nodes
[i
]->GetItem() == item
)
3023 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
3024 wxDataViewColumn
* &column
)
3026 wxDataViewColumn
*col
= NULL
;
3027 unsigned int cols
= GetOwner()->GetColumnCount();
3028 unsigned int colnum
= 0;
3030 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
3031 for (unsigned x_start
= 0; colnum
< cols
; colnum
++)
3033 col
= GetOwner()->GetColumnAt(colnum
);
3034 if (col
->IsHidden())
3035 continue; // skip it!
3037 unsigned int w
= col
->GetWidth();
3038 if (x_start
+w
>= (unsigned int)x
)
3045 item
= GetItemByRow( GetLineAt( y
) );
3048 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
,
3049 const wxDataViewColumn
* column
)
3054 unsigned int cols
= GetOwner()->GetColumnCount();
3055 // If column is null the loop will compute the combined width of all columns.
3056 // Otherwise, it will compute the x position of the column we are looking for.
3057 for (unsigned int i
= 0; i
< cols
; i
++)
3059 wxDataViewColumn
* col
= GetOwner()->GetColumnAt( i
);
3064 if (col
->IsHidden())
3065 continue; // skip it!
3067 xpos
+= col
->GetWidth();
3068 width
+= col
->GetWidth();
3073 // If we have a column, we need can get its width directly.
3074 if(column
->IsHidden())
3077 width
= column
->GetWidth();
3082 // If we have no column, we reset the x position back to zero.
3086 // we have to take an expander column into account and compute its indentation
3087 // to get the correct x position where the actual text is
3089 int row
= GetRowByItem(item
);
3090 if (!IsList() && (column
== 0 || GetOwner()->GetExpanderColumn() == column
) )
3092 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3093 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
3094 indent
= indent
+ m_lineHeight
; // use m_lineHeight as the width of the expander
3096 if(!node
->HasChildren())
3100 wxRect
itemRect( xpos
+ indent
,
3101 GetLineStart( row
),
3103 GetLineHeight( row
) );
3105 GetOwner()->CalcScrolledPosition( itemRect
.x
, itemRect
.y
,
3106 &itemRect
.x
, &itemRect
.y
);
3111 int wxDataViewMainWindow::RecalculateCount()
3113 if (IsVirtualList())
3115 wxDataViewVirtualListModel
*list_model
=
3116 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
3118 return list_model
->GetCount();
3122 return m_root
->GetSubTreeCount();
3126 class ItemToRowJob
: public DoJob
3129 ItemToRowJob(const wxDataViewItem
& item_
, ItemList::const_iterator iter
)
3136 // Maybe binary search will help to speed up this process
3137 virtual int operator() ( wxDataViewTreeNode
* node
)
3140 if( node
->GetItem() == item
)
3145 if( node
->GetItem() == **m_iter
)
3152 ret
+= node
->GetSubTreeCount();
3158 virtual int operator() ( void * n
)
3161 if( n
== item
.GetID() )
3166 // the row number is begin from zero
3167 int GetResult() const
3171 ItemList::const_iterator m_iter
;
3172 wxDataViewItem item
;
3177 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
3179 const wxDataViewModel
* model
= GetOwner()->GetModel();
3183 if (IsVirtualList())
3185 return wxPtrToUInt( item
.GetID() ) -1;
3192 // Compose the a parent-chain of the finding item
3194 wxDataViewItem
* pItem
;
3195 list
.DeleteContents( true );
3196 wxDataViewItem
it( item
);
3199 pItem
= new wxDataViewItem( it
);
3200 list
.Insert( pItem
);
3201 it
= model
->GetParent( it
);
3203 pItem
= new wxDataViewItem( );
3204 list
.Insert( pItem
);
3206 ItemToRowJob
job( item
, list
.begin() );
3207 Walker(m_root
, job
);
3208 return job
.GetResult();
3212 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
3213 wxDataViewTreeNode
* node
)
3215 if( !model
->IsContainer( item
) )
3218 wxDataViewItemArray children
;
3219 unsigned int num
= model
->GetChildren( item
, children
);
3221 unsigned int index
= 0;
3222 while( index
< num
)
3224 if( model
->IsContainer( children
[index
] ) )
3226 wxDataViewTreeNode
* n
= new wxDataViewTreeNode( node
);
3227 n
->SetItem(children
[index
]);
3228 n
->SetHasChildren( true );
3233 node
->AddLeaf( children
[index
].GetID() );
3237 node
->SetSubTreeCount( num
);
3238 wxDataViewTreeNode
* n
= node
->GetParent();
3240 n
->ChangeSubTreeCount(num
);
3244 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
3248 if (GetOwner()->GetModel()->IsVirtualListModel())
3254 m_root
= new wxDataViewTreeNode( NULL
);
3255 m_root
->SetHasChildren(true);
3257 // First we define a invalid item to fetch the top-level elements
3258 wxDataViewItem item
;
3260 BuildTreeHelper( model
, item
, m_root
);
3264 static void DestroyTreeHelper( wxDataViewTreeNode
* node
)
3266 if( node
->GetNodeNumber() != 0 )
3268 int len
= node
->GetNodeNumber();
3269 wxDataViewTreeNodes
& nodes
= node
->GetNodes();
3270 for (int i
= 0; i
< len
; i
++)
3271 DestroyTreeHelper(nodes
[i
]);
3276 void wxDataViewMainWindow::DestroyTree()
3278 if (!IsVirtualList())
3280 ::DestroyTreeHelper(m_root
);
3286 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
3288 wxWindow
* const parent
= GetParent();
3290 // propagate the char event upwards
3291 wxKeyEvent
eventForParent(event
);
3292 eventForParent
.SetEventObject(parent
);
3293 if ( parent
->ProcessWindowEvent(eventForParent
) )
3296 if ( parent
->HandleAsNavigationKey(event
) )
3299 // no item -> nothing to do
3300 if (!HasCurrentRow())
3306 // don't use m_linesPerPage directly as it might not be computed yet
3307 const int pageSize
= GetCountPerPage();
3308 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
3310 switch ( event
.GetKeyCode() )
3314 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
,
3316 le
.SetItem( GetItemByRow(m_currentRow
) );
3317 le
.SetEventObject(parent
);
3318 le
.SetModel(GetOwner()->GetModel());
3320 parent
->GetEventHandler()->ProcessEvent(le
);
3325 if ( m_currentRow
> 0 )
3326 OnArrowChar( m_currentRow
- 1, event
);
3330 if ( m_currentRow
< GetRowCount() - 1 )
3331 OnArrowChar( m_currentRow
+ 1, event
);
3333 // Add the process for tree expanding/collapsing
3339 wxDataViewTreeNode
* node
= GetTreeNodeByRow(m_currentRow
);
3343 if (node
->HasChildren() && node
->IsOpen())
3345 Collapse(m_currentRow
);
3347 else // if the node is already closed we move the selection to its parent
3349 wxDataViewTreeNode
*parent_node
= node
->GetParent();
3351 if(!node
->HasChildren())
3356 int parent
= GetRowByItem( parent_node
->GetItem() );
3359 unsigned int row
= m_currentRow
;
3360 SelectRow( row
, false);
3361 SelectRow( parent
, true );
3362 ChangeCurrentRow( parent
);
3363 GetOwner()->EnsureVisible( parent
, -1 );
3364 SendSelectionChangedEvent( parent_node
->GetItem() );
3372 if (!IsExpanded( m_currentRow
))
3373 Expand( m_currentRow
);
3376 unsigned int row
= m_currentRow
;
3377 SelectRow( row
, false );
3378 SelectRow( row
+ 1, true );
3379 ChangeCurrentRow( row
+ 1 );
3380 GetOwner()->EnsureVisible( row
+ 1, -1 );
3381 SendSelectionChangedEvent( GetItemByRow(row
+1) );
3388 OnArrowChar( GetRowCount() - 1, event
);
3393 OnArrowChar( 0, event
);
3398 int steps
= pageSize
- 1;
3399 int index
= m_currentRow
- steps
;
3403 OnArrowChar( index
, event
);
3409 int steps
= pageSize
- 1;
3410 unsigned int index
= m_currentRow
+ steps
;
3411 unsigned int count
= GetRowCount();
3412 if ( index
>= count
)
3415 OnArrowChar( index
, event
);
3421 if(m_selection
.size() == 1)
3423 // TODO: we need to revise that when we have a concept for a 'current column'
3424 GetOwner()->StartEditor(GetItemByRow(m_selection
[0]), 0);
3434 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
3436 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3438 // let the base handle mouse wheel events.
3443 int x
= event
.GetX();
3444 int y
= event
.GetY();
3445 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
3446 wxDataViewColumn
*col
= NULL
;
3449 unsigned int cols
= GetOwner()->GetColumnCount();
3451 for (i
= 0; i
< cols
; i
++)
3453 wxDataViewColumn
*c
= GetOwner()->GetColumnAt( i
);
3455 continue; // skip it!
3457 if (x
< xpos
+ c
->GetWidth())
3462 xpos
+= c
->GetWidth();
3467 wxDataViewRenderer
*cell
= col
->GetRenderer();
3468 unsigned int current
= GetLineAt( y
);
3469 if ((current
>= GetRowCount()) || (x
> GetEndOfLastCol()))
3471 // Unselect all if below the last row ?
3475 // Test whether the mouse is hovered on the tree item button
3476 bool hoverOverExpander
= false;
3477 if ((!IsList()) && (GetOwner()->GetExpanderColumn() == col
))
3479 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3480 if( node
!=NULL
&& node
->HasChildren() )
3482 int indent
= node
->GetIndentLevel();
3483 indent
= GetOwner()->GetIndent()*indent
;
3485 // we make the rectangle we are looking in a bit bigger than the actual
3486 // visual expander so the user can hit that little thing reliably
3487 wxRect
rect( xpos
+ indent
,
3488 GetLineStart( current
) + (GetLineHeight(current
) - m_lineHeight
)/2,
3489 m_lineHeight
, m_lineHeight
);
3490 if( rect
.Contains(x
, y
) )
3492 // So the mouse is over the expander
3493 hoverOverExpander
= true;
3494 if (m_underMouse
&& m_underMouse
!= node
)
3496 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3497 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3499 if (m_underMouse
!= node
)
3501 // wxLogMessage("Do the row: %d", current);
3502 RefreshRow(current
);
3504 m_underMouse
= node
;
3507 if (node
!=NULL
&& !node
->HasChildren())
3510 if (!hoverOverExpander
)
3512 if (m_underMouse
!= NULL
)
3514 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3515 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3516 m_underMouse
= NULL
;
3520 wxDataViewModel
*model
= GetOwner()->GetModel();
3522 #if wxUSE_DRAG_AND_DROP
3523 if (event
.Dragging())
3525 if (m_dragCount
== 0)
3527 // we have to report the raw, physical coords as we want to be
3528 // able to call HitTest(event.m_pointDrag) from the user code to
3529 // get the item being dragged
3530 m_dragStart
= event
.GetPosition();
3535 if (m_dragCount
!= 3)
3538 if (event
.LeftIsDown())
3540 m_owner
->CalcUnscrolledPosition( m_dragStart
.x
, m_dragStart
.y
,
3541 &m_dragStart
.x
, &m_dragStart
.y
);
3542 unsigned int drag_item_row
= GetLineAt( m_dragStart
.y
);
3543 wxDataViewItem item
= GetItemByRow( drag_item_row
);
3545 // Notify cell about drag
3546 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3547 event
.SetEventObject( m_owner
);
3548 event
.SetItem( item
);
3549 event
.SetModel( model
);
3550 if (!m_owner
->HandleWindowEvent( event
))
3553 if (!event
.IsAllowed())
3556 wxDataObject
*obj
= event
.GetDataObject();
3560 wxDataViewDropSource
drag( this, drag_item_row
);
3561 drag
.SetData( *obj
);
3562 /* wxDragResult res = */ drag
.DoDragDrop();
3571 #endif // wxUSE_DRAG_AND_DROP
3573 bool simulateClick
= false;
3575 if (event
.ButtonDClick())
3577 m_renameTimer
->Stop();
3578 m_lastOnSame
= false;
3581 wxDataViewItem item
= GetItemByRow(current
);
3582 bool ignore_other_columns
=
3583 ((GetOwner()->GetExpanderColumn() != col
) &&
3584 (model
->IsContainer(item
)) &&
3585 (!model
->HasContainerColumns(item
)));
3587 if (event
.LeftDClick())
3589 if(hoverOverExpander
)
3591 // a double click on the expander will be converted into a "simulated" normal click
3592 simulateClick
= true;
3594 else if ( current
== m_lineLastClicked
)
3596 if ((!ignore_other_columns
) && (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
3598 const unsigned colIdx
= col
->GetModelColumn();
3601 model
->GetValue( value
, item
, colIdx
);
3603 cell
->WXOnActivate(model
, value
, item
, colIdx
);
3605 if ( wxDataViewCustomRenderer
*custom
= cell
->WXGetAsCustom() )
3607 cell
->SetValue( value
);
3609 wxRect
cell_rect( xpos
, GetLineStart( current
),
3610 col
->GetWidth(), GetLineHeight( current
) );
3611 custom
->Activate( cell_rect
, model
, item
, colIdx
);
3616 wxWindow
*parent
= GetParent();
3617 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3619 le
.SetEventObject(parent
);
3620 le
.SetModel(GetOwner()->GetModel());
3622 parent
->GetEventHandler()->ProcessEvent(le
);
3628 // The first click was on another item, so don't interpret this as
3629 // a double click, but as a simple click instead
3630 simulateClick
= true;
3634 if (event
.LeftUp() && !hoverOverExpander
)
3636 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
3638 // select single line
3639 SelectAllRows( false );
3640 SelectRow( m_lineSelectSingleOnUp
, true );
3641 SendSelectionChangedEvent( GetItemByRow(m_lineSelectSingleOnUp
) );
3644 // If the user click the expander, we do not do editing even if the column
3645 // with expander are editable
3646 if (m_lastOnSame
&& !ignore_other_columns
)
3648 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
3649 (cell
->GetMode() & wxDATAVIEW_CELL_EDITABLE
) )
3651 m_renameTimer
->Start( 100, true );
3655 m_lastOnSame
= false;
3656 m_lineSelectSingleOnUp
= (unsigned int)-1;
3658 else if(!event
.LeftUp())
3660 // This is necessary, because after a DnD operation in
3661 // from and to ourself, the up event is swallowed by the
3662 // DnD code. So on next non-up event (which means here and
3663 // now) m_lineSelectSingleOnUp should be reset.
3664 m_lineSelectSingleOnUp
= (unsigned int)-1;
3667 if (event
.RightDown())
3669 m_lineBeforeLastClicked
= m_lineLastClicked
;
3670 m_lineLastClicked
= current
;
3672 // If the item is already selected, do not update the selection.
3673 // Multi-selections should not be cleared if a selected item is clicked.
3674 if (!IsRowSelected(current
))
3676 SelectAllRows(false);
3677 ChangeCurrentRow(current
);
3678 SelectRow(m_currentRow
,true);
3679 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3682 else if (event
.RightUp())
3685 model
->GetValue( value
, item
, col
->GetModelColumn() );
3686 wxWindow
*parent
= GetParent();
3687 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
3689 le
.SetEventObject(parent
);
3690 le
.SetModel(GetOwner()->GetModel());
3692 parent
->GetEventHandler()->ProcessEvent(le
);
3694 else if (event
.MiddleDown())
3698 if((event
.LeftDown() || simulateClick
) && hoverOverExpander
)
3700 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3702 // hoverOverExpander being true tells us that our node must be
3703 // valid and have children.
3704 // So we don't need any extra checks.
3705 if( node
->IsOpen() )
3710 else if ((event
.LeftDown() || simulateClick
) && !hoverOverExpander
)
3714 m_lineBeforeLastClicked
= m_lineLastClicked
;
3715 m_lineLastClicked
= current
;
3717 unsigned int oldCurrentRow
= m_currentRow
;
3718 bool oldWasSelected
= IsRowSelected(m_currentRow
);
3720 bool cmdModifierDown
= event
.CmdDown();
3721 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3723 if ( IsSingleSel() || !IsRowSelected(current
) )
3725 SelectAllRows( false );
3726 ChangeCurrentRow(current
);
3727 SelectRow(m_currentRow
,true);
3728 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3730 else // multi sel & current is highlighted & no mod keys
3732 m_lineSelectSingleOnUp
= current
;
3733 ChangeCurrentRow(current
); // change focus
3736 else // multi sel & either ctrl or shift is down
3738 if (cmdModifierDown
)
3740 ChangeCurrentRow(current
);
3741 ReverseRowSelection(m_currentRow
);
3742 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
3744 else if (event
.ShiftDown())
3746 ChangeCurrentRow(current
);
3748 unsigned int lineFrom
= oldCurrentRow
,
3751 if ( lineTo
< lineFrom
)
3754 lineFrom
= m_currentRow
;
3757 SelectRows(lineFrom
, lineTo
, true);
3758 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3760 else // !ctrl, !shift
3762 // test in the enclosing if should make it impossible
3763 wxFAIL_MSG( wxT("how did we get here?") );
3767 if (m_currentRow
!= oldCurrentRow
)
3768 RefreshRow( oldCurrentRow
);
3770 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
3772 // Update selection here...
3775 m_lastOnSame
= !simulateClick
&& ((col
== oldCurrentCol
) &&
3776 (current
== oldCurrentRow
)) && oldWasSelected
;
3778 // Call LeftClick after everything else as under GTK+
3779 if (cell
->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE
)
3781 if ( wxDataViewCustomRenderer
*custom
= cell
->WXGetAsCustom() )
3783 // notify cell about click
3785 model
->GetValue( value
, item
, col
->GetModelColumn() );
3786 custom
->SetValue( value
);
3787 wxRect
cell_rect( xpos
, GetLineStart( current
),
3788 col
->GetWidth(), GetLineHeight( current
) );
3790 // Report position relative to the cell's custom area, i.e.
3791 // no the entire space as given by the control but the one
3792 // used by the renderer after calculation of alignment etc.
3794 // adjust the rectangle ourselves to account for the alignment
3795 wxRect rectItem
= cell_rect
;
3796 const int align
= custom
->GetAlignment();
3797 if ( align
!= wxDVR_DEFAULT_ALIGNMENT
)
3799 const wxSize size
= custom
->GetSize();
3801 if ( size
.x
>= 0 && size
.x
< cell_rect
.width
)
3803 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
3804 rectItem
.x
+= (cell_rect
.width
- size
.x
)/2;
3805 else if ( align
& wxALIGN_RIGHT
)
3806 rectItem
.x
+= cell_rect
.width
- size
.x
;
3807 // else: wxALIGN_LEFT is the default
3810 if ( size
.y
>= 0 && size
.y
< cell_rect
.height
)
3812 if ( align
& wxALIGN_CENTER_VERTICAL
)
3813 rectItem
.y
+= (cell_rect
.height
- size
.y
)/2;
3814 else if ( align
& wxALIGN_BOTTOM
)
3815 rectItem
.y
+= cell_rect
.height
- size
.y
;
3816 // else: wxALIGN_TOP is the default
3820 wxPoint
pos( event
.GetPosition() );
3821 pos
.x
-= rectItem
.x
;
3822 pos
.y
-= rectItem
.y
;
3824 m_owner
->CalcUnscrolledPosition( pos
.x
, pos
.y
, &pos
.x
, &pos
.y
);
3826 /* ignore ret */ custom
->LeftClick( pos
, cell_rect
,
3827 model
, item
, col
->GetModelColumn());
3833 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
3837 if (HasCurrentRow())
3843 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
3847 if (HasCurrentRow())
3853 wxDataViewItem
wxDataViewMainWindow::GetSelection() const
3855 if( m_selection
.GetCount() != 1 )
3856 return wxDataViewItem();
3858 return GetItemByRow( m_selection
.Item(0));
3861 //-----------------------------------------------------------------------------
3863 //-----------------------------------------------------------------------------
3865 WX_DEFINE_LIST(wxDataViewColumnList
)
3867 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3868 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
3869 EVT_SIZE(wxDataViewCtrl::OnSize
)
3872 wxDataViewCtrl::~wxDataViewCtrl()
3875 GetModel()->RemoveNotifier( m_notifier
);
3880 void wxDataViewCtrl::Init()
3882 m_cols
.DeleteContents(true);
3885 // No sorting column at start
3886 m_sortingColumnIdx
= wxNOT_FOUND
;
3888 m_headerArea
= NULL
;
3891 bool wxDataViewCtrl::Create(wxWindow
*parent
,
3896 const wxValidator
& validator
,
3897 const wxString
& name
)
3899 // if ( (style & wxBORDER_MASK) == 0)
3900 // style |= wxBORDER_SUNKEN;
3904 if (!wxControl::Create( parent
, id
, pos
, size
,
3905 style
| wxScrolledWindowStyle
, validator
, name
))
3908 SetInitialSize(size
);
3911 MacSetClipChildren( true );
3914 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
3916 // We use the cursor keys for moving the selection, not scrolling, so call
3917 // this method to ensure wxScrollHelperEvtHandler doesn't catch all
3918 // keyboard events forwarded to us from wxListMainWindow.
3919 DisableKeyboardScrolling();
3921 if (HasFlag(wxDV_NO_HEADER
))
3922 m_headerArea
= NULL
;
3924 m_headerArea
= new wxDataViewHeaderWindow(this);
3926 SetTargetWindow( m_clientArea
);
3928 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
3930 sizer
->Add( m_headerArea
, 0, wxGROW
);
3931 sizer
->Add( m_clientArea
, 1, wxGROW
);
3937 wxBorder
wxDataViewCtrl::GetDefaultBorder() const
3939 return wxBORDER_THEME
;
3943 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
3947 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
3950 // we need to process arrows ourselves for scrolling
3951 if ( nMsg
== WM_GETDLGCODE
)
3953 rc
|= DLGC_WANTARROWS
;
3961 wxSize
wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
3963 wxSize newsize
= size
;
3964 if (!HasFlag(wxDV_NO_HEADER
) && (m_headerArea
))
3965 newsize
.y
-= m_headerArea
->GetSize().y
;
3970 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3972 // We need to override OnSize so that our scrolled
3973 // window a) does call Layout() to use sizers for
3974 // positioning the controls but b) does not query
3975 // the sizer for their size and use that for setting
3976 // the scrollable area as set that ourselves by
3977 // calling SetScrollbar() further down.
3984 void wxDataViewCtrl::SetFocus()
3987 m_clientArea
->SetFocus();
3990 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3992 if (!wxDataViewCtrlBase::AssociateModel( model
))
3995 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
3997 model
->AddNotifier( m_notifier
);
3999 m_clientArea
->DestroyTree();
4001 m_clientArea
->BuildTree(model
);
4003 m_clientArea
->UpdateDisplay();
4008 #if wxUSE_DRAG_AND_DROP
4010 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4012 return m_clientArea
->EnableDragSource( format
);
4015 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4017 return m_clientArea
->EnableDropTarget( format
);
4020 #endif // wxUSE_DRAG_AND_DROP
4022 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4024 if (!wxDataViewCtrlBase::AppendColumn(col
))
4027 m_cols
.Append( col
);
4028 OnColumnsCountChanged();
4032 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4034 if (!wxDataViewCtrlBase::PrependColumn(col
))
4037 m_cols
.Insert( col
);
4038 OnColumnsCountChanged();
4042 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4044 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4047 m_cols
.Insert( pos
, col
);
4048 OnColumnsCountChanged();
4052 void wxDataViewCtrl::OnColumnChange(unsigned int idx
)
4055 m_headerArea
->UpdateColumn(idx
);
4057 m_clientArea
->UpdateDisplay();
4060 void wxDataViewCtrl::OnColumnsCountChanged()
4063 m_headerArea
->SetColumnCount(GetColumnCount());
4065 m_clientArea
->UpdateDisplay();
4068 void wxDataViewCtrl::DoSetExpanderColumn()
4070 m_clientArea
->UpdateDisplay();
4073 void wxDataViewCtrl::DoSetIndent()
4075 m_clientArea
->UpdateDisplay();
4078 unsigned int wxDataViewCtrl::GetColumnCount() const
4080 return m_cols
.GetCount();
4083 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int idx
) const
4088 wxDataViewColumn
*wxDataViewCtrl::GetColumnAt(unsigned int pos
) const
4090 // columns can't be reordered if there is no header window which allows
4092 const unsigned idx
= m_headerArea
? m_headerArea
->GetColumnsOrder()[pos
]
4095 return GetColumn(idx
);
4098 int wxDataViewCtrl::GetColumnIndex(const wxDataViewColumn
*column
) const
4100 const unsigned count
= m_cols
.size();
4101 for ( unsigned n
= 0; n
< count
; n
++ )
4103 if ( m_cols
[n
] == column
)
4110 void wxDataViewCtrl::ColumnMoved(wxDataViewColumn
* WXUNUSED(col
),
4111 unsigned int WXUNUSED(new_pos
))
4113 // do _not_ reorder m_cols elements here, they should always be in the
4114 // order in which columns were added, we only display the columns in
4116 m_clientArea
->UpdateDisplay();
4119 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4121 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
4126 OnColumnsCountChanged();
4131 bool wxDataViewCtrl::ClearColumns()
4134 OnColumnsCountChanged();
4138 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4141 unsigned int len
= GetColumnCount();
4142 for ( unsigned int i
= 0; i
< len
; i
++ )
4144 wxDataViewColumn
* col
= GetColumnAt(i
);
4151 // This returns the position in pixels which is not what we want.
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
);
4171 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4173 return m_sortingColumnIdx
== wxNOT_FOUND
? NULL
4174 : GetColumn(m_sortingColumnIdx
);
4177 // Selection code with wxDataViewItem as parameters
4178 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4180 return m_clientArea
->GetSelection();
4183 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4186 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4187 int len
= selection
.GetCount();
4188 for( int i
= 0; i
< len
; i
++)
4190 unsigned int row
= selection
[i
];
4191 sel
.Add( m_clientArea
->GetItemByRow( row
) );
4196 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4198 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4200 wxDataViewItem last_parent
;
4202 int len
= sel
.GetCount();
4203 for( int i
= 0; i
< len
; i
++ )
4205 wxDataViewItem item
= sel
[i
];
4206 wxDataViewItem parent
= GetModel()->GetParent( item
);
4209 if (parent
!= last_parent
)
4210 ExpandAncestors(item
);
4213 last_parent
= parent
;
4214 int row
= m_clientArea
->GetRowByItem( item
);
4216 selection
.Add( static_cast<unsigned int>(row
) );
4219 m_clientArea
->SetSelections( selection
);
4222 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4224 ExpandAncestors( item
);
4226 int row
= m_clientArea
->GetRowByItem( item
);
4229 // Unselect all rows before select another in the single select mode
4230 if (m_clientArea
->IsSingleSel())
4231 m_clientArea
->SelectAllRows(false);
4233 m_clientArea
->SelectRow(row
, true);
4235 // Also set focus to the selected item
4236 m_clientArea
->ChangeCurrentRow( row
);
4240 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4242 int row
= m_clientArea
->GetRowByItem( item
);
4244 m_clientArea
->SelectRow(row
, false);
4247 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4249 int row
= m_clientArea
->GetRowByItem( item
);
4252 return m_clientArea
->IsRowSelected(row
);
4257 // Selection code with row number as parameter
4258 int wxDataViewCtrl::GetSelections( wxArrayInt
& sel
) const
4261 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4262 int len
= selection
.GetCount();
4263 for( int i
= 0; i
< len
; i
++)
4265 unsigned int row
= selection
[i
];
4271 void wxDataViewCtrl::SetSelections( const wxArrayInt
& sel
)
4273 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4274 int len
= sel
.GetCount();
4275 for( int i
= 0; i
< len
; i
++ )
4279 selection
.Add( static_cast<unsigned int>(row
) );
4281 m_clientArea
->SetSelections( selection
);
4284 void wxDataViewCtrl::Select( int row
)
4288 if (m_clientArea
->IsSingleSel())
4289 m_clientArea
->SelectAllRows(false);
4290 m_clientArea
->SelectRow( row
, true );
4294 void wxDataViewCtrl::Unselect( int row
)
4297 m_clientArea
->SelectRow(row
, false);
4300 bool wxDataViewCtrl::IsSelected( int row
) const
4303 return m_clientArea
->IsRowSelected(row
);
4307 void wxDataViewCtrl::SelectRange( int from
, int to
)
4310 for( int i
= from
; i
< to
; i
++ )
4312 m_clientArea
->Select(sel
);
4315 void wxDataViewCtrl::UnselectRange( int from
, int to
)
4317 wxDataViewSelection sel
= m_clientArea
->GetSelections();
4318 for( int i
= from
; i
< to
; i
++ )
4319 if( sel
.Index( i
) != wxNOT_FOUND
)
4321 m_clientArea
->SetSelections(sel
);
4324 void wxDataViewCtrl::SelectAll()
4326 m_clientArea
->SelectAllRows(true);
4329 void wxDataViewCtrl::UnselectAll()
4331 m_clientArea
->SelectAllRows(false);
4334 void wxDataViewCtrl::EnsureVisible( int row
, int column
)
4338 if( row
> (int) m_clientArea
->GetRowCount() )
4339 row
= m_clientArea
->GetRowCount();
4341 int first
= m_clientArea
->GetFirstVisibleRow();
4342 int last
= m_clientArea
->GetLastVisibleRow();
4344 m_clientArea
->ScrollTo( row
, column
);
4345 else if( row
> last
)
4346 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
4348 m_clientArea
->ScrollTo( first
, column
);
4351 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
4353 ExpandAncestors( item
);
4355 m_clientArea
->RecalculateDisplay();
4357 int row
= m_clientArea
->GetRowByItem(item
);
4360 if( column
== NULL
)
4361 EnsureVisible(row
, -1);
4363 EnsureVisible( row
, GetColumnIndex(column
) );
4368 void wxDataViewCtrl::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
4369 wxDataViewColumn
* &column
) const
4371 m_clientArea
->HitTest(point
, item
, column
);
4374 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
& item
,
4375 const wxDataViewColumn
* column
) const
4377 return m_clientArea
->GetItemRect(item
, column
);
4380 wxDataViewItem
wxDataViewCtrl::GetItemByRow( unsigned int row
) const
4382 return m_clientArea
->GetItemByRow( row
);
4385 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem
& item
) const
4387 return m_clientArea
->GetRowByItem( item
);
4390 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4392 int row
= m_clientArea
->GetRowByItem( item
);
4394 m_clientArea
->Expand(row
);
4397 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4399 int row
= m_clientArea
->GetRowByItem( item
);
4401 m_clientArea
->Collapse(row
);
4404 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4406 int row
= m_clientArea
->GetRowByItem( item
);
4408 return m_clientArea
->IsExpanded(row
);
4412 void wxDataViewCtrl::StartEditor( const wxDataViewItem
& item
, unsigned int column
)
4414 wxDataViewColumn
* col
= GetColumn( column
);
4418 wxRect itemRect
= GetItemRect(item
, col
);
4419 wxDataViewRenderer
* renderer
= col
->GetRenderer();
4420 renderer
->StartEditing(item
, itemRect
);
4423 #endif // !wxUSE_GENERICDATAVIEWCTRL
4425 #endif // wxUSE_DATAVIEWCTRL