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
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
17 #if wxUSE_DATAVIEWCTRL
19 #include "wx/dataview.h"
21 #ifdef wxUSE_GENERICDATAVIEWCTRL
25 #include "wx/msw/private.h"
26 #include "wx/msw/wrapwin.h"
27 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
31 #include "wx/dcclient.h"
33 #include "wx/settings.h"
34 #include "wx/msgdlg.h"
35 #include "wx/dcscreen.h"
39 #include "wx/stockitem.h"
40 #include "wx/popupwin.h"
41 #include "wx/renderer.h"
42 #include "wx/dcbuffer.h"
45 #include "wx/listimpl.cpp"
46 #include "wx/imaglist.h"
47 #include "wx/headerctrl.h"
49 #include "wx/stopwatch.h"
50 #include "wx/weakref.h"
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
56 class wxDataViewColumn
;
57 class wxDataViewHeaderWindow
;
60 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
64 static const int SCROLL_UNIT_X
= 15;
66 // the cell padding on the left/right
67 static const int PADDING_RIGHTLEFT
= 3;
69 // the expander space margin
70 static const int EXPANDER_MARGIN
= 4;
73 static const int EXPANDER_OFFSET
= 4;
75 static const int EXPANDER_OFFSET
= 1;
78 // Below is the compare stuff.
79 // For the generic implementation, both the leaf nodes and the nodes are sorted for
80 // fast search when needed
81 static wxDataViewModel
* g_model
;
83 // The column is either the index of the column to be used for sorting or one
84 // of the special values in this enum:
87 // Sort when we're thawed later.
88 SortColumn_OnThaw
= -3,
93 // Sort using the model default sort order.
94 SortColumn_Default
= -1
97 static int g_column
= SortColumn_None
;
98 static bool g_asending
= true;
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
107 // Return the expander column or, if it is not set, the first column and also
108 // set it as the expander one for the future.
109 wxDataViewColumn
* GetExpanderColumnOrFirstOne(wxDataViewCtrl
* dataview
)
111 wxDataViewColumn
* expander
= dataview
->GetExpanderColumn();
114 // TODO-RTL: last column for RTL support
115 expander
= dataview
->GetColumnAt( 0 );
116 dataview
->SetExpanderColumn(expander
);
122 } // anonymous namespace
124 //-----------------------------------------------------------------------------
126 //-----------------------------------------------------------------------------
128 void wxDataViewColumn::Init(int width
, wxAlignment align
, int flags
)
135 m_sortAscending
= true;
138 int wxDataViewColumn::GetWidth() const
142 case wxCOL_WIDTH_DEFAULT
:
143 return wxDVC_DEFAULT_WIDTH
;
145 case wxCOL_WIDTH_AUTOSIZE
:
146 wxCHECK_MSG( m_owner
, wxDVC_DEFAULT_WIDTH
, "no owner control" );
147 return m_owner
->GetBestColumnWidth(m_owner
->GetColumnIndex(this));
154 void wxDataViewColumn::UpdateDisplay()
158 int idx
= m_owner
->GetColumnIndex( this );
159 m_owner
->OnColumnChange( idx
);
163 void wxDataViewColumn::UnsetAsSortKey()
168 m_owner
->SetSortingColumnIndex(wxNOT_FOUND
);
173 void wxDataViewColumn::SetSortOrder(bool ascending
)
178 // First unset the old sort column if any.
179 int oldSortKey
= m_owner
->GetSortingColumnIndex();
180 if ( oldSortKey
!= wxNOT_FOUND
)
182 m_owner
->GetColumn(oldSortKey
)->UnsetAsSortKey();
185 // Now set this one as the new sort column.
186 const int idx
= m_owner
->GetColumnIndex(this);
187 m_owner
->SetSortingColumnIndex(idx
);
190 m_sortAscending
= ascending
;
192 // Call this directly instead of using UpdateDisplay() as we already have
193 // the column index, no need to look it up again.
194 m_owner
->OnColumnChange(idx
);
197 //-----------------------------------------------------------------------------
198 // wxDataViewHeaderWindow
199 //-----------------------------------------------------------------------------
201 class wxDataViewHeaderWindow
: public wxHeaderCtrl
204 wxDataViewHeaderWindow(wxDataViewCtrl
*parent
)
205 : wxHeaderCtrl(parent
)
209 wxDataViewCtrl
*GetOwner() const
210 { return static_cast<wxDataViewCtrl
*>(GetParent()); }
213 // implement/override wxHeaderCtrl functions by forwarding them to the main
215 virtual const wxHeaderColumn
& GetColumn(unsigned int idx
) const
217 return *(GetOwner()->GetColumn(idx
));
220 virtual bool UpdateColumnWidthToFit(unsigned int idx
, int widthTitle
)
222 wxDataViewCtrl
* const owner
= GetOwner();
224 int widthContents
= owner
->GetBestColumnWidth(idx
);
225 owner
->GetColumn(idx
)->SetWidth(wxMax(widthTitle
, widthContents
));
226 owner
->OnColumnChange(idx
);
232 bool SendEvent(wxEventType type
, unsigned int n
)
234 wxDataViewCtrl
* const owner
= GetOwner();
235 wxDataViewEvent
event(type
, owner
->GetId());
237 event
.SetEventObject(owner
);
239 event
.SetDataViewColumn(owner
->GetColumn(n
));
240 event
.SetModel(owner
->GetModel());
242 // for events created by wxDataViewHeaderWindow the
243 // row / value fields are not valid
244 return owner
->ProcessWindowEvent(event
);
247 void OnClick(wxHeaderCtrlEvent
& event
)
249 const unsigned idx
= event
.GetColumn();
251 if ( SendEvent(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK
, idx
) )
254 // default handling for the column click is to sort by this column or
255 // toggle its sort order
256 wxDataViewCtrl
* const owner
= GetOwner();
257 wxDataViewColumn
* const col
= owner
->GetColumn(idx
);
258 if ( !col
->IsSortable() )
260 // no default handling for non-sortable columns
265 if ( col
->IsSortKey() )
267 // already using this column for sorting, just change the order
268 col
->ToggleSortOrder();
270 else // not using this column for sorting yet
272 col
->SetSortOrder(true);
275 wxDataViewModel
* const model
= owner
->GetModel();
279 owner
->OnColumnChange(idx
);
281 SendEvent(wxEVT_DATAVIEW_COLUMN_SORTED
, idx
);
284 void OnRClick(wxHeaderCtrlEvent
& event
)
286 if ( !SendEvent(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
291 void OnResize(wxHeaderCtrlEvent
& event
)
293 wxDataViewCtrl
* const owner
= GetOwner();
295 const unsigned col
= event
.GetColumn();
296 owner
->GetColumn(col
)->SetWidth(event
.GetWidth());
297 GetOwner()->OnColumnChange(col
);
300 void OnEndReorder(wxHeaderCtrlEvent
& event
)
302 wxDataViewCtrl
* const owner
= GetOwner();
303 owner
->ColumnMoved(owner
->GetColumn(event
.GetColumn()),
304 event
.GetNewOrder());
307 DECLARE_EVENT_TABLE()
308 wxDECLARE_NO_COPY_CLASS(wxDataViewHeaderWindow
);
311 BEGIN_EVENT_TABLE(wxDataViewHeaderWindow
, wxHeaderCtrl
)
312 EVT_HEADER_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnClick
)
313 EVT_HEADER_RIGHT_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnRClick
)
315 EVT_HEADER_RESIZING(wxID_ANY
, wxDataViewHeaderWindow::OnResize
)
316 EVT_HEADER_END_RESIZE(wxID_ANY
, wxDataViewHeaderWindow::OnResize
)
318 EVT_HEADER_END_REORDER(wxID_ANY
, wxDataViewHeaderWindow::OnEndReorder
)
321 //-----------------------------------------------------------------------------
322 // wxDataViewRenameTimer
323 //-----------------------------------------------------------------------------
325 class wxDataViewRenameTimer
: public wxTimer
328 wxDataViewMainWindow
*m_owner
;
331 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
335 //-----------------------------------------------------------------------------
336 // wxDataViewTreeNode
337 //-----------------------------------------------------------------------------
339 class wxDataViewTreeNode
;
340 WX_DEFINE_ARRAY( wxDataViewTreeNode
*, wxDataViewTreeNodes
);
342 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
,
343 wxDataViewTreeNode
** node2
);
345 class wxDataViewTreeNode
348 wxDataViewTreeNode(wxDataViewTreeNode
*parent
, const wxDataViewItem
& item
)
355 ~wxDataViewTreeNode()
359 wxDataViewTreeNodes
& nodes
= m_branchData
->children
;
360 for ( wxDataViewTreeNodes::iterator i
= nodes
.begin();
371 static wxDataViewTreeNode
* CreateRootNode()
373 wxDataViewTreeNode
*n
= new wxDataViewTreeNode(NULL
, wxDataViewItem());
374 n
->m_branchData
= new BranchNodeData
;
375 n
->m_branchData
->open
= true;
379 wxDataViewTreeNode
* GetParent() const { return m_parent
; }
381 const wxDataViewTreeNodes
& GetChildNodes() const
383 wxASSERT( m_branchData
!= NULL
);
384 return m_branchData
->children
;
387 void InsertChild(wxDataViewTreeNode
*node
, unsigned index
)
390 m_branchData
= new BranchNodeData
;
392 m_branchData
->children
.Insert(node
, index
);
394 // TODO: insert into sorted array directly in O(log n) instead of resorting in O(n log n)
396 m_branchData
->children
.Sort( &wxGenericTreeModelNodeCmp
);
399 void RemoveChild(wxDataViewTreeNode
*node
)
401 wxCHECK_RET( m_branchData
!= NULL
, "leaf node doesn't have children" );
402 m_branchData
->children
.Remove(node
);
405 // returns position of child node for given item in children list or wxNOT_FOUND
406 int FindChildByItem(const wxDataViewItem
& item
) const
411 const wxDataViewTreeNodes
& nodes
= m_branchData
->children
;
412 const int len
= nodes
.size();
413 for ( int i
= 0; i
< len
; i
++ )
415 if ( nodes
[i
]->m_item
== item
)
421 const wxDataViewItem
& GetItem() const { return m_item
; }
422 void SetItem( const wxDataViewItem
& item
) { m_item
= item
; }
424 int GetIndentLevel() const
427 const wxDataViewTreeNode
* node
= this;
428 while( node
->GetParent()->GetParent() != NULL
)
430 node
= node
->GetParent();
438 return m_branchData
&& m_branchData
->open
;
443 // We do not allow the (invisible) root node to be collapsed because
444 // there is no way to expand it again.
448 wxCHECK_RET( m_branchData
!= NULL
, "can't open leaf node" );
452 const wxDataViewTreeNodes
& nodes
= m_branchData
->children
;
453 const int len
= nodes
.GetCount();
454 for ( int i
= 0;i
< len
; i
++)
455 sum
+= 1 + nodes
[i
]->GetSubTreeCount();
457 if (m_branchData
->open
)
459 ChangeSubTreeCount(-sum
);
460 m_branchData
->open
= !m_branchData
->open
;
464 m_branchData
->open
= !m_branchData
->open
;
465 ChangeSubTreeCount(+sum
);
469 // "HasChildren" property corresponds to model's IsContainer(). Note that it may be true
470 // even if GetChildNodes() is empty; see below.
471 bool HasChildren() const
473 return m_branchData
!= NULL
;
476 void SetHasChildren(bool has
)
478 // The invisible root item always has children, so ignore any attempts
485 wxDELETE(m_branchData
);
487 else if ( m_branchData
== NULL
)
489 m_branchData
= new BranchNodeData
;
493 int GetSubTreeCount() const
495 return m_branchData
? m_branchData
->subTreeCount
: 0;
498 void ChangeSubTreeCount( int num
)
500 wxASSERT( m_branchData
!= NULL
);
502 if( !m_branchData
->open
)
505 m_branchData
->subTreeCount
+= num
;
506 wxASSERT( m_branchData
->subTreeCount
>= 0 );
509 m_parent
->ChangeSubTreeCount(num
);
519 wxDataViewTreeNodes
& nodes
= m_branchData
->children
;
521 nodes
.Sort( &wxGenericTreeModelNodeCmp
);
522 int len
= nodes
.GetCount();
523 for (int i
= 0; i
< len
; i
++)
525 if ( nodes
[i
]->HasChildren() )
533 wxDataViewTreeNode
*m_parent
;
535 // Corresponding model item.
536 wxDataViewItem m_item
;
538 // Data specific to non-leaf (branch, inner) nodes. They are kept in a
539 // separate struct in order to conserve memory.
540 struct BranchNodeData
548 // Child nodes. Note that this may be empty even if m_hasChildren in
549 // case this branch of the tree wasn't expanded and realized yet.
550 wxDataViewTreeNodes children
;
552 // Is the branch node currently open (expanded)?
555 // Total count of expanded (i.e. visible with the help of some
556 // scrolling) items in the subtree, but excluding this node. I.e. it is
557 // 0 for leaves and is the number of rows the subtree occupies for
562 BranchNodeData
*m_branchData
;
566 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
,
567 wxDataViewTreeNode
** node2
)
569 return g_model
->Compare( (*node1
)->GetItem(), (*node2
)->GetItem(), g_column
, g_asending
);
573 //-----------------------------------------------------------------------------
574 // wxDataViewMainWindow
575 //-----------------------------------------------------------------------------
577 WX_DEFINE_SORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
);
579 class wxDataViewMainWindow
: public wxWindow
582 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
584 const wxPoint
&pos
= wxDefaultPosition
,
585 const wxSize
&size
= wxDefaultSize
,
586 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
587 virtual ~wxDataViewMainWindow();
589 bool IsList() const { return GetModel()->IsListModel(); }
590 bool IsVirtualList() const { return m_root
== NULL
; }
592 // notifications from wxDataViewModel
593 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
594 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
595 bool ItemChanged( const wxDataViewItem
&item
);
596 bool ValueChanged( const wxDataViewItem
&item
, unsigned int model_column
);
600 if (!IsVirtualList())
608 // Override the base class method to resort if needed, i.e. if
609 // SortPrepare() was called -- and ignored -- while we were frozen.
610 virtual void DoThaw()
612 if ( g_column
== SortColumn_OnThaw
)
615 g_column
= SortColumn_None
;
623 g_model
= GetModel();
625 wxDataViewColumn
* col
= GetOwner()->GetSortingColumn();
628 if (g_model
->HasDefaultCompare())
630 // See below for the explanation of IsFrozen() test.
632 g_column
= SortColumn_OnThaw
;
634 g_column
= SortColumn_Default
;
637 g_column
= SortColumn_None
;
643 // Avoid sorting while the window is frozen, this allows to quickly add
644 // many items without resorting after each addition and only resort
645 // them all at once when the window is finally thawed, see above.
648 g_column
= SortColumn_OnThaw
;
652 g_column
= col
->GetModelColumn();
653 g_asending
= col
->IsSortOrderAscending();
656 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
657 wxDataViewCtrl
*GetOwner() { return m_owner
; }
658 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
660 wxDataViewModel
* GetModel() { return GetOwner()->GetModel(); }
661 const wxDataViewModel
* GetModel() const { return GetOwner()->GetModel(); }
663 #if wxUSE_DRAG_AND_DROP
664 wxBitmap
CreateItemBitmap( unsigned int row
, int &indent
);
665 #endif // wxUSE_DRAG_AND_DROP
666 void OnPaint( wxPaintEvent
&event
);
667 void OnCharHook( wxKeyEvent
&event
);
668 void OnChar( wxKeyEvent
&event
);
669 void OnVerticalNavigation(int delta
, const wxKeyEvent
& event
);
672 void OnMouse( wxMouseEvent
&event
);
673 void OnSetFocus( wxFocusEvent
&event
);
674 void OnKillFocus( wxFocusEvent
&event
);
676 void UpdateDisplay();
677 void RecalculateDisplay();
678 void OnInternalIdle();
680 void OnRenameTimer();
682 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
683 void ScrollTo( int rows
, int column
);
685 unsigned GetCurrentRow() const { return m_currentRow
; }
686 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
687 void ChangeCurrentRow( unsigned int row
);
688 bool TryAdvanceCurrentColumn(wxDataViewTreeNode
*node
, bool forward
);
690 wxDataViewColumn
*GetCurrentColumn() const { return m_currentCol
; }
691 void ClearCurrentColumn() { m_currentCol
= NULL
; }
693 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
694 bool IsEmpty() { return GetRowCount() == 0; }
696 int GetCountPerPage() const;
697 int GetEndOfLastCol() const;
698 unsigned int GetFirstVisibleRow() const;
700 // I change this method to un const because in the tree view,
701 // the displaying number of the tree are changing along with the
702 // expanding/collapsing of the tree nodes
703 unsigned int GetLastVisibleRow();
704 unsigned int GetRowCount() const;
706 const wxDataViewSelection
& GetSelections() const { return m_selection
; }
707 void SetSelections( const wxDataViewSelection
& sel
)
708 { m_selection
= sel
; UpdateDisplay(); }
709 void Select( const wxArrayInt
& aSelections
);
710 void SelectAllRows( bool on
);
711 void SelectRow( unsigned int row
, bool on
);
712 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
713 void ReverseRowSelection( unsigned int row
);
714 bool IsRowSelected( unsigned int row
);
715 void SendSelectionChangedEvent( const wxDataViewItem
& item
);
717 void RefreshRow( unsigned int row
);
718 void RefreshRows( unsigned int from
, unsigned int to
);
719 void RefreshRowsAfter( unsigned int firstRow
);
721 // returns the colour to be used for drawing the rules
722 wxColour
GetRuleColour() const
724 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
727 wxRect
GetLineRect( unsigned int row
) const;
729 int GetLineStart( unsigned int row
) const; // row * m_lineHeight in fixed mode
730 int GetLineHeight( unsigned int row
) const; // m_lineHeight in fixed mode
731 int GetLineAt( unsigned int y
) const; // y / m_lineHeight in fixed mode
733 void SetRowHeight( int lineHeight
) { m_lineHeight
= lineHeight
; }
734 int GetRowHeight() const { return m_lineHeight
; }
735 int GetDefaultRowHeight() const;
737 // Some useful functions for row and item mapping
738 wxDataViewItem
GetItemByRow( unsigned int row
) const;
739 int GetRowByItem( const wxDataViewItem
& item
) const;
741 wxDataViewTreeNode
* GetTreeNodeByRow( unsigned int row
) const;
742 // We did not need this temporarily
743 // wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
745 // Methods for building the mapping tree
746 void BuildTree( wxDataViewModel
* model
);
748 void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
);
749 wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
);
751 void Expand( unsigned int row
);
752 void Collapse( unsigned int row
);
753 bool IsExpanded( unsigned int row
) const;
754 bool HasChildren( unsigned int row
) const;
756 #if wxUSE_DRAG_AND_DROP
757 bool EnableDragSource( const wxDataFormat
&format
);
758 bool EnableDropTarget( const wxDataFormat
&format
);
760 void RemoveDropHint();
761 wxDragResult
OnDragOver( wxDataFormat format
, wxCoord x
, wxCoord y
, wxDragResult def
);
762 bool OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
);
763 wxDragResult
OnData( wxDataFormat format
, wxCoord x
, wxCoord y
, wxDragResult def
);
765 #endif // wxUSE_DRAG_AND_DROP
767 void OnColumnsCountChanged();
769 // Called by wxDataViewCtrl and our own OnRenameTimer() to start edit the
770 // specified item in the given column.
771 void StartEditing(const wxDataViewItem
& item
, const wxDataViewColumn
* col
);
774 int RecalculateCount() const;
776 // Return false only if the event was vetoed by its handler.
777 bool SendExpanderEvent(wxEventType type
, const wxDataViewItem
& item
);
779 wxDataViewTreeNode
* FindNode( const wxDataViewItem
& item
);
781 wxDataViewColumn
*FindColumnForEditing(const wxDataViewItem
& item
, wxDataViewCellMode mode
);
783 bool IsCellEditableInMode(const wxDataViewItem
& item
, const wxDataViewColumn
*col
, wxDataViewCellMode mode
) const;
785 void DrawCellBackground( wxDataViewRenderer
* cell
, wxDC
& dc
, const wxRect
& rect
);
788 wxDataViewCtrl
*m_owner
;
792 wxDataViewColumn
*m_currentCol
;
793 unsigned int m_currentRow
;
794 wxDataViewSelection m_selection
;
796 wxDataViewRenameTimer
*m_renameTimer
;
801 bool m_currentColSetByKeyboard
;
803 #if wxUSE_DRAG_AND_DROP
808 wxDataFormat m_dragFormat
;
811 wxDataFormat m_dropFormat
;
813 unsigned int m_dropHintLine
;
814 #endif // wxUSE_DRAG_AND_DROP
816 // for double click logic
817 unsigned int m_lineLastClicked
,
818 m_lineBeforeLastClicked
,
819 m_lineSelectSingleOnUp
;
821 // the pen used to draw horiz/vertical rules
824 // the pen used to draw the expander and the lines
827 // This is the tree structure of the model
828 wxDataViewTreeNode
* m_root
;
831 // This is the tree node under the cursor
832 wxDataViewTreeNode
* m_underMouse
;
834 // The control used for editing or NULL.
835 wxWeakRef
<wxWindow
> m_editorCtrl
;
837 // Id m_editorCtrl is non-NULL, pointer to the associated renderer.
838 wxDataViewRenderer
* m_editorRenderer
;
841 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
842 DECLARE_EVENT_TABLE()
845 // ---------------------------------------------------------
846 // wxGenericDataViewModelNotifier
847 // ---------------------------------------------------------
849 class wxGenericDataViewModelNotifier
: public wxDataViewModelNotifier
852 wxGenericDataViewModelNotifier( wxDataViewMainWindow
*mainWindow
)
853 { m_mainWindow
= mainWindow
; }
855 virtual bool ItemAdded( const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
856 { return m_mainWindow
->ItemAdded( parent
, item
); }
857 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
858 { return m_mainWindow
->ItemDeleted( parent
, item
); }
859 virtual bool ItemChanged( const wxDataViewItem
& item
)
860 { return m_mainWindow
->ItemChanged(item
); }
861 virtual bool ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
862 { return m_mainWindow
->ValueChanged( item
, col
); }
863 virtual bool Cleared()
864 { return m_mainWindow
->Cleared(); }
865 virtual void Resort()
866 { m_mainWindow
->Resort(); }
868 wxDataViewMainWindow
*m_mainWindow
;
871 // ---------------------------------------------------------
872 // wxDataViewRenderer
873 // ---------------------------------------------------------
875 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
877 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
878 wxDataViewCellMode mode
,
880 wxDataViewCustomRendererBase( varianttype
, mode
, align
)
884 m_ellipsizeMode
= wxELLIPSIZE_MIDDLE
;
888 wxDataViewRenderer::~wxDataViewRenderer()
893 wxDC
*wxDataViewRenderer::GetDC()
897 if (GetOwner() == NULL
)
899 if (GetOwner()->GetOwner() == NULL
)
901 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
907 void wxDataViewRenderer::SetAlignment( int align
)
912 int wxDataViewRenderer::GetAlignment() const
917 // ---------------------------------------------------------
918 // wxDataViewCustomRenderer
919 // ---------------------------------------------------------
921 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
923 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
924 wxDataViewCellMode mode
, int align
) :
925 wxDataViewRenderer( varianttype
, mode
, align
)
929 // ---------------------------------------------------------
930 // wxDataViewTextRenderer
931 // ---------------------------------------------------------
933 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
935 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
936 wxDataViewCellMode mode
, int align
) :
937 wxDataViewRenderer( varianttype
, mode
, align
)
941 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
943 m_text
= value
.GetString();
948 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
953 bool wxDataViewTextRenderer::HasEditorCtrl() const
958 wxWindow
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
959 wxRect labelRect
, const wxVariant
&value
)
961 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, value
,
962 wxPoint(labelRect
.x
,labelRect
.y
),
963 wxSize(labelRect
.width
,labelRect
.height
),
964 wxTE_PROCESS_ENTER
);
966 // select the text in the control an place the cursor at the end
967 ctrl
->SetInsertionPointEnd();
973 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxWindow
*editor
, wxVariant
&value
)
975 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
976 value
= text
->GetValue();
980 bool wxDataViewTextRenderer::Render(wxRect rect
, wxDC
*dc
, int state
)
982 RenderText(m_text
, 0, rect
, dc
, state
);
986 wxSize
wxDataViewTextRenderer::GetSize() const
989 return GetTextExtent(m_text
);
991 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
994 // ---------------------------------------------------------
995 // wxDataViewBitmapRenderer
996 // ---------------------------------------------------------
998 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1000 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
1001 wxDataViewCellMode mode
, int align
) :
1002 wxDataViewRenderer( varianttype
, mode
, align
)
1006 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1008 if (value
.GetType() == wxT("wxBitmap"))
1010 if (value
.GetType() == wxT("wxIcon"))
1016 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1021 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
1023 if (m_bitmap
.IsOk())
1024 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
, true /* use mask */ );
1025 else if (m_icon
.IsOk())
1026 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
1031 wxSize
wxDataViewBitmapRenderer::GetSize() const
1033 if (m_bitmap
.IsOk())
1034 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
1035 else if (m_icon
.IsOk())
1036 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
1038 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE
,wxDVC_DEFAULT_RENDERER_SIZE
);
1041 // ---------------------------------------------------------
1042 // wxDataViewToggleRenderer
1043 // ---------------------------------------------------------
1045 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1047 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1048 wxDataViewCellMode mode
, int align
) :
1049 wxDataViewRenderer( varianttype
, mode
, align
)
1054 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1056 m_toggle
= value
.GetBool();
1061 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
1066 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
1070 flags
|= wxCONTROL_CHECKED
;
1071 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
||
1072 GetEnabled() == false)
1073 flags
|= wxCONTROL_DISABLED
;
1075 // Ensure that the check boxes always have at least the minimal required
1076 // size, otherwise DrawCheckBox() doesn't really work well. If this size is
1077 // greater than the cell size, the checkbox will be truncated but this is a
1079 wxSize size
= cell
.GetSize();
1080 size
.IncTo(GetSize());
1083 wxRendererNative::Get().DrawCheckBox(
1084 GetOwner()->GetOwner(),
1092 bool wxDataViewToggleRenderer::WXActivateCell(const wxRect
& WXUNUSED(cellRect
),
1093 wxDataViewModel
*model
,
1094 const wxDataViewItem
& item
,
1096 const wxMouseEvent
*mouseEvent
)
1100 // Only react to clicks directly on the checkbox, not elsewhere in the
1102 if ( !wxRect(GetSize()).Contains(mouseEvent
->GetPosition()) )
1106 model
->ChangeValue(!m_toggle
, item
, col
);
1110 wxSize
wxDataViewToggleRenderer::GetSize() const
1112 // the window parameter is not used by GetCheckBoxSize() so it's
1113 // safe to pass NULL
1114 return wxRendererNative::Get().GetCheckBoxSize(NULL
);
1117 // ---------------------------------------------------------
1118 // wxDataViewProgressRenderer
1119 // ---------------------------------------------------------
1121 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewRenderer
)
1123 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1124 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1125 wxDataViewRenderer( varianttype
, mode
, align
)
1131 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1133 m_value
= (long) value
;
1135 if (m_value
< 0) m_value
= 0;
1136 if (m_value
> 100) m_value
= 100;
1141 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
1143 value
= (long) m_value
;
1148 wxDataViewProgressRenderer::Render(wxRect rect
, wxDC
*dc
, int WXUNUSED(state
))
1150 // deflate the rect to leave a small border between bars in adjacent rows
1151 wxRect bar
= rect
.Deflate(0, 1);
1153 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1154 dc
->SetPen( *wxBLACK_PEN
);
1155 dc
->DrawRectangle( bar
);
1157 bar
.width
= (int)(bar
.width
* m_value
/ 100.);
1158 dc
->SetPen( *wxTRANSPARENT_PEN
);
1160 const wxDataViewItemAttr
& attr
= GetAttr();
1161 dc
->SetBrush( attr
.HasColour() ? wxBrush(attr
.GetColour())
1163 dc
->DrawRectangle( bar
);
1168 wxSize
wxDataViewProgressRenderer::GetSize() const
1170 return wxSize(40,12);
1173 // ---------------------------------------------------------
1174 // wxDataViewIconTextRenderer
1175 // ---------------------------------------------------------
1177 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewRenderer
)
1179 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1180 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1181 wxDataViewRenderer( varianttype
, mode
, align
)
1184 SetAlignment(align
);
1187 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1193 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1198 bool wxDataViewIconTextRenderer::Render(wxRect rect
, wxDC
*dc
, int state
)
1202 const wxIcon
& icon
= m_value
.GetIcon();
1205 dc
->DrawIcon(icon
, rect
.x
, rect
.y
+ (rect
.height
- icon
.GetHeight())/2);
1206 xoffset
= icon
.GetWidth()+4;
1209 RenderText(m_value
.GetText(), xoffset
, rect
, dc
, state
);
1214 wxSize
wxDataViewIconTextRenderer::GetSize() const
1216 if (!m_value
.GetText().empty())
1218 wxSize size
= GetTextExtent(m_value
.GetText());
1220 if (m_value
.GetIcon().IsOk())
1221 size
.x
+= m_value
.GetIcon().GetWidth() + 4;
1224 return wxSize(80,20);
1227 wxWindow
* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1229 wxDataViewIconText iconText
;
1232 wxString text
= iconText
.GetText();
1234 // adjust the label rect to take the width of the icon into account
1235 if (iconText
.GetIcon().IsOk())
1237 int w
= iconText
.GetIcon().GetWidth() + 4;
1239 labelRect
.width
-= w
;
1242 wxTextCtrl
* ctrl
= new wxTextCtrl( parent
, wxID_ANY
, text
,
1243 wxPoint(labelRect
.x
,labelRect
.y
),
1244 wxSize(labelRect
.width
,labelRect
.height
),
1245 wxTE_PROCESS_ENTER
);
1247 // select the text in the control an place the cursor at the end
1248 ctrl
->SetInsertionPointEnd();
1254 bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxWindow
*editor
, wxVariant
& value
)
1256 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
1258 // The icon can't be edited so get its old value and reuse it.
1260 wxDataViewColumn
* const col
= GetOwner();
1261 GetView()->GetModel()->GetValue(valueOld
, m_item
, col
->GetModelColumn());
1263 wxDataViewIconText iconText
;
1264 iconText
<< valueOld
;
1266 // But replace the text with the value entered by user.
1267 iconText
.SetText(text
->GetValue());
1273 //-----------------------------------------------------------------------------
1274 // wxDataViewDropTarget
1275 //-----------------------------------------------------------------------------
1277 #if wxUSE_DRAG_AND_DROP
1279 class wxBitmapCanvas
: public wxWindow
1282 wxBitmapCanvas( wxWindow
*parent
, const wxBitmap
&bitmap
, const wxSize
&size
) :
1283 wxWindow( parent
, wxID_ANY
, wxPoint(0,0), size
)
1286 Connect( wxEVT_PAINT
, wxPaintEventHandler(wxBitmapCanvas::OnPaint
) );
1289 void OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1292 dc
.DrawBitmap( m_bitmap
, 0, 0);
1298 class wxDataViewDropSource
: public wxDropSource
1301 wxDataViewDropSource( wxDataViewMainWindow
*win
, unsigned int row
) :
1309 ~wxDataViewDropSource()
1314 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
) )
1316 wxPoint pos
= wxGetMousePosition();
1320 int liney
= m_win
->GetLineStart( m_row
);
1322 m_win
->GetOwner()->CalcUnscrolledPosition( 0, liney
, NULL
, &liney
);
1323 m_win
->ClientToScreen( &linex
, &liney
);
1324 m_dist_x
= pos
.x
- linex
;
1325 m_dist_y
= pos
.y
- liney
;
1328 wxBitmap ib
= m_win
->CreateItemBitmap( m_row
, indent
);
1330 m_hint
= new wxFrame( m_win
->GetParent(), wxID_ANY
, wxEmptyString
,
1331 wxPoint(pos
.x
- m_dist_x
, pos
.y
+ 5 ),
1333 wxFRAME_TOOL_WINDOW
|
1334 wxFRAME_FLOAT_ON_PARENT
|
1335 wxFRAME_NO_TASKBAR
|
1337 new wxBitmapCanvas( m_hint
, ib
, ib
.GetSize() );
1342 m_hint
->Move( pos
.x
- m_dist_x
, pos
.y
+ 5 );
1343 m_hint
->SetTransparent( 128 );
1349 wxDataViewMainWindow
*m_win
;
1352 int m_dist_x
,m_dist_y
;
1356 class wxDataViewDropTarget
: public wxDropTarget
1359 wxDataViewDropTarget( wxDataObject
*obj
, wxDataViewMainWindow
*win
) :
1365 virtual wxDragResult
OnDragOver( wxCoord x
, wxCoord y
, wxDragResult def
)
1367 wxDataFormat format
= GetMatchingPair();
1368 if (format
== wxDF_INVALID
)
1370 return m_win
->OnDragOver( format
, x
, y
, def
);
1373 virtual bool OnDrop( wxCoord x
, wxCoord y
)
1375 wxDataFormat format
= GetMatchingPair();
1376 if (format
== wxDF_INVALID
)
1378 return m_win
->OnDrop( format
, x
, y
);
1381 virtual wxDragResult
OnData( wxCoord x
, wxCoord y
, wxDragResult def
)
1383 wxDataFormat format
= GetMatchingPair();
1384 if (format
== wxDF_INVALID
)
1388 return m_win
->OnData( format
, x
, y
, def
);
1391 virtual void OnLeave()
1392 { m_win
->OnLeave(); }
1394 wxDataViewMainWindow
*m_win
;
1397 #endif // wxUSE_DRAG_AND_DROP
1399 //-----------------------------------------------------------------------------
1400 // wxDataViewRenameTimer
1401 //-----------------------------------------------------------------------------
1403 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1408 void wxDataViewRenameTimer::Notify()
1410 m_owner
->OnRenameTimer();
1413 //-----------------------------------------------------------------------------
1414 // wxDataViewMainWindow
1415 //-----------------------------------------------------------------------------
1417 // The tree building helper, declared firstly
1418 static void BuildTreeHelper( const wxDataViewModel
* model
, const wxDataViewItem
& item
,
1419 wxDataViewTreeNode
* node
);
1421 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1423 if (row1
> row2
) return 1;
1424 if (row1
== row2
) return 0;
1428 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1430 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1431 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1432 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1433 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1434 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1435 EVT_CHAR_HOOK (wxDataViewMainWindow::OnCharHook
)
1436 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1439 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1440 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1441 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
1442 m_selection( wxDataViewSelectionCmp
)
1447 m_editorRenderer
= NULL
;
1449 m_lastOnSame
= false;
1450 m_renameTimer
= new wxDataViewRenameTimer( this );
1452 // TODO: user better initial values/nothing selected
1453 m_currentCol
= NULL
;
1454 m_currentColSetByKeyboard
= false;
1455 m_useCellFocus
= false;
1456 m_currentRow
= (unsigned)-1;
1457 m_lineHeight
= GetDefaultRowHeight();
1459 #if wxUSE_DRAG_AND_DROP
1461 m_dragStart
= wxPoint(0,0);
1463 m_dragEnabled
= false;
1464 m_dropEnabled
= false;
1466 m_dropHintLine
= (unsigned int) -1;
1467 #endif // wxUSE_DRAG_AND_DROP
1469 m_lineLastClicked
= (unsigned int) -1;
1470 m_lineBeforeLastClicked
= (unsigned int) -1;
1471 m_lineSelectSingleOnUp
= (unsigned int) -1;
1475 SetBackgroundColour( *wxWHITE
);
1477 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1479 m_penRule
= wxPen(GetRuleColour());
1481 // compose a pen whichcan draw black lines
1482 // TODO: maybe there is something system colour to use
1483 m_penExpander
= wxPen(wxColour(0,0,0));
1485 m_root
= wxDataViewTreeNode::CreateRootNode();
1487 // Make m_count = -1 will cause the class recaculate the real displaying number of rows.
1489 m_underMouse
= NULL
;
1493 wxDataViewMainWindow::~wxDataViewMainWindow()
1496 delete m_renameTimer
;
1500 int wxDataViewMainWindow::GetDefaultRowHeight() const
1503 // We would like to use the same line height that Explorer uses. This is
1504 // different from standard ListView control since Vista.
1505 if ( wxGetWinVersion() >= wxWinVersion_Vista
)
1506 return wxMax(16, GetCharHeight()) + 6; // 16 = mini icon height
1509 return wxMax(16, GetCharHeight()) + 1; // 16 = mini icon height
1514 #if wxUSE_DRAG_AND_DROP
1515 bool wxDataViewMainWindow::EnableDragSource( const wxDataFormat
&format
)
1517 m_dragFormat
= format
;
1518 m_dragEnabled
= format
!= wxDF_INVALID
;
1523 bool wxDataViewMainWindow::EnableDropTarget( const wxDataFormat
&format
)
1525 m_dropFormat
= format
;
1526 m_dropEnabled
= format
!= wxDF_INVALID
;
1529 SetDropTarget( new wxDataViewDropTarget( new wxCustomDataObject( format
), this ) );
1534 void wxDataViewMainWindow::RemoveDropHint()
1539 RefreshRow( m_dropHintLine
);
1540 m_dropHintLine
= (unsigned int) -1;
1544 wxDragResult
wxDataViewMainWindow::OnDragOver( wxDataFormat format
, wxCoord x
,
1545 wxCoord y
, wxDragResult def
)
1549 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1550 unsigned int row
= GetLineAt( yy
);
1552 if ((row
>= GetRowCount()) || (xx
> GetEndOfLastCol()))
1558 wxDataViewItem item
= GetItemByRow( row
);
1560 wxDataViewModel
*model
= GetModel();
1562 wxDataViewEvent
event( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1563 event
.SetEventObject( m_owner
);
1564 event
.SetItem( item
);
1565 event
.SetModel( model
);
1566 event
.SetDataFormat( format
);
1567 event
.SetDropEffect( def
);
1568 if (!m_owner
->HandleWindowEvent( event
))
1574 if (!event
.IsAllowed())
1581 if (m_dropHint
&& (row
!= m_dropHintLine
))
1582 RefreshRow( m_dropHintLine
);
1584 m_dropHintLine
= row
;
1590 bool wxDataViewMainWindow::OnDrop( wxDataFormat format
, wxCoord x
, wxCoord y
)
1596 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1597 unsigned int row
= GetLineAt( yy
);
1599 if ((row
>= GetRowCount()) || (xx
> GetEndOfLastCol()))
1602 wxDataViewItem item
= GetItemByRow( row
);
1604 wxDataViewModel
*model
= GetModel();
1606 wxDataViewEvent
event( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE
, m_owner
->GetId() );
1607 event
.SetEventObject( m_owner
);
1608 event
.SetItem( item
);
1609 event
.SetModel( model
);
1610 event
.SetDataFormat( format
);
1611 if (!m_owner
->HandleWindowEvent( event
))
1614 if (!event
.IsAllowed())
1620 wxDragResult
wxDataViewMainWindow::OnData( wxDataFormat format
, wxCoord x
, wxCoord y
,
1625 m_owner
->CalcUnscrolledPosition( xx
, yy
, &xx
, &yy
);
1626 unsigned int row
= GetLineAt( yy
);
1628 if ((row
>= GetRowCount()) || (xx
> GetEndOfLastCol()))
1631 wxDataViewItem item
= GetItemByRow( row
);
1633 wxDataViewModel
*model
= GetModel();
1635 wxCustomDataObject
*obj
= (wxCustomDataObject
*) GetDropTarget()->GetDataObject();
1637 wxDataViewEvent
event( wxEVT_DATAVIEW_ITEM_DROP
, m_owner
->GetId() );
1638 event
.SetEventObject( m_owner
);
1639 event
.SetItem( item
);
1640 event
.SetModel( model
);
1641 event
.SetDataFormat( format
);
1642 event
.SetDataSize( obj
->GetSize() );
1643 event
.SetDataBuffer( obj
->GetData() );
1644 event
.SetDropEffect( def
);
1645 if (!m_owner
->HandleWindowEvent( event
))
1648 if (!event
.IsAllowed())
1654 void wxDataViewMainWindow::OnLeave()
1659 wxBitmap
wxDataViewMainWindow::CreateItemBitmap( unsigned int row
, int &indent
)
1661 int height
= GetLineHeight( row
);
1663 unsigned int cols
= GetOwner()->GetColumnCount();
1665 for (col
= 0; col
< cols
; col
++)
1667 wxDataViewColumn
*column
= GetOwner()->GetColumnAt(col
);
1668 if (column
->IsHidden())
1669 continue; // skip it!
1670 width
+= column
->GetWidth();
1676 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
1677 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
1678 indent
= indent
+ m_lineHeight
;
1679 // try to use the m_lineHeight as the expander space
1683 wxBitmap
bitmap( width
, height
);
1684 wxMemoryDC
dc( bitmap
);
1685 dc
.SetFont( GetFont() );
1686 dc
.SetPen( *wxBLACK_PEN
);
1687 dc
.SetBrush( *wxWHITE_BRUSH
);
1688 dc
.DrawRectangle( 0,0,width
,height
);
1690 wxDataViewModel
*model
= m_owner
->GetModel();
1692 wxDataViewColumn
* const
1693 expander
= GetExpanderColumnOrFirstOne(GetOwner());
1696 for (col
= 0; col
< cols
; col
++)
1698 wxDataViewColumn
*column
= GetOwner()->GetColumnAt( col
);
1699 wxDataViewRenderer
*cell
= column
->GetRenderer();
1701 if (column
->IsHidden())
1702 continue; // skip it!
1704 width
= column
->GetWidth();
1706 if (column
== expander
)
1709 wxDataViewItem item
= GetItemByRow( row
);
1710 cell
->PrepareForItem(model
, item
, column
->GetModelColumn());
1712 wxRect
item_rect(x
, 0, width
, height
);
1713 item_rect
.Deflate(PADDING_RIGHTLEFT
, 0);
1715 // dc.SetClippingRegion( item_rect );
1716 cell
->WXCallRender(item_rect
, &dc
, 0);
1717 // dc.DestroyClippingRegion();
1725 #endif // wxUSE_DRAG_AND_DROP
1728 // Draw focus rect for individual cell. Unlike native focus rect, we render
1729 // this in foreground text color (typically white) to enhance contrast and
1731 static void DrawSelectedCellFocusRect(wxDC
& dc
, const wxRect
& rect
)
1733 // (This code is based on wxRendererGeneric::DrawFocusRect and modified.)
1735 // draw the pixels manually because the "dots" in wxPen with wxDOT style
1736 // may be short traits and not really dots
1738 // note that to behave in the same manner as DrawRect(), we must exclude
1739 // the bottom and right borders from the rectangle
1740 wxCoord x1
= rect
.GetLeft(),
1742 x2
= rect
.GetRight(),
1743 y2
= rect
.GetBottom();
1745 wxDCPenChanger
pen(dc
, wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
1748 for ( z
= x1
+ 1; z
< x2
; z
+= 2 )
1749 dc
.DrawPoint(z
, rect
.GetTop());
1751 wxCoord shift
= z
== x2
? 0 : 1;
1752 for ( z
= y1
+ shift
; z
< y2
; z
+= 2 )
1753 dc
.DrawPoint(x2
, z
);
1755 shift
= z
== y2
? 0 : 1;
1756 for ( z
= x2
- shift
; z
> x1
; z
-= 2 )
1757 dc
.DrawPoint(z
, y2
);
1759 shift
= z
== x1
? 0 : 1;
1760 for ( z
= y2
- shift
; z
> y1
; z
-= 2 )
1761 dc
.DrawPoint(x1
, z
);
1765 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1767 wxDataViewModel
*model
= GetModel();
1768 wxAutoBufferedPaintDC
dc( this );
1770 dc
.SetBrush(GetOwner()->GetBackgroundColour());
1771 dc
.SetPen( *wxTRANSPARENT_PEN
);
1772 dc
.DrawRectangle(GetClientSize());
1776 // No items to draw.
1781 GetOwner()->PrepareDC( dc
);
1782 dc
.SetFont( GetFont() );
1784 wxRect update
= GetUpdateRegion().GetBox();
1785 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1787 // compute which items needs to be redrawn
1788 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
1789 unsigned int item_count
=
1790 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
1791 (int)(GetRowCount( ) - item_start
));
1792 unsigned int item_last
= item_start
+ item_count
;
1794 // Send the event to wxDataViewCtrl itself.
1795 wxWindow
* const parent
= GetParent();
1796 wxDataViewEvent
cache_event(wxEVT_DATAVIEW_CACHE_HINT
, parent
->GetId());
1797 cache_event
.SetEventObject(parent
);
1798 cache_event
.SetCache(item_start
, item_last
- 1);
1799 parent
->ProcessWindowEvent(cache_event
);
1801 // compute which columns needs to be redrawn
1802 unsigned int cols
= GetOwner()->GetColumnCount();
1805 // we assume that we have at least one column below and painting an
1806 // empty control is unnecessary anyhow
1810 unsigned int col_start
= 0;
1811 unsigned int x_start
;
1812 for (x_start
= 0; col_start
< cols
; col_start
++)
1814 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_start
);
1815 if (col
->IsHidden())
1816 continue; // skip it!
1818 unsigned int w
= col
->GetWidth();
1819 if (x_start
+w
>= (unsigned int)update
.x
)
1825 unsigned int col_last
= col_start
;
1826 unsigned int x_last
= x_start
;
1827 for (; col_last
< cols
; col_last
++)
1829 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(col_last
);
1830 if (col
->IsHidden())
1831 continue; // skip it!
1833 if (x_last
> (unsigned int)update
.GetRight())
1836 x_last
+= col
->GetWidth();
1839 // Draw background of alternate rows specially if required
1840 if ( m_owner
->HasFlag(wxDV_ROW_LINES
) )
1842 wxColour altRowColour
= m_owner
->m_alternateRowColour
;
1843 if ( !altRowColour
.IsOk() )
1845 // Determine the alternate rows colour automatically from the
1846 // background colour.
1847 const wxColour bgColour
= m_owner
->GetBackgroundColour();
1849 // Depending on the background, alternate row color
1850 // will be 3% more dark or 50% brighter.
1851 int alpha
= bgColour
.GetRGB() > 0x808080 ? 97 : 150;
1852 altRowColour
= bgColour
.ChangeLightness(alpha
);
1855 dc
.SetPen(*wxTRANSPARENT_PEN
);
1856 dc
.SetBrush(wxBrush(altRowColour
));
1858 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1862 dc
.DrawRectangle(x_start
,
1864 GetClientSize().GetWidth(),
1865 GetLineHeight(item
));
1870 // Draw horizontal rules if required
1871 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1873 dc
.SetPen(m_penRule
);
1874 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1876 for (unsigned int i
= item_start
; i
<= item_last
; i
++)
1878 int y
= GetLineStart( i
);
1879 dc
.DrawLine(x_start
, y
, x_last
, y
);
1883 // Draw vertical rules if required
1884 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1886 dc
.SetPen(m_penRule
);
1887 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1889 // NB: Vertical rules are drawn in the last pixel of a column so that
1890 // they align perfectly with native MSW wxHeaderCtrl as well as for
1891 // consistency with MSW native list control. There's no vertical
1892 // rule at the most-left side of the control.
1894 int x
= x_start
- 1;
1895 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1897 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(i
);
1898 if (col
->IsHidden())
1899 continue; // skip it
1901 x
+= col
->GetWidth();
1903 dc
.DrawLine(x
, GetLineStart( item_start
),
1904 x
, GetLineStart( item_last
) );
1908 // redraw the background for the items which are selected/current
1909 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1911 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1913 if (selected
|| item
== m_currentRow
)
1915 wxRect
rect( x_start
, GetLineStart( item
),
1916 x_last
- x_start
, GetLineHeight( item
) );
1918 // draw selection and whole-item focus:
1921 int flags
= wxCONTROL_SELECTED
;
1923 flags
|= wxCONTROL_FOCUSED
;
1925 wxRendererNative::Get().DrawItemSelectionRect
1934 // draw keyboard focus rect if applicable
1935 if ( item
== m_currentRow
&& m_hasFocus
)
1937 bool renderColumnFocus
= false;
1939 if ( m_useCellFocus
&& m_currentCol
&& m_currentColSetByKeyboard
)
1941 renderColumnFocus
= true;
1943 // If this is container node without columns, render full-row focus:
1946 wxDataViewTreeNode
*node
= GetTreeNodeByRow(item
);
1947 if ( node
->HasChildren() && !model
->HasContainerColumns(node
->GetItem()) )
1948 renderColumnFocus
= false;
1952 if ( renderColumnFocus
)
1954 for ( unsigned int i
= col_start
; i
< col_last
; i
++ )
1956 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(i
);
1957 if ( col
->IsHidden() )
1960 rect
.width
= col
->GetWidth();
1962 if ( col
== m_currentCol
)
1964 // make the rect more visible by adding a small
1965 // margin around it:
1970 // DrawFocusRect() uses XOR and is all but
1971 // invisible against dark-blue background. Use
1972 // the same color used for selected text.
1973 DrawSelectedCellFocusRect(dc
, rect
);
1977 wxRendererNative::Get().DrawFocusRect
1988 rect
.x
+= rect
.width
;
1993 // render focus rectangle for the whole row
1994 wxRendererNative::Get().DrawFocusRect
1999 selected
? (int)wxCONTROL_SELECTED
: 0
2006 #if wxUSE_DRAG_AND_DROP
2009 wxRect
rect( x_start
, GetLineStart( m_dropHintLine
),
2010 x_last
- x_start
, GetLineHeight( m_dropHintLine
) );
2011 dc
.SetPen( *wxBLACK_PEN
);
2012 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
2013 dc
.DrawRectangle( rect
);
2015 #endif // wxUSE_DRAG_AND_DROP
2017 wxDataViewColumn
* const
2018 expander
= GetExpanderColumnOrFirstOne(GetOwner());
2020 // redraw all cells for all rows which must be repainted and all columns
2022 cell_rect
.x
= x_start
;
2023 for (unsigned int i
= col_start
; i
< col_last
; i
++)
2025 wxDataViewColumn
*col
= GetOwner()->GetColumnAt( i
);
2026 wxDataViewRenderer
*cell
= col
->GetRenderer();
2027 cell_rect
.width
= col
->GetWidth();
2029 if ( col
->IsHidden() || cell_rect
.width
<= 0 )
2030 continue; // skip it!
2032 for (unsigned int item
= item_start
; item
< item_last
; item
++)
2034 // get the cell value and set it into the renderer
2035 wxDataViewTreeNode
*node
= NULL
;
2036 wxDataViewItem dataitem
;
2038 if (!IsVirtualList())
2040 node
= GetTreeNodeByRow(item
);
2044 dataitem
= node
->GetItem();
2046 // Skip all columns of "container" rows except the expander
2047 // column itself unless HasContainerColumns() overrides this.
2048 if ( col
!= expander
&&
2049 model
->IsContainer(dataitem
) &&
2050 !model
->HasContainerColumns(dataitem
) )
2055 dataitem
= wxDataViewItem( wxUIntToPtr(item
+1) );
2058 cell
->PrepareForItem(model
, dataitem
, col
->GetModelColumn());
2061 cell_rect
.y
= GetLineStart( item
);
2062 cell_rect
.height
= GetLineHeight( item
);
2064 // draw the background
2065 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
2067 DrawCellBackground( cell
, dc
, cell_rect
);
2069 // deal with the expander
2071 if ((!IsList()) && (col
== expander
))
2073 // Calculate the indent first
2074 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
2076 // we reserve m_lineHeight of horizontal space for the expander
2077 // but leave EXPANDER_MARGIN around the expander itself
2078 int exp_x
= cell_rect
.x
+ indent
+ EXPANDER_MARGIN
;
2080 indent
+= m_lineHeight
;
2082 // draw expander if needed and visible
2083 if ( node
->HasChildren() && exp_x
< cell_rect
.GetRight() )
2085 dc
.SetPen( m_penExpander
);
2086 dc
.SetBrush( wxNullBrush
);
2088 int exp_size
= m_lineHeight
- 2*EXPANDER_MARGIN
;
2089 int exp_y
= cell_rect
.y
+ (cell_rect
.height
- exp_size
)/2
2090 + EXPANDER_MARGIN
- EXPANDER_OFFSET
;
2092 const wxRect
rect(exp_x
, exp_y
, exp_size
, exp_size
);
2095 if ( m_underMouse
== node
)
2096 flag
|= wxCONTROL_CURRENT
;
2097 if ( node
->IsOpen() )
2098 flag
|= wxCONTROL_EXPANDED
;
2100 // ensure that we don't overflow the cell (which might
2101 // happen if the column is very narrow)
2102 wxDCClipper
clip(dc
, cell_rect
);
2104 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
2107 // force the expander column to left-center align
2108 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
2111 wxRect item_rect
= cell_rect
;
2112 item_rect
.Deflate(PADDING_RIGHTLEFT
, 0);
2114 // account for the tree indent (harmless if we're not indented)
2115 item_rect
.x
+= indent
;
2116 item_rect
.width
-= indent
;
2118 if ( item_rect
.width
<= 0 )
2122 if (m_hasFocus
&& selected
)
2123 state
|= wxDATAVIEW_CELL_SELECTED
;
2125 // TODO: it would be much more efficient to create a clipping
2126 // region for the entire column being rendered (in the OnPaint
2127 // of wxDataViewMainWindow) instead of a single clip region for
2128 // each cell. However it would mean that each renderer should
2129 // respect the given wxRect's top & bottom coords, eventually
2130 // violating only the left & right coords - however the user can
2131 // make its own renderer and thus we cannot be sure of that.
2132 wxDCClipper
clip(dc
, item_rect
);
2134 cell
->WXCallRender(item_rect
, &dc
, state
);
2137 cell_rect
.x
+= cell_rect
.width
;
2142 void wxDataViewMainWindow::DrawCellBackground( wxDataViewRenderer
* cell
, wxDC
& dc
, const wxRect
& rect
)
2144 wxRect
rectBg( rect
);
2146 // don't overlap the horizontal rules
2147 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
2153 // don't overlap the vertical rules
2154 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
2160 cell
->RenderBackground(&dc
, rectBg
);
2163 void wxDataViewMainWindow::OnRenameTimer()
2165 // We have to call this here because changes may just have
2166 // been made and no screen update taken place.
2169 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
2170 // (needs to be tested!)
2174 wxDataViewItem item
= GetItemByRow( m_currentRow
);
2176 StartEditing( item
, m_currentCol
);
2180 wxDataViewMainWindow::StartEditing(const wxDataViewItem
& item
,
2181 const wxDataViewColumn
* col
)
2183 wxDataViewRenderer
* renderer
= col
->GetRenderer();
2184 if ( !IsCellEditableInMode(item
, col
, wxDATAVIEW_CELL_EDITABLE
) )
2187 const wxRect itemRect
= GetItemRect(item
, col
);
2188 if ( renderer
->StartEditing(item
, itemRect
) )
2190 // Save the renderer to be able to finish/cancel editing it later and
2191 // save the control to be able to detect if we're still editing it.
2192 m_editorRenderer
= renderer
;
2193 m_editorCtrl
= renderer
->GetEditorCtrl();
2197 //-----------------------------------------------------------------------------
2198 // Helper class for do operation on the tree node
2199 //-----------------------------------------------------------------------------
2204 virtual ~DoJob() { }
2206 // The return value control how the tree-walker tranverse the tree
2209 DONE
, // Job done, stop traversing and return
2210 SKIP_SUBTREE
, // Ignore the current node's subtree and continue
2211 CONTINUE
// Job not done, continue
2214 virtual int operator() ( wxDataViewTreeNode
* node
) = 0;
2217 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
2219 wxCHECK_MSG( node
, false, "can't walk NULL node" );
2221 switch( func( node
) )
2225 case DoJob::SKIP_SUBTREE
:
2227 case DoJob::CONTINUE
:
2231 if ( node
->HasChildren() )
2233 const wxDataViewTreeNodes
& nodes
= node
->GetChildNodes();
2235 for ( wxDataViewTreeNodes::const_iterator i
= nodes
.begin();
2239 if ( Walker(*i
, func
) )
2247 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
2249 if (IsVirtualList())
2251 wxDataViewVirtualListModel
*list_model
=
2252 (wxDataViewVirtualListModel
*) GetModel();
2253 m_count
= list_model
->GetCount();
2259 wxDataViewTreeNode
*parentNode
= FindNode(parent
);
2264 wxDataViewItemArray modelSiblings
;
2265 GetModel()->GetChildren(parent
, modelSiblings
);
2266 const int modelSiblingsSize
= modelSiblings
.size();
2268 int posInModel
= modelSiblings
.Index(item
, /*fromEnd=*/true);
2269 wxCHECK_MSG( posInModel
!= wxNOT_FOUND
, false, "adding non-existent item?" );
2271 wxDataViewTreeNode
*itemNode
= new wxDataViewTreeNode(parentNode
, item
);
2272 itemNode
->SetHasChildren(GetModel()->IsContainer(item
));
2274 parentNode
->SetHasChildren(true);
2276 const wxDataViewTreeNodes
& nodeSiblings
= parentNode
->GetChildNodes();
2277 const int nodeSiblingsSize
= nodeSiblings
.size();
2281 if ( posInModel
== modelSiblingsSize
- 1 )
2283 nodePos
= nodeSiblingsSize
;
2285 else if ( modelSiblingsSize
== nodeSiblingsSize
+ 1 )
2287 // This is the simple case when our node tree already matches the
2288 // model and only this one item is missing.
2289 nodePos
= posInModel
;
2293 // It's possible that a larger discrepancy between the model and
2294 // our realization exists. This can happen e.g. when adding a bunch
2295 // of items to the model and then calling ItemsAdded() just once
2296 // afterwards. In this case, we must find the right position by
2297 // looking at sibling items.
2299 // append to the end if we won't find a better position:
2300 nodePos
= nodeSiblingsSize
;
2302 for ( int nextItemPos
= posInModel
+ 1;
2303 nextItemPos
< modelSiblingsSize
;
2306 int nextNodePos
= parentNode
->FindChildByItem(modelSiblings
[nextItemPos
]);
2307 if ( nextNodePos
!= wxNOT_FOUND
)
2309 nodePos
= nextNodePos
;
2315 parentNode
->ChangeSubTreeCount(+1);
2316 parentNode
->InsertChild(itemNode
, nodePos
);
2321 GetOwner()->InvalidateColBestWidths();
2327 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
2328 const wxDataViewItem
& item
)
2330 if (IsVirtualList())
2332 wxDataViewVirtualListModel
*list_model
=
2333 (wxDataViewVirtualListModel
*) GetModel();
2334 m_count
= list_model
->GetCount();
2336 if ( !m_selection
.empty() )
2338 const int row
= GetRowByItem(item
);
2340 int rowIndexInSelection
= wxNOT_FOUND
;
2342 const size_t selCount
= m_selection
.size();
2343 for ( size_t i
= 0; i
< selCount
; i
++ )
2345 if ( m_selection
[i
] == (unsigned)row
)
2346 rowIndexInSelection
= i
;
2347 else if ( m_selection
[i
] > (unsigned)row
)
2351 if ( rowIndexInSelection
!= wxNOT_FOUND
)
2352 m_selection
.RemoveAt(rowIndexInSelection
);
2356 else // general case
2358 wxDataViewTreeNode
*parentNode
= FindNode(parent
);
2360 // Notice that it is possible that the item being deleted is not in the
2361 // tree at all, for example we could be deleting a never shown (because
2362 // collapsed) item in a tree model. So it's not an error if we don't know
2363 // about this item, just return without doing anything then.
2367 wxCHECK_MSG( parentNode
->HasChildren(), false, "parent node doesn't have children?" );
2368 const wxDataViewTreeNodes
& parentsChildren
= parentNode
->GetChildNodes();
2370 // We can't use FindNode() to find 'item', because it was already
2371 // removed from the model by the time ItemDeleted() is called, so we
2372 // have to do it manually. We keep track of its position as well for
2374 int itemPosInNode
= 0;
2375 wxDataViewTreeNode
*itemNode
= NULL
;
2376 for ( wxDataViewTreeNodes::const_iterator i
= parentsChildren
.begin();
2377 i
!= parentsChildren
.end();
2378 ++i
, ++itemPosInNode
)
2380 if( (*i
)->GetItem() == item
)
2387 // If the parent wasn't expanded, it's possible that we didn't have a
2388 // node corresponding to 'item' and so there's nothing left to do.
2391 // If this was the last child to be removed, it's possible the parent
2392 // node became a leaf. Let's ask the model about it.
2393 if ( parentNode
->GetChildNodes().empty() )
2394 parentNode
->SetHasChildren(GetModel()->IsContainer(parent
));
2399 // Delete the item from wxDataViewTreeNode representation:
2400 const int itemsDeleted
= 1 + itemNode
->GetSubTreeCount();
2402 parentNode
->RemoveChild(itemNode
);
2404 parentNode
->ChangeSubTreeCount(-itemsDeleted
);
2406 // Make the row number invalid and get a new valid one when user call GetRowCount
2409 // If this was the last child to be removed, it's possible the parent
2410 // node became a leaf. Let's ask the model about it.
2411 if ( parentNode
->GetChildNodes().empty() )
2413 bool isContainer
= GetModel()->IsContainer(parent
);
2414 parentNode
->SetHasChildren(isContainer
);
2417 // If it's still a container, make sure we show "+" icon for it
2418 // and not "-" one as there is nothing to collapse any more.
2419 if ( parentNode
->IsOpen() )
2420 parentNode
->ToggleOpen();
2424 // Update selection by removing 'item' and its entire children tree from the selection.
2425 if ( !m_selection
.empty() )
2427 // we can't call GetRowByItem() on 'item', as it's already deleted, so compute it from
2428 // the parent ('parentNode') and position in its list of children
2430 if ( itemPosInNode
== 0 )
2432 // 1st child, row number is that of the parent parentNode + 1
2433 itemRow
= GetRowByItem(parentNode
->GetItem()) + 1;
2437 // row number is that of the sibling above 'item' + its subtree if any + 1
2438 const wxDataViewTreeNode
*siblingNode
= parentNode
->GetChildNodes()[itemPosInNode
- 1];
2440 itemRow
= GetRowByItem(siblingNode
->GetItem()) +
2441 siblingNode
->GetSubTreeCount() +
2445 wxDataViewSelection
newsel(wxDataViewSelectionCmp
);
2447 const size_t numSelections
= m_selection
.size();
2448 for ( size_t i
= 0; i
< numSelections
; ++i
)
2450 const int s
= m_selection
[i
];
2452 newsel
.push_back(s
);
2453 else if ( s
>= itemRow
+ itemsDeleted
)
2454 newsel
.push_back(s
- itemsDeleted
);
2455 // else: deleted item, remove from selection
2458 m_selection
= newsel
;
2462 // Change the current row to the last row if the current exceed the max row number
2463 if ( m_currentRow
>= GetRowCount() )
2464 ChangeCurrentRow(m_count
- 1);
2466 GetOwner()->InvalidateColBestWidths();
2472 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
2477 GetOwner()->InvalidateColBestWidths();
2480 wxWindow
*parent
= GetParent();
2481 wxDataViewEvent
le(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2482 le
.SetEventObject(parent
);
2483 le
.SetModel(GetModel());
2485 parent
->ProcessWindowEvent(le
);
2490 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int model_column
)
2492 int view_column
= m_owner
->GetModelColumnIndex(model_column
);
2493 if ( view_column
== wxNOT_FOUND
)
2496 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
2497 /*#define MAX_VIRTUAL_WIDTH 100000
2499 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
2500 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2501 Refresh( true, &rect );
2508 GetOwner()->InvalidateColBestWidth(view_column
);
2511 wxWindow
*parent
= GetParent();
2512 wxDataViewEvent
le(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2513 le
.SetEventObject(parent
);
2514 le
.SetModel(GetModel());
2516 le
.SetColumn(view_column
);
2517 le
.SetDataViewColumn(GetOwner()->GetColumn(view_column
));
2518 parent
->ProcessWindowEvent(le
);
2523 bool wxDataViewMainWindow::Cleared()
2526 m_selection
.Clear();
2527 m_currentRow
= (unsigned)-1;
2532 BuildTree( GetModel() );
2539 GetOwner()->InvalidateColBestWidths();
2545 void wxDataViewMainWindow::UpdateDisplay()
2548 m_underMouse
= NULL
;
2551 void wxDataViewMainWindow::OnInternalIdle()
2553 wxWindow::OnInternalIdle();
2557 RecalculateDisplay();
2562 void wxDataViewMainWindow::RecalculateDisplay()
2564 wxDataViewModel
*model
= GetModel();
2571 int width
= GetEndOfLastCol();
2572 int height
= GetLineStart( GetRowCount() );
2574 SetVirtualSize( width
, height
);
2575 GetOwner()->SetScrollRate( 10, m_lineHeight
);
2580 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2582 m_underMouse
= NULL
;
2584 wxWindow::ScrollWindow( dx
, dy
, rect
);
2586 if (GetOwner()->m_headerArea
)
2587 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
2590 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
2592 m_underMouse
= NULL
;
2595 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
2596 int sy
= GetLineStart( rows
)/y
;
2600 wxRect rect
= GetClientRect();
2604 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
2605 for (x_start
= 0; colnum
< column
; colnum
++)
2607 wxDataViewColumn
*col
= GetOwner()->GetColumnAt(colnum
);
2608 if (col
->IsHidden())
2609 continue; // skip it!
2611 w
= col
->GetWidth();
2615 int x_end
= x_start
+ w
;
2616 xe
= xx
+ rect
.width
;
2619 sx
= ( xx
+ x_end
- xe
)/x
;
2626 m_owner
->Scroll( sx
, sy
);
2629 int wxDataViewMainWindow::GetCountPerPage() const
2631 wxSize size
= GetClientSize();
2632 return size
.y
/ m_lineHeight
;
2635 int wxDataViewMainWindow::GetEndOfLastCol() const
2639 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2641 const wxDataViewColumn
*c
=
2642 const_cast<wxDataViewCtrl
*>(GetOwner())->GetColumnAt( i
);
2645 width
+= c
->GetWidth();
2650 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2654 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2656 return GetLineAt( y
);
2659 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
2661 wxSize client_size
= GetClientSize();
2662 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2663 &client_size
.x
, &client_size
.y
);
2665 // we should deal with the pixel here
2666 unsigned int row
= GetLineAt(client_size
.y
) - 1;
2668 return wxMin( GetRowCount()-1, row
);
2671 unsigned int wxDataViewMainWindow::GetRowCount() const
2673 if ( m_count
== -1 )
2675 wxDataViewMainWindow
* const
2676 self
= const_cast<wxDataViewMainWindow
*>(this);
2677 self
->m_count
= RecalculateCount();
2678 self
->UpdateDisplay();
2683 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
2690 void wxDataViewMainWindow::SelectAllRows( bool on
)
2697 m_selection
.Clear();
2698 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2699 m_selection
.Add( i
);
2704 unsigned int first_visible
= GetFirstVisibleRow();
2705 unsigned int last_visible
= GetLastVisibleRow();
2707 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2709 unsigned int row
= m_selection
[i
];
2710 if ((row
>= first_visible
) && (row
<= last_visible
))
2713 m_selection
.Clear();
2717 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
2719 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2723 m_selection
.Add( row
);
2731 m_selection
.Remove( row
);
2737 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2741 unsigned int tmp
= from
;
2747 for (i
= from
; i
<= to
; i
++)
2749 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2752 m_selection
.Add( i
);
2757 m_selection
.Remove( i
);
2760 RefreshRows( from
, to
);
2763 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2765 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2767 int n
= aSelections
[i
];
2769 m_selection
.Add( n
);
2774 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2776 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2777 m_selection
.Add( row
);
2779 m_selection
.Remove( row
);
2783 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2785 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2788 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
2790 wxWindow
*parent
= GetParent();
2791 wxDataViewEvent
le(wxEVT_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
2793 le
.SetEventObject(parent
);
2794 le
.SetModel(GetModel());
2797 parent
->ProcessWindowEvent(le
);
2800 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2802 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
2803 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2805 wxSize client_size
= GetClientSize();
2806 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2807 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2808 if (intersect_rect
.width
> 0)
2809 Refresh( true, &intersect_rect
);
2812 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2816 unsigned int tmp
= to
;
2821 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
2822 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2824 wxSize client_size
= GetClientSize();
2825 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2826 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2827 if (intersect_rect
.width
> 0)
2828 Refresh( true, &intersect_rect
);
2831 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2833 wxSize client_size
= GetClientSize();
2834 int start
= GetLineStart( firstRow
);
2835 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
2836 if (start
> client_size
.y
) return;
2838 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
2840 Refresh( true, &rect
);
2843 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2847 rect
.y
= GetLineStart( row
);
2848 rect
.width
= GetEndOfLastCol();
2849 rect
.height
= GetLineHeight( row
);
2854 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2856 const wxDataViewModel
*model
= GetModel();
2858 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2860 // TODO make more efficient
2865 for (r
= 0; r
< row
; r
++)
2867 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2868 if (!node
) return start
;
2870 wxDataViewItem item
= node
->GetItem();
2872 unsigned int cols
= GetOwner()->GetColumnCount();
2874 int height
= m_lineHeight
;
2875 for (col
= 0; col
< cols
; col
++)
2877 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2878 if (column
->IsHidden())
2879 continue; // skip it!
2882 model
->IsContainer(item
) &&
2883 !model
->HasContainerColumns(item
))
2884 continue; // skip it!
2886 wxDataViewRenderer
*renderer
=
2887 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2888 renderer
->PrepareForItem(model
, item
, column
->GetModelColumn());
2890 height
= wxMax( height
, renderer
->GetSize().y
);
2900 return row
* m_lineHeight
;
2904 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
2906 const wxDataViewModel
*model
= GetModel();
2908 // check for the easy case first
2909 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
2910 return y
/ m_lineHeight
;
2912 // TODO make more efficient
2913 unsigned int row
= 0;
2914 unsigned int yy
= 0;
2917 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2920 // not really correct...
2921 return row
+ ((y
-yy
) / m_lineHeight
);
2924 wxDataViewItem item
= node
->GetItem();
2926 unsigned int cols
= GetOwner()->GetColumnCount();
2928 int height
= m_lineHeight
;
2929 for (col
= 0; col
< cols
; col
++)
2931 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2932 if (column
->IsHidden())
2933 continue; // skip it!
2936 model
->IsContainer(item
) &&
2937 !model
->HasContainerColumns(item
))
2938 continue; // skip it!
2940 wxDataViewRenderer
*renderer
=
2941 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2942 renderer
->PrepareForItem(model
, item
, column
->GetModelColumn());
2944 height
= wxMax( height
, renderer
->GetSize().y
);
2955 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
2957 const wxDataViewModel
*model
= GetModel();
2959 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2961 wxASSERT( !IsVirtualList() );
2963 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2964 // wxASSERT( node );
2965 if (!node
) return m_lineHeight
;
2967 wxDataViewItem item
= node
->GetItem();
2969 int height
= m_lineHeight
;
2971 unsigned int cols
= GetOwner()->GetColumnCount();
2973 for (col
= 0; col
< cols
; col
++)
2975 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2976 if (column
->IsHidden())
2977 continue; // skip it!
2980 model
->IsContainer(item
) &&
2981 !model
->HasContainerColumns(item
))
2982 continue; // skip it!
2984 wxDataViewRenderer
*renderer
=
2985 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
2986 renderer
->PrepareForItem(model
, item
, column
->GetModelColumn());
2988 height
= wxMax( height
, renderer
->GetSize().y
);
2995 return m_lineHeight
;
3000 class RowToTreeNodeJob
: public DoJob
3003 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
3006 this->current
= current
;
3011 virtual int operator() ( wxDataViewTreeNode
* node
)
3014 if( current
== static_cast<int>(row
))
3020 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
3022 current
+= node
->GetSubTreeCount();
3023 return DoJob::SKIP_SUBTREE
;
3029 // If the current node has only leaf children, we can find the
3030 // desired node directly. This can speed up finding the node
3031 // in some cases, and will have a very good effect for list views.
3032 if ( node
->HasChildren() &&
3033 (int)node
->GetChildNodes().size() == node
->GetSubTreeCount() )
3035 const int index
= static_cast<int>(row
) - current
- 1;
3036 ret
= node
->GetChildNodes()[index
];
3040 return DoJob::CONTINUE
;
3044 wxDataViewTreeNode
* GetResult() const
3050 wxDataViewTreeNode
* ret
;
3051 wxDataViewTreeNode
* parent
;
3054 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
3056 wxASSERT( !IsVirtualList() );
3058 if ( row
== (unsigned)-1 )
3061 RowToTreeNodeJob
job( row
, -2, m_root
);
3062 Walker( m_root
, job
);
3063 return job
.GetResult();
3066 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
3068 wxDataViewItem item
;
3069 if (IsVirtualList())
3071 if ( row
< GetRowCount() )
3072 item
= wxDataViewItem(wxUIntToPtr(row
+1));
3076 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
3078 item
= node
->GetItem();
3085 wxDataViewMainWindow::SendExpanderEvent(wxEventType type
,
3086 const wxDataViewItem
& item
)
3088 wxWindow
*parent
= GetParent();
3089 wxDataViewEvent
le(type
, parent
->GetId());
3091 le
.SetEventObject(parent
);
3092 le
.SetModel(GetModel());
3095 return !parent
->ProcessWindowEvent(le
) || le
.IsAllowed();
3098 bool wxDataViewMainWindow::IsExpanded( unsigned int row
) const
3103 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3107 if (!node
->HasChildren())
3110 return node
->IsOpen();
3113 bool wxDataViewMainWindow::HasChildren( unsigned int row
) const
3118 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3122 if (!node
->HasChildren())
3128 void wxDataViewMainWindow::Expand( unsigned int row
)
3133 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3137 if (!node
->HasChildren())
3140 if (!node
->IsOpen())
3142 if ( !SendExpanderEvent(wxEVT_DATAVIEW_ITEM_EXPANDING
, node
->GetItem()) )
3144 // Vetoed by the event handler.
3150 // build the children of current node
3151 if( node
->GetChildNodes().empty() )
3154 ::BuildTreeHelper(GetModel(), node
->GetItem(), node
);
3157 // By expanding the node all row indices that are currently in the selection list
3158 // and are greater than our node have become invalid. So we have to correct that now.
3159 const unsigned rowAdjustment
= node
->GetSubTreeCount();
3160 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3162 const unsigned testRow
= m_selection
[i
];
3163 // all rows above us are not affected, so skip them
3167 m_selection
[i
] += rowAdjustment
;
3170 if(m_currentRow
> row
)
3171 ChangeCurrentRow(m_currentRow
+ rowAdjustment
);
3175 // Send the expanded event
3176 SendExpanderEvent(wxEVT_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
3180 void wxDataViewMainWindow::Collapse(unsigned int row
)
3185 wxDataViewTreeNode
*node
= GetTreeNodeByRow(row
);
3189 if (!node
->HasChildren())
3194 if ( !SendExpanderEvent(wxEVT_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem()) )
3196 // Vetoed by the event handler.
3200 // Find out if there are selected items below the current node.
3201 bool selectCollapsingRow
= false;
3202 const unsigned rowAdjustment
= node
->GetSubTreeCount();
3203 unsigned maxRowToBeTested
= row
+ rowAdjustment
;
3204 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3206 const unsigned testRow
= m_selection
[i
];
3207 if(testRow
> row
&& testRow
<= maxRowToBeTested
)
3209 selectCollapsingRow
= true;
3210 // get out as soon as we have found a node that is selected
3217 // If the node to be closed has selected items the user won't see those any longer.
3218 // We select the collapsing node in this case.
3219 if(selectCollapsingRow
)
3221 SelectAllRows(false);
3222 ChangeCurrentRow(row
);
3223 SelectRow(row
, true);
3224 SendSelectionChangedEvent(GetItemByRow(row
));
3228 // if there were no selected items below our node we still need to "fix" the
3229 // selection list to adjust for the changing of the row indices.
3230 // We actually do the opposite of what we are doing in Expand().
3231 for(unsigned i
=0; i
<m_selection
.size(); ++i
)
3233 const unsigned testRow
= m_selection
[i
];
3234 // all rows above us are not affected, so skip them
3238 m_selection
[i
] -= rowAdjustment
;
3241 // if the "current row" is being collapsed away we change it to the current row ;-)
3242 if(m_currentRow
> row
&& m_currentRow
<= maxRowToBeTested
)
3243 ChangeCurrentRow(row
);
3244 else if(m_currentRow
> row
)
3245 ChangeCurrentRow(m_currentRow
- rowAdjustment
);
3250 SendExpanderEvent(wxEVT_DATAVIEW_ITEM_COLLAPSED
,node
->GetItem());
3254 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
3256 const wxDataViewModel
* model
= GetModel();
3263 // Compose the parent-chain for the item we are looking for
3264 wxVector
<wxDataViewItem
> parentChain
;
3265 wxDataViewItem
it( item
);
3268 parentChain
.push_back(it
);
3269 it
= model
->GetParent(it
);
3272 // Find the item along the parent-chain.
3273 // This algorithm is designed to speed up the node-finding method
3274 wxDataViewTreeNode
* node
= m_root
;
3275 for( unsigned iter
= parentChain
.size()-1; ; --iter
)
3277 if( node
->HasChildren() )
3279 if( node
->GetChildNodes().empty() )
3281 // Even though the item is a container, it doesn't have any
3282 // child nodes in the control's representation yet. We have
3283 // to realize its subtree now.
3285 ::BuildTreeHelper(model
, node
->GetItem(), node
);
3288 const wxDataViewTreeNodes
& nodes
= node
->GetChildNodes();
3291 for (unsigned i
= 0; i
< nodes
.GetCount(); ++i
)
3293 wxDataViewTreeNode
* currentNode
= nodes
[i
];
3294 if (currentNode
->GetItem() == parentChain
[iter
])
3296 if (currentNode
->GetItem() == item
)
3316 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
3317 wxDataViewColumn
* &column
)
3319 wxDataViewColumn
*col
= NULL
;
3320 unsigned int cols
= GetOwner()->GetColumnCount();
3321 unsigned int colnum
= 0;
3323 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
3324 for (unsigned x_start
= 0; colnum
< cols
; colnum
++)
3326 col
= GetOwner()->GetColumnAt(colnum
);
3327 if (col
->IsHidden())
3328 continue; // skip it!
3330 unsigned int w
= col
->GetWidth();
3331 if (x_start
+w
>= (unsigned int)x
)
3338 item
= GetItemByRow( GetLineAt( y
) );
3341 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
,
3342 const wxDataViewColumn
* column
)
3347 unsigned int cols
= GetOwner()->GetColumnCount();
3348 // If column is null the loop will compute the combined width of all columns.
3349 // Otherwise, it will compute the x position of the column we are looking for.
3350 for (unsigned int i
= 0; i
< cols
; i
++)
3352 wxDataViewColumn
* col
= GetOwner()->GetColumnAt( i
);
3357 if (col
->IsHidden())
3358 continue; // skip it!
3360 xpos
+= col
->GetWidth();
3361 width
+= col
->GetWidth();
3366 // If we have a column, we need can get its width directly.
3367 if(column
->IsHidden())
3370 width
= column
->GetWidth();
3375 // If we have no column, we reset the x position back to zero.
3379 // we have to take an expander column into account and compute its indentation
3380 // to get the correct x position where the actual text is
3382 int row
= GetRowByItem(item
);
3384 (column
== 0 || GetExpanderColumnOrFirstOne(GetOwner()) == column
) )
3386 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3387 indent
= GetOwner()->GetIndent() * node
->GetIndentLevel();
3388 indent
= indent
+ m_lineHeight
; // use m_lineHeight as the width of the expander
3391 wxRect
itemRect( xpos
+ indent
,
3392 GetLineStart( row
),
3394 GetLineHeight( row
) );
3396 GetOwner()->CalcScrolledPosition( itemRect
.x
, itemRect
.y
,
3397 &itemRect
.x
, &itemRect
.y
);
3402 int wxDataViewMainWindow::RecalculateCount() const
3404 if (IsVirtualList())
3406 wxDataViewVirtualListModel
*list_model
=
3407 (wxDataViewVirtualListModel
*) GetModel();
3409 return list_model
->GetCount();
3413 return m_root
->GetSubTreeCount();
3417 class ItemToRowJob
: public DoJob
3420 ItemToRowJob(const wxDataViewItem
& item_
, wxVector
<wxDataViewItem
>::reverse_iterator iter
)
3427 // Maybe binary search will help to speed up this process
3428 virtual int operator() ( wxDataViewTreeNode
* node
)
3431 if( node
->GetItem() == item
)
3436 if( node
->GetItem() == *m_iter
)
3439 return DoJob::CONTINUE
;
3443 ret
+= node
->GetSubTreeCount();
3444 return DoJob::SKIP_SUBTREE
;
3449 // the row number is begin from zero
3450 int GetResult() const
3454 wxVector
<wxDataViewItem
>::reverse_iterator m_iter
;
3455 wxDataViewItem item
;
3460 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
3462 const wxDataViewModel
* model
= GetModel();
3466 if (IsVirtualList())
3468 return wxPtrToUInt( item
.GetID() ) -1;
3475 // Compose the parent-chain of the item we are looking for
3476 wxVector
<wxDataViewItem
> parentChain
;
3477 wxDataViewItem
it( item
);
3480 parentChain
.push_back(it
);
3481 it
= model
->GetParent(it
);
3484 // add an 'invalid' item to represent our 'invisible' root node
3485 parentChain
.push_back(wxDataViewItem());
3487 // the parent chain was created by adding the deepest parent first.
3488 // so if we want to start at the root node, we have to iterate backwards through the vector
3489 ItemToRowJob
job( item
, parentChain
.rbegin() );
3490 Walker( m_root
, job
);
3491 return job
.GetResult();
3495 static void BuildTreeHelper( const wxDataViewModel
* model
, const wxDataViewItem
& item
,
3496 wxDataViewTreeNode
* node
)
3498 if( !model
->IsContainer( item
) )
3501 wxDataViewItemArray children
;
3502 unsigned int num
= model
->GetChildren( item
, children
);
3504 for ( unsigned int index
= 0; index
< num
; index
++ )
3506 wxDataViewTreeNode
*n
= new wxDataViewTreeNode(node
, children
[index
]);
3508 if( model
->IsContainer(children
[index
]) )
3509 n
->SetHasChildren( true );
3511 node
->InsertChild(n
, index
);
3514 wxASSERT( node
->IsOpen() );
3515 node
->ChangeSubTreeCount(+num
);
3518 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
3522 if (GetModel()->IsVirtualListModel())
3528 m_root
= wxDataViewTreeNode::CreateRootNode();
3530 // First we define a invalid item to fetch the top-level elements
3531 wxDataViewItem item
;
3533 BuildTreeHelper( model
, item
, m_root
);
3537 void wxDataViewMainWindow::DestroyTree()
3539 if (!IsVirtualList())
3547 wxDataViewMainWindow::FindColumnForEditing(const wxDataViewItem
& item
, wxDataViewCellMode mode
)
3549 // Edit the current column editable in 'mode'. If no column is focused
3550 // (typically because the user has full row selected), try to find the
3551 // first editable column (this would typically be a checkbox for
3552 // wxDATAVIEW_CELL_ACTIVATABLE and we don't want to force the user to set
3553 // focus on the checkbox column; or on the only editable text column).
3555 wxDataViewColumn
*candidate
= m_currentCol
;
3558 !IsCellEditableInMode(item
, candidate
, mode
) &&
3559 !m_currentColSetByKeyboard
)
3561 // If current column was set by mouse to something not editable (in
3562 // 'mode') and the user pressed Space/F2 to edit it, treat the
3563 // situation as if there was whole-row focus, because that's what is
3564 // visually indicated and the mouse click could very well be targeted
3565 // on the row rather than on an individual cell.
3567 // But if it was done by keyboard, respect that even if the column
3568 // isn't editable, because focus is visually on that column and editing
3569 // something else would be surprising.
3575 const unsigned cols
= GetOwner()->GetColumnCount();
3576 for ( unsigned i
= 0; i
< cols
; i
++ )
3578 wxDataViewColumn
*c
= GetOwner()->GetColumnAt(i
);
3579 if ( c
->IsHidden() )
3582 if ( IsCellEditableInMode(item
, c
, mode
) )
3590 // If on container item without columns, only the expander column
3591 // may be directly editable:
3593 GetOwner()->GetExpanderColumn() != candidate
&&
3594 GetModel()->IsContainer(item
) &&
3595 !GetModel()->HasContainerColumns(item
) )
3597 candidate
= GetOwner()->GetExpanderColumn();
3603 if ( !IsCellEditableInMode(item
, candidate
, mode
) )
3609 bool wxDataViewMainWindow::IsCellEditableInMode(const wxDataViewItem
& item
,
3610 const wxDataViewColumn
*col
,
3611 wxDataViewCellMode mode
) const
3613 if ( col
->GetRenderer()->GetMode() != mode
)
3616 if ( !GetModel()->IsEnabled(item
, col
->GetModelColumn()) )
3622 void wxDataViewMainWindow::OnCharHook(wxKeyEvent
& event
)
3626 // Handle any keys special for the in-place editor and return without
3627 // calling Skip() below.
3628 switch ( event
.GetKeyCode() )
3631 m_editorRenderer
->CancelEditing();
3635 m_editorRenderer
->FinishEditing();
3643 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
3645 wxWindow
* const parent
= GetParent();
3647 // propagate the char event upwards
3648 wxKeyEvent
eventForParent(event
);
3649 eventForParent
.SetEventObject(parent
);
3650 if ( parent
->ProcessWindowEvent(eventForParent
) )
3653 if ( parent
->HandleAsNavigationKey(event
) )
3656 // no item -> nothing to do
3657 if (!HasCurrentRow())
3663 // don't use m_linesPerPage directly as it might not be computed yet
3664 const int pageSize
= GetCountPerPage();
3665 wxCHECK_RET( pageSize
, wxT("should have non zero page size") );
3667 switch ( event
.GetKeyCode() )
3670 if ( event
.HasModifiers() )
3677 // Enter activates the item, i.e. sends wxEVT_DATAVIEW_ITEM_ACTIVATED to
3678 // it. Only if that event is not handled do we activate column renderer (which
3679 // is normally done by Space) or even inline editing.
3681 const wxDataViewItem item
= GetItemByRow(m_currentRow
);
3683 wxDataViewEvent
le(wxEVT_DATAVIEW_ITEM_ACTIVATED
,
3686 le
.SetEventObject(parent
);
3687 le
.SetModel(GetModel());
3689 if ( parent
->ProcessWindowEvent(le
) )
3691 // else: fall through to WXK_SPACE handling
3695 if ( event
.HasModifiers() )
3702 // Space toggles activatable items or -- if not activatable --
3703 // starts inline editing (this is normally done using F2 on
3704 // Windows, but Space is common everywhere else, so use it too
3705 // for greater cross-platform compatibility).
3707 const wxDataViewItem item
= GetItemByRow(m_currentRow
);
3709 // Activate the current activatable column. If not column is focused (typically
3710 // because the user has full row selected), try to find the first activatable
3711 // column (this would typically be a checkbox and we don't want to force the user
3712 // to set focus on the checkbox column).
3713 wxDataViewColumn
*activatableCol
= FindColumnForEditing(item
, wxDATAVIEW_CELL_ACTIVATABLE
);
3715 if ( activatableCol
)
3717 const unsigned colIdx
= activatableCol
->GetModelColumn();
3718 const wxRect cell_rect
= GetOwner()->GetItemRect(item
, activatableCol
);
3720 wxDataViewRenderer
*cell
= activatableCol
->GetRenderer();
3721 cell
->PrepareForItem(GetModel(), item
, colIdx
);
3722 cell
->WXActivateCell(cell_rect
, GetModel(), item
, colIdx
, NULL
);
3726 // else: fall through to WXK_F2 handling
3730 if ( event
.HasModifiers() )
3737 if( !m_selection
.empty() )
3739 // Mimic Windows 7 behavior: edit the item that has focus
3740 // if it is selected and the first selected item if focus
3741 // is out of selection.
3743 if ( m_selection
.Index(m_currentRow
) != wxNOT_FOUND
)
3746 sel
= m_selection
[0];
3749 const wxDataViewItem item
= GetItemByRow(sel
);
3751 // Edit the current column. If no column is focused
3752 // (typically because the user has full row selected), try
3753 // to find the first editable column.
3754 wxDataViewColumn
*editableCol
= FindColumnForEditing(item
, wxDATAVIEW_CELL_EDITABLE
);
3757 GetOwner()->EditItem(item
, editableCol
);
3763 OnVerticalNavigation( -1, event
);
3767 OnVerticalNavigation( +1, event
);
3769 // Add the process for tree expanding/collapsing
3779 OnVerticalNavigation( +(int)GetRowCount(), event
);
3783 OnVerticalNavigation( -(int)GetRowCount(), event
);
3787 OnVerticalNavigation( -(pageSize
- 1), event
);
3791 OnVerticalNavigation( +(pageSize
- 1), event
);
3799 void wxDataViewMainWindow::OnVerticalNavigation(int delta
, const wxKeyEvent
& event
)
3801 // if there is no selection, we cannot move it anywhere
3802 if (!HasCurrentRow() || IsEmpty())
3805 int newRow
= (int)m_currentRow
+ delta
;
3807 // let's keep the new row inside the allowed range
3811 const int rowCount
= (int)GetRowCount();
3812 if ( newRow
>= rowCount
)
3813 newRow
= rowCount
- 1;
3815 unsigned int oldCurrent
= m_currentRow
;
3816 unsigned int newCurrent
= (unsigned int)newRow
;
3818 // in single selection we just ignore Shift as we can't select several
3820 if ( event
.ShiftDown() && !IsSingleSel() )
3822 RefreshRow( oldCurrent
);
3824 ChangeCurrentRow( newCurrent
);
3826 // select all the items between the old and the new one
3827 if ( oldCurrent
> newCurrent
)
3829 newCurrent
= oldCurrent
;
3830 oldCurrent
= m_currentRow
;
3833 SelectRows( oldCurrent
, newCurrent
, true );
3834 if (oldCurrent
!=newCurrent
)
3835 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
3839 RefreshRow( oldCurrent
);
3841 // all previously selected items are unselected unless ctrl is held
3842 if ( !event
.ControlDown() )
3843 SelectAllRows(false);
3845 ChangeCurrentRow( newCurrent
);
3847 if ( !event
.ControlDown() )
3849 SelectRow( m_currentRow
, true );
3850 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
3853 RefreshRow( m_currentRow
);
3856 GetOwner()->EnsureVisible( m_currentRow
, -1 );
3859 void wxDataViewMainWindow::OnLeftKey()
3863 TryAdvanceCurrentColumn(NULL
, /*forward=*/false);
3867 wxDataViewTreeNode
* node
= GetTreeNodeByRow(m_currentRow
);
3871 if ( TryAdvanceCurrentColumn(node
, /*forward=*/false) )
3874 // Because TryAdvanceCurrentColumn() return false, we are at the first
3875 // column or using whole-row selection. In this situation, we can use
3876 // the standard TreeView handling of the left key.
3877 if (node
->HasChildren() && node
->IsOpen())
3879 Collapse(m_currentRow
);
3883 // if the node is already closed, we move the selection to its parent
3884 wxDataViewTreeNode
*parent_node
= node
->GetParent();
3888 int parent
= GetRowByItem( parent_node
->GetItem() );
3891 unsigned int row
= m_currentRow
;
3892 SelectRow( row
, false);
3893 SelectRow( parent
, true );
3894 ChangeCurrentRow( parent
);
3895 GetOwner()->EnsureVisible( parent
, -1 );
3896 SendSelectionChangedEvent( parent_node
->GetItem() );
3903 void wxDataViewMainWindow::OnRightKey()
3907 TryAdvanceCurrentColumn(NULL
, /*forward=*/true);
3911 wxDataViewTreeNode
* node
= GetTreeNodeByRow(m_currentRow
);
3915 if ( node
->HasChildren() )
3917 if ( !node
->IsOpen() )
3919 Expand( m_currentRow
);
3923 // if the node is already open, we move the selection to the first child
3924 unsigned int row
= m_currentRow
;
3925 SelectRow( row
, false );
3926 SelectRow( row
+ 1, true );
3927 ChangeCurrentRow( row
+ 1 );
3928 GetOwner()->EnsureVisible( row
+ 1, -1 );
3929 SendSelectionChangedEvent( GetItemByRow(row
+1) );
3934 TryAdvanceCurrentColumn(node
, /*forward=*/true);
3939 bool wxDataViewMainWindow::TryAdvanceCurrentColumn(wxDataViewTreeNode
*node
, bool forward
)
3941 if ( GetOwner()->GetColumnCount() == 0 )
3944 if ( !m_useCellFocus
)
3949 // navigation shouldn't work in branch nodes without other columns:
3950 if ( node
->HasChildren() && !GetModel()->HasContainerColumns(node
->GetItem()) )
3954 if ( m_currentCol
== NULL
|| !m_currentColSetByKeyboard
)
3958 m_currentCol
= GetOwner()->GetColumnAt(1);
3959 m_currentColSetByKeyboard
= true;
3960 RefreshRow(m_currentRow
);
3967 int idx
= GetOwner()->GetColumnIndex(m_currentCol
) + (forward
? +1 : -1);
3969 if ( idx
>= (int)GetOwner()->GetColumnCount() )
3972 GetOwner()->EnsureVisible(m_currentRow
, idx
);
3976 // We are going to the left of the second column. Reset to whole-row
3977 // focus (which means first column would be edited).
3978 m_currentCol
= NULL
;
3979 RefreshRow(m_currentRow
);
3983 m_currentCol
= GetOwner()->GetColumnAt(idx
);
3984 m_currentColSetByKeyboard
= true;
3985 RefreshRow(m_currentRow
);
3989 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
3991 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3993 // let the base handle mouse wheel events.
3998 if(event
.ButtonDown())
4000 // Not skipping button down events would prevent the system from
4001 // setting focus to this window as most (all?) of them do by default,
4002 // so skip it to enable default handling.
4006 int x
= event
.GetX();
4007 int y
= event
.GetY();
4008 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
4009 wxDataViewColumn
*col
= NULL
;
4012 unsigned int cols
= GetOwner()->GetColumnCount();
4014 for (i
= 0; i
< cols
; i
++)
4016 wxDataViewColumn
*c
= GetOwner()->GetColumnAt( i
);
4018 continue; // skip it!
4020 if (x
< xpos
+ c
->GetWidth())
4025 xpos
+= c
->GetWidth();
4028 wxDataViewModel
* const model
= GetModel();
4030 const unsigned int current
= GetLineAt( y
);
4031 const wxDataViewItem item
= GetItemByRow(current
);
4033 // Handle right clicking here, before everything else as context menu
4034 // events should be sent even when we click outside of any item, unlike all
4036 if (event
.RightUp())
4038 wxWindow
*parent
= GetParent();
4039 wxDataViewEvent
le(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
4040 le
.SetEventObject(parent
);
4043 if ( item
.IsOk() && col
)
4046 le
.SetColumn( col
->GetModelColumn() );
4047 le
.SetDataViewColumn( col
);
4050 parent
->ProcessWindowEvent(le
);
4054 #if wxUSE_DRAG_AND_DROP
4055 if (event
.Dragging() || ((m_dragCount
> 0) && event
.Leaving()))
4057 if (m_dragCount
== 0)
4059 // we have to report the raw, physical coords as we want to be
4060 // able to call HitTest(event.m_pointDrag) from the user code to
4061 // get the item being dragged
4062 m_dragStart
= event
.GetPosition();
4066 if ((m_dragCount
< 3) && (event
.Leaving()))
4068 else if (m_dragCount
!= 3)
4071 if (event
.LeftIsDown())
4073 m_owner
->CalcUnscrolledPosition( m_dragStart
.x
, m_dragStart
.y
,
4074 &m_dragStart
.x
, &m_dragStart
.y
);
4075 unsigned int drag_item_row
= GetLineAt( m_dragStart
.y
);
4076 wxDataViewItem itemDragged
= GetItemByRow( drag_item_row
);
4078 // Notify cell about drag
4079 wxDataViewEvent
event( wxEVT_DATAVIEW_ITEM_BEGIN_DRAG
, m_owner
->GetId() );
4080 event
.SetEventObject( m_owner
);
4081 event
.SetItem( itemDragged
);
4082 event
.SetModel( model
);
4083 if (!m_owner
->HandleWindowEvent( event
))
4086 if (!event
.IsAllowed())
4089 wxDataObject
*obj
= event
.GetDataObject();
4093 wxDataViewDropSource
drag( this, drag_item_row
);
4094 drag
.SetData( *obj
);
4095 /* wxDragResult res = */ drag
.DoDragDrop(event
.GetDragFlags());
4104 #endif // wxUSE_DRAG_AND_DROP
4106 // Check if we clicked outside the item area.
4107 if ((current
>= GetRowCount()) || !col
)
4109 // Follow Windows convention here: clicking either left or right (but
4110 // not middle) button clears the existing selection.
4111 if (m_owner
&& (event
.LeftDown() || event
.RightDown()))
4113 if (!GetSelections().empty())
4115 m_owner
->UnselectAll();
4116 SendSelectionChangedEvent(wxDataViewItem());
4123 wxDataViewRenderer
*cell
= col
->GetRenderer();
4124 wxDataViewColumn
* const
4125 expander
= GetExpanderColumnOrFirstOne(GetOwner());
4127 // Test whether the mouse is hovering over the expander (a.k.a tree "+"
4128 // button) and also determine the offset of the real cell start, skipping
4129 // the indentation and the expander itself.
4130 bool hoverOverExpander
= false;
4132 if ((!IsList()) && (expander
== col
))
4134 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
4136 int indent
= node
->GetIndentLevel();
4137 itemOffset
= GetOwner()->GetIndent()*indent
;
4139 if ( node
->HasChildren() )
4141 // we make the rectangle we are looking in a bit bigger than the actual
4142 // visual expander so the user can hit that little thing reliably
4143 wxRect
rect(itemOffset
,
4144 GetLineStart( current
) + (GetLineHeight(current
) - m_lineHeight
)/2,
4145 m_lineHeight
, m_lineHeight
);
4147 if( rect
.Contains(x
, y
) )
4149 // So the mouse is over the expander
4150 hoverOverExpander
= true;
4151 if (m_underMouse
&& m_underMouse
!= node
)
4153 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
4154 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
4156 if (m_underMouse
!= node
)
4158 // wxLogMessage("Do the row: %d", current);
4159 RefreshRow(current
);
4161 m_underMouse
= node
;
4165 // Account for the expander as well, even if this item doesn't have it,
4166 // its parent does so it still counts for the offset.
4167 itemOffset
+= m_lineHeight
;
4169 if (!hoverOverExpander
)
4171 if (m_underMouse
!= NULL
)
4173 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
4174 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
4175 m_underMouse
= NULL
;
4179 bool simulateClick
= false;
4181 if (event
.ButtonDClick())
4183 m_renameTimer
->Stop();
4184 m_lastOnSame
= false;
4187 bool ignore_other_columns
=
4188 ((expander
!= col
) &&
4189 (model
->IsContainer(item
)) &&
4190 (!model
->HasContainerColumns(item
)));
4192 if (event
.LeftDClick())
4194 if(hoverOverExpander
)
4196 // a double click on the expander will be converted into a "simulated" normal click
4197 simulateClick
= true;
4199 else if ( current
== m_lineLastClicked
)
4201 wxWindow
*parent
= GetParent();
4202 wxDataViewEvent
le(wxEVT_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
4204 le
.SetColumn( col
->GetModelColumn() );
4205 le
.SetDataViewColumn( col
);
4206 le
.SetEventObject(parent
);
4207 le
.SetModel(GetModel());
4209 parent
->ProcessWindowEvent(le
);
4214 // The first click was on another item, so don't interpret this as
4215 // a double click, but as a simple click instead
4216 simulateClick
= true;
4220 if (event
.LeftUp() && !hoverOverExpander
)
4222 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
4224 // select single line
4225 SelectAllRows( false );
4226 SelectRow( m_lineSelectSingleOnUp
, true );
4227 SendSelectionChangedEvent( GetItemByRow(m_lineSelectSingleOnUp
) );
4230 // If the user click the expander, we do not do editing even if the column
4231 // with expander are editable
4232 if (m_lastOnSame
&& !ignore_other_columns
)
4234 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
4235 IsCellEditableInMode(item
, col
, wxDATAVIEW_CELL_EDITABLE
) )
4237 m_renameTimer
->Start( 100, true );
4241 m_lastOnSame
= false;
4242 m_lineSelectSingleOnUp
= (unsigned int)-1;
4244 else if(!event
.LeftUp())
4246 // This is necessary, because after a DnD operation in
4247 // from and to ourself, the up event is swallowed by the
4248 // DnD code. So on next non-up event (which means here and
4249 // now) m_lineSelectSingleOnUp should be reset.
4250 m_lineSelectSingleOnUp
= (unsigned int)-1;
4253 if (event
.RightDown())
4255 m_lineBeforeLastClicked
= m_lineLastClicked
;
4256 m_lineLastClicked
= current
;
4258 // If the item is already selected, do not update the selection.
4259 // Multi-selections should not be cleared if a selected item is clicked.
4260 if (!IsRowSelected(current
))
4262 SelectAllRows(false);
4263 const unsigned oldCurrent
= m_currentRow
;
4264 ChangeCurrentRow(current
);
4265 SelectRow(m_currentRow
,true);
4266 RefreshRow(oldCurrent
);
4267 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
4270 else if (event
.MiddleDown())
4274 if((event
.LeftDown() || simulateClick
) && hoverOverExpander
)
4276 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
4278 // hoverOverExpander being true tells us that our node must be
4279 // valid and have children.
4280 // So we don't need any extra checks.
4281 if( node
->IsOpen() )
4286 else if ((event
.LeftDown() || simulateClick
) && !hoverOverExpander
)
4288 m_lineBeforeLastClicked
= m_lineLastClicked
;
4289 m_lineLastClicked
= current
;
4291 unsigned int oldCurrentRow
= m_currentRow
;
4292 bool oldWasSelected
= IsRowSelected(m_currentRow
);
4294 bool cmdModifierDown
= event
.CmdDown();
4295 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
4297 if ( IsSingleSel() || !IsRowSelected(current
) )
4299 SelectAllRows( false );
4300 ChangeCurrentRow(current
);
4301 SelectRow(m_currentRow
,true);
4302 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
4304 else // multi sel & current is highlighted & no mod keys
4306 m_lineSelectSingleOnUp
= current
;
4307 ChangeCurrentRow(current
); // change focus
4310 else // multi sel & either ctrl or shift is down
4312 if (cmdModifierDown
)
4314 ChangeCurrentRow(current
);
4315 ReverseRowSelection(m_currentRow
);
4316 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
4318 else if (event
.ShiftDown())
4320 ChangeCurrentRow(current
);
4322 unsigned int lineFrom
= oldCurrentRow
,
4325 if ( lineTo
< lineFrom
)
4328 lineFrom
= m_currentRow
;
4331 SelectRows(lineFrom
, lineTo
, true);
4332 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
4334 else // !ctrl, !shift
4336 // test in the enclosing if should make it impossible
4337 wxFAIL_MSG( wxT("how did we get here?") );
4341 if (m_currentRow
!= oldCurrentRow
)
4342 RefreshRow( oldCurrentRow
);
4344 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
4346 // Update selection here...
4348 m_currentColSetByKeyboard
= false;
4350 // This flag is used to decide whether we should start editing the item
4351 // label. We do it if the user clicks twice (but not double clicks,
4352 // i.e. simulateClick is false) on the same item but not if the click
4353 // was used for something else already, e.g. selecting the item (so it
4354 // must have been already selected) or giving the focus to the control
4355 // (so it must have had focus already).
4356 m_lastOnSame
= !simulateClick
&& ((col
== oldCurrentCol
) &&
4357 (current
== oldCurrentRow
)) && oldWasSelected
&&
4360 // Call ActivateCell() after everything else as under GTK+
4361 if ( IsCellEditableInMode(item
, col
, wxDATAVIEW_CELL_ACTIVATABLE
) )
4363 // notify cell about click
4364 cell
->PrepareForItem(model
, item
, col
->GetModelColumn());
4366 wxRect
cell_rect( xpos
+ itemOffset
,
4367 GetLineStart( current
),
4368 col
->GetWidth() - itemOffset
,
4369 GetLineHeight( current
) );
4371 // Report position relative to the cell's custom area, i.e.
4372 // not the entire space as given by the control but the one
4373 // used by the renderer after calculation of alignment etc.
4375 // Notice that this results in negative coordinates when clicking
4376 // in the upper left corner of a centre-aligned cell which doesn't
4377 // fill its column entirely so this is somewhat surprising, but we
4378 // do it like this for compatibility with the native GTK+ version,
4381 // adjust the rectangle ourselves to account for the alignment
4382 int align
= cell
->GetAlignment();
4383 if ( align
== wxDVR_DEFAULT_ALIGNMENT
)
4384 align
= wxALIGN_CENTRE
;
4386 wxRect rectItem
= cell_rect
;
4387 const wxSize size
= cell
->GetSize();
4388 if ( size
.x
>= 0 && size
.x
< cell_rect
.width
)
4390 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
4391 rectItem
.x
+= (cell_rect
.width
- size
.x
)/2;
4392 else if ( align
& wxALIGN_RIGHT
)
4393 rectItem
.x
+= cell_rect
.width
- size
.x
;
4394 // else: wxALIGN_LEFT is the default
4397 if ( size
.y
>= 0 && size
.y
< cell_rect
.height
)
4399 if ( align
& wxALIGN_CENTER_VERTICAL
)
4400 rectItem
.y
+= (cell_rect
.height
- size
.y
)/2;
4401 else if ( align
& wxALIGN_BOTTOM
)
4402 rectItem
.y
+= cell_rect
.height
- size
.y
;
4403 // else: wxALIGN_TOP is the default
4406 wxMouseEvent
event2(event
);
4407 event2
.m_x
-= rectItem
.x
;
4408 event2
.m_y
-= rectItem
.y
;
4409 m_owner
->CalcUnscrolledPosition(event2
.m_x
, event2
.m_y
, &event2
.m_x
, &event2
.m_y
);
4411 /* ignore ret */ cell
->WXActivateCell
4416 col
->GetModelColumn(),
4423 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
4427 if (HasCurrentRow())
4433 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
4437 if (HasCurrentRow())
4443 void wxDataViewMainWindow::OnColumnsCountChanged()
4445 int editableCount
= 0;
4447 const unsigned cols
= GetOwner()->GetColumnCount();
4448 for ( unsigned i
= 0; i
< cols
; i
++ )
4450 wxDataViewColumn
*c
= GetOwner()->GetColumnAt(i
);
4451 if ( c
->IsHidden() )
4453 if ( c
->GetRenderer()->GetMode() != wxDATAVIEW_CELL_INERT
)
4457 m_useCellFocus
= (editableCount
> 1);
4462 //-----------------------------------------------------------------------------
4464 //-----------------------------------------------------------------------------
4466 WX_DEFINE_LIST(wxDataViewColumnList
)
4468 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4469 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
4470 EVT_SIZE(wxDataViewCtrl::OnSize
)
4473 wxDataViewCtrl::~wxDataViewCtrl()
4476 GetModel()->RemoveNotifier( m_notifier
);
4479 m_colsBestWidths
.clear();
4482 void wxDataViewCtrl::Init()
4484 m_cols
.DeleteContents(true);
4487 // No sorting column at start
4488 m_sortingColumnIdx
= wxNOT_FOUND
;
4490 m_headerArea
= NULL
;
4491 m_clientArea
= NULL
;
4493 m_colsDirty
= false;
4496 bool wxDataViewCtrl::Create(wxWindow
*parent
,
4501 const wxValidator
& validator
,
4502 const wxString
& name
)
4504 // if ( (style & wxBORDER_MASK) == 0)
4505 // style |= wxBORDER_SUNKEN;
4509 if (!wxControl::Create( parent
, id
, pos
, size
,
4510 style
| wxScrolledWindowStyle
, validator
, name
))
4513 SetInitialSize(size
);
4516 MacSetClipChildren( true );
4519 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
4521 // We use the cursor keys for moving the selection, not scrolling, so call
4522 // this method to ensure wxScrollHelperEvtHandler doesn't catch all
4523 // keyboard events forwarded to us from wxListMainWindow.
4524 DisableKeyboardScrolling();
4526 if (HasFlag(wxDV_NO_HEADER
))
4527 m_headerArea
= NULL
;
4529 m_headerArea
= new wxDataViewHeaderWindow(this);
4531 SetTargetWindow( m_clientArea
);
4533 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
4535 sizer
->Add( m_headerArea
, 0, wxGROW
);
4536 sizer
->Add( m_clientArea
, 1, wxGROW
);
4542 wxBorder
wxDataViewCtrl::GetDefaultBorder() const
4544 return wxBORDER_THEME
;
4548 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
4552 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
4555 // we need to process arrows ourselves for scrolling
4556 if ( nMsg
== WM_GETDLGCODE
)
4558 rc
|= DLGC_WANTARROWS
;
4566 wxSize
wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
4568 wxSize newsize
= size
;
4569 if (!HasFlag(wxDV_NO_HEADER
) && (m_headerArea
))
4570 newsize
.y
-= m_headerArea
->GetSize().y
;
4575 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
4577 // We need to override OnSize so that our scrolled
4578 // window a) does call Layout() to use sizers for
4579 // positioning the controls but b) does not query
4580 // the sizer for their size and use that for setting
4581 // the scrollable area as set that ourselves by
4582 // calling SetScrollbar() further down.
4588 // We must redraw the headers if their height changed. Normally this
4589 // shouldn't happen as the control shouldn't let itself be resized beneath
4590 // its minimal height but avoid the display artefacts that appear if it
4591 // does happen, e.g. because there is really not enough vertical space.
4592 if ( !HasFlag(wxDV_NO_HEADER
) && m_headerArea
&&
4593 m_headerArea
->GetSize().y
<= m_headerArea
->GetBestSize(). y
)
4595 m_headerArea
->Refresh();
4599 void wxDataViewCtrl::SetFocus()
4602 m_clientArea
->SetFocus();
4605 bool wxDataViewCtrl::SetFont(const wxFont
& font
)
4607 if (!wxControl::SetFont(font
))
4611 m_headerArea
->SetFont(font
);
4615 m_clientArea
->SetFont(font
);
4616 m_clientArea
->SetRowHeight(m_clientArea
->GetDefaultRowHeight());
4619 if (m_headerArea
|| m_clientArea
)
4621 InvalidateColBestWidths();
4630 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4632 if (!wxDataViewCtrlBase::AssociateModel( model
))
4637 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
4638 model
->AddNotifier( m_notifier
);
4640 else if (m_notifier
)
4642 m_notifier
->Cleared();
4646 m_clientArea
->DestroyTree();
4650 m_clientArea
->BuildTree(model
);
4653 m_clientArea
->UpdateDisplay();
4658 #if wxUSE_DRAG_AND_DROP
4660 bool wxDataViewCtrl::EnableDragSource( const wxDataFormat
&format
)
4662 return m_clientArea
->EnableDragSource( format
);
4665 bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat
&format
)
4667 return m_clientArea
->EnableDropTarget( format
);
4670 #endif // wxUSE_DRAG_AND_DROP
4672 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4674 if (!wxDataViewCtrlBase::AppendColumn(col
))
4677 m_cols
.Append( col
);
4678 m_colsBestWidths
.push_back(CachedColWidthInfo());
4679 OnColumnsCountChanged();
4683 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4685 if (!wxDataViewCtrlBase::PrependColumn(col
))
4688 m_cols
.Insert( col
);
4689 m_colsBestWidths
.insert(m_colsBestWidths
.begin(), CachedColWidthInfo());
4690 OnColumnsCountChanged();
4694 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4696 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4699 m_cols
.Insert( pos
, col
);
4700 m_colsBestWidths
.insert(m_colsBestWidths
.begin() + pos
, CachedColWidthInfo());
4701 OnColumnsCountChanged();
4705 void wxDataViewCtrl::OnColumnChange(unsigned int idx
)
4708 m_headerArea
->UpdateColumn(idx
);
4710 m_clientArea
->UpdateDisplay();
4713 void wxDataViewCtrl::OnColumnsCountChanged()
4716 m_headerArea
->SetColumnCount(GetColumnCount());
4718 m_clientArea
->OnColumnsCountChanged();
4721 void wxDataViewCtrl::DoSetExpanderColumn()
4723 wxDataViewColumn
* column
= GetExpanderColumn();
4726 int index
= GetColumnIndex(column
);
4727 if ( index
!= wxNOT_FOUND
)
4728 InvalidateColBestWidth(index
);
4731 m_clientArea
->UpdateDisplay();
4734 void wxDataViewCtrl::DoSetIndent()
4736 m_clientArea
->UpdateDisplay();
4739 unsigned int wxDataViewCtrl::GetColumnCount() const
4741 return m_cols
.GetCount();
4744 bool wxDataViewCtrl::SetRowHeight( int lineHeight
)
4746 if ( !m_clientArea
)
4749 m_clientArea
->SetRowHeight(lineHeight
);
4754 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int idx
) const
4759 wxDataViewColumn
*wxDataViewCtrl::GetColumnAt(unsigned int pos
) const
4761 // columns can't be reordered if there is no header window which allows
4763 const unsigned idx
= m_headerArea
? m_headerArea
->GetColumnsOrder()[pos
]
4766 return GetColumn(idx
);
4769 int wxDataViewCtrl::GetColumnIndex(const wxDataViewColumn
*column
) const
4771 const unsigned count
= m_cols
.size();
4772 for ( unsigned n
= 0; n
< count
; n
++ )
4774 if ( m_cols
[n
] == column
)
4781 int wxDataViewCtrl::GetModelColumnIndex( unsigned int model_column
) const
4783 const int count
= GetColumnCount();
4784 for ( int index
= 0; index
< count
; index
++ )
4786 wxDataViewColumn
* column
= GetColumn(index
);
4787 if ( column
->GetModelColumn() == model_column
)
4793 unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx
) const
4795 if ( m_colsBestWidths
[idx
].width
!= 0 )
4796 return m_colsBestWidths
[idx
].width
;
4798 const int count
= m_clientArea
->GetRowCount();
4799 wxDataViewColumn
*column
= GetColumn(idx
);
4800 wxDataViewRenderer
*renderer
=
4801 const_cast<wxDataViewRenderer
*>(column
->GetRenderer());
4803 class MaxWidthCalculator
4806 MaxWidthCalculator(const wxDataViewCtrl
*dvc
,
4807 wxDataViewMainWindow
*clientArea
,
4808 wxDataViewRenderer
*renderer
,
4809 const wxDataViewModel
*model
,
4810 unsigned int model_column
,
4814 m_clientArea(clientArea
),
4815 m_renderer(renderer
),
4817 m_model_column(model_column
),
4818 m_expanderSize(expanderSize
)
4821 int index
= dvc
->GetModelColumnIndex( model_column
);
4822 wxDataViewColumn
* column
= index
== wxNOT_FOUND
? NULL
: dvc
->GetColumn(index
);
4824 !clientArea
->IsList() &&
4826 GetExpanderColumnOrFirstOne(const_cast<wxDataViewCtrl
*>(dvc
)) == column
);
4829 void UpdateWithWidth(int width
)
4831 m_width
= wxMax(m_width
, width
);
4834 void UpdateWithRow(int row
)
4837 wxDataViewItem item
;
4839 if ( m_isExpanderCol
)
4841 wxDataViewTreeNode
*node
= m_clientArea
->GetTreeNodeByRow(row
);
4842 item
= node
->GetItem();
4843 indent
= m_dvc
->GetIndent() * node
->GetIndentLevel() + m_expanderSize
;
4847 item
= m_clientArea
->GetItemByRow(row
);
4850 m_renderer
->PrepareForItem(m_model
, item
, m_model_column
);
4851 m_width
= wxMax(m_width
, m_renderer
->GetSize().x
+ indent
);
4854 int GetMaxWidth() const { return m_width
; }
4858 const wxDataViewCtrl
*m_dvc
;
4859 wxDataViewMainWindow
*m_clientArea
;
4860 wxDataViewRenderer
*m_renderer
;
4861 const wxDataViewModel
*m_model
;
4862 unsigned m_model_column
;
4863 bool m_isExpanderCol
;
4867 MaxWidthCalculator
calculator(this, m_clientArea
, renderer
,
4868 GetModel(), column
->GetModelColumn(),
4869 m_clientArea
->GetRowHeight());
4871 calculator
.UpdateWithWidth(column
->GetMinWidth());
4874 calculator
.UpdateWithWidth(m_headerArea
->GetColumnTitleWidth(*column
));
4876 // The code below deserves some explanation. For very large controls, we
4877 // simply can't afford to calculate sizes for all items, it takes too
4878 // long. So the best we can do is to check the first and the last N/2
4879 // items in the control for some sufficiently large N and calculate best
4880 // sizes from that. That can result in the calculated best width being too
4881 // small for some outliers, but it's better to get slightly imperfect
4882 // result than to wait several seconds after every update. To avoid highly
4883 // visible miscalculations, we also include all currently visible items
4884 // no matter what. Finally, the value of N is determined dynamically by
4885 // measuring how much time we spent on the determining item widths so far.
4888 int top_part_end
= count
;
4889 static const long CALC_TIMEOUT
= 20/*ms*/;
4890 // don't call wxStopWatch::Time() too often
4891 static const unsigned CALC_CHECK_FREQ
= 100;
4894 // use some hard-coded limit, that's the best we can do without timer
4895 int top_part_end
= wxMin(500, count
);
4896 #endif // wxUSE_STOPWATCH/!wxUSE_STOPWATCH
4900 for ( row
= 0; row
< top_part_end
; row
++ )
4903 if ( row
% CALC_CHECK_FREQ
== CALC_CHECK_FREQ
-1 &&
4904 timer
.Time() > CALC_TIMEOUT
)
4906 #endif // wxUSE_STOPWATCH
4907 calculator
.UpdateWithRow(row
);
4910 // row is the first unmeasured item now; that's our value of N/2
4916 // add bottom N/2 items now:
4917 const int bottom_part_start
= wxMax(row
, count
- row
);
4918 for ( row
= bottom_part_start
; row
< count
; row
++ )
4920 calculator
.UpdateWithRow(row
);
4923 // finally, include currently visible items in the calculation:
4924 const wxPoint origin
= CalcUnscrolledPosition(wxPoint(0, 0));
4925 int first_visible
= m_clientArea
->GetLineAt(origin
.y
);
4926 int last_visible
= m_clientArea
->GetLineAt(origin
.y
+ GetClientSize().y
);
4928 first_visible
= wxMax(first_visible
, top_part_end
);
4929 last_visible
= wxMin(bottom_part_start
, last_visible
);
4931 for ( row
= first_visible
; row
< last_visible
; row
++ )
4933 calculator
.UpdateWithRow(row
);
4936 wxLogTrace("dataview",
4937 "determined best size from %d top, %d bottom plus %d more visible items out of %d total",
4939 count
- bottom_part_start
,
4940 wxMax(0, last_visible
- first_visible
),
4944 int max_width
= calculator
.GetMaxWidth();
4945 if ( max_width
> 0 )
4946 max_width
+= 2 * PADDING_RIGHTLEFT
;
4948 const_cast<wxDataViewCtrl
*>(this)->m_colsBestWidths
[idx
].width
= max_width
;
4952 void wxDataViewCtrl::ColumnMoved(wxDataViewColumn
* WXUNUSED(col
),
4953 unsigned int WXUNUSED(new_pos
))
4955 // do _not_ reorder m_cols elements here, they should always be in the
4956 // order in which columns were added, we only display the columns in
4958 m_clientArea
->UpdateDisplay();
4961 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4963 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
4967 m_colsBestWidths
.erase(m_colsBestWidths
.begin() + GetColumnIndex(column
));
4970 if ( m_clientArea
->GetCurrentColumn() == column
)
4971 m_clientArea
->ClearCurrentColumn();
4973 OnColumnsCountChanged();
4978 bool wxDataViewCtrl::ClearColumns()
4980 SetExpanderColumn(NULL
);
4982 m_colsBestWidths
.clear();
4984 m_clientArea
->ClearCurrentColumn();
4986 OnColumnsCountChanged();
4991 void wxDataViewCtrl::InvalidateColBestWidth(int idx
)
4993 m_colsBestWidths
[idx
].width
= 0;
4994 m_colsBestWidths
[idx
].dirty
= true;
4998 void wxDataViewCtrl::InvalidateColBestWidths()
5000 // mark all columns as dirty:
5001 m_colsBestWidths
.clear();
5002 m_colsBestWidths
.resize(m_cols
.size());
5006 void wxDataViewCtrl::UpdateColWidths()
5008 m_colsDirty
= false;
5010 if ( !m_headerArea
)
5013 const unsigned len
= m_colsBestWidths
.size();
5014 for ( unsigned i
= 0; i
< len
; i
++ )
5016 // Note that we have to have an explicit 'dirty' flag here instead of
5017 // checking if the width==0, as is done in GetBestColumnWidth().
5019 // Testing width==0 wouldn't work correctly if some code called
5020 // GetWidth() after col. width invalidation but before
5021 // wxDataViewCtrl::UpdateColWidths() was called at idle time. This
5022 // would result in the header's column width getting out of sync with
5023 // the control itself.
5024 if ( m_colsBestWidths
[i
].dirty
)
5026 m_headerArea
->UpdateColumn(i
);
5027 m_colsBestWidths
[i
].dirty
= false;
5032 void wxDataViewCtrl::OnInternalIdle()
5034 wxDataViewCtrlBase::OnInternalIdle();
5040 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
5042 unsigned int len
= GetColumnCount();
5043 for ( unsigned int i
= 0; i
< len
; i
++ )
5045 wxDataViewColumn
* col
= GetColumnAt(i
);
5053 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
5055 return m_sortingColumnIdx
== wxNOT_FOUND
? NULL
5056 : GetColumn(m_sortingColumnIdx
);
5059 wxDataViewItem
wxDataViewCtrl::DoGetCurrentItem() const
5061 return GetItemByRow(m_clientArea
->GetCurrentRow());
5064 void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem
& item
)
5066 const int row
= m_clientArea
->GetRowByItem(item
);
5068 const unsigned oldCurrent
= m_clientArea
->GetCurrentRow();
5069 if ( static_cast<unsigned>(row
) != oldCurrent
)
5071 m_clientArea
->ChangeCurrentRow(row
);
5072 m_clientArea
->RefreshRow(oldCurrent
);
5073 m_clientArea
->RefreshRow(row
);
5077 wxDataViewColumn
*wxDataViewCtrl::GetCurrentColumn() const
5079 return m_clientArea
->GetCurrentColumn();
5082 int wxDataViewCtrl::GetSelectedItemsCount() const
5084 return m_clientArea
->GetSelections().size();
5087 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
5090 const wxDataViewSelection
& selections
= m_clientArea
->GetSelections();
5092 const size_t len
= selections
.size();
5093 for ( size_t i
= 0; i
< len
; i
++ )
5095 wxDataViewItem item
= m_clientArea
->GetItemByRow(selections
[i
]);
5102 wxFAIL_MSG( "invalid item in selection - bad internal state" );
5109 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
5111 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
5113 wxDataViewItem last_parent
;
5115 int len
= sel
.GetCount();
5116 for( int i
= 0; i
< len
; i
++ )
5118 wxDataViewItem item
= sel
[i
];
5119 wxDataViewItem parent
= GetModel()->GetParent( item
);
5122 if (parent
!= last_parent
)
5123 ExpandAncestors(item
);
5126 last_parent
= parent
;
5127 int row
= m_clientArea
->GetRowByItem( item
);
5129 selection
.Add( static_cast<unsigned int>(row
) );
5132 m_clientArea
->SetSelections( selection
);
5135 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
5137 ExpandAncestors( item
);
5139 int row
= m_clientArea
->GetRowByItem( item
);
5142 // Unselect all rows before select another in the single select mode
5143 if (m_clientArea
->IsSingleSel())
5144 m_clientArea
->SelectAllRows(false);
5146 m_clientArea
->SelectRow(row
, true);
5148 // Also set focus to the selected item
5149 m_clientArea
->ChangeCurrentRow( row
);
5153 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
5155 int row
= m_clientArea
->GetRowByItem( item
);
5157 m_clientArea
->SelectRow(row
, false);
5160 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
5162 int row
= m_clientArea
->GetRowByItem( item
);
5165 return m_clientArea
->IsRowSelected(row
);
5170 void wxDataViewCtrl::SetAlternateRowColour(const wxColour
& colour
)
5172 m_alternateRowColour
= colour
;
5175 void wxDataViewCtrl::SelectAll()
5177 m_clientArea
->SelectAllRows(true);
5180 void wxDataViewCtrl::UnselectAll()
5182 m_clientArea
->SelectAllRows(false);
5185 void wxDataViewCtrl::EnsureVisible( int row
, int column
)
5189 if( row
> (int) m_clientArea
->GetRowCount() )
5190 row
= m_clientArea
->GetRowCount();
5192 int first
= m_clientArea
->GetFirstVisibleRow();
5193 int last
= m_clientArea
->GetLastVisibleRow();
5195 m_clientArea
->ScrollTo( row
, column
);
5196 else if( row
> last
)
5197 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
5199 m_clientArea
->ScrollTo( first
, column
);
5202 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
5204 ExpandAncestors( item
);
5206 m_clientArea
->RecalculateDisplay();
5208 int row
= m_clientArea
->GetRowByItem(item
);
5211 if( column
== NULL
)
5212 EnsureVisible(row
, -1);
5214 EnsureVisible( row
, GetColumnIndex(column
) );
5219 void wxDataViewCtrl::HitTest( const wxPoint
& point
, wxDataViewItem
& item
,
5220 wxDataViewColumn
* &column
) const
5222 m_clientArea
->HitTest(point
, item
, column
);
5225 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
& item
,
5226 const wxDataViewColumn
* column
) const
5228 return m_clientArea
->GetItemRect(item
, column
);
5231 wxDataViewItem
wxDataViewCtrl::GetItemByRow( unsigned int row
) const
5233 return m_clientArea
->GetItemByRow( row
);
5236 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem
& item
) const
5238 return m_clientArea
->GetRowByItem( item
);
5241 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
5243 ExpandAncestors( item
);
5245 int row
= m_clientArea
->GetRowByItem( item
);
5248 m_clientArea
->Expand(row
);
5249 InvalidateColBestWidths();
5253 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
5255 int row
= m_clientArea
->GetRowByItem( item
);
5258 m_clientArea
->Collapse(row
);
5259 InvalidateColBestWidths();
5263 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
5265 int row
= m_clientArea
->GetRowByItem( item
);
5267 return m_clientArea
->IsExpanded(row
);
5271 void wxDataViewCtrl::EditItem(const wxDataViewItem
& item
, const wxDataViewColumn
*column
)
5273 wxCHECK_RET( item
.IsOk(), "invalid item" );
5274 wxCHECK_RET( column
, "no column provided" );
5276 m_clientArea
->StartEditing(item
, column
);
5279 #endif // !wxUSE_GENERICDATAVIEWCTRL
5281 #endif // wxUSE_DATAVIEWCTRL