1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/datavgen.cpp
3 // Purpose: wxDataViewCtrl generic implementation
4 // Author: Robert Roebling
5 // Modified by: Francesco Montorsi, Guru Kathiresan, Otto Wyss
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 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
52 static const int SCROLL_UNIT_X
= 15;
54 // the cell padding on the left/right
55 static const int PADDING_RIGHTLEFT
= 3;
57 // the cell padding on the top/bottom
58 static const int PADDING_TOPBOTTOM
= 1;
61 //-----------------------------------------------------------------------------
62 // wxDataViewHeaderWindow
63 //-----------------------------------------------------------------------------
65 #define USE_NATIVE_HEADER_WINDOW 1
67 // NB: for some reason, this class must be dllexport'ed or we get warnings from
69 class WXDLLIMPEXP_ADV wxDataViewHeaderWindowBase
: public wxControl
72 wxDataViewHeaderWindowBase()
75 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
76 const wxPoint
&pos
, const wxSize
&size
,
79 return wxWindow::Create(parent
, id
, pos
, size
, wxNO_BORDER
, name
);
82 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
83 wxDataViewCtrl
*GetOwner() { return m_owner
; }
85 // called on column addition/removal
86 virtual void UpdateDisplay() { /* by default, do nothing */ }
88 // returns the n-th column
89 virtual wxDataViewColumn
*GetColumn(unsigned int n
)
92 wxDataViewColumn
*ret
= m_owner
->GetColumn(n
);
99 wxDataViewCtrl
*m_owner
;
101 // sends an event generated from the n-th wxDataViewColumn
102 void SendEvent(wxEventType type
, unsigned int n
);
105 // on wxMSW the header window (only that part however) can be made native!
106 #if defined(__WXMSW__) && USE_NATIVE_HEADER_WINDOW
108 #define COLUMN_WIDTH_OFFSET 2
109 #define wxDataViewHeaderWindowMSW wxDataViewHeaderWindow
111 class wxDataViewHeaderWindowMSW
: public wxDataViewHeaderWindowBase
115 wxDataViewHeaderWindowMSW( wxDataViewCtrl
*parent
,
117 const wxPoint
&pos
= wxDefaultPosition
,
118 const wxSize
&size
= wxDefaultSize
,
119 const wxString
&name
= wxT("wxdataviewctrlheaderwindow") )
121 Create(parent
, id
, pos
, size
, name
);
124 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
125 const wxPoint
&pos
, const wxSize
&size
,
126 const wxString
&name
);
128 ~wxDataViewHeaderWindowMSW();
130 // called when any column setting is changed and/or changed
132 virtual void UpdateDisplay();
134 // called when the main window gets scrolled
135 virtual void ScrollWindow(int dx
, int dy
, const wxRect
*rect
= NULL
);
138 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
139 virtual void DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
);
141 unsigned int GetColumnIdxFromHeader(NMHEADER
*nmHDR
);
143 wxDataViewColumn
*GetColumnFromHeader(NMHEADER
*nmHDR
)
144 { return GetColumn(GetColumnIdxFromHeader(nmHDR
)); }
147 DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindowMSW
)
150 #else // !defined(__WXMSW__)
152 #define HEADER_WINDOW_HEIGHT 25
153 #define HEADER_HORIZ_BORDER 5
154 #define HEADER_VERT_BORDER 3
155 #define wxGenericDataViewHeaderWindow wxDataViewHeaderWindow
157 class wxGenericDataViewHeaderWindow
: public wxDataViewHeaderWindowBase
160 wxGenericDataViewHeaderWindow( wxDataViewCtrl
*parent
,
162 const wxPoint
&pos
= wxDefaultPosition
,
163 const wxSize
&size
= wxDefaultSize
,
164 const wxString
&name
= wxT("wxdataviewctrlheaderwindow") )
167 Create(parent
, id
, pos
, size
, name
);
170 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
171 const wxPoint
&pos
, const wxSize
&size
,
172 const wxString
&name
);
174 ~wxGenericDataViewHeaderWindow()
176 delete m_resizeCursor
;
179 virtual void UpdateDisplay() { Refresh(); }
183 void OnPaint( wxPaintEvent
&event
);
184 void OnMouse( wxMouseEvent
&event
);
185 void OnSetFocus( wxFocusEvent
&event
);
190 // vars used for column resizing:
192 wxCursor
*m_resizeCursor
;
193 const wxCursor
*m_currentCursor
;
196 bool m_dirty
; // needs refresh?
197 int m_column
; // index of the column being resized
198 int m_currentX
; // divider line position in logical (unscrolled) coords
199 int m_minX
; // minimal position beyond which the divider line
200 // can't be dragged in logical coords
202 // the pen used to draw the current column width drag line
203 // when resizing the columsn
207 // internal utilities:
211 m_currentCursor
= (wxCursor
*) NULL
;
212 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
214 m_isDragging
= false;
217 m_column
= wxNOT_FOUND
;
221 wxColour col
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
222 m_penCurrent
= wxPen(col
, 1, wxSOLID
);
226 void AdjustDC(wxDC
& dc
);
229 DECLARE_DYNAMIC_CLASS(wxGenericDataViewHeaderWindow
)
230 DECLARE_EVENT_TABLE()
233 #endif // defined(__WXMSW__)
235 //-----------------------------------------------------------------------------
236 // wxDataViewRenameTimer
237 //-----------------------------------------------------------------------------
239 class wxDataViewRenameTimer
: public wxTimer
242 wxDataViewMainWindow
*m_owner
;
245 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
249 //-----------------------------------------------------------------------------
250 // wxDataViewMainWindow
251 //-----------------------------------------------------------------------------
253 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
,
256 class wxDataViewMainWindow
: public wxWindow
259 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
261 const wxPoint
&pos
= wxDefaultPosition
,
262 const wxSize
&size
= wxDefaultSize
,
263 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
264 virtual ~wxDataViewMainWindow();
266 // notifications from wxDataViewListModel
269 bool RowInserted( unsigned int before
);
270 bool RowDeleted( unsigned int row
);
271 bool RowChanged( unsigned int row
);
272 bool ValueChanged( unsigned int col
, unsigned int row
);
273 bool RowsReordered( unsigned int *new_order
);
276 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
277 wxDataViewCtrl
*GetOwner() { return m_owner
; }
278 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
280 void OnPaint( wxPaintEvent
&event
);
281 void OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
);
282 void OnChar( wxKeyEvent
&event
);
283 void OnMouse( wxMouseEvent
&event
);
284 void OnSetFocus( wxFocusEvent
&event
);
285 void OnKillFocus( wxFocusEvent
&event
);
287 void UpdateDisplay();
288 void RecalculateDisplay();
289 void OnInternalIdle();
291 void OnRenameTimer();
293 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
295 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
296 void ChangeCurrentRow( unsigned int row
);
298 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
299 bool IsEmpty() { return GetRowCount() == 0; }
301 int GetCountPerPage() const;
302 int GetEndOfLastCol() const;
303 unsigned int GetFirstVisibleRow() const;
304 unsigned int GetLastVisibleRow() const;
305 unsigned int GetRowCount() const;
307 void Select( const wxArrayInt
& aSelections
);
308 void SelectAllRows( bool on
);
309 void SelectRow( unsigned int row
, bool on
);
310 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
311 void ReverseRowSelection( unsigned int row
);
312 bool IsRowSelected( unsigned int row
);
314 void RefreshRow( unsigned int row
);
315 void RefreshRows( unsigned int from
, unsigned int to
);
316 void RefreshRowsAfter( unsigned int firstRow
);
318 // returns the colour to be used for drawing the rules
319 wxColour
GetRuleColour() const
321 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
324 //void EnsureVisible( unsigned int row );
325 wxRect
GetLineRect( unsigned int row
) const;
328 wxDataViewCtrl
*m_owner
;
332 wxDataViewColumn
*m_currentCol
;
333 unsigned int m_currentRow
;
334 wxDataViewSelection m_selection
;
336 wxDataViewRenameTimer
*m_renameTimer
;
344 // for double click logic
345 unsigned int m_lineLastClicked
,
346 m_lineBeforeLastClicked
,
347 m_lineSelectSingleOnUp
;
349 // the pen used to draw horiz/vertical rules
353 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
354 DECLARE_EVENT_TABLE()
357 // ---------------------------------------------------------
358 // wxGenericDataViewListModelNotifier
359 // ---------------------------------------------------------
361 class wxGenericDataViewListModelNotifier
: public wxDataViewListModelNotifier
364 wxGenericDataViewListModelNotifier( wxDataViewMainWindow
*mainWindow
)
365 { m_mainWindow
= mainWindow
; }
367 virtual bool RowAppended()
368 { return m_mainWindow
->RowAppended(); }
369 virtual bool RowPrepended()
370 { return m_mainWindow
->RowPrepended(); }
371 virtual bool RowInserted( unsigned int before
)
372 { return m_mainWindow
->RowInserted( before
); }
373 virtual bool RowDeleted( unsigned int row
)
374 { return m_mainWindow
->RowDeleted( row
); }
375 virtual bool RowChanged( unsigned int row
)
376 { return m_mainWindow
->RowChanged( row
); }
377 virtual bool ValueChanged( unsigned int col
, unsigned int row
)
378 { return m_mainWindow
->ValueChanged( col
, row
); }
379 virtual bool RowsReordered( unsigned int *new_order
)
380 { return m_mainWindow
->RowsReordered( new_order
); }
381 virtual bool Cleared()
382 { return m_mainWindow
->Cleared(); }
384 wxDataViewMainWindow
*m_mainWindow
;
387 // ---------------------------------------------------------
388 // wxDataViewRenderer
389 // ---------------------------------------------------------
391 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
393 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
394 wxDataViewCellMode mode
,
396 wxDataViewRendererBase( varianttype
, mode
, align
)
403 wxDataViewRenderer::~wxDataViewRenderer()
409 wxDC
*wxDataViewRenderer::GetDC()
413 if (GetOwner() == NULL
)
415 if (GetOwner()->GetOwner() == NULL
)
417 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
423 // ---------------------------------------------------------
424 // wxDataViewCustomRenderer
425 // ---------------------------------------------------------
427 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
429 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
430 wxDataViewCellMode mode
, int align
) :
431 wxDataViewRenderer( varianttype
, mode
, align
)
435 // ---------------------------------------------------------
436 // wxDataViewTextRenderer
437 // ---------------------------------------------------------
439 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
441 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
442 wxDataViewCellMode mode
, int align
) :
443 wxDataViewCustomRenderer( varianttype
, mode
, align
)
447 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
449 m_text
= value
.GetString();
454 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
459 bool wxDataViewTextRenderer::HasEditorCtrl()
464 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
465 wxRect labelRect
, const wxVariant
&value
)
467 return new wxTextCtrl( parent
, wxID_ANY
, value
,
468 wxPoint(labelRect
.x
,labelRect
.y
),
469 wxSize(labelRect
.width
,labelRect
.height
) );
472 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
474 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
475 value
= text
->GetValue();
479 bool wxDataViewTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
481 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
482 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
483 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
484 view
->GetForegroundColour();
486 dc
->SetTextForeground(col
);
487 dc
->DrawText( m_text
, cell
.x
, cell
.y
);
492 wxSize
wxDataViewTextRenderer::GetSize() const
494 const wxDataViewCtrl
*view
= GetView();
498 view
->GetTextExtent( m_text
, &x
, &y
);
499 return wxSize( x
, y
);
501 return wxSize(80,20);
504 // ---------------------------------------------------------
505 // wxDataViewBitmapRenderer
506 // ---------------------------------------------------------
508 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
510 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
511 wxDataViewCellMode mode
, int align
) :
512 wxDataViewCustomRenderer( varianttype
, mode
, align
)
516 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
518 if (value
.GetType() == wxT("wxBitmap"))
520 if (value
.GetType() == wxT("wxIcon"))
526 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
531 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
534 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
535 else if (m_icon
.Ok())
536 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
541 wxSize
wxDataViewBitmapRenderer::GetSize() const
544 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
545 else if (m_icon
.Ok())
546 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
548 return wxSize(16,16);
551 // ---------------------------------------------------------
552 // wxDataViewToggleRenderer
553 // ---------------------------------------------------------
555 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
557 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
558 wxDataViewCellMode mode
, int align
) :
559 wxDataViewCustomRenderer( varianttype
, mode
, align
)
564 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
566 m_toggle
= value
.GetBool();
571 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
576 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
578 // User wxRenderer here
581 rect
.x
= cell
.x
+ cell
.width
/2 - 10;
583 rect
.y
= cell
.y
+ cell
.height
/2 - 10;
588 flags
|= wxCONTROL_CHECKED
;
589 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
590 flags
|= wxCONTROL_DISABLED
;
592 wxRendererNative::Get().DrawCheckBox(
593 GetOwner()->GetOwner(),
601 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
602 wxDataViewListModel
*model
,
603 unsigned int col
, unsigned int row
)
605 bool value
= !m_toggle
;
606 wxVariant variant
= value
;
607 model
->SetValue( variant
, col
, row
);
608 model
->ValueChanged( col
, row
);
612 wxSize
wxDataViewToggleRenderer::GetSize() const
614 return wxSize(20,20);
617 // ---------------------------------------------------------
618 // wxDataViewProgressRenderer
619 // ---------------------------------------------------------
621 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
623 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
624 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
625 wxDataViewCustomRenderer( varianttype
, mode
, align
)
631 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
635 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
637 m_value
= (long) value
;
639 if (m_value
< 0) m_value
= 0;
640 if (m_value
> 100) m_value
= 100;
645 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
647 value
= (long) m_value
;
651 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
653 double pct
= (double)m_value
/ 100.0;
655 bar
.width
= (int)(cell
.width
* pct
);
656 dc
->SetPen( *wxTRANSPARENT_PEN
);
657 dc
->SetBrush( *wxBLUE_BRUSH
);
658 dc
->DrawRectangle( bar
);
660 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
661 dc
->SetPen( *wxBLACK_PEN
);
662 dc
->DrawRectangle( cell
);
667 wxSize
wxDataViewProgressRenderer::GetSize() const
669 return wxSize(40,12);
672 // ---------------------------------------------------------
673 // wxDataViewDateRenderer
674 // ---------------------------------------------------------
676 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
678 #if wxUSE_DATE_RENDERER_POPUP
680 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
683 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
684 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
) :
685 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
690 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
691 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
692 sizer
->Add( m_cal
, 1, wxGROW
);
697 void OnCalendar( wxCalendarEvent
&event
);
699 wxCalendarCtrl
*m_cal
;
700 wxDataViewListModel
*m_model
;
705 virtual void OnDismiss()
710 DECLARE_EVENT_TABLE()
713 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
714 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
717 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
719 wxDateTime date
= event
.GetDate();
720 wxVariant value
= date
;
721 m_model
->SetValue( value
, m_col
, m_row
);
722 m_model
->ValueChanged( m_col
, m_row
);
726 #endif // wxUSE_DATE_RENDERER_POPUP
728 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
730 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
731 wxDataViewCellMode mode
, int align
) :
732 wxDataViewCustomRenderer( varianttype
, mode
, align
)
736 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
738 m_date
= value
.GetDateTime();
743 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
749 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
751 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
752 wxString tmp
= m_date
.FormatDate();
753 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
758 wxSize
wxDataViewDateRenderer::GetSize() const
760 const wxDataViewCtrl
* view
= GetView();
761 wxString tmp
= m_date
.FormatDate();
763 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
764 return wxSize(x
,y
+d
);
767 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewListModel
*model
,
768 unsigned int col
, unsigned int row
)
771 model
->GetValue( variant
, col
, row
);
772 wxDateTime value
= variant
.GetDateTime();
774 #if wxUSE_DATE_RENDERER_POPUP
775 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
776 GetOwner()->GetOwner()->GetParent(), &value
, model
, col
, row
);
777 wxPoint pos
= wxGetMousePosition();
780 popup
->Popup( popup
->m_cal
);
781 #else // !wxUSE_DATE_RENDERER_POPUP
782 wxMessageBox(value
.Format());
783 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
787 // ---------------------------------------------------------
789 // ---------------------------------------------------------
791 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
793 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
794 unsigned int model_column
,
795 int width
, wxAlignment align
, int flags
) :
796 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
802 Init(width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
805 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
806 unsigned int model_column
,
807 int width
, wxAlignment align
, int flags
) :
808 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
813 Init(width
< 0 ? wxDVC_TOGGLE_DEFAULT_WIDTH
: width
);
816 wxDataViewColumn::~wxDataViewColumn()
820 void wxDataViewColumn::Init( int width
)
823 m_minWidth
= wxDVC_DEFAULT_MINWIDTH
;
827 void wxDataViewColumn::SetResizeable( bool resizeable
)
830 m_flags
|= wxDATAVIEW_COL_RESIZABLE
;
832 m_flags
&= ~wxDATAVIEW_COL_RESIZABLE
;
835 void wxDataViewColumn::SetHidden( bool hidden
)
838 m_flags
|= wxDATAVIEW_COL_HIDDEN
;
840 m_flags
&= ~wxDATAVIEW_COL_HIDDEN
;
842 // tell our owner to e.g. update its scrollbars:
844 GetOwner()->OnColumnChange();
847 void wxDataViewColumn::SetSortable( bool sortable
)
850 m_flags
|= wxDATAVIEW_COL_SORTABLE
;
852 m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
854 // Update header button
856 GetOwner()->OnColumnChange();
859 void wxDataViewColumn::SetSortOrder( bool ascending
)
861 m_ascending
= ascending
;
863 // Update header button
865 GetOwner()->OnColumnChange();
868 bool wxDataViewColumn::IsSortOrderAscending() const
873 void wxDataViewColumn::SetInternalWidth( int width
)
877 // the scrollbars of the wxDataViewCtrl needs to be recalculated!
878 if (m_owner
&& m_owner
->m_clientArea
)
879 m_owner
->m_clientArea
->RecalculateDisplay();
882 void wxDataViewColumn::SetWidth( int width
)
884 m_owner
->m_headerArea
->UpdateDisplay();
886 SetInternalWidth(width
);
890 //-----------------------------------------------------------------------------
891 // wxDataViewHeaderWindowBase
892 //-----------------------------------------------------------------------------
894 void wxDataViewHeaderWindowBase::SendEvent(wxEventType type
, unsigned int n
)
896 wxWindow
*parent
= GetParent();
897 wxDataViewEvent
le(type
, parent
->GetId());
899 le
.SetEventObject(parent
);
901 le
.SetDataViewColumn(GetColumn(n
));
902 le
.SetModel(GetOwner()->GetModel());
904 // for events created by wxDataViewHeaderWindow the
905 // row / value fields are not valid
907 parent
->GetEventHandler()->ProcessEvent(le
);
910 #if defined(__WXMSW__) && USE_NATIVE_HEADER_WINDOW
912 // implemented in msw/listctrl.cpp:
913 int WXDLLIMPEXP_CORE
wxMSWGetColumnClicked(NMHDR
*nmhdr
, POINT
*ptClick
);
915 IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindowMSW
, wxWindow
)
917 bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl
*parent
, wxWindowID id
,
918 const wxPoint
&pos
, const wxSize
&size
,
919 const wxString
&name
)
923 if ( !CreateControl(parent
, id
, pos
, size
, 0, wxDefaultValidator
, name
) )
926 int x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
927 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
928 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
929 h
= size
.y
== wxDefaultCoord
? 22 : size
.y
;
931 // create the native WC_HEADER window:
932 WXHWND hwndParent
= (HWND
)parent
->GetHandle();
933 WXDWORD msStyle
= WS_CHILD
| HDS_BUTTONS
| HDS_HORZ
| HDS_HOTTRACK
| HDS_FULLDRAG
;
934 m_hWnd
= CreateWindowEx(0,
945 wxLogLastError(_T("CreateWindowEx"));
949 // we need to subclass the m_hWnd to force wxWindow::HandleNotify
950 // to call wxDataViewHeaderWindow::MSWOnNotify
953 // the following is required to get the default win's font for
954 // header windows and must be done befor sending the HDM_LAYOUT msg
961 // Retrieve the bounding rectangle of the parent window's
962 // client area, and then request size and position values
963 // from the header control.
964 ::GetClientRect((HWND
)hwndParent
, &rcParent
);
968 if (!SendMessage((HWND
)m_hWnd
, HDM_LAYOUT
, 0, (LPARAM
) &hdl
))
970 wxLogLastError(_T("SendMessage"));
974 // Set the size, position, and visibility of the header control.
975 SetWindowPos((HWND
)m_hWnd
,
979 wp
.flags
| SWP_SHOWWINDOW
);
981 // set our size hints: wxDataViewCtrl will put this wxWindow inside
982 // a wxBoxSizer and in order to avoid super-big header windows,
983 // we need to set our height as fixed
984 SetMinSize(wxSize(-1, wp
.cy
));
985 SetMaxSize(wxSize(-1, wp
.cy
));
990 wxDataViewHeaderWindowMSW::~wxDataViewHeaderWindow()
995 void wxDataViewHeaderWindowMSW::UpdateDisplay()
997 // remove old columns
998 for (int j
=0, max
=Header_GetItemCount((HWND
)m_hWnd
); j
< max
; j
++)
999 Header_DeleteItem((HWND
)m_hWnd
, 0);
1001 // add the updated array of columns to the header control
1002 unsigned int cols
= GetOwner()->GetColumnCount();
1003 unsigned int added
= 0;
1004 for (unsigned int i
= 0; i
< cols
; i
++)
1006 wxDataViewColumn
*col
= GetColumn( i
);
1007 if (col
->IsHidden())
1008 continue; // don't add it!
1011 hdi
.mask
= HDI_TEXT
| HDI_FORMAT
| HDI_WIDTH
;
1012 hdi
.pszText
= (wxChar
*) col
->GetTitle().wx_str();
1013 hdi
.cxy
= col
->GetWidth();
1014 hdi
.cchTextMax
= sizeof(hdi
.pszText
)/sizeof(hdi
.pszText
[0]);
1015 hdi
.fmt
= HDF_LEFT
| HDF_STRING
;
1017 // lParam is reserved for application's use:
1018 // we store there the column index to use it later in MSWOnNotify
1019 // (since columns may have been hidden)
1020 hdi
.lParam
= (LPARAM
)i
;
1022 // the native wxMSW implementation of the header window
1023 // draws the column separator COLUMN_WIDTH_OFFSET pixels
1024 // on the right: to correct this effect we make the column
1025 // exactly COLUMN_WIDTH_OFFSET wider (for the first column):
1027 hdi
.cxy
+= COLUMN_WIDTH_OFFSET
;
1029 switch (col
->GetAlignment())
1032 hdi
.fmt
|= HDF_LEFT
;
1034 case wxALIGN_CENTER
:
1035 case wxALIGN_CENTER_HORIZONTAL
:
1036 hdi
.fmt
|= HDF_CENTER
;
1039 hdi
.fmt
|= HDF_RIGHT
;
1043 // such alignment is not allowed for the column header!
1047 SendMessage((HWND
)m_hWnd
, HDM_INSERTITEM
,
1048 (WPARAM
)added
, (LPARAM
)&hdi
);
1053 unsigned int wxDataViewHeaderWindowMSW::GetColumnIdxFromHeader(NMHEADER
*nmHDR
)
1057 // NOTE: we don't just return nmHDR->iItem because when there are
1058 // hidden columns, nmHDR->iItem may be different from
1059 // nmHDR->pitem->lParam
1061 if (nmHDR
->pitem
&& nmHDR
->pitem
->mask
& HDI_LPARAM
)
1063 idx
= (unsigned int)nmHDR
->pitem
->lParam
;
1068 item
.mask
= HDI_LPARAM
;
1069 Header_GetItem((HWND
)m_hWnd
, nmHDR
->iItem
, &item
);
1071 return (unsigned int)item
.lParam
;
1074 bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1076 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1078 // is it a message from the header?
1079 if ( nmhdr
->hwndFrom
!= (HWND
)m_hWnd
)
1080 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
1082 NMHEADER
*nmHDR
= (NMHEADER
*)nmhdr
;
1083 switch ( nmhdr
->code
)
1085 case HDN_BEGINTRACK
:
1086 // user has started to resize a column:
1087 // do we need to veto it?
1088 if (!GetColumn(nmHDR
->iItem
)->IsResizeable())
1096 // user has started to reorder a column
1099 case HDN_ITEMCHANGING
:
1100 if (nmHDR
->pitem
!= NULL
&&
1101 (nmHDR
->pitem
->mask
& HDI_WIDTH
) != 0)
1103 int minWidth
= GetColumnFromHeader(nmHDR
)->GetMinWidth();
1104 if (nmHDR
->pitem
->cxy
< minWidth
)
1106 // do not allow the user to resize this column under
1107 // its minimal width:
1113 case HDN_ITEMCHANGED
: // user is resizing a column
1114 case HDN_ENDTRACK
: // user has finished resizing a column
1115 case HDN_ENDDRAG
: // user has finished reordering a column
1117 // update the width of the modified column:
1118 if (nmHDR
->pitem
!= NULL
&&
1119 (nmHDR
->pitem
->mask
& HDI_WIDTH
) != 0)
1121 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1122 unsigned int w
= nmHDR
->pitem
->cxy
;
1123 wxDataViewColumn
*col
= GetColumn(idx
);
1125 // see UpdateDisplay() for more info about COLUMN_WIDTH_OFFSET
1126 if (idx
== 0 && w
> COLUMN_WIDTH_OFFSET
)
1127 w
-= COLUMN_WIDTH_OFFSET
;
1129 if (w
>= (unsigned)col
->GetMinWidth())
1130 col
->SetInternalWidth(w
);
1136 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1137 wxEventType evt
= nmHDR
->iButton
== 0 ?
1138 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
:
1139 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
;
1140 SendEvent(evt
, idx
);
1146 // NOTE: for some reason (i.e. for a bug in Windows)
1147 // the HDN_ITEMCLICK notification is not sent on
1148 // right clicks, so we need to handle NM_RCLICK
1151 int column
= wxMSWGetColumnClicked(nmhdr
, &ptClick
);
1152 if (column
!= wxNOT_FOUND
)
1155 item
.mask
= HDI_LPARAM
;
1156 Header_GetItem((HWND
)m_hWnd
, column
, &item
);
1158 // 'idx' may be different from 'column' if there are
1159 // hidden columns...
1160 unsigned int idx
= (unsigned int)item
.lParam
;
1161 SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
1167 case HDN_GETDISPINFOW
:
1168 // see wxListCtrl::MSWOnNotify for more info!
1171 case HDN_ITEMDBLCLICK
:
1173 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1174 int w
= GetOwner()->GetBestColumnWidth(idx
);
1176 // update the native control:
1178 ZeroMemory(&hd
, sizeof(hd
));
1179 hd
.mask
= HDI_WIDTH
;
1181 Header_SetItem(GetHwnd(),
1182 nmHDR
->iItem
, // NOTE: we don't want 'idx' here!
1185 // update the wxDataViewColumn class:
1186 GetColumn(idx
)->SetInternalWidth(w
);
1191 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
1197 void wxDataViewHeaderWindowMSW::ScrollWindow(int WXUNUSED(dx
), int WXUNUSED(dy
),
1198 const wxRect
*WXUNUSED(rect
))
1200 wxSize ourSz
= GetClientSize();
1201 wxSize ownerSz
= m_owner
->GetClientSize();
1203 // where should the (logical) origin of this window be placed?
1205 m_owner
->CalcUnscrolledPosition(0, 0, &x1
, &y1
);
1207 // put this window on top of our parent and
1208 SetWindowPos((HWND
)m_hWnd
, HWND_TOP
, -x1
, 0,
1209 ownerSz
.GetWidth() + x1
, ourSz
.GetHeight(),
1213 void wxDataViewHeaderWindowMSW::DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
1214 int WXUNUSED(w
), int WXUNUSED(h
),
1217 // the wxDataViewCtrl's internal wxBoxSizer will call this function when
1218 // the wxDataViewCtrl window gets resized: the following dummy call
1219 // to ScrollWindow() is required in order to get this header window
1220 // correctly repainted when it's (horizontally) scrolled:
1225 #else // !defined(__WXMSW__)
1227 IMPLEMENT_ABSTRACT_CLASS(wxGenericDataViewHeaderWindow
, wxWindow
)
1228 BEGIN_EVENT_TABLE(wxGenericDataViewHeaderWindow
, wxWindow
)
1229 EVT_PAINT (wxGenericDataViewHeaderWindow::OnPaint
)
1230 EVT_MOUSE_EVENTS (wxGenericDataViewHeaderWindow::OnMouse
)
1231 EVT_SET_FOCUS (wxGenericDataViewHeaderWindow::OnSetFocus
)
1234 bool wxGenericDataViewHeaderWindow::Create(wxDataViewCtrl
*parent
, wxWindowID id
,
1235 const wxPoint
&pos
, const wxSize
&size
,
1236 const wxString
&name
)
1240 if (!wxDataViewHeaderWindowBase::Create(parent
, id
, pos
, size
, name
))
1243 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1244 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1245 SetOwnForegroundColour( attr
.colFg
);
1246 SetOwnBackgroundColour( attr
.colBg
);
1248 SetOwnFont( attr
.font
);
1250 // set our size hints: wxDataViewCtrl will put this wxWindow inside
1251 // a wxBoxSizer and in order to avoid super-big header windows,
1252 // we need to set our height as fixed
1253 SetMinSize(wxSize(-1, HEADER_WINDOW_HEIGHT
));
1254 SetMaxSize(wxSize(-1, HEADER_WINDOW_HEIGHT
));
1259 void wxGenericDataViewHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1262 GetClientSize( &w
, &h
);
1264 wxAutoBufferedPaintDC
dc( this );
1266 dc
.SetBackground(GetBackgroundColour());
1270 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1273 m_owner
->GetViewStart( &x
, NULL
);
1275 // account for the horz scrollbar offset
1276 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1278 dc
.SetFont( GetFont() );
1280 unsigned int cols
= GetOwner()->GetColumnCount();
1283 for (i
= 0; i
< cols
; i
++)
1285 wxDataViewColumn
*col
= GetColumn( i
);
1286 if (col
->IsHidden())
1287 continue; // skip it!
1289 int cw
= col
->GetWidth();
1292 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
;
1293 if (col
->IsSortable())
1295 if (col
->IsSortOrderAscending())
1296 sortArrow
= wxHDR_SORT_ICON_UP
;
1298 sortArrow
= wxHDR_SORT_ICON_DOWN
;
1301 wxRendererNative::Get().DrawHeaderButton
1305 wxRect(xpos
, 0, cw
, ch
-1),
1306 m_parent
->IsEnabled() ? 0
1307 : (int)wxCONTROL_DISABLED
,
1311 // align as required the column title:
1313 wxSize titleSz
= dc
.GetTextExtent(col
->GetTitle());
1314 switch (col
->GetAlignment())
1317 x
+= HEADER_HORIZ_BORDER
;
1319 case wxALIGN_CENTER
:
1320 case wxALIGN_CENTER_HORIZONTAL
:
1321 x
+= (cw
- titleSz
.GetWidth() - 2 * HEADER_HORIZ_BORDER
)/2;
1324 x
+= cw
- titleSz
.GetWidth() - HEADER_HORIZ_BORDER
;
1328 // always center the title vertically:
1329 int y
= wxMax((ch
- titleSz
.GetHeight()) / 2, HEADER_VERT_BORDER
);
1331 dc
.SetClippingRegion( xpos
+HEADER_HORIZ_BORDER
,
1333 wxMax(cw
- 2 * HEADER_HORIZ_BORDER
, 1), // width
1334 wxMax(ch
- 2 * HEADER_VERT_BORDER
, 1)); // height
1335 dc
.DrawText( col
->GetTitle(), x
, y
);
1336 dc
.DestroyClippingRegion();
1342 void wxGenericDataViewHeaderWindow::OnSetFocus( wxFocusEvent
&event
)
1344 GetParent()->SetFocus();
1348 void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent
&event
)
1350 // we want to work with logical coords
1352 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1353 int y
= event
.GetY();
1357 // we don't draw the line beyond our window,
1358 // but we allow dragging it there
1360 GetClientSize( &w
, NULL
);
1361 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1364 // erase the line if it was drawn
1368 if (event
.ButtonUp())
1370 m_isDragging
= false;
1376 GetColumn(m_column
)->SetWidth(m_currentX
- m_minX
);
1379 GetOwner()->Refresh();
1383 m_currentX
= wxMax(m_minX
+ 7, x
);
1385 // draw in the new location
1386 if (m_currentX
< w
) DrawCurrent();
1390 else // not dragging
1393 m_column
= wxNOT_FOUND
;
1395 bool hit_border
= false;
1397 // end of the current column
1400 // find the column where this event occured
1401 int countCol
= m_owner
->GetColumnCount();
1402 for (int column
= 0; column
< countCol
; column
++)
1404 wxDataViewColumn
*p
= GetColumn(column
);
1407 continue; // skip if not shown
1409 xpos
+= p
->GetWidth();
1411 if ((abs(x
-xpos
) < 3) && (y
< 22))
1419 // inside the column
1426 if (m_column
== wxNOT_FOUND
)
1429 bool resizeable
= GetColumn(m_column
)->IsResizeable();
1430 if (event
.LeftDClick() && resizeable
)
1432 GetColumn(m_column
)->SetWidth(GetOwner()->GetBestColumnWidth(m_column
));
1435 else if (event
.LeftDown() || event
.RightUp())
1437 if (hit_border
&& event
.LeftDown() && resizeable
)
1439 m_isDragging
= true;
1444 else // click on a column
1446 wxEventType evt
= event
.LeftDown() ?
1447 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
:
1448 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
;
1449 SendEvent(evt
, m_column
);
1452 else if (event
.Moving())
1454 if (hit_border
&& resizeable
)
1455 m_currentCursor
= m_resizeCursor
;
1457 m_currentCursor
= wxSTANDARD_CURSOR
;
1459 SetCursor(*m_currentCursor
);
1464 void wxGenericDataViewHeaderWindow::DrawCurrent()
1466 int x1
= m_currentX
;
1468 ClientToScreen (&x1
, &y1
);
1470 int x2
= m_currentX
-1;
1472 ++x2
; // but why ????
1475 m_owner
->GetClientSize( NULL
, &y2
);
1476 m_owner
->ClientToScreen( &x2
, &y2
);
1479 dc
.SetLogicalFunction(wxINVERT
);
1480 dc
.SetPen(m_penCurrent
);
1481 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1483 dc
.DrawLine(x1
, y1
, x2
, y2
);
1486 void wxGenericDataViewHeaderWindow::AdjustDC(wxDC
& dc
)
1490 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1491 m_owner
->GetViewStart( &x
, NULL
);
1493 // shift the DC origin to match the position of the main window horizontal
1494 // scrollbar: this allows us to always use logical coords
1495 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1498 #endif // defined(__WXMSW__)
1500 //-----------------------------------------------------------------------------
1501 // wxDataViewRenameTimer
1502 //-----------------------------------------------------------------------------
1504 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1509 void wxDataViewRenameTimer::Notify()
1511 m_owner
->OnRenameTimer();
1514 //-----------------------------------------------------------------------------
1515 // wxDataViewMainWindow
1516 //-----------------------------------------------------------------------------
1518 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1520 if (row1
> row2
) return 1;
1521 if (row1
== row2
) return 0;
1526 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1528 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1529 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1530 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1531 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1532 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1533 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1536 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1537 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1538 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
, name
),
1539 m_selection( wxDataViewSelectionCmp
)
1544 m_lastOnSame
= false;
1545 m_renameTimer
= new wxDataViewRenameTimer( this );
1547 // TODO: user better initial values/nothing selected
1548 m_currentCol
= NULL
;
1551 // TODO: we need to calculate this smartly
1558 wxASSERT(m_lineHeight
> 2*PADDING_TOPBOTTOM
);
1561 m_dragStart
= wxPoint(0,0);
1562 m_lineLastClicked
= (unsigned int) -1;
1563 m_lineBeforeLastClicked
= (unsigned int) -1;
1564 m_lineSelectSingleOnUp
= (unsigned int) -1;
1568 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1569 SetBackgroundColour( *wxWHITE
);
1571 m_penRule
= wxPen(GetRuleColour(), 1, wxSOLID
);
1576 wxDataViewMainWindow::~wxDataViewMainWindow()
1578 delete m_renameTimer
;
1581 void wxDataViewMainWindow::OnRenameTimer()
1583 // We have to call this here because changes may just have
1584 // been made and no screen update taken place.
1589 unsigned int cols
= GetOwner()->GetColumnCount();
1591 for (i
= 0; i
< cols
; i
++)
1593 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
1595 continue; // skip it!
1597 if (c
== m_currentCol
)
1599 xpos
+= c
->GetWidth();
1601 wxRect
labelRect( xpos
, m_currentRow
* m_lineHeight
,
1602 m_currentCol
->GetWidth(), m_lineHeight
);
1604 GetOwner()->CalcScrolledPosition( labelRect
.x
, labelRect
.y
,
1605 &labelRect
.x
, &labelRect
.y
);
1607 m_currentCol
->GetRenderer()->StartEditing( m_currentRow
, labelRect
);
1610 bool wxDataViewMainWindow::RowAppended()
1616 bool wxDataViewMainWindow::RowPrepended()
1622 bool wxDataViewMainWindow::RowInserted( unsigned int WXUNUSED(before
) )
1628 bool wxDataViewMainWindow::RowDeleted( unsigned int WXUNUSED(row
) )
1634 bool wxDataViewMainWindow::RowChanged( unsigned int WXUNUSED(row
) )
1640 bool wxDataViewMainWindow::ValueChanged( unsigned int WXUNUSED(col
), unsigned int row
)
1642 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
1643 #define MAX_VIRTUAL_WIDTH 100000
1645 wxRect
rect( 0, row
*m_lineHeight
, MAX_VIRTUAL_WIDTH
, m_lineHeight
);
1646 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1647 Refresh( true, &rect
);
1652 bool wxDataViewMainWindow::RowsReordered( unsigned int *WXUNUSED(new_order
) )
1658 bool wxDataViewMainWindow::Cleared()
1664 void wxDataViewMainWindow::UpdateDisplay()
1669 void wxDataViewMainWindow::OnInternalIdle()
1671 wxWindow::OnInternalIdle();
1675 RecalculateDisplay();
1680 void wxDataViewMainWindow::RecalculateDisplay()
1682 wxDataViewListModel
*model
= GetOwner()->GetModel();
1689 int width
= GetEndOfLastCol();
1690 int height
= model
->GetRowCount() * m_lineHeight
;
1692 SetVirtualSize( width
, height
);
1693 GetOwner()->SetScrollRate( 10, m_lineHeight
);
1698 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
1700 wxWindow::ScrollWindow( dx
, dy
, rect
);
1702 if (GetOwner()->m_headerArea
)
1703 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
1706 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1708 wxDataViewListModel
*model
= GetOwner()->GetModel();
1709 wxAutoBufferedPaintDC
dc( this );
1712 dc
.SetBackground(GetBackgroundColour());
1714 GetOwner()->PrepareDC( dc
);
1715 dc
.SetFont( GetFont() );
1717 wxRect update
= GetUpdateRegion().GetBox();
1718 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1720 // compute which items needs to be redrawn
1721 unsigned int item_start
= wxMax( 0, (update
.y
/ m_lineHeight
) );
1722 unsigned int item_count
=
1723 wxMin( (int)(((update
.y
+ update
.height
) / m_lineHeight
) - item_start
+ 1),
1724 (int)(model
->GetRowCount() - item_start
) );
1725 unsigned int item_last
= item_start
+ item_count
;
1727 // compute which columns needs to be redrawn
1728 unsigned int cols
= GetOwner()->GetColumnCount();
1729 unsigned int col_start
= 0;
1730 unsigned int x_start
= 0;
1731 for (x_start
= 0; col_start
< cols
; col_start
++)
1733 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_start
);
1734 if (col
->IsHidden())
1735 continue; // skip it!
1737 unsigned int w
= col
->GetWidth();
1738 if (x_start
+w
>= (unsigned int)update
.x
)
1744 unsigned int col_last
= col_start
;
1745 unsigned int x_last
= x_start
;
1746 for (; col_last
< cols
; col_last
++)
1748 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_last
);
1749 if (col
->IsHidden())
1750 continue; // skip it!
1752 if (x_last
> (unsigned int)update
.GetRight())
1755 x_last
+= col
->GetWidth();
1758 // Draw horizontal rules if required
1759 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1761 dc
.SetPen(m_penRule
);
1762 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1764 for (unsigned int i
= item_start
; i
<= item_last
+1; i
++)
1766 int y
= i
* m_lineHeight
;
1767 dc
.DrawLine(x_start
, y
, x_last
, y
);
1771 // Draw vertical rules if required
1772 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1774 dc
.SetPen(m_penRule
);
1775 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1778 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1780 wxDataViewColumn
*col
= GetOwner()->GetColumn(i
);
1781 if (col
->IsHidden())
1782 continue; // skip it
1784 dc
.DrawLine(x
, item_start
* m_lineHeight
,
1785 x
, item_last
* m_lineHeight
);
1787 x
+= col
->GetWidth();
1790 // Draw last vertical rule
1791 dc
.DrawLine(x
, item_start
* m_lineHeight
,
1792 x
, item_last
* m_lineHeight
);
1795 // redraw the background for the items which are selected/current
1796 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1798 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1799 if (selected
|| item
== m_currentRow
)
1801 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
1802 if (item
== m_currentRow
)
1803 flags
|= wxCONTROL_CURRENT
;
1805 flags
|= wxCONTROL_FOCUSED
;
1807 wxRect
rect( x_start
, item
*m_lineHeight
, x_last
, m_lineHeight
);
1808 wxRendererNative::Get().DrawItemSelectionRect
1818 // redraw all cells for all rows which must be repainted and for all columns
1820 cell_rect
.x
= x_start
;
1821 cell_rect
.height
= m_lineHeight
; // -1 is for the horizontal rules
1822 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1824 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
1825 wxDataViewRenderer
*cell
= col
->GetRenderer();
1826 cell_rect
.width
= col
->GetWidth();
1828 if (col
->IsHidden())
1829 continue; // skipt it!
1831 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1833 // get the cell value and set it into the renderer
1835 model
->GetValue( value
, col
->GetModelColumn(), item
);
1836 cell
->SetValue( value
);
1838 // update the y offset
1839 cell_rect
.y
= item
* m_lineHeight
;
1841 // cannot be bigger than allocated space
1842 wxSize size
= cell
->GetSize();
1843 size
.x
= wxMin( size
.x
+ 2*PADDING_RIGHTLEFT
, cell_rect
.width
);
1844 size
.y
= wxMin( size
.y
+ 2*PADDING_TOPBOTTOM
, cell_rect
.height
);
1846 wxRect
item_rect(cell_rect
.GetTopLeft(), size
);
1847 int align
= cell
->GetAlignment();
1849 // horizontal alignment:
1850 item_rect
.x
= cell_rect
.x
;
1851 if (align
& wxALIGN_CENTER_HORIZONTAL
)
1852 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
1853 else if (align
& wxALIGN_RIGHT
)
1854 item_rect
.x
= cell_rect
.x
+ cell_rect
.width
- size
.x
;
1855 //else: wxALIGN_LEFT is the default
1857 // vertical alignment:
1858 item_rect
.y
= cell_rect
.y
;
1859 if (align
& wxALIGN_CENTER_VERTICAL
)
1860 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
1861 else if (align
& wxALIGN_BOTTOM
)
1862 item_rect
.y
= cell_rect
.y
+ cell_rect
.height
- size
.y
;
1863 //else: wxALIGN_TOP is the default
1866 item_rect
.x
+= PADDING_RIGHTLEFT
;
1867 item_rect
.y
+= PADDING_TOPBOTTOM
;
1868 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
1869 item_rect
.height
= size
.y
- 2 * PADDING_TOPBOTTOM
;
1872 if (m_selection
.Index(item
) != wxNOT_FOUND
)
1873 state
|= wxDATAVIEW_CELL_SELECTED
;
1875 // TODO: it would be much more efficient to create a clipping
1876 // region for the entire column being rendered (in the OnPaint
1877 // of wxDataViewMainWindow) instead of a single clip region for
1878 // each cell. However it would mean that each renderer should
1879 // respect the given wxRect's top & bottom coords, eventually
1880 // violating only the left & right coords - however the user can
1881 // make its own renderer and thus we cannot be sure of that.
1882 dc
.SetClippingRegion( item_rect
);
1883 cell
->Render( item_rect
, &dc
, state
);
1884 dc
.DestroyClippingRegion();
1887 cell_rect
.x
+= cell_rect
.width
;
1891 int wxDataViewMainWindow::GetCountPerPage() const
1893 wxSize size
= GetClientSize();
1894 return size
.y
/ m_lineHeight
;
1897 int wxDataViewMainWindow::GetEndOfLastCol() const
1901 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
1903 const wxDataViewColumn
*c
=
1904 wx_const_cast(wxDataViewCtrl
*, GetOwner())->GetColumn( i
);
1907 width
+= c
->GetWidth();
1912 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
1916 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
1918 return y
/ m_lineHeight
;
1921 unsigned int wxDataViewMainWindow::GetLastVisibleRow() const
1923 wxSize client_size
= GetClientSize();
1924 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
1925 &client_size
.x
, &client_size
.y
);
1927 return wxMin( GetRowCount()-1, ((unsigned)client_size
.y
/m_lineHeight
)+1 );
1930 unsigned int wxDataViewMainWindow::GetRowCount() const
1932 return wx_const_cast(wxDataViewCtrl
*, GetOwner())->GetModel()->GetRowCount();
1935 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
1942 void wxDataViewMainWindow::SelectAllRows( bool on
)
1949 m_selection
.Clear();
1950 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
1951 m_selection
.Add( i
);
1956 unsigned int first_visible
= GetFirstVisibleRow();
1957 unsigned int last_visible
= GetLastVisibleRow();
1959 for (i
= 0; i
< m_selection
.GetCount(); i
++)
1961 unsigned int row
= m_selection
[i
];
1962 if ((row
>= first_visible
) && (row
<= last_visible
))
1965 m_selection
.Clear();
1969 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
1971 if (m_selection
.Index( row
) == wxNOT_FOUND
)
1975 m_selection
.Add( row
);
1983 m_selection
.Remove( row
);
1989 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
1993 unsigned int tmp
= from
;
1999 for (i
= from
; i
<= to
; i
++)
2001 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2004 m_selection
.Add( i
);
2009 m_selection
.Remove( i
);
2012 RefreshRows( from
, to
);
2015 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2017 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2019 int n
= aSelections
[i
];
2021 m_selection
.Add( n
);
2026 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2028 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2029 m_selection
.Add( row
);
2031 m_selection
.Remove( row
);
2035 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2037 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2040 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2042 wxRect
rect( 0, row
*m_lineHeight
, GetEndOfLastCol(), m_lineHeight
);
2043 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2045 wxSize client_size
= GetClientSize();
2046 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2047 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2048 if (intersect_rect
.width
> 0)
2049 Refresh( true, &intersect_rect
);
2052 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2056 unsigned int tmp
= to
;
2061 wxRect
rect( 0, from
*m_lineHeight
, GetEndOfLastCol(), (to
-from
+1) * m_lineHeight
);
2062 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2064 wxSize client_size
= GetClientSize();
2065 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2066 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2067 if (intersect_rect
.width
> 0)
2068 Refresh( true, &intersect_rect
);
2071 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2073 unsigned int count
= GetRowCount();
2074 if (firstRow
> count
)
2077 wxRect
rect( 0, firstRow
*m_lineHeight
, GetEndOfLastCol(), count
* m_lineHeight
);
2078 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2080 wxSize client_size
= GetClientSize();
2081 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2082 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2083 if (intersect_rect
.width
> 0)
2084 Refresh( true, &intersect_rect
);
2087 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2089 wxCHECK_RET( newCurrent
< GetRowCount(),
2090 _T("invalid item index in OnArrowChar()") );
2092 // if there is no selection, we cannot move it anywhere
2093 if (!HasCurrentRow())
2096 unsigned int oldCurrent
= m_currentRow
;
2098 // in single selection we just ignore Shift as we can't select several
2100 if ( event
.ShiftDown() && !IsSingleSel() )
2102 RefreshRow( oldCurrent
);
2104 ChangeCurrentRow( newCurrent
);
2106 // select all the items between the old and the new one
2107 if ( oldCurrent
> newCurrent
)
2109 newCurrent
= oldCurrent
;
2110 oldCurrent
= m_currentRow
;
2113 SelectRows( oldCurrent
, newCurrent
, true );
2117 RefreshRow( oldCurrent
);
2119 // all previously selected items are unselected unless ctrl is held
2120 if ( !event
.ControlDown() )
2121 SelectAllRows(false);
2123 ChangeCurrentRow( newCurrent
);
2125 if ( !event
.ControlDown() )
2126 SelectRow( m_currentRow
, true );
2128 RefreshRow( m_currentRow
);
2131 //EnsureVisible( m_currentRow );
2134 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2138 rect
.y
= m_lineHeight
* row
;
2139 rect
.width
= GetEndOfLastCol();
2140 rect
.height
= m_lineHeight
;
2145 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
2147 if (event
.GetKeyCode() == WXK_TAB
)
2149 wxNavigationKeyEvent nevent
;
2150 nevent
.SetWindowChange( event
.ControlDown() );
2151 nevent
.SetDirection( !event
.ShiftDown() );
2152 nevent
.SetEventObject( GetParent()->GetParent() );
2153 nevent
.SetCurrentFocus( m_parent
);
2154 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
2158 // no item -> nothing to do
2159 if (!HasCurrentRow())
2165 // don't use m_linesPerPage directly as it might not be computed yet
2166 const int pageSize
= GetCountPerPage();
2167 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
2169 switch ( event
.GetKeyCode() )
2172 if ( m_currentRow
> 0 )
2173 OnArrowChar( m_currentRow
- 1, event
);
2177 if ( m_currentRow
< GetRowCount() - 1 )
2178 OnArrowChar( m_currentRow
+ 1, event
);
2183 OnArrowChar( GetRowCount() - 1, event
);
2188 OnArrowChar( 0, event
);
2193 int steps
= pageSize
- 1;
2194 int index
= m_currentRow
- steps
;
2198 OnArrowChar( index
, event
);
2204 int steps
= pageSize
- 1;
2205 unsigned int index
= m_currentRow
+ steps
;
2206 unsigned int count
= GetRowCount();
2207 if ( index
>= count
)
2210 OnArrowChar( index
, event
);
2219 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
2221 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2223 // let the base handle mouse wheel events.
2228 int x
= event
.GetX();
2229 int y
= event
.GetY();
2230 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2232 wxDataViewColumn
*col
= NULL
;
2235 unsigned int cols
= GetOwner()->GetColumnCount();
2237 for (i
= 0; i
< cols
; i
++)
2239 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
2241 continue; // skip it!
2243 if (x
< xpos
+ c
->GetWidth())
2248 xpos
+= c
->GetWidth();
2252 wxDataViewRenderer
*cell
= col
->GetRenderer();
2254 unsigned int current
= y
/ m_lineHeight
;
2256 if ((current
> GetRowCount()) || (x
> GetEndOfLastCol()))
2258 // Unselect all if below the last row ?
2262 wxDataViewListModel
*model
= GetOwner()->GetModel();
2264 if (event
.Dragging())
2266 if (m_dragCount
== 0)
2268 // we have to report the raw, physical coords as we want to be
2269 // able to call HitTest(event.m_pointDrag) from the user code to
2270 // get the item being dragged
2271 m_dragStart
= event
.GetPosition();
2276 if (m_dragCount
!= 3)
2279 if (event
.LeftIsDown())
2281 // Notify cell about drag
2290 bool forceClick
= false;
2292 if (event
.ButtonDClick())
2294 m_renameTimer
->Stop();
2295 m_lastOnSame
= false;
2298 if (event
.LeftDClick())
2300 if ( current
== m_lineLastClicked
)
2302 if (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
)
2305 model
->GetValue( value
, col
->GetModelColumn(), current
);
2306 cell
->SetValue( value
);
2307 wxRect
cell_rect( xpos
, current
* m_lineHeight
,
2308 col
->GetWidth(), m_lineHeight
);
2309 cell
->Activate( cell_rect
, model
, col
->GetModelColumn(), current
);
2315 // The first click was on another item, so don't interpret this as
2316 // a double click, but as a simple click instead
2323 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
2325 // select single line
2326 SelectAllRows( false );
2327 SelectRow( m_lineSelectSingleOnUp
, true );
2332 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
2333 (cell
->GetMode() == wxDATAVIEW_CELL_EDITABLE
) )
2335 m_renameTimer
->Start( 100, true );
2339 m_lastOnSame
= false;
2340 m_lineSelectSingleOnUp
= (unsigned int)-1;
2344 // This is necessary, because after a DnD operation in
2345 // from and to ourself, the up event is swallowed by the
2346 // DnD code. So on next non-up event (which means here and
2347 // now) m_lineSelectSingleOnUp should be reset.
2348 m_lineSelectSingleOnUp
= (unsigned int)-1;
2351 if (event
.RightDown())
2353 m_lineBeforeLastClicked
= m_lineLastClicked
;
2354 m_lineLastClicked
= current
;
2356 // If the item is already selected, do not update the selection.
2357 // Multi-selections should not be cleared if a selected item is clicked.
2358 if (!IsRowSelected(current
))
2360 SelectAllRows(false);
2361 ChangeCurrentRow(current
);
2362 SelectRow(m_currentRow
,true);
2365 // notify cell about right click
2368 // Allow generation of context menu event
2371 else if (event
.MiddleDown())
2373 // notify cell about middle click
2376 if (event
.LeftDown() || forceClick
)
2382 m_lineBeforeLastClicked
= m_lineLastClicked
;
2383 m_lineLastClicked
= current
;
2385 unsigned int oldCurrentRow
= m_currentRow
;
2386 bool oldWasSelected
= IsRowSelected(m_currentRow
);
2388 bool cmdModifierDown
= event
.CmdDown();
2389 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
2391 if ( IsSingleSel() || !IsRowSelected(current
) )
2393 SelectAllRows( false );
2395 ChangeCurrentRow(current
);
2397 SelectRow(m_currentRow
,true);
2399 else // multi sel & current is highlighted & no mod keys
2401 m_lineSelectSingleOnUp
= current
;
2402 ChangeCurrentRow(current
); // change focus
2405 else // multi sel & either ctrl or shift is down
2407 if (cmdModifierDown
)
2409 ChangeCurrentRow(current
);
2411 ReverseRowSelection(m_currentRow
);
2413 else if (event
.ShiftDown())
2415 ChangeCurrentRow(current
);
2417 unsigned int lineFrom
= oldCurrentRow
,
2420 if ( lineTo
< lineFrom
)
2423 lineFrom
= m_currentRow
;
2426 SelectRows(lineFrom
, lineTo
, true);
2428 else // !ctrl, !shift
2430 // test in the enclosing if should make it impossible
2431 wxFAIL_MSG( _T("how did we get here?") );
2435 if (m_currentRow
!= oldCurrentRow
)
2436 RefreshRow( oldCurrentRow
);
2438 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
2440 // Update selection here...
2443 m_lastOnSame
= !forceClick
&& ((col
== oldCurrentCol
) &&
2444 (current
== oldCurrentRow
)) && oldWasSelected
;
2448 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
2452 if (HasCurrentRow())
2458 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
2462 if (HasCurrentRow())
2468 //-----------------------------------------------------------------------------
2470 //-----------------------------------------------------------------------------
2472 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
2474 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
2475 EVT_SIZE(wxDataViewCtrl::OnSize
)
2478 wxDataViewCtrl::~wxDataViewCtrl()
2481 GetModel()->RemoveNotifier( m_notifier
);
2484 void wxDataViewCtrl::Init()
2489 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
2490 const wxPoint
& pos
, const wxSize
& size
,
2491 long style
, const wxValidator
& validator
)
2493 if (!wxControl::Create( parent
, id
, pos
, size
,
2494 style
| wxScrolledWindowStyle
|wxSUNKEN_BORDER
, validator
))
2500 MacSetClipChildren( true ) ;
2503 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
2505 if (HasFlag(wxDV_NO_HEADER
))
2506 m_headerArea
= NULL
;
2508 m_headerArea
= new wxDataViewHeaderWindow( this, wxID_ANY
);
2510 SetTargetWindow( m_clientArea
);
2512 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
2514 sizer
->Add( m_headerArea
, 0, wxGROW
);
2515 sizer
->Add( m_clientArea
, 1, wxGROW
);
2522 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
2526 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
2529 // we need to process arrows ourselves for scrolling
2530 if ( nMsg
== WM_GETDLGCODE
)
2532 rc
|= DLGC_WANTARROWS
;
2540 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2542 // We need to override OnSize so that our scrolled
2543 // window a) does call Layout() to use sizers for
2544 // positioning the controls but b) does not query
2545 // the sizer for their size and use that for setting
2546 // the scrollable area as set that ourselves by
2547 // calling SetScrollbar() further down.
2554 bool wxDataViewCtrl::AssociateModel( wxDataViewListModel
*model
)
2556 if (!wxDataViewCtrlBase::AssociateModel( model
))
2559 m_notifier
= new wxGenericDataViewListModelNotifier( m_clientArea
);
2561 model
->AddNotifier( m_notifier
);
2563 m_clientArea
->UpdateDisplay();
2568 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
2570 if (!wxDataViewCtrlBase::AppendColumn(col
))
2577 void wxDataViewCtrl::OnColumnChange()
2580 m_headerArea
->UpdateDisplay();
2582 m_clientArea
->UpdateDisplay();
2585 void wxDataViewCtrl::SetSelection( int row
)
2587 m_clientArea
->SelectRow(row
, true);
2590 void wxDataViewCtrl::SetSelectionRange( unsigned int from
, unsigned int to
)
2592 m_clientArea
->SelectRows(from
, to
, true);
2595 void wxDataViewCtrl::SetSelections( const wxArrayInt
& aSelections
)
2597 m_clientArea
->Select(aSelections
);
2600 void wxDataViewCtrl::Unselect( unsigned int WXUNUSED(row
) )
2605 bool wxDataViewCtrl::IsSelected( unsigned int WXUNUSED(row
) ) const
2612 int wxDataViewCtrl::GetSelection() const
2619 int wxDataViewCtrl::GetSelections(wxArrayInt
& WXUNUSED(aSelections
) ) const
2627 // !wxUSE_GENERICDATAVIEWCTRL
2630 // wxUSE_DATAVIEWCTRL