1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/datavgen.cpp
3 // Purpose: wxDataViewCtrl generic implementation
4 // Author: Robert Roebling
5 // Modified by: Francesco Montorsi, Guru Kathiresan, Bo Yang
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_DATAVIEWCTRL
20 #include "wx/dataview.h"
22 #ifdef wxUSE_GENERICDATAVIEWCTRL
26 #include "wx/msw/private.h"
27 #include "wx/msw/wrapwin.h"
28 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/msgdlg.h"
36 #include "wx/dcscreen.h"
40 #include "wx/stockitem.h"
41 #include "wx/calctrl.h"
42 #include "wx/popupwin.h"
43 #include "wx/renderer.h"
44 #include "wx/dcbuffer.h"
47 #include "wx/listimpl.cpp"
48 #include "wx/imaglist.h"
49 #include "wx/headerctrl.h"
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
58 static const int SCROLL_UNIT_X
= 15;
60 // the cell padding on the left/right
61 static const int PADDING_RIGHTLEFT
= 3;
63 // the expander space margin
64 static const int EXPANDER_MARGIN
= 4;
67 static const int EXPANDER_OFFSET
= 4;
69 static const int EXPANDER_OFFSET
= 1;
72 // Below is the compare stuff.
73 // For the generic implementation, both the leaf nodes and the nodes are sorted for
74 // fast search when needed
75 static wxDataViewModel
* g_model
;
76 static int g_column
= -2;
77 static bool g_asending
= true;
79 //-----------------------------------------------------------------------------
80 // wxDataViewHeaderWindow
81 //-----------------------------------------------------------------------------
83 class wxDataViewHeaderWindow
: public wxHeaderCtrl
86 wxDataViewHeaderWindow(wxDataViewCtrl
*parent
)
87 : wxHeaderCtrl(parent
)
91 wxDataViewCtrl
*GetOwner() const
92 { return static_cast<wxDataViewCtrl
*>(GetParent()); }
95 // implement/override wxHeaderCtrl functions by forwarding them to the main
97 virtual const wxHeaderColumn
& GetColumn(unsigned int idx
) const
99 return *(GetOwner()->GetColumn(idx
));
102 // FIXME: currently unused
103 virtual bool UpdateColumnWidthToFit(unsigned int idx
, int widthTitle
)
105 wxDataViewCtrl
* const owner
= GetOwner();
107 int widthContents
= owner
->GetBestColumnWidth(idx
);
108 owner
->GetColumn(idx
)->SetWidth(wxMax(widthTitle
, widthContents
));
109 owner
->OnColumnChange(idx
);
115 bool SendEvent(wxEventType type
, unsigned int n
)
117 wxDataViewCtrl
* const owner
= GetOwner();
118 wxDataViewEvent
event(type
, owner
->GetId());
120 event
.SetEventObject(owner
);
122 event
.SetDataViewColumn(owner
->GetColumn(n
));
123 event
.SetModel(owner
->GetModel());
125 // for events created by wxDataViewHeaderWindow the
126 // row / value fields are not valid
127 return owner
->GetEventHandler()->ProcessEvent(event
);
130 void OnClick(wxHeaderCtrlEvent
& event
)
132 const unsigned idx
= event
.GetColumn();
134 if ( SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, idx
) )
137 // default handling for the column click is to sort by this column or
138 // toggle its sort order
139 wxDataViewCtrl
* const owner
= GetOwner();
140 wxDataViewColumn
* const col
= owner
->GetColumn(idx
);
141 if ( !col
->IsSortable() )
143 // no default handling for non-sortable columns
148 if ( col
->IsSortKey() )
150 // already using this column for sorting, just change the order
151 col
->ToggleSortOrder();
153 else // not using this column for sorting yet
155 // first unset the old sort column if any
156 int oldSortKey
= owner
->GetSortingColumnIndex();
157 if ( oldSortKey
!= wxNOT_FOUND
)
159 owner
->GetColumn(oldSortKey
)->UnsetAsSortKey();
160 owner
->OnColumnChange(oldSortKey
);
163 owner
->SetSortingColumnIndex(idx
);
167 wxDataViewModel
* const model
= owner
->GetModel();
171 owner
->OnColumnChange(idx
);
174 void OnRClick(wxHeaderCtrlEvent
& event
)
176 if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
181 void OnResize(wxHeaderCtrlEvent
& event
)
183 wxDataViewCtrl
* const owner
= GetOwner();
185 const unsigned col
= event
.GetColumn();
186 owner
->GetColumn(col
)->SetWidth(event
.GetWidth());
187 GetOwner()->OnColumnChange(col
);
190 void OnEndReorder(wxHeaderCtrlEvent
& event
)
192 wxDataViewCtrl
* const owner
= GetOwner();
193 owner
->ColumnMoved(owner
->GetColumn(event
.GetColumn()),
194 event
.GetNewOrder());
197 DECLARE_EVENT_TABLE()
198 wxDECLARE_NO_COPY_CLASS(wxDataViewHeaderWindow
);
201 BEGIN_EVENT_TABLE(wxDataViewHeaderWindow
, wxHeaderCtrl
)
202 EVT_HEADER_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnClick
)
203 EVT_HEADER_RIGHT_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnRClick
)
205 EVT_HEADER_RESIZING(wxID_ANY
, wxDataViewHeaderWindow::OnResize
)
206 EVT_HEADER_END_RESIZE(wxID_ANY
, wxDataViewHeaderWindow::OnResize
)
208 EVT_HEADER_END_REORDER(wxID_ANY
, wxDataViewHeaderWindow::OnEndReorder
)
211 //-----------------------------------------------------------------------------
212 // wxDataViewRenameTimer
213 //-----------------------------------------------------------------------------
215 class wxDataViewRenameTimer
: public wxTimer
218 wxDataViewMainWindow
*m_owner
;
221 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
225 //-----------------------------------------------------------------------------
226 // wxDataViewTreeNode
227 //-----------------------------------------------------------------------------
229 class wxDataViewTreeNode
;
230 WX_DEFINE_ARRAY( wxDataViewTreeNode
*, wxDataViewTreeNodes
);
231 WX_DEFINE_ARRAY( void* , wxDataViewTreeLeaves
);
233 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
,
234 wxDataViewTreeNode
** node2
);
235 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
);
237 class wxDataViewTreeNode
240 wxDataViewTreeNode( wxDataViewTreeNode
* parent
= NULL
)
247 m_hasChildren
= false;
251 ~wxDataViewTreeNode()
255 wxDataViewTreeNode
* GetParent() const { return m_parent
; }
256 void SetParent( wxDataViewTreeNode
* parent
) { m_parent
= parent
; }
257 wxDataViewTreeNodes
& GetNodes() { return m_nodes
; }
258 wxDataViewTreeLeaves
& GetChildren() { return m_leaves
; }
260 void AddNode( wxDataViewTreeNode
* node
)
262 m_leaves
.Add( node
->GetItem().GetID() );
264 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
267 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
269 void AddLeaf( void * leaf
)
271 m_leaves
.Add( leaf
);
273 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
276 wxDataViewItem
& GetItem() { return m_item
; }
277 const wxDataViewItem
& GetItem() const { return m_item
; }
278 void SetItem( const wxDataViewItem
& item
) { m_item
= item
; }
280 unsigned int GetChildrenNumber() const { return m_leaves
.GetCount(); }
281 unsigned int GetNodeNumber() const { return m_nodes
.GetCount(); }
282 int GetIndentLevel() const
285 const wxDataViewTreeNode
* node
= this;
286 while( node
->GetParent()->GetParent() != NULL
)
288 node
= node
->GetParent();
301 int len
= m_nodes
.GetCount();
303 for ( int i
= 0;i
< len
; i
++)
304 sum
+= m_nodes
[i
]->GetSubTreeCount();
306 sum
+= m_leaves
.GetCount();
309 ChangeSubTreeCount(-sum
);
315 ChangeSubTreeCount(sum
);
318 bool HasChildren() const { return m_hasChildren
; }
319 void SetHasChildren( bool has
){ m_hasChildren
= has
; }
321 void SetSubTreeCount( int num
) { m_subTreeCount
= num
; }
322 int GetSubTreeCount() const { return m_subTreeCount
; }
323 void ChangeSubTreeCount( int num
)
327 m_subTreeCount
+= num
;
329 m_parent
->ChangeSubTreeCount(num
);
336 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
337 int len
= m_nodes
.GetCount();
338 for (int i
= 0; i
< len
; i
++)
339 m_nodes
[i
]->Resort();
340 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
345 wxDataViewTreeNode
*m_parent
;
346 wxDataViewTreeNodes m_nodes
;
347 wxDataViewTreeLeaves m_leaves
;
348 wxDataViewItem m_item
;
354 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
,
355 wxDataViewTreeNode
** node2
)
357 return g_model
->Compare( (*node1
)->GetItem(), (*node2
)->GetItem(), g_column
, g_asending
);
360 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
)
362 return g_model
->Compare( *id1
, *id2
, g_column
, g_asending
);
366 //-----------------------------------------------------------------------------
367 // wxDataViewMainWindow
368 //-----------------------------------------------------------------------------
370 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
,
372 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
373 WX_DEFINE_LIST(ItemList
)
375 class wxDataViewMainWindow
: public wxWindow
378 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
380 const wxPoint
&pos
= wxDefaultPosition
,
381 const wxSize
&size
= wxDefaultSize
,
382 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
383 virtual ~wxDataViewMainWindow();
385 bool IsVirtualList() const { return m_root
== NULL
; }
387 // notifications from wxDataViewModel
388 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
389 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
390 bool ItemChanged( const wxDataViewItem
&item
);
391 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
395 if (!IsVirtualList())
405 g_model
= GetOwner()->GetModel();
406 wxDataViewColumn
* col
= GetOwner()->GetSortingColumn();
409 if (g_model
->HasDefaultCompare())
417 g_column
= col
->GetModelColumn();
418 g_asending
= col
->IsSortOrderAscending();
421 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
422 wxDataViewCtrl
*GetOwner() { return m_owner
; }
423 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
425 #if wxUSE_DRAG_AND_DROP
426 wxBitmap
CreateItemBitmap( unsigned int row
, int &indent
);
427 #endif // wxUSE_DRAG_AND_DROP
428 void OnPaint( wxPaintEvent
&event
);
429 void OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
);
430 void OnChar( wxKeyEvent
&event
);
431 void OnMouse( wxMouseEvent
&event
);
432 void OnSetFocus( wxFocusEvent
&event
);
433 void OnKillFocus( wxFocusEvent
&event
);
435 void UpdateDisplay();
436 void RecalculateDisplay();
437 void OnInternalIdle();
439 void OnRenameTimer();
441 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
442 void ScrollTo( int rows
, int column
);
444 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
445 void ChangeCurrentRow( unsigned int row
);
447 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
448 bool IsEmpty() { return GetRowCount() == 0; }
450 int GetCountPerPage() const;
451 int GetEndOfLastCol() const;
452 unsigned int GetFirstVisibleRow() const;
454 // I change this method to un const because in the tree view,
455 // the displaying number of the tree are changing along with the
456 // expanding/collapsing of the tree nodes
457 unsigned int GetLastVisibleRow();
458 unsigned int GetRowCount();
460 wxDataViewItem
GetSelection() const;
461 wxDataViewSelection
GetSelections(){ return m_selection
; }
462 void SetSelections( const wxDataViewSelection
& sel
)
463 { m_selection
= sel
; UpdateDisplay(); }
464 void Select( const wxArrayInt
& aSelections
);
465 void SelectAllRows( bool on
);
466 void SelectRow( unsigned int row
, bool on
);
467 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
468 void ReverseRowSelection( unsigned int row
);
469 bool IsRowSelected( unsigned int row
);
470 void SendSelectionChangedEvent( const wxDataViewItem
& item
);
472 void RefreshRow( unsigned int row
);
473 void RefreshRows( unsigned int from
, unsigned int to
);
474 void RefreshRowsAfter( unsigned int firstRow
);
476 // returns the colour to be used for drawing the rules
477 wxColour
GetRuleColour() const
479 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
482 wxRect
GetLineRect( unsigned int row
) const;
484 int GetLineStart( unsigned int row
) const; // row * m_lineHeight in fixed mode
485 int GetLineHeight( unsigned int row
) const; // m_lineHeight in fixed mode
486 int GetLineAt( unsigned int y
) const; // y / m_lineHeight in fixed mode
488 // Some useful functions for row and item mapping
489 wxDataViewItem
GetItemByRow( unsigned int row
) const;
490 int GetRowByItem( const wxDataViewItem
& item
) const;
492 // Methods for building the mapping tree
493 void BuildTree( wxDataViewModel
* model
);
495 void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
);
496 wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
);
498 void Expand( unsigned int row
);
499 void Collapse( unsigned int row
);
500 bool IsExpanded( unsigned int row
) const;
501 bool HasChildren( unsigned int row
) const;
503 #if wxUSE_DRAG_AND_DROP
504 bool EnableDragSource( const wxDataFormat
&format
);
505 bool EnableDropTarget( const wxDataFormat
&format
);
507 void RemoveDropHint();
508 wxDragResult
OnDragOver( wxDataFormat format
, wxCoord x
, wxCoord y
, wxDragResult def
);
509 bool OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
);
510 wxDragResult
OnData( wxDataFormat format
, wxCoord x
, wxCoord y
, wxDragResult def
);
512 #endif // wxUSE_DRAG_AND_DROP
515 wxDataViewTreeNode
* GetTreeNodeByRow( unsigned int row
) const;
516 // We did not need this temporarily
517 // wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
519 int RecalculateCount();
521 wxDataViewEvent
SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
);
523 wxDataViewTreeNode
* FindNode( const wxDataViewItem
& item
);
526 wxDataViewCtrl
*m_owner
;
530 wxDataViewColumn
*m_currentCol
;
531 unsigned int m_currentRow
;
532 wxDataViewSelection m_selection
;
534 wxDataViewRenameTimer
*m_renameTimer
;
539 #if wxUSE_DRAG_AND_DROP
544 wxDataFormat m_dragFormat
;
547 wxDataFormat m_dropFormat
;
549 unsigned int m_dropHintLine
;
550 #endif // wxUSE_DRAG_AND_DROP
552 // for double click logic
553 unsigned int m_lineLastClicked
,
554 m_lineBeforeLastClicked
,
555 m_lineSelectSingleOnUp
;
557 // the pen used to draw horiz/vertical rules
560 // the pen used to draw the expander and the lines
563 // This is the tree structure of the model
564 wxDataViewTreeNode
* m_root
;
567 // This is the tree node under the cursor
568 wxDataViewTreeNode
* m_underMouse
;
571 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
572 DECLARE_EVENT_TABLE()
575 // ---------------------------------------------------------
576 // wxGenericDataViewModelNotifier
577 // ---------------------------------------------------------
579 class wxGenericDataViewModelNotifier
: public wxDataViewModelNotifier
582 wxGenericDataViewModelNotifier( wxDataViewMainWindow
*mainWindow
)
583 { m_mainWindow
= mainWindow
; }
585 virtual bool ItemAdded( const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
586 { return m_mainWindow
->ItemAdded( parent
, item
); }
587 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
588 { return m_mainWindow
->ItemDeleted( parent
, item
); }
589 virtual bool ItemChanged( const wxDataViewItem
& item
)
590 { return m_mainWindow
->ItemChanged(item
); }
591 virtual bool ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
592 { return m_mainWindow
->ValueChanged( item
, col
); }
593 virtual bool Cleared()
594 { return m_mainWindow
->Cleared(); }
595 virtual void Resort()
596 { m_mainWindow
->Resort(); }
598 wxDataViewMainWindow
*m_mainWindow
;
601 // ---------------------------------------------------------
602 // wxDataViewRenderer
603 // ---------------------------------------------------------
605 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
607 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
608 wxDataViewCellMode mode
,
610 wxDataViewCustomRendererBase( varianttype
, mode
, align
)
614 m_ellipsizeMode
= wxELLIPSIZE_MIDDLE
;
618 wxDataViewRenderer::~wxDataViewRenderer()
623 wxDC
*wxDataViewRenderer::GetDC()
627 if (GetOwner() == NULL
)
629 if (GetOwner()->GetOwner() == NULL
)
631 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
637 void wxDataViewRenderer::SetAlignment( int align
)
642 int wxDataViewRenderer::GetAlignment() const
647 int wxDataViewRenderer::CalculateAlignment() const
649 if (m_align
== wxDVR_DEFAULT_ALIGNMENT
)
651 if (GetOwner() == NULL
)
652 return wxALIGN_LEFT
| wxALIGN_CENTRE_VERTICAL
;
654 return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
661 wxDataViewRenderer::RenderWithAttr(wxDC
& dc
,
662 const wxRect
& cell_rect
,
664 const wxDataViewItemAttr
*WXUNUSED(attr
),
667 // adjust the rectangle ourselves to account for the alignment
669 wxRect item_rect
= cell_rect
;
672 const wxSize size
= GetSize();
674 // take alignment into account only if there is enough space, otherwise
675 // show as much contents as possible
677 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
678 // return hard-coded size which can be more than they need and if we
679 // trusted their GetSize() we'd draw the text out of cell bounds
682 if ( size
.x
< cell_rect
.width
)
684 if (align
& wxALIGN_CENTER_HORIZONTAL
)
685 item_rect
.x
+= (cell_rect
.width
- size
.x
)/2;
686 else if (align
& wxALIGN_RIGHT
)
687 item_rect
.x
+= cell_rect
.width
- size
.x
;
688 // else: wxALIGN_LEFT is the default
690 item_rect
.width
= size
.x
;
693 if ( size
.y
< cell_rect
.height
)
695 if (align
& wxALIGN_CENTER_VERTICAL
)
696 item_rect
.y
+= (cell_rect
.height
- size
.y
)/2;
697 else if (align
& wxALIGN_BOTTOM
)
698 item_rect
.y
+= cell_rect
.height
- size
.y
;
699 // else: wxALIGN_TOP is the default
701 item_rect
.height
= size
.y
;
705 return Render(item_rect
, &dc
, state
);
709 wxDataViewRenderer::RenderText(wxDC
& dc
,
712 const wxString
& text
,
713 const wxDataViewItemAttr
*attr
,
717 // override custom foreground with the standard one for the selected items
718 // because we currently don't allow changing the selection background and
719 // custom colours may be unreadable on it
721 if ( state
& wxDATAVIEW_CELL_SELECTED
)
722 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
723 else if ( attr
&& attr
->HasColour() )
724 col
= attr
->GetColour();
725 else // use default foreground
726 col
= GetOwner()->GetOwner()->GetForegroundColour();
728 wxDCTextColourChanger
changeFg(dc
, col
);
730 wxDCFontChanger
changeFont(dc
);
731 if ( attr
&& attr
->HasFont() )
733 wxFont
font(dc
.GetFont());
734 if ( attr
->GetBold() )
736 if ( attr
->GetItalic() )
739 changeFont
.Set(font
);
742 wxRect rectText
= rect
;
743 rectText
.x
+= xoffset
;
744 rectText
.width
-= xoffset
;
746 // check if we want to ellipsize the text if it doesn't fit
747 wxString ellipsizedText
;
748 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
750 ellipsizedText
= wxControl::Ellipsize
756 wxELLIPSIZE_FLAGS_NONE
760 dc
.DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
764 // ---------------------------------------------------------
765 // wxDataViewCustomRenderer
766 // ---------------------------------------------------------
768 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
770 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
771 wxDataViewCellMode mode
, int align
) :
772 wxDataViewRenderer( varianttype
, mode
, align
)
776 // ---------------------------------------------------------
777 // wxDataViewTextRenderer
778 // ---------------------------------------------------------
780 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
782 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
783 wxDataViewCellMode mode
, int align
) :
784 wxDataViewRenderer( varianttype
, mode
, align
)
788 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
790 m_text
= value
.GetString();
795 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
800 bool wxDataViewTextRenderer::HasEditorCtrl() const
805 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
806 wxRect labelRect
, const wxVariant
&value
)
808 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, value
,
809 wxPoint(labelRect
.x
,labelRect
.y
),
810 wxSize(labelRect
.width
,labelRect
.height
) );
812 // select the text in the control an place the cursor at the end
813 ctrl
->SetInsertionPointEnd();
819 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
821 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
822 value
= text
->GetValue();
827 wxDataViewTextRenderer::RenderWithAttr(wxDC
& dc
,
830 const wxDataViewItemAttr
*attr
,
833 RenderText(dc
, rect
, align
, m_text
, attr
, state
);
837 wxSize
wxDataViewTextRenderer::GetSize() const
839 const wxDataViewCtrl
*view
= GetView();
841 return view
->wxWindowBase::GetTextExtent( m_text
);
842 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
845 // ---------------------------------------------------------
846 // wxDataViewBitmapRenderer
847 // ---------------------------------------------------------
849 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
851 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
852 wxDataViewCellMode mode
, int align
) :
853 wxDataViewRenderer( varianttype
, mode
, align
)
857 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
859 if (value
.GetType() == wxT("wxBitmap"))
861 if (value
.GetType() == wxT("wxIcon"))
867 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
872 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
875 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
876 else if (m_icon
.Ok())
877 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
882 wxSize
wxDataViewBitmapRenderer::GetSize() const
885 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
886 else if (m_icon
.Ok())
887 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
889 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
892 // ---------------------------------------------------------
893 // wxDataViewToggleRenderer
894 // ---------------------------------------------------------
896 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
898 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
899 wxDataViewCellMode mode
, int align
) :
900 wxDataViewRenderer( varianttype
, mode
, align
)
905 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
907 m_toggle
= value
.GetBool();
912 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
917 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
921 flags
|= wxCONTROL_CHECKED
;
922 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
923 flags
|= wxCONTROL_DISABLED
;
925 wxRendererNative::Get().DrawCheckBox(
926 GetOwner()->GetOwner(),
934 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
935 wxDataViewModel
*model
,
936 const wxDataViewItem
& item
, unsigned int col
)
938 model
->ChangeValue(!m_toggle
, item
, col
);
942 wxSize
wxDataViewToggleRenderer::GetSize() const
944 // the window parameter is not used by GetCheckBoxSize() so it's
946 return wxRendererNative::Get().GetCheckBoxSize(NULL
);
949 // ---------------------------------------------------------
950 // wxDataViewProgressRenderer
951 // ---------------------------------------------------------
953 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewRenderer
)
955 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
956 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
957 wxDataViewRenderer( varianttype
, mode
, align
)
963 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
965 m_value
= (long) value
;
967 if (m_value
< 0) m_value
= 0;
968 if (m_value
> 100) m_value
= 100;
973 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
975 value
= (long) m_value
;
979 bool wxDataViewProgressRenderer::RenderWithAttr(wxDC
& dc
,
982 const wxDataViewItemAttr
*attr
,
985 // deflat the rect to leave a small border between bars in adjacent rows
986 wxRect bar
= rect
.Deflate(0, 1);
988 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
989 dc
.SetPen( *wxBLACK_PEN
);
990 dc
.DrawRectangle( bar
);
992 bar
.width
= (int)(bar
.width
* m_value
/ 100.);
993 dc
.SetPen( *wxTRANSPARENT_PEN
);
994 dc
.SetBrush( attr
&& attr
->HasColour() ? wxBrush(attr
->GetColour())
996 dc
.DrawRectangle( bar
);
1001 wxSize
wxDataViewProgressRenderer::GetSize() const
1003 return wxSize(40,12);
1006 // ---------------------------------------------------------
1007 // wxDataViewDateRenderer
1008 // ---------------------------------------------------------
1010 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
1012 #if wxUSE_DATE_RENDERER_POPUP
1014 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1017 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1018 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
) :
1019 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
),
1024 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
1025 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1026 sizer
->Add( m_cal
, 1, wxGROW
);
1031 void OnCalendar( wxCalendarEvent
&event
);
1033 wxCalendarCtrl
*m_cal
;
1034 wxDataViewModel
*m_model
;
1036 const wxDataViewItem
& m_item
;
1039 virtual void OnDismiss()
1044 DECLARE_EVENT_TABLE()
1047 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1048 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
1051 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1053 m_model
->ChangeValue( event
.GetDate(), m_item
, m_col
);
1057 #endif // wxUSE_DATE_RENDERER_POPUP
1059 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewRenderer
)
1061 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1062 wxDataViewCellMode mode
, int align
) :
1063 wxDataViewRenderer( varianttype
, mode
, align
)
1067 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1069 m_date
= value
.GetDateTime();
1074 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1080 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1082 wxString tmp
= m_date
.FormatDate();
1083 RenderText( tmp
, 0, cell
, dc
, state
);
1087 wxSize
wxDataViewDateRenderer::GetSize() const
1089 const wxDataViewCtrl
* view
= GetView();
1090 wxString tmp
= m_date
.FormatDate();
1092 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1093 return wxSize(x
,y
+d
);
1096 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
1097 const wxDataViewItem
& item
, unsigned int col
)
1100 model
->GetValue( variant
, item
, col
);
1101 wxDateTime value
= variant
.GetDateTime();
1103 #if wxUSE_DATE_RENDERER_POPUP
1104 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1105 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1106 wxPoint pos
= wxGetMousePosition();
1109 popup
->Popup( popup
->m_cal
);
1110 #else // !wxUSE_DATE_RENDERER_POPUP
1111 wxMessageBox(value
.Format());
1112 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
1116 // ---------------------------------------------------------
1117 // wxDataViewIconTextRenderer
1118 // ---------------------------------------------------------
1120 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewRenderer
)
1122 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1123 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1124 wxDataViewRenderer( varianttype
, mode
, align
)
1127 SetAlignment(align
);
1130 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1136 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1142 wxDataViewIconTextRenderer::RenderWithAttr(wxDC
& dc
,
1145 const wxDataViewItemAttr
*attr
,
1150 const wxIcon
& icon
= m_value
.GetIcon();
1153 dc
.DrawIcon(icon
, rect
.x
, rect
.y
+ (rect
.height
- icon
.GetHeight())/2);
1154 xoffset
= icon
.GetWidth()+4;
1157 RenderText(dc
, rect
, align
, m_value
.GetText(), attr
, state
, xoffset
);
1162 wxSize
wxDataViewIconTextRenderer::GetSize() const
1164 const wxDataViewCtrl
*view
= GetView();
1165 if (!m_value
.GetText().empty())
1168 view
->GetTextExtent( m_value
.GetText(), &x
, &y
);
1170 if (m_value
.GetIcon().IsOk())
1171 x
+= m_value
.GetIcon().GetWidth() + 4;
1172 return wxSize( x
, y
);
1174 return wxSize(80,20);
1177 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1179 wxDataViewIconText iconText
;
1182 wxString text
= iconText
.GetText();
1184 // adjust the label rect to take the width of the icon into account
1185 if (iconText
.GetIcon().IsOk())
1187 int w
= iconText
.GetIcon().GetWidth() + 4;
1189 labelRect
.width
-= w
;
1192 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, text
,
1193 wxPoint(labelRect
.x
,labelRect
.y
),
1194 wxSize(labelRect
.width
,labelRect
.height
) );
1196 // select the text in the control an place the cursor at the end
1197 ctrl
->SetInsertionPointEnd();
1203 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
& value
)
1205 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
1207 wxDataViewIconText
iconText(text
->GetValue(), m_value
.GetIcon());
1212 //-----------------------------------------------------------------------------
1213 // wxDataViewDropTarget
1214 //-----------------------------------------------------------------------------
1216 #if wxUSE_DRAG_AND_DROP
1218 class wxBitmapCanvas
: public wxWindow
1221 wxBitmapCanvas( wxWindow
*parent
, const wxBitmap
&bitmap
, const wxSize
&size
) :
1222 wxWindow( parent
, wxID_ANY
, wxPoint(0,0), size
)
1225 Connect( wxEVT_PAINT
, wxPaintEventHandler(wxBitmapCanvas::OnPaint
) );
1228 void OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1231 dc
.DrawBitmap( m_bitmap
, 0, 0);
1237 class wxDataViewDropSource
: public wxDropSource
1240 wxDataViewDropSource( wxDataViewMainWindow
*win
, unsigned int row
) :
1248 ~wxDataViewDropSource()
1253 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
) )
1255 wxPoint pos
= wxGetMousePosition();
1259 int liney
= m_win
->GetLineStart( m_row
);
1261 m_win
->GetOwner()->CalcUnscrolledPosition( 0, liney
, NULL
, &liney
);
1262 m_win
->ClientToScreen( &linex
, &liney
);
1263 m_dist_x
= pos
.x
- linex
;
1264 m_dist_y
= pos
.y
- liney
;
1267 wxBitmap ib
= m_win
->CreateItemBitmap( m_row
, indent
);
1269 m_hint
= new wxFrame( m_win
->GetParent(), wxID_ANY
, wxEmptyString
,
1270 wxPoint(pos
.x
- m_dist_x
, pos
.y
+ 5 ),
1272 wxFRAME_TOOL_WINDOW
|
1273 wxFRAME_FLOAT_ON_PARENT
|
1274 wxFRAME_NO_TASKBAR
|
1276 new wxBitmapCanvas( m_hint
, ib
, ib
.GetSize() );
1281 m_hint
->Move( pos
.x
- m_dist_x
, pos
.y
+ 5 );
1282 m_hint
->SetTransparent( 128 );
1288 wxDataViewMainWindow
*m_win
;
1291 int m_dist_x
,m_dist_y
;
1295 class wxDataViewDropTarget
: public wxDropTarget
1298 wxDataViewDropTarget( wxDataObject
*obj
, wxDataViewMainWindow
*win
) :
1304 virtual wxDragResult
OnDragOver( wxCoord x
, wxCoord y
, wxDragResult def
)
1306 wxDataFormat format
= GetMatchingPair();
1307 if (format
== wxDF_INVALID
)
1309 return m_win
->OnDragOver( format
, x
, y
, def
);
1312 virtual bool OnDrop( wxCoord x
, wxCoord y
)
1314 wxDataFormat format
= GetMatchingPair();
1315 if (format
== wxDF_INVALID
)
1317 return m_win
->OnDrop( format
, x
, y
);
1320 virtual wxDragResult
OnData( wxCoord x
, wxCoord y
, wxDragResult def
)
1322 wxDataFormat format
= GetMatchingPair();
1323 if (format
== wxDF_INVALID
)
1327 return m_win
->OnData( format
, x
, y
, def
);
1330 virtual void OnLeave()
1331 { m_win
->OnLeave(); }
1333 wxDataViewMainWindow
*m_win
;
1336 #endif // wxUSE_DRAG_AND_DROP
1338 //-----------------------------------------------------------------------------
1339 // wxDataViewRenameTimer
1340 //-----------------------------------------------------------------------------
1342 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1347 void wxDataViewRenameTimer::Notify()
1349 m_owner
->OnRenameTimer();
1352 //-----------------------------------------------------------------------------
1353 // wxDataViewMainWindow
1354 //-----------------------------------------------------------------------------
1356 // The tree building helper, declared firstly
1357 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
1358 wxDataViewTreeNode
* node
);
1360 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1362 if (row1
> row2
) return 1;
1363 if (row1
== row2
) return 0;
1367 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1369 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1370 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1371 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1372 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1373 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1374 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1377 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1378 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1379 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
1380 m_selection( wxDataViewSelectionCmp
)
1385 m_lastOnSame
= false;
1386 m_renameTimer
= new wxDataViewRenameTimer( this );
1388 // TODO: user better initial values/nothing selected
1389 m_currentCol
= NULL
;
1392 m_lineHeight
= wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
1394 #if wxUSE_DRAG_AND_DROP
1396 m_dragStart
= wxPoint(0,0);
1398 m_dragEnabled
= false;
1399 m_dropEnabled
= false;
1401 m_dropHintLine
= (unsigned int) -1;
1402 #endif // wxUSE_DRAG_AND_DROP
1404 m_lineLastClicked
= (unsigned int) -1;
1405 m_lineBeforeLastClicked
= (unsigned int) -1;
1406 m_lineSelectSingleOnUp
= (unsigned int) -1;
1410 SetBackgroundColour( *wxWHITE
);
1412 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1414 m_penRule
= wxPen(GetRuleColour());
1416 // compose a pen whichcan draw black lines
1417 // TODO: maybe there is something system colour to use
1418 m_penExpander
= wxPen(wxColour(0,0,0));
1420 m_root
= new wxDataViewTreeNode( NULL
);
1421 m_root
->SetHasChildren(true);
1423 // Make m_count = -1 will cause the class recaculate the real displaying number of rows.
1425 m_underMouse
= NULL
;
1429 wxDataViewMainWindow::~wxDataViewMainWindow()
1432 delete m_renameTimer
;
1436 #if wxUSE_DRAG_AND_DROP
1437 bool wxDataViewMainWindow::EnableDragSource( const wxDataFormat
&format
)
1439 m_dragFormat
= format
;
1440 m_dragEnabled
= format
!= wxDF_INVALID
;
1445 bool wxDataViewMainWindow::EnableDropTarget( const wxDataFormat
&format
)
1447 m_dropFormat
= format
;
1448 m_dropEnabled
= format
!= wxDF_INVALID
;
1451 SetDropTarget( new wxDataViewDropTarget( new wxCustomDataObject( format
), this ) );
1456 void wxDataViewMainWindow::RemoveDropHint()
1461 RefreshRow( m_dropHintLine
);
1462 m_dropHintLine
= (unsigned int) -1;
1466 wxDragResult
wxDataViewMainWindow::OnDragOver( wxDataFormat format
, wxCoord x
,
1467 wxCoord y
, wxDragResult def
)
1471 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1472 unsigned int row
= GetLineAt( yy
);
1474 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1480 wxDataViewItem item
= GetItemByRow( row
);
1482 wxDataViewModel
*model
= GetOwner()->GetModel();
1484 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1485 event
.SetEventObject( m_owner
);
1486 event
.SetItem( item
);
1487 event
.SetModel( model
);
1488 event
.SetDataFormat( format
);
1489 if (!m_owner
->HandleWindowEvent( event
))
1495 if (!event
.IsAllowed())
1502 if (m_dropHint
&& (row
!= m_dropHintLine
))
1503 RefreshRow( m_dropHintLine
);
1505 m_dropHintLine
= row
;
1511 bool wxDataViewMainWindow::OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
)
1517 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1518 unsigned int row
= GetLineAt( yy
);
1520 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1523 wxDataViewItem item
= GetItemByRow( row
);
1525 wxDataViewModel
*model
= GetOwner()->GetModel();
1527 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1528 event
.SetEventObject( m_owner
);
1529 event
.SetItem( item
);
1530 event
.SetModel( model
);
1531 event
.SetDataFormat( format
);
1532 if (!m_owner
->HandleWindowEvent( event
))
1535 if (!event
.IsAllowed())
1541 wxDragResult
wxDataViewMainWindow::OnData( wxDataFormat format
, wxCoord x
, wxCoord y
,
1546 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1547 unsigned int row
= GetLineAt( yy
);
1549 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1552 wxDataViewItem item
= GetItemByRow( row
);
1554 wxDataViewModel
*model
= GetOwner()->GetModel();
1556 wxCustomDataObject
*obj
= (wxCustomDataObject
*) GetDropTarget()->GetDataObject();
1558 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
1559 event
.SetEventObject( m_owner
);
1560 event
.SetItem( item
);
1561 event
.SetModel( model
);
1562 event
.SetDataFormat( format
);
1563 event
.SetDataSize( obj
->GetSize() );
1564 event
.SetDataBuffer( obj
->GetData() );
1565 if (!m_owner
->HandleWindowEvent( event
))
1568 if (!event
.IsAllowed())
1574 void wxDataViewMainWindow::OnLeave()
1579 wxBitmap
wxDataViewMainWindow::CreateItemBitmap( unsigned int row
, int &indent
)
1581 int height
= GetLineHeight( row
);
1583 unsigned int cols
= GetOwner()->GetColumnCount();
1585 for (col
= 0; col
< cols
; col
++)
1587 wxDataViewColumn
*column
= GetOwner()->GetColumnAt(col
);
1588 if (column
->IsHidden())
1589 continue; // skip it!
1590 width
+= column
->GetWidth();
1594 if (!IsVirtualList())
1596 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
1597 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
1598 indent
= indent
+ m_lineHeight
;
1599 // try to use the m_lineHeight as the expander space
1601 if(!node
->HasChildren())
1606 wxBitmap
bitmap( width
, height
);
1607 wxMemoryDC
dc( bitmap
);
1608 dc
.SetFont( GetFont() );
1609 dc
.SetPen( *wxBLACK_PEN
);
1610 dc
.SetBrush( *wxWHITE_BRUSH
);
1611 dc
.DrawRectangle( 0,0,width
,height
);
1613 wxDataViewModel
*model
= m_owner
->GetModel();
1615 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1618 // TODO-RTL: last column for RTL support
1619 expander
= GetOwner()->GetColumnAt( 0 );
1620 GetOwner()->SetExpanderColumn(expander
);
1625 for (col
= 0; col
< cols
; col
++)
1627 wxDataViewColumn
*column
= GetOwner()->GetColumnAt( col
);
1628 wxDataViewRenderer
*cell
= column
->GetRenderer();
1630 if (column
->IsHidden())
1631 continue; // skip it!
1633 width
= column
->GetWidth();
1635 if (column
== expander
)
1639 wxDataViewItem item
= GetItemByRow( row
);
1640 model
->GetValue( value
, item
, column
->GetModelColumn());
1641 cell
->SetValue( value
);
1643 wxRect
item_rect(x
, 0, width
, height
);
1644 item_rect
.Deflate(PADDING_RIGHTLEFT
, 0);
1646 // dc.SetClippingRegion( item_rect );
1647 wxDataViewItemAttr attr
;
1649 hasAttr
= model
->GetAttr(item
, column
->GetModelColumn(), attr
);
1650 cell
->RenderWithAttr(dc
, item_rect
, cell
->CalculateAlignment(),
1651 hasAttr
? &attr
: NULL
, 0);
1652 // dc.DestroyClippingRegion();
1660 #endif // wxUSE_DRAG_AND_DROP
1663 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1665 wxDataViewModel
*model
= GetOwner()->GetModel();
1666 wxAutoBufferedPaintDC
dc( this );
1669 dc
.SetBrush(GetOwner()->GetBackgroundColour());
1670 dc
.SetPen( *wxTRANSPARENT_PEN
);
1671 dc
.DrawRectangle(GetClientSize());
1675 GetOwner()->PrepareDC( dc
);
1676 dc
.SetFont( GetFont() );
1678 wxRect update
= GetUpdateRegion().GetBox();
1679 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1681 // compute which items needs to be redrawn
1682 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
1683 unsigned int item_count
=
1684 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
1685 (int)(GetRowCount( ) - item_start
));
1686 unsigned int item_last
= item_start
+ item_count
;
1687 // Get the parent of DataViewCtrl
1688 wxWindow
*parent
= GetParent()->GetParent();
1689 wxDataViewEvent
cache_event(wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, parent
->GetId());
1690 cache_event
.SetEventObject(GetParent());
1691 cache_event
.SetCache(item_start
, item_last
- 1);
1692 parent
->ProcessWindowEvent(cache_event
);
1694 // compute which columns needs to be redrawn
1695 unsigned int cols
= GetOwner()->GetColumnCount();
1696 unsigned int col_start
= 0;
1697 unsigned int x_start
;
1698 for (x_start
= 0; col_start
< cols
; col_start
++)
1700 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_start
);
1701 if (col
->IsHidden())
1702 continue; // skip it!
1704 unsigned int w
= col
->GetWidth();
1705 if (x_start
+w
>= (unsigned int)update
.x
)
1711 unsigned int col_last
= col_start
;
1712 unsigned int x_last
= x_start
;
1713 for (; col_last
< cols
; col_last
++)
1715 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_last
);
1716 if (col
->IsHidden())
1717 continue; // skip it!
1719 if (x_last
> (unsigned int)update
.GetRight())
1722 x_last
+= col
->GetWidth();
1725 // Draw horizontal rules if required
1726 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1728 dc
.SetPen(m_penRule
);
1729 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1731 for (unsigned int i
= item_start
; i
<= item_last
; i
++)
1733 int y
= GetLineStart( i
);
1734 dc
.DrawLine(x_start
, y
, x_last
, y
);
1738 // Draw vertical rules if required
1739 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1741 dc
.SetPen(m_penRule
);
1742 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1745 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1747 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(i
);
1748 if (col
->IsHidden())
1749 continue; // skip it
1751 dc
.DrawLine(x
, GetLineStart( item_start
),
1752 x
, GetLineStart( item_last
) );
1754 x
+= col
->GetWidth();
1757 // Draw last vertical rule
1758 dc
.DrawLine(x
, GetLineStart( item_start
),
1759 x
, GetLineStart( item_last
) );
1762 // redraw the background for the items which are selected/current
1763 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1765 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1766 if (selected
|| item
== m_currentRow
)
1768 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
1769 if (item
== m_currentRow
)
1770 flags
|= wxCONTROL_CURRENT
;
1772 flags
|= wxCONTROL_FOCUSED
;
1774 wxRect
rect( x_start
, GetLineStart( item
), x_last
, GetLineHeight( item
) );
1775 wxRendererNative::Get().DrawItemSelectionRect
1785 #if wxUSE_DRAG_AND_DROP
1788 wxRect
rect( x_start
, GetLineStart( m_dropHintLine
),
1789 x_last
, GetLineHeight( m_dropHintLine
) );
1790 dc
.SetPen( *wxBLACK_PEN
);
1791 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1792 dc
.DrawRectangle( rect
);
1794 #endif // wxUSE_DRAG_AND_DROP
1796 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1799 // TODO-RTL: last column for RTL support
1800 expander
= GetOwner()->GetColumnAt( 0 );
1801 GetOwner()->SetExpanderColumn(expander
);
1804 // redraw all cells for all rows which must be repainted and all columns
1806 cell_rect
.x
= x_start
;
1807 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1809 wxDataViewColumn
*col
= GetOwner()->GetColumnAt( i
);
1810 wxDataViewRenderer
*cell
= col
->GetRenderer();
1811 cell_rect
.width
= col
->GetWidth();
1813 if (col
->IsHidden())
1814 continue; // skip it!
1816 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1818 // get the cell value and set it into the renderer
1820 wxDataViewTreeNode
*node
= NULL
;
1821 wxDataViewItem dataitem
;
1823 if (!IsVirtualList())
1825 node
= GetTreeNodeByRow(item
);
1829 dataitem
= node
->GetItem();
1831 if ((i
> 0) && model
->IsContainer(dataitem
) &&
1832 !model
->HasContainerColumns(dataitem
))
1837 dataitem
= wxDataViewItem( wxUIntToPtr(item
+1) );
1840 model
->GetValue( value
, dataitem
, col
->GetModelColumn());
1841 cell
->SetValue( value
);
1844 cell_rect
.y
= GetLineStart( item
);
1845 cell_rect
.height
= GetLineHeight( item
);
1847 // Draw the expander here.
1849 if ((!IsVirtualList()) && (col
== expander
))
1851 indent
= node
->GetIndentLevel();
1853 // Calculate the indent first
1854 indent
= cell_rect
.x
+ GetOwner()->GetIndent() * indent
;
1856 int expander_width
= m_lineHeight
- 2*EXPANDER_MARGIN
;
1858 // change the cell_rect.x to the appropriate pos
1859 int expander_x
= indent
+ EXPANDER_MARGIN
;
1860 int expander_y
= cell_rect
.y
+ EXPANDER_MARGIN
+ (GetLineHeight(item
) / 2)
1861 - (expander_width
/2) - EXPANDER_OFFSET
;
1863 indent
= indent
+ m_lineHeight
;
1864 // try to use the m_lineHeight as the expander space
1866 dc
.SetPen( m_penExpander
);
1867 dc
.SetBrush( wxNullBrush
);
1868 if( node
->HasChildren() )
1870 wxRect
rect( expander_x
, expander_y
, expander_width
, expander_width
);
1872 if (m_underMouse
== node
)
1874 flag
|= wxCONTROL_CURRENT
;
1876 if( node
->IsOpen() )
1877 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
,
1878 flag
|wxCONTROL_EXPANDED
);
1880 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
1883 // force the expander column to left-center align
1884 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
1886 if (node
&& !node
->HasChildren())
1888 // Yes, if the node does not have any child, it must be a leaf which
1889 // mean that it is a temporarily created by GetTreeNodeByRow
1893 wxRect item_rect
= cell_rect
;
1894 item_rect
.Deflate(PADDING_RIGHTLEFT
, 0);
1896 // account for the tree indent (harmless if we're not indented)
1897 item_rect
.x
+= indent
;
1898 item_rect
.width
-= indent
;
1901 if (m_hasFocus
&& (m_selection
.Index(item
) != wxNOT_FOUND
))
1902 state
|= wxDATAVIEW_CELL_SELECTED
;
1904 // TODO: it would be much more efficient to create a clipping
1905 // region for the entire column being rendered (in the OnPaint
1906 // of wxDataViewMainWindow) instead of a single clip region for
1907 // each cell. However it would mean that each renderer should
1908 // respect the given wxRect's top & bottom coords, eventually
1909 // violating only the left & right coords - however the user can
1910 // make its own renderer and thus we cannot be sure of that.
1911 wxDCClipper
clip(dc
, item_rect
);
1913 wxDataViewItemAttr attr
;
1915 hasAttr
= model
->GetAttr(dataitem
, col
->GetModelColumn(), attr
);
1916 cell
->RenderWithAttr(dc
, item_rect
, cell
->CalculateAlignment(),
1917 hasAttr
? &attr
: NULL
, state
);
1920 cell_rect
.x
+= cell_rect
.width
;
1924 void wxDataViewMainWindow::OnRenameTimer()
1926 // We have to call this here because changes may just have
1927 // been made and no screen update taken place.
1930 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
1931 // (needs to be tested!)
1935 wxDataViewItem item
= GetItemByRow( m_currentRow
);
1937 wxRect labelRect
= GetItemRect(item
, m_currentCol
);
1939 m_currentCol
->GetRenderer()->StartEditing( item
, labelRect
);
1942 //-----------------------------------------------------------------------------
1943 // Helper class for do operation on the tree node
1944 //-----------------------------------------------------------------------------
1949 virtual ~DoJob() { }
1951 // The return value control how the tree-walker tranverse the tree
1952 // 0: Job done, stop tranverse and return
1953 // 1: Ignore the current node's subtree and continue
1954 // 2: Job not done, continue
1955 enum { OK
= 0 , IGR
= 1, CONT
= 2 };
1956 virtual int operator() ( wxDataViewTreeNode
* node
) = 0;
1957 virtual int operator() ( void * n
) = 0;
1960 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
1965 switch( func( node
) )
1976 wxDataViewTreeNodes nodes
= node
->GetNodes();
1977 wxDataViewTreeLeaves leaves
= node
->GetChildren();
1979 int len_nodes
= nodes
.GetCount();
1980 int len
= leaves
.GetCount();
1981 int i
= 0, nodes_i
= 0;
1983 for(; i
< len
; i
++ )
1985 void * n
= leaves
[i
];
1986 if( nodes_i
< len_nodes
&& n
== nodes
[nodes_i
]->GetItem().GetID() )
1988 wxDataViewTreeNode
* nd
= nodes
[nodes_i
];
1991 if( Walker( nd
, func
) )
2010 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
2012 if (IsVirtualList())
2014 wxDataViewVirtualListModel
*list_model
=
2015 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
2016 m_count
= list_model
->GetCount();
2023 wxDataViewTreeNode
* node
;
2024 node
= FindNode(parent
);
2029 node
->SetHasChildren( true );
2031 if( g_model
->IsContainer( item
) )
2033 wxDataViewTreeNode
* newnode
= new wxDataViewTreeNode( node
);
2034 newnode
->SetItem(item
);
2035 newnode
->SetHasChildren( true );
2036 node
->AddNode( newnode
);
2039 node
->AddLeaf( item
.GetID() );
2041 node
->ChangeSubTreeCount(1);
2049 static void DestroyTreeHelper( wxDataViewTreeNode
* node
);
2051 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
2052 const wxDataViewItem
& item
)
2054 if (IsVirtualList())
2056 wxDataViewVirtualListModel
*list_model
=
2057 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
2058 m_count
= list_model
->GetCount();
2060 if( m_currentRow
> GetRowCount() )
2061 m_currentRow
= m_count
- 1;
2063 // TODO: why empty the entire selection?
2064 m_selection
.Empty();
2071 wxDataViewTreeNode
* node
= FindNode(parent
);
2073 wxCHECK_MSG( node
!= NULL
, false, "item not found" );
2074 wxCHECK_MSG( node
->GetChildren().Index( item
.GetID() ) != wxNOT_FOUND
,
2075 false, "item not found" );
2078 node
->GetChildren().Remove( item
.GetID() );
2079 // Manipolate selection
2080 if( m_selection
.GetCount() > 1 )
2082 m_selection
.Empty();
2084 bool isContainer
= false;
2085 wxDataViewTreeNodes nds
= node
->GetNodes();
2086 for (size_t i
= 0; i
< nds
.GetCount(); i
++)
2088 if (nds
[i
]->GetItem() == item
)
2096 wxDataViewTreeNode
* n
= NULL
;
2097 wxDataViewTreeNodes nodes
= node
->GetNodes();
2098 int len
= nodes
.GetCount();
2099 for( int i
= 0; i
< len
; i
++)
2101 if( nodes
[i
]->GetItem() == item
)
2108 wxCHECK_MSG( n
!= NULL
, false, "item not found" );
2110 node
->GetNodes().Remove( n
);
2111 sub
-= n
->GetSubTreeCount();
2112 ::DestroyTreeHelper(n
);
2114 // Make the row number invalid and get a new valid one when user call GetRowCount
2116 node
->ChangeSubTreeCount(sub
);
2118 // Change the current row to the last row if the current exceed the max row number
2119 if( m_currentRow
> GetRowCount() )
2120 m_currentRow
= m_count
- 1;
2127 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
2133 wxWindow
*parent
= GetParent();
2134 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2135 le
.SetEventObject(parent
);
2136 le
.SetModel(GetOwner()->GetModel());
2138 parent
->GetEventHandler()->ProcessEvent(le
);
2143 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
2145 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
2146 /*#define MAX_VIRTUAL_WIDTH 100000
2148 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
2149 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2150 Refresh( true, &rect );
2158 wxWindow
*parent
= GetParent();
2159 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2160 le
.SetEventObject(parent
);
2161 le
.SetModel(GetOwner()->GetModel());
2164 le
.SetDataViewColumn(GetOwner()->GetColumn(col
));
2165 parent
->GetEventHandler()->ProcessEvent(le
);
2170 bool wxDataViewMainWindow::Cleared()
2175 BuildTree( GetOwner()->GetModel() );
2182 void wxDataViewMainWindow::UpdateDisplay()
2187 void wxDataViewMainWindow::OnInternalIdle()
2189 wxWindow::OnInternalIdle();
2193 RecalculateDisplay();
2198 void wxDataViewMainWindow::RecalculateDisplay()
2200 wxDataViewModel
*model
= GetOwner()->GetModel();
2207 int width
= GetEndOfLastCol();
2208 int height
= GetLineStart( GetRowCount() );
2210 SetVirtualSize( width
, height
);
2211 GetOwner()->SetScrollRate( 10, m_lineHeight
);
2216 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2218 wxWindow::ScrollWindow( dx
, dy
, rect
);
2220 if (GetOwner()->m_headerArea
)
2221 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
2224 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
2227 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
2228 int sy
= GetLineStart( rows
)/y
;
2232 wxRect rect
= GetClientRect();
2236 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
2237 for (x_start
= 0; colnum
< column
; colnum
++)
2239 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(colnum
);
2240 if (col
->IsHidden())
2241 continue; // skip it!
2243 w
= col
->GetWidth();
2247 int x_end
= x_start
+ w
;
2248 xe
= xx
+ rect
.width
;
2251 sx
= ( xx
+ x_end
- xe
)/x
;
2258 m_owner
->Scroll( sx
, sy
);
2261 int wxDataViewMainWindow::GetCountPerPage() const
2263 wxSize size
= GetClientSize();
2264 return size
.y
/ m_lineHeight
;
2267 int wxDataViewMainWindow::GetEndOfLastCol() const
2271 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2273 const wxDataViewColumn
*c
=
2274 const_cast<wxDataViewCtrl
*>(GetOwner())->GetColumnAt( i
);
2277 width
+= c
->GetWidth();
2282 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2286 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2288 return GetLineAt( y
);
2291 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
2293 wxSize client_size
= GetClientSize();
2294 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2295 &client_size
.x
, &client_size
.y
);
2297 // we should deal with the pixel here
2298 unsigned int row
= GetLineAt(client_size
.y
) - 1;
2300 return wxMin( GetRowCount()-1, row
);
2303 unsigned int wxDataViewMainWindow::GetRowCount()
2305 if ( m_count
== -1 )
2307 m_count
= RecalculateCount();
2313 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
2320 void wxDataViewMainWindow::SelectAllRows( bool on
)
2327 m_selection
.Clear();
2328 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2329 m_selection
.Add( i
);
2334 unsigned int first_visible
= GetFirstVisibleRow();
2335 unsigned int last_visible
= GetLastVisibleRow();
2337 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2339 unsigned int row
= m_selection
[i
];
2340 if ((row
>= first_visible
) && (row
<= last_visible
))
2343 m_selection
.Clear();
2347 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
2349 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2353 m_selection
.Add( row
);
2361 m_selection
.Remove( row
);
2367 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2371 unsigned int tmp
= from
;
2377 for (i
= from
; i
<= to
; i
++)
2379 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2382 m_selection
.Add( i
);
2387 m_selection
.Remove( i
);
2390 RefreshRows( from
, to
);
2393 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2395 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2397 int n
= aSelections
[i
];
2399 m_selection
.Add( n
);
2404 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2406 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2407 m_selection
.Add( row
);
2409 m_selection
.Remove( row
);
2413 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2415 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2418 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
2420 wxWindow
*parent
= GetParent();
2421 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
2423 le
.SetEventObject(parent
);
2424 le
.SetModel(GetOwner()->GetModel());
2427 parent
->GetEventHandler()->ProcessEvent(le
);
2430 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2432 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
2433 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2435 wxSize client_size
= GetClientSize();
2436 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2437 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2438 if (intersect_rect
.width
> 0)
2439 Refresh( true, &intersect_rect
);
2442 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2446 unsigned int tmp
= to
;
2451 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
2452 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2454 wxSize client_size
= GetClientSize();
2455 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2456 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2457 if (intersect_rect
.width
> 0)
2458 Refresh( true, &intersect_rect
);
2461 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2463 wxSize client_size
= GetClientSize();
2464 int start
= GetLineStart( firstRow
);
2465 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
2466 if (start
> client_size
.y
) return;
2468 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
2470 Refresh( true, &rect
);
2473 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2475 wxCHECK_RET( newCurrent
< GetRowCount(),
2476 wxT("invalid item index in OnArrowChar()") );
2478 // if there is no selection, we cannot move it anywhere
2479 if (!HasCurrentRow())
2482 unsigned int oldCurrent
= m_currentRow
;
2484 // in single selection we just ignore Shift as we can't select several
2486 if ( event
.ShiftDown() && !IsSingleSel() )
2488 RefreshRow( oldCurrent
);
2490 ChangeCurrentRow( newCurrent
);
2492 // select all the items between the old and the new one
2493 if ( oldCurrent
> newCurrent
)
2495 newCurrent
= oldCurrent
;
2496 oldCurrent
= m_currentRow
;
2499 SelectRows( oldCurrent
, newCurrent
, true );
2500 if (oldCurrent
!=newCurrent
)
2501 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
2505 RefreshRow( oldCurrent
);
2507 // all previously selected items are unselected unless ctrl is held
2508 if ( !event
.ControlDown() )
2509 SelectAllRows(false);
2511 ChangeCurrentRow( newCurrent
);
2513 if ( !event
.ControlDown() )
2515 SelectRow( m_currentRow
, true );
2516 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
2519 RefreshRow( m_currentRow
);
2522 GetOwner()->EnsureVisible( m_currentRow
, -1 );
2525 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2529 rect
.y
= GetLineStart( row
);
2530 rect
.width
= GetEndOfLastCol();
2531 rect
.height
= GetLineHeight( row
);
2536 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2538 const wxDataViewModel
*model
= GetOwner()->GetModel();
2540 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2542 // TODO make more efficient
2547 for (r
= 0; r
< row
; r
++)
2549 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2550 if (!node
) return start
;
2552 wxDataViewItem item
= node
->GetItem();
2554 if (node
&& !node
->HasChildren())
2556 // Yes, if the node does not have any child, it must be a leaf which
2557 // mean that it is a temporarily created by GetTreeNodeByRow
2561 unsigned int cols
= GetOwner()->GetColumnCount();
2563 int height
= m_lineHeight
;
2564 for (col
= 0; col
< cols
; col
++)
2566 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2567 if (column
->IsHidden())
2568 continue; // skip it!
2571 model
->IsContainer(item
) &&
2572 !model
->HasContainerColumns(item
))
2573 continue; // skip it!
2576 model
->GetValue( value
, item
, column
->GetModelColumn() );
2578 wxDataViewRenderer
*renderer
=
2579 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2580 renderer
->SetValue( value
);
2581 height
= wxMax( height
, renderer
->GetSize().y
);
2591 return row
* m_lineHeight
;
2595 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
2597 const wxDataViewModel
*model
= GetOwner()->GetModel();
2599 // check for the easy case first
2600 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
2601 return y
/ m_lineHeight
;
2603 // TODO make more efficient
2604 unsigned int row
= 0;
2605 unsigned int yy
= 0;
2608 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2611 // not really correct...
2612 return row
+ ((y
-yy
) / m_lineHeight
);
2615 wxDataViewItem item
= node
->GetItem();
2617 if (node
&& !node
->HasChildren())
2619 // Yes, if the node does not have any child, it must be a leaf which
2620 // mean that it is a temporarily created by GetTreeNodeByRow
2624 unsigned int cols
= GetOwner()->GetColumnCount();
2626 int height
= m_lineHeight
;
2627 for (col
= 0; col
< cols
; col
++)
2629 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2630 if (column
->IsHidden())
2631 continue; // skip it!
2634 model
->IsContainer(item
) &&
2635 !model
->HasContainerColumns(item
))
2636 continue; // skip it!
2639 model
->GetValue( value
, item
, column
->GetModelColumn() );
2641 wxDataViewRenderer
*renderer
=
2642 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2643 renderer
->SetValue( value
);
2644 height
= wxMax( height
, renderer
->GetSize().y
);
2655 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
2657 const wxDataViewModel
*model
= GetOwner()->GetModel();
2659 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2661 wxASSERT( !IsVirtualList() );
2663 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2664 // wxASSERT( node );
2665 if (!node
) return m_lineHeight
;
2667 wxDataViewItem item
= node
->GetItem();
2669 if (node
&& !node
->HasChildren())
2671 // Yes, if the node does not have any child, it must be a leaf which
2672 // mean that it is a temporarily created by GetTreeNodeByRow
2676 int height
= m_lineHeight
;
2678 unsigned int cols
= GetOwner()->GetColumnCount();
2680 for (col
= 0; col
< cols
; col
++)
2682 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2683 if (column
->IsHidden())
2684 continue; // skip it!
2687 model
->IsContainer(item
) &&
2688 !model
->HasContainerColumns(item
))
2689 continue; // skip it!
2692 model
->GetValue( value
, item
, column
->GetModelColumn() );
2694 wxDataViewRenderer
*renderer
=
2695 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2696 renderer
->SetValue( value
);
2697 height
= wxMax( height
, renderer
->GetSize().y
);
2704 return m_lineHeight
;
2708 class RowToItemJob
: public DoJob
2711 RowToItemJob( unsigned int row
, int current
)
2712 { this->row
= row
; this->current
= current
; }
2713 virtual ~RowToItemJob() {}
2715 virtual int operator() ( wxDataViewTreeNode
* node
)
2718 if( current
== static_cast<int>(row
))
2720 ret
= node
->GetItem();
2724 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2726 current
+= node
->GetSubTreeCount();
2731 // If the current has no child node, we can find the desired item of the row
2733 // This if can speed up finding in some case, and will has a very good effect
2734 // when it comes to list view
2735 if( node
->GetNodes().GetCount() == 0)
2737 int index
= static_cast<int>(row
) - current
- 1;
2738 ret
= node
->GetChildren().Item( index
);
2745 virtual int operator() ( void * n
)
2748 if( current
== static_cast<int>(row
))
2750 ret
= wxDataViewItem( n
);
2756 wxDataViewItem
GetResult() const
2765 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
2767 if (IsVirtualList())
2769 return wxDataViewItem( wxUIntToPtr(row
+1) );
2773 RowToItemJob
job( row
, -2 );
2774 Walker( m_root
, job
);
2775 return job
.GetResult();
2779 class RowToTreeNodeJob
: public DoJob
2782 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
2785 this->current
= current
;
2789 virtual ~RowToTreeNodeJob(){ }
2791 virtual int operator() ( wxDataViewTreeNode
* node
)
2794 if( current
== static_cast<int>(row
))
2800 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2802 current
+= node
->GetSubTreeCount();
2809 // If the current node has no children, we can find the desired item of the
2810 // row number directly.
2811 // This if can speed up finding in some case, and will have a very good
2812 // effect for list views.
2813 if( node
->GetNodes().GetCount() == 0)
2815 int index
= static_cast<int>(row
) - current
- 1;
2816 void * n
= node
->GetChildren().Item( index
);
2817 ret
= new wxDataViewTreeNode( parent
);
2818 ret
->SetItem( wxDataViewItem( n
));
2819 ret
->SetHasChildren(false);
2826 virtual int operator() ( void * n
)
2829 if( current
== static_cast<int>(row
))
2831 ret
= new wxDataViewTreeNode( parent
);
2832 ret
->SetItem( wxDataViewItem( n
));
2833 ret
->SetHasChildren(false);
2840 wxDataViewTreeNode
* GetResult() const
2846 wxDataViewTreeNode
* ret
;
2847 wxDataViewTreeNode
* parent
;
2850 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
2852 wxASSERT( !IsVirtualList() );
2854 RowToTreeNodeJob
job( row
, -2, m_root
);
2855 Walker( m_root
, job
);
2856 return job
.GetResult();
2859 wxDataViewEvent
wxDataViewMainWindow::SendExpanderEvent( wxEventType type
,
2860 const wxDataViewItem
& item
)
2862 wxWindow
*parent
= GetParent();
2863 wxDataViewEvent
le(type
, parent
->GetId());
2865 le
.SetEventObject(parent
);
2866 le
.SetModel(GetOwner()->GetModel());
2869 parent
->GetEventHandler()->ProcessEvent(le
);
2873 bool wxDataViewMainWindow::IsExpanded( unsigned int row
) const
2875 if (IsVirtualList())
2878 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2882 if (!node
->HasChildren())
2888 return node
->IsOpen();
2891 bool wxDataViewMainWindow::HasChildren( unsigned int row
) const
2893 if (IsVirtualList())
2896 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2900 if (!node
->HasChildren())
2909 void wxDataViewMainWindow::Expand( unsigned int row
)
2911 if (IsVirtualList())
2914 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2918 if (!node
->HasChildren())
2924 if (!node
->IsOpen())
2927 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, node
->GetItem());
2929 // Check if the user prevent expanding
2930 if( e
.GetSkipped() )
2935 // build the children of current node
2936 if( node
->GetChildrenNumber() == 0 )
2939 ::BuildTreeHelper(GetOwner()->GetModel(), node
->GetItem(), node
);
2942 // By expanding the node all row indices that are currently in the selection list
2943 // and are greater than our node have become invalid. So we have to correct that now.
2944 const unsigned rowAdjustment
= node
->GetSubTreeCount();
2945 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2947 const unsigned testRow
= m_selection
[i
];
2948 // all rows above us are not affected, so skip them
2952 m_selection
[i
] += rowAdjustment
;
2955 if(m_currentRow
> row
)
2956 ChangeCurrentRow(m_currentRow
+ rowAdjustment
);
2960 // Send the expanded event
2961 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
2965 void wxDataViewMainWindow::Collapse(unsigned int row
)
2967 if (IsVirtualList())
2970 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
2974 if (!node
->HasChildren())
2983 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem());
2984 if( e
.GetSkipped() )
2987 // Find out if there are selected items below the current node.
2988 bool selectCollapsingRow
= false;
2989 const unsigned rowAdjustment
= node
->GetSubTreeCount();
2990 unsigned maxRowToBeTested
= row
+ rowAdjustment
;
2991 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2993 const unsigned testRow
= m_selection
[i
];
2994 if(testRow
> row
&& testRow
<= maxRowToBeTested
)
2996 selectCollapsingRow
= true;
2997 // get out as soon as we have found a node that is selected
3004 // If the node to be closed has selected items the user won't see those any longer.
3005 // We select the collapsing node in this case.
3006 if(selectCollapsingRow
)
3008 SelectAllRows(false);
3009 ChangeCurrentRow(row
);
3010 SelectRow(row
, true);
3011 SendSelectionChangedEvent(GetItemByRow(row
));
3015 // if there were no selected items below our node we still need to "fix" the
3016 // selection list to adjust for the changing of the row indices.
3017 // We actually do the opposite of what we are doing in Expand().
3018 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3020 const unsigned testRow
= m_selection
[i
];
3021 // all rows above us are not affected, so skip them
3025 m_selection
[i
] -= rowAdjustment
;
3028 // if the "current row" is being collapsed away we change it to the current row ;-)
3029 if(m_currentRow
> row
&& m_currentRow
<= maxRowToBeTested
)
3030 ChangeCurrentRow(row
);
3031 else if(m_currentRow
> row
)
3032 ChangeCurrentRow(m_currentRow
- rowAdjustment
);
3037 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,node
->GetItem());
3041 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
3043 wxDataViewModel
* model
= GetOwner()->GetModel();
3050 // Compose the a parent-chain of the finding item
3052 list
.DeleteContents( true );
3053 wxDataViewItem
it( item
);
3056 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3057 list
.Insert( pItem
);
3058 it
= model
->GetParent( it
);
3061 // Find the item along the parent-chain.
3062 // This algorithm is designed to speed up the node-finding method
3063 wxDataViewTreeNode
* node
= m_root
;
3064 for( ItemList::const_iterator iter
= list
.begin(); iter
!=list
.end(); iter
++ )
3066 if( node
->HasChildren() )
3068 if( node
->GetChildrenNumber() == 0 )
3071 ::BuildTreeHelper(model
, node
->GetItem(), node
);
3074 wxDataViewTreeNodes nodes
= node
->GetNodes();
3078 for (i
= 0; i
< nodes
.GetCount(); i
++)
3080 if (nodes
[i
]->GetItem() == (**iter
))
3082 if (nodes
[i
]->GetItem() == item
)
3099 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
3100 wxDataViewColumn
* &column
)
3102 wxDataViewColumn
*col
= NULL
;
3103 unsigned int cols
= GetOwner()->GetColumnCount();
3104 unsigned int colnum
= 0;
3106 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
3107 for (unsigned x_start
= 0; colnum
< cols
; colnum
++)
3109 col
= GetOwner()->GetColumnAt(colnum
);
3110 if (col
->IsHidden())
3111 continue; // skip it!
3113 unsigned int w
= col
->GetWidth();
3114 if (x_start
+w
>= (unsigned int)x
)
3121 item
= GetItemByRow( GetLineAt( y
) );
3124 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
,
3125 const wxDataViewColumn
* column
)
3130 unsigned int cols
= GetOwner()->GetColumnCount();
3131 // If column is null the loop will compute the combined width of all columns.
3132 // Otherwise, it will compute the x position of the column we are looking for.
3133 for (unsigned int i
= 0; i
< cols
; i
++)
3135 wxDataViewColumn
* col
= GetOwner()->GetColumnAt( i
);
3140 if (col
->IsHidden())
3141 continue; // skip it!
3143 xpos
+= col
->GetWidth();
3144 width
+= col
->GetWidth();
3149 // If we have a column, we need can get its width directly.
3150 if(column
->IsHidden())
3153 width
= column
->GetWidth();
3158 // If we have no column, we reset the x position back to zero.
3162 // we have to take an expander column into account and compute its indentation
3163 // to get the correct x position where the actual text is
3165 int row
= GetRowByItem(item
);
3166 if (!IsVirtualList() && (column
== 0 || GetOwner()->GetExpanderColumn() == column
) )
3168 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3169 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
3170 indent
= indent
+ m_lineHeight
; // use m_lineHeight as the width of the expander
3172 if(!node
->HasChildren())
3176 wxRect
itemRect( xpos
+ indent
,
3177 GetLineStart( row
),
3179 GetLineHeight( row
) );
3181 GetOwner()->CalcScrolledPosition( itemRect
.x
, itemRect
.y
,
3182 &itemRect
.x
, &itemRect
.y
);
3187 int wxDataViewMainWindow::RecalculateCount()
3189 if (IsVirtualList())
3191 wxDataViewVirtualListModel
*list_model
=
3192 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
3194 return list_model
->GetCount();
3198 return m_root
->GetSubTreeCount();
3202 class ItemToRowJob
: public DoJob
3205 ItemToRowJob(const wxDataViewItem
& item_
, ItemList::const_iterator iter
)
3212 // Maybe binary search will help to speed up this process
3213 virtual int operator() ( wxDataViewTreeNode
* node
)
3216 if( node
->GetItem() == item
)
3221 if( node
->GetItem() == **m_iter
)
3228 ret
+= node
->GetSubTreeCount();
3234 virtual int operator() ( void * n
)
3237 if( n
== item
.GetID() )
3242 // the row number is begin from zero
3243 int GetResult() const
3247 ItemList::const_iterator m_iter
;
3248 wxDataViewItem item
;
3253 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
3255 const wxDataViewModel
* model
= GetOwner()->GetModel();
3259 if (IsVirtualList())
3261 return wxPtrToUInt( item
.GetID() ) -1;
3268 // Compose the a parent-chain of the finding item
3270 wxDataViewItem
* pItem
;
3271 list
.DeleteContents( true );
3272 wxDataViewItem
it( item
);
3275 pItem
= new wxDataViewItem( it
);
3276 list
.Insert( pItem
);
3277 it
= model
->GetParent( it
);
3279 pItem
= new wxDataViewItem( );
3280 list
.Insert( pItem
);
3282 ItemToRowJob
job( item
, list
.begin() );
3283 Walker(m_root
, job
);
3284 return job
.GetResult();
3288 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
3289 wxDataViewTreeNode
* node
)
3291 if( !model
->IsContainer( item
) )
3294 wxDataViewItemArray children
;
3295 unsigned int num
= model
->GetChildren( item
, children
);
3297 unsigned int index
= 0;
3298 while( index
< num
)
3300 if( model
->IsContainer( children
[index
] ) )
3302 wxDataViewTreeNode
* n
= new wxDataViewTreeNode( node
);
3303 n
->SetItem(children
[index
]);
3304 n
->SetHasChildren( true );
3309 node
->AddLeaf( children
[index
].GetID() );
3313 node
->SetSubTreeCount( num
);
3314 wxDataViewTreeNode
* n
= node
->GetParent();
3316 n
->ChangeSubTreeCount(num
);
3320 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
3324 if (GetOwner()->GetModel()->IsVirtualListModel())
3330 m_root
= new wxDataViewTreeNode( NULL
);
3331 m_root
->SetHasChildren(true);
3333 // First we define a invalid item to fetch the top-level elements
3334 wxDataViewItem item
;
3336 BuildTreeHelper( model
, item
, m_root
);
3340 static void DestroyTreeHelper( wxDataViewTreeNode
* node
)
3342 if( node
->GetNodeNumber() != 0 )
3344 int len
= node
->GetNodeNumber();
3345 wxDataViewTreeNodes
& nodes
= node
->GetNodes();
3346 for (int i
= 0; i
< len
; i
++)
3347 DestroyTreeHelper(nodes
[i
]);
3352 void wxDataViewMainWindow::DestroyTree()
3354 if (!IsVirtualList())
3356 ::DestroyTreeHelper(m_root
);
3362 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
3364 if ( GetParent()->HandleAsNavigationKey(event
) )
3367 // no item -> nothing to do
3368 if (!HasCurrentRow())
3374 // don't use m_linesPerPage directly as it might not be computed yet
3375 const int pageSize
= GetCountPerPage();
3376 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
3378 switch ( event
.GetKeyCode() )
3382 wxWindow
*parent
= GetParent();
3383 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
,
3385 le
.SetItem( GetItemByRow(m_currentRow
) );
3386 le
.SetEventObject(parent
);
3387 le
.SetModel(GetOwner()->GetModel());
3389 parent
->GetEventHandler()->ProcessEvent(le
);
3394 if ( m_currentRow
> 0 )
3395 OnArrowChar( m_currentRow
- 1, event
);
3399 if ( m_currentRow
< GetRowCount() - 1 )
3400 OnArrowChar( m_currentRow
+ 1, event
);
3402 // Add the process for tree expanding/collapsing
3405 if (IsVirtualList())
3408 wxDataViewTreeNode
* node
= GetTreeNodeByRow(m_currentRow
);
3412 if (node
->HasChildren() && node
->IsOpen())
3414 Collapse(m_currentRow
);
3416 else // if the node is already closed we move the selection to its parent
3418 wxDataViewTreeNode
*parent_node
= node
->GetParent();
3420 if(!node
->HasChildren())
3425 int parent
= GetRowByItem( parent_node
->GetItem() );
3428 unsigned int row
= m_currentRow
;
3429 SelectRow( row
, false);
3430 SelectRow( parent
, true );
3431 ChangeCurrentRow( parent
);
3432 GetOwner()->EnsureVisible( parent
, -1 );
3433 SendSelectionChangedEvent( parent_node
->GetItem() );
3441 if (!IsExpanded( m_currentRow
))
3442 Expand( m_currentRow
);
3445 unsigned int row
= m_currentRow
;
3446 SelectRow( row
, false );
3447 SelectRow( row
+ 1, true );
3448 ChangeCurrentRow( row
+ 1 );
3449 GetOwner()->EnsureVisible( row
+ 1, -1 );
3450 SendSelectionChangedEvent( GetItemByRow(row
+1) );
3457 OnArrowChar( GetRowCount() - 1, event
);
3462 OnArrowChar( 0, event
);
3467 int steps
= pageSize
- 1;
3468 int index
= m_currentRow
- steps
;
3472 OnArrowChar( index
, event
);
3478 int steps
= pageSize
- 1;
3479 unsigned int index
= m_currentRow
+ steps
;
3480 unsigned int count
= GetRowCount();
3481 if ( index
>= count
)
3484 OnArrowChar( index
, event
);
3490 if(m_selection
.size() == 1)
3492 // TODO: we need to revise that when we have a concept for a 'current column'
3493 GetOwner()->StartEditor(GetItemByRow(m_selection
[0]), 0);
3503 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
3505 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3507 // let the base handle mouse wheel events.
3512 int x
= event
.GetX();
3513 int y
= event
.GetY();
3514 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
3515 wxDataViewColumn
*col
= NULL
;
3518 unsigned int cols
= GetOwner()->GetColumnCount();
3520 for (i
= 0; i
< cols
; i
++)
3522 wxDataViewColumn
*c
= GetOwner()->GetColumnAt( i
);
3524 continue; // skip it!
3526 if (x
< xpos
+ c
->GetWidth())
3531 xpos
+= c
->GetWidth();
3536 wxDataViewRenderer
*cell
= col
->GetRenderer();
3537 unsigned int current
= GetLineAt( y
);
3538 if ((current
>= GetRowCount()) || (x
> GetEndOfLastCol()))
3540 // Unselect all if below the last row ?
3544 // Test whether the mouse is hovered on the tree item button
3545 bool hoverOverExpander
= false;
3546 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
3548 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3549 if( node
!=NULL
&& node
->HasChildren() )
3551 int indent
= node
->GetIndentLevel();
3552 indent
= GetOwner()->GetIndent()*indent
;
3554 // we make the rectangle we are looking in a bit bigger than the actual
3555 // visual expander so the user can hit that little thing reliably
3556 wxRect
rect( xpos
+ indent
,
3557 GetLineStart( current
) + (GetLineHeight(current
) - m_lineHeight
)/2,
3558 m_lineHeight
, m_lineHeight
);
3559 if( rect
.Contains(x
, y
) )
3561 // So the mouse is over the expander
3562 hoverOverExpander
= true;
3563 if (m_underMouse
&& m_underMouse
!= node
)
3565 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3566 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3568 if (m_underMouse
!= node
)
3570 // wxLogMessage("Do the row: %d", current);
3571 RefreshRow(current
);
3573 m_underMouse
= node
;
3576 if (node
!=NULL
&& !node
->HasChildren())
3579 if (!hoverOverExpander
)
3581 if (m_underMouse
!= NULL
)
3583 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3584 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3585 m_underMouse
= NULL
;
3589 wxDataViewModel
*model
= GetOwner()->GetModel();
3591 #if wxUSE_DRAG_AND_DROP
3592 if (event
.Dragging())
3594 if (m_dragCount
== 0)
3596 // we have to report the raw, physical coords as we want to be
3597 // able to call HitTest(event.m_pointDrag) from the user code to
3598 // get the item being dragged
3599 m_dragStart
= event
.GetPosition();
3604 if (m_dragCount
!= 3)
3607 if (event
.LeftIsDown())
3609 m_owner
->CalcUnscrolledPosition( m_dragStart
.x
, m_dragStart
.y
,
3610 &m_dragStart
.x
, &m_dragStart
.y
);
3611 unsigned int drag_item_row
= GetLineAt( m_dragStart
.y
);
3612 wxDataViewItem item
= GetItemByRow( drag_item_row
);
3614 // Notify cell about drag
3615 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3616 event
.SetEventObject( m_owner
);
3617 event
.SetItem( item
);
3618 event
.SetModel( model
);
3619 if (!m_owner
->HandleWindowEvent( event
))
3622 if (!event
.IsAllowed())
3625 wxDataObject
*obj
= event
.GetDataObject();
3629 wxDataViewDropSource
drag( this, drag_item_row
);
3630 drag
.SetData( *obj
);
3631 /* wxDragResult res = */ drag
.DoDragDrop();
3640 #endif // wxUSE_DRAG_AND_DROP
3642 bool simulateClick
= false;
3644 if (event
.ButtonDClick())
3646 m_renameTimer
->Stop();
3647 m_lastOnSame
= false;
3650 wxDataViewItem item
= GetItemByRow(current
);
3651 bool ignore_other_columns
=
3652 ((GetOwner()->GetExpanderColumn() != col
) &&
3653 (model
->IsContainer(item
)) &&
3654 (!model
->HasContainerColumns(item
)));
3656 if (event
.LeftDClick())
3658 if(hoverOverExpander
)
3660 // a double click on the expander will be converted into a "simulated" normal click
3661 simulateClick
= true;
3663 else if ( current
== m_lineLastClicked
)
3665 if ((!ignore_other_columns
) && (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
3667 if ( wxDataViewCustomRenderer
*custom
= cell
->WXGetAsCustom() )
3670 model
->GetValue( value
, item
, col
->GetModelColumn() );
3671 custom
->SetValue( value
);
3672 wxRect
cell_rect( xpos
, GetLineStart( current
),
3673 col
->GetWidth(), GetLineHeight( current
) );
3674 custom
->Activate( cell_rect
, model
, item
, col
->GetModelColumn() );
3679 wxWindow
*parent
= GetParent();
3680 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3682 le
.SetEventObject(parent
);
3683 le
.SetModel(GetOwner()->GetModel());
3685 parent
->GetEventHandler()->ProcessEvent(le
);
3691 // The first click was on another item, so don't interpret this as
3692 // a double click, but as a simple click instead
3693 simulateClick
= true;
3697 if (event
.LeftUp() && !hoverOverExpander
)
3699 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
3701 // select single line
3702 SelectAllRows( false );
3703 SelectRow( m_lineSelectSingleOnUp
, true );
3704 SendSelectionChangedEvent( GetItemByRow(m_lineSelectSingleOnUp
) );
3707 // If the user click the expander, we do not do editing even if the column
3708 // with expander are editable
3709 if (m_lastOnSame
&& !ignore_other_columns
)
3711 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
3712 (cell
->GetMode() & wxDATAVIEW_CELL_EDITABLE
) )
3714 m_renameTimer
->Start( 100, true );
3718 m_lastOnSame
= false;
3719 m_lineSelectSingleOnUp
= (unsigned int)-1;
3721 else if(!event
.LeftUp())
3723 // This is necessary, because after a DnD operation in
3724 // from and to ourself, the up event is swallowed by the
3725 // DnD code. So on next non-up event (which means here and
3726 // now) m_lineSelectSingleOnUp should be reset.
3727 m_lineSelectSingleOnUp
= (unsigned int)-1;
3730 if (event
.RightDown())
3732 m_lineBeforeLastClicked
= m_lineLastClicked
;
3733 m_lineLastClicked
= current
;
3735 // If the item is already selected, do not update the selection.
3736 // Multi-selections should not be cleared if a selected item is clicked.
3737 if (!IsRowSelected(current
))
3739 SelectAllRows(false);
3740 ChangeCurrentRow(current
);
3741 SelectRow(m_currentRow
,true);
3742 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3745 else if (event
.RightUp())
3748 model
->GetValue( value
, item
, col
->GetModelColumn() );
3749 wxWindow
*parent
= GetParent();
3750 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
3752 le
.SetEventObject(parent
);
3753 le
.SetModel(GetOwner()->GetModel());
3755 parent
->GetEventHandler()->ProcessEvent(le
);
3757 else if (event
.MiddleDown())
3761 if((event
.LeftDown() || simulateClick
) && hoverOverExpander
)
3763 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3765 // hoverOverExpander being true tells us that our node must be
3766 // valid and have children.
3767 // So we don't need any extra checks.
3768 if( node
->IsOpen() )
3773 else if ((event
.LeftDown() || simulateClick
) && !hoverOverExpander
)
3777 m_lineBeforeLastClicked
= m_lineLastClicked
;
3778 m_lineLastClicked
= current
;
3780 unsigned int oldCurrentRow
= m_currentRow
;
3781 bool oldWasSelected
= IsRowSelected(m_currentRow
);
3783 bool cmdModifierDown
= event
.CmdDown();
3784 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3786 if ( IsSingleSel() || !IsRowSelected(current
) )
3788 SelectAllRows( false );
3789 ChangeCurrentRow(current
);
3790 SelectRow(m_currentRow
,true);
3791 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3793 else // multi sel & current is highlighted & no mod keys
3795 m_lineSelectSingleOnUp
= current
;
3796 ChangeCurrentRow(current
); // change focus
3799 else // multi sel & either ctrl or shift is down
3801 if (cmdModifierDown
)
3803 ChangeCurrentRow(current
);
3804 ReverseRowSelection(m_currentRow
);
3805 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3807 else if (event
.ShiftDown())
3809 ChangeCurrentRow(current
);
3811 unsigned int lineFrom
= oldCurrentRow
,
3814 if ( lineTo
< lineFrom
)
3817 lineFrom
= m_currentRow
;
3820 SelectRows(lineFrom
, lineTo
, true);
3821 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3823 else // !ctrl, !shift
3825 // test in the enclosing if should make it impossible
3826 wxFAIL_MSG( wxT("how did we get here?") );
3830 if (m_currentRow
!= oldCurrentRow
)
3831 RefreshRow( oldCurrentRow
);
3833 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
3835 // Update selection here...
3838 m_lastOnSame
= !simulateClick
&& ((col
== oldCurrentCol
) &&
3839 (current
== oldCurrentRow
)) && oldWasSelected
;
3841 // Call LeftClick after everything else as under GTK+
3842 if (cell
->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE
)
3844 if ( wxDataViewCustomRenderer
*custom
= cell
->WXGetAsCustom() )
3846 // notify cell about click
3848 model
->GetValue( value
, item
, col
->GetModelColumn() );
3849 custom
->SetValue( value
);
3850 wxRect
cell_rect( xpos
, GetLineStart( current
),
3851 col
->GetWidth(), GetLineHeight( current
) );
3852 /* ignore ret */ custom
->LeftClick( event
.GetPosition(), cell_rect
,
3853 model
, item
, col
->GetModelColumn());
3859 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
3863 if (HasCurrentRow())
3869 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
3873 if (HasCurrentRow())
3879 wxDataViewItem
wxDataViewMainWindow::GetSelection() const
3881 if( m_selection
.GetCount() != 1 )
3882 return wxDataViewItem();
3884 return GetItemByRow( m_selection
.Item(0));
3887 //-----------------------------------------------------------------------------
3889 //-----------------------------------------------------------------------------
3891 WX_DEFINE_LIST(wxDataViewColumnList
)
3893 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3894 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
3895 EVT_SIZE(wxDataViewCtrl::OnSize
)
3898 wxDataViewCtrl::~wxDataViewCtrl()
3901 GetModel()->RemoveNotifier( m_notifier
);
3906 void wxDataViewCtrl::Init()
3908 m_cols
.DeleteContents(true);
3911 // No sorting column at start
3912 m_sortingColumnIdx
= wxNOT_FOUND
;
3914 m_headerArea
= NULL
;
3917 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3918 const wxPoint
& pos
, const wxSize
& size
,
3919 long style
, const wxValidator
& validator
)
3921 // if ( (style & wxBORDER_MASK) == 0)
3922 // style |= wxBORDER_SUNKEN;
3926 if (!wxControl::Create( parent
, id
, pos
, size
,
3927 style
| wxScrolledWindowStyle
, validator
))
3930 SetInitialSize(size
);
3933 MacSetClipChildren( true );
3936 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
3938 if (HasFlag(wxDV_NO_HEADER
))
3939 m_headerArea
= NULL
;
3941 m_headerArea
= new wxDataViewHeaderWindow(this);
3943 SetTargetWindow( m_clientArea
);
3945 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
3947 sizer
->Add( m_headerArea
, 0, wxGROW
);
3948 sizer
->Add( m_clientArea
, 1, wxGROW
);
3954 wxBorder
wxDataViewCtrl::GetDefaultBorder() const
3956 return wxBORDER_THEME
;
3960 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
3964 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
3967 // we need to process arrows ourselves for scrolling
3968 if ( nMsg
== WM_GETDLGCODE
)
3970 rc
|= DLGC_WANTARROWS
;
3978 wxSize
wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
3980 wxSize newsize
= size
;
3981 if (!HasFlag(wxDV_NO_HEADER
) && (m_headerArea
))
3982 newsize
.y
-= m_headerArea
->GetSize().y
;
3987 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3989 // We need to override OnSize so that our scrolled
3990 // window a) does call Layout() to use sizers for
3991 // positioning the controls but b) does not query
3992 // the sizer for their size and use that for setting
3993 // the scrollable area as set that ourselves by
3994 // calling SetScrollbar() further down.
4001 void wxDataViewCtrl::SetFocus()
4004 m_clientArea
->SetFocus();
4007 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4009 if (!wxDataViewCtrlBase::AssociateModel( model
))
4012 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
4014 model
->AddNotifier( m_notifier
);
4016 m_clientArea
->DestroyTree();
4018 m_clientArea
->BuildTree(model
);
4020 m_clientArea
->UpdateDisplay();
4025 #if wxUSE_DRAG_AND_DROP
4027 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4029 return m_clientArea
->EnableDragSource( format
);
4032 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4034 return m_clientArea
->EnableDropTarget( format
);
4037 #endif // wxUSE_DRAG_AND_DROP
4039 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4041 if (!wxDataViewCtrlBase::AppendColumn(col
))
4044 m_cols
.Append( col
);
4045 OnColumnsCountChanged();
4049 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4051 if (!wxDataViewCtrlBase::PrependColumn(col
))
4054 m_cols
.Insert( col
);
4055 OnColumnsCountChanged();
4059 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4061 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4064 m_cols
.Insert( pos
, col
);
4065 OnColumnsCountChanged();
4069 void wxDataViewCtrl::OnColumnChange(unsigned int idx
)
4072 m_headerArea
->UpdateColumn(idx
);
4074 m_clientArea
->UpdateDisplay();
4077 void wxDataViewCtrl::OnColumnsCountChanged()
4080 m_headerArea
->SetColumnCount(GetColumnCount());
4082 m_clientArea
->UpdateDisplay();
4085 void wxDataViewCtrl::DoSetExpanderColumn()
4087 m_clientArea
->UpdateDisplay();
4090 void wxDataViewCtrl::DoSetIndent()
4092 m_clientArea
->UpdateDisplay();
4095 unsigned int wxDataViewCtrl::GetColumnCount() const
4097 return m_cols
.GetCount();
4100 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int idx
) const
4105 wxDataViewColumn
*wxDataViewCtrl::GetColumnAt(unsigned int pos
) const
4107 // columns can't be reordered if there is no header window which allows
4109 const unsigned idx
= m_headerArea
? m_headerArea
->GetColumnsOrder()[pos
]
4112 return GetColumn(idx
);
4115 int wxDataViewCtrl::GetColumnIndex(const wxDataViewColumn
*column
) const
4117 const unsigned count
= m_cols
.size();
4118 for ( unsigned n
= 0; n
< count
; n
++ )
4120 if ( m_cols
[n
] == column
)
4127 void wxDataViewCtrl::ColumnMoved(wxDataViewColumn
* WXUNUSED(col
),
4128 unsigned int WXUNUSED(new_pos
))
4130 // do _not_ reorder m_cols elements here, they should always be in the
4131 // order in which columns were added, we only display the columns in
4133 m_clientArea
->UpdateDisplay();
4136 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4138 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
4143 OnColumnsCountChanged();
4148 bool wxDataViewCtrl::ClearColumns()
4151 OnColumnsCountChanged();
4155 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4159 unsigned int len
= GetColumnCount();
4160 for ( unsigned int i
= 0; i
< len
; i
++ )
4162 wxDataViewColumn
* col
= GetColumnAt(i
);
4163 if (col
->IsHidden())
4165 ret
+= col
->GetWidth();
4168 CalcScrolledPosition( ret
, dummy
, &ret
, &dummy
);
4175 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4177 return m_sortingColumnIdx
== wxNOT_FOUND
? NULL
4178 : GetColumn(m_sortingColumnIdx
);
4181 // Selection code with wxDataViewItem as parameters
4182 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4184 return m_clientArea
->GetSelection();
4187 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4190 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4191 int len
= selection
.GetCount();
4192 for( int i
= 0; i
< len
; i
++)
4194 unsigned int row
= selection
[i
];
4195 sel
.Add( m_clientArea
->GetItemByRow( row
) );
4200 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4202 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4204 wxDataViewItem last_parent
;
4206 int len
= sel
.GetCount();
4207 for( int i
= 0; i
< len
; i
++ )
4209 wxDataViewItem item
= sel
[i
];
4210 wxDataViewItem parent
= GetModel()->GetParent( item
);
4213 if (parent
!= last_parent
)
4214 ExpandAncestors(item
);
4217 last_parent
= parent
;
4218 int row
= m_clientArea
->GetRowByItem( item
);
4220 selection
.Add( static_cast<unsigned int>(row
) );
4223 m_clientArea
->SetSelections( selection
);
4226 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4228 ExpandAncestors( item
);
4230 int row
= m_clientArea
->GetRowByItem( item
);
4233 // Unselect all rows before select another in the single select mode
4234 if (m_clientArea
->IsSingleSel())
4235 m_clientArea
->SelectAllRows(false);
4236 m_clientArea
->SelectRow(row
, true);
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