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
;
181 void OnPaint( wxPaintEvent
&event
);
182 void OnMouse( wxMouseEvent
&event
);
183 void OnSetFocus( wxFocusEvent
&event
);
188 // vars used for column resizing:
190 wxCursor
*m_resizeCursor
;
191 const wxCursor
*m_currentCursor
;
194 bool m_dirty
; // needs refresh?
195 int m_column
; // index of the column being resized
196 int m_currentX
; // divider line position in logical (unscrolled) coords
197 int m_minX
; // minimal position beyond which the divider line
198 // can't be dragged in logical coords
200 // the pen used to draw the current column width drag line
201 // when resizing the columsn
205 // internal utilities:
209 m_currentCursor
= (wxCursor
*) NULL
;
210 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
212 m_isDragging
= false;
215 m_column
= wxNOT_FOUND
;
219 wxColour col
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
220 m_penCurrent
= wxPen(col
, 1, wxSOLID
);
224 void AdjustDC(wxDC
& dc
);
227 DECLARE_DYNAMIC_CLASS(wxGenericDataViewHeaderWindow
)
228 DECLARE_EVENT_TABLE()
231 #endif // defined(__WXMSW__)
233 //-----------------------------------------------------------------------------
234 // wxDataViewRenameTimer
235 //-----------------------------------------------------------------------------
237 class wxDataViewRenameTimer
: public wxTimer
240 wxDataViewMainWindow
*m_owner
;
243 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
247 //-----------------------------------------------------------------------------
248 // wxDataViewMainWindow
249 //-----------------------------------------------------------------------------
251 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
,
254 class wxDataViewMainWindow
: public wxWindow
257 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
259 const wxPoint
&pos
= wxDefaultPosition
,
260 const wxSize
&size
= wxDefaultSize
,
261 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
262 virtual ~wxDataViewMainWindow();
264 // notifications from wxDataViewListModel
267 bool RowInserted( unsigned int before
);
268 bool RowDeleted( unsigned int row
);
269 bool RowChanged( unsigned int row
);
270 bool ValueChanged( unsigned int col
, unsigned int row
);
271 bool RowsReordered( unsigned int *new_order
);
274 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
275 wxDataViewCtrl
*GetOwner() { return m_owner
; }
276 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
278 void OnPaint( wxPaintEvent
&event
);
279 void OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
);
280 void OnChar( wxKeyEvent
&event
);
281 void OnMouse( wxMouseEvent
&event
);
282 void OnSetFocus( wxFocusEvent
&event
);
283 void OnKillFocus( wxFocusEvent
&event
);
285 void UpdateDisplay();
286 void RecalculateDisplay();
287 void OnInternalIdle();
289 void OnRenameTimer();
291 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
293 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
294 void ChangeCurrentRow( unsigned int row
);
296 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
297 bool IsEmpty() { return GetRowCount() == 0; }
299 int GetCountPerPage() const;
300 int GetEndOfLastCol() const;
301 unsigned int GetFirstVisibleRow() const;
302 unsigned int GetLastVisibleRow() const;
303 unsigned int GetRowCount() const;
305 void Select( const wxArrayInt
& aSelections
);
306 void SelectAllRows( bool on
);
307 void SelectRow( unsigned int row
, bool on
);
308 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
309 void ReverseRowSelection( unsigned int row
);
310 bool IsRowSelected( unsigned int row
);
312 void RefreshRow( unsigned int row
);
313 void RefreshRows( unsigned int from
, unsigned int to
);
314 void RefreshRowsAfter( unsigned int firstRow
);
316 // returns the colour to be used for drawing the rules
317 wxColour
GetRuleColour() const
319 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
322 //void EnsureVisible( unsigned int row );
323 wxRect
GetLineRect( unsigned int row
) const;
326 wxDataViewCtrl
*m_owner
;
330 wxDataViewColumn
*m_currentCol
;
331 unsigned int m_currentRow
;
332 wxDataViewSelection m_selection
;
334 wxDataViewRenameTimer
*m_renameTimer
;
342 // for double click logic
343 unsigned int m_lineLastClicked
,
344 m_lineBeforeLastClicked
,
345 m_lineSelectSingleOnUp
;
347 // the pen used to draw horiz/vertical rules
351 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
352 DECLARE_EVENT_TABLE()
355 // ---------------------------------------------------------
356 // wxGenericDataViewListModelNotifier
357 // ---------------------------------------------------------
359 class wxGenericDataViewListModelNotifier
: public wxDataViewListModelNotifier
362 wxGenericDataViewListModelNotifier( wxDataViewMainWindow
*mainWindow
)
363 { m_mainWindow
= mainWindow
; }
365 virtual bool RowAppended()
366 { return m_mainWindow
->RowAppended(); }
367 virtual bool RowPrepended()
368 { return m_mainWindow
->RowPrepended(); }
369 virtual bool RowInserted( unsigned int before
)
370 { return m_mainWindow
->RowInserted( before
); }
371 virtual bool RowDeleted( unsigned int row
)
372 { return m_mainWindow
->RowDeleted( row
); }
373 virtual bool RowChanged( unsigned int row
)
374 { return m_mainWindow
->RowChanged( row
); }
375 virtual bool ValueChanged( unsigned int col
, unsigned int row
)
376 { return m_mainWindow
->ValueChanged( col
, row
); }
377 virtual bool RowsReordered( unsigned int *new_order
)
378 { return m_mainWindow
->RowsReordered( new_order
); }
379 virtual bool Cleared()
380 { return m_mainWindow
->Cleared(); }
382 wxDataViewMainWindow
*m_mainWindow
;
385 // ---------------------------------------------------------
386 // wxDataViewRenderer
387 // ---------------------------------------------------------
389 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
391 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
392 wxDataViewCellMode mode
,
394 wxDataViewRendererBase( varianttype
, mode
, align
)
401 wxDataViewRenderer::~wxDataViewRenderer()
407 wxDC
*wxDataViewRenderer::GetDC()
411 if (GetOwner() == NULL
)
413 if (GetOwner()->GetOwner() == NULL
)
415 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
421 // ---------------------------------------------------------
422 // wxDataViewCustomRenderer
423 // ---------------------------------------------------------
425 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
427 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
428 wxDataViewCellMode mode
, int align
) :
429 wxDataViewRenderer( varianttype
, mode
, align
)
433 // ---------------------------------------------------------
434 // wxDataViewTextRenderer
435 // ---------------------------------------------------------
437 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
439 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
440 wxDataViewCellMode mode
, int align
) :
441 wxDataViewCustomRenderer( varianttype
, mode
, align
)
445 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
447 m_text
= value
.GetString();
452 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
457 bool wxDataViewTextRenderer::HasEditorCtrl()
462 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
463 wxRect labelRect
, const wxVariant
&value
)
465 return new wxTextCtrl( parent
, wxID_ANY
, value
,
466 wxPoint(labelRect
.x
,labelRect
.y
),
467 wxSize(labelRect
.width
,labelRect
.height
) );
470 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
472 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
473 value
= text
->GetValue();
477 bool wxDataViewTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
479 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
480 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
481 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
482 view
->GetForegroundColour();
484 dc
->SetTextForeground(col
);
485 dc
->DrawText( m_text
, cell
.x
, cell
.y
);
490 wxSize
wxDataViewTextRenderer::GetSize() const
492 const wxDataViewCtrl
*view
= GetView();
496 view
->GetTextExtent( m_text
, &x
, &y
);
497 return wxSize( x
, y
);
499 return wxSize(80,20);
502 // ---------------------------------------------------------
503 // wxDataViewBitmapRenderer
504 // ---------------------------------------------------------
506 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
508 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
509 wxDataViewCellMode mode
, int align
) :
510 wxDataViewCustomRenderer( varianttype
, mode
, align
)
514 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
516 if (value
.GetType() == wxT("wxBitmap"))
518 if (value
.GetType() == wxT("wxIcon"))
524 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
529 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
532 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
533 else if (m_icon
.Ok())
534 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
539 wxSize
wxDataViewBitmapRenderer::GetSize() const
542 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
543 else if (m_icon
.Ok())
544 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
546 return wxSize(16,16);
549 // ---------------------------------------------------------
550 // wxDataViewToggleRenderer
551 // ---------------------------------------------------------
553 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
555 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
556 wxDataViewCellMode mode
, int align
) :
557 wxDataViewCustomRenderer( varianttype
, mode
, align
)
562 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
564 m_toggle
= value
.GetBool();
569 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
574 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
576 // User wxRenderer here
579 rect
.x
= cell
.x
+ cell
.width
/2 - 10;
581 rect
.y
= cell
.y
+ cell
.height
/2 - 10;
586 flags
|= wxCONTROL_CHECKED
;
587 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
588 flags
|= wxCONTROL_DISABLED
;
590 wxRendererNative::Get().DrawCheckBox(
591 GetOwner()->GetOwner(),
599 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
600 wxDataViewListModel
*model
,
601 unsigned int col
, unsigned int row
)
603 bool value
= !m_toggle
;
604 wxVariant variant
= value
;
605 model
->SetValue( variant
, col
, row
);
606 model
->ValueChanged( col
, row
);
610 wxSize
wxDataViewToggleRenderer::GetSize() const
612 return wxSize(20,20);
615 // ---------------------------------------------------------
616 // wxDataViewProgressRenderer
617 // ---------------------------------------------------------
619 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
621 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
622 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
623 wxDataViewCustomRenderer( varianttype
, mode
, align
)
629 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
633 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
635 m_value
= (long) value
;
637 if (m_value
< 0) m_value
= 0;
638 if (m_value
> 100) m_value
= 100;
643 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
645 value
= (long) m_value
;
649 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
651 double pct
= (double)m_value
/ 100.0;
653 bar
.width
= (int)(cell
.width
* pct
);
654 dc
->SetPen( *wxTRANSPARENT_PEN
);
655 dc
->SetBrush( *wxBLUE_BRUSH
);
656 dc
->DrawRectangle( bar
);
658 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
659 dc
->SetPen( *wxBLACK_PEN
);
660 dc
->DrawRectangle( cell
);
665 wxSize
wxDataViewProgressRenderer::GetSize() const
667 return wxSize(40,12);
670 // ---------------------------------------------------------
671 // wxDataViewDateRenderer
672 // ---------------------------------------------------------
674 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
676 #if wxUSE_DATE_RENDERER_POPUP
678 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
681 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
682 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
) :
683 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
688 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
689 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
690 sizer
->Add( m_cal
, 1, wxGROW
);
695 void OnCalendar( wxCalendarEvent
&event
);
697 wxCalendarCtrl
*m_cal
;
698 wxDataViewListModel
*m_model
;
703 virtual void OnDismiss()
708 DECLARE_EVENT_TABLE()
711 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
712 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
715 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
717 wxDateTime date
= event
.GetDate();
718 wxVariant value
= date
;
719 m_model
->SetValue( value
, m_col
, m_row
);
720 m_model
->ValueChanged( m_col
, m_row
);
724 #endif // wxUSE_DATE_RENDERER_POPUP
726 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
728 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
729 wxDataViewCellMode mode
, int align
) :
730 wxDataViewCustomRenderer( varianttype
, mode
, align
)
734 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
736 m_date
= value
.GetDateTime();
741 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
747 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
749 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
750 wxString tmp
= m_date
.FormatDate();
751 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
756 wxSize
wxDataViewDateRenderer::GetSize() const
758 const wxDataViewCtrl
* view
= GetView();
759 wxString tmp
= m_date
.FormatDate();
761 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
762 return wxSize(x
,y
+d
);
765 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewListModel
*model
,
766 unsigned int col
, unsigned int row
)
769 model
->GetValue( variant
, col
, row
);
770 wxDateTime value
= variant
.GetDateTime();
772 #if wxUSE_DATE_RENDERER_POPUP
773 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
774 GetOwner()->GetOwner()->GetParent(), &value
, model
, col
, row
);
775 wxPoint pos
= wxGetMousePosition();
778 popup
->Popup( popup
->m_cal
);
779 #else // !wxUSE_DATE_RENDERER_POPUP
780 wxMessageBox(value
.Format());
781 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
785 // ---------------------------------------------------------
787 // ---------------------------------------------------------
789 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
791 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
792 unsigned int model_column
,
793 int width
, wxAlignment align
, int flags
) :
794 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
800 Init(width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
803 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
804 unsigned int model_column
,
805 int width
, wxAlignment align
, int flags
) :
806 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
811 Init(width
< 0 ? wxDVC_TOGGLE_DEFAULT_WIDTH
: width
);
814 wxDataViewColumn::~wxDataViewColumn()
818 void wxDataViewColumn::Init( int width
)
821 m_minWidth
= wxDVC_DEFAULT_MINWIDTH
;
824 void wxDataViewColumn::SetResizeable( bool resizeable
)
827 m_flags
|= wxDATAVIEW_COL_RESIZABLE
;
829 m_flags
&= ~wxDATAVIEW_COL_RESIZABLE
;
832 void wxDataViewColumn::SetHidden( bool hidden
)
835 m_flags
|= wxDATAVIEW_COL_HIDDEN
;
837 m_flags
&= ~wxDATAVIEW_COL_HIDDEN
;
839 // tell our owner to e.g. update its scrollbars:
841 GetOwner()->OnColumnChange();
844 void wxDataViewColumn::SetSortable( bool sortable
)
847 m_flags
|= wxDATAVIEW_COL_SORTABLE
;
849 m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
852 void wxDataViewColumn::SetSortOrder( bool WXUNUSED(ascending
) )
857 bool wxDataViewColumn::IsSortOrderAscending() const
863 void wxDataViewColumn::SetInternalWidth( int width
)
867 // the scrollbars of the wxDataViewCtrl needs to be recalculated!
868 if (m_owner
&& m_owner
->m_clientArea
)
869 m_owner
->m_clientArea
->RecalculateDisplay();
872 void wxDataViewColumn::SetWidth( int width
)
874 m_owner
->m_headerArea
->UpdateDisplay();
876 SetInternalWidth(width
);
880 //-----------------------------------------------------------------------------
881 // wxDataViewHeaderWindowBase
882 //-----------------------------------------------------------------------------
884 void wxDataViewHeaderWindowBase::SendEvent(wxEventType type
, unsigned int n
)
886 wxWindow
*parent
= GetParent();
887 wxDataViewEvent
le(type
, parent
->GetId());
889 le
.SetEventObject(parent
);
891 le
.SetDataViewColumn(GetColumn(n
));
892 le
.SetModel(GetOwner()->GetModel());
894 // for events created by wxDataViewHeaderWindow the
895 // row / value fields are not valid
897 parent
->GetEventHandler()->ProcessEvent(le
);
900 #if defined(__WXMSW__) && USE_NATIVE_HEADER_WINDOW
902 // implemented in msw/listctrl.cpp:
903 int WXDLLIMPEXP_CORE
wxMSWGetColumnClicked(NMHDR
*nmhdr
, POINT
*ptClick
);
905 IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindowMSW
, wxWindow
)
907 bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl
*parent
, wxWindowID id
,
908 const wxPoint
&pos
, const wxSize
&size
,
909 const wxString
&name
)
913 if ( !CreateControl(parent
, id
, pos
, size
, 0, wxDefaultValidator
, name
) )
916 int x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
917 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
918 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
919 h
= size
.y
== wxDefaultCoord
? 22 : size
.y
;
921 // create the native WC_HEADER window:
922 WXHWND hwndParent
= (HWND
)parent
->GetHandle();
923 WXDWORD msStyle
= WS_CHILD
| HDS_BUTTONS
| HDS_HORZ
| HDS_HOTTRACK
| HDS_FULLDRAG
;
924 m_hWnd
= CreateWindowEx(0,
935 wxLogLastError(_T("CreateWindowEx"));
939 // we need to subclass the m_hWnd to force wxWindow::HandleNotify
940 // to call wxDataViewHeaderWindow::MSWOnNotify
943 // the following is required to get the default win's font for
944 // header windows and must be done befor sending the HDM_LAYOUT msg
951 // Retrieve the bounding rectangle of the parent window's
952 // client area, and then request size and position values
953 // from the header control.
954 ::GetClientRect((HWND
)hwndParent
, &rcParent
);
958 if (!SendMessage((HWND
)m_hWnd
, HDM_LAYOUT
, 0, (LPARAM
) &hdl
))
960 wxLogLastError(_T("SendMessage"));
964 // Set the size, position, and visibility of the header control.
965 SetWindowPos((HWND
)m_hWnd
,
969 wp
.flags
| SWP_SHOWWINDOW
);
971 // set our size hints: wxDataViewCtrl will put this wxWindow inside
972 // a wxBoxSizer and in order to avoid super-big header windows,
973 // we need to set our height as fixed
974 SetMinSize(wxSize(-1, wp
.cy
));
975 SetMaxSize(wxSize(-1, wp
.cy
));
980 wxDataViewHeaderWindowMSW::~wxDataViewHeaderWindow()
985 void wxDataViewHeaderWindowMSW::UpdateDisplay()
987 // remove old columns
988 for (int j
=0, max
=Header_GetItemCount((HWND
)m_hWnd
); j
< max
; j
++)
989 Header_DeleteItem((HWND
)m_hWnd
, 0);
991 // add the updated array of columns to the header control
992 unsigned int cols
= GetOwner()->GetColumnCount();
993 unsigned int added
= 0;
994 for (unsigned int i
= 0; i
< cols
; i
++)
996 wxDataViewColumn
*col
= GetColumn( i
);
998 continue; // don't add it!
1001 hdi
.mask
= HDI_TEXT
| HDI_FORMAT
| HDI_WIDTH
;
1002 hdi
.pszText
= (wxChar
*) col
->GetTitle().wx_str();
1003 hdi
.cxy
= col
->GetWidth();
1004 hdi
.cchTextMax
= sizeof(hdi
.pszText
)/sizeof(hdi
.pszText
[0]);
1005 hdi
.fmt
= HDF_LEFT
| HDF_STRING
;
1007 // lParam is reserved for application's use:
1008 // we store there the column index to use it later in MSWOnNotify
1009 // (since columns may have been hidden)
1010 hdi
.lParam
= (LPARAM
)i
;
1012 // the native wxMSW implementation of the header window
1013 // draws the column separator COLUMN_WIDTH_OFFSET pixels
1014 // on the right: to correct this effect we make the column
1015 // exactly COLUMN_WIDTH_OFFSET wider (for the first column):
1017 hdi
.cxy
+= COLUMN_WIDTH_OFFSET
;
1019 switch (col
->GetAlignment())
1022 hdi
.fmt
|= HDF_LEFT
;
1024 case wxALIGN_CENTER
:
1025 case wxALIGN_CENTER_HORIZONTAL
:
1026 hdi
.fmt
|= HDF_CENTER
;
1029 hdi
.fmt
|= HDF_RIGHT
;
1033 // such alignment is not allowed for the column header!
1037 SendMessage((HWND
)m_hWnd
, HDM_INSERTITEM
,
1038 (WPARAM
)added
, (LPARAM
)&hdi
);
1043 unsigned int wxDataViewHeaderWindowMSW::GetColumnIdxFromHeader(NMHEADER
*nmHDR
)
1047 // NOTE: we don't just return nmHDR->iItem because when there are
1048 // hidden columns, nmHDR->iItem may be different from
1049 // nmHDR->pitem->lParam
1051 if (nmHDR
->pitem
&& nmHDR
->pitem
->mask
& HDI_LPARAM
)
1053 idx
= (unsigned int)nmHDR
->pitem
->lParam
;
1058 item
.mask
= HDI_LPARAM
;
1059 Header_GetItem((HWND
)m_hWnd
, nmHDR
->iItem
, &item
);
1061 return (unsigned int)item
.lParam
;
1064 bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1066 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1068 // is it a message from the header?
1069 if ( nmhdr
->hwndFrom
!= (HWND
)m_hWnd
)
1070 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
1072 NMHEADER
*nmHDR
= (NMHEADER
*)nmhdr
;
1073 switch ( nmhdr
->code
)
1075 case HDN_BEGINTRACK
:
1076 // user has started to resize a column:
1077 // do we need to veto it?
1078 if (!GetColumn(nmHDR
->iItem
)->IsResizeable())
1086 // user has started to reorder a column
1089 case HDN_ITEMCHANGING
:
1090 if (nmHDR
->pitem
!= NULL
&&
1091 (nmHDR
->pitem
->mask
& HDI_WIDTH
) != 0)
1093 int minWidth
= GetColumnFromHeader(nmHDR
)->GetMinWidth();
1094 if (nmHDR
->pitem
->cxy
< minWidth
)
1096 // do not allow the user to resize this column under
1097 // its minimal width:
1103 case HDN_ITEMCHANGED
: // user is resizing a column
1104 case HDN_ENDTRACK
: // user has finished resizing a column
1105 case HDN_ENDDRAG
: // user has finished reordering a column
1107 // update the width of the modified column:
1108 if (nmHDR
->pitem
!= NULL
&&
1109 (nmHDR
->pitem
->mask
& HDI_WIDTH
) != 0)
1111 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1112 unsigned int w
= nmHDR
->pitem
->cxy
;
1113 wxDataViewColumn
*col
= GetColumn(idx
);
1115 // see UpdateDisplay() for more info about COLUMN_WIDTH_OFFSET
1116 if (idx
== 0 && w
> COLUMN_WIDTH_OFFSET
)
1117 w
-= COLUMN_WIDTH_OFFSET
;
1119 if (w
>= (unsigned)col
->GetMinWidth())
1120 col
->SetInternalWidth(w
);
1126 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1127 wxEventType evt
= nmHDR
->iButton
== 0 ?
1128 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
:
1129 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
;
1130 SendEvent(evt
, idx
);
1136 // NOTE: for some reason (i.e. for a bug in Windows)
1137 // the HDN_ITEMCLICK notification is not sent on
1138 // right clicks, so we need to handle NM_RCLICK
1141 int column
= wxMSWGetColumnClicked(nmhdr
, &ptClick
);
1142 if (column
!= wxNOT_FOUND
)
1145 item
.mask
= HDI_LPARAM
;
1146 Header_GetItem((HWND
)m_hWnd
, column
, &item
);
1148 // 'idx' may be different from 'column' if there are
1149 // hidden columns...
1150 unsigned int idx
= (unsigned int)item
.lParam
;
1151 SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
1157 case HDN_GETDISPINFOW
:
1158 // see wxListCtrl::MSWOnNotify for more info!
1161 case HDN_ITEMDBLCLICK
:
1163 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1164 int w
= GetOwner()->GetBestColumnWidth(idx
);
1166 // update the native control:
1168 ZeroMemory(&hd
, sizeof(hd
));
1169 hd
.mask
= HDI_WIDTH
;
1171 Header_SetItem(GetHwnd(),
1172 nmHDR
->iItem
, // NOTE: we don't want 'idx' here!
1175 // update the wxDataViewColumn class:
1176 GetColumn(idx
)->SetInternalWidth(w
);
1181 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
1187 void wxDataViewHeaderWindowMSW::ScrollWindow(int WXUNUSED(dx
), int WXUNUSED(dy
),
1188 const wxRect
*WXUNUSED(rect
))
1190 wxSize ourSz
= GetClientSize();
1191 wxSize ownerSz
= m_owner
->GetClientSize();
1193 // where should the (logical) origin of this window be placed?
1195 m_owner
->CalcUnscrolledPosition(0, 0, &x1
, &y1
);
1197 // put this window on top of our parent and
1198 SetWindowPos((HWND
)m_hWnd
, HWND_TOP
, -x1
, 0,
1199 ownerSz
.GetWidth() + x1
, ourSz
.GetHeight(),
1203 void wxDataViewHeaderWindowMSW::DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
1204 int WXUNUSED(w
), int WXUNUSED(h
),
1207 // the wxDataViewCtrl's internal wxBoxSizer will call this function when
1208 // the wxDataViewCtrl window gets resized: the following dummy call
1209 // to ScrollWindow() is required in order to get this header window
1210 // correctly repainted when it's (horizontally) scrolled:
1215 #else // !defined(__WXMSW__)
1217 IMPLEMENT_ABSTRACT_CLASS(wxGenericDataViewHeaderWindow
, wxWindow
)
1218 BEGIN_EVENT_TABLE(wxGenericDataViewHeaderWindow
, wxWindow
)
1219 EVT_PAINT (wxGenericDataViewHeaderWindow::OnPaint
)
1220 EVT_MOUSE_EVENTS (wxGenericDataViewHeaderWindow::OnMouse
)
1221 EVT_SET_FOCUS (wxGenericDataViewHeaderWindow::OnSetFocus
)
1224 bool wxGenericDataViewHeaderWindow::Create(wxDataViewCtrl
*parent
, wxWindowID id
,
1225 const wxPoint
&pos
, const wxSize
&size
,
1226 const wxString
&name
)
1230 if (!wxDataViewHeaderWindowBase::Create(parent
, id
, pos
, size
, name
))
1233 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1234 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1235 SetOwnForegroundColour( attr
.colFg
);
1236 SetOwnBackgroundColour( attr
.colBg
);
1238 SetOwnFont( attr
.font
);
1240 // set our size hints: wxDataViewCtrl will put this wxWindow inside
1241 // a wxBoxSizer and in order to avoid super-big header windows,
1242 // we need to set our height as fixed
1243 SetMinSize(wxSize(-1, HEADER_WINDOW_HEIGHT
));
1244 SetMaxSize(wxSize(-1, HEADER_WINDOW_HEIGHT
));
1249 void wxGenericDataViewHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1252 GetClientSize( &w
, &h
);
1254 wxAutoBufferedPaintDC
dc( this );
1256 dc
.SetBackground(GetBackgroundColour());
1260 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1263 m_owner
->GetViewStart( &x
, NULL
);
1265 // account for the horz scrollbar offset
1266 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1268 dc
.SetFont( GetFont() );
1270 unsigned int cols
= GetOwner()->GetColumnCount();
1273 for (i
= 0; i
< cols
; i
++)
1275 wxDataViewColumn
*col
= GetColumn( i
);
1276 if (col
->IsHidden())
1277 continue; // skip it!
1279 int cw
= col
->GetWidth();
1282 wxRendererNative::Get().DrawHeaderButton
1286 wxRect(xpos
, 0, cw
, ch
-1),
1287 m_parent
->IsEnabled() ? 0
1288 : (int)wxCONTROL_DISABLED
1291 // align as required the column title:
1293 wxSize titleSz
= dc
.GetTextExtent(col
->GetTitle());
1294 switch (col
->GetAlignment())
1297 x
+= HEADER_HORIZ_BORDER
;
1299 case wxALIGN_CENTER
:
1300 case wxALIGN_CENTER_HORIZONTAL
:
1301 x
+= (cw
- titleSz
.GetWidth() - 2 * HEADER_HORIZ_BORDER
)/2;
1304 x
+= cw
- titleSz
.GetWidth() - HEADER_HORIZ_BORDER
;
1308 // always center the title vertically:
1309 int y
= wxMax((ch
- titleSz
.GetHeight()) / 2, HEADER_VERT_BORDER
);
1311 dc
.SetClippingRegion( xpos
+HEADER_HORIZ_BORDER
,
1313 wxMax(cw
- 2 * HEADER_HORIZ_BORDER
, 1), // width
1314 wxMax(ch
- 2 * HEADER_VERT_BORDER
, 1)); // height
1315 dc
.DrawText( col
->GetTitle(), x
, y
);
1316 dc
.DestroyClippingRegion();
1322 void wxGenericDataViewHeaderWindow::OnSetFocus( wxFocusEvent
&event
)
1324 GetParent()->SetFocus();
1328 void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent
&event
)
1330 // we want to work with logical coords
1332 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1333 int y
= event
.GetY();
1337 // we don't draw the line beyond our window,
1338 // but we allow dragging it there
1340 GetClientSize( &w
, NULL
);
1341 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1344 // erase the line if it was drawn
1348 if (event
.ButtonUp())
1350 m_isDragging
= false;
1356 GetColumn(m_column
)->SetWidth(m_currentX
- m_minX
);
1359 GetOwner()->Refresh();
1363 m_currentX
= wxMax(m_minX
+ 7, x
);
1365 // draw in the new location
1366 if (m_currentX
< w
) DrawCurrent();
1370 else // not dragging
1373 m_column
= wxNOT_FOUND
;
1375 bool hit_border
= false;
1377 // end of the current column
1380 // find the column where this event occured
1381 int countCol
= m_owner
->GetColumnCount();
1382 for (int column
= 0; column
< countCol
; column
++)
1384 wxDataViewColumn
*p
= GetColumn(column
);
1387 continue; // skip if not shown
1389 xpos
+= p
->GetWidth();
1391 if ((abs(x
-xpos
) < 3) && (y
< 22))
1399 // inside the column
1406 if (m_column
== wxNOT_FOUND
)
1409 bool resizeable
= GetColumn(m_column
)->IsResizeable();
1410 if (event
.LeftDClick() && resizeable
)
1412 GetColumn(m_column
)->SetWidth(GetOwner()->GetBestColumnWidth(m_column
));
1415 else if (event
.LeftDown() || event
.RightUp())
1417 if (hit_border
&& event
.LeftDown() && resizeable
)
1419 m_isDragging
= true;
1424 else // click on a column
1426 wxEventType evt
= event
.LeftDown() ?
1427 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
:
1428 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
;
1429 SendEvent(evt
, m_column
);
1432 else if (event
.Moving())
1434 if (hit_border
&& resizeable
)
1435 m_currentCursor
= m_resizeCursor
;
1437 m_currentCursor
= wxSTANDARD_CURSOR
;
1439 SetCursor(*m_currentCursor
);
1444 void wxGenericDataViewHeaderWindow::DrawCurrent()
1446 int x1
= m_currentX
;
1448 ClientToScreen (&x1
, &y1
);
1450 int x2
= m_currentX
-1;
1452 ++x2
; // but why ????
1455 m_owner
->GetClientSize( NULL
, &y2
);
1456 m_owner
->ClientToScreen( &x2
, &y2
);
1459 dc
.SetLogicalFunction(wxINVERT
);
1460 dc
.SetPen(m_penCurrent
);
1461 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1463 dc
.DrawLine(x1
, y1
, x2
, y2
);
1466 void wxGenericDataViewHeaderWindow::AdjustDC(wxDC
& dc
)
1470 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1471 m_owner
->GetViewStart( &x
, NULL
);
1473 // shift the DC origin to match the position of the main window horizontal
1474 // scrollbar: this allows us to always use logical coords
1475 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1478 #endif // defined(__WXMSW__)
1480 //-----------------------------------------------------------------------------
1481 // wxDataViewRenameTimer
1482 //-----------------------------------------------------------------------------
1484 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1489 void wxDataViewRenameTimer::Notify()
1491 m_owner
->OnRenameTimer();
1494 //-----------------------------------------------------------------------------
1495 // wxDataViewMainWindow
1496 //-----------------------------------------------------------------------------
1498 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1500 if (row1
> row2
) return 1;
1501 if (row1
== row2
) return 0;
1506 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1508 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1509 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1510 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1511 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1512 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1513 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1516 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1517 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1518 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
, name
),
1519 m_selection( wxDataViewSelectionCmp
)
1524 m_lastOnSame
= false;
1525 m_renameTimer
= new wxDataViewRenameTimer( this );
1527 // TODO: user better initial values/nothing selected
1528 m_currentCol
= NULL
;
1531 // TODO: we need to calculate this smartly
1538 wxASSERT(m_lineHeight
> 2*PADDING_TOPBOTTOM
);
1541 m_dragStart
= wxPoint(0,0);
1542 m_lineLastClicked
= (unsigned int) -1;
1543 m_lineBeforeLastClicked
= (unsigned int) -1;
1544 m_lineSelectSingleOnUp
= (unsigned int) -1;
1548 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1549 SetBackgroundColour( *wxWHITE
);
1551 m_penRule
= wxPen(GetRuleColour(), 1, wxSOLID
);
1556 wxDataViewMainWindow::~wxDataViewMainWindow()
1558 delete m_renameTimer
;
1561 void wxDataViewMainWindow::OnRenameTimer()
1563 // We have to call this here because changes may just have
1564 // been made and no screen update taken place.
1569 unsigned int cols
= GetOwner()->GetColumnCount();
1571 for (i
= 0; i
< cols
; i
++)
1573 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
1575 continue; // skip it!
1577 if (c
== m_currentCol
)
1579 xpos
+= c
->GetWidth();
1581 wxRect
labelRect( xpos
, m_currentRow
* m_lineHeight
,
1582 m_currentCol
->GetWidth(), m_lineHeight
);
1584 GetOwner()->CalcScrolledPosition( labelRect
.x
, labelRect
.y
,
1585 &labelRect
.x
, &labelRect
.y
);
1587 m_currentCol
->GetRenderer()->StartEditing( m_currentRow
, labelRect
);
1590 bool wxDataViewMainWindow::RowAppended()
1596 bool wxDataViewMainWindow::RowPrepended()
1602 bool wxDataViewMainWindow::RowInserted( unsigned int WXUNUSED(before
) )
1608 bool wxDataViewMainWindow::RowDeleted( unsigned int WXUNUSED(row
) )
1614 bool wxDataViewMainWindow::RowChanged( unsigned int WXUNUSED(row
) )
1620 bool wxDataViewMainWindow::ValueChanged( unsigned int WXUNUSED(col
), unsigned int row
)
1622 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
1623 #define MAX_VIRTUAL_WIDTH 100000
1625 wxRect
rect( 0, row
*m_lineHeight
, MAX_VIRTUAL_WIDTH
, m_lineHeight
);
1626 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1627 Refresh( true, &rect
);
1632 bool wxDataViewMainWindow::RowsReordered( unsigned int *WXUNUSED(new_order
) )
1638 bool wxDataViewMainWindow::Cleared()
1644 void wxDataViewMainWindow::UpdateDisplay()
1649 void wxDataViewMainWindow::OnInternalIdle()
1651 wxWindow::OnInternalIdle();
1655 RecalculateDisplay();
1660 void wxDataViewMainWindow::RecalculateDisplay()
1662 wxDataViewListModel
*model
= GetOwner()->GetModel();
1669 int width
= GetEndOfLastCol();
1670 int height
= model
->GetRowCount() * m_lineHeight
;
1672 SetVirtualSize( width
, height
);
1673 GetOwner()->SetScrollRate( 10, m_lineHeight
);
1678 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
1680 wxWindow::ScrollWindow( dx
, dy
, rect
);
1682 if (GetOwner()->m_headerArea
)
1683 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
1686 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1688 wxDataViewListModel
*model
= GetOwner()->GetModel();
1689 wxAutoBufferedPaintDC
dc( this );
1692 dc
.SetBackground(GetBackgroundColour());
1694 GetOwner()->PrepareDC( dc
);
1695 dc
.SetFont( GetFont() );
1697 wxRect update
= GetUpdateRegion().GetBox();
1698 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1700 // compute which items needs to be redrawn
1701 unsigned int item_start
= wxMax( 0, (update
.y
/ m_lineHeight
) );
1702 unsigned int item_count
=
1703 wxMin( (int)(((update
.y
+ update
.height
) / m_lineHeight
) - item_start
+ 1),
1704 (int)(model
->GetRowCount() - item_start
) );
1705 unsigned int item_last
= item_start
+ item_count
;
1707 // compute which columns needs to be redrawn
1708 unsigned int cols
= GetOwner()->GetColumnCount();
1709 unsigned int col_start
= 0;
1710 unsigned int x_start
= 0;
1711 for (x_start
= 0; col_start
< cols
; col_start
++)
1713 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_start
);
1714 if (col
->IsHidden())
1715 continue; // skip it!
1717 unsigned int w
= col
->GetWidth();
1718 if (x_start
+w
>= (unsigned int)update
.x
)
1724 unsigned int col_last
= col_start
;
1725 unsigned int x_last
= x_start
;
1726 for (; col_last
< cols
; col_last
++)
1728 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_last
);
1729 if (col
->IsHidden())
1730 continue; // skip it!
1732 if (x_last
> (unsigned int)update
.GetRight())
1735 x_last
+= col
->GetWidth();
1738 // Draw horizontal rules if required
1739 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1741 dc
.SetPen(m_penRule
);
1742 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1744 for (unsigned int i
= item_start
; i
<= item_last
+1; i
++)
1746 int y
= i
* m_lineHeight
;
1747 dc
.DrawLine(x_start
, y
, x_last
, y
);
1751 // Draw vertical rules if required
1752 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1754 dc
.SetPen(m_penRule
);
1755 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1758 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1760 wxDataViewColumn
*col
= GetOwner()->GetColumn(i
);
1761 if (col
->IsHidden())
1762 continue; // skip it
1764 dc
.DrawLine(x
, item_start
* m_lineHeight
,
1765 x
, item_last
* m_lineHeight
);
1767 x
+= col
->GetWidth();
1770 // Draw last vertical rule
1771 dc
.DrawLine(x
, item_start
* m_lineHeight
,
1772 x
, item_last
* m_lineHeight
);
1775 // redraw the background for the items which are selected/current
1776 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1778 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1779 if (selected
|| item
== m_currentRow
)
1781 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
1782 if (item
== m_currentRow
)
1783 flags
|= wxCONTROL_CURRENT
;
1785 flags
|= wxCONTROL_FOCUSED
;
1787 wxRect
rect( x_start
, item
*m_lineHeight
, x_last
, m_lineHeight
);
1788 wxRendererNative::Get().DrawItemSelectionRect
1798 // redraw all cells for all rows which must be repainted and for all columns
1800 cell_rect
.x
= x_start
;
1801 cell_rect
.height
= m_lineHeight
; // -1 is for the horizontal rules
1802 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1804 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
1805 wxDataViewRenderer
*cell
= col
->GetRenderer();
1806 cell_rect
.width
= col
->GetWidth();
1808 if (col
->IsHidden())
1809 continue; // skipt it!
1811 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1813 // get the cell value and set it into the renderer
1815 model
->GetValue( value
, col
->GetModelColumn(), item
);
1816 cell
->SetValue( value
);
1818 // update the y offset
1819 cell_rect
.y
= item
* m_lineHeight
;
1821 // cannot be bigger than allocated space
1822 wxSize size
= cell
->GetSize();
1823 size
.x
= wxMin( size
.x
+ 2*PADDING_RIGHTLEFT
, cell_rect
.width
);
1824 size
.y
= wxMin( size
.y
+ 2*PADDING_TOPBOTTOM
, cell_rect
.height
);
1826 wxRect
item_rect(cell_rect
.GetTopLeft(), size
);
1827 int align
= cell
->GetAlignment();
1829 // horizontal alignment:
1830 item_rect
.x
= cell_rect
.x
;
1831 if (align
& wxALIGN_CENTER_HORIZONTAL
)
1832 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
1833 else if (align
& wxALIGN_RIGHT
)
1834 item_rect
.x
= cell_rect
.x
+ cell_rect
.width
- size
.x
;
1835 //else: wxALIGN_LEFT is the default
1837 // vertical alignment:
1838 item_rect
.y
= cell_rect
.y
;
1839 if (align
& wxALIGN_CENTER_VERTICAL
)
1840 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
1841 else if (align
& wxALIGN_BOTTOM
)
1842 item_rect
.y
= cell_rect
.y
+ cell_rect
.height
- size
.y
;
1843 //else: wxALIGN_TOP is the default
1846 item_rect
.x
+= PADDING_RIGHTLEFT
;
1847 item_rect
.y
+= PADDING_TOPBOTTOM
;
1848 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
1849 item_rect
.height
= size
.y
- 2 * PADDING_TOPBOTTOM
;
1852 if (m_selection
.Index(item
) != wxNOT_FOUND
)
1853 state
|= wxDATAVIEW_CELL_SELECTED
;
1855 // TODO: it would be much more efficient to create a clipping
1856 // region for the entire column being rendered (in the OnPaint
1857 // of wxDataViewMainWindow) instead of a single clip region for
1858 // each cell. However it would mean that each renderer should
1859 // respect the given wxRect's top & bottom coords, eventually
1860 // violating only the left & right coords - however the user can
1861 // make its own renderer and thus we cannot be sure of that.
1862 dc
.SetClippingRegion( item_rect
);
1863 cell
->Render( item_rect
, &dc
, state
);
1864 dc
.DestroyClippingRegion();
1867 cell_rect
.x
+= cell_rect
.width
;
1871 int wxDataViewMainWindow::GetCountPerPage() const
1873 wxSize size
= GetClientSize();
1874 return size
.y
/ m_lineHeight
;
1877 int wxDataViewMainWindow::GetEndOfLastCol() const
1881 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
1883 const wxDataViewColumn
*c
=
1884 wx_const_cast(wxDataViewCtrl
*, GetOwner())->GetColumn( i
);
1887 width
+= c
->GetWidth();
1892 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
1896 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
1898 return y
/ m_lineHeight
;
1901 unsigned int wxDataViewMainWindow::GetLastVisibleRow() const
1903 wxSize client_size
= GetClientSize();
1904 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
1905 &client_size
.x
, &client_size
.y
);
1907 return wxMin( GetRowCount()-1, ((unsigned)client_size
.y
/m_lineHeight
)+1 );
1910 unsigned int wxDataViewMainWindow::GetRowCount() const
1912 return wx_const_cast(wxDataViewCtrl
*, GetOwner())->GetModel()->GetRowCount();
1915 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
1922 void wxDataViewMainWindow::SelectAllRows( bool on
)
1929 m_selection
.Clear();
1930 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
1931 m_selection
.Add( i
);
1936 unsigned int first_visible
= GetFirstVisibleRow();
1937 unsigned int last_visible
= GetLastVisibleRow();
1939 for (i
= 0; i
< m_selection
.GetCount(); i
++)
1941 unsigned int row
= m_selection
[i
];
1942 if ((row
>= first_visible
) && (row
<= last_visible
))
1945 m_selection
.Clear();
1949 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
1951 if (m_selection
.Index( row
) == wxNOT_FOUND
)
1955 m_selection
.Add( row
);
1963 m_selection
.Remove( row
);
1969 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
1973 unsigned int tmp
= from
;
1979 for (i
= from
; i
<= to
; i
++)
1981 if (m_selection
.Index( i
) == wxNOT_FOUND
)
1984 m_selection
.Add( i
);
1989 m_selection
.Remove( i
);
1992 RefreshRows( from
, to
);
1995 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
1997 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
1999 int n
= aSelections
[i
];
2001 m_selection
.Add( n
);
2006 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2008 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2009 m_selection
.Add( row
);
2011 m_selection
.Remove( row
);
2015 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2017 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2020 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2022 wxRect
rect( 0, row
*m_lineHeight
, GetEndOfLastCol(), m_lineHeight
);
2023 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2025 wxSize client_size
= GetClientSize();
2026 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2027 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2028 if (intersect_rect
.width
> 0)
2029 Refresh( true, &intersect_rect
);
2032 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2036 unsigned int tmp
= to
;
2041 wxRect
rect( 0, from
*m_lineHeight
, GetEndOfLastCol(), (to
-from
+1) * m_lineHeight
);
2042 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2044 wxSize client_size
= GetClientSize();
2045 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2046 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2047 if (intersect_rect
.width
> 0)
2048 Refresh( true, &intersect_rect
);
2051 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2053 unsigned int count
= GetRowCount();
2054 if (firstRow
> count
)
2057 wxRect
rect( 0, firstRow
*m_lineHeight
, GetEndOfLastCol(), count
* m_lineHeight
);
2058 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2060 wxSize client_size
= GetClientSize();
2061 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2062 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2063 if (intersect_rect
.width
> 0)
2064 Refresh( true, &intersect_rect
);
2067 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2069 wxCHECK_RET( newCurrent
< GetRowCount(),
2070 _T("invalid item index in OnArrowChar()") );
2072 // if there is no selection, we cannot move it anywhere
2073 if (!HasCurrentRow())
2076 unsigned int oldCurrent
= m_currentRow
;
2078 // in single selection we just ignore Shift as we can't select several
2080 if ( event
.ShiftDown() && !IsSingleSel() )
2082 RefreshRow( oldCurrent
);
2084 ChangeCurrentRow( newCurrent
);
2086 // select all the items between the old and the new one
2087 if ( oldCurrent
> newCurrent
)
2089 newCurrent
= oldCurrent
;
2090 oldCurrent
= m_currentRow
;
2093 SelectRows( oldCurrent
, newCurrent
, true );
2097 RefreshRow( oldCurrent
);
2099 // all previously selected items are unselected unless ctrl is held
2100 if ( !event
.ControlDown() )
2101 SelectAllRows(false);
2103 ChangeCurrentRow( newCurrent
);
2105 if ( !event
.ControlDown() )
2106 SelectRow( m_currentRow
, true );
2108 RefreshRow( m_currentRow
);
2111 //EnsureVisible( m_currentRow );
2114 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2118 rect
.y
= m_lineHeight
* row
;
2119 rect
.width
= GetEndOfLastCol();
2120 rect
.height
= m_lineHeight
;
2125 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
2127 if (event
.GetKeyCode() == WXK_TAB
)
2129 wxNavigationKeyEvent nevent
;
2130 nevent
.SetWindowChange( event
.ControlDown() );
2131 nevent
.SetDirection( !event
.ShiftDown() );
2132 nevent
.SetEventObject( GetParent()->GetParent() );
2133 nevent
.SetCurrentFocus( m_parent
);
2134 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
2138 // no item -> nothing to do
2139 if (!HasCurrentRow())
2145 // don't use m_linesPerPage directly as it might not be computed yet
2146 const int pageSize
= GetCountPerPage();
2147 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
2149 switch ( event
.GetKeyCode() )
2152 if ( m_currentRow
> 0 )
2153 OnArrowChar( m_currentRow
- 1, event
);
2157 if ( m_currentRow
< GetRowCount() - 1 )
2158 OnArrowChar( m_currentRow
+ 1, event
);
2163 OnArrowChar( GetRowCount() - 1, event
);
2168 OnArrowChar( 0, event
);
2173 int steps
= pageSize
- 1;
2174 int index
= m_currentRow
- steps
;
2178 OnArrowChar( index
, event
);
2184 int steps
= pageSize
- 1;
2185 unsigned int index
= m_currentRow
+ steps
;
2186 unsigned int count
= GetRowCount();
2187 if ( index
>= count
)
2190 OnArrowChar( index
, event
);
2199 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
2201 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2203 // let the base handle mouse wheel events.
2208 int x
= event
.GetX();
2209 int y
= event
.GetY();
2210 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2212 wxDataViewColumn
*col
= NULL
;
2215 unsigned int cols
= GetOwner()->GetColumnCount();
2217 for (i
= 0; i
< cols
; i
++)
2219 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
2221 continue; // skip it!
2223 if (x
< xpos
+ c
->GetWidth())
2228 xpos
+= c
->GetWidth();
2232 wxDataViewRenderer
*cell
= col
->GetRenderer();
2234 unsigned int current
= y
/ m_lineHeight
;
2236 if ((current
> GetRowCount()) || (x
> GetEndOfLastCol()))
2238 // Unselect all if below the last row ?
2242 wxDataViewListModel
*model
= GetOwner()->GetModel();
2244 if (event
.Dragging())
2246 if (m_dragCount
== 0)
2248 // we have to report the raw, physical coords as we want to be
2249 // able to call HitTest(event.m_pointDrag) from the user code to
2250 // get the item being dragged
2251 m_dragStart
= event
.GetPosition();
2256 if (m_dragCount
!= 3)
2259 if (event
.LeftIsDown())
2261 // Notify cell about drag
2270 bool forceClick
= false;
2272 if (event
.ButtonDClick())
2274 m_renameTimer
->Stop();
2275 m_lastOnSame
= false;
2278 if (event
.LeftDClick())
2280 if ( current
== m_lineLastClicked
)
2282 if (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
)
2285 model
->GetValue( value
, col
->GetModelColumn(), current
);
2286 cell
->SetValue( value
);
2287 wxRect
cell_rect( xpos
, current
* m_lineHeight
,
2288 col
->GetWidth(), m_lineHeight
);
2289 cell
->Activate( cell_rect
, model
, col
->GetModelColumn(), current
);
2295 // The first click was on another item, so don't interpret this as
2296 // a double click, but as a simple click instead
2303 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
2305 // select single line
2306 SelectAllRows( false );
2307 SelectRow( m_lineSelectSingleOnUp
, true );
2312 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
2313 (cell
->GetMode() == wxDATAVIEW_CELL_EDITABLE
) )
2315 m_renameTimer
->Start( 100, true );
2319 m_lastOnSame
= false;
2320 m_lineSelectSingleOnUp
= (unsigned int)-1;
2324 // This is necessary, because after a DnD operation in
2325 // from and to ourself, the up event is swallowed by the
2326 // DnD code. So on next non-up event (which means here and
2327 // now) m_lineSelectSingleOnUp should be reset.
2328 m_lineSelectSingleOnUp
= (unsigned int)-1;
2331 if (event
.RightDown())
2333 m_lineBeforeLastClicked
= m_lineLastClicked
;
2334 m_lineLastClicked
= current
;
2336 // If the item is already selected, do not update the selection.
2337 // Multi-selections should not be cleared if a selected item is clicked.
2338 if (!IsRowSelected(current
))
2340 SelectAllRows(false);
2341 ChangeCurrentRow(current
);
2342 SelectRow(m_currentRow
,true);
2345 // notify cell about right click
2348 // Allow generation of context menu event
2351 else if (event
.MiddleDown())
2353 // notify cell about middle click
2356 if (event
.LeftDown() || forceClick
)
2362 m_lineBeforeLastClicked
= m_lineLastClicked
;
2363 m_lineLastClicked
= current
;
2365 unsigned int oldCurrentRow
= m_currentRow
;
2366 bool oldWasSelected
= IsRowSelected(m_currentRow
);
2368 bool cmdModifierDown
= event
.CmdDown();
2369 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
2371 if ( IsSingleSel() || !IsRowSelected(current
) )
2373 SelectAllRows( false );
2375 ChangeCurrentRow(current
);
2377 SelectRow(m_currentRow
,true);
2379 else // multi sel & current is highlighted & no mod keys
2381 m_lineSelectSingleOnUp
= current
;
2382 ChangeCurrentRow(current
); // change focus
2385 else // multi sel & either ctrl or shift is down
2387 if (cmdModifierDown
)
2389 ChangeCurrentRow(current
);
2391 ReverseRowSelection(m_currentRow
);
2393 else if (event
.ShiftDown())
2395 ChangeCurrentRow(current
);
2397 unsigned int lineFrom
= oldCurrentRow
,
2400 if ( lineTo
< lineFrom
)
2403 lineFrom
= m_currentRow
;
2406 SelectRows(lineFrom
, lineTo
, true);
2408 else // !ctrl, !shift
2410 // test in the enclosing if should make it impossible
2411 wxFAIL_MSG( _T("how did we get here?") );
2415 if (m_currentRow
!= oldCurrentRow
)
2416 RefreshRow( oldCurrentRow
);
2418 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
2420 // Update selection here...
2423 m_lastOnSame
= !forceClick
&& ((col
== oldCurrentCol
) &&
2424 (current
== oldCurrentRow
)) && oldWasSelected
;
2428 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
2432 if (HasCurrentRow())
2438 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
2442 if (HasCurrentRow())
2448 //-----------------------------------------------------------------------------
2450 //-----------------------------------------------------------------------------
2452 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
2454 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
2455 EVT_SIZE(wxDataViewCtrl::OnSize
)
2458 wxDataViewCtrl::~wxDataViewCtrl()
2461 GetModel()->RemoveNotifier( m_notifier
);
2464 void wxDataViewCtrl::Init()
2469 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
2470 const wxPoint
& pos
, const wxSize
& size
,
2471 long style
, const wxValidator
& validator
)
2473 if (!wxControl::Create( parent
, id
, pos
, size
,
2474 style
| wxScrolledWindowStyle
|wxSUNKEN_BORDER
, validator
))
2480 MacSetClipChildren( true ) ;
2483 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
2485 if (HasFlag(wxDV_NO_HEADER
))
2486 m_headerArea
= NULL
;
2488 m_headerArea
= new wxDataViewHeaderWindow( this, wxID_ANY
);
2490 SetTargetWindow( m_clientArea
);
2492 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
2494 sizer
->Add( m_headerArea
, 0, wxGROW
);
2495 sizer
->Add( m_clientArea
, 1, wxGROW
);
2502 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
2506 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
2509 // we need to process arrows ourselves for scrolling
2510 if ( nMsg
== WM_GETDLGCODE
)
2512 rc
|= DLGC_WANTARROWS
;
2520 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2522 // We need to override OnSize so that our scrolled
2523 // window a) does call Layout() to use sizers for
2524 // positioning the controls but b) does not query
2525 // the sizer for their size and use that for setting
2526 // the scrollable area as set that ourselves by
2527 // calling SetScrollbar() further down.
2534 bool wxDataViewCtrl::AssociateModel( wxDataViewListModel
*model
)
2536 if (!wxDataViewCtrlBase::AssociateModel( model
))
2539 m_notifier
= new wxGenericDataViewListModelNotifier( m_clientArea
);
2541 model
->AddNotifier( m_notifier
);
2543 m_clientArea
->UpdateDisplay();
2548 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
2550 if (!wxDataViewCtrlBase::AppendColumn(col
))
2557 void wxDataViewCtrl::OnColumnChange()
2560 m_headerArea
->UpdateDisplay();
2562 m_clientArea
->UpdateDisplay();
2565 void wxDataViewCtrl::SetSelection( int row
)
2567 m_clientArea
->SelectRow(row
, true);
2570 void wxDataViewCtrl::SetSelectionRange( unsigned int from
, unsigned int to
)
2572 m_clientArea
->SelectRows(from
, to
, true);
2575 void wxDataViewCtrl::SetSelections( const wxArrayInt
& aSelections
)
2577 m_clientArea
->Select(aSelections
);
2580 void wxDataViewCtrl::Unselect( unsigned int WXUNUSED(row
) )
2585 bool wxDataViewCtrl::IsSelected( unsigned int WXUNUSED(row
) ) const
2592 int wxDataViewCtrl::GetSelection() const
2599 int wxDataViewCtrl::GetSelections(wxArrayInt
& WXUNUSED(aSelections
) ) const
2607 // !wxUSE_GENERICDATAVIEWCTRL
2610 // wxUSE_DATAVIEWCTRL