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
319 rect
.x
= cell
.x
+ cell
.width
/2 - 10;
321 rect
.y
= cell
.y
+ cell
.height
/2 - 10;
326 flags
|= wxCONTROL_CHECKED
;
327 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
328 flags
|= wxCONTROL_DISABLED
;
330 wxRendererNative::Get().DrawCheckButton(
331 GetOwner()->GetOwner(),
339 bool wxDataViewToggleCell::Activate( wxRect
WXUNUSED(cell
), wxDataViewListModel
*model
, size_t col
, size_t row
)
341 bool value
= !m_toggle
;
342 wxVariant variant
= value
;
343 model
->SetValue( variant
, col
, row
);
344 model
->ValueChanged( col
, row
);
348 wxSize
wxDataViewToggleCell::GetSize()
350 return wxSize(20,20);
353 // ---------------------------------------------------------
354 // wxDataViewProgressCell
355 // ---------------------------------------------------------
357 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressCell
, wxDataViewCustomCell
)
359 wxDataViewProgressCell::wxDataViewProgressCell( const wxString
&label
,
360 const wxString
&varianttype
, wxDataViewCellMode mode
) :
361 wxDataViewCustomCell( varianttype
, mode
)
367 wxDataViewProgressCell::~wxDataViewProgressCell()
371 bool wxDataViewProgressCell::SetValue( const wxVariant
&value
)
373 m_value
= (long) value
;
375 if (m_value
< 0) m_value
= 0;
376 if (m_value
> 100) m_value
= 100;
381 bool wxDataViewProgressCell::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
383 double pct
= (double)m_value
/ 100.0;
385 bar
.width
= (int)(cell
.width
* pct
);
386 dc
->SetPen( *wxTRANSPARENT_PEN
);
387 dc
->SetBrush( *wxBLUE_BRUSH
);
388 dc
->DrawRectangle( bar
);
390 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
391 dc
->SetPen( *wxBLACK_PEN
);
392 dc
->DrawRectangle( cell
);
397 wxSize
wxDataViewProgressCell::GetSize()
399 return wxSize(40,12);
402 // ---------------------------------------------------------
403 // wxDataViewDateCell
404 // ---------------------------------------------------------
406 class wxDataViewDateCellPopupTransient
: public wxPopupTransientWindow
409 wxDataViewDateCellPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
410 wxDataViewListModel
*model
, size_t col
, size_t row
) :
411 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
416 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
417 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
418 sizer
->Add( m_cal
, 1, wxGROW
);
423 virtual void OnDismiss()
427 void OnCalendar( wxCalendarEvent
&event
);
429 wxCalendarCtrl
*m_cal
;
430 wxDataViewListModel
*m_model
;
435 DECLARE_EVENT_TABLE()
438 BEGIN_EVENT_TABLE(wxDataViewDateCellPopupTransient
,wxPopupTransientWindow
)
439 EVT_CALENDAR( wxID_ANY
, wxDataViewDateCellPopupTransient::OnCalendar
)
442 void wxDataViewDateCellPopupTransient::OnCalendar( wxCalendarEvent
&event
)
444 wxDateTime date
= event
.GetDate();
445 wxVariant value
= date
;
446 m_model
->SetValue( value
, m_col
, m_row
);
447 m_model
->ValueChanged( m_col
, m_row
);
451 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateCell
, wxDataViewCustomCell
)
453 wxDataViewDateCell::wxDataViewDateCell( const wxString
&varianttype
,
454 wxDataViewCellMode mode
) :
455 wxDataViewCustomCell( varianttype
, mode
)
459 bool wxDataViewDateCell::SetValue( const wxVariant
&value
)
461 m_date
= value
.GetDateTime();
466 bool wxDataViewDateCell::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
468 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
469 wxString tmp
= m_date
.FormatDate();
470 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
475 wxSize
wxDataViewDateCell::GetSize()
477 wxDataViewCtrl
* view
= GetOwner()->GetOwner();
478 wxString tmp
= m_date
.FormatDate();
480 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
481 return wxSize(x
,y
+d
);
484 bool wxDataViewDateCell::Activate( wxRect
WXUNUSED(cell
), wxDataViewListModel
*model
, size_t col
, size_t row
)
487 model
->GetValue( variant
, col
, row
);
488 wxDateTime value
= variant
.GetDateTime();
490 wxDataViewDateCellPopupTransient
*popup
= new wxDataViewDateCellPopupTransient(
491 GetOwner()->GetOwner()->GetParent(), &value
, model
, col
, row
);
492 wxPoint pos
= wxGetMousePosition();
495 popup
->Popup( popup
->m_cal
);
500 // ---------------------------------------------------------
502 // ---------------------------------------------------------
504 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
506 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewCell
*cell
,
507 size_t model_column
, int flags
) :
508 wxDataViewColumnBase( title
, cell
, model_column
, flags
)
513 wxDataViewColumn::~wxDataViewColumn()
517 void wxDataViewColumn::SetTitle( const wxString
&title
)
519 wxDataViewColumnBase::SetTitle( title
);
523 //-----------------------------------------------------------------------------
524 // wxDataViewHeaderWindow
525 //-----------------------------------------------------------------------------
527 IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindow
, wxWindow
)
529 BEGIN_EVENT_TABLE(wxDataViewHeaderWindow
,wxWindow
)
530 EVT_PAINT (wxDataViewHeaderWindow::OnPaint
)
531 EVT_MOUSE_EVENTS (wxDataViewHeaderWindow::OnMouse
)
532 EVT_SET_FOCUS (wxDataViewHeaderWindow::OnSetFocus
)
535 wxDataViewHeaderWindow::wxDataViewHeaderWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
536 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
537 wxWindow( parent
, id
, pos
, size
, 0, name
)
541 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
543 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
544 SetOwnForegroundColour( attr
.colFg
);
545 SetOwnBackgroundColour( attr
.colBg
);
547 SetOwnFont( attr
.font
);
550 wxDataViewHeaderWindow::~wxDataViewHeaderWindow()
552 delete m_resizeCursor
;
555 void wxDataViewHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
558 GetClientSize( &w
, &h
);
560 wxPaintDC
dc( this );
563 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
566 m_owner
->GetViewStart( &x
, NULL
);
568 // account for the horz scrollbar offset
569 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
571 dc
.SetFont( GetFont() );
573 size_t cols
= GetOwner()->GetNumberOfColumns();
576 for (i
= 0; i
< cols
; i
++)
578 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
579 int width
= col
->GetWidth();
581 // the width of the rect to draw: make it smaller to fit entirely
582 // inside the column rect
591 wxRendererNative::Get().DrawHeaderButton
595 wxRect(xpos
, 0, cw
, ch
),
596 m_parent
->IsEnabled() ? 0
597 : (int)wxCONTROL_DISABLED
600 dc
.DrawText( col
->GetTitle(), xpos
+3, 3 );
606 void wxDataViewHeaderWindow::OnMouse( wxMouseEvent
&WXUNUSED(event
) )
610 void wxDataViewHeaderWindow::OnSetFocus( wxFocusEvent
&event
)
615 //-----------------------------------------------------------------------------
616 // wxDataViewRenameTimer
617 //-----------------------------------------------------------------------------
619 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
624 void wxDataViewRenameTimer::Notify()
626 m_owner
->OnRenameTimer();
629 //-----------------------------------------------------------------------------
630 // wxDataViewTextCtrlWrapper: wraps a wxTextCtrl for inline editing
631 //-----------------------------------------------------------------------------
633 BEGIN_EVENT_TABLE(wxDataViewTextCtrlWrapper
, wxEvtHandler
)
634 EVT_CHAR (wxDataViewTextCtrlWrapper::OnChar
)
635 EVT_KEY_UP (wxDataViewTextCtrlWrapper::OnKeyUp
)
636 EVT_KILL_FOCUS (wxDataViewTextCtrlWrapper::OnKillFocus
)
639 wxDataViewTextCtrlWrapper::wxDataViewTextCtrlWrapper(
640 wxDataViewMainWindow
*owner
,
642 wxDataViewListModel
*model
,
643 size_t col
, size_t row
,
653 m_aboutToFinish
= false;
656 model
->GetValue( value
, col
, row
);
657 m_startValue
= value
.GetString();
659 m_owner
->GetOwner()->CalcScrolledPosition(
660 rectLabel
.x
, rectLabel
.y
, &rectLabel
.x
, &rectLabel
.y
);
662 m_text
->Create( owner
, wxID_ANY
, m_startValue
,
663 wxPoint(rectLabel
.x
-2,rectLabel
.y
-2),
664 wxSize(rectLabel
.width
+7,rectLabel
.height
+4) );
667 m_text
->PushEventHandler(this);
670 void wxDataViewTextCtrlWrapper::AcceptChangesAndFinish()
672 m_aboutToFinish
= true;
674 // Notify the owner about the changes
677 // Even if vetoed, close the control (consistent with MSW)
681 void wxDataViewTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
683 switch ( event
.m_keyCode
)
686 AcceptChangesAndFinish();
690 // m_owner->OnRenameCancelled( m_itemEdited );
699 void wxDataViewTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
707 // auto-grow the textctrl
708 wxSize parentSize
= m_owner
->GetSize();
709 wxPoint myPos
= m_text
->GetPosition();
710 wxSize mySize
= m_text
->GetSize();
712 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
713 if (myPos
.x
+ sx
> parentSize
.x
)
714 sx
= parentSize
.x
- myPos
.x
;
717 m_text
->SetSize(sx
, wxDefaultCoord
);
722 void wxDataViewTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
724 if ( !m_finished
&& !m_aboutToFinish
)
727 //if ( !AcceptChanges() )
728 // m_owner->OnRenameCancelled( m_itemEdited );
733 // We must let the native text control handle focus
737 bool wxDataViewTextCtrlWrapper::AcceptChanges()
739 const wxString value
= m_text
->GetValue();
741 if ( value
== m_startValue
)
742 // nothing changed, always accept
745 // if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
746 // vetoed by the user
749 // accepted, do rename the item
752 m_model
->SetValue( variant
, m_col
, m_row
);
753 m_model
->ValueChanged( m_col
, m_row
);
758 void wxDataViewTextCtrlWrapper::Finish()
764 m_text
->RemoveEventHandler(this);
765 m_owner
->FinishEditing(m_text
);
768 wxPendingDelete
.Append( this );
772 //-----------------------------------------------------------------------------
773 // wxDataViewMainWindow
774 //-----------------------------------------------------------------------------
776 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
778 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
779 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
780 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
781 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
784 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
785 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
786 wxWindow( parent
, id
, pos
, size
, 0, name
)
790 m_lastOnSame
= false;
791 m_renameTimer
= new wxDataViewRenameTimer( this );
792 m_textctrlWrapper
= NULL
;
794 // TODO: user better initial values/nothing selected
798 // TODO: we need to calculate this smartly
804 wxDataViewMainWindow::~wxDataViewMainWindow()
806 delete m_renameTimer
;
809 void wxDataViewMainWindow::OnRenameTimer()
811 // We have to call this here because changes may just have
812 // been made and no screen update taken place.
818 size_t cols
= GetOwner()->GetNumberOfColumns();
820 for (i
= 0; i
< cols
; i
++)
822 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
823 if (c
== m_currentCol
)
825 xpos
+= c
->GetWidth();
827 wxRect
labelRect( xpos
, m_currentRow
* m_lineHeight
, m_currentCol
->GetWidth(), m_lineHeight
);
829 wxClassInfo
*textControlClass
= CLASSINFO(wxTextCtrl
);
831 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
832 m_textctrlWrapper
= new wxDataViewTextCtrlWrapper(this, text
, GetOwner()->GetModel(),
833 m_currentCol
->GetModelColumn(), m_currentRow
, labelRect
);
836 void wxDataViewMainWindow::FinishEditing( wxTextCtrl
*text
)
839 m_textctrlWrapper
= NULL
;
841 // SetFocusIgnoringChildren();
844 bool wxDataViewMainWindow::RowAppended()
849 bool wxDataViewMainWindow::RowPrepended()
854 bool wxDataViewMainWindow::RowInserted( size_t WXUNUSED(before
) )
859 bool wxDataViewMainWindow::RowDeleted( size_t WXUNUSED(row
) )
864 bool wxDataViewMainWindow::RowChanged( size_t WXUNUSED(row
) )
869 bool wxDataViewMainWindow::ValueChanged( size_t WXUNUSED(col
), size_t row
)
871 wxRect
rect( 0, row
*m_lineHeight
, 10000, m_lineHeight
);
872 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
873 Refresh( true, &rect
);
878 bool wxDataViewMainWindow::RowsReordered( size_t *WXUNUSED(new_order
) )
885 bool wxDataViewMainWindow::Cleared()
890 void wxDataViewMainWindow::UpdateDisplay()
895 void wxDataViewMainWindow::OnInternalIdle()
897 wxWindow::OnInternalIdle();
901 RecalculateDisplay();
906 void wxDataViewMainWindow::RecalculateDisplay()
908 wxDataViewListModel
*model
= GetOwner()->GetModel();
916 size_t cols
= GetOwner()->GetNumberOfColumns();
918 for (i
= 0; i
< cols
; i
++)
920 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
921 width
+= col
->GetWidth();
924 int height
= model
->GetNumberOfRows() * m_lineHeight
;
926 SetVirtualSize( width
, height
);
927 GetOwner()->SetScrollRate( 10, m_lineHeight
);
932 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
934 wxWindow::ScrollWindow( dx
, dy
, rect
);
935 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
938 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
940 wxPaintDC
dc( this );
942 GetOwner()->PrepareDC( dc
);
944 dc
.SetFont( GetFont() );
946 wxRect update
= GetUpdateRegion().GetBox();
947 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
949 wxDataViewListModel
*model
= GetOwner()->GetModel();
951 size_t item_start
= wxMax( 0, update
.y
/ m_lineHeight
);
952 size_t item_count
= wxMin( (update
.height
/ m_lineHeight
) + 1,
953 (int)(model
->GetNumberOfRows()-item_start
) );
957 cell_rect
.height
= m_lineHeight
;
958 size_t cols
= GetOwner()->GetNumberOfColumns();
960 for (i
= 0; i
< cols
; i
++)
962 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
963 wxDataViewCell
*cell
= col
->GetCell();
964 cell_rect
.width
= col
->GetWidth();
967 for (item
= item_start
; item
< item_start
+item_count
; item
++)
969 cell_rect
.y
= item
*m_lineHeight
;
971 model
->GetValue( value
, col
->GetModelColumn(), item
);
972 cell
->SetValue( value
);
973 wxSize size
= cell
->GetSize();
974 // cannot be bigger than allocated space
975 size
.x
= wxMin( size
.x
, cell_rect
.width
);
976 size
.y
= wxMin( size
.y
, cell_rect
.height
);
977 // TODO: check for left/right/centre alignment here
980 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
981 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
983 item_rect
.width
= size
.x
;
984 item_rect
.height
= size
.y
;
985 cell
->Render( item_rect
, &dc
, 0 );
988 cell_rect
.x
+= cell_rect
.width
;
992 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
994 int x
= event
.GetX();
995 int y
= event
.GetY();
996 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
998 wxDataViewColumn
*col
= NULL
;
1001 size_t cols
= GetOwner()->GetNumberOfColumns();
1003 for (i
= 0; i
< cols
; i
++)
1005 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
1006 if (x
< xpos
+ c
->GetWidth())
1011 xpos
+= c
->GetWidth();
1015 wxDataViewCell
*cell
= col
->GetCell();
1017 size_t row
= y
/ m_lineHeight
;
1019 wxDataViewListModel
*model
= GetOwner()->GetModel();
1021 if (event
.ButtonDClick())
1023 m_renameTimer
->Stop();
1024 m_lastOnSame
= false;
1027 if (event
.LeftDClick())
1029 if (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
)
1032 model
->GetValue( value
, col
->GetModelColumn(), row
);
1033 cell
->SetValue( value
);
1034 wxRect
cell_rect( xpos
, row
* m_lineHeight
, col
->GetWidth(), m_lineHeight
);
1035 cell
->Activate( cell_rect
, model
, col
->GetModelColumn(), row
);
1044 if ((col
== m_currentCol
) & (row
== m_currentRow
) &&
1045 (cell
->GetMode() == wxDATAVIEW_CELL_EDITABLE
) )
1047 m_renameTimer
->Start( 100, true );
1051 m_lastOnSame
= false;
1053 if (event
.LeftDown())
1055 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
1056 size_t oldCurrentRow
= m_currentRow
;
1058 // Update selection here...
1062 m_lastOnSame
= (col
== oldCurrentCol
) && (row
== oldCurrentRow
);
1070 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
1075 //-----------------------------------------------------------------------------
1077 //-----------------------------------------------------------------------------
1079 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
1081 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
1082 EVT_SIZE(wxDataViewCtrl::OnSize
)
1085 wxDataViewCtrl::~wxDataViewCtrl()
1088 GetModel()->RemoveNotifier( m_notifier
);
1091 void wxDataViewCtrl::Init()
1096 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
1097 const wxPoint
& pos
, const wxSize
& size
,
1098 long style
, const wxValidator
& validator
)
1100 if (!wxControl::Create( parent
, id
, pos
, size
, style
| wxScrolledWindowStyle
|wxSUNKEN_BORDER
, validator
))
1106 MacSetClipChildren( true ) ;
1109 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
1110 m_headerArea
= new wxDataViewHeaderWindow( this, wxID_ANY
, wxDefaultPosition
, wxSize(wxDefaultCoord
,25) );
1112 SetTargetWindow( m_clientArea
);
1114 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
1115 sizer
->Add( m_headerArea
, 0, wxGROW
);
1116 sizer
->Add( m_clientArea
, 1, wxGROW
);
1123 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
1127 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
1130 // we need to process arrows ourselves for scrolling
1131 if ( nMsg
== WM_GETDLGCODE
)
1133 rc
|= DLGC_WANTARROWS
;
1141 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1143 // We need to override OnSize so that our scrolled
1144 // window a) does call Layout() to use sizers for
1145 // positioning the controls but b) does not query
1146 // the sizer for their size and use that for setting
1147 // the scrollable area as set that ourselves by
1148 // calling SetScrollbar() further down.
1155 bool wxDataViewCtrl::AssociateModel( wxDataViewListModel
*model
)
1157 if (!wxDataViewCtrlBase::AssociateModel( model
))
1160 m_notifier
= new wxGenericDataViewListModelNotifier( m_clientArea
);
1162 model
->AddNotifier( m_notifier
);
1164 m_clientArea
->UpdateDisplay();
1169 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
1171 if (!wxDataViewCtrlBase::AppendColumn(col
))
1174 m_clientArea
->UpdateDisplay();
1180 // !wxUSE_GENERICDATAVIEWCTRL
1183 // wxUSE_DATAVIEWCTRL