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/popupwin.h"
42 #include "wx/renderer.h"
43 #include "wx/dcbuffer.h"
46 #include "wx/listimpl.cpp"
47 #include "wx/imaglist.h"
48 #include "wx/headerctrl.h"
50 #include "wx/stopwatch.h"
51 #include "wx/weakref.h"
53 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
57 class wxDataViewColumn
;
58 class wxDataViewHeaderWindow
;
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
65 static const int SCROLL_UNIT_X
= 15;
67 // the cell padding on the left/right
68 static const int PADDING_RIGHTLEFT
= 3;
70 // the expander space margin
71 static const int EXPANDER_MARGIN
= 4;
74 static const int EXPANDER_OFFSET
= 4;
76 static const int EXPANDER_OFFSET
= 1;
79 // Below is the compare stuff.
80 // For the generic implementation, both the leaf nodes and the nodes are sorted for
81 // fast search when needed
82 static wxDataViewModel
* g_model
;
84 // The column is either the index of the column to be used for sorting or one
85 // of the special values in this enum:
88 // Sort when we're thawed later.
89 SortColumn_OnThaw
= -3,
94 // Sort using the model default sort order.
95 SortColumn_Default
= -1
98 static int g_column
= SortColumn_None
;
99 static bool g_asending
= true;
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
108 // Return the expander column or, if it is not set, the first column and also
109 // set it as the expander one for the future.
110 wxDataViewColumn
* GetExpanderColumnOrFirstOne(wxDataViewCtrl
* dataview
)
112 wxDataViewColumn
* expander
= dataview
->GetExpanderColumn();
115 // TODO-RTL: last column for RTL support
116 expander
= dataview
->GetColumnAt( 0 );
117 dataview
->SetExpanderColumn(expander
);
123 } // anonymous namespace
125 //-----------------------------------------------------------------------------
127 //-----------------------------------------------------------------------------
129 void wxDataViewColumn
::Init(int width
, wxAlignment align
, int flags
)
136 m_sortAscending
= true;
139 int wxDataViewColumn
::GetWidth() const
143 case wxCOL_WIDTH_DEFAULT
:
144 return wxDVC_DEFAULT_WIDTH
;
146 case wxCOL_WIDTH_AUTOSIZE
:
147 wxCHECK_MSG( m_owner
, wxDVC_DEFAULT_WIDTH
, "no owner control" );
148 return m_owner
->GetBestColumnWidth(m_owner
->GetColumnIndex(this));
155 void wxDataViewColumn
::UpdateDisplay()
159 int idx
= m_owner
->GetColumnIndex( this );
160 m_owner
->OnColumnChange( idx
);
164 void wxDataViewColumn
::UnsetAsSortKey()
169 m_owner
->SetSortingColumnIndex(wxNOT_FOUND
);
174 void wxDataViewColumn
::SetSortOrder(bool ascending
)
179 // First unset the old sort column if any.
180 int oldSortKey
= m_owner
->GetSortingColumnIndex();
181 if ( oldSortKey
!= wxNOT_FOUND
)
183 m_owner
->GetColumn(oldSortKey
)->UnsetAsSortKey();
186 // Now set this one as the new sort column.
187 const int idx
= m_owner
->GetColumnIndex(this);
188 m_owner
->SetSortingColumnIndex(idx
);
191 m_sortAscending
= ascending
;
193 // Call this directly instead of using UpdateDisplay() as we already have
194 // the column index, no need to look it up again.
195 m_owner
->OnColumnChange(idx
);
198 //-----------------------------------------------------------------------------
199 // wxDataViewHeaderWindow
200 //-----------------------------------------------------------------------------
202 class wxDataViewHeaderWindow
: public wxHeaderCtrl
205 wxDataViewHeaderWindow(wxDataViewCtrl
*parent
)
206 : wxHeaderCtrl(parent
)
210 wxDataViewCtrl
*GetOwner() const
211 { return static_cast<wxDataViewCtrl
*>(GetParent()); }
214 // implement/override wxHeaderCtrl functions by forwarding them to the main
216 virtual const wxHeaderColumn
& GetColumn(unsigned int idx
) const
218 return *(GetOwner()->GetColumn(idx
));
221 virtual bool UpdateColumnWidthToFit(unsigned int idx
, int widthTitle
)
223 wxDataViewCtrl
* const owner
= GetOwner();
225 int widthContents
= owner
->GetBestColumnWidth(idx
);
226 owner
->GetColumn(idx
)->SetWidth(wxMax(widthTitle
, widthContents
));
227 owner
->OnColumnChange(idx
);
233 bool SendEvent(wxEventType type
, unsigned int n
)
235 wxDataViewCtrl
* const owner
= GetOwner();
236 wxDataViewEvent
event(type
, owner
->GetId());
238 event
.SetEventObject(owner
);
240 event
.SetDataViewColumn(owner
->GetColumn(n
));
241 event
.SetModel(owner
->GetModel());
243 // for events created by wxDataViewHeaderWindow the
244 // row / value fields are not valid
245 return owner
->ProcessWindowEvent(event
);
248 void OnClick(wxHeaderCtrlEvent
& event
)
250 const unsigned idx
= event
.GetColumn();
252 if ( SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, idx
) )
255 // default handling for the column click is to sort by this column or
256 // toggle its sort order
257 wxDataViewCtrl
* const owner
= GetOwner();
258 wxDataViewColumn
* const col
= owner
->GetColumn(idx
);
259 if ( !col
->IsSortable() )
261 // no default handling for non-sortable columns
266 if ( col
->IsSortKey() )
268 // already using this column for sorting, just change the order
269 col
->ToggleSortOrder();
271 else // not using this column for sorting yet
273 col
->SetSortOrder(true);
276 wxDataViewModel
* const model
= owner
->GetModel();
280 owner
->OnColumnChange(idx
);
282 SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, idx
);
285 void OnRClick(wxHeaderCtrlEvent
& event
)
287 if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
292 void OnResize(wxHeaderCtrlEvent
& event
)
294 wxDataViewCtrl
* const owner
= GetOwner();
296 const unsigned col
= event
.GetColumn();
297 owner
->GetColumn(col
)->SetWidth(event
.GetWidth());
298 GetOwner()->OnColumnChange(col
);
301 void OnEndReorder(wxHeaderCtrlEvent
& event
)
303 wxDataViewCtrl
* const owner
= GetOwner();
304 owner
->ColumnMoved(owner
->GetColumn(event
.GetColumn()),
305 event
.GetNewOrder());
308 DECLARE_EVENT_TABLE()
309 wxDECLARE_NO_COPY_CLASS(wxDataViewHeaderWindow
);
312 BEGIN_EVENT_TABLE(wxDataViewHeaderWindow
, wxHeaderCtrl
)
313 EVT_HEADER_CLICK(wxID_ANY
, wxDataViewHeaderWindow
::OnClick
)
314 EVT_HEADER_RIGHT_CLICK(wxID_ANY
, wxDataViewHeaderWindow
::OnRClick
)
316 EVT_HEADER_RESIZING(wxID_ANY
, wxDataViewHeaderWindow
::OnResize
)
317 EVT_HEADER_END_RESIZE(wxID_ANY
, wxDataViewHeaderWindow
::OnResize
)
319 EVT_HEADER_END_REORDER(wxID_ANY
, wxDataViewHeaderWindow
::OnEndReorder
)
322 //-----------------------------------------------------------------------------
323 // wxDataViewRenameTimer
324 //-----------------------------------------------------------------------------
326 class wxDataViewRenameTimer
: public wxTimer
329 wxDataViewMainWindow
*m_owner
;
332 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
336 //-----------------------------------------------------------------------------
337 // wxDataViewTreeNode
338 //-----------------------------------------------------------------------------
340 class wxDataViewTreeNode
;
341 WX_DEFINE_ARRAY( wxDataViewTreeNode
*, wxDataViewTreeNodes
);
343 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
,
344 wxDataViewTreeNode
** node2
);
346 class wxDataViewTreeNode
349 wxDataViewTreeNode(wxDataViewTreeNode
*parent
, const wxDataViewItem
& item
)
356 ~wxDataViewTreeNode()
360 wxDataViewTreeNodes
& nodes
= m_branchData
->children
;
361 for ( wxDataViewTreeNodes
::iterator i
= nodes
.begin();
372 static wxDataViewTreeNode
* CreateRootNode()
374 wxDataViewTreeNode
*n
= new wxDataViewTreeNode(NULL
, wxDataViewItem());
375 n
->m_branchData
= new BranchNodeData
;
376 n
->m_branchData
->open
= true;
380 wxDataViewTreeNode
* GetParent() const { return m_parent
; }
382 const wxDataViewTreeNodes
& GetChildNodes() const
384 wxASSERT( m_branchData
!= NULL
);
385 return m_branchData
->children
;
388 void InsertChild(wxDataViewTreeNode
*node
, unsigned index
)
391 m_branchData
= new BranchNodeData
;
393 m_branchData
->children
.Insert(node
, index
);
395 // TODO: insert into sorted array directly in O(log n) instead of resorting in O(n log n)
397 m_branchData
->children
.Sort( &wxGenericTreeModelNodeCmp
);
400 void RemoveChild(wxDataViewTreeNode
*node
)
402 wxCHECK_RET( m_branchData
!= NULL
, "leaf node doesn't have children" );
403 m_branchData
->children
.Remove(node
);
406 // returns position of child node for given item in children list or wxNOT_FOUND
407 int FindChildByItem(const wxDataViewItem
& item
) const
412 const wxDataViewTreeNodes
& nodes
= m_branchData
->children
;
413 const int len
= nodes
.size();
414 for ( int i
= 0; i
< len
; i
++ )
416 if ( nodes
[i
]->m_item
== item
)
422 const wxDataViewItem
& GetItem() const { return m_item
; }
423 void SetItem( const wxDataViewItem
& item
) { m_item
= item
; }
425 int GetIndentLevel() const
428 const wxDataViewTreeNode
* node
= this;
429 while( node
->GetParent()->GetParent() != NULL
)
431 node
= node
->GetParent();
439 return m_branchData
&& m_branchData
->open
;
444 // We do not allow the (invisible) root node to be collapsed because
445 // there is no way to expand it again.
449 wxCHECK_RET( m_branchData
!= NULL
, "can't open leaf node" );
453 const wxDataViewTreeNodes
& nodes
= m_branchData
->children
;
454 const int len
= nodes
.GetCount();
455 for ( int i
= 0;i
< len
; i
++)
456 sum
+= 1 + nodes
[i
]->GetSubTreeCount();
458 if (m_branchData
->open
)
460 ChangeSubTreeCount(-sum
);
461 m_branchData
->open
= !m_branchData
->open
;
465 m_branchData
->open
= !m_branchData
->open
;
466 ChangeSubTreeCount(+sum
);
470 // "HasChildren" property corresponds to model's IsContainer(). Note that it may be true
471 // even if GetChildNodes() is empty; see below.
472 bool HasChildren() const
474 return m_branchData
!= NULL
;
477 void SetHasChildren(bool has
)
479 // The invisible root item always has children, so ignore any attempts
486 wxDELETE(m_branchData
);
488 else if ( m_branchData
== NULL
)
490 m_branchData
= new BranchNodeData
;
494 int GetSubTreeCount() const
496 return m_branchData ? m_branchData
->subTreeCount
: 0;
499 void ChangeSubTreeCount( int num
)
501 wxASSERT( m_branchData
!= NULL
);
503 if( !m_branchData
->open
)
506 m_branchData
->subTreeCount
+= num
;
507 wxASSERT( m_branchData
->subTreeCount
>= 0 );
510 m_parent
->ChangeSubTreeCount(num
);
520 wxDataViewTreeNodes
& nodes
= m_branchData
->children
;
522 nodes
.Sort( &wxGenericTreeModelNodeCmp
);
523 int len
= nodes
.GetCount();
524 for (int i
= 0; i
< len
; i
++)
526 if ( nodes
[i
]->HasChildren() )
534 wxDataViewTreeNode
*m_parent
;
536 // Corresponding model item.
537 wxDataViewItem m_item
;
539 // Data specific to non-leaf (branch, inner) nodes. They are kept in a
540 // separate struct in order to conserve memory.
541 struct BranchNodeData
549 // Child nodes. Note that this may be empty even if m_hasChildren in
550 // case this branch of the tree wasn't expanded and realized yet.
551 wxDataViewTreeNodes children
;
553 // Is the branch node currently open (expanded)?
556 // Total count of expanded (i.e. visible with the help of some
557 // scrolling) items in the subtree, but excluding this node. I.e. it is
558 // 0 for leaves and is the number of rows the subtree occupies for
563 BranchNodeData
*m_branchData
;
567 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
,
568 wxDataViewTreeNode
** node2
)
570 return g_model
->Compare( (*node1
)->GetItem(), (*node2
)->GetItem(), g_column
, g_asending
);
574 //-----------------------------------------------------------------------------
575 // wxDataViewMainWindow
576 //-----------------------------------------------------------------------------
578 WX_DEFINE_SORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
);
580 class wxDataViewMainWindow
: public wxWindow
583 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
585 const wxPoint
&pos
= wxDefaultPosition
,
586 const wxSize
&size
= wxDefaultSize
,
587 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
588 virtual ~wxDataViewMainWindow();
590 bool IsList() const { return GetModel()->IsListModel(); }
591 bool IsVirtualList() const { return m_root
== NULL
; }
593 // notifications from wxDataViewModel
594 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
595 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
596 bool ItemChanged( const wxDataViewItem
&item
);
597 bool ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
);
601 if (!IsVirtualList())
609 // Override the base class method to resort if needed, i.e. if
610 // SortPrepare() was called -- and ignored -- while we were frozen.
611 virtual void DoThaw()
613 if ( g_column
== SortColumn_OnThaw
)
616 g_column
= SortColumn_None
;
624 g_model
= GetModel();
626 wxDataViewColumn
* col
= GetOwner()->GetSortingColumn();
629 if (g_model
->HasDefaultCompare())
631 // See below for the explanation of IsFrozen() test.
633 g_column
= SortColumn_OnThaw
;
635 g_column
= SortColumn_Default
;
638 g_column
= SortColumn_None
;
644 // Avoid sorting while the window is frozen, this allows to quickly add
645 // many items without resorting after each addition and only resort
646 // them all at once when the window is finally thawed, see above.
649 g_column
= SortColumn_OnThaw
;
653 g_column
= col
->GetModelColumn();
654 g_asending
= col
->IsSortOrderAscending();
657 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
658 wxDataViewCtrl
*GetOwner() { return m_owner
; }
659 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
661 wxDataViewModel
* GetModel() { return GetOwner()->GetModel(); }
662 const wxDataViewModel
* GetModel() const { return GetOwner()->GetModel(); }
664 #if wxUSE_DRAG_AND_DROP
665 wxBitmap
CreateItemBitmap( unsigned int row
, int &indent
);
666 #endif // wxUSE_DRAG_AND_DROP
667 void OnPaint( wxPaintEvent
&event
);
668 void OnCharHook( wxKeyEvent
&event
);
669 void OnChar( wxKeyEvent
&event
);
670 void OnVerticalNavigation(int delta
, const wxKeyEvent
& event
);
673 void OnMouse( wxMouseEvent
&event
);
674 void OnSetFocus( wxFocusEvent
&event
);
675 void OnKillFocus( wxFocusEvent
&event
);
677 void UpdateDisplay();
678 void RecalculateDisplay();
679 void OnInternalIdle();
681 void OnRenameTimer();
683 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
684 void ScrollTo( int rows
, int column
);
686 unsigned GetCurrentRow() const { return m_currentRow
; }
687 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
688 void ChangeCurrentRow( unsigned int row
);
689 bool TryAdvanceCurrentColumn(wxDataViewTreeNode
*node
, bool forward
);
691 wxDataViewColumn
*GetCurrentColumn() const { return m_currentCol
; }
692 void ClearCurrentColumn() { m_currentCol
= NULL
; }
694 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
695 bool IsEmpty() { return GetRowCount() == 0; }
697 int GetCountPerPage() const;
698 int GetEndOfLastCol() const;
699 unsigned int GetFirstVisibleRow() const;
701 // I change this method to un const because in the tree view,
702 // the displaying number of the tree are changing along with the
703 // expanding/collapsing of the tree nodes
704 unsigned int GetLastVisibleRow();
705 unsigned int GetRowCount() const;
707 const wxDataViewSelection
& GetSelections() const { return m_selection
; }
708 void SetSelections( const wxDataViewSelection
& sel
)
709 { m_selection
= sel
; UpdateDisplay(); }
710 void Select( const wxArrayInt
& aSelections
);
711 void SelectAllRows( bool on
);
712 void SelectRow( unsigned int row
, bool on
);
713 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
714 void ReverseRowSelection( unsigned int row
);
715 bool IsRowSelected( unsigned int row
);
716 void SendSelectionChangedEvent( const wxDataViewItem
& item
);
718 void RefreshRow( unsigned int row
);
719 void RefreshRows( unsigned int from
, unsigned int to
);
720 void RefreshRowsAfter( unsigned int firstRow
);
722 // returns the colour to be used for drawing the rules
723 wxColour
GetRuleColour() const
725 return wxSystemSettings
::GetColour(wxSYS_COLOUR_3DLIGHT
);
728 wxRect
GetLineRect( unsigned int row
) const;
730 int GetLineStart( unsigned int row
) const; // row * m_lineHeight in fixed mode
731 int GetLineHeight( unsigned int row
) const; // m_lineHeight in fixed mode
732 int GetLineAt( unsigned int y
) const; // y / m_lineHeight in fixed mode
734 void SetRowHeight( int lineHeight
) { m_lineHeight
= lineHeight
; }
735 int GetRowHeight() const { return m_lineHeight
; }
736 int GetDefaultRowHeight() const;
738 // Some useful functions for row and item mapping
739 wxDataViewItem
GetItemByRow( unsigned int row
) const;
740 int GetRowByItem( const wxDataViewItem
& item
) const;
742 wxDataViewTreeNode
* GetTreeNodeByRow( unsigned int row
) const;
743 // We did not need this temporarily
744 // wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
746 // Methods for building the mapping tree
747 void BuildTree( wxDataViewModel
* model
);
749 void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
);
750 wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
);
752 void Expand( unsigned int row
);
753 void Collapse( unsigned int row
);
754 bool IsExpanded( unsigned int row
) const;
755 bool HasChildren( unsigned int row
) const;
757 #if wxUSE_DRAG_AND_DROP
758 bool EnableDragSource( const wxDataFormat
&format
);
759 bool EnableDropTarget( const wxDataFormat
&format
);
761 void RemoveDropHint();
762 wxDragResult
OnDragOver( wxDataFormat format
, wxCoord x
, wxCoord y
, wxDragResult def
);
763 bool OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
);
764 wxDragResult
OnData( wxDataFormat format
, wxCoord x
, wxCoord y
, wxDragResult def
);
766 #endif // wxUSE_DRAG_AND_DROP
768 void OnColumnsCountChanged();
770 // Called by wxDataViewCtrl and our own OnRenameTimer() to start edit the
771 // specified item in the given column.
772 void StartEditing(const wxDataViewItem
& item
, const wxDataViewColumn
* col
);
775 int RecalculateCount() const;
777 // Return false only if the event was vetoed by its handler.
778 bool SendExpanderEvent(wxEventType type
, const wxDataViewItem
& item
);
780 wxDataViewTreeNode
* FindNode( const wxDataViewItem
& item
);
782 wxDataViewColumn
*FindColumnForEditing(const wxDataViewItem
& item
, wxDataViewCellMode mode
);
784 bool IsCellEditableInMode(const wxDataViewItem
& item
, const wxDataViewColumn
*col
, wxDataViewCellMode mode
) const;
786 void DrawCellBackground( wxDataViewRenderer
* cell
, wxDC
& dc
, const wxRect
& rect
);
789 wxDataViewCtrl
*m_owner
;
793 wxDataViewColumn
*m_currentCol
;
794 unsigned int m_currentRow
;
795 wxDataViewSelection m_selection
;
797 wxDataViewRenameTimer
*m_renameTimer
;
802 bool m_currentColSetByKeyboard
;
804 #if wxUSE_DRAG_AND_DROP
809 wxDataFormat m_dragFormat
;
812 wxDataFormat m_dropFormat
;
814 unsigned int m_dropHintLine
;
815 #endif // wxUSE_DRAG_AND_DROP
817 // for double click logic
818 unsigned int m_lineLastClicked
,
819 m_lineBeforeLastClicked
,
820 m_lineSelectSingleOnUp
;
822 // the pen used to draw horiz/vertical rules
825 // the pen used to draw the expander and the lines
828 // This is the tree structure of the model
829 wxDataViewTreeNode
* m_root
;
832 // This is the tree node under the cursor
833 wxDataViewTreeNode
* m_underMouse
;
835 // The control used for editing or NULL.
836 wxWeakRef
<wxWindow
> m_editorCtrl
;
838 // Id m_editorCtrl is non-NULL, pointer to the associated renderer.
839 wxDataViewRenderer
* m_editorRenderer
;
842 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
843 DECLARE_EVENT_TABLE()
846 // ---------------------------------------------------------
847 // wxGenericDataViewModelNotifier
848 // ---------------------------------------------------------
850 class wxGenericDataViewModelNotifier
: public wxDataViewModelNotifier
853 wxGenericDataViewModelNotifier( wxDataViewMainWindow
*mainWindow
)
854 { m_mainWindow
= mainWindow
; }
856 virtual bool ItemAdded( const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
857 { return m_mainWindow
->ItemAdded( parent
, item
); }
858 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
859 { return m_mainWindow
->ItemDeleted( parent
, item
); }
860 virtual bool ItemChanged( const wxDataViewItem
& item
)
861 { return m_mainWindow
->ItemChanged(item
); }
862 virtual bool ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
863 { return m_mainWindow
->ValueChanged( item
, col
); }
864 virtual bool Cleared()
865 { return m_mainWindow
->Cleared(); }
866 virtual void Resort()
867 { m_mainWindow
->Resort(); }
869 wxDataViewMainWindow
*m_mainWindow
;
872 // ---------------------------------------------------------
873 // wxDataViewRenderer
874 // ---------------------------------------------------------
876 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
878 wxDataViewRenderer
::wxDataViewRenderer( const wxString
&varianttype
,
879 wxDataViewCellMode mode
,
881 wxDataViewCustomRendererBase( varianttype
, mode
, align
)
885 m_ellipsizeMode
= wxELLIPSIZE_MIDDLE
;
889 wxDataViewRenderer
::~wxDataViewRenderer()
894 wxDC
*wxDataViewRenderer
::GetDC()
898 if (GetOwner() == NULL
)
900 if (GetOwner()->GetOwner() == NULL
)
902 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
908 void wxDataViewRenderer
::SetAlignment( int align
)
913 int wxDataViewRenderer
::GetAlignment() const
918 // ---------------------------------------------------------
919 // wxDataViewCustomRenderer
920 // ---------------------------------------------------------
922 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
924 wxDataViewCustomRenderer
::wxDataViewCustomRenderer( const wxString
&varianttype
,
925 wxDataViewCellMode mode
, int align
) :
926 wxDataViewRenderer( varianttype
, mode
, align
)
930 // ---------------------------------------------------------
931 // wxDataViewTextRenderer
932 // ---------------------------------------------------------
934 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
936 wxDataViewTextRenderer
::wxDataViewTextRenderer( const wxString
&varianttype
,
937 wxDataViewCellMode mode
, int align
) :
938 wxDataViewRenderer( varianttype
, mode
, align
)
942 bool wxDataViewTextRenderer
::SetValue( const wxVariant
&value
)
944 m_text
= value
.GetString();
949 bool wxDataViewTextRenderer
::GetValue( wxVariant
& WXUNUSED(value
) ) const
954 bool wxDataViewTextRenderer
::HasEditorCtrl() const
959 wxWindow
* wxDataViewTextRenderer
::CreateEditorCtrl( wxWindow
*parent
,
960 wxRect labelRect
, const wxVariant
&value
)
962 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, value
,
963 wxPoint(labelRect
.x
,labelRect
.y
),
964 wxSize(labelRect
.width
,labelRect
.height
),
965 wxTE_PROCESS_ENTER
);
967 // select the text in the control an place the cursor at the end
968 ctrl
->SetInsertionPointEnd();
974 bool wxDataViewTextRenderer
::GetValueFromEditorCtrl( wxWindow
*editor
, wxVariant
&value
)
976 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
977 value
= text
->GetValue();
981 bool wxDataViewTextRenderer
::Render(wxRect rect
, wxDC
*dc
, int state
)
983 RenderText(m_text
, 0, rect
, dc
, state
);
987 wxSize wxDataViewTextRenderer
::GetSize() const
990 return GetTextExtent(m_text
);
992 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
995 // ---------------------------------------------------------
996 // wxDataViewBitmapRenderer
997 // ---------------------------------------------------------
999 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1001 wxDataViewBitmapRenderer
::wxDataViewBitmapRenderer( const wxString
&varianttype
,
1002 wxDataViewCellMode mode
, int align
) :
1003 wxDataViewRenderer( varianttype
, mode
, align
)
1007 bool wxDataViewBitmapRenderer
::SetValue( const wxVariant
&value
)
1009 if (value
.GetType() == wxT("wxBitmap"))
1011 if (value
.GetType() == wxT("wxIcon"))
1017 bool wxDataViewBitmapRenderer
::GetValue( wxVariant
& WXUNUSED(value
) ) const
1022 bool wxDataViewBitmapRenderer
::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
1024 if (m_bitmap
.IsOk())
1025 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
1026 else if (m_icon
.IsOk())
1027 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
1032 wxSize wxDataViewBitmapRenderer
::GetSize() const
1034 if (m_bitmap
.IsOk())
1035 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
1036 else if (m_icon
.IsOk())
1037 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
1039 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
1042 // ---------------------------------------------------------
1043 // wxDataViewToggleRenderer
1044 // ---------------------------------------------------------
1046 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1048 wxDataViewToggleRenderer
::wxDataViewToggleRenderer( const wxString
&varianttype
,
1049 wxDataViewCellMode mode
, int align
) :
1050 wxDataViewRenderer( varianttype
, mode
, align
)
1055 bool wxDataViewToggleRenderer
::SetValue( const wxVariant
&value
)
1057 m_toggle
= value
.GetBool();
1062 bool wxDataViewToggleRenderer
::GetValue( wxVariant
&WXUNUSED(value
) ) const
1067 bool wxDataViewToggleRenderer
::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
1071 flags
|= wxCONTROL_CHECKED
;
1072 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
||
1073 GetEnabled() == false)
1074 flags
|= wxCONTROL_DISABLED
;
1076 // Ensure that the check boxes always have at least the minimal required
1077 // size, otherwise DrawCheckBox() doesn't really work well. If this size is
1078 // greater than the cell size, the checkbox will be truncated but this is a
1080 wxSize size
= cell
.GetSize();
1081 size
.IncTo(GetSize());
1084 wxRendererNative
::Get().DrawCheckBox(
1085 GetOwner()->GetOwner(),
1093 bool wxDataViewToggleRenderer
::WXActivateCell(const wxRect
& cellRect
,
1094 wxDataViewModel
*model
,
1095 const wxDataViewItem
& item
,
1097 const wxMouseEvent
*mouseEvent
)
1101 // Only react to clicks directly on the checkbox, not elsewhere in the
1104 // We suppose that the checkbox is centred in the total cell rectangle
1105 // as this is how it's rendered, at least under MSW. If this turns out
1106 // to be a wrong assumption, we probably would need to do the hit test
1107 // checking in wxRendererNative but for now this simple solution works.
1108 const wxRect checkRect
= wxRect(GetSize()).CentreIn(cellRect
);
1110 if ( !checkRect
.Contains(mouseEvent
->GetPosition()) )
1114 model
->ChangeValue(!m_toggle
, item
, col
);
1118 wxSize wxDataViewToggleRenderer
::GetSize() const
1120 // the window parameter is not used by GetCheckBoxSize() so it's
1121 // safe to pass NULL
1122 return wxRendererNative
::Get().GetCheckBoxSize(NULL
);
1125 // ---------------------------------------------------------
1126 // wxDataViewProgressRenderer
1127 // ---------------------------------------------------------
1129 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewRenderer
)
1131 wxDataViewProgressRenderer
::wxDataViewProgressRenderer( const wxString
&label
,
1132 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1133 wxDataViewRenderer( varianttype
, mode
, align
)
1139 bool wxDataViewProgressRenderer
::SetValue( const wxVariant
&value
)
1141 m_value
= (long) value
;
1143 if (m_value
< 0) m_value
= 0;
1144 if (m_value
> 100) m_value
= 100;
1149 bool wxDataViewProgressRenderer
::GetValue( wxVariant
&value
) const
1151 value
= (long) m_value
;
1156 wxDataViewProgressRenderer
::Render(wxRect rect
, wxDC
*dc
, int WXUNUSED(state
))
1158 // deflate the rect to leave a small border between bars in adjacent rows
1159 wxRect bar
= rect
.Deflate(0, 1);
1161 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1162 dc
->SetPen( *wxBLACK_PEN
);
1163 dc
->DrawRectangle( bar
);
1165 bar
.width
= (int)(bar
.width
* m_value
/ 100.);
1166 dc
->SetPen( *wxTRANSPARENT_PEN
);
1168 const wxDataViewItemAttr
& attr
= GetAttr();
1169 dc
->SetBrush( attr
.HasColour() ?
wxBrush(attr
.GetColour())
1171 dc
->DrawRectangle( bar
);
1176 wxSize wxDataViewProgressRenderer
::GetSize() const
1178 return wxSize(40,12);
1181 // ---------------------------------------------------------
1182 // wxDataViewIconTextRenderer
1183 // ---------------------------------------------------------
1185 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewRenderer
)
1187 wxDataViewIconTextRenderer
::wxDataViewIconTextRenderer(
1188 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1189 wxDataViewRenderer( varianttype
, mode
, align
)
1192 SetAlignment(align
);
1195 bool wxDataViewIconTextRenderer
::SetValue( const wxVariant
&value
)
1201 bool wxDataViewIconTextRenderer
::GetValue( wxVariant
& WXUNUSED(value
) ) const
1206 bool wxDataViewIconTextRenderer
::Render(wxRect rect
, wxDC
*dc
, int state
)
1210 const wxIcon
& icon
= m_value
.GetIcon();
1213 dc
->DrawIcon(icon
, rect
.x
, rect
.y
+ (rect
.height
- icon
.GetHeight())/2);
1214 xoffset
= icon
.GetWidth()+4;
1217 RenderText(m_value
.GetText(), xoffset
, rect
, dc
, state
);
1222 wxSize wxDataViewIconTextRenderer
::GetSize() const
1224 if (!m_value
.GetText().empty())
1226 wxSize size
= GetTextExtent(m_value
.GetText());
1228 if (m_value
.GetIcon().IsOk())
1229 size
.x
+= m_value
.GetIcon().GetWidth() + 4;
1232 return wxSize(80,20);
1235 wxWindow
* wxDataViewIconTextRenderer
::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1237 wxDataViewIconText iconText
;
1240 wxString text
= iconText
.GetText();
1242 // adjust the label rect to take the width of the icon into account
1243 if (iconText
.GetIcon().IsOk())
1245 int w
= iconText
.GetIcon().GetWidth() + 4;
1247 labelRect
.width
-= w
;
1250 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, text
,
1251 wxPoint(labelRect
.x
,labelRect
.y
),
1252 wxSize(labelRect
.width
,labelRect
.height
),
1253 wxTE_PROCESS_ENTER
);
1255 // select the text in the control an place the cursor at the end
1256 ctrl
->SetInsertionPointEnd();
1262 bool wxDataViewIconTextRenderer
::GetValueFromEditorCtrl( wxWindow
*editor
, wxVariant
& value
)
1264 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
1266 // The icon can't be edited so get its old value and reuse it.
1268 wxDataViewColumn
* const col
= GetOwner();
1269 GetView()->GetModel()->GetValue(valueOld
, m_item
, col
->GetModelColumn());
1271 wxDataViewIconText iconText
;
1272 iconText
<< valueOld
;
1274 // But replace the text with the value entered by user.
1275 iconText
.SetText(text
->GetValue());
1281 //-----------------------------------------------------------------------------
1282 // wxDataViewDropTarget
1283 //-----------------------------------------------------------------------------
1285 #if wxUSE_DRAG_AND_DROP
1287 class wxBitmapCanvas
: public wxWindow
1290 wxBitmapCanvas( wxWindow
*parent
, const wxBitmap
&bitmap
, const wxSize
&size
) :
1291 wxWindow( parent
, wxID_ANY
, wxPoint(0,0), size
)
1294 Connect( wxEVT_PAINT
, wxPaintEventHandler(wxBitmapCanvas
::OnPaint
) );
1297 void OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1300 dc
.DrawBitmap( m_bitmap
, 0, 0);
1306 class wxDataViewDropSource
: public wxDropSource
1309 wxDataViewDropSource( wxDataViewMainWindow
*win
, unsigned int row
) :
1317 ~wxDataViewDropSource()
1322 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
) )
1324 wxPoint pos
= wxGetMousePosition();
1328 int liney
= m_win
->GetLineStart( m_row
);
1330 m_win
->GetOwner()->CalcUnscrolledPosition( 0, liney
, NULL
, &liney
);
1331 m_win
->ClientToScreen( &linex
, &liney
);
1332 m_dist_x
= pos
.x
- linex
;
1333 m_dist_y
= pos
.y
- liney
;
1336 wxBitmap ib
= m_win
->CreateItemBitmap( m_row
, indent
);
1338 m_hint
= new wxFrame( m_win
->GetParent(), wxID_ANY
, wxEmptyString
,
1339 wxPoint(pos
.x
- m_dist_x
, pos
.y
+ 5 ),
1341 wxFRAME_TOOL_WINDOW
|
1342 wxFRAME_FLOAT_ON_PARENT
|
1343 wxFRAME_NO_TASKBAR
|
1345 new wxBitmapCanvas( m_hint
, ib
, ib
.GetSize() );
1350 m_hint
->Move( pos
.x
- m_dist_x
, pos
.y
+ 5 );
1351 m_hint
->SetTransparent( 128 );
1357 wxDataViewMainWindow
*m_win
;
1360 int m_dist_x
,m_dist_y
;
1364 class wxDataViewDropTarget
: public wxDropTarget
1367 wxDataViewDropTarget( wxDataObject
*obj
, wxDataViewMainWindow
*win
) :
1373 virtual wxDragResult
OnDragOver( wxCoord x
, wxCoord y
, wxDragResult def
)
1375 wxDataFormat format
= GetMatchingPair();
1376 if (format
== wxDF_INVALID
)
1378 return m_win
->OnDragOver( format
, x
, y
, def
);
1381 virtual bool OnDrop( wxCoord x
, wxCoord y
)
1383 wxDataFormat format
= GetMatchingPair();
1384 if (format
== wxDF_INVALID
)
1386 return m_win
->OnDrop( format
, x
, y
);
1389 virtual wxDragResult
OnData( wxCoord x
, wxCoord y
, wxDragResult def
)
1391 wxDataFormat format
= GetMatchingPair();
1392 if (format
== wxDF_INVALID
)
1396 return m_win
->OnData( format
, x
, y
, def
);
1399 virtual void OnLeave()
1400 { m_win
->OnLeave(); }
1402 wxDataViewMainWindow
*m_win
;
1405 #endif // wxUSE_DRAG_AND_DROP
1407 //-----------------------------------------------------------------------------
1408 // wxDataViewRenameTimer
1409 //-----------------------------------------------------------------------------
1411 wxDataViewRenameTimer
::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1416 void wxDataViewRenameTimer
::Notify()
1418 m_owner
->OnRenameTimer();
1421 //-----------------------------------------------------------------------------
1422 // wxDataViewMainWindow
1423 //-----------------------------------------------------------------------------
1425 // The tree building helper, declared firstly
1426 static void BuildTreeHelper( const wxDataViewModel
* model
, const wxDataViewItem
& item
,
1427 wxDataViewTreeNode
* node
);
1429 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1431 if (row1
> row2
) return 1;
1432 if (row1
== row2
) return 0;
1436 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1438 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1439 EVT_PAINT (wxDataViewMainWindow
::OnPaint
)
1440 EVT_MOUSE_EVENTS (wxDataViewMainWindow
::OnMouse
)
1441 EVT_SET_FOCUS (wxDataViewMainWindow
::OnSetFocus
)
1442 EVT_KILL_FOCUS (wxDataViewMainWindow
::OnKillFocus
)
1443 EVT_CHAR_HOOK (wxDataViewMainWindow
::OnCharHook
)
1444 EVT_CHAR (wxDataViewMainWindow
::OnChar
)
1447 wxDataViewMainWindow
::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1448 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1449 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
1450 m_selection( wxDataViewSelectionCmp
)
1455 m_editorRenderer
= NULL
;
1457 m_lastOnSame
= false;
1458 m_renameTimer
= new wxDataViewRenameTimer( this );
1460 // TODO: user better initial values/nothing selected
1461 m_currentCol
= NULL
;
1462 m_currentColSetByKeyboard
= false;
1463 m_useCellFocus
= false;
1464 m_currentRow
= (unsigned)-1;
1465 m_lineHeight
= GetDefaultRowHeight();
1467 #if wxUSE_DRAG_AND_DROP
1469 m_dragStart
= wxPoint(0,0);
1471 m_dragEnabled
= false;
1472 m_dropEnabled
= false;
1474 m_dropHintLine
= (unsigned int) -1;
1475 #endif // wxUSE_DRAG_AND_DROP
1477 m_lineLastClicked
= (unsigned int) -1;
1478 m_lineBeforeLastClicked
= (unsigned int) -1;
1479 m_lineSelectSingleOnUp
= (unsigned int) -1;
1483 SetBackgroundColour( *wxWHITE
);
1485 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1487 m_penRule
= wxPen(GetRuleColour());
1489 // compose a pen whichcan draw black lines
1490 // TODO: maybe there is something system colour to use
1491 m_penExpander
= wxPen(wxColour(0,0,0));
1493 m_root
= wxDataViewTreeNode
::CreateRootNode();
1495 // Make m_count = -1 will cause the class recaculate the real displaying number of rows.
1497 m_underMouse
= NULL
;
1501 wxDataViewMainWindow
::~wxDataViewMainWindow()
1504 delete m_renameTimer
;
1508 int wxDataViewMainWindow
::GetDefaultRowHeight() const
1511 // We would like to use the same line height that Explorer uses. This is
1512 // different from standard ListView control since Vista.
1513 if ( wxGetWinVersion() >= wxWinVersion_Vista
)
1514 return wxMax(16, GetCharHeight()) + 6; // 16 = mini icon height
1517 return wxMax(16, GetCharHeight()) + 1; // 16 = mini icon height
1522 #if wxUSE_DRAG_AND_DROP
1523 bool wxDataViewMainWindow
::EnableDragSource( const wxDataFormat
&format
)
1525 m_dragFormat
= format
;
1526 m_dragEnabled
= format
!= wxDF_INVALID
;
1531 bool wxDataViewMainWindow
::EnableDropTarget( const wxDataFormat
&format
)
1533 m_dropFormat
= format
;
1534 m_dropEnabled
= format
!= wxDF_INVALID
;
1537 SetDropTarget( new wxDataViewDropTarget( new wxCustomDataObject( format
), this ) );
1542 void wxDataViewMainWindow
::RemoveDropHint()
1547 RefreshRow( m_dropHintLine
);
1548 m_dropHintLine
= (unsigned int) -1;
1552 wxDragResult wxDataViewMainWindow
::OnDragOver( wxDataFormat format
, wxCoord x
,
1553 wxCoord y
, wxDragResult def
)
1557 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1558 unsigned int row
= GetLineAt( yy
);
1560 if ((row
>= GetRowCount()) || (xx
> GetEndOfLastCol()))
1566 wxDataViewItem item
= GetItemByRow( row
);
1568 wxDataViewModel
*model
= GetModel();
1570 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1571 event
.SetEventObject( m_owner
);
1572 event
.SetItem( item
);
1573 event
.SetModel( model
);
1574 event
.SetDataFormat( format
);
1575 event
.SetDropEffect( def
);
1576 if (!m_owner
->HandleWindowEvent( event
))
1582 if (!event
.IsAllowed())
1589 if (m_dropHint
&& (row
!= m_dropHintLine
))
1590 RefreshRow( m_dropHintLine
);
1592 m_dropHintLine
= row
;
1598 bool wxDataViewMainWindow
::OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
)
1604 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1605 unsigned int row
= GetLineAt( yy
);
1607 if ((row
>= GetRowCount()) || (xx
> GetEndOfLastCol()))
1610 wxDataViewItem item
= GetItemByRow( row
);
1612 wxDataViewModel
*model
= GetModel();
1614 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1615 event
.SetEventObject( m_owner
);
1616 event
.SetItem( item
);
1617 event
.SetModel( model
);
1618 event
.SetDataFormat( format
);
1619 if (!m_owner
->HandleWindowEvent( event
))
1622 if (!event
.IsAllowed())
1628 wxDragResult wxDataViewMainWindow
::OnData( wxDataFormat format
, wxCoord x
, wxCoord y
,
1633 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1634 unsigned int row
= GetLineAt( yy
);
1636 if ((row
>= GetRowCount()) || (xx
> GetEndOfLastCol()))
1639 wxDataViewItem item
= GetItemByRow( row
);
1641 wxDataViewModel
*model
= GetModel();
1643 wxCustomDataObject
*obj
= (wxCustomDataObject
*) GetDropTarget()->GetDataObject();
1645 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
1646 event
.SetEventObject( m_owner
);
1647 event
.SetItem( item
);
1648 event
.SetModel( model
);
1649 event
.SetDataFormat( format
);
1650 event
.SetDataSize( obj
->GetSize() );
1651 event
.SetDataBuffer( obj
->GetData() );
1652 event
.SetDropEffect( def
);
1653 if (!m_owner
->HandleWindowEvent( event
))
1656 if (!event
.IsAllowed())
1662 void wxDataViewMainWindow
::OnLeave()
1667 wxBitmap wxDataViewMainWindow
::CreateItemBitmap( unsigned int row
, int &indent
)
1669 int height
= GetLineHeight( row
);
1671 unsigned int cols
= GetOwner()->GetColumnCount();
1673 for (col
= 0; col
< cols
; col
++)
1675 wxDataViewColumn
*column
= GetOwner()->GetColumnAt(col
);
1676 if (column
->IsHidden())
1677 continue; // skip it!
1678 width
+= column
->GetWidth();
1684 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
1685 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
1686 indent
= indent
+ m_lineHeight
;
1687 // try to use the m_lineHeight as the expander space
1691 wxBitmap
bitmap( width
, height
);
1692 wxMemoryDC
dc( bitmap
);
1693 dc
.SetFont( GetFont() );
1694 dc
.SetPen( *wxBLACK_PEN
);
1695 dc
.SetBrush( *wxWHITE_BRUSH
);
1696 dc
.DrawRectangle( 0,0,width
,height
);
1698 wxDataViewModel
*model
= m_owner
->GetModel();
1700 wxDataViewColumn
* const
1701 expander
= GetExpanderColumnOrFirstOne(GetOwner());
1704 for (col
= 0; col
< cols
; col
++)
1706 wxDataViewColumn
*column
= GetOwner()->GetColumnAt( col
);
1707 wxDataViewRenderer
*cell
= column
->GetRenderer();
1709 if (column
->IsHidden())
1710 continue; // skip it!
1712 width
= column
->GetWidth();
1714 if (column
== expander
)
1717 wxDataViewItem item
= GetItemByRow( row
);
1718 cell
->PrepareForItem(model
, item
, column
->GetModelColumn());
1720 wxRect
item_rect(x
, 0, width
, height
);
1721 item_rect
.Deflate(PADDING_RIGHTLEFT
, 0);
1723 // dc.SetClippingRegion( item_rect );
1724 cell
->WXCallRender(item_rect
, &dc
, 0);
1725 // dc.DestroyClippingRegion();
1733 #endif // wxUSE_DRAG_AND_DROP
1736 // Draw focus rect for individual cell. Unlike native focus rect, we render
1737 // this in foreground text color (typically white) to enhance contrast and
1739 static void DrawSelectedCellFocusRect(wxDC
& dc
, const wxRect
& rect
)
1741 // (This code is based on wxRendererGeneric::DrawFocusRect and modified.)
1743 // draw the pixels manually because the "dots" in wxPen with wxDOT style
1744 // may be short traits and not really dots
1746 // note that to behave in the same manner as DrawRect(), we must exclude
1747 // the bottom and right borders from the rectangle
1748 wxCoord x1
= rect
.GetLeft(),
1750 x2
= rect
.GetRight(),
1751 y2
= rect
.GetBottom();
1753 wxDCPenChanger
pen(dc
, wxSystemSettings
::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
1756 for ( z
= x1
+ 1; z
< x2
; z
+= 2 )
1757 dc
.DrawPoint(z
, rect
.GetTop());
1759 wxCoord shift
= z
== x2 ?
0 : 1;
1760 for ( z
= y1
+ shift
; z
< y2
; z
+= 2 )
1761 dc
.DrawPoint(x2
, z
);
1763 shift
= z
== y2 ?
0 : 1;
1764 for ( z
= x2
- shift
; z
> x1
; z
-= 2 )
1765 dc
.DrawPoint(z
, y2
);
1767 shift
= z
== x1 ?
0 : 1;
1768 for ( z
= y2
- shift
; z
> y1
; z
-= 2 )
1769 dc
.DrawPoint(x1
, z
);
1773 void wxDataViewMainWindow
::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1775 wxDataViewModel
*model
= GetModel();
1776 wxAutoBufferedPaintDC
dc( this );
1778 dc
.SetBrush(GetOwner()->GetBackgroundColour());
1779 dc
.SetPen( *wxTRANSPARENT_PEN
);
1780 dc
.DrawRectangle(GetClientSize());
1784 // No items to draw.
1789 GetOwner()->PrepareDC( dc
);
1790 dc
.SetFont( GetFont() );
1792 wxRect update
= GetUpdateRegion().GetBox();
1793 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1795 // compute which items needs to be redrawn
1796 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
1797 unsigned int item_count
=
1798 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
1799 (int)(GetRowCount( ) - item_start
));
1800 unsigned int item_last
= item_start
+ item_count
;
1802 // Send the event to wxDataViewCtrl itself.
1803 wxWindow
* const parent
= GetParent();
1804 wxDataViewEvent
cache_event(wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, parent
->GetId());
1805 cache_event
.SetEventObject(parent
);
1806 cache_event
.SetCache(item_start
, item_last
- 1);
1807 parent
->ProcessWindowEvent(cache_event
);
1809 // compute which columns needs to be redrawn
1810 unsigned int cols
= GetOwner()->GetColumnCount();
1813 // we assume that we have at least one column below and painting an
1814 // empty control is unnecessary anyhow
1818 unsigned int col_start
= 0;
1819 unsigned int x_start
;
1820 for (x_start
= 0; col_start
< cols
; col_start
++)
1822 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_start
);
1823 if (col
->IsHidden())
1824 continue; // skip it!
1826 unsigned int w
= col
->GetWidth();
1827 if (x_start
+w
>= (unsigned int)update
.x
)
1833 unsigned int col_last
= col_start
;
1834 unsigned int x_last
= x_start
;
1835 for (; col_last
< cols
; col_last
++)
1837 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_last
);
1838 if (col
->IsHidden())
1839 continue; // skip it!
1841 if (x_last
> (unsigned int)update
.GetRight())
1844 x_last
+= col
->GetWidth();
1847 // Draw background of alternate rows specially if required
1848 if ( m_owner
->HasFlag(wxDV_ROW_LINES
) )
1850 wxColour altRowColour
= m_owner
->m_alternateRowColour
;
1851 if ( !altRowColour
.IsOk() )
1853 // Determine the alternate rows colour automatically from the
1854 // background colour.
1855 const wxColour bgColour
= m_owner
->GetBackgroundColour();
1857 // Depending on the background, alternate row color
1858 // will be 3% more dark or 50% brighter.
1859 int alpha
= bgColour
.GetRGB() > 0x808080 ?
97 : 150;
1860 altRowColour
= bgColour
.ChangeLightness(alpha
);
1863 dc
.SetPen(*wxTRANSPARENT_PEN
);
1864 dc
.SetBrush(wxBrush(altRowColour
));
1866 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1870 dc
.DrawRectangle(x_start
,
1872 GetClientSize().GetWidth(),
1873 GetLineHeight(item
));
1878 // Draw horizontal rules if required
1879 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1881 dc
.SetPen(m_penRule
);
1882 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1884 for (unsigned int i
= item_start
; i
<= item_last
; i
++)
1886 int y
= GetLineStart( i
);
1887 dc
.DrawLine(x_start
, y
, x_last
, y
);
1891 // Draw vertical rules if required
1892 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1894 dc
.SetPen(m_penRule
);
1895 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1897 // NB: Vertical rules are drawn in the last pixel of a column so that
1898 // they align perfectly with native MSW wxHeaderCtrl as well as for
1899 // consistency with MSW native list control. There's no vertical
1900 // rule at the most-left side of the control.
1902 int x
= x_start
- 1;
1903 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1905 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(i
);
1906 if (col
->IsHidden())
1907 continue; // skip it
1909 x
+= col
->GetWidth();
1911 dc
.DrawLine(x
, GetLineStart( item_start
),
1912 x
, GetLineStart( item_last
) );
1916 // redraw the background for the items which are selected/current
1917 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1919 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1921 if (selected
|| item
== m_currentRow
)
1923 wxRect
rect( x_start
, GetLineStart( item
),
1924 x_last
- x_start
, GetLineHeight( item
) );
1926 // draw selection and whole-item focus:
1929 int flags
= wxCONTROL_SELECTED
;
1931 flags
|= wxCONTROL_FOCUSED
;
1933 wxRendererNative
::Get().DrawItemSelectionRect
1942 // draw keyboard focus rect if applicable
1943 if ( item
== m_currentRow
&& m_hasFocus
)
1945 bool renderColumnFocus
= false;
1947 if ( m_useCellFocus
&& m_currentCol
&& m_currentColSetByKeyboard
)
1949 renderColumnFocus
= true;
1951 // If this is container node without columns, render full-row focus:
1954 wxDataViewTreeNode
*node
= GetTreeNodeByRow(item
);
1955 if ( node
->HasChildren() && !model
->HasContainerColumns(node
->GetItem()) )
1956 renderColumnFocus
= false;
1960 if ( renderColumnFocus
)
1962 for ( unsigned int i
= col_start
; i
< col_last
; i
++ )
1964 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(i
);
1965 if ( col
->IsHidden() )
1968 rect
.width
= col
->GetWidth();
1970 if ( col
== m_currentCol
)
1972 // make the rect more visible by adding a small
1973 // margin around it:
1978 // DrawFocusRect() uses XOR and is all but
1979 // invisible against dark-blue background. Use
1980 // the same color used for selected text.
1981 DrawSelectedCellFocusRect(dc
, rect
);
1985 wxRendererNative
::Get().DrawFocusRect
1996 rect
.x
+= rect
.width
;
2001 // render focus rectangle for the whole row
2002 wxRendererNative
::Get().DrawFocusRect
2007 selected ?
(int)wxCONTROL_SELECTED
: 0
2014 #if wxUSE_DRAG_AND_DROP
2017 wxRect
rect( x_start
, GetLineStart( m_dropHintLine
),
2018 x_last
- x_start
, GetLineHeight( m_dropHintLine
) );
2019 dc
.SetPen( *wxBLACK_PEN
);
2020 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2021 dc
.DrawRectangle( rect
);
2023 #endif // wxUSE_DRAG_AND_DROP
2025 wxDataViewColumn
* const
2026 expander
= GetExpanderColumnOrFirstOne(GetOwner());
2028 // redraw all cells for all rows which must be repainted and all columns
2030 cell_rect
.x
= x_start
;
2031 for (unsigned int i
= col_start
; i
< col_last
; i
++)
2033 wxDataViewColumn
*col
= GetOwner()->GetColumnAt( i
);
2034 wxDataViewRenderer
*cell
= col
->GetRenderer();
2035 cell_rect
.width
= col
->GetWidth();
2037 if ( col
->IsHidden() || cell_rect
.width
<= 0 )
2038 continue; // skip it!
2040 for (unsigned int item
= item_start
; item
< item_last
; item
++)
2042 // get the cell value and set it into the renderer
2043 wxDataViewTreeNode
*node
= NULL
;
2044 wxDataViewItem dataitem
;
2046 if (!IsVirtualList())
2048 node
= GetTreeNodeByRow(item
);
2052 dataitem
= node
->GetItem();
2054 // Skip all columns of "container" rows except the expander
2055 // column itself unless HasContainerColumns() overrides this.
2056 if ( col
!= expander
&&
2057 model
->IsContainer(dataitem
) &&
2058 !model
->HasContainerColumns(dataitem
) )
2063 dataitem
= wxDataViewItem( wxUIntToPtr(item
+1) );
2066 cell
->PrepareForItem(model
, dataitem
, col
->GetModelColumn());
2069 cell_rect
.y
= GetLineStart( item
);
2070 cell_rect
.height
= GetLineHeight( item
);
2072 // draw the background
2073 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
2075 DrawCellBackground( cell
, dc
, cell_rect
);
2077 // deal with the expander
2079 if ((!IsList()) && (col
== expander
))
2081 // Calculate the indent first
2082 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
2084 // we reserve m_lineHeight of horizontal space for the expander
2085 // but leave EXPANDER_MARGIN around the expander itself
2086 int exp_x
= cell_rect
.x
+ indent
+ EXPANDER_MARGIN
;
2088 indent
+= m_lineHeight
;
2090 // draw expander if needed and visible
2091 if ( node
->HasChildren() && exp_x
< cell_rect
.GetRight() )
2093 dc
.SetPen( m_penExpander
);
2094 dc
.SetBrush( wxNullBrush
);
2096 int exp_size
= m_lineHeight
- 2*EXPANDER_MARGIN
;
2097 int exp_y
= cell_rect
.y
+ (cell_rect
.height
- exp_size
)/2
2098 + EXPANDER_MARGIN
- EXPANDER_OFFSET
;
2100 const wxRect
rect(exp_x
, exp_y
, exp_size
, exp_size
);
2103 if ( m_underMouse
== node
)
2104 flag
|= wxCONTROL_CURRENT
;
2105 if ( node
->IsOpen() )
2106 flag
|= wxCONTROL_EXPANDED
;
2108 // ensure that we don't overflow the cell (which might
2109 // happen if the column is very narrow)
2110 wxDCClipper
clip(dc
, cell_rect
);
2112 wxRendererNative
::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
2115 // force the expander column to left-center align
2116 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
2119 wxRect item_rect
= cell_rect
;
2120 item_rect
.Deflate(PADDING_RIGHTLEFT
, 0);
2122 // account for the tree indent (harmless if we're not indented)
2123 item_rect
.x
+= indent
;
2124 item_rect
.width
-= indent
;
2126 if ( item_rect
.width
<= 0 )
2130 if (m_hasFocus
&& selected
)
2131 state
|= wxDATAVIEW_CELL_SELECTED
;
2133 // TODO: it would be much more efficient to create a clipping
2134 // region for the entire column being rendered (in the OnPaint
2135 // of wxDataViewMainWindow) instead of a single clip region for
2136 // each cell. However it would mean that each renderer should
2137 // respect the given wxRect's top & bottom coords, eventually
2138 // violating only the left & right coords - however the user can
2139 // make its own renderer and thus we cannot be sure of that.
2140 wxDCClipper
clip(dc
, item_rect
);
2142 cell
->WXCallRender(item_rect
, &dc
, state
);
2145 cell_rect
.x
+= cell_rect
.width
;
2150 void wxDataViewMainWindow
::DrawCellBackground( wxDataViewRenderer
* cell
, wxDC
& dc
, const wxRect
& rect
)
2152 wxRect
rectBg( rect
);
2154 // don't overlap the horizontal rules
2155 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
2161 // don't overlap the vertical rules
2162 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
2168 cell
->RenderBackground(&dc
, rectBg
);
2171 void wxDataViewMainWindow
::OnRenameTimer()
2173 // We have to call this here because changes may just have
2174 // been made and no screen update taken place.
2177 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
2178 // (needs to be tested!)
2182 wxDataViewItem item
= GetItemByRow( m_currentRow
);
2184 StartEditing( item
, m_currentCol
);
2188 wxDataViewMainWindow
::StartEditing(const wxDataViewItem
& item
,
2189 const wxDataViewColumn
* col
)
2191 wxDataViewRenderer
* renderer
= col
->GetRenderer();
2192 if ( !IsCellEditableInMode(item
, col
, wxDATAVIEW_CELL_EDITABLE
) )
2195 const wxRect itemRect
= GetItemRect(item
, col
);
2196 if ( renderer
->StartEditing(item
, itemRect
) )
2198 // Save the renderer to be able to finish/cancel editing it later and
2199 // save the control to be able to detect if we're still editing it.
2200 m_editorRenderer
= renderer
;
2201 m_editorCtrl
= renderer
->GetEditorCtrl();
2205 //-----------------------------------------------------------------------------
2206 // Helper class for do operation on the tree node
2207 //-----------------------------------------------------------------------------
2212 virtual ~DoJob() { }
2214 // The return value control how the tree-walker tranverse the tree
2217 DONE
, // Job done, stop traversing and return
2218 SKIP_SUBTREE
, // Ignore the current node's subtree and continue
2219 CONTINUE
// Job not done, continue
2222 virtual int operator() ( wxDataViewTreeNode
* node
) = 0;
2225 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
2227 wxCHECK_MSG( node
, false, "can't walk NULL node" );
2229 switch( func( node
) )
2233 case DoJob
::SKIP_SUBTREE
:
2235 case DoJob
::CONTINUE
:
2239 if ( node
->HasChildren() )
2241 const wxDataViewTreeNodes
& nodes
= node
->GetChildNodes();
2243 for ( wxDataViewTreeNodes
::const_iterator i
= nodes
.begin();
2247 if ( Walker(*i
, func
) )
2255 bool wxDataViewMainWindow
::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
2257 if (IsVirtualList())
2259 wxDataViewVirtualListModel
*list_model
=
2260 (wxDataViewVirtualListModel
*) GetModel();
2261 m_count
= list_model
->GetCount();
2267 wxDataViewTreeNode
*parentNode
= FindNode(parent
);
2272 wxDataViewItemArray modelSiblings
;
2273 GetModel()->GetChildren(parent
, modelSiblings
);
2274 const int modelSiblingsSize
= modelSiblings
.size();
2276 int posInModel
= modelSiblings
.Index(item
, /*fromEnd=*/true);
2277 wxCHECK_MSG( posInModel
!= wxNOT_FOUND
, false, "adding non-existent item?" );
2279 wxDataViewTreeNode
*itemNode
= new wxDataViewTreeNode(parentNode
, item
);
2280 itemNode
->SetHasChildren(GetModel()->IsContainer(item
));
2282 parentNode
->SetHasChildren(true);
2284 const wxDataViewTreeNodes
& nodeSiblings
= parentNode
->GetChildNodes();
2285 const int nodeSiblingsSize
= nodeSiblings
.size();
2289 if ( posInModel
== modelSiblingsSize
- 1 )
2291 nodePos
= nodeSiblingsSize
;
2293 else if ( modelSiblingsSize
== nodeSiblingsSize
+ 1 )
2295 // This is the simple case when our node tree already matches the
2296 // model and only this one item is missing.
2297 nodePos
= posInModel
;
2301 // It's possible that a larger discrepancy between the model and
2302 // our realization exists. This can happen e.g. when adding a bunch
2303 // of items to the model and then calling ItemsAdded() just once
2304 // afterwards. In this case, we must find the right position by
2305 // looking at sibling items.
2307 // append to the end if we won't find a better position:
2308 nodePos
= nodeSiblingsSize
;
2310 for ( int nextItemPos
= posInModel
+ 1;
2311 nextItemPos
< modelSiblingsSize
;
2314 int nextNodePos
= parentNode
->FindChildByItem(modelSiblings
[nextItemPos
]);
2315 if ( nextNodePos
!= wxNOT_FOUND
)
2317 nodePos
= nextNodePos
;
2323 parentNode
->ChangeSubTreeCount(+1);
2324 parentNode
->InsertChild(itemNode
, nodePos
);
2329 GetOwner()->InvalidateColBestWidths();
2335 bool wxDataViewMainWindow
::ItemDeleted(const wxDataViewItem
& parent
,
2336 const wxDataViewItem
& item
)
2338 if (IsVirtualList())
2340 wxDataViewVirtualListModel
*list_model
=
2341 (wxDataViewVirtualListModel
*) GetModel();
2342 m_count
= list_model
->GetCount();
2344 if ( !m_selection
.empty() )
2346 const int row
= GetRowByItem(item
);
2348 int rowIndexInSelection
= wxNOT_FOUND
;
2350 const size_t selCount
= m_selection
.size();
2351 for ( size_t i
= 0; i
< selCount
; i
++ )
2353 if ( m_selection
[i
] == (unsigned)row
)
2354 rowIndexInSelection
= i
;
2355 else if ( m_selection
[i
] > (unsigned)row
)
2359 if ( rowIndexInSelection
!= wxNOT_FOUND
)
2360 m_selection
.RemoveAt(rowIndexInSelection
);
2364 else // general case
2366 wxDataViewTreeNode
*parentNode
= FindNode(parent
);
2368 // Notice that it is possible that the item being deleted is not in the
2369 // tree at all, for example we could be deleting a never shown (because
2370 // collapsed) item in a tree model. So it's not an error if we don't know
2371 // about this item, just return without doing anything then.
2375 wxCHECK_MSG( parentNode
->HasChildren(), false, "parent node doesn't have children?" );
2376 const wxDataViewTreeNodes
& parentsChildren
= parentNode
->GetChildNodes();
2378 // We can't use FindNode() to find 'item', because it was already
2379 // removed from the model by the time ItemDeleted() is called, so we
2380 // have to do it manually. We keep track of its position as well for
2382 int itemPosInNode
= 0;
2383 wxDataViewTreeNode
*itemNode
= NULL
;
2384 for ( wxDataViewTreeNodes
::const_iterator i
= parentsChildren
.begin();
2385 i
!= parentsChildren
.end();
2386 ++i
, ++itemPosInNode
)
2388 if( (*i
)->GetItem() == item
)
2395 // If the parent wasn't expanded, it's possible that we didn't have a
2396 // node corresponding to 'item' and so there's nothing left to do.
2399 // If this was the last child to be removed, it's possible the parent
2400 // node became a leaf. Let's ask the model about it.
2401 if ( parentNode
->GetChildNodes().empty() )
2402 parentNode
->SetHasChildren(GetModel()->IsContainer(parent
));
2407 // Delete the item from wxDataViewTreeNode representation:
2408 const int itemsDeleted
= 1 + itemNode
->GetSubTreeCount();
2410 parentNode
->RemoveChild(itemNode
);
2412 parentNode
->ChangeSubTreeCount(-itemsDeleted
);
2414 // Make the row number invalid and get a new valid one when user call GetRowCount
2417 // If this was the last child to be removed, it's possible the parent
2418 // node became a leaf. Let's ask the model about it.
2419 if ( parentNode
->GetChildNodes().empty() )
2421 bool isContainer
= GetModel()->IsContainer(parent
);
2422 parentNode
->SetHasChildren(isContainer
);
2425 // If it's still a container, make sure we show "+" icon for it
2426 // and not "-" one as there is nothing to collapse any more.
2427 if ( parentNode
->IsOpen() )
2428 parentNode
->ToggleOpen();
2432 // Update selection by removing 'item' and its entire children tree from the selection.
2433 if ( !m_selection
.empty() )
2435 // we can't call GetRowByItem() on 'item', as it's already deleted, so compute it from
2436 // the parent ('parentNode') and position in its list of children
2438 if ( itemPosInNode
== 0 )
2440 // 1st child, row number is that of the parent parentNode + 1
2441 itemRow
= GetRowByItem(parentNode
->GetItem()) + 1;
2445 // row number is that of the sibling above 'item' + its subtree if any + 1
2446 const wxDataViewTreeNode
*siblingNode
= parentNode
->GetChildNodes()[itemPosInNode
- 1];
2448 itemRow
= GetRowByItem(siblingNode
->GetItem()) +
2449 siblingNode
->GetSubTreeCount() +
2453 wxDataViewSelection
newsel(wxDataViewSelectionCmp
);
2455 const size_t numSelections
= m_selection
.size();
2456 for ( size_t i
= 0; i
< numSelections
; ++i
)
2458 const int s
= m_selection
[i
];
2460 newsel
.push_back(s
);
2461 else if ( s
>= itemRow
+ itemsDeleted
)
2462 newsel
.push_back(s
- itemsDeleted
);
2463 // else: deleted item, remove from selection
2466 m_selection
= newsel
;
2470 // Change the current row to the last row if the current exceed the max row number
2471 if ( m_currentRow
>= GetRowCount() )
2472 ChangeCurrentRow(m_count
- 1);
2474 GetOwner()->InvalidateColBestWidths();
2480 bool wxDataViewMainWindow
::ItemChanged(const wxDataViewItem
& item
)
2485 GetOwner()->InvalidateColBestWidths();
2488 wxWindow
*parent
= GetParent();
2489 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2490 le
.SetEventObject(parent
);
2491 le
.SetModel(GetModel());
2493 parent
->ProcessWindowEvent(le
);
2498 bool wxDataViewMainWindow
::ValueChanged( const wxDataViewItem
& item
, unsigned int model_column
)
2500 int view_column
= -1;
2501 unsigned int n_col
= m_owner
->GetColumnCount();
2502 for (unsigned i
= 0; i
< n_col
; i
++)
2504 wxDataViewColumn
*column
= m_owner
->GetColumn( i
);
2505 if (column
->GetModelColumn() == model_column
)
2507 view_column
= (int) i
;
2511 if (view_column
== -1)
2514 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
2515 /*#define MAX_VIRTUAL_WIDTH 100000
2517 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
2518 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2519 Refresh( true, &rect );
2526 GetOwner()->InvalidateColBestWidth(view_column
);
2529 wxWindow
*parent
= GetParent();
2530 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2531 le
.SetEventObject(parent
);
2532 le
.SetModel(GetModel());
2534 le
.SetColumn(view_column
);
2535 le
.SetDataViewColumn(GetOwner()->GetColumn(view_column
));
2536 parent
->ProcessWindowEvent(le
);
2541 bool wxDataViewMainWindow
::Cleared()
2544 m_selection
.Clear();
2545 m_currentRow
= (unsigned)-1;
2550 BuildTree( GetModel() );
2557 GetOwner()->InvalidateColBestWidths();
2563 void wxDataViewMainWindow
::UpdateDisplay()
2566 m_underMouse
= NULL
;
2569 void wxDataViewMainWindow
::OnInternalIdle()
2571 wxWindow
::OnInternalIdle();
2575 RecalculateDisplay();
2580 void wxDataViewMainWindow
::RecalculateDisplay()
2582 wxDataViewModel
*model
= GetModel();
2589 int width
= GetEndOfLastCol();
2590 int height
= GetLineStart( GetRowCount() );
2592 SetVirtualSize( width
, height
);
2593 GetOwner()->SetScrollRate( 10, m_lineHeight
);
2598 void wxDataViewMainWindow
::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2600 m_underMouse
= NULL
;
2602 wxWindow
::ScrollWindow( dx
, dy
, rect
);
2604 if (GetOwner()->m_headerArea
)
2605 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
2608 void wxDataViewMainWindow
::ScrollTo( int rows
, int column
)
2610 m_underMouse
= NULL
;
2613 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
2614 int sy
= GetLineStart( rows
)/y
;
2618 wxRect rect
= GetClientRect();
2622 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
2623 for (x_start
= 0; colnum
< column
; colnum
++)
2625 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(colnum
);
2626 if (col
->IsHidden())
2627 continue; // skip it!
2629 w
= col
->GetWidth();
2633 int x_end
= x_start
+ w
;
2634 xe
= xx
+ rect
.width
;
2637 sx
= ( xx
+ x_end
- xe
)/x
;
2644 m_owner
->Scroll( sx
, sy
);
2647 int wxDataViewMainWindow
::GetCountPerPage() const
2649 wxSize size
= GetClientSize();
2650 return size
.y
/ m_lineHeight
;
2653 int wxDataViewMainWindow
::GetEndOfLastCol() const
2657 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2659 const wxDataViewColumn
*c
=
2660 const_cast<wxDataViewCtrl
*>(GetOwner())->GetColumnAt( i
);
2663 width
+= c
->GetWidth();
2668 unsigned int wxDataViewMainWindow
::GetFirstVisibleRow() const
2672 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2674 return GetLineAt( y
);
2677 unsigned int wxDataViewMainWindow
::GetLastVisibleRow()
2679 wxSize client_size
= GetClientSize();
2680 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2681 &client_size
.x
, &client_size
.y
);
2683 // we should deal with the pixel here
2684 unsigned int row
= GetLineAt(client_size
.y
) - 1;
2686 return wxMin( GetRowCount()-1, row
);
2689 unsigned int wxDataViewMainWindow
::GetRowCount() const
2691 if ( m_count
== -1 )
2693 wxDataViewMainWindow
* const
2694 self
= const_cast<wxDataViewMainWindow
*>(this);
2695 self
->m_count
= RecalculateCount();
2696 self
->UpdateDisplay();
2701 void wxDataViewMainWindow
::ChangeCurrentRow( unsigned int row
)
2708 void wxDataViewMainWindow
::SelectAllRows( bool on
)
2715 m_selection
.Clear();
2716 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2717 m_selection
.Add( i
);
2722 unsigned int first_visible
= GetFirstVisibleRow();
2723 unsigned int last_visible
= GetLastVisibleRow();
2725 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2727 unsigned int row
= m_selection
[i
];
2728 if ((row
>= first_visible
) && (row
<= last_visible
))
2731 m_selection
.Clear();
2735 void wxDataViewMainWindow
::SelectRow( unsigned int row
, bool on
)
2737 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2741 m_selection
.Add( row
);
2749 m_selection
.Remove( row
);
2755 void wxDataViewMainWindow
::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2759 unsigned int tmp
= from
;
2765 for (i
= from
; i
<= to
; i
++)
2767 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2770 m_selection
.Add( i
);
2775 m_selection
.Remove( i
);
2778 RefreshRows( from
, to
);
2781 void wxDataViewMainWindow
::Select( const wxArrayInt
& aSelections
)
2783 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2785 int n
= aSelections
[i
];
2787 m_selection
.Add( n
);
2792 void wxDataViewMainWindow
::ReverseRowSelection( unsigned int row
)
2794 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2795 m_selection
.Add( row
);
2797 m_selection
.Remove( row
);
2801 bool wxDataViewMainWindow
::IsRowSelected( unsigned int row
)
2803 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2806 void wxDataViewMainWindow
::SendSelectionChangedEvent( const wxDataViewItem
& item
)
2808 wxWindow
*parent
= GetParent();
2809 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
2811 le
.SetEventObject(parent
);
2812 le
.SetModel(GetModel());
2815 parent
->ProcessWindowEvent(le
);
2818 void wxDataViewMainWindow
::RefreshRow( unsigned int row
)
2820 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
2821 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2823 wxSize client_size
= GetClientSize();
2824 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2825 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2826 if (intersect_rect
.width
> 0)
2827 Refresh( true, &intersect_rect
);
2830 void wxDataViewMainWindow
::RefreshRows( unsigned int from
, unsigned int to
)
2834 unsigned int tmp
= to
;
2839 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
2840 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2842 wxSize client_size
= GetClientSize();
2843 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2844 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2845 if (intersect_rect
.width
> 0)
2846 Refresh( true, &intersect_rect
);
2849 void wxDataViewMainWindow
::RefreshRowsAfter( unsigned int firstRow
)
2851 wxSize client_size
= GetClientSize();
2852 int start
= GetLineStart( firstRow
);
2853 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
2854 if (start
> client_size
.y
) return;
2856 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
2858 Refresh( true, &rect
);
2861 wxRect wxDataViewMainWindow
::GetLineRect( unsigned int row
) const
2865 rect
.y
= GetLineStart( row
);
2866 rect
.width
= GetEndOfLastCol();
2867 rect
.height
= GetLineHeight( row
);
2872 int wxDataViewMainWindow
::GetLineStart( unsigned int row
) const
2874 const wxDataViewModel
*model
= GetModel();
2876 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2878 // TODO make more efficient
2883 for (r
= 0; r
< row
; r
++)
2885 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2886 if (!node
) return start
;
2888 wxDataViewItem item
= node
->GetItem();
2890 unsigned int cols
= GetOwner()->GetColumnCount();
2892 int height
= m_lineHeight
;
2893 for (col
= 0; col
< cols
; col
++)
2895 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2896 if (column
->IsHidden())
2897 continue; // skip it!
2900 model
->IsContainer(item
) &&
2901 !model
->HasContainerColumns(item
))
2902 continue; // skip it!
2904 wxDataViewRenderer
*renderer
=
2905 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2906 renderer
->PrepareForItem(model
, item
, column
->GetModelColumn());
2908 height
= wxMax( height
, renderer
->GetSize().y
);
2918 return row
* m_lineHeight
;
2922 int wxDataViewMainWindow
::GetLineAt( unsigned int y
) const
2924 const wxDataViewModel
*model
= GetModel();
2926 // check for the easy case first
2927 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
2928 return y
/ m_lineHeight
;
2930 // TODO make more efficient
2931 unsigned int row
= 0;
2932 unsigned int yy
= 0;
2935 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2938 // not really correct...
2939 return row
+ ((y
-yy
) / m_lineHeight
);
2942 wxDataViewItem item
= node
->GetItem();
2944 unsigned int cols
= GetOwner()->GetColumnCount();
2946 int height
= m_lineHeight
;
2947 for (col
= 0; col
< cols
; col
++)
2949 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2950 if (column
->IsHidden())
2951 continue; // skip it!
2954 model
->IsContainer(item
) &&
2955 !model
->HasContainerColumns(item
))
2956 continue; // skip it!
2958 wxDataViewRenderer
*renderer
=
2959 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2960 renderer
->PrepareForItem(model
, item
, column
->GetModelColumn());
2962 height
= wxMax( height
, renderer
->GetSize().y
);
2973 int wxDataViewMainWindow
::GetLineHeight( unsigned int row
) const
2975 const wxDataViewModel
*model
= GetModel();
2977 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2979 wxASSERT( !IsVirtualList() );
2981 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2982 // wxASSERT( node );
2983 if (!node
) return m_lineHeight
;
2985 wxDataViewItem item
= node
->GetItem();
2987 int height
= m_lineHeight
;
2989 unsigned int cols
= GetOwner()->GetColumnCount();
2991 for (col
= 0; col
< cols
; col
++)
2993 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2994 if (column
->IsHidden())
2995 continue; // skip it!
2998 model
->IsContainer(item
) &&
2999 !model
->HasContainerColumns(item
))
3000 continue; // skip it!
3002 wxDataViewRenderer
*renderer
=
3003 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
3004 renderer
->PrepareForItem(model
, item
, column
->GetModelColumn());
3006 height
= wxMax( height
, renderer
->GetSize().y
);
3013 return m_lineHeight
;
3018 class RowToTreeNodeJob
: public DoJob
3021 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
3024 this->current
= current
;
3029 virtual int operator() ( wxDataViewTreeNode
* node
)
3032 if( current
== static_cast<int>(row
))
3038 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
3040 current
+= node
->GetSubTreeCount();
3041 return DoJob
::SKIP_SUBTREE
;
3047 // If the current node has only leaf children, we can find the
3048 // desired node directly. This can speed up finding the node
3049 // in some cases, and will have a very good effect for list views.
3050 if ( node
->HasChildren() &&
3051 (int)node
->GetChildNodes().size() == node
->GetSubTreeCount() )
3053 const int index
= static_cast<int>(row
) - current
- 1;
3054 ret
= node
->GetChildNodes()[index
];
3058 return DoJob
::CONTINUE
;
3062 wxDataViewTreeNode
* GetResult() const
3068 wxDataViewTreeNode
* ret
;
3069 wxDataViewTreeNode
* parent
;
3072 wxDataViewTreeNode
* wxDataViewMainWindow
::GetTreeNodeByRow(unsigned int row
) const
3074 wxASSERT( !IsVirtualList() );
3076 if ( row
== (unsigned)-1 )
3079 RowToTreeNodeJob
job( row
, -2, m_root
);
3080 Walker( m_root
, job
);
3081 return job
.GetResult();
3084 wxDataViewItem wxDataViewMainWindow
::GetItemByRow(unsigned int row
) const
3086 wxDataViewItem item
;
3087 if (IsVirtualList())
3089 if ( row
< GetRowCount() )
3090 item
= wxDataViewItem(wxUIntToPtr(row
+1));
3094 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
3096 item
= node
->GetItem();
3103 wxDataViewMainWindow
::SendExpanderEvent(wxEventType type
,
3104 const wxDataViewItem
& item
)
3106 wxWindow
*parent
= GetParent();
3107 wxDataViewEvent
le(type
, parent
->GetId());
3109 le
.SetEventObject(parent
);
3110 le
.SetModel(GetModel());
3113 return !parent
->ProcessWindowEvent(le
) || le
.IsAllowed();
3116 bool wxDataViewMainWindow
::IsExpanded( unsigned int row
) const
3121 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3125 if (!node
->HasChildren())
3128 return node
->IsOpen();
3131 bool wxDataViewMainWindow
::HasChildren( unsigned int row
) const
3136 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3140 if (!node
->HasChildren())
3146 void wxDataViewMainWindow
::Expand( unsigned int row
)
3151 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3155 if (!node
->HasChildren())
3158 if (!node
->IsOpen())
3160 if ( !SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, node
->GetItem()) )
3162 // Vetoed by the event handler.
3168 // build the children of current node
3169 if( node
->GetChildNodes().empty() )
3172 ::BuildTreeHelper(GetModel(), node
->GetItem(), node
);
3175 // By expanding the node all row indices that are currently in the selection list
3176 // and are greater than our node have become invalid. So we have to correct that now.
3177 const unsigned rowAdjustment
= node
->GetSubTreeCount();
3178 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3180 const unsigned testRow
= m_selection
[i
];
3181 // all rows above us are not affected, so skip them
3185 m_selection
[i
] += rowAdjustment
;
3188 if(m_currentRow
> row
)
3189 ChangeCurrentRow(m_currentRow
+ rowAdjustment
);
3193 // Send the expanded event
3194 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
3198 void wxDataViewMainWindow
::Collapse(unsigned int row
)
3203 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
3207 if (!node
->HasChildren())
3212 if ( !SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem()) )
3214 // Vetoed by the event handler.
3218 // Find out if there are selected items below the current node.
3219 bool selectCollapsingRow
= false;
3220 const unsigned rowAdjustment
= node
->GetSubTreeCount();
3221 unsigned maxRowToBeTested
= row
+ rowAdjustment
;
3222 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3224 const unsigned testRow
= m_selection
[i
];
3225 if(testRow
> row
&& testRow
<= maxRowToBeTested
)
3227 selectCollapsingRow
= true;
3228 // get out as soon as we have found a node that is selected
3235 // If the node to be closed has selected items the user won't see those any longer.
3236 // We select the collapsing node in this case.
3237 if(selectCollapsingRow
)
3239 SelectAllRows(false);
3240 ChangeCurrentRow(row
);
3241 SelectRow(row
, true);
3242 SendSelectionChangedEvent(GetItemByRow(row
));
3246 // if there were no selected items below our node we still need to "fix" the
3247 // selection list to adjust for the changing of the row indices.
3248 // We actually do the opposite of what we are doing in Expand().
3249 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3251 const unsigned testRow
= m_selection
[i
];
3252 // all rows above us are not affected, so skip them
3256 m_selection
[i
] -= rowAdjustment
;
3259 // if the "current row" is being collapsed away we change it to the current row ;-)
3260 if(m_currentRow
> row
&& m_currentRow
<= maxRowToBeTested
)
3261 ChangeCurrentRow(row
);
3262 else if(m_currentRow
> row
)
3263 ChangeCurrentRow(m_currentRow
- rowAdjustment
);
3268 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,node
->GetItem());
3272 wxDataViewTreeNode
* wxDataViewMainWindow
::FindNode( const wxDataViewItem
& item
)
3274 const wxDataViewModel
* model
= GetModel();
3281 // Compose the parent-chain for the item we are looking for
3282 wxVector
<wxDataViewItem
> parentChain
;
3283 wxDataViewItem
it( item
);
3286 parentChain
.push_back(it
);
3287 it
= model
->GetParent(it
);
3290 // Find the item along the parent-chain.
3291 // This algorithm is designed to speed up the node-finding method
3292 wxDataViewTreeNode
* node
= m_root
;
3293 for( unsigned iter
= parentChain
.size()-1; ; --iter
)
3295 if( node
->HasChildren() )
3297 if( node
->GetChildNodes().empty() )
3299 // Even though the item is a container, it doesn't have any
3300 // child nodes in the control's representation yet. We have
3301 // to realize its subtree now.
3303 ::BuildTreeHelper(model
, node
->GetItem(), node
);
3306 const wxDataViewTreeNodes
& nodes
= node
->GetChildNodes();
3309 for (unsigned i
= 0; i
< nodes
.GetCount(); ++i
)
3311 wxDataViewTreeNode
* currentNode
= nodes
[i
];
3312 if (currentNode
->GetItem() == parentChain
[iter
])
3314 if (currentNode
->GetItem() == item
)
3334 void wxDataViewMainWindow
::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
3335 wxDataViewColumn
* &column
)
3337 wxDataViewColumn
*col
= NULL
;
3338 unsigned int cols
= GetOwner()->GetColumnCount();
3339 unsigned int colnum
= 0;
3341 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
3342 for (unsigned x_start
= 0; colnum
< cols
; colnum
++)
3344 col
= GetOwner()->GetColumnAt(colnum
);
3345 if (col
->IsHidden())
3346 continue; // skip it!
3348 unsigned int w
= col
->GetWidth();
3349 if (x_start
+w
>= (unsigned int)x
)
3356 item
= GetItemByRow( GetLineAt( y
) );
3359 wxRect wxDataViewMainWindow
::GetItemRect( const wxDataViewItem
& item
,
3360 const wxDataViewColumn
* column
)
3365 unsigned int cols
= GetOwner()->GetColumnCount();
3366 // If column is null the loop will compute the combined width of all columns.
3367 // Otherwise, it will compute the x position of the column we are looking for.
3368 for (unsigned int i
= 0; i
< cols
; i
++)
3370 wxDataViewColumn
* col
= GetOwner()->GetColumnAt( i
);
3375 if (col
->IsHidden())
3376 continue; // skip it!
3378 xpos
+= col
->GetWidth();
3379 width
+= col
->GetWidth();
3384 // If we have a column, we need can get its width directly.
3385 if(column
->IsHidden())
3388 width
= column
->GetWidth();
3393 // If we have no column, we reset the x position back to zero.
3397 // we have to take an expander column into account and compute its indentation
3398 // to get the correct x position where the actual text is
3400 int row
= GetRowByItem(item
);
3402 (column
== 0 || GetExpanderColumnOrFirstOne(GetOwner()) == column
) )
3404 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3405 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
3406 indent
= indent
+ m_lineHeight
; // use m_lineHeight as the width of the expander
3409 wxRect
itemRect( xpos
+ indent
,
3410 GetLineStart( row
),
3412 GetLineHeight( row
) );
3414 GetOwner()->CalcScrolledPosition( itemRect
.x
, itemRect
.y
,
3415 &itemRect
.x
, &itemRect
.y
);
3420 int wxDataViewMainWindow
::RecalculateCount() const
3422 if (IsVirtualList())
3424 wxDataViewVirtualListModel
*list_model
=
3425 (wxDataViewVirtualListModel
*) GetModel();
3427 return list_model
->GetCount();
3431 return m_root
->GetSubTreeCount();
3435 class ItemToRowJob
: public DoJob
3438 ItemToRowJob(const wxDataViewItem
& item_
, wxVector
<wxDataViewItem
>::reverse_iterator iter
)
3445 // Maybe binary search will help to speed up this process
3446 virtual int operator() ( wxDataViewTreeNode
* node
)
3449 if( node
->GetItem() == item
)
3454 if( node
->GetItem() == *m_iter
)
3457 return DoJob
::CONTINUE
;
3461 ret
+= node
->GetSubTreeCount();
3462 return DoJob
::SKIP_SUBTREE
;
3467 // the row number is begin from zero
3468 int GetResult() const
3472 wxVector
<wxDataViewItem
>::reverse_iterator m_iter
;
3473 wxDataViewItem item
;
3478 int wxDataViewMainWindow
::GetRowByItem(const wxDataViewItem
& item
) const
3480 const wxDataViewModel
* model
= GetModel();
3484 if (IsVirtualList())
3486 return wxPtrToUInt( item
.GetID() ) -1;
3493 // Compose the parent-chain of the item we are looking for
3494 wxVector
<wxDataViewItem
> parentChain
;
3495 wxDataViewItem
it( item
);
3498 parentChain
.push_back(it
);
3499 it
= model
->GetParent(it
);
3502 // add an 'invalid' item to represent our 'invisible' root node
3503 parentChain
.push_back(wxDataViewItem());
3505 // the parent chain was created by adding the deepest parent first.
3506 // so if we want to start at the root node, we have to iterate backwards through the vector
3507 ItemToRowJob
job( item
, parentChain
.rbegin() );
3508 Walker( m_root
, job
);
3509 return job
.GetResult();
3513 static void BuildTreeHelper( const wxDataViewModel
* model
, const wxDataViewItem
& item
,
3514 wxDataViewTreeNode
* node
)
3516 if( !model
->IsContainer( item
) )
3519 wxDataViewItemArray children
;
3520 unsigned int num
= model
->GetChildren( item
, children
);
3522 for ( unsigned int index
= 0; index
< num
; index
++ )
3524 wxDataViewTreeNode
*n
= new wxDataViewTreeNode(node
, children
[index
]);
3526 if( model
->IsContainer(children
[index
]) )
3527 n
->SetHasChildren( true );
3529 node
->InsertChild(n
, index
);
3532 wxASSERT( node
->IsOpen() );
3533 node
->ChangeSubTreeCount(+num
);
3536 void wxDataViewMainWindow
::BuildTree(wxDataViewModel
* model
)
3540 if (GetModel()->IsVirtualListModel())
3546 m_root
= wxDataViewTreeNode
::CreateRootNode();
3548 // First we define a invalid item to fetch the top-level elements
3549 wxDataViewItem item
;
3551 BuildTreeHelper( model
, item
, m_root
);
3555 void wxDataViewMainWindow
::DestroyTree()
3557 if (!IsVirtualList())
3565 wxDataViewMainWindow
::FindColumnForEditing(const wxDataViewItem
& item
, wxDataViewCellMode mode
)
3567 // Edit the current column editable in 'mode'. If no column is focused
3568 // (typically because the user has full row selected), try to find the
3569 // first editable column (this would typically be a checkbox for
3570 // wxDATAVIEW_CELL_ACTIVATABLE and we don't want to force the user to set
3571 // focus on the checkbox column; or on the only editable text column).
3573 wxDataViewColumn
*candidate
= m_currentCol
;
3576 !IsCellEditableInMode(item
, candidate
, mode
) &&
3577 !m_currentColSetByKeyboard
)
3579 // If current column was set by mouse to something not editable (in
3580 // 'mode') and the user pressed Space/F2 to edit it, treat the
3581 // situation as if there was whole-row focus, because that's what is
3582 // visually indicated and the mouse click could very well be targeted
3583 // on the row rather than on an individual cell.
3585 // But if it was done by keyboard, respect that even if the column
3586 // isn't editable, because focus is visually on that column and editing
3587 // something else would be surprising.
3593 const unsigned cols
= GetOwner()->GetColumnCount();
3594 for ( unsigned i
= 0; i
< cols
; i
++ )
3596 wxDataViewColumn
*c
= GetOwner()->GetColumnAt(i
);
3597 if ( c
->IsHidden() )
3600 if ( IsCellEditableInMode(item
, c
, mode
) )
3608 // If on container item without columns, only the expander column
3609 // may be directly editable:
3611 GetOwner()->GetExpanderColumn() != candidate
&&
3612 GetModel()->IsContainer(item
) &&
3613 !GetModel()->HasContainerColumns(item
) )
3615 candidate
= GetOwner()->GetExpanderColumn();
3621 if ( !IsCellEditableInMode(item
, candidate
, mode
) )
3627 bool wxDataViewMainWindow
::IsCellEditableInMode(const wxDataViewItem
& item
,
3628 const wxDataViewColumn
*col
,
3629 wxDataViewCellMode mode
) const
3631 if ( col
->GetRenderer()->GetMode() != mode
)
3634 if ( !GetModel()->IsEnabled(item
, col
->GetModelColumn()) )
3640 void wxDataViewMainWindow
::OnCharHook(wxKeyEvent
& event
)
3644 // Handle any keys special for the in-place editor and return without
3645 // calling Skip() below.
3646 switch ( event
.GetKeyCode() )
3649 m_editorRenderer
->CancelEditing();
3653 m_editorRenderer
->FinishEditing();
3661 void wxDataViewMainWindow
::OnChar( wxKeyEvent
&event
)
3663 wxWindow
* const parent
= GetParent();
3665 // propagate the char event upwards
3666 wxKeyEvent
eventForParent(event
);
3667 eventForParent
.SetEventObject(parent
);
3668 if ( parent
->ProcessWindowEvent(eventForParent
) )
3671 if ( parent
->HandleAsNavigationKey(event
) )
3674 // no item -> nothing to do
3675 if (!HasCurrentRow())
3681 // don't use m_linesPerPage directly as it might not be computed yet
3682 const int pageSize
= GetCountPerPage();
3683 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
3685 switch ( event
.GetKeyCode() )
3688 if ( event
.HasModifiers() )
3695 // Enter activates the item, i.e. sends wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED to
3696 // it. Only if that event is not handled do we activate column renderer (which
3697 // is normally done by Space) or even inline editing.
3699 const wxDataViewItem item
= GetItemByRow(m_currentRow
);
3701 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
,
3704 le
.SetEventObject(parent
);
3705 le
.SetModel(GetModel());
3707 if ( parent
->ProcessWindowEvent(le
) )
3709 // else: fall through to WXK_SPACE handling
3713 if ( event
.HasModifiers() )
3720 // Space toggles activatable items or -- if not activatable --
3721 // starts inline editing (this is normally done using F2 on
3722 // Windows, but Space is common everywhere else, so use it too
3723 // for greater cross-platform compatibility).
3725 const wxDataViewItem item
= GetItemByRow(m_currentRow
);
3727 // Activate the current activatable column. If not column is focused (typically
3728 // because the user has full row selected), try to find the first activatable
3729 // column (this would typically be a checkbox and we don't want to force the user
3730 // to set focus on the checkbox column).
3731 wxDataViewColumn
*activatableCol
= FindColumnForEditing(item
, wxDATAVIEW_CELL_ACTIVATABLE
);
3733 if ( activatableCol
)
3735 const unsigned colIdx
= activatableCol
->GetModelColumn();
3736 const wxRect cell_rect
= GetOwner()->GetItemRect(item
, activatableCol
);
3738 wxDataViewRenderer
*cell
= activatableCol
->GetRenderer();
3739 cell
->PrepareForItem(GetModel(), item
, colIdx
);
3740 cell
->WXActivateCell(cell_rect
, GetModel(), item
, colIdx
, NULL
);
3744 // else: fall through to WXK_F2 handling
3748 if ( event
.HasModifiers() )
3755 if( !m_selection
.empty() )
3757 // Mimic Windows 7 behavior: edit the item that has focus
3758 // if it is selected and the first selected item if focus
3759 // is out of selection.
3761 if ( m_selection
.Index(m_currentRow
) != wxNOT_FOUND
)
3764 sel
= m_selection
[0];
3767 const wxDataViewItem item
= GetItemByRow(sel
);
3769 // Edit the current column. If no column is focused
3770 // (typically because the user has full row selected), try
3771 // to find the first editable column.
3772 wxDataViewColumn
*editableCol
= FindColumnForEditing(item
, wxDATAVIEW_CELL_EDITABLE
);
3775 GetOwner()->EditItem(item
, editableCol
);
3781 OnVerticalNavigation( -1, event
);
3785 OnVerticalNavigation( +1, event
);
3787 // Add the process for tree expanding/collapsing
3797 OnVerticalNavigation( +(int)GetRowCount(), event
);
3801 OnVerticalNavigation( -(int)GetRowCount(), event
);
3805 OnVerticalNavigation( -(pageSize
- 1), event
);
3809 OnVerticalNavigation( +(pageSize
- 1), event
);
3817 void wxDataViewMainWindow
::OnVerticalNavigation(int delta
, const wxKeyEvent
& event
)
3819 // if there is no selection, we cannot move it anywhere
3820 if (!HasCurrentRow() || IsEmpty())
3823 int newRow
= (int)m_currentRow
+ delta
;
3825 // let's keep the new row inside the allowed range
3829 const int rowCount
= (int)GetRowCount();
3830 if ( newRow
>= rowCount
)
3831 newRow
= rowCount
- 1;
3833 unsigned int oldCurrent
= m_currentRow
;
3834 unsigned int newCurrent
= (unsigned int)newRow
;
3836 // in single selection we just ignore Shift as we can't select several
3838 if ( event
.ShiftDown() && !IsSingleSel() )
3840 RefreshRow( oldCurrent
);
3842 ChangeCurrentRow( newCurrent
);
3844 // select all the items between the old and the new one
3845 if ( oldCurrent
> newCurrent
)
3847 newCurrent
= oldCurrent
;
3848 oldCurrent
= m_currentRow
;
3851 SelectRows( oldCurrent
, newCurrent
, true );
3852 if (oldCurrent
!=newCurrent
)
3853 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
3857 RefreshRow( oldCurrent
);
3859 // all previously selected items are unselected unless ctrl is held
3860 if ( !event
.ControlDown() )
3861 SelectAllRows(false);
3863 ChangeCurrentRow( newCurrent
);
3865 if ( !event
.ControlDown() )
3867 SelectRow( m_currentRow
, true );
3868 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
3871 RefreshRow( m_currentRow
);
3874 GetOwner()->EnsureVisible( m_currentRow
, -1 );
3877 void wxDataViewMainWindow
::OnLeftKey()
3881 TryAdvanceCurrentColumn(NULL
, /*forward=*/false);
3885 wxDataViewTreeNode
* node
= GetTreeNodeByRow(m_currentRow
);
3889 if ( TryAdvanceCurrentColumn(node
, /*forward=*/false) )
3892 // Because TryAdvanceCurrentColumn() return false, we are at the first
3893 // column or using whole-row selection. In this situation, we can use
3894 // the standard TreeView handling of the left key.
3895 if (node
->HasChildren() && node
->IsOpen())
3897 Collapse(m_currentRow
);
3901 // if the node is already closed, we move the selection to its parent
3902 wxDataViewTreeNode
*parent_node
= node
->GetParent();
3906 int parent
= GetRowByItem( parent_node
->GetItem() );
3909 unsigned int row
= m_currentRow
;
3910 SelectRow( row
, false);
3911 SelectRow( parent
, true );
3912 ChangeCurrentRow( parent
);
3913 GetOwner()->EnsureVisible( parent
, -1 );
3914 SendSelectionChangedEvent( parent_node
->GetItem() );
3921 void wxDataViewMainWindow
::OnRightKey()
3925 TryAdvanceCurrentColumn(NULL
, /*forward=*/true);
3929 wxDataViewTreeNode
* node
= GetTreeNodeByRow(m_currentRow
);
3933 if ( node
->HasChildren() )
3935 if ( !node
->IsOpen() )
3937 Expand( m_currentRow
);
3941 // if the node is already open, we move the selection to the first child
3942 unsigned int row
= m_currentRow
;
3943 SelectRow( row
, false );
3944 SelectRow( row
+ 1, true );
3945 ChangeCurrentRow( row
+ 1 );
3946 GetOwner()->EnsureVisible( row
+ 1, -1 );
3947 SendSelectionChangedEvent( GetItemByRow(row
+1) );
3952 TryAdvanceCurrentColumn(node
, /*forward=*/true);
3957 bool wxDataViewMainWindow
::TryAdvanceCurrentColumn(wxDataViewTreeNode
*node
, bool forward
)
3959 if ( GetOwner()->GetColumnCount() == 0 )
3962 if ( !m_useCellFocus
)
3967 // navigation shouldn't work in branch nodes without other columns:
3968 if ( node
->HasChildren() && !GetModel()->HasContainerColumns(node
->GetItem()) )
3972 if ( m_currentCol
== NULL
|| !m_currentColSetByKeyboard
)
3976 m_currentCol
= GetOwner()->GetColumnAt(1);
3977 m_currentColSetByKeyboard
= true;
3978 RefreshRow(m_currentRow
);
3985 int idx
= GetOwner()->GetColumnIndex(m_currentCol
) + (forward ?
+1 : -1);
3987 if ( idx
>= (int)GetOwner()->GetColumnCount() )
3990 GetOwner()->EnsureVisible(m_currentRow
, idx
);
3994 // We are going to the left of the second column. Reset to whole-row
3995 // focus (which means first column would be edited).
3996 m_currentCol
= NULL
;
3997 RefreshRow(m_currentRow
);
4001 m_currentCol
= GetOwner()->GetColumnAt(idx
);
4002 m_currentColSetByKeyboard
= true;
4003 RefreshRow(m_currentRow
);
4007 void wxDataViewMainWindow
::OnMouse( wxMouseEvent
&event
)
4009 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
4011 // let the base handle mouse wheel events.
4016 if(event
.ButtonDown())
4018 // Not skipping button down events would prevent the system from
4019 // setting focus to this window as most (all?) of them do by default,
4020 // so skip it to enable default handling.
4024 int x
= event
.GetX();
4025 int y
= event
.GetY();
4026 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
4027 wxDataViewColumn
*col
= NULL
;
4030 unsigned int cols
= GetOwner()->GetColumnCount();
4032 for (i
= 0; i
< cols
; i
++)
4034 wxDataViewColumn
*c
= GetOwner()->GetColumnAt( i
);
4036 continue; // skip it!
4038 if (x
< xpos
+ c
->GetWidth())
4043 xpos
+= c
->GetWidth();
4046 wxDataViewModel
* const model
= GetModel();
4048 const unsigned int current
= GetLineAt( y
);
4049 const wxDataViewItem item
= GetItemByRow(current
);
4051 // Handle right clicking here, before everything else as context menu
4052 // events should be sent even when we click outside of any item, unlike all
4054 if (event
.RightUp())
4056 wxWindow
*parent
= GetParent();
4057 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
4058 le
.SetEventObject(parent
);
4061 if ( item
.IsOk() && col
)
4064 le
.SetColumn( col
->GetModelColumn() );
4065 le
.SetDataViewColumn( col
);
4068 parent
->ProcessWindowEvent(le
);
4072 // Check if we clicked outside the item area.
4073 if ((current
>= GetRowCount()) || !col
)
4075 // Follow Windows convention here: clicking either left or right (but
4076 // not middle) button clears the existing selection.
4077 if (m_owner
&& (event
.LeftDown() || event
.RightDown()))
4079 if (!GetSelections().empty())
4081 m_owner
->UnselectAll();
4082 SendSelectionChangedEvent(wxDataViewItem());
4089 wxDataViewRenderer
*cell
= col
->GetRenderer();
4090 wxDataViewColumn
* const
4091 expander
= GetExpanderColumnOrFirstOne(GetOwner());
4093 // Test whether the mouse is hovering over the expander (a.k.a tree "+"
4094 // button) and also determine the offset of the real cell start, skipping
4095 // the indentation and the expander itself.
4096 bool hoverOverExpander
= false;
4098 if ((!IsList()) && (expander
== col
))
4100 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
4102 int indent
= node
->GetIndentLevel();
4103 itemOffset
= GetOwner()->GetIndent()*indent
;
4105 if ( node
->HasChildren() )
4107 // we make the rectangle we are looking in a bit bigger than the actual
4108 // visual expander so the user can hit that little thing reliably
4109 wxRect
rect(itemOffset
,
4110 GetLineStart( current
) + (GetLineHeight(current
) - m_lineHeight
)/2,
4111 m_lineHeight
, m_lineHeight
);
4113 if( rect
.Contains(x
, y
) )
4115 // So the mouse is over the expander
4116 hoverOverExpander
= true;
4117 if (m_underMouse
&& m_underMouse
!= node
)
4119 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
4120 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
4122 if (m_underMouse
!= node
)
4124 // wxLogMessage("Do the row: %d", current);
4125 RefreshRow(current
);
4127 m_underMouse
= node
;
4131 // Account for the expander as well, even if this item doesn't have it,
4132 // its parent does so it still counts for the offset.
4133 itemOffset
+= m_lineHeight
;
4135 if (!hoverOverExpander
)
4137 if (m_underMouse
!= NULL
)
4139 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
4140 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
4141 m_underMouse
= NULL
;
4145 #if wxUSE_DRAG_AND_DROP
4146 if (event
.Dragging())
4148 if (m_dragCount
== 0)
4150 // we have to report the raw, physical coords as we want to be
4151 // able to call HitTest(event.m_pointDrag) from the user code to
4152 // get the item being dragged
4153 m_dragStart
= event
.GetPosition();
4158 if (m_dragCount
!= 3)
4161 if (event
.LeftIsDown())
4163 m_owner
->CalcUnscrolledPosition( m_dragStart
.x
, m_dragStart
.y
,
4164 &m_dragStart
.x
, &m_dragStart
.y
);
4165 unsigned int drag_item_row
= GetLineAt( m_dragStart
.y
);
4166 wxDataViewItem itemDragged
= GetItemByRow( drag_item_row
);
4168 // Notify cell about drag
4169 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
4170 event
.SetEventObject( m_owner
);
4171 event
.SetItem( itemDragged
);
4172 event
.SetModel( model
);
4173 if (!m_owner
->HandleWindowEvent( event
))
4176 if (!event
.IsAllowed())
4179 wxDataObject
*obj
= event
.GetDataObject();
4183 wxDataViewDropSource
drag( this, drag_item_row
);
4184 drag
.SetData( *obj
);
4185 /* wxDragResult res = */ drag
.DoDragDrop(event
.GetDragFlags());
4194 #endif // wxUSE_DRAG_AND_DROP
4196 bool simulateClick
= false;
4198 if (event
.ButtonDClick())
4200 m_renameTimer
->Stop();
4201 m_lastOnSame
= false;
4204 bool ignore_other_columns
=
4205 ((expander
!= col
) &&
4206 (model
->IsContainer(item
)) &&
4207 (!model
->HasContainerColumns(item
)));
4209 if (event
.LeftDClick())
4211 if(hoverOverExpander
)
4213 // a double click on the expander will be converted into a "simulated" normal click
4214 simulateClick
= true;
4216 else if ( current
== m_lineLastClicked
)
4218 wxWindow
*parent
= GetParent();
4219 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
4221 le
.SetColumn( col
->GetModelColumn() );
4222 le
.SetDataViewColumn( col
);
4223 le
.SetEventObject(parent
);
4224 le
.SetModel(GetModel());
4226 parent
->ProcessWindowEvent(le
);
4231 // The first click was on another item, so don't interpret this as
4232 // a double click, but as a simple click instead
4233 simulateClick
= true;
4237 if (event
.LeftUp() && !hoverOverExpander
)
4239 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
4241 // select single line
4242 SelectAllRows( false );
4243 SelectRow( m_lineSelectSingleOnUp
, true );
4244 SendSelectionChangedEvent( GetItemByRow(m_lineSelectSingleOnUp
) );
4247 // If the user click the expander, we do not do editing even if the column
4248 // with expander are editable
4249 if (m_lastOnSame
&& !ignore_other_columns
)
4251 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
4252 IsCellEditableInMode(item
, col
, wxDATAVIEW_CELL_EDITABLE
) )
4254 m_renameTimer
->Start( 100, true );
4258 m_lastOnSame
= false;
4259 m_lineSelectSingleOnUp
= (unsigned int)-1;
4261 else if(!event
.LeftUp())
4263 // This is necessary, because after a DnD operation in
4264 // from and to ourself, the up event is swallowed by the
4265 // DnD code. So on next non-up event (which means here and
4266 // now) m_lineSelectSingleOnUp should be reset.
4267 m_lineSelectSingleOnUp
= (unsigned int)-1;
4270 if (event
.RightDown())
4272 m_lineBeforeLastClicked
= m_lineLastClicked
;
4273 m_lineLastClicked
= current
;
4275 // If the item is already selected, do not update the selection.
4276 // Multi-selections should not be cleared if a selected item is clicked.
4277 if (!IsRowSelected(current
))
4279 SelectAllRows(false);
4280 const unsigned oldCurrent
= m_currentRow
;
4281 ChangeCurrentRow(current
);
4282 SelectRow(m_currentRow
,true);
4283 RefreshRow(oldCurrent
);
4284 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
4287 else if (event
.MiddleDown())
4291 if((event
.LeftDown() || simulateClick
) && hoverOverExpander
)
4293 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
4295 // hoverOverExpander being true tells us that our node must be
4296 // valid and have children.
4297 // So we don't need any extra checks.
4298 if( node
->IsOpen() )
4303 else if ((event
.LeftDown() || simulateClick
) && !hoverOverExpander
)
4305 m_lineBeforeLastClicked
= m_lineLastClicked
;
4306 m_lineLastClicked
= current
;
4308 unsigned int oldCurrentRow
= m_currentRow
;
4309 bool oldWasSelected
= IsRowSelected(m_currentRow
);
4311 bool cmdModifierDown
= event
.CmdDown();
4312 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
4314 if ( IsSingleSel() || !IsRowSelected(current
) )
4316 SelectAllRows( false );
4317 ChangeCurrentRow(current
);
4318 SelectRow(m_currentRow
,true);
4319 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
4321 else // multi sel & current is highlighted & no mod keys
4323 m_lineSelectSingleOnUp
= current
;
4324 ChangeCurrentRow(current
); // change focus
4327 else // multi sel & either ctrl or shift is down
4329 if (cmdModifierDown
)
4331 ChangeCurrentRow(current
);
4332 ReverseRowSelection(m_currentRow
);
4333 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
4335 else if (event
.ShiftDown())
4337 ChangeCurrentRow(current
);
4339 unsigned int lineFrom
= oldCurrentRow
,
4342 if ( lineTo
< lineFrom
)
4345 lineFrom
= m_currentRow
;
4348 SelectRows(lineFrom
, lineTo
, true);
4349 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
4351 else // !ctrl, !shift
4353 // test in the enclosing if should make it impossible
4354 wxFAIL_MSG( wxT("how did we get here?") );
4358 if (m_currentRow
!= oldCurrentRow
)
4359 RefreshRow( oldCurrentRow
);
4361 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
4363 // Update selection here...
4365 m_currentColSetByKeyboard
= false;
4367 // This flag is used to decide whether we should start editing the item
4368 // label. We do it if the user clicks twice (but not double clicks,
4369 // i.e. simulateClick is false) on the same item but not if the click
4370 // was used for something else already, e.g. selecting the item (so it
4371 // must have been already selected) or giving the focus to the control
4372 // (so it must have had focus already).
4373 m_lastOnSame
= !simulateClick
&& ((col
== oldCurrentCol
) &&
4374 (current
== oldCurrentRow
)) && oldWasSelected
&&
4377 // Call ActivateCell() after everything else as under GTK+
4378 if ( IsCellEditableInMode(item
, col
, wxDATAVIEW_CELL_ACTIVATABLE
) )
4380 // notify cell about click
4381 cell
->PrepareForItem(model
, item
, col
->GetModelColumn());
4383 wxRect
cell_rect( xpos
+ itemOffset
,
4384 GetLineStart( current
),
4385 col
->GetWidth() - itemOffset
,
4386 GetLineHeight( current
) );
4388 // Report position relative to the cell's custom area, i.e.
4389 // no the entire space as given by the control but the one
4390 // used by the renderer after calculation of alignment etc.
4392 // adjust the rectangle ourselves to account for the alignment
4393 wxRect rectItem
= cell_rect
;
4394 const int align
= cell
->GetAlignment();
4395 if ( align
!= wxDVR_DEFAULT_ALIGNMENT
)
4397 const wxSize size
= cell
->GetSize();
4399 if ( size
.x
>= 0 && size
.x
< cell_rect
.width
)
4401 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
4402 rectItem
.x
+= (cell_rect
.width
- size
.x
)/2;
4403 else if ( align
& wxALIGN_RIGHT
)
4404 rectItem
.x
+= cell_rect
.width
- size
.x
;
4405 // else: wxALIGN_LEFT is the default
4408 if ( size
.y
>= 0 && size
.y
< cell_rect
.height
)
4410 if ( align
& wxALIGN_CENTER_VERTICAL
)
4411 rectItem
.y
+= (cell_rect
.height
- size
.y
)/2;
4412 else if ( align
& wxALIGN_BOTTOM
)
4413 rectItem
.y
+= cell_rect
.height
- size
.y
;
4414 // else: wxALIGN_TOP is the default
4418 wxMouseEvent
event2(event
);
4419 event2
.m_x
-= rectItem
.x
;
4420 event2
.m_y
-= rectItem
.y
;
4421 m_owner
->CalcUnscrolledPosition(event2
.m_x
, event2
.m_y
, &event2
.m_x
, &event2
.m_y
);
4423 /* ignore ret */ cell
->WXActivateCell
4428 col
->GetModelColumn(),
4435 void wxDataViewMainWindow
::OnSetFocus( wxFocusEvent
&event
)
4439 if (HasCurrentRow())
4445 void wxDataViewMainWindow
::OnKillFocus( wxFocusEvent
&event
)
4449 if (HasCurrentRow())
4455 void wxDataViewMainWindow
::OnColumnsCountChanged()
4457 int editableCount
= 0;
4459 const unsigned cols
= GetOwner()->GetColumnCount();
4460 for ( unsigned i
= 0; i
< cols
; i
++ )
4462 wxDataViewColumn
*c
= GetOwner()->GetColumnAt(i
);
4463 if ( c
->IsHidden() )
4465 if ( c
->GetRenderer()->GetMode() != wxDATAVIEW_CELL_INERT
)
4469 m_useCellFocus
= (editableCount
> 1);
4474 //-----------------------------------------------------------------------------
4476 //-----------------------------------------------------------------------------
4478 WX_DEFINE_LIST(wxDataViewColumnList
)
4480 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4481 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
4482 EVT_SIZE(wxDataViewCtrl
::OnSize
)
4485 wxDataViewCtrl
::~wxDataViewCtrl()
4488 GetModel()->RemoveNotifier( m_notifier
);
4491 m_colsBestWidths
.clear();
4494 void wxDataViewCtrl
::Init()
4496 m_cols
.DeleteContents(true);
4499 // No sorting column at start
4500 m_sortingColumnIdx
= wxNOT_FOUND
;
4502 m_headerArea
= NULL
;
4503 m_clientArea
= NULL
;
4505 m_colsDirty
= false;
4508 bool wxDataViewCtrl
::Create(wxWindow
*parent
,
4513 const wxValidator
& validator
,
4514 const wxString
& name
)
4516 // if ( (style & wxBORDER_MASK) == 0)
4517 // style |= wxBORDER_SUNKEN;
4521 if (!wxControl
::Create( parent
, id
, pos
, size
,
4522 style
| wxScrolledWindowStyle
, validator
, name
))
4525 SetInitialSize(size
);
4528 MacSetClipChildren( true );
4531 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
4533 // We use the cursor keys for moving the selection, not scrolling, so call
4534 // this method to ensure wxScrollHelperEvtHandler doesn't catch all
4535 // keyboard events forwarded to us from wxListMainWindow.
4536 DisableKeyboardScrolling();
4538 if (HasFlag(wxDV_NO_HEADER
))
4539 m_headerArea
= NULL
;
4541 m_headerArea
= new wxDataViewHeaderWindow(this);
4543 SetTargetWindow( m_clientArea
);
4545 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
4547 sizer
->Add( m_headerArea
, 0, wxGROW
);
4548 sizer
->Add( m_clientArea
, 1, wxGROW
);
4554 wxBorder wxDataViewCtrl
::GetDefaultBorder() const
4556 return wxBORDER_THEME
;
4560 WXLRESULT wxDataViewCtrl
::MSWWindowProc(WXUINT nMsg
,
4564 WXLRESULT rc
= wxDataViewCtrlBase
::MSWWindowProc(nMsg
, wParam
, lParam
);
4567 // we need to process arrows ourselves for scrolling
4568 if ( nMsg
== WM_GETDLGCODE
)
4570 rc
|= DLGC_WANTARROWS
;
4578 wxSize wxDataViewCtrl
::GetSizeAvailableForScrollTarget(const wxSize
& size
)
4580 wxSize newsize
= size
;
4581 if (!HasFlag(wxDV_NO_HEADER
) && (m_headerArea
))
4582 newsize
.y
-= m_headerArea
->GetSize().y
;
4587 void wxDataViewCtrl
::OnSize( wxSizeEvent
&WXUNUSED(event
) )
4589 // We need to override OnSize so that our scrolled
4590 // window a) does call Layout() to use sizers for
4591 // positioning the controls but b) does not query
4592 // the sizer for their size and use that for setting
4593 // the scrollable area as set that ourselves by
4594 // calling SetScrollbar() further down.
4600 // We must redraw the headers if their height changed. Normally this
4601 // shouldn't happen as the control shouldn't let itself be resized beneath
4602 // its minimal height but avoid the display artefacts that appear if it
4603 // does happen, e.g. because there is really not enough vertical space.
4604 if ( !HasFlag(wxDV_NO_HEADER
) && m_headerArea
&&
4605 m_headerArea
->GetSize().y
<= m_headerArea
->GetBestSize(). y
)
4607 m_headerArea
->Refresh();
4611 void wxDataViewCtrl
::SetFocus()
4614 m_clientArea
->SetFocus();
4617 bool wxDataViewCtrl
::SetFont(const wxFont
& font
)
4619 if (!wxControl
::SetFont(font
))
4623 m_headerArea
->SetFont(font
);
4627 m_clientArea
->SetFont(font
);
4628 m_clientArea
->SetRowHeight(m_clientArea
->GetDefaultRowHeight());
4631 if (m_headerArea
|| m_clientArea
)
4633 InvalidateColBestWidths();
4642 bool wxDataViewCtrl
::AssociateModel( wxDataViewModel
*model
)
4644 if (!wxDataViewCtrlBase
::AssociateModel( model
))
4649 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
4650 model
->AddNotifier( m_notifier
);
4652 else if (m_notifier
)
4654 m_notifier
->Cleared();
4658 m_clientArea
->DestroyTree();
4662 m_clientArea
->BuildTree(model
);
4665 m_clientArea
->UpdateDisplay();
4670 #if wxUSE_DRAG_AND_DROP
4672 bool wxDataViewCtrl
::EnableDragSource( const wxDataFormat
&format
)
4674 return m_clientArea
->EnableDragSource( format
);
4677 bool wxDataViewCtrl
::EnableDropTarget( const wxDataFormat
&format
)
4679 return m_clientArea
->EnableDropTarget( format
);
4682 #endif // wxUSE_DRAG_AND_DROP
4684 bool wxDataViewCtrl
::AppendColumn( wxDataViewColumn
*col
)
4686 if (!wxDataViewCtrlBase
::AppendColumn(col
))
4689 m_cols
.Append( col
);
4690 m_colsBestWidths
.push_back(CachedColWidthInfo());
4691 OnColumnsCountChanged();
4695 bool wxDataViewCtrl
::PrependColumn( wxDataViewColumn
*col
)
4697 if (!wxDataViewCtrlBase
::PrependColumn(col
))
4700 m_cols
.Insert( col
);
4701 m_colsBestWidths
.insert(m_colsBestWidths
.begin(), CachedColWidthInfo());
4702 OnColumnsCountChanged();
4706 bool wxDataViewCtrl
::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4708 if (!wxDataViewCtrlBase
::InsertColumn(pos
,col
))
4711 m_cols
.Insert( pos
, col
);
4712 m_colsBestWidths
.insert(m_colsBestWidths
.begin() + pos
, CachedColWidthInfo());
4713 OnColumnsCountChanged();
4717 void wxDataViewCtrl
::OnColumnChange(unsigned int idx
)
4720 m_headerArea
->UpdateColumn(idx
);
4722 m_clientArea
->UpdateDisplay();
4725 void wxDataViewCtrl
::OnColumnsCountChanged()
4728 m_headerArea
->SetColumnCount(GetColumnCount());
4730 m_clientArea
->OnColumnsCountChanged();
4733 void wxDataViewCtrl
::DoSetExpanderColumn()
4735 m_clientArea
->UpdateDisplay();
4738 void wxDataViewCtrl
::DoSetIndent()
4740 m_clientArea
->UpdateDisplay();
4743 unsigned int wxDataViewCtrl
::GetColumnCount() const
4745 return m_cols
.GetCount();
4748 bool wxDataViewCtrl
::SetRowHeight( int lineHeight
)
4750 if ( !m_clientArea
)
4753 m_clientArea
->SetRowHeight(lineHeight
);
4758 wxDataViewColumn
* wxDataViewCtrl
::GetColumn( unsigned int idx
) const
4763 wxDataViewColumn
*wxDataViewCtrl
::GetColumnAt(unsigned int pos
) const
4765 // columns can't be reordered if there is no header window which allows
4767 const unsigned idx
= m_headerArea ? m_headerArea
->GetColumnsOrder()[pos
]
4770 return GetColumn(idx
);
4773 int wxDataViewCtrl
::GetColumnIndex(const wxDataViewColumn
*column
) const
4775 const unsigned count
= m_cols
.size();
4776 for ( unsigned n
= 0; n
< count
; n
++ )
4778 if ( m_cols
[n
] == column
)
4785 unsigned int wxDataViewCtrl
::GetBestColumnWidth(int idx
) const
4787 if ( m_colsBestWidths
[idx
].width
!= 0 )
4788 return m_colsBestWidths
[idx
].width
;
4790 const int count
= m_clientArea
->GetRowCount();
4791 wxDataViewColumn
*column
= GetColumn(idx
);
4792 wxDataViewRenderer
*renderer
=
4793 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
4795 class MaxWidthCalculator
4798 MaxWidthCalculator(const wxDataViewCtrl
*dvc
,
4799 wxDataViewMainWindow
*clientArea
,
4800 wxDataViewRenderer
*renderer
,
4801 const wxDataViewModel
*model
,
4806 m_clientArea(clientArea
),
4807 m_renderer(renderer
),
4810 m_expanderSize(expanderSize
)
4814 !clientArea
->IsList() &&
4816 GetExpanderColumnOrFirstOne(const_cast<wxDataViewCtrl
*>(dvc
)) == dvc
->GetColumnAt(column
));
4819 void UpdateWithWidth(int width
)
4821 m_width
= wxMax(m_width
, width
);
4824 void UpdateWithRow(int row
)
4827 wxDataViewItem item
;
4829 if ( m_isExpanderCol
)
4831 wxDataViewTreeNode
*node
= m_clientArea
->GetTreeNodeByRow(row
);
4832 item
= node
->GetItem();
4833 indent
= m_dvc
->GetIndent() * node
->GetIndentLevel() + m_expanderSize
;
4837 item
= m_clientArea
->GetItemByRow(row
);
4840 m_renderer
->PrepareForItem(m_model
, item
, m_column
);
4841 m_width
= wxMax(m_width
, m_renderer
->GetSize().x
+ indent
);
4844 int GetMaxWidth() const { return m_width
; }
4848 const wxDataViewCtrl
*m_dvc
;
4849 wxDataViewMainWindow
*m_clientArea
;
4850 wxDataViewRenderer
*m_renderer
;
4851 const wxDataViewModel
*m_model
;
4853 bool m_isExpanderCol
;
4857 MaxWidthCalculator
calculator(this, m_clientArea
, renderer
,
4858 GetModel(), column
->GetModelColumn(),
4859 m_clientArea
->GetRowHeight());
4861 calculator
.UpdateWithWidth(column
->GetMinWidth());
4864 calculator
.UpdateWithWidth(m_headerArea
->GetColumnTitleWidth(*column
));
4866 // The code below deserves some explanation. For very large controls, we
4867 // simply can't afford to calculate sizes for all items, it takes too
4868 // long. So the best we can do is to check the first and the last N/2
4869 // items in the control for some sufficiently large N and calculate best
4870 // sizes from that. That can result in the calculated best width being too
4871 // small for some outliers, but it's better to get slightly imperfect
4872 // result than to wait several seconds after every update. To avoid highly
4873 // visible miscalculations, we also include all currently visible items
4874 // no matter what. Finally, the value of N is determined dynamically by
4875 // measuring how much time we spent on the determining item widths so far.
4878 int top_part_end
= count
;
4879 static const long CALC_TIMEOUT
= 20/*ms*/;
4880 // don't call wxStopWatch::Time() too often
4881 static const unsigned CALC_CHECK_FREQ
= 100;
4884 // use some hard-coded limit, that's the best we can do without timer
4885 int top_part_end
= wxMin(500, count
);
4886 #endif // wxUSE_STOPWATCH/!wxUSE_STOPWATCH
4890 for ( row
= 0; row
< top_part_end
; row
++ )
4893 if ( row
% CALC_CHECK_FREQ
== CALC_CHECK_FREQ
-1 &&
4894 timer
.Time() > CALC_TIMEOUT
)
4896 #endif // wxUSE_STOPWATCH
4897 calculator
.UpdateWithRow(row
);
4900 // row is the first unmeasured item now; that's our value of N/2
4906 // add bottom N/2 items now:
4907 const int bottom_part_start
= wxMax(row
, count
- row
);
4908 for ( row
= bottom_part_start
; row
< count
; row
++ )
4910 calculator
.UpdateWithRow(row
);
4913 // finally, include currently visible items in the calculation:
4914 const wxPoint origin
= CalcUnscrolledPosition(wxPoint(0, 0));
4915 int first_visible
= m_clientArea
->GetLineAt(origin
.y
);
4916 int last_visible
= m_clientArea
->GetLineAt(origin
.y
+ GetClientSize().y
);
4918 first_visible
= wxMax(first_visible
, top_part_end
);
4919 last_visible
= wxMin(bottom_part_start
, last_visible
);
4921 for ( row
= first_visible
; row
< last_visible
; row
++ )
4923 calculator
.UpdateWithRow(row
);
4926 wxLogTrace("dataview",
4927 "determined best size from %d top, %d bottom plus %d more visible items out of %d total",
4929 count
- bottom_part_start
,
4930 wxMax(0, last_visible
- first_visible
),
4934 int max_width
= calculator
.GetMaxWidth();
4935 if ( max_width
> 0 )
4936 max_width
+= 2 * PADDING_RIGHTLEFT
;
4938 const_cast<wxDataViewCtrl
*>(this)->m_colsBestWidths
[idx
].width
= max_width
;
4942 void wxDataViewCtrl
::ColumnMoved(wxDataViewColumn
* WXUNUSED(col
),
4943 unsigned int WXUNUSED(new_pos
))
4945 // do _not_ reorder m_cols elements here, they should always be in the
4946 // order in which columns were added, we only display the columns in
4948 m_clientArea
->UpdateDisplay();
4951 bool wxDataViewCtrl
::DeleteColumn( wxDataViewColumn
*column
)
4953 wxDataViewColumnList
::compatibility_iterator ret
= m_cols
.Find( column
);
4957 m_colsBestWidths
.erase(m_colsBestWidths
.begin() + GetColumnIndex(column
));
4960 if ( m_clientArea
->GetCurrentColumn() == column
)
4961 m_clientArea
->ClearCurrentColumn();
4963 OnColumnsCountChanged();
4968 bool wxDataViewCtrl
::ClearColumns()
4970 SetExpanderColumn(NULL
);
4972 m_colsBestWidths
.clear();
4974 m_clientArea
->ClearCurrentColumn();
4976 OnColumnsCountChanged();
4981 void wxDataViewCtrl
::InvalidateColBestWidth(int idx
)
4983 m_colsBestWidths
[idx
].width
= 0;
4984 m_colsBestWidths
[idx
].dirty
= true;
4988 void wxDataViewCtrl
::InvalidateColBestWidths()
4990 // mark all columns as dirty:
4991 m_colsBestWidths
.clear();
4992 m_colsBestWidths
.resize(m_cols
.size());
4996 void wxDataViewCtrl
::UpdateColWidths()
4998 m_colsDirty
= false;
5000 if ( !m_headerArea
)
5003 const unsigned len
= m_colsBestWidths
.size();
5004 for ( unsigned i
= 0; i
< len
; i
++ )
5006 // Note that we have to have an explicit 'dirty' flag here instead of
5007 // checking if the width==0, as is done in GetBestColumnWidth().
5009 // Testing width==0 wouldn't work correctly if some code called
5010 // GetWidth() after col. width invalidation but before
5011 // wxDataViewCtrl::UpdateColWidths() was called at idle time. This
5012 // would result in the header's column width getting out of sync with
5013 // the control itself.
5014 if ( m_colsBestWidths
[i
].dirty
)
5016 m_headerArea
->UpdateColumn(i
);
5017 m_colsBestWidths
[i
].dirty
= false;
5022 void wxDataViewCtrl
::OnInternalIdle()
5024 wxDataViewCtrlBase
::OnInternalIdle();
5030 int wxDataViewCtrl
::GetColumnPosition( const wxDataViewColumn
*column
) const
5032 unsigned int len
= GetColumnCount();
5033 for ( unsigned int i
= 0; i
< len
; i
++ )
5035 wxDataViewColumn
* col
= GetColumnAt(i
);
5043 wxDataViewColumn
*wxDataViewCtrl
::GetSortingColumn() const
5045 return m_sortingColumnIdx
== wxNOT_FOUND ? NULL
5046 : GetColumn(m_sortingColumnIdx
);
5049 wxDataViewItem wxDataViewCtrl
::DoGetCurrentItem() const
5051 return GetItemByRow(m_clientArea
->GetCurrentRow());
5054 void wxDataViewCtrl
::DoSetCurrentItem(const wxDataViewItem
& item
)
5056 const int row
= m_clientArea
->GetRowByItem(item
);
5058 const unsigned oldCurrent
= m_clientArea
->GetCurrentRow();
5059 if ( static_cast<unsigned>(row
) != oldCurrent
)
5061 m_clientArea
->ChangeCurrentRow(row
);
5062 m_clientArea
->RefreshRow(oldCurrent
);
5063 m_clientArea
->RefreshRow(row
);
5067 wxDataViewColumn
*wxDataViewCtrl
::GetCurrentColumn() const
5069 return m_clientArea
->GetCurrentColumn();
5072 int wxDataViewCtrl
::GetSelectedItemsCount() const
5074 return m_clientArea
->GetSelections().size();
5077 int wxDataViewCtrl
::GetSelections( wxDataViewItemArray
& sel
) const
5080 const wxDataViewSelection
& selections
= m_clientArea
->GetSelections();
5082 const size_t len
= selections
.size();
5083 for ( size_t i
= 0; i
< len
; i
++ )
5085 wxDataViewItem item
= m_clientArea
->GetItemByRow(selections
[i
]);
5092 wxFAIL_MSG( "invalid item in selection - bad internal state" );
5099 void wxDataViewCtrl
::SetSelections( const wxDataViewItemArray
& sel
)
5101 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
5103 wxDataViewItem last_parent
;
5105 int len
= sel
.GetCount();
5106 for( int i
= 0; i
< len
; i
++ )
5108 wxDataViewItem item
= sel
[i
];
5109 wxDataViewItem parent
= GetModel()->GetParent( item
);
5112 if (parent
!= last_parent
)
5113 ExpandAncestors(item
);
5116 last_parent
= parent
;
5117 int row
= m_clientArea
->GetRowByItem( item
);
5119 selection
.Add( static_cast<unsigned int>(row
) );
5122 m_clientArea
->SetSelections( selection
);
5125 void wxDataViewCtrl
::Select( const wxDataViewItem
& item
)
5127 ExpandAncestors( item
);
5129 int row
= m_clientArea
->GetRowByItem( item
);
5132 // Unselect all rows before select another in the single select mode
5133 if (m_clientArea
->IsSingleSel())
5134 m_clientArea
->SelectAllRows(false);
5136 m_clientArea
->SelectRow(row
, true);
5138 // Also set focus to the selected item
5139 m_clientArea
->ChangeCurrentRow( row
);
5143 void wxDataViewCtrl
::Unselect( const wxDataViewItem
& item
)
5145 int row
= m_clientArea
->GetRowByItem( item
);
5147 m_clientArea
->SelectRow(row
, false);
5150 bool wxDataViewCtrl
::IsSelected( const wxDataViewItem
& item
) const
5152 int row
= m_clientArea
->GetRowByItem( item
);
5155 return m_clientArea
->IsRowSelected(row
);
5160 void wxDataViewCtrl
::SetAlternateRowColour(const wxColour
& colour
)
5162 m_alternateRowColour
= colour
;
5165 void wxDataViewCtrl
::SelectAll()
5167 m_clientArea
->SelectAllRows(true);
5170 void wxDataViewCtrl
::UnselectAll()
5172 m_clientArea
->SelectAllRows(false);
5175 void wxDataViewCtrl
::EnsureVisible( int row
, int column
)
5179 if( row
> (int) m_clientArea
->GetRowCount() )
5180 row
= m_clientArea
->GetRowCount();
5182 int first
= m_clientArea
->GetFirstVisibleRow();
5183 int last
= m_clientArea
->GetLastVisibleRow();
5185 m_clientArea
->ScrollTo( row
, column
);
5186 else if( row
> last
)
5187 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
5189 m_clientArea
->ScrollTo( first
, column
);
5192 void wxDataViewCtrl
::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
5194 ExpandAncestors( item
);
5196 m_clientArea
->RecalculateDisplay();
5198 int row
= m_clientArea
->GetRowByItem(item
);
5201 if( column
== NULL
)
5202 EnsureVisible(row
, -1);
5204 EnsureVisible( row
, GetColumnIndex(column
) );
5209 void wxDataViewCtrl
::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
5210 wxDataViewColumn
* &column
) const
5212 m_clientArea
->HitTest(point
, item
, column
);
5215 wxRect wxDataViewCtrl
::GetItemRect( const wxDataViewItem
& item
,
5216 const wxDataViewColumn
* column
) const
5218 return m_clientArea
->GetItemRect(item
, column
);
5221 wxDataViewItem wxDataViewCtrl
::GetItemByRow( unsigned int row
) const
5223 return m_clientArea
->GetItemByRow( row
);
5226 int wxDataViewCtrl
::GetRowByItem( const wxDataViewItem
& item
) const
5228 return m_clientArea
->GetRowByItem( item
);
5231 void wxDataViewCtrl
::Expand( const wxDataViewItem
& item
)
5233 ExpandAncestors( item
);
5235 int row
= m_clientArea
->GetRowByItem( item
);
5238 m_clientArea
->Expand(row
);
5239 InvalidateColBestWidths();
5243 void wxDataViewCtrl
::Collapse( const wxDataViewItem
& item
)
5245 int row
= m_clientArea
->GetRowByItem( item
);
5248 m_clientArea
->Collapse(row
);
5249 InvalidateColBestWidths();
5253 bool wxDataViewCtrl
::IsExpanded( const wxDataViewItem
& item
) const
5255 int row
= m_clientArea
->GetRowByItem( item
);
5257 return m_clientArea
->IsExpanded(row
);
5261 void wxDataViewCtrl
::EditItem(const wxDataViewItem
& item
, const wxDataViewColumn
*column
)
5263 wxCHECK_RET( item
.IsOk(), "invalid item" );
5264 wxCHECK_RET( column
, "no column provided" );
5266 m_clientArea
->StartEditing(item
, column
);
5269 #endif // !wxUSE_GENERICDATAVIEWCTRL
5271 #endif // wxUSE_DATAVIEWCTRL