1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/datavgen.cpp
3 // Purpose: wxDataViewCtrl generic implementation
4 // Author: Robert Roebling
5 // Modified by: Francesco Montorsi, Guru Kathiresan, Bo Yang
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_DATAVIEWCTRL
20 #include "wx/dataview.h"
22 #ifdef wxUSE_GENERICDATAVIEWCTRL
26 #include "wx/msw/private.h"
27 #include "wx/msw/wrapwin.h"
28 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/msgdlg.h"
36 #include "wx/dcscreen.h"
40 #include "wx/stockitem.h"
41 #include "wx/calctrl.h"
42 #include "wx/popupwin.h"
43 #include "wx/renderer.h"
44 #include "wx/dcbuffer.h"
47 #include "wx/listimpl.cpp"
48 #include "wx/imaglist.h"
49 #include "wx/headerctrl.h"
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
58 static const int SCROLL_UNIT_X
= 15;
60 // the cell padding on the left/right
61 static const int PADDING_RIGHTLEFT
= 3;
63 // the expander space margin
64 static const int EXPANDER_MARGIN
= 4;
67 static const int EXPANDER_OFFSET
= 4;
69 static const int EXPANDER_OFFSET
= 1;
72 // Below is the compare stuff.
73 // For the generic implementation, both the leaf nodes and the nodes are sorted for
74 // fast search when needed
75 static wxDataViewModel
* g_model
;
76 static int g_column
= -2;
77 static bool g_asending
= true;
79 //-----------------------------------------------------------------------------
80 // wxDataViewHeaderWindow
81 //-----------------------------------------------------------------------------
83 class wxDataViewHeaderWindow
: public wxHeaderCtrl
86 wxDataViewHeaderWindow(wxDataViewCtrl
*parent
)
87 : wxHeaderCtrl(parent
)
91 wxDataViewCtrl
*GetOwner() const
92 { return static_cast<wxDataViewCtrl
*>(GetParent()); }
95 // implement/override wxHeaderCtrl functions by forwarding them to the main
97 virtual const wxHeaderColumn
& GetColumn(unsigned int idx
) const
99 return *(GetOwner()->GetColumn(idx
));
102 // FIXME: currently unused
103 virtual bool UpdateColumnWidthToFit(unsigned int idx
, int widthTitle
)
105 wxDataViewCtrl
* const owner
= GetOwner();
107 int widthContents
= owner
->GetBestColumnWidth(idx
);
108 owner
->GetColumn(idx
)->SetWidth(wxMax(widthTitle
, widthContents
));
109 owner
->OnColumnChange(idx
);
115 bool SendEvent(wxEventType type
, unsigned int n
)
117 wxDataViewCtrl
* const owner
= GetOwner();
118 wxDataViewEvent
event(type
, owner
->GetId());
120 event
.SetEventObject(owner
);
122 event
.SetDataViewColumn(owner
->GetColumn(n
));
123 event
.SetModel(owner
->GetModel());
125 // for events created by wxDataViewHeaderWindow the
126 // row / value fields are not valid
127 return owner
->GetEventHandler()->ProcessEvent(event
);
130 void OnClick(wxHeaderCtrlEvent
& event
)
132 const unsigned idx
= event
.GetColumn();
134 if ( SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, idx
) )
137 // default handling for the column click is to sort by this column or
138 // toggle its sort order
139 wxDataViewCtrl
* const owner
= GetOwner();
140 wxDataViewColumn
* const col
= owner
->GetColumn(idx
);
141 if ( !col
->IsSortable() )
143 // no default handling for non-sortable columns
148 if ( col
->IsSortKey() )
150 // already using this column for sorting, just change the order
151 col
->ToggleSortOrder();
153 else // not using this column for sorting yet
155 // first unset the old sort column if any
156 int oldSortKey
= owner
->GetSortingColumnIndex();
157 if ( oldSortKey
!= wxNOT_FOUND
)
159 owner
->GetColumn(oldSortKey
)->UnsetAsSortKey();
160 owner
->OnColumnChange(oldSortKey
);
163 owner
->SetSortingColumnIndex(idx
);
167 wxDataViewModel
* const model
= owner
->GetModel();
171 owner
->OnColumnChange(idx
);
174 void OnRClick(wxHeaderCtrlEvent
& event
)
176 if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
181 void OnResize(wxHeaderCtrlEvent
& event
)
183 wxDataViewCtrl
* const owner
= GetOwner();
185 const unsigned col
= event
.GetColumn();
186 owner
->GetColumn(col
)->SetWidth(event
.GetWidth());
187 GetOwner()->OnColumnChange(col
);
190 void OnEndReorder(wxHeaderCtrlEvent
& event
)
192 wxDataViewCtrl
* const owner
= GetOwner();
193 owner
->ColumnMoved(owner
->GetColumn(event
.GetColumn()),
194 event
.GetNewOrder());
197 DECLARE_EVENT_TABLE()
198 wxDECLARE_NO_COPY_CLASS(wxDataViewHeaderWindow
);
201 BEGIN_EVENT_TABLE(wxDataViewHeaderWindow
, wxHeaderCtrl
)
202 EVT_HEADER_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnClick
)
203 EVT_HEADER_RIGHT_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnRClick
)
205 EVT_HEADER_RESIZING(wxID_ANY
, wxDataViewHeaderWindow::OnResize
)
206 EVT_HEADER_END_RESIZE(wxID_ANY
, wxDataViewHeaderWindow::OnResize
)
208 EVT_HEADER_END_REORDER(wxID_ANY
, wxDataViewHeaderWindow::OnEndReorder
)
211 //-----------------------------------------------------------------------------
212 // wxDataViewRenameTimer
213 //-----------------------------------------------------------------------------
215 class wxDataViewRenameTimer
: public wxTimer
218 wxDataViewMainWindow
*m_owner
;
221 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
225 //-----------------------------------------------------------------------------
226 // wxDataViewTreeNode
227 //-----------------------------------------------------------------------------
229 class wxDataViewTreeNode
;
230 WX_DEFINE_ARRAY( wxDataViewTreeNode
*, wxDataViewTreeNodes
);
231 WX_DEFINE_ARRAY( void* , wxDataViewTreeLeaves
);
233 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
,
234 wxDataViewTreeNode
** node2
);
235 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
);
237 class wxDataViewTreeNode
240 wxDataViewTreeNode( wxDataViewTreeNode
* parent
= NULL
)
247 m_hasChildren
= false;
251 ~wxDataViewTreeNode()
255 wxDataViewTreeNode
* GetParent() const { return m_parent
; }
256 void SetParent( wxDataViewTreeNode
* parent
) { m_parent
= parent
; }
257 wxDataViewTreeNodes
& GetNodes() { return m_nodes
; }
258 wxDataViewTreeLeaves
& GetChildren() { return m_leaves
; }
260 void AddNode( wxDataViewTreeNode
* node
)
262 m_leaves
.Add( node
->GetItem().GetID() );
264 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
267 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
269 void AddLeaf( void * leaf
)
271 m_leaves
.Add( leaf
);
273 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
276 wxDataViewItem
& GetItem() { return m_item
; }
277 const wxDataViewItem
& GetItem() const { return m_item
; }
278 void SetItem( const wxDataViewItem
& item
) { m_item
= item
; }
280 unsigned int GetChildrenNumber() const { return m_leaves
.GetCount(); }
281 unsigned int GetNodeNumber() const { return m_nodes
.GetCount(); }
282 int GetIndentLevel() const
285 const wxDataViewTreeNode
* node
= this;
286 while( node
->GetParent()->GetParent() != NULL
)
288 node
= node
->GetParent();
301 int len
= m_nodes
.GetCount();
303 for ( int i
= 0;i
< len
; i
++)
304 sum
+= m_nodes
[i
]->GetSubTreeCount();
306 sum
+= m_leaves
.GetCount();
309 ChangeSubTreeCount(-sum
);
315 ChangeSubTreeCount(sum
);
318 bool HasChildren() const { return m_hasChildren
; }
319 void SetHasChildren( bool has
){ m_hasChildren
= has
; }
321 void SetSubTreeCount( int num
) { m_subTreeCount
= num
; }
322 int GetSubTreeCount() const { return m_subTreeCount
; }
323 void ChangeSubTreeCount( int num
)
327 m_subTreeCount
+= num
;
329 m_parent
->ChangeSubTreeCount(num
);
336 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
337 int len
= m_nodes
.GetCount();
338 for (int i
= 0; i
< len
; i
++)
339 m_nodes
[i
]->Resort();
340 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
345 wxDataViewTreeNode
*m_parent
;
346 wxDataViewTreeNodes m_nodes
;
347 wxDataViewTreeLeaves m_leaves
;
348 wxDataViewItem m_item
;
354 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
,
355 wxDataViewTreeNode
** node2
)
357 return g_model
->Compare( (*node1
)->GetItem(), (*node2
)->GetItem(), g_column
, g_asending
);
360 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
)
362 return g_model
->Compare( *id1
, *id2
, g_column
, g_asending
);
366 //-----------------------------------------------------------------------------
367 // wxDataViewMainWindow
368 //-----------------------------------------------------------------------------
370 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
,
372 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
373 WX_DEFINE_LIST(ItemList
)
375 class wxDataViewMainWindow
: public wxWindow
378 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
380 const wxPoint
&pos
= wxDefaultPosition
,
381 const wxSize
&size
= wxDefaultSize
,
382 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
383 virtual ~wxDataViewMainWindow();
385 bool IsVirtualList() const { return m_root
== NULL
; }
387 // notifications from wxDataViewModel
388 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
389 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
390 bool ItemChanged( const wxDataViewItem
&item
);
391 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
395 if (!IsVirtualList())
405 g_model
= GetOwner()->GetModel();
406 wxDataViewColumn
* col
= GetOwner()->GetSortingColumn();
409 if (g_model
->HasDefaultCompare())
417 g_column
= col
->GetModelColumn();
418 g_asending
= col
->IsSortOrderAscending();
421 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
422 wxDataViewCtrl
*GetOwner() { return m_owner
; }
423 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
425 #if wxUSE_DRAG_AND_DROP
426 wxBitmap
CreateItemBitmap( unsigned int row
, int &indent
);
427 #endif // wxUSE_DRAG_AND_DROP
428 void OnPaint( wxPaintEvent
&event
);
429 void OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
);
430 void OnChar( wxKeyEvent
&event
);
431 void OnMouse( wxMouseEvent
&event
);
432 void OnSetFocus( wxFocusEvent
&event
);
433 void OnKillFocus( wxFocusEvent
&event
);
435 void UpdateDisplay();
436 void RecalculateDisplay();
437 void OnInternalIdle();
439 void OnRenameTimer();
441 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
442 void ScrollTo( int rows
, int column
);
444 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
445 void ChangeCurrentRow( unsigned int row
);
447 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
448 bool IsEmpty() { return GetRowCount() == 0; }
450 int GetCountPerPage() const;
451 int GetEndOfLastCol() const;
452 unsigned int GetFirstVisibleRow() const;
454 // I change this method to un const because in the tree view,
455 // the displaying number of the tree are changing along with the
456 // expanding/collapsing of the tree nodes
457 unsigned int GetLastVisibleRow();
458 unsigned int GetRowCount();
460 wxDataViewItem
GetSelection() const;
461 wxDataViewSelection
GetSelections(){ return m_selection
; }
462 void SetSelections( const wxDataViewSelection
& sel
)
463 { m_selection
= sel
; UpdateDisplay(); }
464 void Select( const wxArrayInt
& aSelections
);
465 void SelectAllRows( bool on
);
466 void SelectRow( unsigned int row
, bool on
);
467 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
468 void ReverseRowSelection( unsigned int row
);
469 bool IsRowSelected( unsigned int row
);
470 void SendSelectionChangedEvent( const wxDataViewItem
& item
);
472 void RefreshRow( unsigned int row
);
473 void RefreshRows( unsigned int from
, unsigned int to
);
474 void RefreshRowsAfter( unsigned int firstRow
);
476 // returns the colour to be used for drawing the rules
477 wxColour
GetRuleColour() const
479 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
482 wxRect
GetLineRect( unsigned int row
) const;
484 int GetLineStart( unsigned int row
) const; // row * m_lineHeight in fixed mode
485 int GetLineHeight( unsigned int row
) const; // m_lineHeight in fixed mode
486 int GetLineAt( unsigned int y
) const; // y / m_lineHeight in fixed mode
488 // Some useful functions for row and item mapping
489 wxDataViewItem
GetItemByRow( unsigned int row
) const;
490 int GetRowByItem( const wxDataViewItem
& item
) const;
492 // Methods for building the mapping tree
493 void BuildTree( wxDataViewModel
* model
);
495 void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
);
496 wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
);
498 void Expand( unsigned int row
);
499 void Collapse( unsigned int row
);
500 bool IsExpanded( unsigned int row
) const;
501 bool HasChildren( unsigned int row
) const;
503 #if wxUSE_DRAG_AND_DROP
504 bool EnableDragSource( const wxDataFormat
&format
);
505 bool EnableDropTarget( const wxDataFormat
&format
);
507 void RemoveDropHint();
508 wxDragResult
OnDragOver( wxDataFormat format
, wxCoord x
, wxCoord y
, wxDragResult def
);
509 bool OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
);
510 wxDragResult
OnData( wxDataFormat format
, wxCoord x
, wxCoord y
, wxDragResult def
);
512 #endif // wxUSE_DRAG_AND_DROP
515 wxDataViewTreeNode
* GetTreeNodeByRow( unsigned int row
) const;
516 // We did not need this temporarily
517 // wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
519 int RecalculateCount();
521 wxDataViewEvent
SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
);
523 wxDataViewTreeNode
* FindNode( const wxDataViewItem
& item
);
526 wxDataViewCtrl
*m_owner
;
530 wxDataViewColumn
*m_currentCol
;
531 unsigned int m_currentRow
;
532 wxDataViewSelection m_selection
;
534 wxDataViewRenameTimer
*m_renameTimer
;
539 #if wxUSE_DRAG_AND_DROP
544 wxDataFormat m_dragFormat
;
547 wxDataFormat m_dropFormat
;
549 unsigned int m_dropHintLine
;
550 #endif // wxUSE_DRAG_AND_DROP
552 // for double click logic
553 unsigned int m_lineLastClicked
,
554 m_lineBeforeLastClicked
,
555 m_lineSelectSingleOnUp
;
557 // the pen used to draw horiz/vertical rules
560 // the pen used to draw the expander and the lines
563 // This is the tree structure of the model
564 wxDataViewTreeNode
* m_root
;
567 // This is the tree node under the cursor
568 wxDataViewTreeNode
* m_underMouse
;
571 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
572 DECLARE_EVENT_TABLE()
575 // ---------------------------------------------------------
576 // wxGenericDataViewModelNotifier
577 // ---------------------------------------------------------
579 class wxGenericDataViewModelNotifier
: public wxDataViewModelNotifier
582 wxGenericDataViewModelNotifier( wxDataViewMainWindow
*mainWindow
)
583 { m_mainWindow
= mainWindow
; }
585 virtual bool ItemAdded( const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
586 { return m_mainWindow
->ItemAdded( parent
, item
); }
587 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
588 { return m_mainWindow
->ItemDeleted( parent
, item
); }
589 virtual bool ItemChanged( const wxDataViewItem
& item
)
590 { return m_mainWindow
->ItemChanged(item
); }
591 virtual bool ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
592 { return m_mainWindow
->ValueChanged( item
, col
); }
593 virtual bool Cleared()
594 { return m_mainWindow
->Cleared(); }
595 virtual void Resort()
596 { m_mainWindow
->Resort(); }
598 wxDataViewMainWindow
*m_mainWindow
;
601 // ---------------------------------------------------------
602 // wxDataViewRenderer
603 // ---------------------------------------------------------
605 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
607 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
608 wxDataViewCellMode mode
,
610 wxDataViewRendererBase( varianttype
, mode
, align
)
619 wxDataViewRenderer::~wxDataViewRenderer()
625 wxDC
*wxDataViewRenderer::GetDC()
629 if (GetOwner() == NULL
)
631 if (GetOwner()->GetOwner() == NULL
)
633 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
639 void wxDataViewRenderer::SetAlignment( int align
)
644 int wxDataViewRenderer::GetAlignment() const
649 int wxDataViewRenderer::CalculateAlignment() const
651 if (m_align
== wxDVR_DEFAULT_ALIGNMENT
)
653 if (GetOwner() == NULL
)
654 return wxALIGN_LEFT
| wxALIGN_CENTRE_VERTICAL
;
656 return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
662 // ---------------------------------------------------------
663 // wxDataViewCustomRenderer
664 // ---------------------------------------------------------
666 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
668 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
669 wxDataViewCellMode mode
, int align
) :
670 wxDataViewRenderer( varianttype
, mode
, align
)
674 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
,
675 wxRect cell
, wxDC
*dc
, int state
)
677 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
678 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
679 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
680 view
->GetForegroundColour();
681 dc
->SetTextForeground(col
);
684 cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
687 // ---------------------------------------------------------
688 // wxDataViewTextRenderer
689 // ---------------------------------------------------------
691 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
693 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
694 wxDataViewCellMode mode
, int align
) :
695 wxDataViewCustomRenderer( varianttype
, mode
, align
)
699 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
701 m_text
= value
.GetString();
706 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
711 bool wxDataViewTextRenderer::HasEditorCtrl() const
716 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
717 wxRect labelRect
, const wxVariant
&value
)
719 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, value
,
720 wxPoint(labelRect
.x
,labelRect
.y
),
721 wxSize(labelRect
.width
,labelRect
.height
) );
723 // select the text in the control an place the cursor at the end
724 ctrl
->SetInsertionPointEnd();
730 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
732 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
733 value
= text
->GetValue();
737 bool wxDataViewTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
739 RenderText( m_text
, 0, cell
, dc
, state
);
743 wxSize
wxDataViewTextRenderer::GetSize() const
745 const wxDataViewCtrl
*view
= GetView();
747 return view
->wxWindowBase::GetTextExtent( m_text
);
748 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
751 // ---------------------------------------------------------
752 // wxDataViewTextRendererAttr
753 // ---------------------------------------------------------
755 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
, wxDataViewTextRenderer
)
757 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
758 wxDataViewCellMode mode
, int align
) :
759 wxDataViewTextRenderer( varianttype
, mode
, align
)
764 bool wxDataViewTextRendererAttr::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
771 if (m_attr
.HasColour())
773 colour
= dc
->GetTextForeground();
774 dc
->SetTextForeground( m_attr
.GetColour() );
777 if (m_attr
.GetBold() || m_attr
.GetItalic())
779 font
= dc
->GetFont();
780 wxFont myfont
= font
;
781 if (m_attr
.GetBold())
782 myfont
.SetWeight( wxFONTWEIGHT_BOLD
);
783 if (m_attr
.GetItalic())
784 myfont
.SetStyle( wxFONTSTYLE_ITALIC
);
785 dc
->SetFont( myfont
);
789 dc
->DrawText( m_text
, cell
.x
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
794 if (m_attr
.HasColour())
795 dc
->SetTextForeground( colour
);
797 if (m_attr
.GetBold() || m_attr
.GetItalic())
805 // ---------------------------------------------------------
806 // wxDataViewBitmapRenderer
807 // ---------------------------------------------------------
809 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
811 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
812 wxDataViewCellMode mode
, int align
) :
813 wxDataViewCustomRenderer( varianttype
, mode
, align
)
817 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
819 if (value
.GetType() == wxT("wxBitmap"))
821 if (value
.GetType() == wxT("wxIcon"))
827 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
832 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
835 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
836 else if (m_icon
.Ok())
837 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
842 wxSize
wxDataViewBitmapRenderer::GetSize() const
845 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
846 else if (m_icon
.Ok())
847 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
849 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
852 // ---------------------------------------------------------
853 // wxDataViewToggleRenderer
854 // ---------------------------------------------------------
856 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
858 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
859 wxDataViewCellMode mode
, int align
) :
860 wxDataViewCustomRenderer( varianttype
, mode
, align
)
865 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
867 m_toggle
= value
.GetBool();
872 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
877 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
881 flags
|= wxCONTROL_CHECKED
;
882 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
883 flags
|= wxCONTROL_DISABLED
;
885 wxRendererNative::Get().DrawCheckBox(
886 GetOwner()->GetOwner(),
894 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
895 wxDataViewModel
*model
,
896 const wxDataViewItem
& item
, unsigned int col
)
898 bool value
= !m_toggle
;
899 wxVariant variant
= value
;
900 model
->SetValue( variant
, item
, col
);
901 model
->ValueChanged( item
, col
);
905 wxSize
wxDataViewToggleRenderer::GetSize() const
907 // the window parameter is not used by GetCheckBoxSize() so it's
909 return wxRendererNative::Get().GetCheckBoxSize(NULL
);
912 // ---------------------------------------------------------
913 // wxDataViewProgressRenderer
914 // ---------------------------------------------------------
916 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
918 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
919 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
920 wxDataViewCustomRenderer( varianttype
, mode
, align
)
926 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
930 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
932 m_value
= (long) value
;
934 if (m_value
< 0) m_value
= 0;
935 if (m_value
> 100) m_value
= 100;
940 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
942 value
= (long) m_value
;
946 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
948 double pct
= (double)m_value
/ 100.0;
950 bar
.width
= (int)(cell
.width
* pct
);
951 dc
->SetPen( *wxTRANSPARENT_PEN
);
952 dc
->SetBrush( *wxBLUE_BRUSH
);
953 dc
->DrawRectangle( bar
);
955 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
956 dc
->SetPen( *wxBLACK_PEN
);
957 dc
->DrawRectangle( cell
);
962 wxSize
wxDataViewProgressRenderer::GetSize() const
964 return wxSize(40,12);
967 // ---------------------------------------------------------
968 // wxDataViewDateRenderer
969 // ---------------------------------------------------------
971 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
973 #if wxUSE_DATE_RENDERER_POPUP
975 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
978 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
979 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
) :
980 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
),
985 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
986 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
987 sizer
->Add( m_cal
, 1, wxGROW
);
992 void OnCalendar( wxCalendarEvent
&event
);
994 wxCalendarCtrl
*m_cal
;
995 wxDataViewModel
*m_model
;
997 const wxDataViewItem
& m_item
;
1000 virtual void OnDismiss()
1005 DECLARE_EVENT_TABLE()
1008 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1009 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
1012 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1014 wxDateTime date
= event
.GetDate();
1015 wxVariant value
= date
;
1016 m_model
->SetValue( value
, m_item
, m_col
);
1017 m_model
->ValueChanged( m_item
, m_col
);
1021 #endif // wxUSE_DATE_RENDERER_POPUP
1023 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1025 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1026 wxDataViewCellMode mode
, int align
) :
1027 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1031 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1033 m_date
= value
.GetDateTime();
1038 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1044 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1046 wxString tmp
= m_date
.FormatDate();
1047 RenderText( tmp
, 0, cell
, dc
, state
);
1051 wxSize
wxDataViewDateRenderer::GetSize() const
1053 const wxDataViewCtrl
* view
= GetView();
1054 wxString tmp
= m_date
.FormatDate();
1056 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1057 return wxSize(x
,y
+d
);
1060 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
1061 const wxDataViewItem
& item
, unsigned int col
)
1064 model
->GetValue( variant
, item
, col
);
1065 wxDateTime value
= variant
.GetDateTime();
1067 #if wxUSE_DATE_RENDERER_POPUP
1068 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1069 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1070 wxPoint pos
= wxGetMousePosition();
1073 popup
->Popup( popup
->m_cal
);
1074 #else // !wxUSE_DATE_RENDERER_POPUP
1075 wxMessageBox(value
.Format());
1076 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
1080 // ---------------------------------------------------------
1081 // wxDataViewIconTextRenderer
1082 // ---------------------------------------------------------
1084 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1086 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1087 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1088 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1091 SetAlignment(align
);
1094 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1098 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1104 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1109 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1112 const wxIcon
&icon
= m_value
.GetIcon();
1115 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ ((cell
.height
- icon
.GetHeight()) / 2));
1116 xoffset
= icon
.GetWidth()+4;
1119 RenderText( m_value
.GetText(), xoffset
, cell
, dc
, state
);
1124 wxSize
wxDataViewIconTextRenderer::GetSize() const
1126 const wxDataViewCtrl
*view
= GetView();
1127 if (!m_value
.GetText().empty())
1130 view
->GetTextExtent( m_value
.GetText(), &x
, &y
);
1132 if (m_value
.GetIcon().IsOk())
1133 x
+= m_value
.GetIcon().GetWidth() + 4;
1134 return wxSize( x
, y
);
1136 return wxSize(80,20);
1139 wxControl
* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1141 wxDataViewIconText iconText
;
1144 wxString text
= iconText
.GetText();
1146 // adjust the label rect to take the width of the icon into account
1147 if (iconText
.GetIcon().IsOk())
1149 int w
= iconText
.GetIcon().GetWidth() + 4;
1151 labelRect
.width
-= w
;
1154 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, text
,
1155 wxPoint(labelRect
.x
,labelRect
.y
),
1156 wxSize(labelRect
.width
,labelRect
.height
) );
1158 // select the text in the control an place the cursor at the end
1159 ctrl
->SetInsertionPointEnd();
1165 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
& value
)
1167 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
1169 wxDataViewIconText
iconText(text
->GetValue(), m_value
.GetIcon());
1174 //-----------------------------------------------------------------------------
1175 // wxDataViewDropTarget
1176 //-----------------------------------------------------------------------------
1178 #if wxUSE_DRAG_AND_DROP
1180 class wxBitmapCanvas
: public wxWindow
1183 wxBitmapCanvas( wxWindow
*parent
, const wxBitmap
&bitmap
, const wxSize
&size
) :
1184 wxWindow( parent
, wxID_ANY
, wxPoint(0,0), size
)
1187 Connect( wxEVT_PAINT
, wxPaintEventHandler(wxBitmapCanvas::OnPaint
) );
1190 void OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1193 dc
.DrawBitmap( m_bitmap
, 0, 0);
1199 class wxDataViewDropSource
: public wxDropSource
1202 wxDataViewDropSource( wxDataViewMainWindow
*win
, unsigned int row
) :
1210 ~wxDataViewDropSource()
1215 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
) )
1217 wxPoint pos
= wxGetMousePosition();
1221 int liney
= m_win
->GetLineStart( m_row
);
1223 m_win
->GetOwner()->CalcUnscrolledPosition( 0, liney
, NULL
, &liney
);
1224 m_win
->ClientToScreen( &linex
, &liney
);
1225 m_dist_x
= pos
.x
- linex
;
1226 m_dist_y
= pos
.y
- liney
;
1229 wxBitmap ib
= m_win
->CreateItemBitmap( m_row
, indent
);
1231 m_hint
= new wxFrame( m_win
->GetParent(), wxID_ANY
, wxEmptyString
,
1232 wxPoint(pos
.x
- m_dist_x
, pos
.y
+ 5 ),
1234 wxFRAME_TOOL_WINDOW
|
1235 wxFRAME_FLOAT_ON_PARENT
|
1236 wxFRAME_NO_TASKBAR
|
1238 new wxBitmapCanvas( m_hint
, ib
, ib
.GetSize() );
1243 m_hint
->Move( pos
.x
- m_dist_x
, pos
.y
+ 5 );
1244 m_hint
->SetTransparent( 128 );
1250 wxDataViewMainWindow
*m_win
;
1253 int m_dist_x
,m_dist_y
;
1257 class wxDataViewDropTarget
: public wxDropTarget
1260 wxDataViewDropTarget( wxDataObject
*obj
, wxDataViewMainWindow
*win
) :
1266 virtual wxDragResult
OnDragOver( wxCoord x
, wxCoord y
, wxDragResult def
)
1268 wxDataFormat format
= GetMatchingPair();
1269 if (format
== wxDF_INVALID
)
1271 return m_win
->OnDragOver( format
, x
, y
, def
);
1274 virtual bool OnDrop( wxCoord x
, wxCoord y
)
1276 wxDataFormat format
= GetMatchingPair();
1277 if (format
== wxDF_INVALID
)
1279 return m_win
->OnDrop( format
, x
, y
);
1282 virtual wxDragResult
OnData( wxCoord x
, wxCoord y
, wxDragResult def
)
1284 wxDataFormat format
= GetMatchingPair();
1285 if (format
== wxDF_INVALID
)
1289 return m_win
->OnData( format
, x
, y
, def
);
1292 virtual void OnLeave()
1293 { m_win
->OnLeave(); }
1295 wxDataViewMainWindow
*m_win
;
1298 #endif // wxUSE_DRAG_AND_DROP
1300 //-----------------------------------------------------------------------------
1301 // wxDataViewRenameTimer
1302 //-----------------------------------------------------------------------------
1304 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1309 void wxDataViewRenameTimer::Notify()
1311 m_owner
->OnRenameTimer();
1314 //-----------------------------------------------------------------------------
1315 // wxDataViewMainWindow
1316 //-----------------------------------------------------------------------------
1318 // The tree building helper, declared firstly
1319 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
1320 wxDataViewTreeNode
* node
);
1322 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1324 if (row1
> row2
) return 1;
1325 if (row1
== row2
) return 0;
1329 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1331 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1332 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1333 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1334 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1335 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1336 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1339 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1340 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1341 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
1342 m_selection( wxDataViewSelectionCmp
)
1347 m_lastOnSame
= false;
1348 m_renameTimer
= new wxDataViewRenameTimer( this );
1350 // TODO: user better initial values/nothing selected
1351 m_currentCol
= NULL
;
1354 m_lineHeight
= wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
1356 #if wxUSE_DRAG_AND_DROP
1358 m_dragStart
= wxPoint(0,0);
1360 m_dragEnabled
= false;
1361 m_dropEnabled
= false;
1363 m_dropHintLine
= (unsigned int) -1;
1364 #endif // wxUSE_DRAG_AND_DROP
1366 m_lineLastClicked
= (unsigned int) -1;
1367 m_lineBeforeLastClicked
= (unsigned int) -1;
1368 m_lineSelectSingleOnUp
= (unsigned int) -1;
1372 SetBackgroundColour( *wxWHITE
);
1374 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1376 m_penRule
= wxPen(GetRuleColour());
1378 // compose a pen whichcan draw black lines
1379 // TODO: maybe there is something system colour to use
1380 m_penExpander
= wxPen(wxColour(0,0,0));
1382 m_root
= new wxDataViewTreeNode( NULL
);
1383 m_root
->SetHasChildren(true);
1385 // Make m_count = -1 will cause the class recaculate the real displaying number of rows.
1387 m_underMouse
= NULL
;
1391 wxDataViewMainWindow::~wxDataViewMainWindow()
1394 delete m_renameTimer
;
1398 #if wxUSE_DRAG_AND_DROP
1399 bool wxDataViewMainWindow::EnableDragSource( const wxDataFormat
&format
)
1401 m_dragFormat
= format
;
1402 m_dragEnabled
= format
!= wxDF_INVALID
;
1407 bool wxDataViewMainWindow::EnableDropTarget( const wxDataFormat
&format
)
1409 m_dropFormat
= format
;
1410 m_dropEnabled
= format
!= wxDF_INVALID
;
1413 SetDropTarget( new wxDataViewDropTarget( new wxCustomDataObject( format
), this ) );
1418 void wxDataViewMainWindow::RemoveDropHint()
1423 RefreshRow( m_dropHintLine
);
1424 m_dropHintLine
= (unsigned int) -1;
1428 wxDragResult
wxDataViewMainWindow::OnDragOver( wxDataFormat format
, wxCoord x
,
1429 wxCoord y
, wxDragResult def
)
1433 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1434 unsigned int row
= GetLineAt( yy
);
1436 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1442 wxDataViewItem item
= GetItemByRow( row
);
1444 wxDataViewModel
*model
= GetOwner()->GetModel();
1446 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1447 event
.SetEventObject( m_owner
);
1448 event
.SetItem( item
);
1449 event
.SetModel( model
);
1450 event
.SetDataFormat( format
);
1451 if (!m_owner
->HandleWindowEvent( event
))
1457 if (!event
.IsAllowed())
1464 if (m_dropHint
&& (row
!= m_dropHintLine
))
1465 RefreshRow( m_dropHintLine
);
1467 m_dropHintLine
= row
;
1473 bool wxDataViewMainWindow::OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
)
1479 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1480 unsigned int row
= GetLineAt( yy
);
1482 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1485 wxDataViewItem item
= GetItemByRow( row
);
1487 wxDataViewModel
*model
= GetOwner()->GetModel();
1489 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1490 event
.SetEventObject( m_owner
);
1491 event
.SetItem( item
);
1492 event
.SetModel( model
);
1493 event
.SetDataFormat( format
);
1494 if (!m_owner
->HandleWindowEvent( event
))
1497 if (!event
.IsAllowed())
1503 wxDragResult
wxDataViewMainWindow::OnData( wxDataFormat format
, wxCoord x
, wxCoord y
,
1508 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1509 unsigned int row
= GetLineAt( yy
);
1511 if ((row
>= GetRowCount()) || (yy
> GetEndOfLastCol()))
1514 wxDataViewItem item
= GetItemByRow( row
);
1516 wxDataViewModel
*model
= GetOwner()->GetModel();
1518 wxCustomDataObject
*obj
= (wxCustomDataObject
*) GetDropTarget()->GetDataObject();
1520 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
1521 event
.SetEventObject( m_owner
);
1522 event
.SetItem( item
);
1523 event
.SetModel( model
);
1524 event
.SetDataFormat( format
);
1525 event
.SetDataSize( obj
->GetSize() );
1526 event
.SetDataBuffer( obj
->GetData() );
1527 if (!m_owner
->HandleWindowEvent( event
))
1530 if (!event
.IsAllowed())
1536 void wxDataViewMainWindow::OnLeave()
1541 wxBitmap
wxDataViewMainWindow::CreateItemBitmap( unsigned int row
, int &indent
)
1543 int height
= GetLineHeight( row
);
1545 unsigned int cols
= GetOwner()->GetColumnCount();
1547 for (col
= 0; col
< cols
; col
++)
1549 wxDataViewColumn
*column
= GetOwner()->GetColumnAt(col
);
1550 if (column
->IsHidden())
1551 continue; // skip it!
1552 width
+= column
->GetWidth();
1556 if (!IsVirtualList())
1558 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
1559 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
1560 indent
= indent
+ m_lineHeight
;
1561 // try to use the m_lineHeight as the expander space
1563 if(!node
->HasChildren())
1568 wxBitmap
bitmap( width
, height
);
1569 wxMemoryDC
dc( bitmap
);
1570 dc
.SetFont( GetFont() );
1571 dc
.SetPen( *wxBLACK_PEN
);
1572 dc
.SetBrush( *wxWHITE_BRUSH
);
1573 dc
.DrawRectangle( 0,0,width
,height
);
1575 wxDataViewModel
*model
= m_owner
->GetModel();
1577 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1580 // TODO-RTL: last column for RTL support
1581 expander
= GetOwner()->GetColumnAt( 0 );
1582 GetOwner()->SetExpanderColumn(expander
);
1587 for (col
= 0; col
< cols
; col
++)
1589 wxDataViewColumn
*column
= GetOwner()->GetColumnAt( col
);
1590 wxDataViewRenderer
*cell
= column
->GetRenderer();
1592 if (column
->IsHidden())
1593 continue; // skip it!
1595 width
= column
->GetWidth();
1597 if (column
== expander
)
1601 wxDataViewItem item
= GetItemByRow( row
);
1602 model
->GetValue( value
, item
, column
->GetModelColumn());
1603 cell
->SetValue( value
);
1605 if (cell
->GetWantsAttr())
1607 wxDataViewItemAttr attr
;
1608 bool ret
= model
->GetAttr( item
, column
->GetModelColumn(), attr
);
1610 cell
->SetAttr( attr
);
1611 cell
->SetHasAttr( ret
);
1614 wxSize size
= cell
->GetSize();
1615 size
.x
= wxMin( 2*PADDING_RIGHTLEFT
+ size
.x
, width
);
1617 wxRect
item_rect(x
, 0, size
.x
, size
.y
);
1619 int align
= cell
->CalculateAlignment();
1620 // horizontal alignment:
1622 if (align
& wxALIGN_CENTER_HORIZONTAL
)
1623 item_rect
.x
= x
+ (width
/ 2) - (size
.x
/ 2);
1624 else if (align
& wxALIGN_RIGHT
)
1625 item_rect
.x
= x
+ width
- size
.x
;
1626 // else: wxALIGN_LEFT is the default
1628 // vertical alignment:
1630 if (align
& wxALIGN_CENTER_VERTICAL
)
1631 item_rect
.y
= (height
/ 2) - (size
.y
/ 2);
1632 else if (align
& wxALIGN_BOTTOM
)
1633 item_rect
.y
= height
- size
.y
;
1634 // else: wxALIGN_TOP is the default
1637 item_rect
.x
+= PADDING_RIGHTLEFT
;
1638 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
1640 // dc.SetClippingRegion( item_rect );
1641 cell
->Render( item_rect
, &dc
, 0 );
1642 // dc.DestroyClippingRegion();
1650 #endif // wxUSE_DRAG_AND_DROP
1653 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1655 wxDataViewModel
*model
= GetOwner()->GetModel();
1656 wxAutoBufferedPaintDC
dc( this );
1659 dc
.SetBrush(GetOwner()->GetBackgroundColour());
1660 dc
.SetPen( *wxTRANSPARENT_PEN
);
1661 dc
.DrawRectangle(GetClientSize());
1665 GetOwner()->PrepareDC( dc
);
1666 dc
.SetFont( GetFont() );
1668 wxRect update
= GetUpdateRegion().GetBox();
1669 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1671 // compute which items needs to be redrawn
1672 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
1673 unsigned int item_count
=
1674 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
1675 (int)(GetRowCount( ) - item_start
));
1676 unsigned int item_last
= item_start
+ item_count
;
1677 // Get the parent of DataViewCtrl
1678 wxWindow
*parent
= GetParent()->GetParent();
1679 wxDataViewEvent
cache_event(wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, parent
->GetId());
1680 cache_event
.SetEventObject(GetParent());
1681 cache_event
.SetCache(item_start
, item_last
- 1);
1682 parent
->ProcessWindowEvent(cache_event
);
1684 // compute which columns needs to be redrawn
1685 unsigned int cols
= GetOwner()->GetColumnCount();
1686 unsigned int col_start
= 0;
1687 unsigned int x_start
;
1688 for (x_start
= 0; col_start
< cols
; col_start
++)
1690 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_start
);
1691 if (col
->IsHidden())
1692 continue; // skip it!
1694 unsigned int w
= col
->GetWidth();
1695 if (x_start
+w
>= (unsigned int)update
.x
)
1701 unsigned int col_last
= col_start
;
1702 unsigned int x_last
= x_start
;
1703 for (; col_last
< cols
; col_last
++)
1705 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_last
);
1706 if (col
->IsHidden())
1707 continue; // skip it!
1709 if (x_last
> (unsigned int)update
.GetRight())
1712 x_last
+= col
->GetWidth();
1715 // Draw horizontal rules if required
1716 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1718 dc
.SetPen(m_penRule
);
1719 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1721 for (unsigned int i
= item_start
; i
<= item_last
; i
++)
1723 int y
= GetLineStart( i
);
1724 dc
.DrawLine(x_start
, y
, x_last
, y
);
1728 // Draw vertical rules if required
1729 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1731 dc
.SetPen(m_penRule
);
1732 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1735 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1737 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(i
);
1738 if (col
->IsHidden())
1739 continue; // skip it
1741 dc
.DrawLine(x
, GetLineStart( item_start
),
1742 x
, GetLineStart( item_last
) );
1744 x
+= col
->GetWidth();
1747 // Draw last vertical rule
1748 dc
.DrawLine(x
, GetLineStart( item_start
),
1749 x
, GetLineStart( item_last
) );
1752 // redraw the background for the items which are selected/current
1753 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1755 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1756 if (selected
|| item
== m_currentRow
)
1758 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
1759 if (item
== m_currentRow
)
1760 flags
|= wxCONTROL_CURRENT
;
1762 flags
|= wxCONTROL_FOCUSED
;
1764 wxRect
rect( x_start
, GetLineStart( item
), x_last
, GetLineHeight( item
) );
1765 wxRendererNative::Get().DrawItemSelectionRect
1775 #if wxUSE_DRAG_AND_DROP
1778 wxRect
rect( x_start
, GetLineStart( m_dropHintLine
),
1779 x_last
, GetLineHeight( m_dropHintLine
) );
1780 dc
.SetPen( *wxBLACK_PEN
);
1781 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1782 dc
.DrawRectangle( rect
);
1784 #endif // wxUSE_DRAG_AND_DROP
1786 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1789 // TODO-RTL: last column for RTL support
1790 expander
= GetOwner()->GetColumnAt( 0 );
1791 GetOwner()->SetExpanderColumn(expander
);
1794 // redraw all cells for all rows which must be repainted and all columns
1796 cell_rect
.x
= x_start
;
1797 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1799 wxDataViewColumn
*col
= GetOwner()->GetColumnAt( i
);
1800 wxDataViewRenderer
*cell
= col
->GetRenderer();
1801 cell_rect
.width
= col
->GetWidth();
1803 if (col
->IsHidden())
1804 continue; // skip it!
1806 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1808 // get the cell value and set it into the renderer
1810 wxDataViewTreeNode
*node
= NULL
;
1811 wxDataViewItem dataitem
;
1813 if (!IsVirtualList())
1815 node
= GetTreeNodeByRow(item
);
1819 dataitem
= node
->GetItem();
1821 if ((i
> 0) && model
->IsContainer(dataitem
) &&
1822 !model
->HasContainerColumns(dataitem
))
1827 dataitem
= wxDataViewItem( wxUIntToPtr(item
+1) );
1830 model
->GetValue( value
, dataitem
, col
->GetModelColumn());
1831 cell
->SetValue( value
);
1833 if (cell
->GetWantsAttr())
1835 wxDataViewItemAttr attr
;
1836 bool ret
= model
->GetAttr( dataitem
, col
->GetModelColumn(), attr
);
1838 cell
->SetAttr( attr
);
1839 cell
->SetHasAttr( ret
);
1843 cell_rect
.y
= GetLineStart( item
);
1844 cell_rect
.height
= GetLineHeight( item
);
1846 // Draw the expander here.
1848 if ((!IsVirtualList()) && (col
== expander
))
1850 indent
= node
->GetIndentLevel();
1852 // Calculate the indent first
1853 indent
= cell_rect
.x
+ GetOwner()->GetIndent() * indent
;
1855 int expander_width
= m_lineHeight
- 2*EXPANDER_MARGIN
;
1857 // change the cell_rect.x to the appropriate pos
1858 int expander_x
= indent
+ EXPANDER_MARGIN
;
1859 int expander_y
= cell_rect
.y
+ EXPANDER_MARGIN
+ (GetLineHeight(item
) / 2)
1860 - (expander_width
/2) - EXPANDER_OFFSET
;
1862 indent
= indent
+ m_lineHeight
;
1863 // try to use the m_lineHeight as the expander space
1865 dc
.SetPen( m_penExpander
);
1866 dc
.SetBrush( wxNullBrush
);
1867 if( node
->HasChildren() )
1869 wxRect
rect( expander_x
, expander_y
, expander_width
, expander_width
);
1871 if (m_underMouse
== node
)
1873 flag
|= wxCONTROL_CURRENT
;
1875 if( node
->IsOpen() )
1876 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
,
1877 flag
|wxCONTROL_EXPANDED
);
1879 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
1882 // force the expander column to left-center align
1883 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
1885 if (node
&& !node
->HasChildren())
1887 // Yes, if the node does not have any child, it must be a leaf which
1888 // mean that it is a temporarily created by GetTreeNodeByRow
1892 // cannot be bigger than allocated space
1893 wxSize size
= cell
->GetSize();
1895 // Because of the tree structure indent, here we should minus the width
1896 // of the cell for drawing
1897 size
.x
= wxMin( size
.x
+ 2*PADDING_RIGHTLEFT
, cell_rect
.width
- indent
);
1898 // size.y = wxMin( size.y, cell_rect.height );
1899 size
.y
= cell_rect
.height
;
1901 wxRect
item_rect(cell_rect
.GetTopLeft(), size
);
1902 int align
= cell
->CalculateAlignment();
1904 // horizontal alignment:
1905 item_rect
.x
= cell_rect
.x
;
1906 if (align
& wxALIGN_CENTER_HORIZONTAL
)
1907 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
1908 else if (align
& wxALIGN_RIGHT
)
1909 item_rect
.x
= cell_rect
.x
+ cell_rect
.width
- size
.x
;
1910 // else: wxALIGN_LEFT is the default
1912 // vertical alignment:
1913 item_rect
.y
= cell_rect
.y
;
1914 if (align
& wxALIGN_CENTER_VERTICAL
)
1915 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
1916 else if (align
& wxALIGN_BOTTOM
)
1917 item_rect
.y
= cell_rect
.y
+ cell_rect
.height
- size
.y
;
1918 // else: wxALIGN_TOP is the default
1921 item_rect
.x
+= PADDING_RIGHTLEFT
;
1922 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
1924 // Here we add the tree indent
1925 item_rect
.x
+= indent
;
1928 if (m_hasFocus
&& (m_selection
.Index(item
) != wxNOT_FOUND
))
1929 state
|= wxDATAVIEW_CELL_SELECTED
;
1931 // TODO: it would be much more efficient to create a clipping
1932 // region for the entire column being rendered (in the OnPaint
1933 // of wxDataViewMainWindow) instead of a single clip region for
1934 // each cell. However it would mean that each renderer should
1935 // respect the given wxRect's top & bottom coords, eventually
1936 // violating only the left & right coords - however the user can
1937 // make its own renderer and thus we cannot be sure of that.
1938 dc
.SetClippingRegion( item_rect
);
1939 cell
->Render( item_rect
, &dc
, state
);
1940 dc
.DestroyClippingRegion();
1943 cell_rect
.x
+= cell_rect
.width
;
1947 void wxDataViewMainWindow::OnRenameTimer()
1949 // We have to call this here because changes may just have
1950 // been made and no screen update taken place.
1953 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
1954 // (needs to be tested!)
1958 wxDataViewItem item
= GetItemByRow( m_currentRow
);
1960 wxRect labelRect
= GetItemRect(item
, m_currentCol
);
1962 m_currentCol
->GetRenderer()->StartEditing( item
, labelRect
);
1965 //-----------------------------------------------------------------------------
1966 // Helper class for do operation on the tree node
1967 //-----------------------------------------------------------------------------
1972 virtual ~DoJob() { }
1974 // The return value control how the tree-walker tranverse the tree
1975 // 0: Job done, stop tranverse and return
1976 // 1: Ignore the current node's subtree and continue
1977 // 2: Job not done, continue
1978 enum { OK
= 0 , IGR
= 1, CONT
= 2 };
1979 virtual int operator() ( wxDataViewTreeNode
* node
) = 0;
1980 virtual int operator() ( void * n
) = 0;
1983 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
1988 switch( func( node
) )
1999 wxDataViewTreeNodes nodes
= node
->GetNodes();
2000 wxDataViewTreeLeaves leaves
= node
->GetChildren();
2002 int len_nodes
= nodes
.GetCount();
2003 int len
= leaves
.GetCount();
2004 int i
= 0, nodes_i
= 0;
2006 for(; i
< len
; i
++ )
2008 void * n
= leaves
[i
];
2009 if( nodes_i
< len_nodes
&& n
== nodes
[nodes_i
]->GetItem().GetID() )
2011 wxDataViewTreeNode
* nd
= nodes
[nodes_i
];
2014 if( Walker( nd
, func
) )
2033 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
2035 if (IsVirtualList())
2037 wxDataViewVirtualListModel
*list_model
=
2038 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
2039 m_count
= list_model
->GetCount();
2046 wxDataViewTreeNode
* node
;
2047 node
= FindNode(parent
);
2052 node
->SetHasChildren( true );
2054 if( g_model
->IsContainer( item
) )
2056 wxDataViewTreeNode
* newnode
= new wxDataViewTreeNode( node
);
2057 newnode
->SetItem(item
);
2058 newnode
->SetHasChildren( true );
2059 node
->AddNode( newnode
);
2062 node
->AddLeaf( item
.GetID() );
2064 node
->ChangeSubTreeCount(1);
2072 static void DestroyTreeHelper( wxDataViewTreeNode
* node
);
2074 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
2075 const wxDataViewItem
& item
)
2077 if (IsVirtualList())
2079 wxDataViewVirtualListModel
*list_model
=
2080 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
2081 m_count
= list_model
->GetCount();
2083 if( m_currentRow
> GetRowCount() )
2084 m_currentRow
= m_count
- 1;
2086 // TODO: why empty the entire selection?
2087 m_selection
.Empty();
2094 wxDataViewTreeNode
* node
= FindNode(parent
);
2096 wxCHECK_MSG( node
!= NULL
, false, "item not found" );
2097 wxCHECK_MSG( node
->GetChildren().Index( item
.GetID() ) != wxNOT_FOUND
,
2098 false, "item not found" );
2101 node
->GetChildren().Remove( item
.GetID() );
2102 // Manipolate selection
2103 if( m_selection
.GetCount() > 1 )
2105 m_selection
.Empty();
2107 bool isContainer
= false;
2108 wxDataViewTreeNodes nds
= node
->GetNodes();
2109 for (size_t i
= 0; i
< nds
.GetCount(); i
++)
2111 if (nds
[i
]->GetItem() == item
)
2119 wxDataViewTreeNode
* n
= NULL
;
2120 wxDataViewTreeNodes nodes
= node
->GetNodes();
2121 int len
= nodes
.GetCount();
2122 for( int i
= 0; i
< len
; i
++)
2124 if( nodes
[i
]->GetItem() == item
)
2131 wxCHECK_MSG( n
!= NULL
, false, "item not found" );
2133 node
->GetNodes().Remove( n
);
2134 sub
-= n
->GetSubTreeCount();
2135 ::DestroyTreeHelper(n
);
2137 // Make the row number invalid and get a new valid one when user call GetRowCount
2139 node
->ChangeSubTreeCount(sub
);
2141 // Change the current row to the last row if the current exceed the max row number
2142 if( m_currentRow
> GetRowCount() )
2143 m_currentRow
= m_count
- 1;
2150 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
2156 wxWindow
*parent
= GetParent();
2157 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2158 le
.SetEventObject(parent
);
2159 le
.SetModel(GetOwner()->GetModel());
2161 parent
->GetEventHandler()->ProcessEvent(le
);
2166 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
2168 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
2169 /*#define MAX_VIRTUAL_WIDTH 100000
2171 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
2172 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2173 Refresh( true, &rect );
2181 wxWindow
*parent
= GetParent();
2182 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2183 le
.SetEventObject(parent
);
2184 le
.SetModel(GetOwner()->GetModel());
2187 le
.SetDataViewColumn(GetOwner()->GetColumn(col
));
2188 parent
->GetEventHandler()->ProcessEvent(le
);
2193 bool wxDataViewMainWindow::Cleared()
2198 BuildTree( GetOwner()->GetModel() );
2205 void wxDataViewMainWindow::UpdateDisplay()
2210 void wxDataViewMainWindow::OnInternalIdle()
2212 wxWindow::OnInternalIdle();
2216 RecalculateDisplay();
2221 void wxDataViewMainWindow::RecalculateDisplay()
2223 wxDataViewModel
*model
= GetOwner()->GetModel();
2230 int width
= GetEndOfLastCol();
2231 int height
= GetLineStart( GetRowCount() );
2233 SetVirtualSize( width
, height
);
2234 GetOwner()->SetScrollRate( 10, m_lineHeight
);
2239 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2241 wxWindow::ScrollWindow( dx
, dy
, rect
);
2243 if (GetOwner()->m_headerArea
)
2244 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
2247 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
2250 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
2251 int sy
= GetLineStart( rows
)/y
;
2255 wxRect rect
= GetClientRect();
2259 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
2260 for (x_start
= 0; colnum
< column
; colnum
++)
2262 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(colnum
);
2263 if (col
->IsHidden())
2264 continue; // skip it!
2266 w
= col
->GetWidth();
2270 int x_end
= x_start
+ w
;
2271 xe
= xx
+ rect
.width
;
2274 sx
= ( xx
+ x_end
- xe
)/x
;
2281 m_owner
->Scroll( sx
, sy
);
2284 int wxDataViewMainWindow::GetCountPerPage() const
2286 wxSize size
= GetClientSize();
2287 return size
.y
/ m_lineHeight
;
2290 int wxDataViewMainWindow::GetEndOfLastCol() const
2294 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2296 const wxDataViewColumn
*c
=
2297 const_cast<wxDataViewCtrl
*>(GetOwner())->GetColumnAt( i
);
2300 width
+= c
->GetWidth();
2305 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2309 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2311 return GetLineAt( y
);
2314 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
2316 wxSize client_size
= GetClientSize();
2317 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2318 &client_size
.x
, &client_size
.y
);
2320 // we should deal with the pixel here
2321 unsigned int row
= GetLineAt(client_size
.y
) - 1;
2323 return wxMin( GetRowCount()-1, row
);
2326 unsigned int wxDataViewMainWindow::GetRowCount()
2328 if ( m_count
== -1 )
2330 m_count
= RecalculateCount();
2336 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
2343 void wxDataViewMainWindow::SelectAllRows( bool on
)
2350 m_selection
.Clear();
2351 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2352 m_selection
.Add( i
);
2357 unsigned int first_visible
= GetFirstVisibleRow();
2358 unsigned int last_visible
= GetLastVisibleRow();
2360 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2362 unsigned int row
= m_selection
[i
];
2363 if ((row
>= first_visible
) && (row
<= last_visible
))
2366 m_selection
.Clear();
2370 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
2372 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2376 m_selection
.Add( row
);
2384 m_selection
.Remove( row
);
2390 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2394 unsigned int tmp
= from
;
2400 for (i
= from
; i
<= to
; i
++)
2402 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2405 m_selection
.Add( i
);
2410 m_selection
.Remove( i
);
2413 RefreshRows( from
, to
);
2416 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2418 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2420 int n
= aSelections
[i
];
2422 m_selection
.Add( n
);
2427 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2429 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2430 m_selection
.Add( row
);
2432 m_selection
.Remove( row
);
2436 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2438 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2441 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
2443 wxWindow
*parent
= GetParent();
2444 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
2446 le
.SetEventObject(parent
);
2447 le
.SetModel(GetOwner()->GetModel());
2450 parent
->GetEventHandler()->ProcessEvent(le
);
2453 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2455 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
2456 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2458 wxSize client_size
= GetClientSize();
2459 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2460 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2461 if (intersect_rect
.width
> 0)
2462 Refresh( true, &intersect_rect
);
2465 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2469 unsigned int tmp
= to
;
2474 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
2475 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2477 wxSize client_size
= GetClientSize();
2478 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2479 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2480 if (intersect_rect
.width
> 0)
2481 Refresh( true, &intersect_rect
);
2484 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2486 wxSize client_size
= GetClientSize();
2487 int start
= GetLineStart( firstRow
);
2488 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
2489 if (start
> client_size
.y
) return;
2491 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
2493 Refresh( true, &rect
);
2496 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2498 wxCHECK_RET( newCurrent
< GetRowCount(),
2499 wxT("invalid item index in OnArrowChar()") );
2501 // if there is no selection, we cannot move it anywhere
2502 if (!HasCurrentRow())
2505 unsigned int oldCurrent
= m_currentRow
;
2507 // in single selection we just ignore Shift as we can't select several
2509 if ( event
.ShiftDown() && !IsSingleSel() )
2511 RefreshRow( oldCurrent
);
2513 ChangeCurrentRow( newCurrent
);
2515 // select all the items between the old and the new one
2516 if ( oldCurrent
> newCurrent
)
2518 newCurrent
= oldCurrent
;
2519 oldCurrent
= m_currentRow
;
2522 SelectRows( oldCurrent
, newCurrent
, true );
2523 if (oldCurrent
!=newCurrent
)
2524 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
2528 RefreshRow( oldCurrent
);
2530 // all previously selected items are unselected unless ctrl is held
2531 if ( !event
.ControlDown() )
2532 SelectAllRows(false);
2534 ChangeCurrentRow( newCurrent
);
2536 if ( !event
.ControlDown() )
2538 SelectRow( m_currentRow
, true );
2539 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
2542 RefreshRow( m_currentRow
);
2545 GetOwner()->EnsureVisible( m_currentRow
, -1 );
2548 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2552 rect
.y
= GetLineStart( row
);
2553 rect
.width
= GetEndOfLastCol();
2554 rect
.height
= GetLineHeight( row
);
2559 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2561 const wxDataViewModel
*model
= GetOwner()->GetModel();
2563 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2565 // TODO make more efficient
2570 for (r
= 0; r
< row
; r
++)
2572 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2573 if (!node
) return start
;
2575 wxDataViewItem item
= node
->GetItem();
2577 if (node
&& !node
->HasChildren())
2579 // Yes, if the node does not have any child, it must be a leaf which
2580 // mean that it is a temporarily created by GetTreeNodeByRow
2584 unsigned int cols
= GetOwner()->GetColumnCount();
2586 int height
= m_lineHeight
;
2587 for (col
= 0; col
< cols
; col
++)
2589 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2590 if (column
->IsHidden())
2591 continue; // skip it!
2594 model
->IsContainer(item
) &&
2595 !model
->HasContainerColumns(item
))
2596 continue; // skip it!
2599 model
->GetValue( value
, item
, column
->GetModelColumn() );
2601 wxDataViewRenderer
*renderer
=
2602 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2603 renderer
->SetValue( value
);
2604 height
= wxMax( height
, renderer
->GetSize().y
);
2614 return row
* m_lineHeight
;
2618 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
2620 const wxDataViewModel
*model
= GetOwner()->GetModel();
2622 // check for the easy case first
2623 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
2624 return y
/ m_lineHeight
;
2626 // TODO make more efficient
2627 unsigned int row
= 0;
2628 unsigned int yy
= 0;
2631 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2634 // not really correct...
2635 return row
+ ((y
-yy
) / m_lineHeight
);
2638 wxDataViewItem item
= node
->GetItem();
2640 if (node
&& !node
->HasChildren())
2642 // Yes, if the node does not have any child, it must be a leaf which
2643 // mean that it is a temporarily created by GetTreeNodeByRow
2647 unsigned int cols
= GetOwner()->GetColumnCount();
2649 int height
= m_lineHeight
;
2650 for (col
= 0; col
< cols
; col
++)
2652 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2653 if (column
->IsHidden())
2654 continue; // skip it!
2657 model
->IsContainer(item
) &&
2658 !model
->HasContainerColumns(item
))
2659 continue; // skip it!
2662 model
->GetValue( value
, item
, column
->GetModelColumn() );
2664 wxDataViewRenderer
*renderer
=
2665 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2666 renderer
->SetValue( value
);
2667 height
= wxMax( height
, renderer
->GetSize().y
);
2678 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
2680 const wxDataViewModel
*model
= GetOwner()->GetModel();
2682 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2684 wxASSERT( !IsVirtualList() );
2686 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2687 // wxASSERT( node );
2688 if (!node
) return m_lineHeight
;
2690 wxDataViewItem item
= node
->GetItem();
2692 if (node
&& !node
->HasChildren())
2694 // Yes, if the node does not have any child, it must be a leaf which
2695 // mean that it is a temporarily created by GetTreeNodeByRow
2699 int height
= m_lineHeight
;
2701 unsigned int cols
= GetOwner()->GetColumnCount();
2703 for (col
= 0; col
< cols
; col
++)
2705 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2706 if (column
->IsHidden())
2707 continue; // skip it!
2710 model
->IsContainer(item
) &&
2711 !model
->HasContainerColumns(item
))
2712 continue; // skip it!
2715 model
->GetValue( value
, item
, column
->GetModelColumn() );
2717 wxDataViewRenderer
*renderer
=
2718 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2719 renderer
->SetValue( value
);
2720 height
= wxMax( height
, renderer
->GetSize().y
);
2727 return m_lineHeight
;
2731 class RowToItemJob
: public DoJob
2734 RowToItemJob( unsigned int row
, int current
)
2735 { this->row
= row
; this->current
= current
; }
2736 virtual ~RowToItemJob() {}
2738 virtual int operator() ( wxDataViewTreeNode
* node
)
2741 if( current
== static_cast<int>(row
))
2743 ret
= node
->GetItem();
2747 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2749 current
+= node
->GetSubTreeCount();
2754 // If the current has no child node, we can find the desired item of the row
2756 // This if can speed up finding in some case, and will has a very good effect
2757 // when it comes to list view
2758 if( node
->GetNodes().GetCount() == 0)
2760 int index
= static_cast<int>(row
) - current
- 1;
2761 ret
= node
->GetChildren().Item( index
);
2768 virtual int operator() ( void * n
)
2771 if( current
== static_cast<int>(row
))
2773 ret
= wxDataViewItem( n
);
2779 wxDataViewItem
GetResult() const
2788 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
2790 if (IsVirtualList())
2792 return wxDataViewItem( wxUIntToPtr(row
+1) );
2796 RowToItemJob
job( row
, -2 );
2797 Walker( m_root
, job
);
2798 return job
.GetResult();
2802 class RowToTreeNodeJob
: public DoJob
2805 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
2808 this->current
= current
;
2812 virtual ~RowToTreeNodeJob(){ }
2814 virtual int operator() ( wxDataViewTreeNode
* node
)
2817 if( current
== static_cast<int>(row
))
2823 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2825 current
+= node
->GetSubTreeCount();
2832 // If the current node has no children, we can find the desired item of the
2833 // row number directly.
2834 // This if can speed up finding in some case, and will have a very good
2835 // effect for list views.
2836 if( node
->GetNodes().GetCount() == 0)
2838 int index
= static_cast<int>(row
) - current
- 1;
2839 void * n
= node
->GetChildren().Item( index
);
2840 ret
= new wxDataViewTreeNode( parent
);
2841 ret
->SetItem( wxDataViewItem( n
));
2842 ret
->SetHasChildren(false);
2849 virtual int operator() ( void * n
)
2852 if( current
== static_cast<int>(row
))
2854 ret
= new wxDataViewTreeNode( parent
);
2855 ret
->SetItem( wxDataViewItem( n
));
2856 ret
->SetHasChildren(false);
2863 wxDataViewTreeNode
* GetResult() const
2869 wxDataViewTreeNode
* ret
;
2870 wxDataViewTreeNode
* parent
;
2873 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
2875 wxASSERT( !IsVirtualList() );
2877 RowToTreeNodeJob
job( row
, -2, m_root
);
2878 Walker( m_root
, job
);
2879 return job
.GetResult();
2882 wxDataViewEvent
wxDataViewMainWindow::SendExpanderEvent( wxEventType type
,
2883 const wxDataViewItem
& item
)
2885 wxWindow
*parent
= GetParent();
2886 wxDataViewEvent
le(type
, parent
->GetId());
2888 le
.SetEventObject(parent
);
2889 le
.SetModel(GetOwner()->GetModel());
2892 parent
->GetEventHandler()->ProcessEvent(le
);
2896 bool wxDataViewMainWindow::IsExpanded( unsigned int row
) const
2898 if (IsVirtualList())
2901 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2905 if (!node
->HasChildren())
2911 return node
->IsOpen();
2914 bool wxDataViewMainWindow::HasChildren( unsigned int row
) const
2916 if (IsVirtualList())
2919 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2923 if (!node
->HasChildren())
2932 void wxDataViewMainWindow::Expand( unsigned int row
)
2934 if (IsVirtualList())
2937 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2941 if (!node
->HasChildren())
2947 if (!node
->IsOpen())
2950 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, node
->GetItem());
2952 // Check if the user prevent expanding
2953 if( e
.GetSkipped() )
2958 // build the children of current node
2959 if( node
->GetChildrenNumber() == 0 )
2962 ::BuildTreeHelper(GetOwner()->GetModel(), node
->GetItem(), node
);
2965 // By expanding the node all row indices that are currently in the selection list
2966 // and are greater than our node have become invalid. So we have to correct that now.
2967 const unsigned rowAdjustment
= node
->GetSubTreeCount();
2968 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
2970 const unsigned testRow
= m_selection
[i
];
2971 // all rows above us are not affected, so skip them
2975 m_selection
[i
] += rowAdjustment
;
2978 if(m_currentRow
> row
)
2979 ChangeCurrentRow(m_currentRow
+ rowAdjustment
);
2983 // Send the expanded event
2984 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
2988 void wxDataViewMainWindow::Collapse(unsigned int row
)
2990 if (IsVirtualList())
2993 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
2997 if (!node
->HasChildren())
3006 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem());
3007 if( e
.GetSkipped() )
3010 // Find out if there are selected items below the current node.
3011 bool selectCollapsingRow
= false;
3012 const unsigned rowAdjustment
= node
->GetSubTreeCount();
3013 unsigned maxRowToBeTested
= row
+ rowAdjustment
;
3014 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3016 const unsigned testRow
= m_selection
[i
];
3017 if(testRow
> row
&& testRow
<= maxRowToBeTested
)
3019 selectCollapsingRow
= true;
3020 // get out as soon as we have found a node that is selected
3027 // If the node to be closed has selected items the user won't see those any longer.
3028 // We select the collapsing node in this case.
3029 if(selectCollapsingRow
)
3031 SelectAllRows(false);
3032 ChangeCurrentRow(row
);
3033 SelectRow(row
, true);
3034 SendSelectionChangedEvent(GetItemByRow(row
));
3038 // if there were no selected items below our node we still need to "fix" the
3039 // selection list to adjust for the changing of the row indices.
3040 // We actually do the opposite of what we are doing in Expand().
3041 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3043 const unsigned testRow
= m_selection
[i
];
3044 // all rows above us are not affected, so skip them
3048 m_selection
[i
] -= rowAdjustment
;
3051 // if the "current row" is being collapsed away we change it to the current row ;-)
3052 if(m_currentRow
> row
&& m_currentRow
<= maxRowToBeTested
)
3053 ChangeCurrentRow(row
);
3054 else if(m_currentRow
> row
)
3055 ChangeCurrentRow(m_currentRow
- rowAdjustment
);
3060 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,node
->GetItem());
3064 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
3066 wxDataViewModel
* model
= GetOwner()->GetModel();
3073 // Compose the a parent-chain of the finding item
3075 list
.DeleteContents( true );
3076 wxDataViewItem
it( item
);
3079 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3080 list
.Insert( pItem
);
3081 it
= model
->GetParent( it
);
3084 // Find the item along the parent-chain.
3085 // This algorithm is designed to speed up the node-finding method
3086 wxDataViewTreeNode
* node
= m_root
;
3087 for( ItemList::const_iterator iter
= list
.begin(); iter
!=list
.end(); iter
++ )
3089 if( node
->HasChildren() )
3091 if( node
->GetChildrenNumber() == 0 )
3094 ::BuildTreeHelper(model
, node
->GetItem(), node
);
3097 wxDataViewTreeNodes nodes
= node
->GetNodes();
3101 for (i
= 0; i
< nodes
.GetCount(); i
++)
3103 if (nodes
[i
]->GetItem() == (**iter
))
3105 if (nodes
[i
]->GetItem() == item
)
3122 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
3123 wxDataViewColumn
* &column
)
3125 wxDataViewColumn
*col
= NULL
;
3126 unsigned int cols
= GetOwner()->GetColumnCount();
3127 unsigned int colnum
= 0;
3129 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
3130 for (unsigned x_start
= 0; colnum
< cols
; colnum
++)
3132 col
= GetOwner()->GetColumnAt(colnum
);
3133 if (col
->IsHidden())
3134 continue; // skip it!
3136 unsigned int w
= col
->GetWidth();
3137 if (x_start
+w
>= (unsigned int)x
)
3144 item
= GetItemByRow( GetLineAt( y
) );
3147 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
,
3148 const wxDataViewColumn
* column
)
3153 unsigned int cols
= GetOwner()->GetColumnCount();
3154 // If column is null the loop will compute the combined width of all columns.
3155 // Otherwise, it will compute the x position of the column we are looking for.
3156 for (unsigned int i
= 0; i
< cols
; i
++)
3158 wxDataViewColumn
* col
= GetOwner()->GetColumnAt( i
);
3163 if (col
->IsHidden())
3164 continue; // skip it!
3166 xpos
+= col
->GetWidth();
3167 width
+= col
->GetWidth();
3172 // If we have a column, we need can get its width directly.
3173 if(column
->IsHidden())
3176 width
= column
->GetWidth();
3181 // If we have no column, we reset the x position back to zero.
3185 // we have to take an expander column into account and compute its indentation
3186 // to get the correct x position where the actual text is
3188 int row
= GetRowByItem(item
);
3189 if (!IsVirtualList() && (column
== 0 || GetOwner()->GetExpanderColumn() == column
) )
3191 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3192 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
3193 indent
= indent
+ m_lineHeight
; // use m_lineHeight as the width of the expander
3195 if(!node
->HasChildren())
3199 wxRect
itemRect( xpos
+ indent
,
3200 GetLineStart( row
),
3202 GetLineHeight( row
) );
3204 GetOwner()->CalcScrolledPosition( itemRect
.x
, itemRect
.y
,
3205 &itemRect
.x
, &itemRect
.y
);
3210 int wxDataViewMainWindow::RecalculateCount()
3212 if (IsVirtualList())
3214 wxDataViewVirtualListModel
*list_model
=
3215 (wxDataViewVirtualListModel
*) GetOwner()->GetModel();
3217 return list_model
->GetCount();
3221 return m_root
->GetSubTreeCount();
3225 class ItemToRowJob
: public DoJob
3228 ItemToRowJob(const wxDataViewItem
& item_
, ItemList::const_iterator iter
)
3235 // Maybe binary search will help to speed up this process
3236 virtual int operator() ( wxDataViewTreeNode
* node
)
3239 if( node
->GetItem() == item
)
3244 if( node
->GetItem() == **m_iter
)
3251 ret
+= node
->GetSubTreeCount();
3257 virtual int operator() ( void * n
)
3260 if( n
== item
.GetID() )
3265 // the row number is begin from zero
3266 int GetResult() const
3270 ItemList::const_iterator m_iter
;
3271 wxDataViewItem item
;
3276 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
3278 const wxDataViewModel
* model
= GetOwner()->GetModel();
3282 if (IsVirtualList())
3284 return wxPtrToUInt( item
.GetID() ) -1;
3291 // Compose the a parent-chain of the finding item
3293 wxDataViewItem
* pItem
;
3294 list
.DeleteContents( true );
3295 wxDataViewItem
it( item
);
3298 pItem
= new wxDataViewItem( it
);
3299 list
.Insert( pItem
);
3300 it
= model
->GetParent( it
);
3302 pItem
= new wxDataViewItem( );
3303 list
.Insert( pItem
);
3305 ItemToRowJob
job( item
, list
.begin() );
3306 Walker(m_root
, job
);
3307 return job
.GetResult();
3311 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
,
3312 wxDataViewTreeNode
* node
)
3314 if( !model
->IsContainer( item
) )
3317 wxDataViewItemArray children
;
3318 unsigned int num
= model
->GetChildren( item
, children
);
3320 unsigned int index
= 0;
3321 while( index
< num
)
3323 if( model
->IsContainer( children
[index
] ) )
3325 wxDataViewTreeNode
* n
= new wxDataViewTreeNode( node
);
3326 n
->SetItem(children
[index
]);
3327 n
->SetHasChildren( true );
3332 node
->AddLeaf( children
[index
].GetID() );
3336 node
->SetSubTreeCount( num
);
3337 wxDataViewTreeNode
* n
= node
->GetParent();
3339 n
->ChangeSubTreeCount(num
);
3343 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
3347 if (GetOwner()->GetModel()->IsVirtualListModel())
3353 m_root
= new wxDataViewTreeNode( NULL
);
3354 m_root
->SetHasChildren(true);
3356 // First we define a invalid item to fetch the top-level elements
3357 wxDataViewItem item
;
3359 BuildTreeHelper( model
, item
, m_root
);
3363 static void DestroyTreeHelper( wxDataViewTreeNode
* node
)
3365 if( node
->GetNodeNumber() != 0 )
3367 int len
= node
->GetNodeNumber();
3368 wxDataViewTreeNodes
& nodes
= node
->GetNodes();
3369 for (int i
= 0; i
< len
; i
++)
3370 DestroyTreeHelper(nodes
[i
]);
3375 void wxDataViewMainWindow::DestroyTree()
3377 if (!IsVirtualList())
3379 ::DestroyTreeHelper(m_root
);
3385 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
3387 if ( GetParent()->HandleAsNavigationKey(event
) )
3390 // no item -> nothing to do
3391 if (!HasCurrentRow())
3397 // don't use m_linesPerPage directly as it might not be computed yet
3398 const int pageSize
= GetCountPerPage();
3399 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
3401 switch ( event
.GetKeyCode() )
3405 wxWindow
*parent
= GetParent();
3406 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
,
3408 le
.SetItem( GetItemByRow(m_currentRow
) );
3409 le
.SetEventObject(parent
);
3410 le
.SetModel(GetOwner()->GetModel());
3412 parent
->GetEventHandler()->ProcessEvent(le
);
3417 if ( m_currentRow
> 0 )
3418 OnArrowChar( m_currentRow
- 1, event
);
3422 if ( m_currentRow
< GetRowCount() - 1 )
3423 OnArrowChar( m_currentRow
+ 1, event
);
3425 // Add the process for tree expanding/collapsing
3428 if (IsVirtualList())
3431 wxDataViewTreeNode
* node
= GetTreeNodeByRow(m_currentRow
);
3435 if (node
->HasChildren() && node
->IsOpen())
3437 Collapse(m_currentRow
);
3439 else // if the node is already closed we move the selection to its parent
3441 wxDataViewTreeNode
*parent_node
= node
->GetParent();
3443 if(!node
->HasChildren())
3448 int parent
= GetRowByItem( parent_node
->GetItem() );
3451 unsigned int row
= m_currentRow
;
3452 SelectRow( row
, false);
3453 SelectRow( parent
, true );
3454 ChangeCurrentRow( parent
);
3455 GetOwner()->EnsureVisible( parent
, -1 );
3456 SendSelectionChangedEvent( parent_node
->GetItem() );
3464 if (!IsExpanded( m_currentRow
))
3465 Expand( m_currentRow
);
3468 unsigned int row
= m_currentRow
;
3469 SelectRow( row
, false );
3470 SelectRow( row
+ 1, true );
3471 ChangeCurrentRow( row
+ 1 );
3472 GetOwner()->EnsureVisible( row
+ 1, -1 );
3473 SendSelectionChangedEvent( GetItemByRow(row
+1) );
3480 OnArrowChar( GetRowCount() - 1, event
);
3485 OnArrowChar( 0, event
);
3490 int steps
= pageSize
- 1;
3491 int index
= m_currentRow
- steps
;
3495 OnArrowChar( index
, event
);
3501 int steps
= pageSize
- 1;
3502 unsigned int index
= m_currentRow
+ steps
;
3503 unsigned int count
= GetRowCount();
3504 if ( index
>= count
)
3507 OnArrowChar( index
, event
);
3513 if(m_selection
.size() == 1)
3515 // TODO: we need to revise that when we have a concept for a 'current column'
3516 GetOwner()->StartEditor(GetItemByRow(m_selection
[0]), 0);
3526 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
3528 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3530 // let the base handle mouse wheel events.
3535 int x
= event
.GetX();
3536 int y
= event
.GetY();
3537 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
3538 wxDataViewColumn
*col
= NULL
;
3541 unsigned int cols
= GetOwner()->GetColumnCount();
3543 for (i
= 0; i
< cols
; i
++)
3545 wxDataViewColumn
*c
= GetOwner()->GetColumnAt( i
);
3547 continue; // skip it!
3549 if (x
< xpos
+ c
->GetWidth())
3554 xpos
+= c
->GetWidth();
3559 wxDataViewRenderer
*cell
= col
->GetRenderer();
3560 unsigned int current
= GetLineAt( y
);
3561 if ((current
>= GetRowCount()) || (x
> GetEndOfLastCol()))
3563 // Unselect all if below the last row ?
3567 // Test whether the mouse is hovered on the tree item button
3568 bool hoverOverExpander
= false;
3569 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
3571 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3572 if( node
!=NULL
&& node
->HasChildren() )
3574 int indent
= node
->GetIndentLevel();
3575 indent
= GetOwner()->GetIndent()*indent
;
3577 // we make the rectangle we are looking in a bit bigger than the actual
3578 // visual expander so the user can hit that little thing reliably
3579 wxRect
rect( xpos
+ indent
,
3580 GetLineStart( current
) + (GetLineHeight(current
) - m_lineHeight
)/2,
3581 m_lineHeight
, m_lineHeight
);
3582 if( rect
.Contains(x
, y
) )
3584 // So the mouse is over the expander
3585 hoverOverExpander
= true;
3586 if (m_underMouse
&& m_underMouse
!= node
)
3588 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3589 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3591 if (m_underMouse
!= node
)
3593 // wxLogMessage("Do the row: %d", current);
3594 RefreshRow(current
);
3596 m_underMouse
= node
;
3599 if (node
!=NULL
&& !node
->HasChildren())
3602 if (!hoverOverExpander
)
3604 if (m_underMouse
!= NULL
)
3606 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3607 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3608 m_underMouse
= NULL
;
3612 wxDataViewModel
*model
= GetOwner()->GetModel();
3614 #if wxUSE_DRAG_AND_DROP
3615 if (event
.Dragging())
3617 if (m_dragCount
== 0)
3619 // we have to report the raw, physical coords as we want to be
3620 // able to call HitTest(event.m_pointDrag) from the user code to
3621 // get the item being dragged
3622 m_dragStart
= event
.GetPosition();
3627 if (m_dragCount
!= 3)
3630 if (event
.LeftIsDown())
3632 m_owner
->CalcUnscrolledPosition( m_dragStart
.x
, m_dragStart
.y
,
3633 &m_dragStart
.x
, &m_dragStart
.y
);
3634 unsigned int drag_item_row
= GetLineAt( m_dragStart
.y
);
3635 wxDataViewItem item
= GetItemByRow( drag_item_row
);
3637 // Notify cell about drag
3638 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
3639 event
.SetEventObject( m_owner
);
3640 event
.SetItem( item
);
3641 event
.SetModel( model
);
3642 if (!m_owner
->HandleWindowEvent( event
))
3645 if (!event
.IsAllowed())
3648 wxDataObject
*obj
= event
.GetDataObject();
3652 wxDataViewDropSource
drag( this, drag_item_row
);
3653 drag
.SetData( *obj
);
3654 /* wxDragResult res = */ drag
.DoDragDrop();
3663 #endif // wxUSE_DRAG_AND_DROP
3665 bool simulateClick
= false;
3667 if (event
.ButtonDClick())
3669 m_renameTimer
->Stop();
3670 m_lastOnSame
= false;
3673 wxDataViewItem item
= GetItemByRow(current
);
3674 bool ignore_other_columns
=
3675 ((GetOwner()->GetExpanderColumn() != col
) &&
3676 (model
->IsContainer(item
)) &&
3677 (!model
->HasContainerColumns(item
)));
3679 if (event
.LeftDClick())
3681 if(hoverOverExpander
)
3683 // a double click on the expander will be converted into a "simulated" normal click
3684 simulateClick
= true;
3686 else if ( current
== m_lineLastClicked
)
3688 if ((!ignore_other_columns
) && (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
3691 model
->GetValue( value
, item
, col
->GetModelColumn() );
3692 cell
->SetValue( value
);
3693 wxRect
cell_rect( xpos
, GetLineStart( current
),
3694 col
->GetWidth(), GetLineHeight( current
) );
3695 cell
->Activate( cell_rect
, model
, item
, col
->GetModelColumn() );
3699 wxWindow
*parent
= GetParent();
3700 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3702 le
.SetEventObject(parent
);
3703 le
.SetModel(GetOwner()->GetModel());
3705 parent
->GetEventHandler()->ProcessEvent(le
);
3711 // The first click was on another item, so don't interpret this as
3712 // a double click, but as a simple click instead
3713 simulateClick
= true;
3717 if (event
.LeftUp() && !hoverOverExpander
)
3719 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
3721 // select single line
3722 SelectAllRows( false );
3723 SelectRow( m_lineSelectSingleOnUp
, true );
3724 SendSelectionChangedEvent( GetItemByRow(m_lineSelectSingleOnUp
) );
3727 // If the user click the expander, we do not do editing even if the column
3728 // with expander are editable
3729 if (m_lastOnSame
&& !ignore_other_columns
)
3731 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
3732 (cell
->GetMode() & wxDATAVIEW_CELL_EDITABLE
) )
3734 m_renameTimer
->Start( 100, true );
3738 m_lastOnSame
= false;
3739 m_lineSelectSingleOnUp
= (unsigned int)-1;
3741 else if(!event
.LeftUp())
3743 // This is necessary, because after a DnD operation in
3744 // from and to ourself, the up event is swallowed by the
3745 // DnD code. So on next non-up event (which means here and
3746 // now) m_lineSelectSingleOnUp should be reset.
3747 m_lineSelectSingleOnUp
= (unsigned int)-1;
3750 if (event
.RightDown())
3752 m_lineBeforeLastClicked
= m_lineLastClicked
;
3753 m_lineLastClicked
= current
;
3755 // If the item is already selected, do not update the selection.
3756 // Multi-selections should not be cleared if a selected item is clicked.
3757 if (!IsRowSelected(current
))
3759 SelectAllRows(false);
3760 ChangeCurrentRow(current
);
3761 SelectRow(m_currentRow
,true);
3762 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3765 else if (event
.RightUp())
3768 model
->GetValue( value
, item
, col
->GetModelColumn() );
3769 wxWindow
*parent
= GetParent();
3770 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
3772 le
.SetEventObject(parent
);
3773 le
.SetModel(GetOwner()->GetModel());
3775 parent
->GetEventHandler()->ProcessEvent(le
);
3777 else if (event
.MiddleDown())
3781 if((event
.LeftDown() || simulateClick
) && hoverOverExpander
)
3783 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3785 // hoverOverExpander being true tells us that our node must be
3786 // valid and have children.
3787 // So we don't need any extra checks.
3788 if( node
->IsOpen() )
3793 else if ((event
.LeftDown() || simulateClick
) && !hoverOverExpander
)
3797 m_lineBeforeLastClicked
= m_lineLastClicked
;
3798 m_lineLastClicked
= current
;
3800 unsigned int oldCurrentRow
= m_currentRow
;
3801 bool oldWasSelected
= IsRowSelected(m_currentRow
);
3803 bool cmdModifierDown
= event
.CmdDown();
3804 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3806 if ( IsSingleSel() || !IsRowSelected(current
) )
3808 SelectAllRows( false );
3809 ChangeCurrentRow(current
);
3810 SelectRow(m_currentRow
,true);
3811 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3813 else // multi sel & current is highlighted & no mod keys
3815 m_lineSelectSingleOnUp
= current
;
3816 ChangeCurrentRow(current
); // change focus
3819 else // multi sel & either ctrl or shift is down
3821 if (cmdModifierDown
)
3823 ChangeCurrentRow(current
);
3824 ReverseRowSelection(m_currentRow
);
3825 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3827 else if (event
.ShiftDown())
3829 ChangeCurrentRow(current
);
3831 unsigned int lineFrom
= oldCurrentRow
,
3834 if ( lineTo
< lineFrom
)
3837 lineFrom
= m_currentRow
;
3840 SelectRows(lineFrom
, lineTo
, true);
3841 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3843 else // !ctrl, !shift
3845 // test in the enclosing if should make it impossible
3846 wxFAIL_MSG( wxT("how did we get here?") );
3850 if (m_currentRow
!= oldCurrentRow
)
3851 RefreshRow( oldCurrentRow
);
3853 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
3855 // Update selection here...
3858 m_lastOnSame
= !simulateClick
&& ((col
== oldCurrentCol
) &&
3859 (current
== oldCurrentRow
)) && oldWasSelected
;
3861 // Call LeftClick after everything else as under GTK+
3862 if (cell
->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE
)
3864 // notify cell about right click
3866 model
->GetValue( value
, item
, col
->GetModelColumn() );
3867 cell
->SetValue( value
);
3868 wxRect
cell_rect( xpos
, GetLineStart( current
),
3869 col
->GetWidth(), GetLineHeight( current
) );
3870 /* ignore ret */ cell
->LeftClick( event
.GetPosition(), cell_rect
,
3871 model
, item
, col
->GetModelColumn());
3876 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
3880 if (HasCurrentRow())
3886 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
3890 if (HasCurrentRow())
3896 wxDataViewItem
wxDataViewMainWindow::GetSelection() const
3898 if( m_selection
.GetCount() != 1 )
3899 return wxDataViewItem();
3901 return GetItemByRow( m_selection
.Item(0));
3904 //-----------------------------------------------------------------------------
3906 //-----------------------------------------------------------------------------
3908 WX_DEFINE_LIST(wxDataViewColumnList
)
3910 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3911 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
3912 EVT_SIZE(wxDataViewCtrl::OnSize
)
3915 wxDataViewCtrl::~wxDataViewCtrl()
3918 GetModel()->RemoveNotifier( m_notifier
);
3923 void wxDataViewCtrl::Init()
3925 m_cols
.DeleteContents(true);
3928 // No sorting column at start
3929 m_sortingColumnIdx
= wxNOT_FOUND
;
3931 m_headerArea
= NULL
;
3934 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3935 const wxPoint
& pos
, const wxSize
& size
,
3936 long style
, const wxValidator
& validator
)
3938 // if ( (style & wxBORDER_MASK) == 0)
3939 // style |= wxBORDER_SUNKEN;
3943 if (!wxControl::Create( parent
, id
, pos
, size
,
3944 style
| wxScrolledWindowStyle
, validator
))
3947 SetInitialSize(size
);
3950 MacSetClipChildren( true );
3953 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
3955 if (HasFlag(wxDV_NO_HEADER
))
3956 m_headerArea
= NULL
;
3958 m_headerArea
= new wxDataViewHeaderWindow(this);
3960 SetTargetWindow( m_clientArea
);
3962 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
3964 sizer
->Add( m_headerArea
, 0, wxGROW
);
3965 sizer
->Add( m_clientArea
, 1, wxGROW
);
3971 wxBorder
wxDataViewCtrl::GetDefaultBorder() const
3973 return wxBORDER_THEME
;
3977 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
3981 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
3984 // we need to process arrows ourselves for scrolling
3985 if ( nMsg
== WM_GETDLGCODE
)
3987 rc
|= DLGC_WANTARROWS
;
3995 wxSize
wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
3997 wxSize newsize
= size
;
3998 if (!HasFlag(wxDV_NO_HEADER
) && (m_headerArea
))
3999 newsize
.y
-= m_headerArea
->GetSize().y
;
4004 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
4006 // We need to override OnSize so that our scrolled
4007 // window a) does call Layout() to use sizers for
4008 // positioning the controls but b) does not query
4009 // the sizer for their size and use that for setting
4010 // the scrollable area as set that ourselves by
4011 // calling SetScrollbar() further down.
4018 void wxDataViewCtrl::SetFocus()
4021 m_clientArea
->SetFocus();
4024 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4026 if (!wxDataViewCtrlBase::AssociateModel( model
))
4029 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
4031 model
->AddNotifier( m_notifier
);
4033 m_clientArea
->DestroyTree();
4035 m_clientArea
->BuildTree(model
);
4037 m_clientArea
->UpdateDisplay();
4042 #if wxUSE_DRAG_AND_DROP
4044 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4046 return m_clientArea
->EnableDragSource( format
);
4049 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4051 return m_clientArea
->EnableDropTarget( format
);
4054 #endif // wxUSE_DRAG_AND_DROP
4056 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4058 if (!wxDataViewCtrlBase::AppendColumn(col
))
4061 m_cols
.Append( col
);
4062 OnColumnsCountChanged();
4066 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4068 if (!wxDataViewCtrlBase::PrependColumn(col
))
4071 m_cols
.Insert( col
);
4072 OnColumnsCountChanged();
4076 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4078 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4081 m_cols
.Insert( pos
, col
);
4082 OnColumnsCountChanged();
4086 void wxDataViewCtrl::OnColumnChange(unsigned int idx
)
4089 m_headerArea
->UpdateColumn(idx
);
4091 m_clientArea
->UpdateDisplay();
4094 void wxDataViewCtrl::OnColumnsCountChanged()
4097 m_headerArea
->SetColumnCount(GetColumnCount());
4099 m_clientArea
->UpdateDisplay();
4102 void wxDataViewCtrl::DoSetExpanderColumn()
4104 m_clientArea
->UpdateDisplay();
4107 void wxDataViewCtrl::DoSetIndent()
4109 m_clientArea
->UpdateDisplay();
4112 unsigned int wxDataViewCtrl::GetColumnCount() const
4114 return m_cols
.GetCount();
4117 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int idx
) const
4122 wxDataViewColumn
*wxDataViewCtrl::GetColumnAt(unsigned int pos
) const
4124 // columns can't be reordered if there is no header window which allows
4126 const unsigned idx
= m_headerArea
? m_headerArea
->GetColumnsOrder()[pos
]
4129 return GetColumn(idx
);
4132 int wxDataViewCtrl::GetColumnIndex(const wxDataViewColumn
*column
) const
4134 const unsigned count
= m_cols
.size();
4135 for ( unsigned n
= 0; n
< count
; n
++ )
4137 if ( m_cols
[n
] == column
)
4144 void wxDataViewCtrl::ColumnMoved(wxDataViewColumn
* WXUNUSED(col
),
4145 unsigned int WXUNUSED(new_pos
))
4147 // do _not_ reorder m_cols elements here, they should always be in the
4148 // order in which columns were added, we only display the columns in
4150 m_clientArea
->UpdateDisplay();
4153 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4155 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
4160 OnColumnsCountChanged();
4165 bool wxDataViewCtrl::ClearColumns()
4168 OnColumnsCountChanged();
4172 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4176 unsigned int len
= GetColumnCount();
4177 for ( unsigned int i
= 0; i
< len
; i
++ )
4179 wxDataViewColumn
* col
= GetColumnAt(i
);
4180 if (col
->IsHidden())
4182 ret
+= col
->GetWidth();
4185 CalcScrolledPosition( ret
, dummy
, &ret
, &dummy
);
4192 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4194 return m_sortingColumnIdx
== wxNOT_FOUND
? NULL
4195 : GetColumn(m_sortingColumnIdx
);
4198 // Selection code with wxDataViewItem as parameters
4199 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4201 return m_clientArea
->GetSelection();
4204 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4207 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4208 int len
= selection
.GetCount();
4209 for( int i
= 0; i
< len
; i
++)
4211 unsigned int row
= selection
[i
];
4212 sel
.Add( m_clientArea
->GetItemByRow( row
) );
4217 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4219 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4221 wxDataViewItem last_parent
;
4223 int len
= sel
.GetCount();
4224 for( int i
= 0; i
< len
; i
++ )
4226 wxDataViewItem item
= sel
[i
];
4227 wxDataViewItem parent
= GetModel()->GetParent( item
);
4230 if (parent
!= last_parent
)
4231 ExpandAncestors(item
);
4234 last_parent
= parent
;
4235 int row
= m_clientArea
->GetRowByItem( item
);
4237 selection
.Add( static_cast<unsigned int>(row
) );
4240 m_clientArea
->SetSelections( selection
);
4243 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4245 ExpandAncestors( item
);
4247 int row
= m_clientArea
->GetRowByItem( item
);
4250 // Unselect all rows before select another in the single select mode
4251 if (m_clientArea
->IsSingleSel())
4252 m_clientArea
->SelectAllRows(false);
4253 m_clientArea
->SelectRow(row
, true);
4257 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4259 int row
= m_clientArea
->GetRowByItem( item
);
4261 m_clientArea
->SelectRow(row
, false);
4264 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4266 int row
= m_clientArea
->GetRowByItem( item
);
4269 return m_clientArea
->IsRowSelected(row
);
4274 // Selection code with row number as parameter
4275 int wxDataViewCtrl::GetSelections( wxArrayInt
& sel
) const
4278 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4279 int len
= selection
.GetCount();
4280 for( int i
= 0; i
< len
; i
++)
4282 unsigned int row
= selection
[i
];
4288 void wxDataViewCtrl::SetSelections( const wxArrayInt
& sel
)
4290 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4291 int len
= sel
.GetCount();
4292 for( int i
= 0; i
< len
; i
++ )
4296 selection
.Add( static_cast<unsigned int>(row
) );
4298 m_clientArea
->SetSelections( selection
);
4301 void wxDataViewCtrl::Select( int row
)
4305 if (m_clientArea
->IsSingleSel())
4306 m_clientArea
->SelectAllRows(false);
4307 m_clientArea
->SelectRow( row
, true );
4311 void wxDataViewCtrl::Unselect( int row
)
4314 m_clientArea
->SelectRow(row
, false);
4317 bool wxDataViewCtrl::IsSelected( int row
) const
4320 return m_clientArea
->IsRowSelected(row
);
4324 void wxDataViewCtrl::SelectRange( int from
, int to
)
4327 for( int i
= from
; i
< to
; i
++ )
4329 m_clientArea
->Select(sel
);
4332 void wxDataViewCtrl::UnselectRange( int from
, int to
)
4334 wxDataViewSelection sel
= m_clientArea
->GetSelections();
4335 for( int i
= from
; i
< to
; i
++ )
4336 if( sel
.Index( i
) != wxNOT_FOUND
)
4338 m_clientArea
->SetSelections(sel
);
4341 void wxDataViewCtrl::SelectAll()
4343 m_clientArea
->SelectAllRows(true);
4346 void wxDataViewCtrl::UnselectAll()
4348 m_clientArea
->SelectAllRows(false);
4351 void wxDataViewCtrl::EnsureVisible( int row
, int column
)
4355 if( row
> (int) m_clientArea
->GetRowCount() )
4356 row
= m_clientArea
->GetRowCount();
4358 int first
= m_clientArea
->GetFirstVisibleRow();
4359 int last
= m_clientArea
->GetLastVisibleRow();
4361 m_clientArea
->ScrollTo( row
, column
);
4362 else if( row
> last
)
4363 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
4365 m_clientArea
->ScrollTo( first
, column
);
4368 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
4370 ExpandAncestors( item
);
4372 m_clientArea
->RecalculateDisplay();
4374 int row
= m_clientArea
->GetRowByItem(item
);
4377 if( column
== NULL
)
4378 EnsureVisible(row
, -1);
4380 EnsureVisible( row
, GetColumnIndex(column
) );
4385 void wxDataViewCtrl::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
4386 wxDataViewColumn
* &column
) const
4388 m_clientArea
->HitTest(point
, item
, column
);
4391 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
& item
,
4392 const wxDataViewColumn
* column
) const
4394 return m_clientArea
->GetItemRect(item
, column
);
4397 wxDataViewItem
wxDataViewCtrl::GetItemByRow( unsigned int row
) const
4399 return m_clientArea
->GetItemByRow( row
);
4402 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem
& item
) const
4404 return m_clientArea
->GetRowByItem( item
);
4407 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4409 int row
= m_clientArea
->GetRowByItem( item
);
4411 m_clientArea
->Expand(row
);
4414 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4416 int row
= m_clientArea
->GetRowByItem( item
);
4418 m_clientArea
->Collapse(row
);
4421 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
4423 int row
= m_clientArea
->GetRowByItem( item
);
4425 return m_clientArea
->IsExpanded(row
);
4429 void wxDataViewCtrl::StartEditor( const wxDataViewItem
& item
, unsigned int column
)
4431 wxDataViewColumn
* col
= GetColumn( column
);
4435 wxRect itemRect
= GetItemRect(item
, col
);
4436 wxDataViewRenderer
* renderer
= col
->GetRenderer();
4437 renderer
->StartEditing(item
, itemRect
);
4440 #endif // !wxUSE_GENERICDATAVIEWCTRL
4442 #endif // wxUSE_DATAVIEWCTRL