1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/datavgen.cpp
3 // Purpose: wxDataViewCtrl generic implementation
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #ifdef wxUSE_GENERICDATAVIEWCTRL
24 #include "wx/stockitem.h"
25 #include "wx/dcclient.h"
26 #include "wx/calctrl.h"
27 #include "wx/popupwin.h"
28 #include "wx/renderer.h"
32 #include "wx/msw/wrapwin.h"
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
42 // wxDataViewHeaderWindow
43 //-----------------------------------------------------------------------------
45 class wxDataViewHeaderWindow
: public wxWindow
48 wxDataViewHeaderWindow( wxDataViewCtrl
*parent
,
50 const wxPoint
&pos
= wxDefaultPosition
,
51 const wxSize
&size
= wxDefaultSize
,
52 const wxString
&name
= wxT("wxdataviewctrlheaderwindow") );
53 ~wxDataViewHeaderWindow();
55 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
56 wxDataViewCtrl
*GetOwner() { return m_owner
; }
58 void OnPaint( wxPaintEvent
&event
);
59 void OnMouse( wxMouseEvent
&event
);
60 void OnSetFocus( wxFocusEvent
&event
);
63 wxDataViewCtrl
*m_owner
;
64 wxCursor
*m_resizeCursor
;
67 DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindow
)
71 //-----------------------------------------------------------------------------
72 // wxDataViewRenameTimer
73 //-----------------------------------------------------------------------------
75 class wxDataViewRenameTimer
: public wxTimer
78 wxDataViewMainWindow
*m_owner
;
81 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
85 //-----------------------------------------------------------------------------
86 // wxDataViewTextCtrlWrapper: wraps a wxTextCtrl for inline editing
87 //-----------------------------------------------------------------------------
89 class wxDataViewTextCtrlWrapper
: public wxEvtHandler
92 // NB: text must be a valid object but not Create()d yet
93 wxDataViewTextCtrlWrapper( wxDataViewMainWindow
*owner
,
95 wxDataViewListModel
*model
,
96 size_t col
, size_t row
,
99 wxTextCtrl
*GetText() const { return m_text
; }
101 void AcceptChangesAndFinish();
104 void OnChar( wxKeyEvent
&event
);
105 void OnKeyUp( wxKeyEvent
&event
);
106 void OnKillFocus( wxFocusEvent
&event
);
108 bool AcceptChanges();
112 wxDataViewMainWindow
*m_owner
;
114 wxString m_startValue
;
115 wxDataViewListModel
*m_model
;
119 bool m_aboutToFinish
;
121 DECLARE_EVENT_TABLE()
124 //-----------------------------------------------------------------------------
125 // wxDataViewMainWindow
126 //-----------------------------------------------------------------------------
128 class wxDataViewMainWindow
: public wxWindow
131 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
133 const wxPoint
&pos
= wxDefaultPosition
,
134 const wxSize
&size
= wxDefaultSize
,
135 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
136 ~wxDataViewMainWindow();
138 // notifications from wxDataViewListModel
141 bool RowInserted( size_t before
);
142 bool RowDeleted( size_t row
);
143 bool RowChanged( size_t row
);
144 bool ValueChanged( size_t col
, size_t row
);
145 bool RowsReordered( size_t *new_order
);
148 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
149 wxDataViewCtrl
*GetOwner() { return m_owner
; }
151 void OnPaint( wxPaintEvent
&event
);
152 void OnMouse( wxMouseEvent
&event
);
153 void OnSetFocus( wxFocusEvent
&event
);
155 void UpdateDisplay();
156 void RecalculateDisplay();
157 void OnInternalIdle();
159 void OnRenameTimer();
160 void FinishEditing( wxTextCtrl
*text
);
162 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
164 wxDataViewCtrl
*m_owner
;
168 wxDataViewColumn
*m_currentCol
;
171 wxDataViewRenameTimer
*m_renameTimer
;
172 wxDataViewTextCtrlWrapper
*m_textctrlWrapper
;
176 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
177 DECLARE_EVENT_TABLE()
180 // ---------------------------------------------------------
181 // wxGenericDataViewListModelNotifier
182 // ---------------------------------------------------------
184 class wxGenericDataViewListModelNotifier
: public wxDataViewListModelNotifier
187 wxGenericDataViewListModelNotifier( wxDataViewMainWindow
*mainWindow
)
188 { m_mainWindow
= mainWindow
; }
190 virtual bool RowAppended()
191 { return m_mainWindow
->RowAppended(); }
192 virtual bool RowPrepended()
193 { return m_mainWindow
->RowPrepended(); }
194 virtual bool RowInserted( size_t before
)
195 { return m_mainWindow
->RowInserted( before
); }
196 virtual bool RowDeleted( size_t row
)
197 { return m_mainWindow
->RowDeleted( row
); }
198 virtual bool RowChanged( size_t row
)
199 { return m_mainWindow
->RowChanged( row
); }
200 virtual bool ValueChanged( size_t col
, size_t row
)
201 { return m_mainWindow
->ValueChanged( col
, row
); }
202 virtual bool RowsReordered( size_t *new_order
)
203 { return m_mainWindow
->RowsReordered( new_order
); }
204 virtual bool Cleared()
205 { return m_mainWindow
->Cleared(); }
207 wxDataViewMainWindow
*m_mainWindow
;
210 // ---------------------------------------------------------
212 // ---------------------------------------------------------
214 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCell
, wxDataViewCellBase
)
216 wxDataViewCell::wxDataViewCell( const wxString
&varianttype
, wxDataViewCellMode mode
) :
217 wxDataViewCellBase( varianttype
, mode
)
222 wxDataViewCell::~wxDataViewCell()
228 wxDC
*wxDataViewCell::GetDC()
232 if (GetOwner() == NULL
)
234 if (GetOwner()->GetOwner() == NULL
)
236 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
242 // ---------------------------------------------------------
243 // wxDataViewCustomCell
244 // ---------------------------------------------------------
246 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomCell
, wxDataViewCell
)
248 wxDataViewCustomCell::wxDataViewCustomCell( const wxString
&varianttype
,
249 wxDataViewCellMode mode
) :
250 wxDataViewCell( varianttype
, mode
)
254 // ---------------------------------------------------------
255 // wxDataViewTextCell
256 // ---------------------------------------------------------
258 IMPLEMENT_ABSTRACT_CLASS(wxDataViewTextCell
, wxDataViewCustomCell
)
260 wxDataViewTextCell::wxDataViewTextCell( const wxString
&varianttype
, wxDataViewCellMode mode
) :
261 wxDataViewCustomCell( varianttype
, mode
)
265 bool wxDataViewTextCell::SetValue( const wxVariant
&value
)
267 m_text
= value
.GetString();
272 bool wxDataViewTextCell::GetValue( wxVariant
& WXUNUSED(value
) )
277 bool wxDataViewTextCell::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
279 dc
->DrawText( m_text
, cell
.x
, cell
.y
);
284 wxSize
wxDataViewTextCell::GetSize()
286 return wxSize(80,20);
289 // ---------------------------------------------------------
290 // wxDataViewToggleCell
291 // ---------------------------------------------------------
293 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleCell
, wxDataViewCustomCell
)
295 wxDataViewToggleCell::wxDataViewToggleCell( const wxString
&varianttype
,
296 wxDataViewCellMode mode
) :
297 wxDataViewCustomCell( varianttype
, mode
)
302 bool wxDataViewToggleCell::SetValue( const wxVariant
&value
)
304 m_toggle
= value
.GetBool();
309 bool wxDataViewToggleCell::GetValue( wxVariant
&WXUNUSED(value
) )
314 bool wxDataViewToggleCell::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
316 // User wxRenderer here
318 if (GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
)
319 dc
->SetPen( *wxBLACK_PEN
);
321 dc
->SetPen( *wxGREY_PEN
);
322 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
324 rect
.x
= cell
.x
+ cell
.width
/2 - 10;
326 rect
.y
= cell
.y
+ cell
.height
/2 - 10;
328 dc
->DrawRectangle( rect
);
335 dc
->DrawLine( rect
.x
, rect
.y
, rect
.x
+rect
.width
, rect
.y
+rect
.height
);
336 dc
->DrawLine( rect
.x
+rect
.width
, rect
.y
, rect
.x
, rect
.y
+rect
.height
);
342 bool wxDataViewToggleCell::Activate( wxRect
WXUNUSED(cell
), wxDataViewListModel
*model
, size_t col
, size_t row
)
344 bool value
= !m_toggle
;
345 wxVariant variant
= value
;
346 model
->SetValue( variant
, col
, row
);
347 model
->ValueChanged( col
, row
);
351 wxSize
wxDataViewToggleCell::GetSize()
353 return wxSize(20,20);
356 // ---------------------------------------------------------
357 // wxDataViewProgressCell
358 // ---------------------------------------------------------
360 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressCell
, wxDataViewCustomCell
)
362 wxDataViewProgressCell::wxDataViewProgressCell( const wxString
&label
,
363 const wxString
&varianttype
, wxDataViewCellMode mode
) :
364 wxDataViewCustomCell( varianttype
, mode
)
370 wxDataViewProgressCell::~wxDataViewProgressCell()
374 bool wxDataViewProgressCell::SetValue( const wxVariant
&value
)
376 m_value
= (long) value
;
378 if (m_value
< 0) m_value
= 0;
379 if (m_value
> 100) m_value
= 100;
384 bool wxDataViewProgressCell::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
386 double pct
= (double)m_value
/ 100.0;
388 bar
.width
= (int)(cell
.width
* pct
);
389 dc
->SetPen( *wxTRANSPARENT_PEN
);
390 dc
->SetBrush( *wxBLUE_BRUSH
);
391 dc
->DrawRectangle( bar
);
393 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
394 dc
->SetPen( *wxBLACK_PEN
);
395 dc
->DrawRectangle( cell
);
400 wxSize
wxDataViewProgressCell::GetSize()
402 return wxSize(40,12);
405 // ---------------------------------------------------------
406 // wxDataViewDateCell
407 // ---------------------------------------------------------
409 class wxDataViewDateCellPopupTransient
: public wxPopupTransientWindow
412 wxDataViewDateCellPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
413 wxDataViewListModel
*model
, size_t col
, size_t row
) :
414 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
419 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
420 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
421 sizer
->Add( m_cal
, 1, wxGROW
);
426 virtual void OnDismiss()
430 void OnCalendar( wxCalendarEvent
&event
);
432 wxCalendarCtrl
*m_cal
;
433 wxDataViewListModel
*m_model
;
438 DECLARE_EVENT_TABLE()
441 BEGIN_EVENT_TABLE(wxDataViewDateCellPopupTransient
,wxPopupTransientWindow
)
442 EVT_CALENDAR( wxID_ANY
, wxDataViewDateCellPopupTransient::OnCalendar
)
445 void wxDataViewDateCellPopupTransient::OnCalendar( wxCalendarEvent
&event
)
447 wxDateTime date
= event
.GetDate();
448 wxVariant value
= date
;
449 m_model
->SetValue( value
, m_col
, m_row
);
450 m_model
->ValueChanged( m_col
, m_row
);
454 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateCell
, wxDataViewCustomCell
)
456 wxDataViewDateCell::wxDataViewDateCell( const wxString
&varianttype
,
457 wxDataViewCellMode mode
) :
458 wxDataViewCustomCell( varianttype
, mode
)
462 bool wxDataViewDateCell::SetValue( const wxVariant
&value
)
464 m_date
= value
.GetDateTime();
469 bool wxDataViewDateCell::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
471 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
472 wxString tmp
= m_date
.FormatDate();
473 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
478 wxSize
wxDataViewDateCell::GetSize()
480 wxDataViewCtrl
* view
= GetOwner()->GetOwner();
481 wxString tmp
= m_date
.FormatDate();
483 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
484 return wxSize(x
,y
+d
);
487 bool wxDataViewDateCell::Activate( wxRect
WXUNUSED(cell
), wxDataViewListModel
*model
, size_t col
, size_t row
)
490 model
->GetValue( variant
, col
, row
);
491 wxDateTime value
= variant
.GetDateTime();
493 wxDataViewDateCellPopupTransient
*popup
= new wxDataViewDateCellPopupTransient(
494 GetOwner()->GetOwner()->GetParent(), &value
, model
, col
, row
);
495 wxPoint pos
= wxGetMousePosition();
498 popup
->Popup( popup
->m_cal
);
503 // ---------------------------------------------------------
505 // ---------------------------------------------------------
507 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
509 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewCell
*cell
,
510 size_t model_column
, int flags
) :
511 wxDataViewColumnBase( title
, cell
, model_column
, flags
)
516 wxDataViewColumn::~wxDataViewColumn()
520 void wxDataViewColumn::SetTitle( const wxString
&title
)
522 wxDataViewColumnBase::SetTitle( title
);
526 //-----------------------------------------------------------------------------
527 // wxDataViewHeaderWindow
528 //-----------------------------------------------------------------------------
530 IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindow
, wxWindow
)
532 BEGIN_EVENT_TABLE(wxDataViewHeaderWindow
,wxWindow
)
533 EVT_PAINT (wxDataViewHeaderWindow::OnPaint
)
534 EVT_MOUSE_EVENTS (wxDataViewHeaderWindow::OnMouse
)
535 EVT_SET_FOCUS (wxDataViewHeaderWindow::OnSetFocus
)
538 wxDataViewHeaderWindow::wxDataViewHeaderWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
539 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
540 wxWindow( parent
, id
, pos
, size
, 0, name
)
544 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
546 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
547 SetOwnForegroundColour( attr
.colFg
);
548 SetOwnBackgroundColour( attr
.colBg
);
550 SetOwnFont( attr
.font
);
553 wxDataViewHeaderWindow::~wxDataViewHeaderWindow()
555 delete m_resizeCursor
;
558 void wxDataViewHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
561 GetClientSize( &w
, &h
);
563 wxPaintDC
dc( this );
566 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
569 m_owner
->GetViewStart( &x
, NULL
);
571 // account for the horz scrollbar offset
572 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
574 dc
.SetFont( GetFont() );
576 size_t cols
= GetOwner()->GetNumberOfColumns();
579 for (i
= 0; i
< cols
; i
++)
581 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
582 int width
= col
->GetWidth();
584 // the width of the rect to draw: make it smaller to fit entirely
585 // inside the column rect
594 wxRendererNative::Get().DrawHeaderButton
598 wxRect(xpos
, 0, cw
, ch
),
599 m_parent
->IsEnabled() ? 0
600 : (int)wxCONTROL_DISABLED
603 dc
.DrawText( col
->GetTitle(), xpos
+3, 3 );
609 void wxDataViewHeaderWindow::OnMouse( wxMouseEvent
&WXUNUSED(event
) )
613 void wxDataViewHeaderWindow::OnSetFocus( wxFocusEvent
&event
)
618 //-----------------------------------------------------------------------------
619 // wxDataViewRenameTimer
620 //-----------------------------------------------------------------------------
622 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
627 void wxDataViewRenameTimer::Notify()
629 m_owner
->OnRenameTimer();
632 //-----------------------------------------------------------------------------
633 // wxDataViewTextCtrlWrapper: wraps a wxTextCtrl for inline editing
634 //-----------------------------------------------------------------------------
636 BEGIN_EVENT_TABLE(wxDataViewTextCtrlWrapper
, wxEvtHandler
)
637 EVT_CHAR (wxDataViewTextCtrlWrapper::OnChar
)
638 EVT_KEY_UP (wxDataViewTextCtrlWrapper::OnKeyUp
)
639 EVT_KILL_FOCUS (wxDataViewTextCtrlWrapper::OnKillFocus
)
642 wxDataViewTextCtrlWrapper::wxDataViewTextCtrlWrapper(
643 wxDataViewMainWindow
*owner
,
645 wxDataViewListModel
*model
,
646 size_t col
, size_t row
,
656 m_aboutToFinish
= false;
659 model
->GetValue( value
, col
, row
);
660 m_startValue
= value
.GetString();
662 m_owner
->GetOwner()->CalcScrolledPosition(
663 rectLabel
.x
, rectLabel
.y
, &rectLabel
.x
, &rectLabel
.y
);
665 m_text
->Create( owner
, wxID_ANY
, m_startValue
,
666 wxPoint(rectLabel
.x
-2,rectLabel
.y
-2),
667 wxSize(rectLabel
.width
+7,rectLabel
.height
+4) );
670 m_text
->PushEventHandler(this);
673 void wxDataViewTextCtrlWrapper::AcceptChangesAndFinish()
675 m_aboutToFinish
= true;
677 // Notify the owner about the changes
680 // Even if vetoed, close the control (consistent with MSW)
684 void wxDataViewTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
686 switch ( event
.m_keyCode
)
689 AcceptChangesAndFinish();
693 // m_owner->OnRenameCancelled( m_itemEdited );
702 void wxDataViewTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
710 // auto-grow the textctrl
711 wxSize parentSize
= m_owner
->GetSize();
712 wxPoint myPos
= m_text
->GetPosition();
713 wxSize mySize
= m_text
->GetSize();
715 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
716 if (myPos
.x
+ sx
> parentSize
.x
)
717 sx
= parentSize
.x
- myPos
.x
;
720 m_text
->SetSize(sx
, wxDefaultCoord
);
725 void wxDataViewTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
727 if ( !m_finished
&& !m_aboutToFinish
)
730 //if ( !AcceptChanges() )
731 // m_owner->OnRenameCancelled( m_itemEdited );
736 // We must let the native text control handle focus
740 bool wxDataViewTextCtrlWrapper::AcceptChanges()
742 const wxString value
= m_text
->GetValue();
744 if ( value
== m_startValue
)
745 // nothing changed, always accept
748 // if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
749 // vetoed by the user
752 // accepted, do rename the item
755 m_model
->SetValue( variant
, m_col
, m_row
);
756 m_model
->ValueChanged( m_col
, m_row
);
761 void wxDataViewTextCtrlWrapper::Finish()
767 m_text
->RemoveEventHandler(this);
768 m_owner
->FinishEditing(m_text
);
771 wxPendingDelete
.Append( this );
775 //-----------------------------------------------------------------------------
776 // wxDataViewMainWindow
777 //-----------------------------------------------------------------------------
779 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
781 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
782 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
783 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
784 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
787 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
788 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
789 wxWindow( parent
, id
, pos
, size
, 0, name
)
793 m_lastOnSame
= false;
794 m_renameTimer
= new wxDataViewRenameTimer( this );
795 m_textctrlWrapper
= NULL
;
797 // TODO: user better initial values/nothing selected
801 // TODO: we need to calculate this smartly
807 wxDataViewMainWindow::~wxDataViewMainWindow()
809 delete m_renameTimer
;
812 void wxDataViewMainWindow::OnRenameTimer()
814 // We have to call this here because changes may just have
815 // been made and no screen update taken place.
821 size_t cols
= GetOwner()->GetNumberOfColumns();
823 for (i
= 0; i
< cols
; i
++)
825 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
826 if (c
== m_currentCol
)
828 xpos
+= c
->GetWidth();
830 wxRect
labelRect( xpos
, m_currentRow
* m_lineHeight
, m_currentCol
->GetWidth(), m_lineHeight
);
832 wxClassInfo
*textControlClass
= CLASSINFO(wxTextCtrl
);
834 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
835 m_textctrlWrapper
= new wxDataViewTextCtrlWrapper(this, text
, GetOwner()->GetModel(),
836 m_currentCol
->GetModelColumn(), m_currentRow
, labelRect
);
839 void wxDataViewMainWindow::FinishEditing( wxTextCtrl
*text
)
842 m_textctrlWrapper
= NULL
;
844 // SetFocusIgnoringChildren();
847 bool wxDataViewMainWindow::RowAppended()
852 bool wxDataViewMainWindow::RowPrepended()
857 bool wxDataViewMainWindow::RowInserted( size_t WXUNUSED(before
) )
862 bool wxDataViewMainWindow::RowDeleted( size_t WXUNUSED(row
) )
867 bool wxDataViewMainWindow::RowChanged( size_t WXUNUSED(row
) )
872 bool wxDataViewMainWindow::ValueChanged( size_t WXUNUSED(col
), size_t row
)
874 wxRect
rect( 0, row
*m_lineHeight
, 10000, m_lineHeight
);
875 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
876 Refresh( true, &rect
);
881 bool wxDataViewMainWindow::RowsReordered( size_t *WXUNUSED(new_order
) )
888 bool wxDataViewMainWindow::Cleared()
893 void wxDataViewMainWindow::UpdateDisplay()
898 void wxDataViewMainWindow::OnInternalIdle()
900 wxWindow::OnInternalIdle();
904 RecalculateDisplay();
909 void wxDataViewMainWindow::RecalculateDisplay()
911 wxDataViewListModel
*model
= GetOwner()->GetModel();
919 size_t cols
= GetOwner()->GetNumberOfColumns();
921 for (i
= 0; i
< cols
; i
++)
923 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
924 width
+= col
->GetWidth();
927 int height
= model
->GetNumberOfRows() * m_lineHeight
;
929 SetVirtualSize( width
, height
);
930 GetOwner()->SetScrollRate( 10, m_lineHeight
);
935 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
937 wxWindow::ScrollWindow( dx
, dy
, rect
);
938 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
941 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
943 wxPaintDC
dc( this );
945 GetOwner()->PrepareDC( dc
);
947 dc
.SetFont( GetFont() );
949 wxRect update
= GetUpdateRegion().GetBox();
950 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
952 wxDataViewListModel
*model
= GetOwner()->GetModel();
954 size_t item_start
= wxMax( 0, update
.y
/ m_lineHeight
);
955 size_t item_count
= wxMin( (update
.height
/ m_lineHeight
) + 1,
956 (int)(model
->GetNumberOfRows()-item_start
) );
960 cell_rect
.height
= m_lineHeight
;
961 size_t cols
= GetOwner()->GetNumberOfColumns();
963 for (i
= 0; i
< cols
; i
++)
965 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
966 wxDataViewCell
*cell
= col
->GetCell();
967 cell_rect
.width
= col
->GetWidth();
970 for (item
= item_start
; item
< item_start
+item_count
; item
++)
972 cell_rect
.y
= item
*m_lineHeight
;
974 model
->GetValue( value
, col
->GetModelColumn(), item
);
975 cell
->SetValue( value
);
976 wxSize size
= cell
->GetSize();
977 // cannot be bigger than allocated space
978 size
.x
= wxMin( size
.x
, cell_rect
.width
);
979 size
.y
= wxMin( size
.y
, cell_rect
.height
);
980 // TODO: check for left/right/centre alignment here
983 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
984 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
986 item_rect
.width
= size
.x
;
987 item_rect
.height
= size
.y
;
988 cell
->Render( item_rect
, &dc
, 0 );
991 cell_rect
.x
+= cell_rect
.width
;
995 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
997 int x
= event
.GetX();
998 int y
= event
.GetY();
999 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
1001 wxDataViewColumn
*col
= NULL
;
1004 size_t cols
= GetOwner()->GetNumberOfColumns();
1006 for (i
= 0; i
< cols
; i
++)
1008 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
1009 if (x
< xpos
+ c
->GetWidth())
1014 xpos
+= c
->GetWidth();
1018 wxDataViewCell
*cell
= col
->GetCell();
1020 size_t row
= y
/ m_lineHeight
;
1022 wxDataViewListModel
*model
= GetOwner()->GetModel();
1024 if (event
.ButtonDClick())
1026 m_renameTimer
->Stop();
1027 m_lastOnSame
= false;
1030 if (event
.LeftDClick())
1032 if (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
)
1035 model
->GetValue( value
, col
->GetModelColumn(), row
);
1036 cell
->SetValue( value
);
1037 wxRect
cell_rect( xpos
, row
* m_lineHeight
, col
->GetWidth(), m_lineHeight
);
1038 cell
->Activate( cell_rect
, model
, col
->GetModelColumn(), row
);
1047 if ((col
== m_currentCol
) & (row
== m_currentRow
) &&
1048 (cell
->GetMode() == wxDATAVIEW_CELL_EDITABLE
) )
1050 m_renameTimer
->Start( 100, true );
1054 m_lastOnSame
= false;
1056 if (event
.LeftDown())
1058 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
1059 size_t oldCurrentRow
= m_currentRow
;
1061 // Update selection here...
1065 m_lastOnSame
= (col
== oldCurrentCol
) && (row
== oldCurrentRow
);
1073 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
1078 //-----------------------------------------------------------------------------
1080 //-----------------------------------------------------------------------------
1082 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
1084 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
1085 EVT_SIZE(wxDataViewCtrl::OnSize
)
1088 wxDataViewCtrl::~wxDataViewCtrl()
1091 GetModel()->RemoveNotifier( m_notifier
);
1094 void wxDataViewCtrl::Init()
1099 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
1100 const wxPoint
& pos
, const wxSize
& size
,
1101 long style
, const wxValidator
& validator
)
1103 if (!wxControl::Create( parent
, id
, pos
, size
, style
| wxScrolledWindowStyle
|wxSUNKEN_BORDER
, validator
))
1109 MacSetClipChildren( true ) ;
1112 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
1113 m_headerArea
= new wxDataViewHeaderWindow( this, wxID_ANY
, wxDefaultPosition
, wxSize(wxDefaultCoord
,25) );
1115 SetTargetWindow( m_clientArea
);
1117 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
1118 sizer
->Add( m_headerArea
, 0, wxGROW
);
1119 sizer
->Add( m_clientArea
, 1, wxGROW
);
1126 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
1130 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
1133 // we need to process arrows ourselves for scrolling
1134 if ( nMsg
== WM_GETDLGCODE
)
1136 rc
|= DLGC_WANTARROWS
;
1144 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1146 // We need to override OnSize so that our scrolled
1147 // window a) does call Layout() to use sizers for
1148 // positioning the controls but b) does not query
1149 // the sizer for their size and use that for setting
1150 // the scrollable area as set that ourselves by
1151 // calling SetScrollbar() further down.
1158 bool wxDataViewCtrl::AssociateModel( wxDataViewListModel
*model
)
1160 if (!wxDataViewCtrlBase::AssociateModel( model
))
1163 m_notifier
= new wxGenericDataViewListModelNotifier( m_clientArea
);
1165 model
->AddNotifier( m_notifier
);
1167 m_clientArea
->UpdateDisplay();
1172 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
1174 if (!wxDataViewCtrlBase::AppendColumn(col
))
1177 m_clientArea
->UpdateDisplay();
1183 // !wxUSE_GENERICDATAVIEWCTRL
1186 // wxUSE_DATAVIEWCTRL