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 // implement/override wxHeaderCtrl functions by forwarding them to the main
94 virtual wxHeaderColumnBase
& GetColumn(unsigned int idx
)
96 return *(GetOwner()->GetColumn(idx
));
99 virtual bool UpdateColumnWidthToFit(unsigned int idx
, int widthTitle
)
101 wxDataViewCtrl
* const owner
= GetOwner();
103 int widthContents
= owner
->GetBestColumnWidth(idx
);
104 owner
->GetColumn(idx
)->SetWidth(wxMax(widthTitle
, widthContents
));
110 bool SendEvent(wxEventType type
, unsigned int n
)
112 wxDataViewCtrl
* const owner
= GetOwner();
113 wxDataViewEvent
event(type
, owner
->GetId());
115 event
.SetEventObject(owner
);
117 event
.SetDataViewColumn(owner
->GetColumn(n
));
118 event
.SetModel(owner
->GetModel());
120 // for events created by wxDataViewHeaderWindow the
121 // row / value fields are not valid
122 return owner
->GetEventHandler()->ProcessEvent(event
);
125 void OnClick(wxHeaderCtrlEvent
& event
)
127 if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
,
132 void OnRClick(wxHeaderCtrlEvent
& event
)
134 if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
139 DECLARE_EVENT_TABLE()
140 DECLARE_NO_COPY_CLASS(wxDataViewHeaderWindow
)
143 BEGIN_EVENT_TABLE(wxDataViewHeaderWindow
, wxHeaderCtrl
)
144 EVT_HEADER_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnClick
)
145 EVT_HEADER_RIGHT_CLICK(wxID_ANY
, wxDataViewHeaderWindow::OnRClick
)
148 //-----------------------------------------------------------------------------
149 // wxDataViewRenameTimer
150 //-----------------------------------------------------------------------------
152 class wxDataViewRenameTimer
: public wxTimer
155 wxDataViewMainWindow
*m_owner
;
158 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
162 //-----------------------------------------------------------------------------
163 // wxDataViewTreeNode
164 //-----------------------------------------------------------------------------
165 class wxDataViewTreeNode
;
166 WX_DEFINE_ARRAY( wxDataViewTreeNode
*, wxDataViewTreeNodes
);
167 WX_DEFINE_ARRAY( void* , wxDataViewTreeLeaves
);
169 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
, wxDataViewTreeNode
** node2
);
170 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
);
172 class wxDataViewTreeNode
175 wxDataViewTreeNode( wxDataViewTreeNode
* parent
= NULL
)
182 m_hasChildren
= false;
186 ~wxDataViewTreeNode()
190 wxDataViewTreeNode
* GetParent() const { return m_parent
; }
191 void SetParent( wxDataViewTreeNode
* parent
) { m_parent
= parent
; }
192 wxDataViewTreeNodes
& GetNodes() { return m_nodes
; }
193 wxDataViewTreeLeaves
& GetChildren() { return m_leaves
; }
195 void AddNode( wxDataViewTreeNode
* node
)
197 m_leaves
.Add( node
->GetItem().GetID() );
199 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
202 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
204 void AddLeaf( void * leaf
)
206 m_leaves
.Add( leaf
);
208 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
211 wxDataViewItem
& GetItem() { return m_item
; }
212 const wxDataViewItem
& GetItem() const { return m_item
; }
213 void SetItem( const wxDataViewItem
& item
) { m_item
= item
; }
215 unsigned int GetChildrenNumber() const { return m_leaves
.GetCount(); }
216 unsigned int GetNodeNumber() const { return m_nodes
.GetCount(); }
217 int GetIndentLevel() const
220 const wxDataViewTreeNode
* node
= this;
221 while( node
->GetParent()->GetParent() != NULL
)
223 node
= node
->GetParent();
236 int len
= m_nodes
.GetCount();
238 for ( int i
= 0;i
< len
; i
++)
239 sum
+= m_nodes
[i
]->GetSubTreeCount();
241 sum
+= m_leaves
.GetCount();
244 ChangeSubTreeCount(-sum
);
250 ChangeSubTreeCount(sum
);
253 bool HasChildren() const { return m_hasChildren
; }
254 void SetHasChildren( bool has
){ m_hasChildren
= has
; }
256 void SetSubTreeCount( int num
) { m_subTreeCount
= num
; }
257 int GetSubTreeCount() const { return m_subTreeCount
; }
258 void ChangeSubTreeCount( int num
)
262 m_subTreeCount
+= num
;
264 m_parent
->ChangeSubTreeCount(num
);
271 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
272 int len
= m_nodes
.GetCount();
273 for (int i
= 0; i
< len
; i
++)
274 m_nodes
[i
]->Resort();
275 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
280 wxDataViewTreeNode
*m_parent
;
281 wxDataViewTreeNodes m_nodes
;
282 wxDataViewTreeLeaves m_leaves
;
283 wxDataViewItem m_item
;
289 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
, wxDataViewTreeNode
** node2
)
291 return g_model
->Compare( (*node1
)->GetItem(), (*node2
)->GetItem(), g_column
, g_asending
);
294 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
)
296 return g_model
->Compare( *id1
, *id2
, g_column
, g_asending
);
301 //-----------------------------------------------------------------------------
302 // wxDataViewMainWindow
303 //-----------------------------------------------------------------------------
305 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
,
307 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
308 WX_DEFINE_LIST(ItemList
)
310 class wxDataViewMainWindow
: public wxWindow
313 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
315 const wxPoint
&pos
= wxDefaultPosition
,
316 const wxSize
&size
= wxDefaultSize
,
317 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
318 virtual ~wxDataViewMainWindow();
320 bool IsVirtualList() const { return m_root
== NULL
; }
322 // notifications from wxDataViewModel
323 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
324 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
325 bool ItemChanged( const wxDataViewItem
&item
);
326 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
330 if (!IsVirtualList())
340 g_model
= GetOwner()->GetModel();
341 wxDataViewColumn
* col
= GetOwner()->GetSortingColumn();
344 if (g_model
->HasDefaultCompare())
352 g_column
= col
->GetModelColumn();
353 g_asending
= col
->IsSortOrderAscending();
356 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
357 wxDataViewCtrl
*GetOwner() { return m_owner
; }
358 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
360 void OnPaint( wxPaintEvent
&event
);
361 void OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
);
362 void OnChar( wxKeyEvent
&event
);
363 void OnMouse( wxMouseEvent
&event
);
364 void OnSetFocus( wxFocusEvent
&event
);
365 void OnKillFocus( wxFocusEvent
&event
);
367 void UpdateDisplay();
368 void RecalculateDisplay();
369 void OnInternalIdle();
371 void OnRenameTimer();
373 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
374 void ScrollTo( int rows
, int column
);
376 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
377 void ChangeCurrentRow( unsigned int row
);
379 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
380 bool IsEmpty() { return GetRowCount() == 0; }
382 int GetCountPerPage() const;
383 int GetEndOfLastCol() const;
384 unsigned int GetFirstVisibleRow() const;
385 //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
386 unsigned int GetLastVisibleRow();
387 unsigned int GetRowCount();
389 wxDataViewItem
GetSelection() const;
390 wxDataViewSelection
GetSelections(){ return m_selection
; }
391 void SetSelections( const wxDataViewSelection
& sel
) { m_selection
= sel
; UpdateDisplay(); }
392 void Select( const wxArrayInt
& aSelections
);
393 void SelectAllRows( bool on
);
394 void SelectRow( unsigned int row
, bool on
);
395 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
396 void ReverseRowSelection( unsigned int row
);
397 bool IsRowSelected( unsigned int row
);
398 void SendSelectionChangedEvent( const wxDataViewItem
& item
);
400 void RefreshRow( unsigned int row
);
401 void RefreshRows( unsigned int from
, unsigned int to
);
402 void RefreshRowsAfter( unsigned int firstRow
);
404 // returns the colour to be used for drawing the rules
405 wxColour
GetRuleColour() const
407 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
410 wxRect
GetLineRect( unsigned int row
) const;
412 int GetLineStart( unsigned int row
) const; // row * m_lineHeight in fixed mode
413 int GetLineHeight( unsigned int row
) const; // m_lineHeight in fixed mode
414 int GetLineAt( unsigned int y
) const; // y / m_lineHeight in fixed mode
416 //Some useful functions for row and item mapping
417 wxDataViewItem
GetItemByRow( unsigned int row
) const;
418 int GetRowByItem( const wxDataViewItem
& item
) const;
420 //Methods for building the mapping tree
421 void BuildTree( wxDataViewModel
* model
);
423 void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
);
424 wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
);
426 void Expand( unsigned int row
) { OnExpanding( row
); }
427 void Collapse( unsigned int row
) { OnCollapsing( row
); }
429 wxDataViewTreeNode
* GetTreeNodeByRow( unsigned int row
) const;
430 //We did not need this temporarily
431 //wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
433 int RecalculateCount();
435 wxDataViewEvent
SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
);
436 void OnExpanding( unsigned int row
);
437 void OnCollapsing( unsigned int row
);
439 wxDataViewTreeNode
* FindNode( const wxDataViewItem
& item
);
442 wxDataViewCtrl
*m_owner
;
446 wxDataViewColumn
*m_currentCol
;
447 unsigned int m_currentRow
;
448 wxDataViewSelection m_selection
;
450 wxDataViewRenameTimer
*m_renameTimer
;
458 // for double click logic
459 unsigned int m_lineLastClicked
,
460 m_lineBeforeLastClicked
,
461 m_lineSelectSingleOnUp
;
463 // the pen used to draw horiz/vertical rules
466 // the pen used to draw the expander and the lines
469 //This is the tree structure of the model
470 wxDataViewTreeNode
* m_root
;
472 //This is the tree node under the cursor
473 wxDataViewTreeNode
* m_underMouse
;
475 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
476 DECLARE_EVENT_TABLE()
479 // ---------------------------------------------------------
480 // wxGenericDataViewModelNotifier
481 // ---------------------------------------------------------
483 class wxGenericDataViewModelNotifier
: public wxDataViewModelNotifier
486 wxGenericDataViewModelNotifier( wxDataViewMainWindow
*mainWindow
)
487 { m_mainWindow
= mainWindow
; }
489 virtual bool ItemAdded( const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
490 { return m_mainWindow
->ItemAdded( parent
, item
); }
491 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
492 { return m_mainWindow
->ItemDeleted( parent
, item
); }
493 virtual bool ItemChanged( const wxDataViewItem
& item
)
494 { return m_mainWindow
->ItemChanged(item
); }
495 virtual bool ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
496 { return m_mainWindow
->ValueChanged( item
, col
); }
497 virtual bool Cleared()
498 { return m_mainWindow
->Cleared(); }
499 virtual void Resort()
500 { m_mainWindow
->Resort(); }
502 wxDataViewMainWindow
*m_mainWindow
;
505 // ---------------------------------------------------------
506 // wxDataViewRenderer
507 // ---------------------------------------------------------
509 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
511 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
512 wxDataViewCellMode mode
,
514 wxDataViewRendererBase( varianttype
, mode
, align
)
523 wxDataViewRenderer::~wxDataViewRenderer()
529 wxDC
*wxDataViewRenderer::GetDC()
533 if (GetOwner() == NULL
)
535 if (GetOwner()->GetOwner() == NULL
)
537 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
543 void wxDataViewRenderer::SetAlignment( int align
)
548 int wxDataViewRenderer::GetAlignment() const
553 int wxDataViewRenderer::CalculateAlignment() const
555 if (m_align
== wxDVR_DEFAULT_ALIGNMENT
)
557 if (GetOwner() == NULL
)
558 return wxALIGN_LEFT
| wxALIGN_CENTRE_VERTICAL
;
560 return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
566 // ---------------------------------------------------------
567 // wxDataViewCustomRenderer
568 // ---------------------------------------------------------
570 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
572 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
573 wxDataViewCellMode mode
, int align
) :
574 wxDataViewRenderer( varianttype
, mode
, align
)
578 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
580 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
581 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
582 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
583 view
->GetForegroundColour();
584 dc
->SetTextForeground(col
);
585 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
588 // ---------------------------------------------------------
589 // wxDataViewTextRenderer
590 // ---------------------------------------------------------
592 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
594 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
595 wxDataViewCellMode mode
, int align
) :
596 wxDataViewCustomRenderer( varianttype
, mode
, align
)
600 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
602 m_text
= value
.GetString();
607 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
612 bool wxDataViewTextRenderer::HasEditorCtrl()
617 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
618 wxRect labelRect
, const wxVariant
&value
)
620 return new wxTextCtrl( parent
, wxID_ANY
, value
,
621 wxPoint(labelRect
.x
,labelRect
.y
),
622 wxSize(labelRect
.width
,labelRect
.height
) );
625 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
627 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
628 value
= text
->GetValue();
632 bool wxDataViewTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
634 RenderText( m_text
, 0, cell
, dc
, state
);
638 wxSize
wxDataViewTextRenderer::GetSize() const
640 const wxDataViewCtrl
*view
= GetView();
644 view
->GetTextExtent( m_text
, &x
, &y
);
645 return wxSize( x
, y
);
647 return wxSize(80,20);
650 // ---------------------------------------------------------
651 // wxDataViewTextRendererAttr
652 // ---------------------------------------------------------
654 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
, wxDataViewTextRenderer
)
656 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
657 wxDataViewCellMode mode
, int align
) :
658 wxDataViewTextRenderer( varianttype
, mode
, align
)
663 bool wxDataViewTextRendererAttr::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
670 if (m_attr
.HasColour())
672 colour
= dc
->GetTextForeground();
673 dc
->SetTextForeground( m_attr
.GetColour() );
676 if (m_attr
.GetBold() || m_attr
.GetItalic())
678 font
= dc
->GetFont();
679 wxFont myfont
= font
;
680 if (m_attr
.GetBold())
681 myfont
.SetWeight( wxFONTWEIGHT_BOLD
);
682 if (m_attr
.GetItalic())
683 myfont
.SetStyle( wxFONTSTYLE_ITALIC
);
684 dc
->SetFont( myfont
);
688 dc
->DrawText( m_text
, cell
.x
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
693 if (m_attr
.HasColour())
694 dc
->SetTextForeground( colour
);
696 if (m_attr
.GetBold() || m_attr
.GetItalic())
704 // ---------------------------------------------------------
705 // wxDataViewBitmapRenderer
706 // ---------------------------------------------------------
708 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
710 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
711 wxDataViewCellMode mode
, int align
) :
712 wxDataViewCustomRenderer( varianttype
, mode
, align
)
716 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
718 if (value
.GetType() == wxT("wxBitmap"))
720 if (value
.GetType() == wxT("wxIcon"))
726 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
731 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
734 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
735 else if (m_icon
.Ok())
736 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
741 wxSize
wxDataViewBitmapRenderer::GetSize() const
744 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
745 else if (m_icon
.Ok())
746 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
748 return wxSize(16,16);
751 // ---------------------------------------------------------
752 // wxDataViewToggleRenderer
753 // ---------------------------------------------------------
755 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
757 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
758 wxDataViewCellMode mode
, int align
) :
759 wxDataViewCustomRenderer( varianttype
, mode
, align
)
764 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
766 m_toggle
= value
.GetBool();
771 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
776 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
778 // User wxRenderer here
781 rect
.x
= cell
.x
+ cell
.width
/2 - 10;
783 rect
.y
= cell
.y
+ cell
.height
/2 - 10;
788 flags
|= wxCONTROL_CHECKED
;
789 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
790 flags
|= wxCONTROL_DISABLED
;
792 wxRendererNative::Get().DrawCheckBox(
793 GetOwner()->GetOwner(),
801 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
802 wxDataViewModel
*model
,
803 const wxDataViewItem
& item
, unsigned int col
)
805 bool value
= !m_toggle
;
806 wxVariant variant
= value
;
807 model
->SetValue( variant
, item
, col
);
808 model
->ValueChanged( item
, col
);
812 wxSize
wxDataViewToggleRenderer::GetSize() const
814 return wxSize(20,20);
817 // ---------------------------------------------------------
818 // wxDataViewProgressRenderer
819 // ---------------------------------------------------------
821 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
823 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
824 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
825 wxDataViewCustomRenderer( varianttype
, mode
, align
)
831 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
835 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
837 m_value
= (long) value
;
839 if (m_value
< 0) m_value
= 0;
840 if (m_value
> 100) m_value
= 100;
845 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
847 value
= (long) m_value
;
851 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
853 double pct
= (double)m_value
/ 100.0;
855 bar
.width
= (int)(cell
.width
* pct
);
856 dc
->SetPen( *wxTRANSPARENT_PEN
);
857 dc
->SetBrush( *wxBLUE_BRUSH
);
858 dc
->DrawRectangle( bar
);
860 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
861 dc
->SetPen( *wxBLACK_PEN
);
862 dc
->DrawRectangle( cell
);
867 wxSize
wxDataViewProgressRenderer::GetSize() const
869 return wxSize(40,12);
872 // ---------------------------------------------------------
873 // wxDataViewDateRenderer
874 // ---------------------------------------------------------
876 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
878 #if wxUSE_DATE_RENDERER_POPUP
880 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
883 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
884 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
) :
885 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
),
890 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
891 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
892 sizer
->Add( m_cal
, 1, wxGROW
);
897 void OnCalendar( wxCalendarEvent
&event
);
899 wxCalendarCtrl
*m_cal
;
900 wxDataViewModel
*m_model
;
902 const wxDataViewItem
& m_item
;
905 virtual void OnDismiss()
910 DECLARE_EVENT_TABLE()
913 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
914 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
917 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
919 wxDateTime date
= event
.GetDate();
920 wxVariant value
= date
;
921 m_model
->SetValue( value
, m_item
, m_col
);
922 m_model
->ValueChanged( m_item
, m_col
);
926 #endif // wxUSE_DATE_RENDERER_POPUP
928 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
930 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
931 wxDataViewCellMode mode
, int align
) :
932 wxDataViewCustomRenderer( varianttype
, mode
, align
)
936 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
938 m_date
= value
.GetDateTime();
943 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
949 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
951 wxString tmp
= m_date
.FormatDate();
952 RenderText( tmp
, 0, cell
, dc
, state
);
956 wxSize
wxDataViewDateRenderer::GetSize() const
958 const wxDataViewCtrl
* view
= GetView();
959 wxString tmp
= m_date
.FormatDate();
961 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
962 return wxSize(x
,y
+d
);
965 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
966 const wxDataViewItem
& item
, unsigned int col
)
969 model
->GetValue( variant
, item
, col
);
970 wxDateTime value
= variant
.GetDateTime();
972 #if wxUSE_DATE_RENDERER_POPUP
973 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
974 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
975 wxPoint pos
= wxGetMousePosition();
978 popup
->Popup( popup
->m_cal
);
979 #else // !wxUSE_DATE_RENDERER_POPUP
980 wxMessageBox(value
.Format());
981 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
985 // ---------------------------------------------------------
986 // wxDataViewIconTextRenderer
987 // ---------------------------------------------------------
989 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
991 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
992 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
993 wxDataViewCustomRenderer( varianttype
, mode
, align
)
999 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1003 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1009 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1014 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1017 const wxIcon
&icon
= m_value
.GetIcon();
1020 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ ((cell
.height
- icon
.GetHeight()) / 2));
1021 xoffset
= icon
.GetWidth()+4;
1024 RenderText( m_value
.GetText(), xoffset
, cell
, dc
, state
);
1029 wxSize
wxDataViewIconTextRenderer::GetSize() const
1031 const wxDataViewCtrl
*view
= GetView();
1032 if (!m_value
.GetText().empty())
1035 view
->GetTextExtent( m_value
.GetText(), &x
, &y
);
1037 if (m_value
.GetIcon().IsOk())
1038 x
+= m_value
.GetIcon().GetWidth() + 4;
1039 return wxSize( x
, y
);
1041 return wxSize(80,20);
1045 wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
* WXUNUSED(parent
),
1046 wxRect
WXUNUSED(labelRect
),
1047 const wxVariant
& WXUNUSED(value
))
1053 wxDataViewIconTextRenderer::GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
),
1054 wxVariant
& WXUNUSED(value
))
1059 //-----------------------------------------------------------------------------
1060 // wxDataViewRenameTimer
1061 //-----------------------------------------------------------------------------
1063 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1068 void wxDataViewRenameTimer::Notify()
1070 m_owner
->OnRenameTimer();
1073 //-----------------------------------------------------------------------------
1074 // wxDataViewMainWindow
1075 //-----------------------------------------------------------------------------
1077 //The tree building helper, declared firstly
1078 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
, wxDataViewTreeNode
* node
);
1080 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1082 if (row1
> row2
) return 1;
1083 if (row1
== row2
) return 0;
1088 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1090 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1091 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1092 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1093 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1094 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1095 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1098 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1099 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1100 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
1101 m_selection( wxDataViewSelectionCmp
)
1106 m_lastOnSame
= false;
1107 m_renameTimer
= new wxDataViewRenameTimer( this );
1109 // TODO: user better initial values/nothing selected
1110 m_currentCol
= NULL
;
1113 m_lineHeight
= wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
1116 m_dragStart
= wxPoint(0,0);
1117 m_lineLastClicked
= (unsigned int) -1;
1118 m_lineBeforeLastClicked
= (unsigned int) -1;
1119 m_lineSelectSingleOnUp
= (unsigned int) -1;
1123 SetBackgroundColour( *wxWHITE
);
1125 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1127 m_penRule
= wxPen(GetRuleColour());
1129 //Here I compose a pen can draw black lines, maybe there are something system colour to use
1130 m_penExpander
= wxPen(wxColour(0,0,0));
1131 //Some new added code to deal with the tree structure
1132 m_root
= new wxDataViewTreeNode( NULL
);
1133 m_root
->SetHasChildren(true);
1135 //Make m_count = -1 will cause the class recaculate the real displaying number of rows.
1137 m_underMouse
= NULL
;
1141 wxDataViewMainWindow::~wxDataViewMainWindow()
1144 delete m_renameTimer
;
1147 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1149 wxDataViewModel
*model
= GetOwner()->GetModel();
1150 wxAutoBufferedPaintDC
dc( this );
1153 dc
.SetPen( *wxTRANSPARENT_PEN
);
1154 dc
.SetBrush( wxBrush( GetBackgroundColour()) );
1155 dc
.SetBrush( *wxWHITE_BRUSH
);
1156 wxSize
size( GetClientSize() );
1157 dc
.DrawRectangle( 0,0,size
.x
,size
.y
);
1161 GetOwner()->PrepareDC( dc
);
1162 dc
.SetFont( GetFont() );
1164 wxRect update
= GetUpdateRegion().GetBox();
1165 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1167 // compute which items needs to be redrawn
1168 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
1169 unsigned int item_count
=
1170 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
1171 (int)(GetRowCount( ) - item_start
));
1172 unsigned int item_last
= item_start
+ item_count
;
1174 // compute which columns needs to be redrawn
1175 unsigned int cols
= GetOwner()->GetColumnCount();
1176 unsigned int col_start
= 0;
1177 unsigned int x_start
;
1178 for (x_start
= 0; col_start
< cols
; col_start
++)
1180 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_start
);
1181 if (col
->IsHidden())
1182 continue; // skip it!
1184 unsigned int w
= col
->GetWidth();
1185 if (x_start
+w
>= (unsigned int)update
.x
)
1191 unsigned int col_last
= col_start
;
1192 unsigned int x_last
= x_start
;
1193 for (; col_last
< cols
; col_last
++)
1195 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_last
);
1196 if (col
->IsHidden())
1197 continue; // skip it!
1199 if (x_last
> (unsigned int)update
.GetRight())
1202 x_last
+= col
->GetWidth();
1205 // Draw horizontal rules if required
1206 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1208 dc
.SetPen(m_penRule
);
1209 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1211 for (unsigned int i
= item_start
; i
<= item_last
+1; i
++)
1213 int y
= GetLineStart( i
);
1214 dc
.DrawLine(x_start
, y
, x_last
, y
);
1218 // Draw vertical rules if required
1219 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1221 dc
.SetPen(m_penRule
);
1222 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1225 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1227 wxDataViewColumn
*col
= GetOwner()->GetColumn(i
);
1228 if (col
->IsHidden())
1229 continue; // skip it
1231 dc
.DrawLine(x
, GetLineStart( item_start
),
1232 x
, GetLineStart( item_last
) );
1234 x
+= col
->GetWidth();
1237 // Draw last vertical rule
1238 dc
.DrawLine(x
, GetLineStart( item_start
),
1239 x
, GetLineStart( item_last
) );
1242 // redraw the background for the items which are selected/current
1243 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1245 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1246 if (selected
|| item
== m_currentRow
)
1248 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
1249 if (item
== m_currentRow
)
1250 flags
|= wxCONTROL_CURRENT
;
1252 flags
|= wxCONTROL_FOCUSED
;
1254 wxRect
rect( x_start
, GetLineStart( item
), x_last
, GetLineHeight( item
) );
1255 wxRendererNative::Get().DrawItemSelectionRect
1265 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
1268 // TODO: last column for RTL support
1269 expander
= GetOwner()->GetColumn( 0 );
1270 GetOwner()->SetExpanderColumn(expander
);
1273 // redraw all cells for all rows which must be repainted and all columns
1275 cell_rect
.x
= x_start
;
1276 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1279 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
1280 wxDataViewRenderer
*cell
= col
->GetRenderer();
1281 cell_rect
.width
= col
->GetWidth();
1283 if (col
->IsHidden())
1284 continue; // skip it!
1286 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1288 // get the cell value and set it into the renderer
1290 wxDataViewTreeNode
*node
= NULL
;
1291 wxDataViewItem dataitem
;
1293 if (!IsVirtualList())
1295 node
= GetTreeNodeByRow(item
);
1299 dataitem
= node
->GetItem();
1301 if ((i
> 0) && model
->IsContainer(dataitem
) && !model
->HasContainerColumns(dataitem
))
1306 dataitem
= wxDataViewItem( wxUIntToPtr(item
) );
1309 model
->GetValue( value
, dataitem
, col
->GetModelColumn());
1310 cell
->SetValue( value
);
1312 if (cell
->GetWantsAttr())
1314 wxDataViewItemAttr attr
;
1315 bool ret
= model
->GetAttr( dataitem
, col
->GetModelColumn(), attr
);
1317 cell
->SetAttr( attr
);
1318 cell
->SetHasAttr( ret
);
1322 cell_rect
.y
= GetLineStart( item
);
1323 cell_rect
.height
= GetLineHeight( item
); // -1 is for the horizontal rules (?)
1325 //Draw the expander here.
1327 if ((!IsVirtualList()) && (col
== expander
))
1329 indent
= node
->GetIndentLevel();
1331 //Calculate the indent first
1332 indent
= cell_rect
.x
+ GetOwner()->GetIndent() * indent
;
1334 int expander_width
= m_lineHeight
- 2*EXPANDER_MARGIN
;
1335 // change the cell_rect.x to the appropriate pos
1336 int expander_x
= indent
+ EXPANDER_MARGIN
;
1337 int expander_y
= cell_rect
.y
+ EXPANDER_MARGIN
+ (GetLineHeight(item
) / 2) - (expander_width
/2) - EXPANDER_OFFSET
;
1338 indent
= indent
+ m_lineHeight
; //try to use the m_lineHeight as the expander space
1339 dc
.SetPen( m_penExpander
);
1340 dc
.SetBrush( wxNullBrush
);
1341 if( node
->HasChildren() )
1343 wxRect
rect( expander_x
, expander_y
, expander_width
, expander_width
);
1345 if (m_underMouse
== node
)
1347 flag
|= wxCONTROL_CURRENT
;
1349 if( node
->IsOpen() )
1350 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
|wxCONTROL_EXPANDED
);
1352 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
1354 //force the expander column to left-center align
1355 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
1357 if (node
&& !node
->HasChildren())
1359 // Yes, if the node does not have any child, it must be a leaf which
1360 // mean that it is a temporarily created by GetTreeNodeByRow
1364 // cannot be bigger than allocated space
1365 wxSize size
= cell
->GetSize();
1366 // Because of the tree structure indent, here we should minus the width of the cell for drawing
1367 size
.x
= wxMin( size
.x
+ 2*PADDING_RIGHTLEFT
, cell_rect
.width
- indent
);
1368 // size.y = wxMin( size.y, cell_rect.height );
1369 size
.y
= cell_rect
.height
;
1371 wxRect
item_rect(cell_rect
.GetTopLeft(), size
);
1372 int align
= cell
->CalculateAlignment();
1374 // horizontal alignment:
1375 item_rect
.x
= cell_rect
.x
;
1376 if (align
& wxALIGN_CENTER_HORIZONTAL
)
1377 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
1378 else if (align
& wxALIGN_RIGHT
)
1379 item_rect
.x
= cell_rect
.x
+ cell_rect
.width
- size
.x
;
1380 //else: wxALIGN_LEFT is the default
1382 // vertical alignment:
1383 item_rect
.y
= cell_rect
.y
;
1384 if (align
& wxALIGN_CENTER_VERTICAL
)
1385 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
1386 else if (align
& wxALIGN_BOTTOM
)
1387 item_rect
.y
= cell_rect
.y
+ cell_rect
.height
- size
.y
;
1388 //else: wxALIGN_TOP is the default
1391 item_rect
.x
+= PADDING_RIGHTLEFT
;
1392 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
1394 //Here we add the tree indent
1395 item_rect
.x
+= indent
;
1398 if (m_hasFocus
&& (m_selection
.Index(item
) != wxNOT_FOUND
))
1399 state
|= wxDATAVIEW_CELL_SELECTED
;
1401 // TODO: it would be much more efficient to create a clipping
1402 // region for the entire column being rendered (in the OnPaint
1403 // of wxDataViewMainWindow) instead of a single clip region for
1404 // each cell. However it would mean that each renderer should
1405 // respect the given wxRect's top & bottom coords, eventually
1406 // violating only the left & right coords - however the user can
1407 // make its own renderer and thus we cannot be sure of that.
1408 dc
.SetClippingRegion( item_rect
);
1409 cell
->Render( item_rect
, &dc
, state
);
1410 dc
.DestroyClippingRegion();
1413 cell_rect
.x
+= cell_rect
.width
;
1417 void wxDataViewMainWindow::OnRenameTimer()
1419 // We have to call this here because changes may just have
1420 // been made and no screen update taken place.
1425 unsigned int cols
= GetOwner()->GetColumnCount();
1427 for (i
= 0; i
< cols
; i
++)
1429 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
1431 continue; // skip it!
1433 if (c
== m_currentCol
)
1435 xpos
+= c
->GetWidth();
1437 wxRect
labelRect( xpos
,
1438 GetLineStart( m_currentRow
),
1439 m_currentCol
->GetWidth(),
1440 GetLineHeight( m_currentRow
) );
1442 GetOwner()->CalcScrolledPosition( labelRect
.x
, labelRect
.y
,
1443 &labelRect
.x
, &labelRect
.y
);
1445 wxDataViewItem item
= GetItemByRow( m_currentRow
);
1446 m_currentCol
->GetRenderer()->StartEditing( item
, labelRect
);
1450 //------------------------------------------------------------------
1451 // Helper class for do operation on the tree node
1452 //------------------------------------------------------------------
1457 virtual ~DoJob() { }
1459 //The return value control how the tree-walker tranverse the tree
1460 // 0: Job done, stop tranverse and return
1461 // 1: Ignore the current node's subtree and continue
1462 // 2: Job not done, continue
1463 enum { OK
= 0 , IGR
= 1, CONT
= 2 };
1464 virtual int operator() ( wxDataViewTreeNode
* node
) = 0;
1465 virtual int operator() ( void * n
) = 0;
1468 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
1473 switch( func( node
) )
1484 wxDataViewTreeNodes nodes
= node
->GetNodes();
1485 wxDataViewTreeLeaves leaves
= node
->GetChildren();
1487 int len_nodes
= nodes
.GetCount();
1488 int len
= leaves
.GetCount();
1489 int i
= 0, nodes_i
= 0;
1491 for(; i
< len
; i
++ )
1493 void * n
= leaves
[i
];
1494 if( nodes_i
< len_nodes
&& n
== nodes
[nodes_i
]->GetItem().GetID() )
1496 wxDataViewTreeNode
* nd
= nodes
[nodes_i
];
1499 if( Walker( nd
, func
) )
1518 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
1529 wxDataViewTreeNode
* node
;
1530 node
= FindNode(parent
);
1535 node
->SetHasChildren( true );
1537 if( g_model
->IsContainer( item
) )
1539 wxDataViewTreeNode
* newnode
= new wxDataViewTreeNode( node
);
1540 newnode
->SetItem(item
);
1541 newnode
->SetHasChildren( true );
1542 node
->AddNode( newnode
);
1545 node
->AddLeaf( item
.GetID() );
1547 node
->ChangeSubTreeCount(1);
1555 static void DestroyTreeHelper( wxDataViewTreeNode
* node
);
1557 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
1558 const wxDataViewItem
& item
)
1563 if( m_currentRow
> GetRowCount() )
1564 m_currentRow
= m_count
- 1;
1566 m_selection
.Empty();
1573 wxDataViewTreeNode
* node
= FindNode(parent
);
1575 wxCHECK_MSG( node
!= NULL
, false, "item not found" );
1576 wxCHECK_MSG( node
->GetChildren().Index( item
.GetID() ) != wxNOT_FOUND
, false, "item not found" );
1579 node
->GetChildren().Remove( item
.GetID() );
1580 //Manuplate selection
1581 if( m_selection
.GetCount() > 1 )
1583 m_selection
.Empty();
1585 bool isContainer
= false;
1586 wxDataViewTreeNodes nds
= node
->GetNodes();
1587 for (size_t i
= 0; i
< nds
.GetCount(); i
++)
1589 if (nds
[i
]->GetItem() == item
)
1597 wxDataViewTreeNode
* n
= NULL
;
1598 wxDataViewTreeNodes nodes
= node
->GetNodes();
1599 int len
= nodes
.GetCount();
1600 for( int i
= 0; i
< len
; i
++)
1602 if( nodes
[i
]->GetItem() == item
)
1609 wxCHECK_MSG( n
!= NULL
, false, "item not found" );
1611 node
->GetNodes().Remove( n
);
1612 sub
-= n
->GetSubTreeCount();
1613 ::DestroyTreeHelper(n
);
1615 //Make the row number invalid and get a new valid one when user call GetRowCount
1617 node
->ChangeSubTreeCount(sub
);
1619 //Change the current row to the last row if the current exceed the max row number
1620 if( m_currentRow
> GetRowCount() )
1621 m_currentRow
= m_count
- 1;
1628 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
1634 wxWindow
*parent
= GetParent();
1635 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
1636 le
.SetEventObject(parent
);
1637 le
.SetModel(GetOwner()->GetModel());
1639 parent
->GetEventHandler()->ProcessEvent(le
);
1644 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
1646 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
1647 /*#define MAX_VIRTUAL_WIDTH 100000
1649 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
1650 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
1651 Refresh( true, &rect );
1659 wxWindow
*parent
= GetParent();
1660 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
1661 le
.SetEventObject(parent
);
1662 le
.SetModel(GetOwner()->GetModel());
1665 le
.SetDataViewColumn(GetOwner()->GetColumn(col
));
1666 parent
->GetEventHandler()->ProcessEvent(le
);
1671 bool wxDataViewMainWindow::Cleared()
1676 BuildTree( GetOwner()->GetModel() );
1683 void wxDataViewMainWindow::UpdateDisplay()
1688 void wxDataViewMainWindow::OnInternalIdle()
1690 wxWindow::OnInternalIdle();
1694 RecalculateDisplay();
1699 void wxDataViewMainWindow::RecalculateDisplay()
1701 wxDataViewModel
*model
= GetOwner()->GetModel();
1708 int width
= GetEndOfLastCol();
1709 int height
= GetLineStart( GetRowCount() );
1711 SetVirtualSize( width
, height
);
1712 GetOwner()->SetScrollRate( 10, m_lineHeight
);
1717 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
1719 wxWindow::ScrollWindow( dx
, dy
, rect
);
1721 if (GetOwner()->m_headerArea
)
1722 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
1725 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
1728 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
1729 int sy
= GetLineStart( rows
)/y
;
1733 wxRect rect
= GetClientRect();
1737 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
1738 for (x_start
= 0; colnum
< column
; colnum
++)
1740 wxDataViewColumn
*col
= GetOwner()->GetColumn(colnum
);
1741 if (col
->IsHidden())
1742 continue; // skip it!
1744 w
= col
->GetWidth();
1748 int x_end
= x_start
+ w
;
1749 xe
= xx
+ rect
.width
;
1752 sx
= ( xx
+ x_end
- xe
)/x
;
1759 m_owner
->Scroll( sx
, sy
);
1762 int wxDataViewMainWindow::GetCountPerPage() const
1764 wxSize size
= GetClientSize();
1765 return size
.y
/ m_lineHeight
;
1768 int wxDataViewMainWindow::GetEndOfLastCol() const
1772 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
1774 const wxDataViewColumn
*c
=
1775 const_cast<wxDataViewCtrl
*>(GetOwner())->GetColumn( i
);
1778 width
+= c
->GetWidth();
1783 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
1787 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
1789 return GetLineAt( y
);
1792 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
1794 wxSize client_size
= GetClientSize();
1795 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
1796 &client_size
.x
, &client_size
.y
);
1798 //we should deal with the pixel here
1799 unsigned int row
= GetLineAt(client_size
.y
) - 1;
1801 return wxMin( GetRowCount()-1, row
);
1804 unsigned int wxDataViewMainWindow::GetRowCount()
1806 if ( m_count
== -1 )
1808 m_count
= RecalculateCount();
1814 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
1821 void wxDataViewMainWindow::SelectAllRows( bool on
)
1828 m_selection
.Clear();
1829 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
1830 m_selection
.Add( i
);
1835 unsigned int first_visible
= GetFirstVisibleRow();
1836 unsigned int last_visible
= GetLastVisibleRow();
1838 for (i
= 0; i
< m_selection
.GetCount(); i
++)
1840 unsigned int row
= m_selection
[i
];
1841 if ((row
>= first_visible
) && (row
<= last_visible
))
1844 m_selection
.Clear();
1848 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
1850 if (m_selection
.Index( row
) == wxNOT_FOUND
)
1854 m_selection
.Add( row
);
1862 m_selection
.Remove( row
);
1868 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
1872 unsigned int tmp
= from
;
1878 for (i
= from
; i
<= to
; i
++)
1880 if (m_selection
.Index( i
) == wxNOT_FOUND
)
1883 m_selection
.Add( i
);
1888 m_selection
.Remove( i
);
1891 RefreshRows( from
, to
);
1894 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
1896 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
1898 int n
= aSelections
[i
];
1900 m_selection
.Add( n
);
1905 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
1907 if (m_selection
.Index( row
) == wxNOT_FOUND
)
1908 m_selection
.Add( row
);
1910 m_selection
.Remove( row
);
1914 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
1916 return (m_selection
.Index( row
) != wxNOT_FOUND
);
1919 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
1921 wxWindow
*parent
= GetParent();
1922 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
1924 le
.SetEventObject(parent
);
1925 le
.SetModel(GetOwner()->GetModel());
1928 parent
->GetEventHandler()->ProcessEvent(le
);
1931 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
1933 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
1934 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1936 wxSize client_size
= GetClientSize();
1937 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
1938 wxRect intersect_rect
= client_rect
.Intersect( rect
);
1939 if (intersect_rect
.width
> 0)
1940 Refresh( true, &intersect_rect
);
1943 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
1947 unsigned int tmp
= to
;
1952 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
1953 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1955 wxSize client_size
= GetClientSize();
1956 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
1957 wxRect intersect_rect
= client_rect
.Intersect( rect
);
1958 if (intersect_rect
.width
> 0)
1959 Refresh( true, &intersect_rect
);
1962 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
1964 wxSize client_size
= GetClientSize();
1965 int start
= GetLineStart( firstRow
);
1966 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
1967 if (start
> client_size
.y
) return;
1969 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
1971 Refresh( true, &rect
);
1974 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
1976 wxCHECK_RET( newCurrent
< GetRowCount(),
1977 _T("invalid item index in OnArrowChar()") );
1979 // if there is no selection, we cannot move it anywhere
1980 if (!HasCurrentRow())
1983 unsigned int oldCurrent
= m_currentRow
;
1985 // in single selection we just ignore Shift as we can't select several
1987 if ( event
.ShiftDown() && !IsSingleSel() )
1989 RefreshRow( oldCurrent
);
1991 ChangeCurrentRow( newCurrent
);
1993 // select all the items between the old and the new one
1994 if ( oldCurrent
> newCurrent
)
1996 newCurrent
= oldCurrent
;
1997 oldCurrent
= m_currentRow
;
2000 SelectRows( oldCurrent
, newCurrent
, true );
2001 if (oldCurrent
!=newCurrent
)
2002 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
2006 RefreshRow( oldCurrent
);
2008 // all previously selected items are unselected unless ctrl is held
2009 if ( !event
.ControlDown() )
2010 SelectAllRows(false);
2012 ChangeCurrentRow( newCurrent
);
2014 if ( !event
.ControlDown() )
2016 SelectRow( m_currentRow
, true );
2017 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
2020 RefreshRow( m_currentRow
);
2023 GetOwner()->EnsureVisible( m_currentRow
, -1 );
2026 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2030 rect
.y
= GetLineStart( row
);
2031 rect
.width
= GetEndOfLastCol();
2032 rect
.height
= GetLineHeight( row
);
2037 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2039 const wxDataViewModel
*model
= GetOwner()->GetModel();
2041 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2043 // TODO make more efficient
2048 for (r
= 0; r
< row
; r
++)
2050 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2051 if (!node
) return start
;
2053 wxDataViewItem item
= node
->GetItem();
2055 if (node
&& !node
->HasChildren())
2057 // Yes, if the node does not have any child, it must be a leaf which
2058 // mean that it is a temporarily created by GetTreeNodeByRow
2062 unsigned int cols
= GetOwner()->GetColumnCount();
2064 int height
= m_lineHeight
;
2065 for (col
= 0; col
< cols
; col
++)
2067 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2068 if (column
->IsHidden())
2069 continue; // skip it!
2071 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
2072 continue; // skip it!
2074 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
2076 model
->GetValue( value
, item
, column
->GetModelColumn() );
2077 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
2078 renderer2
->SetValue( value
);
2079 height
= wxMax( height
, renderer
->GetSize().y
);
2090 return row
* m_lineHeight
;
2094 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
2096 const wxDataViewModel
*model
= GetOwner()->GetModel();
2098 // check for the easy case first
2099 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
2100 return y
/ m_lineHeight
;
2102 // TODO make more efficient
2103 unsigned int row
= 0;
2104 unsigned int yy
= 0;
2107 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2110 // not really correct...
2111 return row
+ ((y
-yy
) / m_lineHeight
);
2114 wxDataViewItem item
= node
->GetItem();
2116 if (node
&& !node
->HasChildren())
2118 // Yes, if the node does not have any child, it must be a leaf which
2119 // mean that it is a temporarily created by GetTreeNodeByRow
2123 unsigned int cols
= GetOwner()->GetColumnCount();
2125 int height
= m_lineHeight
;
2126 for (col
= 0; col
< cols
; col
++)
2128 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2129 if (column
->IsHidden())
2130 continue; // skip it!
2132 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
2133 continue; // skip it!
2135 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
2137 model
->GetValue( value
, item
, column
->GetModelColumn() );
2138 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
2139 renderer2
->SetValue( value
);
2140 height
= wxMax( height
, renderer
->GetSize().y
);
2151 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
2153 const wxDataViewModel
*model
= GetOwner()->GetModel();
2155 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2157 wxASSERT( !IsVirtualList() );
2159 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2160 // wxASSERT( node );
2161 if (!node
) return m_lineHeight
;
2163 wxDataViewItem item
= node
->GetItem();
2165 if (node
&& !node
->HasChildren())
2167 // Yes, if the node does not have any child, it must be a leaf which
2168 // mean that it is a temporarily created by GetTreeNodeByRow
2172 int height
= m_lineHeight
;
2174 unsigned int cols
= GetOwner()->GetColumnCount();
2176 for (col
= 0; col
< cols
; col
++)
2178 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2179 if (column
->IsHidden())
2180 continue; // skip it!
2182 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
2183 continue; // skip it!
2185 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
2187 model
->GetValue( value
, item
, column
->GetModelColumn() );
2188 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
2189 renderer2
->SetValue( value
);
2190 height
= wxMax( height
, renderer
->GetSize().y
);
2197 return m_lineHeight
;
2201 class RowToItemJob
: public DoJob
2204 RowToItemJob( unsigned int row
, int current
) { this->row
= row
; this->current
= current
;}
2205 virtual ~RowToItemJob() { }
2207 virtual int operator() ( wxDataViewTreeNode
* node
)
2210 if( current
== static_cast<int>(row
))
2212 ret
= node
->GetItem();
2216 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2218 current
+= node
->GetSubTreeCount();
2223 //If the current has no child node, we can find the desired item of the row number directly.
2224 //This if can speed up finding in some case, and will has a very good effect when it comes to list view
2225 if( node
->GetNodes().GetCount() == 0)
2227 int index
= static_cast<int>(row
) - current
- 1;
2228 ret
= node
->GetChildren().Item( index
);
2235 virtual int operator() ( void * n
)
2238 if( current
== static_cast<int>(row
))
2240 ret
= wxDataViewItem( n
);
2245 wxDataViewItem
GetResult(){ return ret
; }
2252 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
2256 return wxDataViewItem( wxUIntToPtr(row
) );
2260 RowToItemJob
job( row
, -2 );
2261 Walker( m_root
, job
);
2262 return job
.GetResult();
2266 class RowToTreeNodeJob
: public DoJob
2269 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
2272 this->current
= current
;
2276 virtual ~RowToTreeNodeJob(){ }
2278 virtual int operator() ( wxDataViewTreeNode
* node
)
2281 if( current
== static_cast<int>(row
))
2287 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
2289 current
+= node
->GetSubTreeCount();
2295 //If the current has no child node, we can find the desired item of the row number directly.
2296 //This if can speed up finding in some case, and will has a very good effect when it comes to list view
2297 if( node
->GetNodes().GetCount() == 0)
2299 int index
= static_cast<int>(row
) - current
- 1;
2300 void * n
= node
->GetChildren().Item( index
);
2301 ret
= new wxDataViewTreeNode( parent
);
2302 ret
->SetItem( wxDataViewItem( n
));
2303 ret
->SetHasChildren(false);
2312 virtual int operator() ( void * n
)
2315 if( current
== static_cast<int>(row
))
2317 ret
= new wxDataViewTreeNode( parent
);
2318 ret
->SetItem( wxDataViewItem( n
));
2319 ret
->SetHasChildren(false);
2325 wxDataViewTreeNode
* GetResult(){ return ret
; }
2329 wxDataViewTreeNode
* ret
;
2330 wxDataViewTreeNode
* parent
;
2334 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
2336 wxASSERT( !IsVirtualList() );
2338 RowToTreeNodeJob
job( row
, -2, m_root
);
2339 Walker( m_root
, job
);
2340 return job
.GetResult();
2343 wxDataViewEvent
wxDataViewMainWindow::SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
)
2345 wxWindow
*parent
= GetParent();
2346 wxDataViewEvent
le(type
, parent
->GetId());
2348 le
.SetEventObject(parent
);
2349 le
.SetModel(GetOwner()->GetModel());
2352 parent
->GetEventHandler()->ProcessEvent(le
);
2356 void wxDataViewMainWindow::OnExpanding( unsigned int row
)
2358 if (IsVirtualList())
2361 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2364 if( node
->HasChildren())
2366 if( !node
->IsOpen())
2368 wxDataViewEvent e
= SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
,node
->GetItem());
2369 //Check if the user prevent expanding
2370 if( e
.GetSkipped() )
2374 //Here I build the children of current node
2375 if( node
->GetChildrenNumber() == 0 )
2378 ::BuildTreeHelper(GetOwner()->GetModel(), node
->GetItem(), node
);
2382 //Send the expanded event
2383 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
2387 SelectRow( row
, false );
2388 SelectRow( row
+ 1, true );
2389 ChangeCurrentRow( row
+ 1 );
2390 SendSelectionChangedEvent( GetItemByRow(row
+1));
2398 void wxDataViewMainWindow::OnCollapsing(unsigned int row
)
2400 if (IsVirtualList())
2403 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
2406 wxDataViewTreeNode
* nd
= node
;
2408 if( node
->HasChildren() && node
->IsOpen() )
2410 wxDataViewEvent e
= SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem());
2411 if( e
.GetSkipped() )
2416 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,nd
->GetItem());
2420 node
= node
->GetParent();
2423 int parent
= GetRowByItem( node
->GetItem() );
2426 SelectRow( row
, false);
2427 SelectRow(parent
, true );
2428 ChangeCurrentRow( parent
);
2429 SendSelectionChangedEvent( node
->GetItem() );
2433 if( !nd
->HasChildren())
2438 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
2440 wxDataViewModel
* model
= GetOwner()->GetModel();
2444 //Compose the a parent-chain of the finding item
2446 list
.DeleteContents( true );
2447 wxDataViewItem
it( item
);
2450 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
2451 list
.Insert( pItem
);
2452 it
= model
->GetParent( it
);
2455 //Find the item along the parent-chain.
2456 //This algorithm is designed to speed up the node-finding method
2457 wxDataViewTreeNode
* node
= m_root
;
2458 for( ItemList::const_iterator iter
= list
.begin(); iter
!=list
.end(); iter
++ )
2460 if( node
->HasChildren() )
2462 if( node
->GetChildrenNumber() == 0 )
2465 ::BuildTreeHelper(model
, node
->GetItem(), node
);
2468 wxDataViewTreeNodes nodes
= node
->GetNodes();
2472 for (i
= 0; i
< nodes
.GetCount(); i
++)
2474 if (nodes
[i
]->GetItem() == (**iter
))
2476 if (nodes
[i
]->GetItem() == item
)
2493 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
)
2495 wxDataViewColumn
*col
= NULL
;
2496 unsigned int cols
= GetOwner()->GetColumnCount();
2497 unsigned int colnum
= 0;
2499 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
2500 for (unsigned x_start
= 0; colnum
< cols
; colnum
++)
2502 col
= GetOwner()->GetColumn(colnum
);
2503 if (col
->IsHidden())
2504 continue; // skip it!
2506 unsigned int w
= col
->GetWidth();
2507 if (x_start
+w
>= (unsigned int)x
)
2514 item
= GetItemByRow( GetLineAt( y
) );
2517 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
2519 int row
= GetRowByItem(item
);
2520 int y
= GetLineStart( row
);
2521 int h
= GetLineHeight( m_lineHeight
);
2523 wxDataViewColumn
*col
= NULL
;
2524 for( int i
= 0, cols
= GetOwner()->GetColumnCount(); i
< cols
; i
++ )
2526 col
= GetOwner()->GetColumn( i
);
2527 x
+= col
->GetWidth();
2528 if( GetOwner()->GetColumn(i
+1) == column
)
2531 int w
= col
->GetWidth();
2532 m_owner
->CalcScrolledPosition( x
, y
, &x
, &y
);
2533 return wxRect(x
, y
, w
, h
);
2536 int wxDataViewMainWindow::RecalculateCount()
2540 wxDataViewIndexListModel
*list_model
= (wxDataViewIndexListModel
*) GetOwner()->GetModel();
2542 return list_model
->GetLastIndex() + 1;
2544 return list_model
->GetLastIndex() - 1;
2549 return m_root
->GetSubTreeCount();
2553 class ItemToRowJob
: public DoJob
2556 ItemToRowJob(const wxDataViewItem
& item_
, ItemList::const_iterator iter
)
2563 //Maybe binary search will help to speed up this process
2564 virtual int operator() ( wxDataViewTreeNode
* node
)
2567 if( node
->GetItem() == item
)
2572 if( node
->GetItem() == **m_iter
)
2579 ret
+= node
->GetSubTreeCount();
2585 virtual int operator() ( void * n
)
2588 if( n
== item
.GetID() )
2592 //the row number is begin from zero
2593 int GetResult() { return ret
-1; }
2596 ItemList::const_iterator m_iter
;
2597 wxDataViewItem item
;
2602 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
2604 const wxDataViewModel
* model
= GetOwner()->GetModel();
2610 return wxPtrToUInt( item
.GetID() );
2617 //Compose the a parent-chain of the finding item
2619 wxDataViewItem
* pItem
;
2620 list
.DeleteContents( true );
2621 wxDataViewItem
it( item
);
2624 pItem
= new wxDataViewItem( it
);
2625 list
.Insert( pItem
);
2626 it
= model
->GetParent( it
);
2628 pItem
= new wxDataViewItem( );
2629 list
.Insert( pItem
);
2631 ItemToRowJob
job( item
, list
.begin() );
2632 Walker(m_root
, job
);
2633 return job
.GetResult();
2637 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
, wxDataViewTreeNode
* node
)
2639 if( !model
->IsContainer( item
) )
2642 wxDataViewItemArray children
;
2643 unsigned int num
= model
->GetChildren( item
, children
);
2644 unsigned int index
= 0;
2645 while( index
< num
)
2647 if( model
->IsContainer( children
[index
] ) )
2649 wxDataViewTreeNode
* n
= new wxDataViewTreeNode( node
);
2650 n
->SetItem(children
[index
]);
2651 n
->SetHasChildren( true );
2656 node
->AddLeaf( children
[index
].GetID() );
2660 node
->SetSubTreeCount( num
);
2661 wxDataViewTreeNode
* n
= node
->GetParent();
2663 n
->ChangeSubTreeCount(num
);
2667 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
2671 if (GetOwner()->GetModel()->IsVirtualListModel())
2677 m_root
= new wxDataViewTreeNode( NULL
);
2678 m_root
->SetHasChildren(true);
2680 //First we define a invalid item to fetch the top-level elements
2681 wxDataViewItem item
;
2683 BuildTreeHelper( model
, item
, m_root
);
2687 static void DestroyTreeHelper( wxDataViewTreeNode
* node
)
2689 if( node
->GetNodeNumber() != 0 )
2691 int len
= node
->GetNodeNumber();
2693 wxDataViewTreeNodes
& nodes
= node
->GetNodes();
2694 for(; i
< len
; i
++ )
2696 DestroyTreeHelper(nodes
[i
]);
2702 void wxDataViewMainWindow::DestroyTree()
2704 if (!IsVirtualList())
2706 ::DestroyTreeHelper(m_root
);
2712 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
2714 if ( GetParent()->HandleAsNavigationKey(event
) )
2717 // no item -> nothing to do
2718 if (!HasCurrentRow())
2724 // don't use m_linesPerPage directly as it might not be computed yet
2725 const int pageSize
= GetCountPerPage();
2726 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
2728 switch ( event
.GetKeyCode() )
2732 if (m_currentRow
> 0)
2734 wxWindow
*parent
= GetParent();
2735 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
2736 le
.SetItem( GetItemByRow(m_currentRow
) );
2737 le
.SetEventObject(parent
);
2738 le
.SetModel(GetOwner()->GetModel());
2740 parent
->GetEventHandler()->ProcessEvent(le
);
2745 if ( m_currentRow
> 0 )
2746 OnArrowChar( m_currentRow
- 1, event
);
2750 if ( m_currentRow
< GetRowCount() - 1 )
2751 OnArrowChar( m_currentRow
+ 1, event
);
2753 //Add the process for tree expanding/collapsing
2755 OnCollapsing(m_currentRow
);
2758 OnExpanding( m_currentRow
);
2762 OnArrowChar( GetRowCount() - 1, event
);
2767 OnArrowChar( 0, event
);
2772 int steps
= pageSize
- 1;
2773 int index
= m_currentRow
- steps
;
2777 OnArrowChar( index
, event
);
2783 int steps
= pageSize
- 1;
2784 unsigned int index
= m_currentRow
+ steps
;
2785 unsigned int count
= GetRowCount();
2786 if ( index
>= count
)
2789 OnArrowChar( index
, event
);
2798 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
2800 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2802 // let the base handle mouse wheel events.
2807 int x
= event
.GetX();
2808 int y
= event
.GetY();
2809 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2810 wxDataViewColumn
*col
= NULL
;
2813 unsigned int cols
= GetOwner()->GetColumnCount();
2815 for (i
= 0; i
< cols
; i
++)
2817 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
2819 continue; // skip it!
2821 if (x
< xpos
+ c
->GetWidth())
2826 xpos
+= c
->GetWidth();
2831 wxDataViewRenderer
*cell
= col
->GetRenderer();
2832 unsigned int current
= GetLineAt( y
);
2833 if ((current
> GetRowCount()) || (x
> GetEndOfLastCol()))
2835 // Unselect all if below the last row ?
2839 //Test whether the mouse is hovered on the tree item button
2841 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
2843 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
2844 if( node
!=NULL
&& node
->HasChildren() )
2846 int indent
= node
->GetIndentLevel();
2847 indent
= GetOwner()->GetIndent()*indent
;
2848 wxRect
rect( xpos
+ indent
+ EXPANDER_MARGIN
,
2849 GetLineStart( current
) + EXPANDER_MARGIN
+ (GetLineHeight(current
)/2) - (m_lineHeight
/2) - EXPANDER_OFFSET
,
2850 m_lineHeight
-2*EXPANDER_MARGIN
,
2851 m_lineHeight
-2*EXPANDER_MARGIN
+ EXPANDER_OFFSET
);
2852 if( rect
.Contains( x
, y
) )
2854 //So the mouse is over the expander
2856 if (m_underMouse
&& m_underMouse
!= node
)
2858 //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
2859 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
2861 if (m_underMouse
!= node
)
2863 //wxLogMessage("Do the row: %d", current);
2864 RefreshRow(current
);
2866 m_underMouse
= node
;
2869 if (node
!=NULL
&& !node
->HasChildren())
2874 if (m_underMouse
!= NULL
)
2876 //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
2877 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
2878 m_underMouse
= NULL
;
2882 wxDataViewModel
*model
= GetOwner()->GetModel();
2884 if (event
.Dragging())
2886 if (m_dragCount
== 0)
2888 // we have to report the raw, physical coords as we want to be
2889 // able to call HitTest(event.m_pointDrag) from the user code to
2890 // get the item being dragged
2891 m_dragStart
= event
.GetPosition();
2896 if (m_dragCount
!= 3)
2899 if (event
.LeftIsDown())
2901 // Notify cell about drag
2910 bool forceClick
= false;
2912 if (event
.ButtonDClick())
2914 m_renameTimer
->Stop();
2915 m_lastOnSame
= false;
2918 wxDataViewItem item
= GetItemByRow(current
);
2919 bool ignore_other_columns
=
2920 ((GetOwner()->GetExpanderColumn() != col
) &&
2921 (model
->IsContainer(item
)) &&
2922 (!model
->HasContainerColumns(item
)));
2924 if (event
.LeftDClick())
2926 if ( current
== m_lineLastClicked
)
2928 if ((!ignore_other_columns
) && (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
2931 model
->GetValue( value
, item
, col
->GetModelColumn() );
2932 cell
->SetValue( value
);
2933 wxRect
cell_rect( xpos
, GetLineStart( current
),
2934 col
->GetWidth(), GetLineHeight( current
) );
2935 cell
->Activate( cell_rect
, model
, item
, col
->GetModelColumn() );
2940 wxWindow
*parent
= GetParent();
2941 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
2943 le
.SetEventObject(parent
);
2944 le
.SetModel(GetOwner()->GetModel());
2946 parent
->GetEventHandler()->ProcessEvent(le
);
2952 // The first click was on another item, so don't interpret this as
2953 // a double click, but as a simple click instead
2960 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
2962 // select single line
2963 SelectAllRows( false );
2964 SelectRow( m_lineSelectSingleOnUp
, true );
2967 //Process the event of user clicking the expander
2968 bool expander
= false;
2969 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
2971 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
2972 if( node
!=NULL
&& node
->HasChildren() )
2974 int indent
= node
->GetIndentLevel();
2975 indent
= GetOwner()->GetIndent()*indent
;
2976 wxRect
rect( xpos
+ indent
+ EXPANDER_MARGIN
,
2977 GetLineStart( current
) + EXPANDER_MARGIN
+ (GetLineHeight(current
)/2) - (m_lineHeight
/2) - EXPANDER_OFFSET
,
2978 m_lineHeight
-2*EXPANDER_MARGIN
,
2979 m_lineHeight
-2*EXPANDER_MARGIN
+ EXPANDER_OFFSET
);
2981 if( rect
.Contains( x
, y
) )
2984 if( node
->IsOpen() )
2985 OnCollapsing(current
);
2987 OnExpanding( current
);
2990 if (node
&& !node
->HasChildren())
2993 //If the user click the expander, we do not do editing even if the column with expander are editable
2994 if (m_lastOnSame
&& !expander
&& !ignore_other_columns
)
2996 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
2997 (cell
->GetMode() & wxDATAVIEW_CELL_EDITABLE
) )
2999 m_renameTimer
->Start( 100, true );
3003 m_lastOnSame
= false;
3004 m_lineSelectSingleOnUp
= (unsigned int)-1;
3008 // This is necessary, because after a DnD operation in
3009 // from and to ourself, the up event is swallowed by the
3010 // DnD code. So on next non-up event (which means here and
3011 // now) m_lineSelectSingleOnUp should be reset.
3012 m_lineSelectSingleOnUp
= (unsigned int)-1;
3015 if (event
.RightDown())
3017 m_lineBeforeLastClicked
= m_lineLastClicked
;
3018 m_lineLastClicked
= current
;
3020 // If the item is already selected, do not update the selection.
3021 // Multi-selections should not be cleared if a selected item is clicked.
3022 if (!IsRowSelected(current
))
3024 SelectAllRows(false);
3025 ChangeCurrentRow(current
);
3026 SelectRow(m_currentRow
,true);
3027 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3031 model
->GetValue( value
, item
, col
->GetModelColumn() );
3032 wxWindow
*parent
= GetParent();
3033 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
3035 le
.SetEventObject(parent
);
3036 le
.SetModel(GetOwner()->GetModel());
3038 parent
->GetEventHandler()->ProcessEvent(le
);
3040 else if (event
.MiddleDown())
3043 if (event
.LeftDown() || forceClick
)
3047 m_lineBeforeLastClicked
= m_lineLastClicked
;
3048 m_lineLastClicked
= current
;
3050 unsigned int oldCurrentRow
= m_currentRow
;
3051 bool oldWasSelected
= IsRowSelected(m_currentRow
);
3053 bool cmdModifierDown
= event
.CmdDown();
3054 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3056 if ( IsSingleSel() || !IsRowSelected(current
) )
3058 SelectAllRows( false );
3059 ChangeCurrentRow(current
);
3060 SelectRow(m_currentRow
,true);
3061 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3063 else // multi sel & current is highlighted & no mod keys
3065 m_lineSelectSingleOnUp
= current
;
3066 ChangeCurrentRow(current
); // change focus
3069 else // multi sel & either ctrl or shift is down
3071 if (cmdModifierDown
)
3073 ChangeCurrentRow(current
);
3074 ReverseRowSelection(m_currentRow
);
3075 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3077 else if (event
.ShiftDown())
3079 ChangeCurrentRow(current
);
3081 unsigned int lineFrom
= oldCurrentRow
,
3084 if ( lineTo
< lineFrom
)
3087 lineFrom
= m_currentRow
;
3090 SelectRows(lineFrom
, lineTo
, true);
3091 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3093 else // !ctrl, !shift
3095 // test in the enclosing if should make it impossible
3096 wxFAIL_MSG( _T("how did we get here?") );
3100 if (m_currentRow
!= oldCurrentRow
)
3101 RefreshRow( oldCurrentRow
);
3103 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
3105 // Update selection here...
3108 m_lastOnSame
= !forceClick
&& ((col
== oldCurrentCol
) &&
3109 (current
== oldCurrentRow
)) && oldWasSelected
;
3111 // Call LeftClick after everything else as under GTK+
3112 if (cell
->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE
)
3114 // notify cell about right click
3116 model
->GetValue( value
, item
, col
->GetModelColumn() );
3117 cell
->SetValue( value
);
3118 wxRect
cell_rect( xpos
, GetLineStart( current
),
3119 col
->GetWidth(), GetLineHeight( current
) );
3120 /* ignore ret */ cell
->LeftClick( event
.GetPosition(), cell_rect
, model
, item
, col
->GetModelColumn());
3125 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
3129 if (HasCurrentRow())
3135 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
3139 if (HasCurrentRow())
3145 wxDataViewItem
wxDataViewMainWindow::GetSelection() const
3147 if( m_selection
.GetCount() != 1 )
3148 return wxDataViewItem();
3150 return GetItemByRow( m_selection
.Item(0));
3153 //-----------------------------------------------------------------------------
3155 //-----------------------------------------------------------------------------
3156 WX_DEFINE_LIST(wxDataViewColumnList
)
3158 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
3160 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
3161 EVT_SIZE(wxDataViewCtrl::OnSize
)
3164 wxDataViewCtrl::~wxDataViewCtrl()
3167 GetModel()->RemoveNotifier( m_notifier
);
3172 void wxDataViewCtrl::Init()
3174 m_cols
.DeleteContents(true);
3177 // No sorting column at start
3178 m_sortingColumn
= NULL
;
3179 m_headerArea
= NULL
;
3182 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
3183 const wxPoint
& pos
, const wxSize
& size
,
3184 long style
, const wxValidator
& validator
)
3186 if ( (style
& wxBORDER_MASK
) == 0)
3187 style
|= wxBORDER_SUNKEN
;
3191 if (!wxControl::Create( parent
, id
, pos
, size
,
3192 style
| wxScrolledWindowStyle
, validator
))
3195 SetInitialSize(size
);
3198 MacSetClipChildren( true );
3201 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
3203 if (HasFlag(wxDV_NO_HEADER
))
3204 m_headerArea
= NULL
;
3206 m_headerArea
= new wxDataViewHeaderWindow(this);
3208 SetTargetWindow( m_clientArea
);
3210 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
3212 sizer
->Add( m_headerArea
, 0, wxGROW
);
3213 sizer
->Add( m_clientArea
, 1, wxGROW
);
3220 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
3224 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
3227 // we need to process arrows ourselves for scrolling
3228 if ( nMsg
== WM_GETDLGCODE
)
3230 rc
|= DLGC_WANTARROWS
;
3238 wxSize
wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
3240 wxSize newsize
= size
;
3241 if (!HasFlag(wxDV_NO_HEADER
) && (m_headerArea
))
3242 newsize
.y
-= m_headerArea
->GetSize().y
;
3247 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3249 // We need to override OnSize so that our scrolled
3250 // window a) does call Layout() to use sizers for
3251 // positioning the controls but b) does not query
3252 // the sizer for their size and use that for setting
3253 // the scrollable area as set that ourselves by
3254 // calling SetScrollbar() further down.
3261 void wxDataViewCtrl::SetFocus()
3264 m_clientArea
->SetFocus();
3267 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
3269 if (!wxDataViewCtrlBase::AssociateModel( model
))
3272 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
3274 model
->AddNotifier( m_notifier
);
3276 m_clientArea
->DestroyTree();
3278 m_clientArea
->BuildTree(model
);
3280 m_clientArea
->UpdateDisplay();
3285 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
3287 if (!wxDataViewCtrlBase::AppendColumn(col
))
3290 m_cols
.Append( col
);
3295 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
3297 if (!wxDataViewCtrlBase::PrependColumn(col
))
3300 m_cols
.Insert( col
);
3305 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
3307 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
3310 m_cols
.Insert( pos
, col
);
3315 void wxDataViewCtrl::OnColumnChange()
3318 m_headerArea
->SetColumnCount(GetColumnCount());
3320 m_clientArea
->UpdateDisplay();
3323 void wxDataViewCtrl::DoSetExpanderColumn()
3325 m_clientArea
->UpdateDisplay();
3328 void wxDataViewCtrl::DoSetIndent()
3330 m_clientArea
->UpdateDisplay();
3333 unsigned int wxDataViewCtrl::GetColumnCount() const
3335 return m_cols
.GetCount();
3338 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
3340 wxDataViewColumnList::const_iterator iter
;
3342 for (iter
= m_cols
.begin(); iter
!=m_cols
.end(); iter
++)
3347 if ((*iter
)->IsHidden())
3354 void wxDataViewCtrl::ColumnMoved( wxDataViewColumn
* col
, unsigned int new_pos
)
3356 if (new_pos
> m_cols
.GetCount()) return;
3358 // Exchange position
3359 m_cols
.DeleteContents(false);
3360 m_cols
.DeleteObject( col
);
3361 m_cols
.Insert( new_pos
, col
);
3362 m_cols
.DeleteContents(true);
3364 m_clientArea
->UpdateDisplay();
3367 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
3369 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
3379 bool wxDataViewCtrl::ClearColumns()
3386 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
3388 int ret
= 0, dead
= 0;
3389 int len
= GetColumnCount();
3390 for (int i
=0; i
<len
; i
++)
3392 wxDataViewColumn
* col
= GetColumn(i
);
3393 if (col
->IsHidden())
3395 ret
+= col
->GetWidth();
3398 CalcScrolledPosition( ret
, dead
, &ret
, &dead
);
3405 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
3410 //Selection code with wxDataViewItem as parameters
3411 wxDataViewItem
wxDataViewCtrl::GetSelection() const
3413 return m_clientArea
->GetSelection();
3416 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
3419 wxDataViewSelection selection
= m_clientArea
->GetSelections();
3420 int len
= selection
.GetCount();
3421 for( int i
= 0; i
< len
; i
++)
3423 unsigned int row
= selection
[i
];
3424 sel
.Add( m_clientArea
->GetItemByRow( row
) );
3429 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
3431 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
3432 int len
= sel
.GetCount();
3433 for( int i
= 0; i
< len
; i
++ )
3435 int row
= m_clientArea
->GetRowByItem( sel
[i
] );
3437 selection
.Add( static_cast<unsigned int>(row
) );
3439 m_clientArea
->SetSelections( selection
);
3442 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
3444 int row
= m_clientArea
->GetRowByItem( item
);
3447 //Unselect all rows before select another in the single select mode
3448 if (m_clientArea
->IsSingleSel())
3449 m_clientArea
->SelectAllRows(false);
3450 m_clientArea
->SelectRow(row
, true);
3454 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
3456 int row
= m_clientArea
->GetRowByItem( item
);
3458 m_clientArea
->SelectRow(row
, false);
3461 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
3463 int row
= m_clientArea
->GetRowByItem( item
);
3466 return m_clientArea
->IsRowSelected(row
);
3471 //Selection code with row number as parameter
3472 int wxDataViewCtrl::GetSelections( wxArrayInt
& sel
) const
3475 wxDataViewSelection selection
= m_clientArea
->GetSelections();
3476 int len
= selection
.GetCount();
3477 for( int i
= 0; i
< len
; i
++)
3479 unsigned int row
= selection
[i
];
3485 void wxDataViewCtrl::SetSelections( const wxArrayInt
& sel
)
3487 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
3488 int len
= sel
.GetCount();
3489 for( int i
= 0; i
< len
; i
++ )
3493 selection
.Add( static_cast<unsigned int>(row
) );
3495 m_clientArea
->SetSelections( selection
);
3498 void wxDataViewCtrl::Select( int row
)
3502 if (m_clientArea
->IsSingleSel())
3503 m_clientArea
->SelectAllRows(false);
3504 m_clientArea
->SelectRow( row
, true );
3508 void wxDataViewCtrl::Unselect( int row
)
3511 m_clientArea
->SelectRow(row
, false);
3514 bool wxDataViewCtrl::IsSelected( int row
) const
3517 return m_clientArea
->IsRowSelected(row
);
3521 void wxDataViewCtrl::SelectRange( int from
, int to
)
3524 for( int i
= from
; i
< to
; i
++ )
3526 m_clientArea
->Select(sel
);
3529 void wxDataViewCtrl::UnselectRange( int from
, int to
)
3531 wxDataViewSelection sel
= m_clientArea
->GetSelections();
3532 for( int i
= from
; i
< to
; i
++ )
3533 if( sel
.Index( i
) != wxNOT_FOUND
)
3535 m_clientArea
->SetSelections(sel
);
3538 void wxDataViewCtrl::SelectAll()
3540 m_clientArea
->SelectAllRows(true);
3543 void wxDataViewCtrl::UnselectAll()
3545 m_clientArea
->SelectAllRows(false);
3548 void wxDataViewCtrl::EnsureVisible( int row
, int column
)
3552 if( row
> (int) m_clientArea
->GetRowCount() )
3553 row
= m_clientArea
->GetRowCount();
3555 int first
= m_clientArea
->GetFirstVisibleRow();
3556 int last
= m_clientArea
->GetLastVisibleRow();
3558 m_clientArea
->ScrollTo( row
, column
);
3559 else if( row
> last
)
3560 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
3562 m_clientArea
->ScrollTo( first
, column
);
3565 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
3567 int row
= m_clientArea
->GetRowByItem(item
);
3570 if( column
== NULL
)
3571 EnsureVisible(row
, -1);
3575 int len
= GetColumnCount();
3576 for( int i
= 0; i
< len
; i
++ )
3577 if( GetColumn(i
) == column
)
3582 EnsureVisible( row
, col
);
3588 void wxDataViewCtrl::HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
) const
3590 m_clientArea
->HitTest(point
, item
, column
);
3593 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
) const
3595 return m_clientArea
->GetItemRect(item
, column
);
3598 wxDataViewItem
wxDataViewCtrl::GetItemByRow( unsigned int row
) const
3600 return m_clientArea
->GetItemByRow( row
);
3603 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem
& item
) const
3605 return m_clientArea
->GetRowByItem( item
);
3608 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
3610 int row
= m_clientArea
->GetRowByItem( item
);
3612 m_clientArea
->Expand(row
);
3615 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
3617 int row
= m_clientArea
->GetRowByItem( item
);
3619 m_clientArea
->Collapse(row
);
3623 // !wxUSE_GENERICDATAVIEWCTRL
3626 // wxUSE_DATAVIEWCTRL