1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/datavgen.cpp
3 // Purpose: wxDataViewCtrl generic implementation
4 // Author: Robert Roebling
5 // Modified by: Francesco Montorsi, Guru Kathiresan, Bo Yang
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_DATAVIEWCTRL
20 #include "wx/dataview.h"
22 #ifdef wxUSE_GENERICDATAVIEWCTRL
26 #include "wx/msw/private.h"
27 #include "wx/msw/wrapwin.h"
28 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/msgdlg.h"
36 #include "wx/dcscreen.h"
39 #include "wx/stockitem.h"
40 #include "wx/calctrl.h"
41 #include "wx/popupwin.h"
42 #include "wx/renderer.h"
43 #include "wx/dcbuffer.h"
46 #include "wx/listimpl.cpp"
47 #include "wx/imaglist.h"
48 #include "wx/headerctrl.h"
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
56 static const int SCROLL_UNIT_X
= 15;
58 // the cell padding on the left/right
59 static const int PADDING_RIGHTLEFT
= 3;
61 // the expander space margin
62 static const int EXPANDER_MARGIN
= 4;
65 static const int EXPANDER_OFFSET
= 4;
67 static const int EXPANDER_OFFSET
= 1;
70 //Below is the compare stuff
71 //For the generic implements, both the leaf nodes and the nodes are sorted for fast search when needed
72 static wxDataViewModel
* g_model
;
73 static int g_column
= -2;
74 static bool g_asending
= true;
76 //-----------------------------------------------------------------------------
77 // wxDataViewHeaderWindow
78 //-----------------------------------------------------------------------------
80 class wxDataViewHeaderWindow
: public wxHeaderCtrl
83 wxDataViewHeaderWindow(wxDataViewCtrl
*parent
)
84 : wxHeaderCtrl(parent
)
88 wxDataViewCtrl
*GetOwner() const
89 { return static_cast<wxDataViewCtrl
*>(GetParent()); }
92 virtual wxHeaderColumnBase
& GetColumn(unsigned int idx
)
94 return *(GetOwner()->GetColumn(idx
));
97 bool SendEvent(wxEventType type
, unsigned int n
)
99 wxDataViewCtrl
* const owner
= GetOwner();
100 wxDataViewEvent
event(type
, owner
->GetId());
102 event
.SetEventObject(owner
);
104 event
.SetDataViewColumn(owner
->GetColumn(n
));
105 event
.SetModel(owner
->GetModel());
107 // for events created by wxDataViewHeaderWindow the
108 // row / value fields are not valid
109 return owner
->GetEventHandler()->ProcessEvent(event
);
112 void OnClick(wxHeaderCtrlEvent
& event
)
114 if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
,
119 void OnRClick(wxHeaderCtrlEvent
& event
)
121 if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
126 DECLARE_EVENT_TABLE()
127 DECLARE_NO_COPY_CLASS(wxDataViewHeaderWindow
)
130 BEGIN_EVENT_TABLE(wxDataViewHeaderWindow
, wxHeaderCtrl
)
131 EVT_HEADER_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnClick
)
132 EVT_HEADER_RIGHT_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnRClick
)
135 //-----------------------------------------------------------------------------
136 // wxDataViewRenameTimer
137 //-----------------------------------------------------------------------------
139 class wxDataViewRenameTimer
: public wxTimer
142 wxDataViewMainWindow
*m_owner
;
145 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
149 //-----------------------------------------------------------------------------
150 // wxDataViewTreeNode
151 //-----------------------------------------------------------------------------
152 class wxDataViewTreeNode
;
153 WX_DEFINE_ARRAY( wxDataViewTreeNode
*, wxDataViewTreeNodes
);
154 WX_DEFINE_ARRAY( void* , wxDataViewTreeLeaves
);
156 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
, wxDataViewTreeNode
** node2
);
157 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
);
159 class wxDataViewTreeNode
162 wxDataViewTreeNode( wxDataViewTreeNode
* parent
= NULL
)
169 m_hasChildren
= false;
173 ~wxDataViewTreeNode()
177 wxDataViewTreeNode
* GetParent() const { return m_parent
; }
178 void SetParent( wxDataViewTreeNode
* parent
) { m_parent
= parent
; }
179 wxDataViewTreeNodes
& GetNodes() { return m_nodes
; }
180 wxDataViewTreeLeaves
& GetChildren() { return m_leaves
; }
182 void AddNode( wxDataViewTreeNode
* node
)
184 m_leaves
.Add( node
->GetItem().GetID() );
186 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
189 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
191 void AddLeaf( void * leaf
)
193 m_leaves
.Add( leaf
);
195 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
198 wxDataViewItem
& GetItem() { return m_item
; }
199 const wxDataViewItem
& GetItem() const { return m_item
; }
200 void SetItem( const wxDataViewItem
& item
) { m_item
= item
; }
202 unsigned int GetChildrenNumber() const { return m_leaves
.GetCount(); }
203 unsigned int GetNodeNumber() const { return m_nodes
.GetCount(); }
204 int GetIndentLevel() const
207 const wxDataViewTreeNode
* node
= this;
208 while( node
->GetParent()->GetParent() != NULL
)
210 node
= node
->GetParent();
223 int len
= m_nodes
.GetCount();
225 for ( int i
= 0;i
< len
; i
++)
226 sum
+= m_nodes
[i
]->GetSubTreeCount();
228 sum
+= m_leaves
.GetCount();
231 ChangeSubTreeCount(-sum
);
237 ChangeSubTreeCount(sum
);
240 bool HasChildren() const { return m_hasChildren
; }
241 void SetHasChildren( bool has
){ m_hasChildren
= has
; }
243 void SetSubTreeCount( int num
) { m_subTreeCount
= num
; }
244 int GetSubTreeCount() const { return m_subTreeCount
; }
245 void ChangeSubTreeCount( int num
)
249 m_subTreeCount
+= num
;
251 m_parent
->ChangeSubTreeCount(num
);
258 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
259 int len
= m_nodes
.GetCount();
260 for (int i
= 0; i
< len
; i
++)
261 m_nodes
[i
]->Resort();
262 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
267 wxDataViewTreeNode
*m_parent
;
268 wxDataViewTreeNodes m_nodes
;
269 wxDataViewTreeLeaves m_leaves
;
270 wxDataViewItem m_item
;
276 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
, wxDataViewTreeNode
** node2
)
278 return g_model
->Compare( (*node1
)->GetItem(), (*node2
)->GetItem(), g_column
, g_asending
);
281 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
)
283 return g_model
->Compare( *id1
, *id2
, g_column
, g_asending
);
288 //-----------------------------------------------------------------------------
289 // wxDataViewMainWindow
290 //-----------------------------------------------------------------------------
292 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
,
294 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
295 WX_DEFINE_LIST(ItemList
)
297 class wxDataViewMainWindow
: public wxWindow
300 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
302 const wxPoint
&pos
= wxDefaultPosition
,
303 const wxSize
&size
= wxDefaultSize
,
304 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
305 virtual ~wxDataViewMainWindow();
307 bool IsVirtualList() const { return m_root
== NULL
; }
309 // notifications from wxDataViewModel
310 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
311 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
312 bool ItemChanged( const wxDataViewItem
&item
);
313 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
317 if (!IsVirtualList())
327 g_model
= GetOwner()->GetModel();
328 wxDataViewColumn
* col
= GetOwner()->GetSortingColumn();
331 if (g_model
->HasDefaultCompare())
339 g_column
= col
->GetModelColumn();
340 g_asending
= col
->IsSortOrderAscending();
343 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
344 wxDataViewCtrl
*GetOwner() { return m_owner
; }
345 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
347 void OnPaint( wxPaintEvent
&event
);
348 void OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
);
349 void OnChar( wxKeyEvent
&event
);
350 void OnMouse( wxMouseEvent
&event
);
351 void OnSetFocus( wxFocusEvent
&event
);
352 void OnKillFocus( wxFocusEvent
&event
);
354 void UpdateDisplay();
355 void RecalculateDisplay();
356 void OnInternalIdle();
358 void OnRenameTimer();
360 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
361 void ScrollTo( int rows
, int column
);
363 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
364 void ChangeCurrentRow( unsigned int row
);
366 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
367 bool IsEmpty() { return GetRowCount() == 0; }
369 int GetCountPerPage() const;
370 int GetEndOfLastCol() const;
371 unsigned int GetFirstVisibleRow() const;
372 //I change this method to un const because in the tree view, the displaying number of the tree are changing along with the expanding/collapsing of the tree nodes
373 unsigned int GetLastVisibleRow();
374 unsigned int GetRowCount();
376 wxDataViewItem
GetSelection() const;
377 wxDataViewSelection
GetSelections(){ return m_selection
; }
378 void SetSelections( const wxDataViewSelection
& sel
) { m_selection
= sel
; UpdateDisplay(); }
379 void Select( const wxArrayInt
& aSelections
);
380 void SelectAllRows( bool on
);
381 void SelectRow( unsigned int row
, bool on
);
382 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
383 void ReverseRowSelection( unsigned int row
);
384 bool IsRowSelected( unsigned int row
);
385 void SendSelectionChangedEvent( const wxDataViewItem
& item
);
387 void RefreshRow( unsigned int row
);
388 void RefreshRows( unsigned int from
, unsigned int to
);
389 void RefreshRowsAfter( unsigned int firstRow
);
391 // returns the colour to be used for drawing the rules
392 wxColour
GetRuleColour() const
394 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
397 wxRect
GetLineRect( unsigned int row
) const;
399 int GetLineStart( unsigned int row
) const; // row * m_lineHeight in fixed mode
400 int GetLineHeight( unsigned int row
) const; // m_lineHeight in fixed mode
401 int GetLineAt( unsigned int y
) const; // y / m_lineHeight in fixed mode
403 //Some useful functions for row and item mapping
404 wxDataViewItem
GetItemByRow( unsigned int row
) const;
405 int GetRowByItem( const wxDataViewItem
& item
) const;
407 //Methods for building the mapping tree
408 void BuildTree( wxDataViewModel
* model
);
410 void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
);
411 wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
);
413 void Expand( unsigned int row
) { OnExpanding( row
); }
414 void Collapse( unsigned int row
) { OnCollapsing( row
); }
416 wxDataViewTreeNode
* GetTreeNodeByRow( unsigned int row
) const;
417 //We did not need this temporarily
418 //wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
420 int RecalculateCount();
422 wxDataViewEvent
SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
);
423 void OnExpanding( unsigned int row
);
424 void OnCollapsing( unsigned int row
);
426 wxDataViewTreeNode
* FindNode( const wxDataViewItem
& item
);
429 wxDataViewCtrl
*m_owner
;
433 wxDataViewColumn
*m_currentCol
;
434 unsigned int m_currentRow
;
435 wxDataViewSelection m_selection
;
437 wxDataViewRenameTimer
*m_renameTimer
;
445 // for double click logic
446 unsigned int m_lineLastClicked
,
447 m_lineBeforeLastClicked
,
448 m_lineSelectSingleOnUp
;
450 // the pen used to draw horiz/vertical rules
453 // the pen used to draw the expander and the lines
456 //This is the tree structure of the model
457 wxDataViewTreeNode
* m_root
;
459 //This is the tree node under the cursor
460 wxDataViewTreeNode
* m_underMouse
;
462 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
463 DECLARE_EVENT_TABLE()
466 // ---------------------------------------------------------
467 // wxGenericDataViewModelNotifier
468 // ---------------------------------------------------------
470 class wxGenericDataViewModelNotifier
: public wxDataViewModelNotifier
473 wxGenericDataViewModelNotifier( wxDataViewMainWindow
*mainWindow
)
474 { m_mainWindow
= mainWindow
; }
476 virtual bool ItemAdded( const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
477 { return m_mainWindow
->ItemAdded( parent
, item
); }
478 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
479 { return m_mainWindow
->ItemDeleted( parent
, item
); }
480 virtual bool ItemChanged( const wxDataViewItem
& item
)
481 { return m_mainWindow
->ItemChanged(item
); }
482 virtual bool ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
483 { return m_mainWindow
->ValueChanged( item
, col
); }
484 virtual bool Cleared()
485 { return m_mainWindow
->Cleared(); }
486 virtual void Resort()
487 { m_mainWindow
->Resort(); }
489 wxDataViewMainWindow
*m_mainWindow
;
492 // ---------------------------------------------------------
493 // wxDataViewRenderer
494 // ---------------------------------------------------------
496 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
498 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
499 wxDataViewCellMode mode
,
501 wxDataViewRendererBase( varianttype
, mode
, align
)
510 wxDataViewRenderer::~wxDataViewRenderer()
516 wxDC
*wxDataViewRenderer::GetDC()
520 if (GetOwner() == NULL
)
522 if (GetOwner()->GetOwner() == NULL
)
524 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
530 void wxDataViewRenderer::SetAlignment( int align
)
535 int wxDataViewRenderer::GetAlignment() const
540 int wxDataViewRenderer::CalculateAlignment() const
542 if (m_align
== wxDVR_DEFAULT_ALIGNMENT
)
544 if (GetOwner() == NULL
)
545 return wxALIGN_LEFT
| wxALIGN_CENTRE_VERTICAL
;
547 return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
553 // ---------------------------------------------------------
554 // wxDataViewCustomRenderer
555 // ---------------------------------------------------------
557 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
559 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
560 wxDataViewCellMode mode
, int align
) :
561 wxDataViewRenderer( varianttype
, mode
, align
)
565 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
567 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
568 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
569 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
570 view
->GetForegroundColour();
571 dc
->SetTextForeground(col
);
572 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
575 // ---------------------------------------------------------
576 // wxDataViewTextRenderer
577 // ---------------------------------------------------------
579 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
581 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
582 wxDataViewCellMode mode
, int align
) :
583 wxDataViewCustomRenderer( varianttype
, mode
, align
)
587 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
589 m_text
= value
.GetString();
594 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
599 bool wxDataViewTextRenderer::HasEditorCtrl()
604 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
605 wxRect labelRect
, const wxVariant
&value
)
607 return new wxTextCtrl( parent
, wxID_ANY
, value
,
608 wxPoint(labelRect
.x
,labelRect
.y
),
609 wxSize(labelRect
.width
,labelRect
.height
) );
612 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
614 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
615 value
= text
->GetValue();
619 bool wxDataViewTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
621 RenderText( m_text
, 0, cell
, dc
, state
);
625 wxSize
wxDataViewTextRenderer::GetSize() const
627 const wxDataViewCtrl
*view
= GetView();
631 view
->GetTextExtent( m_text
, &x
, &y
);
632 return wxSize( x
, y
);
634 return wxSize(80,20);
637 // ---------------------------------------------------------
638 // wxDataViewTextRendererAttr
639 // ---------------------------------------------------------
641 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
, wxDataViewTextRenderer
)
643 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
644 wxDataViewCellMode mode
, int align
) :
645 wxDataViewTextRenderer( varianttype
, mode
, align
)
650 bool wxDataViewTextRendererAttr::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
657 if (m_attr
.HasColour())
659 colour
= dc
->GetTextForeground();
660 dc
->SetTextForeground( m_attr
.GetColour() );
663 if (m_attr
.GetBold() || m_attr
.GetItalic())
665 font
= dc
->GetFont();
666 wxFont myfont
= font
;
667 if (m_attr
.GetBold())
668 myfont
.SetWeight( wxFONTWEIGHT_BOLD
);
669 if (m_attr
.GetItalic())
670 myfont
.SetStyle( wxFONTSTYLE_ITALIC
);
671 dc
->SetFont( myfont
);
675 dc
->DrawText( m_text
, cell
.x
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
680 if (m_attr
.HasColour())
681 dc
->SetTextForeground( colour
);
683 if (m_attr
.GetBold() || m_attr
.GetItalic())
691 // ---------------------------------------------------------
692 // wxDataViewBitmapRenderer
693 // ---------------------------------------------------------
695 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
697 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
698 wxDataViewCellMode mode
, int align
) :
699 wxDataViewCustomRenderer( varianttype
, mode
, align
)
703 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
705 if (value
.GetType() == wxT("wxBitmap"))
707 if (value
.GetType() == wxT("wxIcon"))
713 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
718 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
721 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
722 else if (m_icon
.Ok())
723 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
728 wxSize
wxDataViewBitmapRenderer::GetSize() const
731 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
732 else if (m_icon
.Ok())
733 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
735 return wxSize(16,16);
738 // ---------------------------------------------------------
739 // wxDataViewToggleRenderer
740 // ---------------------------------------------------------
742 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
744 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
745 wxDataViewCellMode mode
, int align
) :
746 wxDataViewCustomRenderer( varianttype
, mode
, align
)
751 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
753 m_toggle
= value
.GetBool();
758 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
763 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
765 // User wxRenderer here
768 rect
.x
= cell
.x
+ cell
.width
/2 - 10;
770 rect
.y
= cell
.y
+ cell
.height
/2 - 10;
775 flags
|= wxCONTROL_CHECKED
;
776 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
777 flags
|= wxCONTROL_DISABLED
;
779 wxRendererNative::Get().DrawCheckBox(
780 GetOwner()->GetOwner(),
788 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
789 wxDataViewModel
*model
,
790 const wxDataViewItem
& item
, unsigned int col
)
792 bool value
= !m_toggle
;
793 wxVariant variant
= value
;
794 model
->SetValue( variant
, item
, col
);
795 model
->ValueChanged( item
, col
);
799 wxSize
wxDataViewToggleRenderer::GetSize() const
801 return wxSize(20,20);
804 // ---------------------------------------------------------
805 // wxDataViewProgressRenderer
806 // ---------------------------------------------------------
808 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
810 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
811 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
812 wxDataViewCustomRenderer( varianttype
, mode
, align
)
818 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
822 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
824 m_value
= (long) value
;
826 if (m_value
< 0) m_value
= 0;
827 if (m_value
> 100) m_value
= 100;
832 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
834 value
= (long) m_value
;
838 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
840 double pct
= (double)m_value
/ 100.0;
842 bar
.width
= (int)(cell
.width
* pct
);
843 dc
->SetPen( *wxTRANSPARENT_PEN
);
844 dc
->SetBrush( *wxBLUE_BRUSH
);
845 dc
->DrawRectangle( bar
);
847 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
848 dc
->SetPen( *wxBLACK_PEN
);
849 dc
->DrawRectangle( cell
);
854 wxSize
wxDataViewProgressRenderer::GetSize() const
856 return wxSize(40,12);
859 // ---------------------------------------------------------
860 // wxDataViewDateRenderer
861 // ---------------------------------------------------------
863 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
865 #if wxUSE_DATE_RENDERER_POPUP
867 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
870 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
871 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
) :
872 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
),
877 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
878 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
879 sizer
->Add( m_cal
, 1, wxGROW
);
884 void OnCalendar( wxCalendarEvent
&event
);
886 wxCalendarCtrl
*m_cal
;
887 wxDataViewModel
*m_model
;
889 const wxDataViewItem
& m_item
;
892 virtual void OnDismiss()
897 DECLARE_EVENT_TABLE()
900 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
901 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
904 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
906 wxDateTime date
= event
.GetDate();
907 wxVariant value
= date
;
908 m_model
->SetValue( value
, m_item
, m_col
);
909 m_model
->ValueChanged( m_item
, m_col
);
913 #endif // wxUSE_DATE_RENDERER_POPUP
915 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
917 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
918 wxDataViewCellMode mode
, int align
) :
919 wxDataViewCustomRenderer( varianttype
, mode
, align
)
923 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
925 m_date
= value
.GetDateTime();
930 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
936 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
938 wxString tmp
= m_date
.FormatDate();
939 RenderText( tmp
, 0, cell
, dc
, state
);
943 wxSize
wxDataViewDateRenderer::GetSize() const
945 const wxDataViewCtrl
* view
= GetView();
946 wxString tmp
= m_date
.FormatDate();
948 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
949 return wxSize(x
,y
+d
);
952 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
953 const wxDataViewItem
& item
, unsigned int col
)
956 model
->GetValue( variant
, item
, col
);
957 wxDateTime value
= variant
.GetDateTime();
959 #if wxUSE_DATE_RENDERER_POPUP
960 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
961 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
962 wxPoint pos
= wxGetMousePosition();
965 popup
->Popup( popup
->m_cal
);
966 #else // !wxUSE_DATE_RENDERER_POPUP
967 wxMessageBox(value
.Format());
968 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
972 // ---------------------------------------------------------
973 // wxDataViewIconTextRenderer
974 // ---------------------------------------------------------
976 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
978 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
979 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
980 wxDataViewCustomRenderer( varianttype
, mode
, align
)
986 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
990 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
996 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1001 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1004 const wxIcon
&icon
= m_value
.GetIcon();
1007 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ ((cell
.height
- icon
.GetHeight()) / 2));
1008 xoffset
= icon
.GetWidth()+4;
1011 RenderText( m_value
.GetText(), xoffset
, cell
, dc
, state
);
1016 wxSize
wxDataViewIconTextRenderer::GetSize() const
1018 const wxDataViewCtrl
*view
= GetView();
1019 if (!m_value
.GetText().empty())
1022 view
->GetTextExtent( m_value
.GetText(), &x
, &y
);
1024 if (m_value
.GetIcon().IsOk())
1025 x
+= m_value
.GetIcon().GetWidth() + 4;
1026 return wxSize( x
, y
);
1028 return wxSize(80,20);
1032 wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
* WXUNUSED(parent
),
1033 wxRect
WXUNUSED(labelRect
),
1034 const wxVariant
& WXUNUSED(value
))
1040 wxDataViewIconTextRenderer::GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
),
1041 wxVariant
& WXUNUSED(value
))
1046 //-----------------------------------------------------------------------------
1047 // wxDataViewRenameTimer
1048 //-----------------------------------------------------------------------------
1050 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1055 void wxDataViewRenameTimer::Notify()
1057 m_owner
->OnRenameTimer();
1060 //-----------------------------------------------------------------------------
1061 // wxDataViewMainWindow
1062 //-----------------------------------------------------------------------------
1064 //The tree building helper, declared firstly
1065 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
, wxDataViewTreeNode
* node
);
1067 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1069 if (row1
> row2
) return 1;
1070 if (row1
== row2
) return 0;
1075 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1077 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1078 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1079 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1080 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1081 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1082 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1085 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1086 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1087 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
1088 m_selection( wxDataViewSelectionCmp
)
1093 m_lastOnSame
= false;
1094 m_renameTimer
= new wxDataViewRenameTimer( this );
1096 // TODO: user better initial values/nothing selected
1097 m_currentCol
= NULL
;
1100 m_lineHeight
= wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
1103 m_dragStart
= wxPoint(0,0);
1104 m_lineLastClicked
= (unsigned int) -1;
1105 m_lineBeforeLastClicked
= (unsigned int) -1;
1106 m_lineSelectSingleOnUp
= (unsigned int) -1;
1110 SetBackgroundColour( *wxWHITE
);
1112 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1114 m_penRule
= wxPen(GetRuleColour());
1116 //Here I compose a pen can draw black lines, maybe there are something system colour to use
1117 m_penExpander
= wxPen(wxColour(0,0,0));
1118 //Some new added code to deal with the tree structure
1119 m_root
= new wxDataViewTreeNode( NULL
);
1120 m_root
->SetHasChildren(true);
1122 //Make m_count = -1 will cause the class recaculate the real displaying number of rows.
1124 m_underMouse
= NULL
;
1128 wxDataViewMainWindow::~wxDataViewMainWindow()
1131 delete m_renameTimer
;
1134 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1136 wxDataViewModel
*model
= GetOwner()->GetModel();
1137 wxAutoBufferedPaintDC
dc( this );
1140 dc
.SetPen( *wxTRANSPARENT_PEN
);
1141 dc
.SetBrush( wxBrush( GetBackgroundColour()) );
1142 dc
.SetBrush( *wxWHITE_BRUSH
);
1143 wxSize
size( GetClientSize() );
1144 dc
.DrawRectangle( 0,0,size
.x
,size
.y
);
1148 GetOwner()->PrepareDC( dc
);
1149 dc
.SetFont( GetFont() );
1151 wxRect update
= GetUpdateRegion().GetBox();
1152 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1154 // compute which items needs to be redrawn
1155 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
1156 unsigned int item_count
=
1157 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
1158 (int)(GetRowCount( ) - item_start
));
1159 unsigned int item_last
= item_start
+ item_count
;
1161 // compute which columns needs to be redrawn
1162 unsigned int cols
= GetOwner()->GetColumnCount();
1163 unsigned int col_start
= 0;
1164 unsigned int x_start
;
1165 for (x_start
= 0; col_start
< cols
; col_start
++)
1167 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_start
);
1168 if (col
->IsHidden())
1169 continue; // skip it!
1171 unsigned int w
= col
->GetWidth();
1172 if (x_start
+w
>= (unsigned int)update
.x
)
1178 unsigned int col_last
= col_start
;
1179 unsigned int x_last
= x_start
;
1180 for (; col_last
< cols
; col_last
++)
1182 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_last
);
1183 if (col
->IsHidden())
1184 continue; // skip it!
1186 if (x_last
> (unsigned int)update
.GetRight())
1189 x_last
+= col
->GetWidth();
1192 // Draw horizontal rules if required
1193 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1195 dc
.SetPen(m_penRule
);
1196 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1198 for (unsigned int i
= item_start
; i
<= item_last
+1; i
++)
1200 int y
= GetLineStart( i
);
1201 dc
.DrawLine(x_start
, y
, x_last
, y
);
1205 // Draw vertical rules if required
1206 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1208 dc
.SetPen(m_penRule
);
1209 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1212 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1214 wxDataViewColumn
*col
= GetOwner()->GetColumn(i
);
1215 if (col
->IsHidden())
1216 continue; // skip it
1218 dc
.DrawLine(x
, GetLineStart( item_start
),
1219 x
, GetLineStart( item_last
) );
1221 x
+= col
->GetWidth();
1224 // Draw last vertical rule
1225 dc
.DrawLine(x
, GetLineStart( item_start
),
1226 x
, GetLineStart( item_last
) );
1229 // redraw the background for the items which are selected/current
1230 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1232 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1233 if (selected
|| item
== m_currentRow
)
1235 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
1236 if (item
== m_currentRow
)
1237 flags
|= wxCONTROL_CURRENT
;
1239 flags
|= wxCONTROL_FOCUSED
;
1241 wxRect
rect( x_start
, GetLineStart( item
), x_last
, GetLineHeight( item
) );
1242 wxRendererNative::Get().DrawItemSelectionRect
1252 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1255 // TODO: last column for RTL support
1256 expander
= GetOwner()->GetColumn( 0 );
1257 GetOwner()->SetExpanderColumn(expander
);
1260 // redraw all cells for all rows which must be repainted and all columns
1262 cell_rect
.x
= x_start
;
1263 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1266 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
1267 wxDataViewRenderer
*cell
= col
->GetRenderer();
1268 cell_rect
.width
= col
->GetWidth();
1270 if (col
->IsHidden())
1271 continue; // skip it!
1273 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1275 // get the cell value and set it into the renderer
1277 wxDataViewTreeNode
*node
= NULL
;
1278 wxDataViewItem dataitem
;
1280 if (!IsVirtualList())
1282 node
= GetTreeNodeByRow(item
);
1286 dataitem
= node
->GetItem();
1288 if ((i
> 0) && model
->IsContainer(dataitem
) && !model
->HasContainerColumns(dataitem
))
1293 dataitem
= wxDataViewItem( wxUIntToPtr(item
) );
1296 model
->GetValue( value
, dataitem
, col
->GetModelColumn());
1297 cell
->SetValue( value
);
1299 if (cell
->GetWantsAttr())
1301 wxDataViewItemAttr attr
;
1302 bool ret
= model
->GetAttr( dataitem
, col
->GetModelColumn(), attr
);
1304 cell
->SetAttr( attr
);
1305 cell
->SetHasAttr( ret
);
1309 cell_rect
.y
= GetLineStart( item
);
1310 cell_rect
.height
= GetLineHeight( item
); // -1 is for the horizontal rules (?)
1312 //Draw the expander here.
1314 if ((!IsVirtualList()) && (col
== expander
))
1316 indent
= node
->GetIndentLevel();
1318 //Calculate the indent first
1319 indent
= cell_rect
.x
+ GetOwner()->GetIndent() * indent
;
1321 int expander_width
= m_lineHeight
- 2*EXPANDER_MARGIN
;
1322 // change the cell_rect.x to the appropriate pos
1323 int expander_x
= indent
+ EXPANDER_MARGIN
;
1324 int expander_y
= cell_rect
.y
+ EXPANDER_MARGIN
+ (GetLineHeight(item
) / 2) - (expander_width
/2) - EXPANDER_OFFSET
;
1325 indent
= indent
+ m_lineHeight
; //try to use the m_lineHeight as the expander space
1326 dc
.SetPen( m_penExpander
);
1327 dc
.SetBrush( wxNullBrush
);
1328 if( node
->HasChildren() )
1330 wxRect
rect( expander_x
, expander_y
, expander_width
, expander_width
);
1332 if (m_underMouse
== node
)
1334 flag
|= wxCONTROL_CURRENT
;
1336 if( node
->IsOpen() )
1337 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
|wxCONTROL_EXPANDED
);
1339 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
1341 //force the expander column to left-center align
1342 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
1344 if (node
&& !node
->HasChildren())
1346 // Yes, if the node does not have any child, it must be a leaf which
1347 // mean that it is a temporarily created by GetTreeNodeByRow
1351 // cannot be bigger than allocated space
1352 wxSize size
= cell
->GetSize();
1353 // Because of the tree structure indent, here we should minus the width of the cell for drawing
1354 size
.x
= wxMin( size
.x
+ 2*PADDING_RIGHTLEFT
, cell_rect
.width
- indent
);
1355 // size.y = wxMin( size.y, cell_rect.height );
1356 size
.y
= cell_rect
.height
;
1358 wxRect
item_rect(cell_rect
.GetTopLeft(), size
);
1359 int align
= cell
->CalculateAlignment();
1361 // horizontal alignment:
1362 item_rect
.x
= cell_rect
.x
;
1363 if (align
& wxALIGN_CENTER_HORIZONTAL
)
1364 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
1365 else if (align
& wxALIGN_RIGHT
)
1366 item_rect
.x
= cell_rect
.x
+ cell_rect
.width
- size
.x
;
1367 //else: wxALIGN_LEFT is the default
1369 // vertical alignment:
1370 item_rect
.y
= cell_rect
.y
;
1371 if (align
& wxALIGN_CENTER_VERTICAL
)
1372 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
1373 else if (align
& wxALIGN_BOTTOM
)
1374 item_rect
.y
= cell_rect
.y
+ cell_rect
.height
- size
.y
;
1375 //else: wxALIGN_TOP is the default
1378 item_rect
.x
+= PADDING_RIGHTLEFT
;
1379 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
1381 //Here we add the tree indent
1382 item_rect
.x
+= indent
;
1385 if (m_hasFocus
&& (m_selection
.Index(item
) != wxNOT_FOUND
))
1386 state
|= wxDATAVIEW_CELL_SELECTED
;
1388 // TODO: it would be much more efficient to create a clipping
1389 // region for the entire column being rendered (in the OnPaint
1390 // of wxDataViewMainWindow) instead of a single clip region for
1391 // each cell. However it would mean that each renderer should
1392 // respect the given wxRect's top & bottom coords, eventually
1393 // violating only the left & right coords - however the user can
1394 // make its own renderer and thus we cannot be sure of that.
1395 dc
.SetClippingRegion( item_rect
);
1396 cell
->Render( item_rect
, &dc
, state
);
1397 dc
.DestroyClippingRegion();
1400 cell_rect
.x
+= cell_rect
.width
;
1404 void wxDataViewMainWindow::OnRenameTimer()
1406 // We have to call this here because changes may just have
1407 // been made and no screen update taken place.
1412 unsigned int cols
= GetOwner()->GetColumnCount();
1414 for (i
= 0; i
< cols
; i
++)
1416 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
1418 continue; // skip it!
1420 if (c
== m_currentCol
)
1422 xpos
+= c
->GetWidth();
1424 wxRect
labelRect( xpos
,
1425 GetLineStart( m_currentRow
),
1426 m_currentCol
->GetWidth(),
1427 GetLineHeight( m_currentRow
) );
1429 GetOwner()->CalcScrolledPosition( labelRect
.x
, labelRect
.y
,
1430 &labelRect
.x
, &labelRect
.y
);
1432 wxDataViewItem item
= GetItemByRow( m_currentRow
);
1433 m_currentCol
->GetRenderer()->StartEditing( item
, labelRect
);
1437 //------------------------------------------------------------------
1438 // Helper class for do operation on the tree node
1439 //------------------------------------------------------------------
1444 virtual ~DoJob() { }
1446 //The return value control how the tree-walker tranverse the tree
1447 // 0: Job done, stop tranverse and return
1448 // 1: Ignore the current node's subtree and continue
1449 // 2: Job not done, continue
1450 enum { OK
= 0 , IGR
= 1, CONT
= 2 };
1451 virtual int operator() ( wxDataViewTreeNode
* node
) = 0;
1452 virtual int operator() ( void * n
) = 0;
1455 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
1460 switch( func( node
) )
1471 wxDataViewTreeNodes nodes
= node
->GetNodes();
1472 wxDataViewTreeLeaves leaves
= node
->GetChildren();
1474 int len_nodes
= nodes
.GetCount();
1475 int len
= leaves
.GetCount();
1476 int i
= 0, nodes_i
= 0;
1478 for(; i
< len
; i
++ )
1480 void * n
= leaves
[i
];
1481 if( nodes_i
< len_nodes
&& n
== nodes
[nodes_i
]->GetItem().GetID() )
1483 wxDataViewTreeNode
* nd
= nodes
[nodes_i
];
1486 if( Walker( nd
, func
) )
1505 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
1516 wxDataViewTreeNode
* node
;
1517 node
= FindNode(parent
);
1522 node
->SetHasChildren( true );
1524 if( g_model
->IsContainer( item
) )
1526 wxDataViewTreeNode
* newnode
= new wxDataViewTreeNode( node
);
1527 newnode
->SetItem(item
);
1528 newnode
->SetHasChildren( true );
1529 node
->AddNode( newnode
);
1532 node
->AddLeaf( item
.GetID() );
1534 node
->ChangeSubTreeCount(1);
1542 static void DestroyTreeHelper( wxDataViewTreeNode
* node
);
1544 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
1545 const wxDataViewItem
& item
)
1550 if( m_currentRow
> GetRowCount() )
1551 m_currentRow
= m_count
- 1;
1553 m_selection
.Empty();
1560 wxDataViewTreeNode
* node
= FindNode(parent
);
1562 wxCHECK_MSG( node
!= NULL
, false, "item not found" );
1563 wxCHECK_MSG( node
->GetChildren().Index( item
.GetID() ) != wxNOT_FOUND
, false, "item not found" );
1566 node
->GetChildren().Remove( item
.GetID() );
1567 //Manuplate selection
1568 if( m_selection
.GetCount() > 1 )
1570 m_selection
.Empty();
1572 bool isContainer
= false;
1573 wxDataViewTreeNodes nds
= node
->GetNodes();
1574 for (size_t i
= 0; i
< nds
.GetCount(); i
++)
1576 if (nds
[i
]->GetItem() == item
)
1584 wxDataViewTreeNode
* n
= NULL
;
1585 wxDataViewTreeNodes nodes
= node
->GetNodes();
1586 int len
= nodes
.GetCount();
1587 for( int i
= 0; i
< len
; i
++)
1589 if( nodes
[i
]->GetItem() == item
)
1596 wxCHECK_MSG( n
!= NULL
, false, "item not found" );
1598 node
->GetNodes().Remove( n
);
1599 sub
-= n
->GetSubTreeCount();
1600 ::DestroyTreeHelper(n
);
1602 //Make the row number invalid and get a new valid one when user call GetRowCount
1604 node
->ChangeSubTreeCount(sub
);
1606 //Change the current row to the last row if the current exceed the max row number
1607 if( m_currentRow
> GetRowCount() )
1608 m_currentRow
= m_count
- 1;
1615 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
1621 wxWindow
*parent
= GetParent();
1622 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
1623 le
.SetEventObject(parent
);
1624 le
.SetModel(GetOwner()->GetModel());
1626 parent
->GetEventHandler()->ProcessEvent(le
);
1631 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
1633 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
1634 /*#define MAX_VIRTUAL_WIDTH 100000
1636 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
1637 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
1638 Refresh( true, &rect );
1646 wxWindow
*parent
= GetParent();
1647 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
1648 le
.SetEventObject(parent
);
1649 le
.SetModel(GetOwner()->GetModel());
1652 le
.SetDataViewColumn(GetOwner()->GetColumn(col
));
1653 parent
->GetEventHandler()->ProcessEvent(le
);
1658 bool wxDataViewMainWindow::Cleared()
1663 BuildTree( GetOwner()->GetModel() );
1670 void wxDataViewMainWindow::UpdateDisplay()
1675 void wxDataViewMainWindow::OnInternalIdle()
1677 wxWindow::OnInternalIdle();
1681 RecalculateDisplay();
1686 void wxDataViewMainWindow::RecalculateDisplay()
1688 wxDataViewModel
*model
= GetOwner()->GetModel();
1695 int width
= GetEndOfLastCol();
1696 int height
= GetLineStart( GetRowCount() );
1698 SetVirtualSize( width
, height
);
1699 GetOwner()->SetScrollRate( 10, m_lineHeight
);
1704 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
1706 wxWindow::ScrollWindow( dx
, dy
, rect
);
1708 if (GetOwner()->m_headerArea
)
1709 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
1712 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
1715 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
1716 int sy
= GetLineStart( rows
)/y
;
1720 wxRect rect
= GetClientRect();
1724 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
1725 for (x_start
= 0; colnum
< column
; colnum
++)
1727 wxDataViewColumn
*col
= GetOwner()->GetColumn(colnum
);
1728 if (col
->IsHidden())
1729 continue; // skip it!
1731 w
= col
->GetWidth();
1735 int x_end
= x_start
+ w
;
1736 xe
= xx
+ rect
.width
;
1739 sx
= ( xx
+ x_end
- xe
)/x
;
1746 m_owner
->Scroll( sx
, sy
);
1749 int wxDataViewMainWindow::GetCountPerPage() const
1751 wxSize size
= GetClientSize();
1752 return size
.y
/ m_lineHeight
;
1755 int wxDataViewMainWindow::GetEndOfLastCol() const
1759 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
1761 const wxDataViewColumn
*c
=
1762 const_cast<wxDataViewCtrl
*>(GetOwner())->GetColumn( i
);
1765 width
+= c
->GetWidth();
1770 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
1774 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
1776 return GetLineAt( y
);
1779 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
1781 wxSize client_size
= GetClientSize();
1782 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
1783 &client_size
.x
, &client_size
.y
);
1785 //we should deal with the pixel here
1786 unsigned int row
= GetLineAt(client_size
.y
) - 1;
1788 return wxMin( GetRowCount()-1, row
);
1791 unsigned int wxDataViewMainWindow::GetRowCount()
1793 if ( m_count
== -1 )
1795 m_count
= RecalculateCount();
1801 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
1808 void wxDataViewMainWindow::SelectAllRows( bool on
)
1815 m_selection
.Clear();
1816 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
1817 m_selection
.Add( i
);
1822 unsigned int first_visible
= GetFirstVisibleRow();
1823 unsigned int last_visible
= GetLastVisibleRow();
1825 for (i
= 0; i
< m_selection
.GetCount(); i
++)
1827 unsigned int row
= m_selection
[i
];
1828 if ((row
>= first_visible
) && (row
<= last_visible
))
1831 m_selection
.Clear();
1835 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
1837 if (m_selection
.Index( row
) == wxNOT_FOUND
)
1841 m_selection
.Add( row
);
1849 m_selection
.Remove( row
);
1855 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
1859 unsigned int tmp
= from
;
1865 for (i
= from
; i
<= to
; i
++)
1867 if (m_selection
.Index( i
) == wxNOT_FOUND
)
1870 m_selection
.Add( i
);
1875 m_selection
.Remove( i
);
1878 RefreshRows( from
, to
);
1881 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
1883 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
1885 int n
= aSelections
[i
];
1887 m_selection
.Add( n
);
1892 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
1894 if (m_selection
.Index( row
) == wxNOT_FOUND
)
1895 m_selection
.Add( row
);
1897 m_selection
.Remove( row
);
1901 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
1903 return (m_selection
.Index( row
) != wxNOT_FOUND
);
1906 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
1908 wxWindow
*parent
= GetParent();
1909 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
1911 le
.SetEventObject(parent
);
1912 le
.SetModel(GetOwner()->GetModel());
1915 parent
->GetEventHandler()->ProcessEvent(le
);
1918 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
1920 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
1921 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1923 wxSize client_size
= GetClientSize();
1924 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
1925 wxRect intersect_rect
= client_rect
.Intersect( rect
);
1926 if (intersect_rect
.width
> 0)
1927 Refresh( true, &intersect_rect
);
1930 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
1934 unsigned int tmp
= to
;
1939 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
1940 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1942 wxSize client_size
= GetClientSize();
1943 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
1944 wxRect intersect_rect
= client_rect
.Intersect( rect
);
1945 if (intersect_rect
.width
> 0)
1946 Refresh( true, &intersect_rect
);
1949 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
1951 wxSize client_size
= GetClientSize();
1952 int start
= GetLineStart( firstRow
);
1953 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
1954 if (start
> client_size
.y
) return;
1956 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
1958 Refresh( true, &rect
);
1961 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
1963 wxCHECK_RET( newCurrent
< GetRowCount(),
1964 _T("invalid item index in OnArrowChar()") );
1966 // if there is no selection, we cannot move it anywhere
1967 if (!HasCurrentRow())
1970 unsigned int oldCurrent
= m_currentRow
;
1972 // in single selection we just ignore Shift as we can't select several
1974 if ( event
.ShiftDown() && !IsSingleSel() )
1976 RefreshRow( oldCurrent
);
1978 ChangeCurrentRow( newCurrent
);
1980 // select all the items between the old and the new one
1981 if ( oldCurrent
> newCurrent
)
1983 newCurrent
= oldCurrent
;
1984 oldCurrent
= m_currentRow
;
1987 SelectRows( oldCurrent
, newCurrent
, true );
1988 if (oldCurrent
!=newCurrent
)
1989 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
1993 RefreshRow( oldCurrent
);
1995 // all previously selected items are unselected unless ctrl is held
1996 if ( !event
.ControlDown() )
1997 SelectAllRows(false);
1999 ChangeCurrentRow( newCurrent
);
2001 if ( !event
.ControlDown() )
2003 SelectRow( m_currentRow
, true );
2004 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
2007 RefreshRow( m_currentRow
);
2010 GetOwner()->EnsureVisible( m_currentRow
, -1 );
2013 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2017 rect
.y
= GetLineStart( row
);
2018 rect
.width
= GetEndOfLastCol();
2019 rect
.height
= GetLineHeight( row
);
2024 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2026 const wxDataViewModel
*model
= GetOwner()->GetModel();
2028 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2030 // TODO make more efficient
2035 for (r
= 0; r
< row
; r
++)
2037 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2038 if (!node
) return start
;
2040 wxDataViewItem item
= node
->GetItem();
2042 if (node
&& !node
->HasChildren())
2044 // Yes, if the node does not have any child, it must be a leaf which
2045 // mean that it is a temporarily created by GetTreeNodeByRow
2049 unsigned int cols
= GetOwner()->GetColumnCount();
2051 int height
= m_lineHeight
;
2052 for (col
= 0; col
< cols
; col
++)
2054 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2055 if (column
->IsHidden())
2056 continue; // skip it!
2058 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
2059 continue; // skip it!
2061 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
2063 model
->GetValue( value
, item
, column
->GetModelColumn() );
2064 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
2065 renderer2
->SetValue( value
);
2066 height
= wxMax( height
, renderer
->GetSize().y
);
2077 return row
* m_lineHeight
;
2081 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
2083 const wxDataViewModel
*model
= GetOwner()->GetModel();
2085 // check for the easy case first
2086 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
2087 return y
/ m_lineHeight
;
2089 // TODO make more efficient
2090 unsigned int row
= 0;
2091 unsigned int yy
= 0;
2094 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2097 // not really correct...
2098 return row
+ ((y
-yy
) / m_lineHeight
);
2101 wxDataViewItem item
= node
->GetItem();
2103 if (node
&& !node
->HasChildren())
2105 // Yes, if the node does not have any child, it must be a leaf which
2106 // mean that it is a temporarily created by GetTreeNodeByRow
2110 unsigned int cols
= GetOwner()->GetColumnCount();
2112 int height
= m_lineHeight
;
2113 for (col
= 0; col
< cols
; col
++)
2115 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2116 if (column
->IsHidden())
2117 continue; // skip it!
2119 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
2120 continue; // skip it!
2122 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
2124 model
->GetValue( value
, item
, column
->GetModelColumn() );
2125 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
2126 renderer2
->SetValue( value
);
2127 height
= wxMax( height
, renderer
->GetSize().y
);
2138 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
2140 const wxDataViewModel
*model
= GetOwner()->GetModel();
2142 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2144 wxASSERT( !IsVirtualList() );
2146 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2147 // wxASSERT( node );
2148 if (!node
) return m_lineHeight
;
2150 wxDataViewItem item
= node
->GetItem();
2152 if (node
&& !node
->HasChildren())
2154 // Yes, if the node does not have any child, it must be a leaf which
2155 // mean that it is a temporarily created by GetTreeNodeByRow
2159 int height
= m_lineHeight
;
2161 unsigned int cols
= GetOwner()->GetColumnCount();
2163 for (col
= 0; col
< cols
; col
++)
2165 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2166 if (column
->IsHidden())
2167 continue; // skip it!
2169 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
2170 continue; // skip it!
2172 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
2174 model
->GetValue( value
, item
, column
->GetModelColumn() );
2175 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
2176 renderer2
->SetValue( value
);
2177 height
= wxMax( height
, renderer
->GetSize().y
);
2184 return m_lineHeight
;
2188 class RowToItemJob
: public DoJob
2191 RowToItemJob( unsigned int row
, int current
) { this->row
= row
; this->current
= current
;}
2192 virtual ~RowToItemJob() { }
2194 virtual int operator() ( wxDataViewTreeNode
* node
)
2197 if( current
== static_cast<int>(row
))
2199 ret
= node
->GetItem();
2203 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2205 current
+= node
->GetSubTreeCount();
2210 //If the current has no child node, we can find the desired item of the row number directly.
2211 //This if can speed up finding in some case, and will has a very good effect when it comes to list view
2212 if( node
->GetNodes().GetCount() == 0)
2214 int index
= static_cast<int>(row
) - current
- 1;
2215 ret
= node
->GetChildren().Item( index
);
2222 virtual int operator() ( void * n
)
2225 if( current
== static_cast<int>(row
))
2227 ret
= wxDataViewItem( n
);
2232 wxDataViewItem
GetResult(){ return ret
; }
2239 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
2243 return wxDataViewItem( wxUIntToPtr(row
) );
2247 RowToItemJob
job( row
, -2 );
2248 Walker( m_root
, job
);
2249 return job
.GetResult();
2253 class RowToTreeNodeJob
: public DoJob
2256 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
2259 this->current
= current
;
2263 virtual ~RowToTreeNodeJob(){ }
2265 virtual int operator() ( wxDataViewTreeNode
* node
)
2268 if( current
== static_cast<int>(row
))
2274 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2276 current
+= node
->GetSubTreeCount();
2282 //If the current has no child node, we can find the desired item of the row number directly.
2283 //This if can speed up finding in some case, and will has a very good effect when it comes to list view
2284 if( node
->GetNodes().GetCount() == 0)
2286 int index
= static_cast<int>(row
) - current
- 1;
2287 void * n
= node
->GetChildren().Item( index
);
2288 ret
= new wxDataViewTreeNode( parent
);
2289 ret
->SetItem( wxDataViewItem( n
));
2290 ret
->SetHasChildren(false);
2299 virtual int operator() ( void * n
)
2302 if( current
== static_cast<int>(row
))
2304 ret
= new wxDataViewTreeNode( parent
);
2305 ret
->SetItem( wxDataViewItem( n
));
2306 ret
->SetHasChildren(false);
2312 wxDataViewTreeNode
* GetResult(){ return ret
; }
2316 wxDataViewTreeNode
* ret
;
2317 wxDataViewTreeNode
* parent
;
2321 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
2323 wxASSERT( !IsVirtualList() );
2325 RowToTreeNodeJob
job( row
, -2, m_root
);
2326 Walker( m_root
, job
);
2327 return job
.GetResult();
2330 wxDataViewEvent
wxDataViewMainWindow::SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
)
2332 wxWindow
*parent
= GetParent();
2333 wxDataViewEvent
le(type
, parent
->GetId());
2335 le
.SetEventObject(parent
);
2336 le
.SetModel(GetOwner()->GetModel());
2339 parent
->GetEventHandler()->ProcessEvent(le
);
2343 void wxDataViewMainWindow::OnExpanding( unsigned int row
)
2345 if (IsVirtualList())
2348 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2351 if( node
->HasChildren())
2353 if( !node
->IsOpen())
2355 wxDataViewEvent e
= SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
,node
->GetItem());
2356 //Check if the user prevent expanding
2357 if( e
.GetSkipped() )
2361 //Here I build the children of current node
2362 if( node
->GetChildrenNumber() == 0 )
2365 ::BuildTreeHelper(GetOwner()->GetModel(), node
->GetItem(), node
);
2369 //Send the expanded event
2370 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
2374 SelectRow( row
, false );
2375 SelectRow( row
+ 1, true );
2376 ChangeCurrentRow( row
+ 1 );
2377 SendSelectionChangedEvent( GetItemByRow(row
+1));
2385 void wxDataViewMainWindow::OnCollapsing(unsigned int row
)
2387 if (IsVirtualList())
2390 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2393 wxDataViewTreeNode
* nd
= node
;
2395 if( node
->HasChildren() && node
->IsOpen() )
2397 wxDataViewEvent e
= SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem());
2398 if( e
.GetSkipped() )
2403 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,nd
->GetItem());
2407 node
= node
->GetParent();
2410 int parent
= GetRowByItem( node
->GetItem() );
2413 SelectRow( row
, false);
2414 SelectRow(parent
, true );
2415 ChangeCurrentRow( parent
);
2416 SendSelectionChangedEvent( node
->GetItem() );
2420 if( !nd
->HasChildren())
2425 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
2427 wxDataViewModel
* model
= GetOwner()->GetModel();
2431 //Compose the a parent-chain of the finding item
2433 list
.DeleteContents( true );
2434 wxDataViewItem
it( item
);
2437 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2438 list
.Insert( pItem
);
2439 it
= model
->GetParent( it
);
2442 //Find the item along the parent-chain.
2443 //This algorithm is designed to speed up the node-finding method
2444 wxDataViewTreeNode
* node
= m_root
;
2445 for( ItemList::const_iterator iter
= list
.begin(); iter
!=list
.end(); iter
++ )
2447 if( node
->HasChildren() )
2449 if( node
->GetChildrenNumber() == 0 )
2452 ::BuildTreeHelper(model
, node
->GetItem(), node
);
2455 wxDataViewTreeNodes nodes
= node
->GetNodes();
2459 for (i
= 0; i
< nodes
.GetCount(); i
++)
2461 if (nodes
[i
]->GetItem() == (**iter
))
2463 if (nodes
[i
]->GetItem() == item
)
2480 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
)
2482 wxDataViewColumn
*col
= NULL
;
2483 unsigned int cols
= GetOwner()->GetColumnCount();
2484 unsigned int colnum
= 0;
2486 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
2487 for (unsigned x_start
= 0; colnum
< cols
; colnum
++)
2489 col
= GetOwner()->GetColumn(colnum
);
2490 if (col
->IsHidden())
2491 continue; // skip it!
2493 unsigned int w
= col
->GetWidth();
2494 if (x_start
+w
>= (unsigned int)x
)
2501 item
= GetItemByRow( GetLineAt( y
) );
2504 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
2506 int row
= GetRowByItem(item
);
2507 int y
= GetLineStart( row
);
2508 int h
= GetLineHeight( m_lineHeight
);
2510 wxDataViewColumn
*col
= NULL
;
2511 for( int i
= 0, cols
= GetOwner()->GetColumnCount(); i
< cols
; i
++ )
2513 col
= GetOwner()->GetColumn( i
);
2514 x
+= col
->GetWidth();
2515 if( GetOwner()->GetColumn(i
+1) == column
)
2518 int w
= col
->GetWidth();
2519 m_owner
->CalcScrolledPosition( x
, y
, &x
, &y
);
2520 return wxRect(x
, y
, w
, h
);
2523 int wxDataViewMainWindow::RecalculateCount()
2527 wxDataViewIndexListModel
*list_model
= (wxDataViewIndexListModel
*) GetOwner()->GetModel();
2529 return list_model
->GetLastIndex() + 1;
2531 return list_model
->GetLastIndex() - 1;
2536 return m_root
->GetSubTreeCount();
2540 class ItemToRowJob
: public DoJob
2543 ItemToRowJob(const wxDataViewItem
& item_
, ItemList::const_iterator iter
)
2550 //Maybe binary search will help to speed up this process
2551 virtual int operator() ( wxDataViewTreeNode
* node
)
2554 if( node
->GetItem() == item
)
2559 if( node
->GetItem() == **m_iter
)
2566 ret
+= node
->GetSubTreeCount();
2572 virtual int operator() ( void * n
)
2575 if( n
== item
.GetID() )
2579 //the row number is begin from zero
2580 int GetResult() { return ret
-1; }
2583 ItemList::const_iterator m_iter
;
2584 wxDataViewItem item
;
2589 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
2591 const wxDataViewModel
* model
= GetOwner()->GetModel();
2597 return wxPtrToUInt( item
.GetID() );
2604 //Compose the a parent-chain of the finding item
2606 wxDataViewItem
* pItem
;
2607 list
.DeleteContents( true );
2608 wxDataViewItem
it( item
);
2611 pItem
= new wxDataViewItem( it
);
2612 list
.Insert( pItem
);
2613 it
= model
->GetParent( it
);
2615 pItem
= new wxDataViewItem( );
2616 list
.Insert( pItem
);
2618 ItemToRowJob
job( item
, list
.begin() );
2619 Walker(m_root
, job
);
2620 return job
.GetResult();
2624 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
, wxDataViewTreeNode
* node
)
2626 if( !model
->IsContainer( item
) )
2629 wxDataViewItemArray children
;
2630 unsigned int num
= model
->GetChildren( item
, children
);
2631 unsigned int index
= 0;
2632 while( index
< num
)
2634 if( model
->IsContainer( children
[index
] ) )
2636 wxDataViewTreeNode
* n
= new wxDataViewTreeNode( node
);
2637 n
->SetItem(children
[index
]);
2638 n
->SetHasChildren( true );
2643 node
->AddLeaf( children
[index
].GetID() );
2647 node
->SetSubTreeCount( num
);
2648 wxDataViewTreeNode
* n
= node
->GetParent();
2650 n
->ChangeSubTreeCount(num
);
2654 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
2658 if (GetOwner()->GetModel()->IsVirtualListModel())
2664 m_root
= new wxDataViewTreeNode( NULL
);
2665 m_root
->SetHasChildren(true);
2667 //First we define a invalid item to fetch the top-level elements
2668 wxDataViewItem item
;
2670 BuildTreeHelper( model
, item
, m_root
);
2674 static void DestroyTreeHelper( wxDataViewTreeNode
* node
)
2676 if( node
->GetNodeNumber() != 0 )
2678 int len
= node
->GetNodeNumber();
2680 wxDataViewTreeNodes
& nodes
= node
->GetNodes();
2681 for(; i
< len
; i
++ )
2683 DestroyTreeHelper(nodes
[i
]);
2689 void wxDataViewMainWindow::DestroyTree()
2691 if (!IsVirtualList())
2693 ::DestroyTreeHelper(m_root
);
2699 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
2701 if ( GetParent()->HandleAsNavigationKey(event
) )
2704 // no item -> nothing to do
2705 if (!HasCurrentRow())
2711 // don't use m_linesPerPage directly as it might not be computed yet
2712 const int pageSize
= GetCountPerPage();
2713 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
2715 switch ( event
.GetKeyCode() )
2719 if (m_currentRow
> 0)
2721 wxWindow
*parent
= GetParent();
2722 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
2723 le
.SetItem( GetItemByRow(m_currentRow
) );
2724 le
.SetEventObject(parent
);
2725 le
.SetModel(GetOwner()->GetModel());
2727 parent
->GetEventHandler()->ProcessEvent(le
);
2732 if ( m_currentRow
> 0 )
2733 OnArrowChar( m_currentRow
- 1, event
);
2737 if ( m_currentRow
< GetRowCount() - 1 )
2738 OnArrowChar( m_currentRow
+ 1, event
);
2740 //Add the process for tree expanding/collapsing
2742 OnCollapsing(m_currentRow
);
2745 OnExpanding( m_currentRow
);
2749 OnArrowChar( GetRowCount() - 1, event
);
2754 OnArrowChar( 0, event
);
2759 int steps
= pageSize
- 1;
2760 int index
= m_currentRow
- steps
;
2764 OnArrowChar( index
, event
);
2770 int steps
= pageSize
- 1;
2771 unsigned int index
= m_currentRow
+ steps
;
2772 unsigned int count
= GetRowCount();
2773 if ( index
>= count
)
2776 OnArrowChar( index
, event
);
2785 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
2787 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2789 // let the base handle mouse wheel events.
2794 int x
= event
.GetX();
2795 int y
= event
.GetY();
2796 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2797 wxDataViewColumn
*col
= NULL
;
2800 unsigned int cols
= GetOwner()->GetColumnCount();
2802 for (i
= 0; i
< cols
; i
++)
2804 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
2806 continue; // skip it!
2808 if (x
< xpos
+ c
->GetWidth())
2813 xpos
+= c
->GetWidth();
2818 wxDataViewRenderer
*cell
= col
->GetRenderer();
2819 unsigned int current
= GetLineAt( y
);
2820 if ((current
> GetRowCount()) || (x
> GetEndOfLastCol()))
2822 // Unselect all if below the last row ?
2826 //Test whether the mouse is hovered on the tree item button
2828 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
2830 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
2831 if( node
!=NULL
&& node
->HasChildren() )
2833 int indent
= node
->GetIndentLevel();
2834 indent
= GetOwner()->GetIndent()*indent
;
2835 wxRect
rect( xpos
+ indent
+ EXPANDER_MARGIN
,
2836 GetLineStart( current
) + EXPANDER_MARGIN
+ (GetLineHeight(current
)/2) - (m_lineHeight
/2) - EXPANDER_OFFSET
,
2837 m_lineHeight
-2*EXPANDER_MARGIN
,
2838 m_lineHeight
-2*EXPANDER_MARGIN
+ EXPANDER_OFFSET
);
2839 if( rect
.Contains( x
, y
) )
2841 //So the mouse is over the expander
2843 if (m_underMouse
&& m_underMouse
!= node
)
2845 //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
2846 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
2848 if (m_underMouse
!= node
)
2850 //wxLogMessage("Do the row: %d", current);
2851 RefreshRow(current
);
2853 m_underMouse
= node
;
2856 if (node
!=NULL
&& !node
->HasChildren())
2861 if (m_underMouse
!= NULL
)
2863 //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
2864 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
2865 m_underMouse
= NULL
;
2869 wxDataViewModel
*model
= GetOwner()->GetModel();
2871 if (event
.Dragging())
2873 if (m_dragCount
== 0)
2875 // we have to report the raw, physical coords as we want to be
2876 // able to call HitTest(event.m_pointDrag) from the user code to
2877 // get the item being dragged
2878 m_dragStart
= event
.GetPosition();
2883 if (m_dragCount
!= 3)
2886 if (event
.LeftIsDown())
2888 // Notify cell about drag
2897 bool forceClick
= false;
2899 if (event
.ButtonDClick())
2901 m_renameTimer
->Stop();
2902 m_lastOnSame
= false;
2905 wxDataViewItem item
= GetItemByRow(current
);
2906 bool ignore_other_columns
=
2907 ((GetOwner()->GetExpanderColumn() != col
) &&
2908 (model
->IsContainer(item
)) &&
2909 (!model
->HasContainerColumns(item
)));
2911 if (event
.LeftDClick())
2913 if ( current
== m_lineLastClicked
)
2915 if ((!ignore_other_columns
) && (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
2918 model
->GetValue( value
, item
, col
->GetModelColumn() );
2919 cell
->SetValue( value
);
2920 wxRect
cell_rect( xpos
, GetLineStart( current
),
2921 col
->GetWidth(), GetLineHeight( current
) );
2922 cell
->Activate( cell_rect
, model
, item
, col
->GetModelColumn() );
2927 wxWindow
*parent
= GetParent();
2928 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
2930 le
.SetEventObject(parent
);
2931 le
.SetModel(GetOwner()->GetModel());
2933 parent
->GetEventHandler()->ProcessEvent(le
);
2939 // The first click was on another item, so don't interpret this as
2940 // a double click, but as a simple click instead
2947 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
2949 // select single line
2950 SelectAllRows( false );
2951 SelectRow( m_lineSelectSingleOnUp
, true );
2954 //Process the event of user clicking the expander
2955 bool expander
= false;
2956 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
2958 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
2959 if( node
!=NULL
&& node
->HasChildren() )
2961 int indent
= node
->GetIndentLevel();
2962 indent
= GetOwner()->GetIndent()*indent
;
2963 wxRect
rect( xpos
+ indent
+ EXPANDER_MARGIN
,
2964 GetLineStart( current
) + EXPANDER_MARGIN
+ (GetLineHeight(current
)/2) - (m_lineHeight
/2) - EXPANDER_OFFSET
,
2965 m_lineHeight
-2*EXPANDER_MARGIN
,
2966 m_lineHeight
-2*EXPANDER_MARGIN
+ EXPANDER_OFFSET
);
2968 if( rect
.Contains( x
, y
) )
2971 if( node
->IsOpen() )
2972 OnCollapsing(current
);
2974 OnExpanding( current
);
2977 if (node
&& !node
->HasChildren())
2980 //If the user click the expander, we do not do editing even if the column with expander are editable
2981 if (m_lastOnSame
&& !expander
&& !ignore_other_columns
)
2983 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
2984 (cell
->GetMode() & wxDATAVIEW_CELL_EDITABLE
) )
2986 m_renameTimer
->Start( 100, true );
2990 m_lastOnSame
= false;
2991 m_lineSelectSingleOnUp
= (unsigned int)-1;
2995 // This is necessary, because after a DnD operation in
2996 // from and to ourself, the up event is swallowed by the
2997 // DnD code. So on next non-up event (which means here and
2998 // now) m_lineSelectSingleOnUp should be reset.
2999 m_lineSelectSingleOnUp
= (unsigned int)-1;
3002 if (event
.RightDown())
3004 m_lineBeforeLastClicked
= m_lineLastClicked
;
3005 m_lineLastClicked
= current
;
3007 // If the item is already selected, do not update the selection.
3008 // Multi-selections should not be cleared if a selected item is clicked.
3009 if (!IsRowSelected(current
))
3011 SelectAllRows(false);
3012 ChangeCurrentRow(current
);
3013 SelectRow(m_currentRow
,true);
3014 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3018 model
->GetValue( value
, item
, col
->GetModelColumn() );
3019 wxWindow
*parent
= GetParent();
3020 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
3022 le
.SetEventObject(parent
);
3023 le
.SetModel(GetOwner()->GetModel());
3025 parent
->GetEventHandler()->ProcessEvent(le
);
3027 else if (event
.MiddleDown())
3030 if (event
.LeftDown() || forceClick
)
3034 m_lineBeforeLastClicked
= m_lineLastClicked
;
3035 m_lineLastClicked
= current
;
3037 unsigned int oldCurrentRow
= m_currentRow
;
3038 bool oldWasSelected
= IsRowSelected(m_currentRow
);
3040 bool cmdModifierDown
= event
.CmdDown();
3041 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3043 if ( IsSingleSel() || !IsRowSelected(current
) )
3045 SelectAllRows( false );
3046 ChangeCurrentRow(current
);
3047 SelectRow(m_currentRow
,true);
3048 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3050 else // multi sel & current is highlighted & no mod keys
3052 m_lineSelectSingleOnUp
= current
;
3053 ChangeCurrentRow(current
); // change focus
3056 else // multi sel & either ctrl or shift is down
3058 if (cmdModifierDown
)
3060 ChangeCurrentRow(current
);
3061 ReverseRowSelection(m_currentRow
);
3062 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3064 else if (event
.ShiftDown())
3066 ChangeCurrentRow(current
);
3068 unsigned int lineFrom
= oldCurrentRow
,
3071 if ( lineTo
< lineFrom
)
3074 lineFrom
= m_currentRow
;
3077 SelectRows(lineFrom
, lineTo
, true);
3078 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3080 else // !ctrl, !shift
3082 // test in the enclosing if should make it impossible
3083 wxFAIL_MSG( _T("how did we get here?") );
3087 if (m_currentRow
!= oldCurrentRow
)
3088 RefreshRow( oldCurrentRow
);
3090 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
3092 // Update selection here...
3095 m_lastOnSame
= !forceClick
&& ((col
== oldCurrentCol
) &&
3096 (current
== oldCurrentRow
)) && oldWasSelected
;
3098 // Call LeftClick after everything else as under GTK+
3099 if (cell
->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE
)
3101 // notify cell about right click
3103 model
->GetValue( value
, item
, col
->GetModelColumn() );
3104 cell
->SetValue( value
);
3105 wxRect
cell_rect( xpos
, GetLineStart( current
),
3106 col
->GetWidth(), GetLineHeight( current
) );
3107 /* ignore ret */ cell
->LeftClick( event
.GetPosition(), cell_rect
, model
, item
, col
->GetModelColumn());
3112 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
3116 if (HasCurrentRow())
3122 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
3126 if (HasCurrentRow())
3132 wxDataViewItem
wxDataViewMainWindow::GetSelection() const
3134 if( m_selection
.GetCount() != 1 )
3135 return wxDataViewItem();
3137 return GetItemByRow( m_selection
.Item(0));
3140 //-----------------------------------------------------------------------------
3142 //-----------------------------------------------------------------------------
3143 WX_DEFINE_LIST(wxDataViewColumnList
)
3145 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3147 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
3148 EVT_SIZE(wxDataViewCtrl::OnSize
)
3151 wxDataViewCtrl::~wxDataViewCtrl()
3154 GetModel()->RemoveNotifier( m_notifier
);
3159 void wxDataViewCtrl::Init()
3161 m_cols
.DeleteContents(true);
3164 // No sorting column at start
3165 m_sortingColumn
= NULL
;
3166 m_headerArea
= NULL
;
3169 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3170 const wxPoint
& pos
, const wxSize
& size
,
3171 long style
, const wxValidator
& validator
)
3173 if ( (style
& wxBORDER_MASK
) == 0)
3174 style
|= wxBORDER_SUNKEN
;
3178 if (!wxControl::Create( parent
, id
, pos
, size
,
3179 style
| wxScrolledWindowStyle
, validator
))
3182 SetInitialSize(size
);
3185 MacSetClipChildren( true );
3188 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
3190 if (HasFlag(wxDV_NO_HEADER
))
3191 m_headerArea
= NULL
;
3193 m_headerArea
= new wxDataViewHeaderWindow(this);
3195 SetTargetWindow( m_clientArea
);
3197 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
3199 sizer
->Add( m_headerArea
, 0, wxGROW
);
3200 sizer
->Add( m_clientArea
, 1, wxGROW
);
3207 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
3211 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
3214 // we need to process arrows ourselves for scrolling
3215 if ( nMsg
== WM_GETDLGCODE
)
3217 rc
|= DLGC_WANTARROWS
;
3225 wxSize
wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
3227 wxSize newsize
= size
;
3228 if (!HasFlag(wxDV_NO_HEADER
) && (m_headerArea
))
3229 newsize
.y
-= m_headerArea
->GetSize().y
;
3234 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3236 // We need to override OnSize so that our scrolled
3237 // window a) does call Layout() to use sizers for
3238 // positioning the controls but b) does not query
3239 // the sizer for their size and use that for setting
3240 // the scrollable area as set that ourselves by
3241 // calling SetScrollbar() further down.
3248 void wxDataViewCtrl::SetFocus()
3251 m_clientArea
->SetFocus();
3254 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3256 if (!wxDataViewCtrlBase::AssociateModel( model
))
3259 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
3261 model
->AddNotifier( m_notifier
);
3263 m_clientArea
->DestroyTree();
3265 m_clientArea
->BuildTree(model
);
3267 m_clientArea
->UpdateDisplay();
3272 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
3274 if (!wxDataViewCtrlBase::AppendColumn(col
))
3277 m_cols
.Append( col
);
3282 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
3284 if (!wxDataViewCtrlBase::PrependColumn(col
))
3287 m_cols
.Insert( col
);
3292 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
3294 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
3297 m_cols
.Insert( pos
, col
);
3302 void wxDataViewCtrl::OnColumnChange()
3305 m_headerArea
->SetColumnCount(GetColumnCount());
3307 m_clientArea
->UpdateDisplay();
3310 void wxDataViewCtrl::DoSetExpanderColumn()
3312 m_clientArea
->UpdateDisplay();
3315 void wxDataViewCtrl::DoSetIndent()
3317 m_clientArea
->UpdateDisplay();
3320 unsigned int wxDataViewCtrl::GetColumnCount() const
3322 return m_cols
.GetCount();
3325 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
3327 wxDataViewColumnList::const_iterator iter
;
3329 for (iter
= m_cols
.begin(); iter
!=m_cols
.end(); iter
++)
3334 if ((*iter
)->IsHidden())
3341 void wxDataViewCtrl::ColumnMoved( wxDataViewColumn
* col
, unsigned int new_pos
)
3343 if (new_pos
> m_cols
.GetCount()) return;
3345 // Exchange position
3346 m_cols
.DeleteContents(false);
3347 m_cols
.DeleteObject( col
);
3348 m_cols
.Insert( new_pos
, col
);
3349 m_cols
.DeleteContents(true);
3351 m_clientArea
->UpdateDisplay();
3354 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
3356 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
3366 bool wxDataViewCtrl::ClearColumns()
3373 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
3375 int ret
= 0, dead
= 0;
3376 int len
= GetColumnCount();
3377 for (int i
=0; i
<len
; i
++)
3379 wxDataViewColumn
* col
= GetColumn(i
);
3380 if (col
->IsHidden())
3382 ret
+= col
->GetWidth();
3385 CalcScrolledPosition( ret
, dead
, &ret
, &dead
);
3392 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
3397 //Selection code with wxDataViewItem as parameters
3398 wxDataViewItem
wxDataViewCtrl::GetSelection() const
3400 return m_clientArea
->GetSelection();
3403 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
3406 wxDataViewSelection selection
= m_clientArea
->GetSelections();
3407 int len
= selection
.GetCount();
3408 for( int i
= 0; i
< len
; i
++)
3410 unsigned int row
= selection
[i
];
3411 sel
.Add( m_clientArea
->GetItemByRow( row
) );
3416 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
3418 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
3419 int len
= sel
.GetCount();
3420 for( int i
= 0; i
< len
; i
++ )
3422 int row
= m_clientArea
->GetRowByItem( sel
[i
] );
3424 selection
.Add( static_cast<unsigned int>(row
) );
3426 m_clientArea
->SetSelections( selection
);
3429 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
3431 int row
= m_clientArea
->GetRowByItem( item
);
3434 //Unselect all rows before select another in the single select mode
3435 if (m_clientArea
->IsSingleSel())
3436 m_clientArea
->SelectAllRows(false);
3437 m_clientArea
->SelectRow(row
, true);
3441 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
3443 int row
= m_clientArea
->GetRowByItem( item
);
3445 m_clientArea
->SelectRow(row
, false);
3448 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
3450 int row
= m_clientArea
->GetRowByItem( item
);
3453 return m_clientArea
->IsRowSelected(row
);
3458 //Selection code with row number as parameter
3459 int wxDataViewCtrl::GetSelections( wxArrayInt
& sel
) const
3462 wxDataViewSelection selection
= m_clientArea
->GetSelections();
3463 int len
= selection
.GetCount();
3464 for( int i
= 0; i
< len
; i
++)
3466 unsigned int row
= selection
[i
];
3472 void wxDataViewCtrl::SetSelections( const wxArrayInt
& sel
)
3474 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
3475 int len
= sel
.GetCount();
3476 for( int i
= 0; i
< len
; i
++ )
3480 selection
.Add( static_cast<unsigned int>(row
) );
3482 m_clientArea
->SetSelections( selection
);
3485 void wxDataViewCtrl::Select( int row
)
3489 if (m_clientArea
->IsSingleSel())
3490 m_clientArea
->SelectAllRows(false);
3491 m_clientArea
->SelectRow( row
, true );
3495 void wxDataViewCtrl::Unselect( int row
)
3498 m_clientArea
->SelectRow(row
, false);
3501 bool wxDataViewCtrl::IsSelected( int row
) const
3504 return m_clientArea
->IsRowSelected(row
);
3508 void wxDataViewCtrl::SelectRange( int from
, int to
)
3511 for( int i
= from
; i
< to
; i
++ )
3513 m_clientArea
->Select(sel
);
3516 void wxDataViewCtrl::UnselectRange( int from
, int to
)
3518 wxDataViewSelection sel
= m_clientArea
->GetSelections();
3519 for( int i
= from
; i
< to
; i
++ )
3520 if( sel
.Index( i
) != wxNOT_FOUND
)
3522 m_clientArea
->SetSelections(sel
);
3525 void wxDataViewCtrl::SelectAll()
3527 m_clientArea
->SelectAllRows(true);
3530 void wxDataViewCtrl::UnselectAll()
3532 m_clientArea
->SelectAllRows(false);
3535 void wxDataViewCtrl::EnsureVisible( int row
, int column
)
3539 if( row
> (int) m_clientArea
->GetRowCount() )
3540 row
= m_clientArea
->GetRowCount();
3542 int first
= m_clientArea
->GetFirstVisibleRow();
3543 int last
= m_clientArea
->GetLastVisibleRow();
3545 m_clientArea
->ScrollTo( row
, column
);
3546 else if( row
> last
)
3547 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
3549 m_clientArea
->ScrollTo( first
, column
);
3552 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
3554 int row
= m_clientArea
->GetRowByItem(item
);
3557 if( column
== NULL
)
3558 EnsureVisible(row
, -1);
3562 int len
= GetColumnCount();
3563 for( int i
= 0; i
< len
; i
++ )
3564 if( GetColumn(i
) == column
)
3569 EnsureVisible( row
, col
);
3575 void wxDataViewCtrl::HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
) const
3577 m_clientArea
->HitTest(point
, item
, column
);
3580 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
) const
3582 return m_clientArea
->GetItemRect(item
, column
);
3585 wxDataViewItem
wxDataViewCtrl::GetItemByRow( unsigned int row
) const
3587 return m_clientArea
->GetItemByRow( row
);
3590 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem
& item
) const
3592 return m_clientArea
->GetRowByItem( item
);
3595 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
3597 int row
= m_clientArea
->GetRowByItem( item
);
3599 m_clientArea
->Expand(row
);
3602 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
3604 int row
= m_clientArea
->GetRowByItem( item
);
3606 m_clientArea
->Collapse(row
);
3610 // !wxUSE_GENERICDATAVIEWCTRL
3613 // wxUSE_DATAVIEWCTRL