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"
38 #include "wx/stockitem.h"
39 #include "wx/calctrl.h"
40 #include "wx/popupwin.h"
41 #include "wx/renderer.h"
42 #include "wx/dcbuffer.h"
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
51 static const int SCROLL_UNIT_X
= 15;
53 // the cell padding on the left/right
54 static const int PADDING_RIGHTLEFT
= 3;
56 // the cell padding on the top/bottom
57 static const int PADDING_TOPBOTTOM
= 1;
60 //-----------------------------------------------------------------------------
61 // wxDataViewHeaderWindow
62 //-----------------------------------------------------------------------------
64 #define USE_NATIVE_HEADER_WINDOW 1
66 // NB: for some reason, this class must be dllexport'ed or we get warnings from
68 class WXDLLIMPEXP_ADV wxDataViewHeaderWindowBase
: public wxControl
71 wxDataViewHeaderWindowBase()
74 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
75 const wxPoint
&pos
, const wxSize
&size
,
78 return wxWindow::Create(parent
, id
, pos
, size
, wxNO_BORDER
, name
);
81 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
82 wxDataViewCtrl
*GetOwner() { return m_owner
; }
84 // called on column addition/removal
85 virtual void UpdateDisplay() { /* by default, do nothing */ }
87 // returns the n-th column
88 virtual wxDataViewColumn
*GetColumn(unsigned int n
)
91 wxDataViewColumn
*ret
= m_owner
->GetColumn(n
);
98 wxDataViewCtrl
*m_owner
;
100 // sends an event generated from the n-th wxDataViewColumn
101 void SendEvent(wxEventType type
, unsigned int n
);
104 // on wxMSW the header window (only that part however) can be made native!
105 #if defined(__WXMSW__) && USE_NATIVE_HEADER_WINDOW
107 #define COLUMN_WIDTH_OFFSET 2
108 #define wxDataViewHeaderWindowMSW wxDataViewHeaderWindow
110 class wxDataViewHeaderWindowMSW
: public wxDataViewHeaderWindowBase
114 wxDataViewHeaderWindowMSW( wxDataViewCtrl
*parent
,
116 const wxPoint
&pos
= wxDefaultPosition
,
117 const wxSize
&size
= wxDefaultSize
,
118 const wxString
&name
= wxT("wxdataviewctrlheaderwindow") )
120 Create(parent
, id
, pos
, size
, name
);
123 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
124 const wxPoint
&pos
, const wxSize
&size
,
125 const wxString
&name
);
127 ~wxDataViewHeaderWindowMSW();
129 // called when any column setting is changed and/or changed
131 virtual void UpdateDisplay();
133 // called when the main window gets scrolled
134 virtual void ScrollWindow(int dx
, int dy
, const wxRect
*rect
= NULL
);
137 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
138 virtual void DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
);
140 unsigned int GetColumnIdxFromHeader(NMHEADER
*nmHDR
);
142 wxDataViewColumn
*GetColumnFromHeader(NMHEADER
*nmHDR
)
143 { return GetColumn(GetColumnIdxFromHeader(nmHDR
)); }
146 DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindowMSW
)
149 #else // !defined(__WXMSW__)
151 #define HEADER_WINDOW_HEIGHT 25
152 #define HEADER_HORIZ_BORDER 5
153 #define HEADER_VERT_BORDER 3
154 #define wxGenericDataViewHeaderWindow wxDataViewHeaderWindow
156 class wxGenericDataViewHeaderWindow
: public wxDataViewHeaderWindowBase
159 wxGenericDataViewHeaderWindow( wxDataViewCtrl
*parent
,
161 const wxPoint
&pos
= wxDefaultPosition
,
162 const wxSize
&size
= wxDefaultSize
,
163 const wxString
&name
= wxT("wxdataviewctrlheaderwindow") )
166 Create(parent
, id
, pos
, size
, name
);
169 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
170 const wxPoint
&pos
, const wxSize
&size
,
171 const wxString
&name
);
173 ~wxGenericDataViewHeaderWindow()
175 delete m_resizeCursor
;
180 void OnPaint( wxPaintEvent
&event
);
181 void OnMouse( wxMouseEvent
&event
);
182 void OnSetFocus( wxFocusEvent
&event
);
187 // vars used for column resizing:
189 wxCursor
*m_resizeCursor
;
190 const wxCursor
*m_currentCursor
;
193 bool m_dirty
; // needs refresh?
194 int m_column
; // index of the column being resized
195 int m_currentX
; // divider line position in logical (unscrolled) coords
196 int m_minX
; // minimal position beyond which the divider line
197 // can't be dragged in logical coords
199 // the pen used to draw the current column width drag line
200 // when resizing the columsn
204 // internal utilities:
208 m_currentCursor
= (wxCursor
*) NULL
;
209 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
211 m_isDragging
= false;
214 m_column
= wxNOT_FOUND
;
218 wxColour col
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
219 m_penCurrent
= wxPen(col
, 1, wxSOLID
);
223 void AdjustDC(wxDC
& dc
);
226 DECLARE_DYNAMIC_CLASS(wxGenericDataViewHeaderWindow
)
227 DECLARE_EVENT_TABLE()
230 #endif // defined(__WXMSW__)
232 //-----------------------------------------------------------------------------
233 // wxDataViewRenameTimer
234 //-----------------------------------------------------------------------------
236 class wxDataViewRenameTimer
: public wxTimer
239 wxDataViewMainWindow
*m_owner
;
242 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
246 //-----------------------------------------------------------------------------
247 // wxDataViewTextCtrlWrapper: wraps a wxTextCtrl for inline editing
248 //-----------------------------------------------------------------------------
250 class wxDataViewTextCtrlWrapper
: public wxEvtHandler
253 // NB: text must be a valid object but not Create()d yet
254 wxDataViewTextCtrlWrapper( wxDataViewMainWindow
*owner
,
256 wxDataViewListModel
*model
,
257 unsigned int col
, unsigned int row
,
260 wxTextCtrl
*GetText() const { return m_text
; }
262 void AcceptChangesAndFinish();
265 void OnChar( wxKeyEvent
&event
);
266 void OnKeyUp( wxKeyEvent
&event
);
267 void OnKillFocus( wxFocusEvent
&event
);
269 bool AcceptChanges();
273 wxDataViewMainWindow
*m_owner
;
275 wxString m_startValue
;
276 wxDataViewListModel
*m_model
;
280 bool m_aboutToFinish
;
282 DECLARE_EVENT_TABLE()
285 //-----------------------------------------------------------------------------
286 // wxDataViewMainWindow
287 //-----------------------------------------------------------------------------
289 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
,
292 class wxDataViewMainWindow
: public wxWindow
295 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
297 const wxPoint
&pos
= wxDefaultPosition
,
298 const wxSize
&size
= wxDefaultSize
,
299 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
300 virtual ~wxDataViewMainWindow();
302 // notifications from wxDataViewListModel
305 bool RowInserted( unsigned int before
);
306 bool RowDeleted( unsigned int row
);
307 bool RowChanged( unsigned int row
);
308 bool ValueChanged( unsigned int col
, unsigned int row
);
309 bool RowsReordered( unsigned int *new_order
);
312 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
313 wxDataViewCtrl
*GetOwner() { return m_owner
; }
314 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
316 void OnPaint( wxPaintEvent
&event
);
317 void OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
);
318 void OnChar( wxKeyEvent
&event
);
319 void OnMouse( wxMouseEvent
&event
);
320 void OnSetFocus( wxFocusEvent
&event
);
321 void OnKillFocus( wxFocusEvent
&event
);
323 void UpdateDisplay();
324 void RecalculateDisplay();
325 void OnInternalIdle();
327 void OnRenameTimer();
328 void FinishEditing( wxTextCtrl
*text
);
330 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
332 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
333 void ChangeCurrentRow( unsigned int row
);
335 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); };
336 bool IsEmpty() { return GetRowCount() == 0; }
338 int GetCountPerPage() const;
339 int GetEndOfLastCol() const;
340 unsigned int GetFirstVisibleRow() const;
341 unsigned int GetLastVisibleRow() const;
342 unsigned int GetRowCount() const;
344 void Select( const wxArrayInt
& aSelections
);
345 void SelectAllRows( bool on
);
346 void SelectRow( unsigned int row
, bool on
);
347 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
348 void ReverseRowSelection( unsigned int row
);
349 bool IsRowSelected( unsigned int row
);
351 void RefreshRow( unsigned int row
);
352 void RefreshRows( unsigned int from
, unsigned int to
);
353 void RefreshRowsAfter( unsigned int firstRow
);
355 // returns the colour to be used for drawing the rules
356 wxColour
GetRuleColour() const
358 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
361 //void EnsureVisible( unsigned int row );
362 wxRect
GetLineRect( unsigned int row
) const;
365 wxDataViewCtrl
*m_owner
;
369 wxDataViewColumn
*m_currentCol
;
370 unsigned int m_currentRow
;
371 wxDataViewSelection m_selection
;
373 wxDataViewRenameTimer
*m_renameTimer
;
374 wxDataViewTextCtrlWrapper
*m_textctrlWrapper
;
382 // for double click logic
383 unsigned int m_lineLastClicked
,
384 m_lineBeforeLastClicked
,
385 m_lineSelectSingleOnUp
;
387 // the pen used to draw horiz/vertical rules
391 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
392 DECLARE_EVENT_TABLE()
395 // ---------------------------------------------------------
396 // wxGenericDataViewListModelNotifier
397 // ---------------------------------------------------------
399 class wxGenericDataViewListModelNotifier
: public wxDataViewListModelNotifier
402 wxGenericDataViewListModelNotifier( wxDataViewMainWindow
*mainWindow
)
403 { m_mainWindow
= mainWindow
; }
405 virtual bool RowAppended()
406 { return m_mainWindow
->RowAppended(); }
407 virtual bool RowPrepended()
408 { return m_mainWindow
->RowPrepended(); }
409 virtual bool RowInserted( unsigned int before
)
410 { return m_mainWindow
->RowInserted( before
); }
411 virtual bool RowDeleted( unsigned int row
)
412 { return m_mainWindow
->RowDeleted( row
); }
413 virtual bool RowChanged( unsigned int row
)
414 { return m_mainWindow
->RowChanged( row
); }
415 virtual bool ValueChanged( unsigned int col
, unsigned int row
)
416 { return m_mainWindow
->ValueChanged( col
, row
); }
417 virtual bool RowsReordered( unsigned int *new_order
)
418 { return m_mainWindow
->RowsReordered( new_order
); }
419 virtual bool Cleared()
420 { return m_mainWindow
->Cleared(); }
422 wxDataViewMainWindow
*m_mainWindow
;
425 // ---------------------------------------------------------
426 // wxDataViewRenderer
427 // ---------------------------------------------------------
429 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
431 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
432 wxDataViewCellMode mode
,
434 wxDataViewRendererBase( varianttype
, mode
, align
)
441 wxDataViewRenderer::~wxDataViewRenderer()
447 wxDC
*wxDataViewRenderer::GetDC()
451 if (GetOwner() == NULL
)
453 if (GetOwner()->GetOwner() == NULL
)
455 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
462 // ---------------------------------------------------------
463 // wxDataViewCustomRenderer
464 // ---------------------------------------------------------
466 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
468 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
469 wxDataViewCellMode mode
, int align
) :
470 wxDataViewRenderer( varianttype
, mode
, align
)
474 // ---------------------------------------------------------
475 // wxDataViewTextRenderer
476 // ---------------------------------------------------------
478 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
480 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
481 wxDataViewCellMode mode
, int align
) :
482 wxDataViewCustomRenderer( varianttype
, mode
, align
)
486 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
488 m_text
= value
.GetString();
493 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
498 bool wxDataViewTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
500 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
501 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
502 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
503 view
->GetForegroundColour();
505 dc
->SetTextForeground(col
);
506 dc
->DrawText( m_text
, cell
.x
, cell
.y
);
511 wxSize
wxDataViewTextRenderer::GetSize() const
513 const wxDataViewCtrl
*view
= GetView();
517 view
->GetTextExtent( m_text
, &x
, &y
);
518 return wxSize( x
, y
);
520 return wxSize(80,20);
523 // ---------------------------------------------------------
524 // wxDataViewBitmapRenderer
525 // ---------------------------------------------------------
527 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
529 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
530 wxDataViewCellMode mode
, int align
) :
531 wxDataViewCustomRenderer( varianttype
, mode
, align
)
535 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
537 if (value
.GetType() == wxT("wxBitmap"))
539 if (value
.GetType() == wxT("wxIcon"))
545 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
550 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
553 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
554 else if (m_icon
.Ok())
555 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
560 wxSize
wxDataViewBitmapRenderer::GetSize() const
563 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
564 else if (m_icon
.Ok())
565 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
567 return wxSize(16,16);
570 // ---------------------------------------------------------
571 // wxDataViewToggleRenderer
572 // ---------------------------------------------------------
574 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
576 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
577 wxDataViewCellMode mode
, int align
) :
578 wxDataViewCustomRenderer( varianttype
, mode
, align
)
583 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
585 m_toggle
= value
.GetBool();
590 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
595 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
597 // User wxRenderer here
600 rect
.x
= cell
.x
+ cell
.width
/2 - 10;
602 rect
.y
= cell
.y
+ cell
.height
/2 - 10;
607 flags
|= wxCONTROL_CHECKED
;
608 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
609 flags
|= wxCONTROL_DISABLED
;
611 wxRendererNative::Get().DrawCheckBox(
612 GetOwner()->GetOwner(),
620 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
621 wxDataViewListModel
*model
,
622 unsigned int col
, unsigned int row
)
624 bool value
= !m_toggle
;
625 wxVariant variant
= value
;
626 model
->SetValue( variant
, col
, row
);
627 model
->ValueChanged( col
, row
);
631 wxSize
wxDataViewToggleRenderer::GetSize() const
633 return wxSize(20,20);
636 // ---------------------------------------------------------
637 // wxDataViewProgressRenderer
638 // ---------------------------------------------------------
640 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
642 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
643 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
644 wxDataViewCustomRenderer( varianttype
, mode
, align
)
650 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
654 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
656 m_value
= (long) value
;
658 if (m_value
< 0) m_value
= 0;
659 if (m_value
> 100) m_value
= 100;
664 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
666 value
= (long) m_value
;
670 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
672 double pct
= (double)m_value
/ 100.0;
674 bar
.width
= (int)(cell
.width
* pct
);
675 dc
->SetPen( *wxTRANSPARENT_PEN
);
676 dc
->SetBrush( *wxBLUE_BRUSH
);
677 dc
->DrawRectangle( bar
);
679 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
680 dc
->SetPen( *wxBLACK_PEN
);
681 dc
->DrawRectangle( cell
);
686 wxSize
wxDataViewProgressRenderer::GetSize() const
688 return wxSize(40,12);
691 // ---------------------------------------------------------
692 // wxDataViewDateRenderer
693 // ---------------------------------------------------------
695 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
697 #if wxUSE_DATE_RENDERER_POPUP
699 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
702 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
703 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
) :
704 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
709 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
710 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
711 sizer
->Add( m_cal
, 1, wxGROW
);
716 void OnCalendar( wxCalendarEvent
&event
);
718 wxCalendarCtrl
*m_cal
;
719 wxDataViewListModel
*m_model
;
724 virtual void OnDismiss()
729 DECLARE_EVENT_TABLE()
732 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
733 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
736 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
738 wxDateTime date
= event
.GetDate();
739 wxVariant value
= date
;
740 m_model
->SetValue( value
, m_col
, m_row
);
741 m_model
->ValueChanged( m_col
, m_row
);
745 #endif // wxUSE_DATE_RENDERER_POPUP
747 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
749 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
750 wxDataViewCellMode mode
, int align
) :
751 wxDataViewCustomRenderer( varianttype
, mode
, align
)
755 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
757 m_date
= value
.GetDateTime();
762 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
768 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
770 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
771 wxString tmp
= m_date
.FormatDate();
772 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
777 wxSize
wxDataViewDateRenderer::GetSize() const
779 const wxDataViewCtrl
* view
= GetView();
780 wxString tmp
= m_date
.FormatDate();
782 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
783 return wxSize(x
,y
+d
);
786 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewListModel
*model
,
787 unsigned int col
, unsigned int row
)
790 model
->GetValue( variant
, col
, row
);
791 wxDateTime value
= variant
.GetDateTime();
793 #if wxUSE_DATE_RENDERER_POPUP
794 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
795 GetOwner()->GetOwner()->GetParent(), &value
, model
, col
, row
);
796 wxPoint pos
= wxGetMousePosition();
799 popup
->Popup( popup
->m_cal
);
800 #else // !wxUSE_DATE_RENDERER_POPUP
801 wxMessageBox(value
.Format());
802 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
806 // ---------------------------------------------------------
808 // ---------------------------------------------------------
810 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
812 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
813 unsigned int model_column
,
814 int width
, wxAlignment align
, int flags
) :
815 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
821 Init(width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
824 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
825 unsigned int model_column
,
826 int width
, wxAlignment align
, int flags
) :
827 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
832 Init(width
< 0 ? wxDVC_TOGGLE_DEFAULT_WIDTH
: width
);
835 wxDataViewColumn::~wxDataViewColumn()
839 void wxDataViewColumn::Init( int width
)
842 m_minWidth
= wxDVC_DEFAULT_MINWIDTH
;
845 void wxDataViewColumn::SetResizeable( bool resizeable
)
848 m_flags
|= wxDATAVIEW_COL_RESIZABLE
;
850 m_flags
&= ~wxDATAVIEW_COL_RESIZABLE
;
853 void wxDataViewColumn::SetHidden( bool hidden
)
856 m_flags
|= wxDATAVIEW_COL_HIDDEN
;
858 m_flags
&= ~wxDATAVIEW_COL_HIDDEN
;
860 // tell our owner to e.g. update its scrollbars:
862 GetOwner()->OnColumnChange();
865 void wxDataViewColumn::SetSortable( bool sortable
)
868 m_flags
|= wxDATAVIEW_COL_SORTABLE
;
870 m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
873 void wxDataViewColumn::SetSortOrder( bool WXUNUSED(ascending
) )
878 bool wxDataViewColumn::IsSortOrderAscending() const
884 void wxDataViewColumn::SetInternalWidth( int width
)
888 // the scrollbars of the wxDataViewCtrl needs to be recalculated!
889 if (m_owner
&& m_owner
->m_clientArea
)
890 m_owner
->m_clientArea
->RecalculateDisplay();
893 void wxDataViewColumn::SetWidth( int width
)
895 m_owner
->m_headerArea
->UpdateDisplay();
897 SetInternalWidth(width
);
901 //-----------------------------------------------------------------------------
902 // wxDataViewHeaderWindowBase
903 //-----------------------------------------------------------------------------
905 void wxDataViewHeaderWindowBase::SendEvent(wxEventType type
, unsigned int n
)
907 wxWindow
*parent
= GetParent();
908 wxDataViewEvent
le(type
, parent
->GetId());
910 le
.SetEventObject(parent
);
912 le
.SetDataViewColumn(GetColumn(n
));
913 le
.SetModel(GetOwner()->GetModel());
915 // for events created by wxDataViewHeaderWindow the
916 // row / value fields are not valid
918 parent
->GetEventHandler()->ProcessEvent(le
);
921 #if defined(__WXMSW__) && USE_NATIVE_HEADER_WINDOW
923 // implemented in msw/listctrl.cpp:
924 int WXDLLIMPEXP_CORE
wxMSWGetColumnClicked(NMHDR
*nmhdr
, POINT
*ptClick
);
926 IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindowMSW
, wxWindow
)
928 bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl
*parent
, wxWindowID id
,
929 const wxPoint
&pos
, const wxSize
&size
,
930 const wxString
&name
)
934 if ( !CreateControl(parent
, id
, pos
, size
, 0, wxDefaultValidator
, name
) )
937 int x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
938 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
939 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
940 h
= size
.y
== wxDefaultCoord
? 22 : size
.y
;
942 // create the native WC_HEADER window:
943 WXHWND hwndParent
= (HWND
)parent
->GetHandle();
944 WXDWORD msStyle
= WS_CHILD
| HDS_BUTTONS
| HDS_HORZ
| HDS_HOTTRACK
| HDS_FULLDRAG
;
945 m_hWnd
= CreateWindowEx(0,
956 wxLogLastError(_T("CreateWindowEx"));
960 // we need to subclass the m_hWnd to force wxWindow::HandleNotify
961 // to call wxDataViewHeaderWindow::MSWOnNotify
964 // the following is required to get the default win's font for
965 // header windows and must be done befor sending the HDM_LAYOUT msg
972 // Retrieve the bounding rectangle of the parent window's
973 // client area, and then request size and position values
974 // from the header control.
975 ::GetClientRect((HWND
)hwndParent
, &rcParent
);
979 if (!SendMessage((HWND
)m_hWnd
, HDM_LAYOUT
, 0, (LPARAM
) &hdl
))
981 wxLogLastError(_T("SendMessage"));
985 // Set the size, position, and visibility of the header control.
986 SetWindowPos((HWND
)m_hWnd
,
990 wp
.flags
| SWP_SHOWWINDOW
);
992 // set our size hints: wxDataViewCtrl will put this wxWindow inside
993 // a wxBoxSizer and in order to avoid super-big header windows,
994 // we need to set our height as fixed
995 SetMinSize(wxSize(-1, wp
.cy
));
996 SetMaxSize(wxSize(-1, wp
.cy
));
1001 wxDataViewHeaderWindowMSW::~wxDataViewHeaderWindow()
1006 void wxDataViewHeaderWindowMSW::UpdateDisplay()
1008 // remove old columns
1009 for (int j
=0, max
=Header_GetItemCount((HWND
)m_hWnd
); j
< max
; j
++)
1010 Header_DeleteItem((HWND
)m_hWnd
, 0);
1012 // add the updated array of columns to the header control
1013 unsigned int cols
= GetOwner()->GetColumnCount();
1014 unsigned int added
= 0;
1015 for (unsigned int i
= 0; i
< cols
; i
++)
1017 wxDataViewColumn
*col
= GetColumn( i
);
1018 if (col
->IsHidden())
1019 continue; // don't add it!
1022 hdi
.mask
= HDI_TEXT
| HDI_FORMAT
| HDI_WIDTH
;
1023 hdi
.pszText
= (wxChar
*) col
->GetTitle().c_str();
1024 hdi
.cxy
= col
->GetWidth();
1025 hdi
.cchTextMax
= sizeof(hdi
.pszText
)/sizeof(hdi
.pszText
[0]);
1026 hdi
.fmt
= HDF_LEFT
| HDF_STRING
;
1028 // lParam is reserved for application's use:
1029 // we store there the column index to use it later in MSWOnNotify
1030 // (since columns may have been hidden)
1031 hdi
.lParam
= (LPARAM
)i
;
1033 // the native wxMSW implementation of the header window
1034 // draws the column separator COLUMN_WIDTH_OFFSET pixels
1035 // on the right: to correct this effect we make the column
1036 // exactly COLUMN_WIDTH_OFFSET wider (for the first column):
1038 hdi
.cxy
+= COLUMN_WIDTH_OFFSET
;
1040 switch (col
->GetAlignment())
1043 hdi
.fmt
|= HDF_LEFT
;
1045 case wxALIGN_CENTER
:
1046 case wxALIGN_CENTER_HORIZONTAL
:
1047 hdi
.fmt
|= HDF_CENTER
;
1050 hdi
.fmt
|= HDF_RIGHT
;
1054 // such alignment is not allowed for the column header!
1058 SendMessage((HWND
)m_hWnd
, HDM_INSERTITEM
,
1059 (WPARAM
)added
, (LPARAM
)&hdi
);
1064 unsigned int wxDataViewHeaderWindowMSW::GetColumnIdxFromHeader(NMHEADER
*nmHDR
)
1068 // NOTE: we don't just return nmHDR->iItem because when there are
1069 // hidden columns, nmHDR->iItem may be different from
1070 // nmHDR->pitem->lParam
1072 if (nmHDR
->pitem
&& nmHDR
->pitem
->mask
& HDI_LPARAM
)
1074 idx
= (unsigned int)nmHDR
->pitem
->lParam
;
1079 item
.mask
= HDI_LPARAM
;
1080 Header_GetItem((HWND
)m_hWnd
, nmHDR
->iItem
, &item
);
1082 return (unsigned int)item
.lParam
;
1085 bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1087 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1089 // is it a message from the header?
1090 if ( nmhdr
->hwndFrom
!= (HWND
)m_hWnd
)
1091 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
1093 NMHEADER
*nmHDR
= (NMHEADER
*)nmhdr
;
1094 switch ( nmhdr
->code
)
1096 case HDN_BEGINTRACK
:
1097 // user has started to resize a column:
1098 // do we need to veto it?
1099 if (!GetColumn(nmHDR
->iItem
)->IsResizeable())
1107 // user has started to reorder a column
1110 case HDN_ITEMCHANGING
:
1111 if (nmHDR
->pitem
!= NULL
&&
1112 (nmHDR
->pitem
->mask
& HDI_WIDTH
) != 0)
1114 int minWidth
= GetColumnFromHeader(nmHDR
)->GetMinWidth();
1115 if (nmHDR
->pitem
->cxy
< minWidth
)
1117 // do not allow the user to resize this column under
1118 // its minimal width:
1124 case HDN_ITEMCHANGED
: // user is resizing a column
1125 case HDN_ENDTRACK
: // user has finished resizing a column
1126 case HDN_ENDDRAG
: // user has finished reordering a column
1128 // update the width of the modified column:
1129 if (nmHDR
->pitem
!= NULL
&&
1130 (nmHDR
->pitem
->mask
& HDI_WIDTH
) != 0)
1132 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1133 unsigned int w
= nmHDR
->pitem
->cxy
;
1134 wxDataViewColumn
*col
= GetColumn(idx
);
1136 // see UpdateDisplay() for more info about COLUMN_WIDTH_OFFSET
1137 if (idx
== 0 && w
> COLUMN_WIDTH_OFFSET
)
1138 w
-= COLUMN_WIDTH_OFFSET
;
1140 if (w
>= (unsigned)col
->GetMinWidth())
1141 col
->SetInternalWidth(w
);
1147 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1148 wxEventType evt
= nmHDR
->iButton
== 0 ?
1149 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
:
1150 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
;
1151 SendEvent(evt
, idx
);
1157 // NOTE: for some reason (i.e. for a bug in Windows)
1158 // the HDN_ITEMCLICK notification is not sent on
1159 // right clicks, so we need to handle NM_RCLICK
1162 int column
= wxMSWGetColumnClicked(nmhdr
, &ptClick
);
1163 if (column
!= wxNOT_FOUND
)
1166 item
.mask
= HDI_LPARAM
;
1167 Header_GetItem((HWND
)m_hWnd
, column
, &item
);
1169 // 'idx' may be different from 'column' if there are
1170 // hidden columns...
1171 unsigned int idx
= (unsigned int)item
.lParam
;
1172 SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
1178 case HDN_GETDISPINFOW
:
1179 // see wxListCtrl::MSWOnNotify for more info!
1182 case HDN_ITEMDBLCLICK
:
1184 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1185 int w
= GetOwner()->GetBestColumnWidth(idx
);
1187 // update the native control:
1189 ZeroMemory(&hd
, sizeof(hd
));
1190 hd
.mask
= HDI_WIDTH
;
1192 Header_SetItem(GetHwnd(),
1193 nmHDR
->iItem
, // NOTE: we don't want 'idx' here!
1196 // update the wxDataViewColumn class:
1197 GetColumn(idx
)->SetInternalWidth(w
);
1202 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
1208 void wxDataViewHeaderWindowMSW::ScrollWindow(int WXUNUSED(dx
), int WXUNUSED(dy
),
1209 const wxRect
*WXUNUSED(rect
))
1211 wxSize ourSz
= GetClientSize();
1212 wxSize ownerSz
= m_owner
->GetClientSize();
1214 // where should the (logical) origin of this window be placed?
1216 m_owner
->CalcUnscrolledPosition(0, 0, &x1
, &y1
);
1218 // put this window on top of our parent and
1219 SetWindowPos((HWND
)m_hWnd
, HWND_TOP
, -x1
, 0,
1220 ownerSz
.GetWidth() + x1
, ourSz
.GetHeight(),
1224 void wxDataViewHeaderWindowMSW::DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
1225 int WXUNUSED(w
), int WXUNUSED(h
),
1228 // the wxDataViewCtrl's internal wxBoxSizer will call this function when
1229 // the wxDataViewCtrl window gets resized: the following dummy call
1230 // to ScrollWindow() is required in order to get this header window
1231 // correctly repainted when it's (horizontally) scrolled:
1236 #else // !defined(__WXMSW__)
1238 IMPLEMENT_ABSTRACT_CLASS(wxGenericDataViewHeaderWindow
, wxWindow
)
1239 BEGIN_EVENT_TABLE(wxGenericDataViewHeaderWindow
, wxWindow
)
1240 EVT_PAINT (wxGenericDataViewHeaderWindow::OnPaint
)
1241 EVT_MOUSE_EVENTS (wxGenericDataViewHeaderWindow::OnMouse
)
1242 EVT_SET_FOCUS (wxGenericDataViewHeaderWindow::OnSetFocus
)
1245 bool wxGenericDataViewHeaderWindow::Create(wxDataViewCtrl
*parent
, wxWindowID id
,
1246 const wxPoint
&pos
, const wxSize
&size
,
1247 const wxString
&name
)
1251 if (!wxDataViewHeaderWindowBase::Create(parent
, id
, pos
, size
, name
))
1254 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1255 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1256 SetOwnForegroundColour( attr
.colFg
);
1257 SetOwnBackgroundColour( attr
.colBg
);
1259 SetOwnFont( attr
.font
);
1261 // set our size hints: wxDataViewCtrl will put this wxWindow inside
1262 // a wxBoxSizer and in order to avoid super-big header windows,
1263 // we need to set our height as fixed
1264 SetMinSize(wxSize(-1, HEADER_WINDOW_HEIGHT
));
1265 SetMaxSize(wxSize(-1, HEADER_WINDOW_HEIGHT
));
1270 void wxGenericDataViewHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1273 GetClientSize( &w
, &h
);
1275 wxAutoBufferedPaintDC
dc( this );
1277 dc
.SetBackground(GetBackgroundColour());
1281 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1284 m_owner
->GetViewStart( &x
, NULL
);
1286 // account for the horz scrollbar offset
1287 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1289 dc
.SetFont( GetFont() );
1291 unsigned int cols
= GetOwner()->GetColumnCount();
1294 for (i
= 0; i
< cols
; i
++)
1296 wxDataViewColumn
*col
= GetColumn( i
);
1297 if (col
->IsHidden())
1298 continue; // skip it!
1300 int cw
= col
->GetWidth();
1303 wxRendererNative::Get().DrawHeaderButton
1307 wxRect(xpos
, 0, cw
, ch
-1),
1308 m_parent
->IsEnabled() ? 0
1309 : (int)wxCONTROL_DISABLED
1312 // align as required the column title:
1314 wxSize titleSz
= dc
.GetTextExtent(col
->GetTitle());
1315 switch (col
->GetAlignment())
1318 x
+= HEADER_HORIZ_BORDER
;
1320 case wxALIGN_CENTER
:
1321 case wxALIGN_CENTER_HORIZONTAL
:
1322 x
+= (cw
- titleSz
.GetWidth() - 2 * HEADER_HORIZ_BORDER
)/2;
1325 x
+= cw
- titleSz
.GetWidth() - HEADER_HORIZ_BORDER
;
1329 // always center the title vertically:
1330 int y
= wxMax((ch
- titleSz
.GetHeight()) / 2, HEADER_VERT_BORDER
);
1332 dc
.SetClippingRegion( xpos
+HEADER_HORIZ_BORDER
,
1334 wxMax(cw
- 2 * HEADER_HORIZ_BORDER
, 1), // width
1335 wxMax(ch
- 2 * HEADER_VERT_BORDER
, 1)); // height
1336 dc
.DrawText( col
->GetTitle(), x
, y
);
1337 dc
.DestroyClippingRegion();
1343 void wxGenericDataViewHeaderWindow::OnSetFocus( wxFocusEvent
&event
)
1345 GetParent()->SetFocus();
1349 void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent
&event
)
1351 // we want to work with logical coords
1353 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1354 int y
= event
.GetY();
1358 // we don't draw the line beyond our window,
1359 // but we allow dragging it there
1361 GetClientSize( &w
, NULL
);
1362 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1365 // erase the line if it was drawn
1369 if (event
.ButtonUp())
1371 m_isDragging
= false;
1377 GetColumn(m_column
)->SetWidth(m_currentX
- m_minX
);
1380 GetOwner()->Refresh();
1384 m_currentX
= wxMax(m_minX
+ 7, x
);
1386 // draw in the new location
1387 if (m_currentX
< w
) DrawCurrent();
1391 else // not dragging
1394 m_column
= wxNOT_FOUND
;
1396 bool hit_border
= false;
1398 // end of the current column
1401 // find the column where this event occured
1402 int countCol
= m_owner
->GetColumnCount();
1403 for (int column
= 0; column
< countCol
; column
++)
1405 wxDataViewColumn
*p
= GetColumn(column
);
1408 continue; // skip if not shown
1410 xpos
+= p
->GetWidth();
1412 if ((abs(x
-xpos
) < 3) && (y
< 22))
1420 // inside the column
1427 if (m_column
== wxNOT_FOUND
)
1430 bool resizeable
= GetColumn(m_column
)->IsResizeable();
1431 if (event
.LeftDClick() && resizeable
)
1433 GetColumn(m_column
)->SetWidth(GetOwner()->GetBestColumnWidth(m_column
));
1436 else if (event
.LeftDown() || event
.RightUp())
1438 if (hit_border
&& event
.LeftDown() && resizeable
)
1440 m_isDragging
= true;
1445 else // click on a column
1447 wxEventType evt
= event
.LeftDown() ?
1448 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
:
1449 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
;
1450 SendEvent(evt
, m_column
);
1453 else if (event
.Moving())
1455 if (hit_border
&& resizeable
)
1456 m_currentCursor
= m_resizeCursor
;
1458 m_currentCursor
= wxSTANDARD_CURSOR
;
1460 SetCursor(*m_currentCursor
);
1465 void wxGenericDataViewHeaderWindow::DrawCurrent()
1467 int x1
= m_currentX
;
1469 ClientToScreen (&x1
, &y1
);
1471 int x2
= m_currentX
-1;
1473 ++x2
; // but why ????
1476 m_owner
->GetClientSize( NULL
, &y2
);
1477 m_owner
->ClientToScreen( &x2
, &y2
);
1480 dc
.SetLogicalFunction(wxINVERT
);
1481 dc
.SetPen(m_penCurrent
);
1482 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1484 dc
.DrawLine(x1
, y1
, x2
, y2
);
1487 void wxGenericDataViewHeaderWindow::AdjustDC(wxDC
& dc
)
1491 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1492 m_owner
->GetViewStart( &x
, NULL
);
1494 // shift the DC origin to match the position of the main window horizontal
1495 // scrollbar: this allows us to always use logical coords
1496 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1499 #endif // defined(__WXMSW__)
1501 //-----------------------------------------------------------------------------
1502 // wxDataViewRenameTimer
1503 //-----------------------------------------------------------------------------
1505 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1510 void wxDataViewRenameTimer::Notify()
1512 m_owner
->OnRenameTimer();
1515 //-----------------------------------------------------------------------------
1516 // wxDataViewTextCtrlWrapper: wraps a wxTextCtrl for inline editing
1517 //-----------------------------------------------------------------------------
1519 BEGIN_EVENT_TABLE(wxDataViewTextCtrlWrapper
, wxEvtHandler
)
1520 EVT_CHAR (wxDataViewTextCtrlWrapper::OnChar
)
1521 EVT_KEY_UP (wxDataViewTextCtrlWrapper::OnKeyUp
)
1522 EVT_KILL_FOCUS (wxDataViewTextCtrlWrapper::OnKillFocus
)
1525 wxDataViewTextCtrlWrapper::wxDataViewTextCtrlWrapper(
1526 wxDataViewMainWindow
*owner
,
1528 wxDataViewListModel
*model
,
1529 unsigned int col
, unsigned int row
,
1539 m_aboutToFinish
= false;
1542 model
->GetValue( value
, col
, row
);
1543 m_startValue
= value
.GetString();
1545 m_owner
->GetOwner()->CalcScrolledPosition(
1546 rectLabel
.x
, rectLabel
.y
, &rectLabel
.x
, &rectLabel
.y
);
1548 m_text
->Create( owner
, wxID_ANY
, m_startValue
,
1549 wxPoint(rectLabel
.x
-2,rectLabel
.y
-2),
1550 wxSize(rectLabel
.width
+7,rectLabel
.height
+4) );
1553 m_text
->PushEventHandler(this);
1556 void wxDataViewTextCtrlWrapper::AcceptChangesAndFinish()
1558 m_aboutToFinish
= true;
1560 // Notify the owner about the changes
1563 // Even if vetoed, close the control (consistent with MSW)
1567 void wxDataViewTextCtrlWrapper::OnChar( wxKeyEvent
&event
)
1569 switch ( event
.m_keyCode
)
1572 AcceptChangesAndFinish();
1576 // m_owner->OnRenameCancelled( m_itemEdited );
1585 void wxDataViewTextCtrlWrapper::OnKeyUp( wxKeyEvent
&event
)
1593 // auto-grow the textctrl
1594 wxSize parentSize
= m_owner
->GetSize();
1595 wxPoint myPos
= m_text
->GetPosition();
1596 wxSize mySize
= m_text
->GetSize();
1598 m_text
->GetTextExtent(m_text
->GetValue() + _T("MM"), &sx
, &sy
);
1599 if (myPos
.x
+ sx
> parentSize
.x
)
1600 sx
= parentSize
.x
- myPos
.x
;
1603 m_text
->SetSize(sx
, wxDefaultCoord
);
1608 void wxDataViewTextCtrlWrapper::OnKillFocus( wxFocusEvent
&event
)
1610 if ( !m_finished
&& !m_aboutToFinish
)
1613 //if ( !AcceptChanges() )
1614 // m_owner->OnRenameCancelled( m_itemEdited );
1619 // We must let the native text control handle focus
1623 bool wxDataViewTextCtrlWrapper::AcceptChanges()
1625 const wxString value
= m_text
->GetValue();
1627 if ( value
== m_startValue
)
1628 // nothing changed, always accept
1631 // if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
1632 // vetoed by the user
1635 // accepted, do rename the item
1638 m_model
->SetValue( variant
, m_col
, m_row
);
1639 m_model
->ValueChanged( m_col
, m_row
);
1644 void wxDataViewTextCtrlWrapper::Finish()
1650 m_text
->RemoveEventHandler(this);
1651 m_owner
->FinishEditing(m_text
);
1654 wxPendingDelete
.Append( this );
1658 //-----------------------------------------------------------------------------
1659 // wxDataViewMainWindow
1660 //-----------------------------------------------------------------------------
1662 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1664 if (row1
> row2
) return 1;
1665 if (row1
== row2
) return 0;
1670 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1672 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1673 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1674 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1675 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1676 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1677 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1680 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1681 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
1682 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
, name
),
1683 m_selection( wxDataViewSelectionCmp
)
1688 m_lastOnSame
= false;
1689 m_renameTimer
= new wxDataViewRenameTimer( this );
1690 m_textctrlWrapper
= NULL
;
1692 // TODO: user better initial values/nothing selected
1693 m_currentCol
= NULL
;
1696 // TODO: we need to calculate this smartly
1703 wxASSERT(m_lineHeight
> 2*PADDING_TOPBOTTOM
);
1706 m_dragStart
= wxPoint(0,0);
1707 m_lineLastClicked
= (unsigned int) -1;
1708 m_lineBeforeLastClicked
= (unsigned int) -1;
1709 m_lineSelectSingleOnUp
= (unsigned int) -1;
1713 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1714 SetBackgroundColour( *wxWHITE
);
1716 m_penRule
= wxPen(GetRuleColour(), 1, wxSOLID
);
1721 wxDataViewMainWindow::~wxDataViewMainWindow()
1723 delete m_renameTimer
;
1726 void wxDataViewMainWindow::OnRenameTimer()
1728 // We have to call this here because changes may just have
1729 // been made and no screen update taken place.
1735 unsigned int cols
= GetOwner()->GetColumnCount();
1737 for (i
= 0; i
< cols
; i
++)
1739 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
1741 continue; // skip it!
1743 if (c
== m_currentCol
)
1745 xpos
+= c
->GetWidth();
1747 wxRect
labelRect( xpos
, m_currentRow
* m_lineHeight
,
1748 m_currentCol
->GetWidth(), m_lineHeight
);
1750 wxClassInfo
*textControlClass
= CLASSINFO(wxTextCtrl
);
1752 wxTextCtrl
* const text
= (wxTextCtrl
*)textControlClass
->CreateObject();
1753 m_textctrlWrapper
= new wxDataViewTextCtrlWrapper(this, text
, GetOwner()->GetModel(),
1754 m_currentCol
->GetModelColumn(), m_currentRow
, labelRect
);
1757 void wxDataViewMainWindow::FinishEditing( wxTextCtrl
*text
)
1760 m_textctrlWrapper
= NULL
;
1762 // SetFocusIgnoringChildren();
1765 bool wxDataViewMainWindow::RowAppended()
1770 bool wxDataViewMainWindow::RowPrepended()
1775 bool wxDataViewMainWindow::RowInserted( unsigned int WXUNUSED(before
) )
1780 bool wxDataViewMainWindow::RowDeleted( unsigned int WXUNUSED(row
) )
1785 bool wxDataViewMainWindow::RowChanged( unsigned int WXUNUSED(row
) )
1790 bool wxDataViewMainWindow::ValueChanged( unsigned int WXUNUSED(col
), unsigned int row
)
1792 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
1793 #define MAX_VIRTUAL_WIDTH 100000
1795 wxRect
rect( 0, row
*m_lineHeight
, MAX_VIRTUAL_WIDTH
, m_lineHeight
);
1796 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
1797 Refresh( true, &rect
);
1802 bool wxDataViewMainWindow::RowsReordered( unsigned int *WXUNUSED(new_order
) )
1809 bool wxDataViewMainWindow::Cleared()
1814 void wxDataViewMainWindow::UpdateDisplay()
1819 void wxDataViewMainWindow::OnInternalIdle()
1821 wxWindow::OnInternalIdle();
1825 RecalculateDisplay();
1830 void wxDataViewMainWindow::RecalculateDisplay()
1832 wxDataViewListModel
*model
= GetOwner()->GetModel();
1839 int width
= GetEndOfLastCol();
1840 int height
= model
->GetRowCount() * m_lineHeight
;
1842 SetVirtualSize( width
, height
);
1843 GetOwner()->SetScrollRate( 10, m_lineHeight
);
1848 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
1850 wxWindow::ScrollWindow( dx
, dy
, rect
);
1852 if (GetOwner()->m_headerArea
)
1853 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
1856 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1858 wxDataViewListModel
*model
= GetOwner()->GetModel();
1859 wxAutoBufferedPaintDC
dc( this );
1862 dc
.SetBackground(GetBackgroundColour());
1864 GetOwner()->PrepareDC( dc
);
1865 dc
.SetFont( GetFont() );
1867 wxRect update
= GetUpdateRegion().GetBox();
1868 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
1870 // compute which items needs to be redrawn
1871 unsigned int item_start
= wxMax( 0, (update
.y
/ m_lineHeight
) );
1872 unsigned int item_count
=
1873 wxMin( (int)(((update
.y
+ update
.height
) / m_lineHeight
) - item_start
+ 1),
1874 (int)(model
->GetRowCount() - item_start
) );
1875 unsigned int item_last
= item_start
+ item_count
;
1877 // compute which columns needs to be redrawn
1878 unsigned int cols
= GetOwner()->GetColumnCount();
1879 unsigned int col_start
= 0;
1880 unsigned int x_start
= 0;
1881 for (x_start
= 0; col_start
< cols
; col_start
++)
1883 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_start
);
1884 if (col
->IsHidden())
1885 continue; // skip it!
1887 unsigned int w
= col
->GetWidth();
1888 if (x_start
+w
>= (unsigned int)update
.x
)
1894 unsigned int col_last
= col_start
;
1895 unsigned int x_last
= x_start
;
1896 for (; col_last
< cols
; col_last
++)
1898 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_last
);
1899 if (col
->IsHidden())
1900 continue; // skip it!
1902 if (x_last
> (unsigned int)update
.GetRight())
1905 x_last
+= col
->GetWidth();
1908 // Draw horizontal rules if required
1909 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
1911 dc
.SetPen(m_penRule
);
1912 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1914 for (unsigned int i
= item_start
; i
<= item_last
+1; i
++)
1916 int y
= i
* m_lineHeight
;
1917 dc
.DrawLine(x_start
, y
, x_last
, y
);
1921 // Draw vertical rules if required
1922 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
1924 dc
.SetPen(m_penRule
);
1925 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1928 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1930 wxDataViewColumn
*col
= GetOwner()->GetColumn(i
);
1931 if (col
->IsHidden())
1932 continue; // skip it
1934 dc
.DrawLine(x
, item_start
* m_lineHeight
,
1935 x
, item_last
* m_lineHeight
);
1937 x
+= col
->GetWidth();
1940 // Draw last vertical rule
1941 dc
.DrawLine(x
, item_start
* m_lineHeight
,
1942 x
, item_last
* m_lineHeight
);
1945 // redraw the background for the items which are selected/current
1946 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1948 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
1949 if (selected
|| item
== m_currentRow
)
1951 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
1952 if (item
== m_currentRow
)
1953 flags
|= wxCONTROL_CURRENT
;
1955 flags
|= wxCONTROL_FOCUSED
;
1957 wxRect
rect( x_start
, item
*m_lineHeight
, x_last
, m_lineHeight
);
1958 wxRendererNative::Get().DrawItemSelectionRect
1968 // redraw all cells for all rows which must be repainted and for all columns
1970 cell_rect
.x
= x_start
;
1971 cell_rect
.height
= m_lineHeight
; // -1 is for the horizontal rules
1972 for (unsigned int i
= col_start
; i
< col_last
; i
++)
1974 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
1975 wxDataViewRenderer
*cell
= col
->GetRenderer();
1976 cell_rect
.width
= col
->GetWidth();
1978 if (col
->IsHidden())
1979 continue; // skipt it!
1981 for (unsigned int item
= item_start
; item
< item_last
; item
++)
1983 // get the cell value and set it into the renderer
1985 model
->GetValue( value
, col
->GetModelColumn(), item
);
1986 cell
->SetValue( value
);
1988 // update the y offset
1989 cell_rect
.y
= item
* m_lineHeight
;
1991 // cannot be bigger than allocated space
1992 wxSize size
= cell
->GetSize();
1993 size
.x
= wxMin( size
.x
+ 2*PADDING_RIGHTLEFT
, cell_rect
.width
);
1994 size
.y
= wxMin( size
.y
+ 2*PADDING_TOPBOTTOM
, cell_rect
.height
);
1996 wxRect
item_rect(cell_rect
.GetTopLeft(), size
);
1997 int align
= cell
->GetAlignment();
1999 // horizontal alignment:
2000 item_rect
.x
= cell_rect
.x
;
2001 if (align
& wxALIGN_CENTER_HORIZONTAL
)
2002 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
2003 else if (align
& wxALIGN_RIGHT
)
2004 item_rect
.x
= cell_rect
.x
+ cell_rect
.width
- size
.x
;
2005 //else: wxALIGN_LEFT is the default
2007 // vertical alignment:
2008 item_rect
.y
= cell_rect
.y
;
2009 if (align
& wxALIGN_CENTER_VERTICAL
)
2010 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
2011 else if (align
& wxALIGN_BOTTOM
)
2012 item_rect
.y
= cell_rect
.y
+ cell_rect
.height
- size
.y
;
2013 //else: wxALIGN_TOP is the default
2016 item_rect
.x
+= PADDING_RIGHTLEFT
;
2017 item_rect
.y
+= PADDING_TOPBOTTOM
;
2018 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
2019 item_rect
.height
= size
.y
- 2 * PADDING_TOPBOTTOM
;
2022 if (m_selection
.Index(item
) != wxNOT_FOUND
)
2023 state
|= wxDATAVIEW_CELL_SELECTED
;
2025 // TODO: it would be much more efficient to create a clipping
2026 // region for the entire column being rendered (in the OnPaint
2027 // of wxDataViewMainWindow) instead of a single clip region for
2028 // each cell. However it would mean that each renderer should
2029 // respect the given wxRect's top & bottom coords, eventually
2030 // violating only the left & right coords - however the user can
2031 // make its own renderer and thus we cannot be sure of that.
2032 dc
.SetClippingRegion( item_rect
);
2033 cell
->Render( item_rect
, &dc
, state
);
2034 dc
.DestroyClippingRegion();
2037 cell_rect
.x
+= cell_rect
.width
;
2041 int wxDataViewMainWindow::GetCountPerPage() const
2043 wxSize size
= GetClientSize();
2044 return size
.y
/ m_lineHeight
;
2047 int wxDataViewMainWindow::GetEndOfLastCol() const
2051 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2053 const wxDataViewColumn
*c
=
2054 wx_const_cast(wxDataViewCtrl
*, GetOwner())->GetColumn( i
);
2057 width
+= c
->GetWidth();
2062 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2066 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2068 return y
/ m_lineHeight
;
2071 unsigned int wxDataViewMainWindow::GetLastVisibleRow() const
2073 wxSize client_size
= GetClientSize();
2074 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2075 &client_size
.x
, &client_size
.y
);
2077 return wxMin( GetRowCount()-1, ((unsigned)client_size
.y
/m_lineHeight
)+1 );
2080 unsigned int wxDataViewMainWindow::GetRowCount() const
2082 return wx_const_cast(wxDataViewCtrl
*, GetOwner())->GetModel()->GetRowCount();
2085 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
2092 void wxDataViewMainWindow::SelectAllRows( bool on
)
2099 m_selection
.Clear();
2100 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2101 m_selection
.Add( i
);
2106 unsigned int first_visible
= GetFirstVisibleRow();
2107 unsigned int last_visible
= GetLastVisibleRow();
2109 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2111 unsigned int row
= m_selection
[i
];
2112 if ((row
>= first_visible
) && (row
<= last_visible
))
2115 m_selection
.Clear();
2119 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
2121 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2125 m_selection
.Add( row
);
2133 m_selection
.Remove( row
);
2139 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2143 unsigned int tmp
= from
;
2149 for (i
= from
; i
<= to
; i
++)
2151 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2154 m_selection
.Add( i
);
2159 m_selection
.Remove( i
);
2162 RefreshRows( from
, to
);
2165 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2167 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2169 int n
= aSelections
[i
];
2171 m_selection
.Add( n
);
2176 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2178 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2179 m_selection
.Add( row
);
2181 m_selection
.Remove( row
);
2185 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2187 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2190 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2192 wxRect
rect( 0, row
*m_lineHeight
, GetEndOfLastCol(), m_lineHeight
);
2193 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2195 wxSize client_size
= GetClientSize();
2196 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2197 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2198 if (intersect_rect
.width
> 0)
2199 Refresh( true, &intersect_rect
);
2202 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2206 unsigned int tmp
= to
;
2211 wxRect
rect( 0, from
*m_lineHeight
, GetEndOfLastCol(), (to
-from
+1) * m_lineHeight
);
2212 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2214 wxSize client_size
= GetClientSize();
2215 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2216 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2217 if (intersect_rect
.width
> 0)
2218 Refresh( true, &intersect_rect
);
2221 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2223 unsigned int count
= GetRowCount();
2224 if (firstRow
> count
)
2227 wxRect
rect( 0, firstRow
*m_lineHeight
, GetEndOfLastCol(), count
* m_lineHeight
);
2228 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2230 wxSize client_size
= GetClientSize();
2231 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2232 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2233 if (intersect_rect
.width
> 0)
2234 Refresh( true, &intersect_rect
);
2237 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2239 wxCHECK_RET( newCurrent
< GetRowCount(),
2240 _T("invalid item index in OnArrowChar()") );
2242 // if there is no selection, we cannot move it anywhere
2243 if (!HasCurrentRow())
2246 unsigned int oldCurrent
= m_currentRow
;
2248 // in single selection we just ignore Shift as we can't select several
2250 if ( event
.ShiftDown() && !IsSingleSel() )
2252 RefreshRow( oldCurrent
);
2254 ChangeCurrentRow( newCurrent
);
2256 // select all the items between the old and the new one
2257 if ( oldCurrent
> newCurrent
)
2259 newCurrent
= oldCurrent
;
2260 oldCurrent
= m_currentRow
;
2263 SelectRows( oldCurrent
, newCurrent
, true );
2267 RefreshRow( oldCurrent
);
2269 // all previously selected items are unselected unless ctrl is held
2270 if ( !event
.ControlDown() )
2271 SelectAllRows(false);
2273 ChangeCurrentRow( newCurrent
);
2275 if ( !event
.ControlDown() )
2276 SelectRow( m_currentRow
, true );
2278 RefreshRow( m_currentRow
);
2281 //EnsureVisible( m_currentRow );
2284 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2288 rect
.y
= m_lineHeight
* row
;
2289 rect
.width
= GetEndOfLastCol();
2290 rect
.height
= m_lineHeight
;
2295 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
2297 if (event
.GetKeyCode() == WXK_TAB
)
2299 wxNavigationKeyEvent nevent
;
2300 nevent
.SetWindowChange( event
.ControlDown() );
2301 nevent
.SetDirection( !event
.ShiftDown() );
2302 nevent
.SetEventObject( GetParent()->GetParent() );
2303 nevent
.SetCurrentFocus( m_parent
);
2304 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
))
2308 // no item -> nothing to do
2309 if (!HasCurrentRow())
2315 // don't use m_linesPerPage directly as it might not be computed yet
2316 const int pageSize
= GetCountPerPage();
2317 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
2319 switch ( event
.GetKeyCode() )
2322 if ( m_currentRow
> 0 )
2323 OnArrowChar( m_currentRow
- 1, event
);
2327 if ( m_currentRow
< GetRowCount() - 1 )
2328 OnArrowChar( m_currentRow
+ 1, event
);
2333 OnArrowChar( GetRowCount() - 1, event
);
2338 OnArrowChar( 0, event
);
2343 int steps
= pageSize
- 1;
2344 int index
= m_currentRow
- steps
;
2348 OnArrowChar( index
, event
);
2354 int steps
= pageSize
- 1;
2355 unsigned int index
= m_currentRow
+ steps
;
2356 unsigned int count
= GetRowCount();
2357 if ( index
>= count
)
2360 OnArrowChar( index
, event
);
2369 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
2371 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
2373 // let the base handle mouse wheel events.
2378 int x
= event
.GetX();
2379 int y
= event
.GetY();
2380 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2382 wxDataViewColumn
*col
= NULL
;
2385 unsigned int cols
= GetOwner()->GetColumnCount();
2387 for (i
= 0; i
< cols
; i
++)
2389 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
2391 continue; // skip it!
2393 if (x
< xpos
+ c
->GetWidth())
2398 xpos
+= c
->GetWidth();
2402 wxDataViewRenderer
*cell
= col
->GetRenderer();
2404 unsigned int current
= y
/ m_lineHeight
;
2406 if ((current
> GetRowCount()) || (x
> GetEndOfLastCol()))
2408 // Unselect all if below the last row ?
2412 wxDataViewListModel
*model
= GetOwner()->GetModel();
2414 if (event
.Dragging())
2416 if (m_dragCount
== 0)
2418 // we have to report the raw, physical coords as we want to be
2419 // able to call HitTest(event.m_pointDrag) from the user code to
2420 // get the item being dragged
2421 m_dragStart
= event
.GetPosition();
2426 if (m_dragCount
!= 3)
2429 if (event
.LeftIsDown())
2431 // Notify cell about drag
2440 bool forceClick
= false;
2442 if (event
.ButtonDClick())
2444 m_renameTimer
->Stop();
2445 m_lastOnSame
= false;
2448 if (event
.LeftDClick())
2450 if ( current
== m_lineLastClicked
)
2452 if (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
)
2455 model
->GetValue( value
, col
->GetModelColumn(), current
);
2456 cell
->SetValue( value
);
2457 wxRect
cell_rect( xpos
, current
* m_lineHeight
,
2458 col
->GetWidth(), m_lineHeight
);
2459 cell
->Activate( cell_rect
, model
, col
->GetModelColumn(), current
);
2465 // The first click was on another item, so don't interpret this as
2466 // a double click, but as a simple click instead
2473 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
2475 // select single line
2476 SelectAllRows( false );
2477 SelectRow( m_lineSelectSingleOnUp
, true );
2482 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
2483 (cell
->GetMode() == wxDATAVIEW_CELL_EDITABLE
) )
2485 m_renameTimer
->Start( 100, true );
2489 m_lastOnSame
= false;
2490 m_lineSelectSingleOnUp
= (unsigned int)-1;
2494 // This is necessary, because after a DnD operation in
2495 // from and to ourself, the up event is swallowed by the
2496 // DnD code. So on next non-up event (which means here and
2497 // now) m_lineSelectSingleOnUp should be reset.
2498 m_lineSelectSingleOnUp
= (unsigned int)-1;
2501 if (event
.RightDown())
2503 m_lineBeforeLastClicked
= m_lineLastClicked
;
2504 m_lineLastClicked
= current
;
2506 // If the item is already selected, do not update the selection.
2507 // Multi-selections should not be cleared if a selected item is clicked.
2508 if (!IsRowSelected(current
))
2510 SelectAllRows(false);
2511 ChangeCurrentRow(current
);
2512 SelectRow(m_currentRow
,true);
2515 // notify cell about right click
2518 // Allow generation of context menu event
2521 else if (event
.MiddleDown())
2523 // notify cell about middle click
2526 if (event
.LeftDown() || forceClick
)
2532 m_lineBeforeLastClicked
= m_lineLastClicked
;
2533 m_lineLastClicked
= current
;
2535 unsigned int oldCurrentRow
= m_currentRow
;
2536 bool oldWasSelected
= IsRowSelected(m_currentRow
);
2538 bool cmdModifierDown
= event
.CmdDown();
2539 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
2541 if ( IsSingleSel() || !IsRowSelected(current
) )
2543 SelectAllRows( false );
2545 ChangeCurrentRow(current
);
2547 SelectRow(m_currentRow
,true);
2549 else // multi sel & current is highlighted & no mod keys
2551 m_lineSelectSingleOnUp
= current
;
2552 ChangeCurrentRow(current
); // change focus
2555 else // multi sel & either ctrl or shift is down
2557 if (cmdModifierDown
)
2559 ChangeCurrentRow(current
);
2561 ReverseRowSelection(m_currentRow
);
2563 else if (event
.ShiftDown())
2565 ChangeCurrentRow(current
);
2567 unsigned int lineFrom
= oldCurrentRow
,
2570 if ( lineTo
< lineFrom
)
2573 lineFrom
= m_currentRow
;
2576 SelectRows(lineFrom
, lineTo
, true);
2578 else // !ctrl, !shift
2580 // test in the enclosing if should make it impossible
2581 wxFAIL_MSG( _T("how did we get here?") );
2585 if (m_currentRow
!= oldCurrentRow
)
2586 RefreshRow( oldCurrentRow
);
2588 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
2590 // Update selection here...
2593 m_lastOnSame
= !forceClick
&& ((col
== oldCurrentCol
) &&
2594 (current
== oldCurrentRow
)) && oldWasSelected
;
2598 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
2602 if (HasCurrentRow())
2608 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
2612 if (HasCurrentRow())
2618 //-----------------------------------------------------------------------------
2620 //-----------------------------------------------------------------------------
2622 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
2624 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
2625 EVT_SIZE(wxDataViewCtrl::OnSize
)
2628 wxDataViewCtrl::~wxDataViewCtrl()
2631 GetModel()->RemoveNotifier( m_notifier
);
2634 void wxDataViewCtrl::Init()
2639 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
2640 const wxPoint
& pos
, const wxSize
& size
,
2641 long style
, const wxValidator
& validator
)
2643 if (!wxControl::Create( parent
, id
, pos
, size
,
2644 style
| wxScrolledWindowStyle
|wxSUNKEN_BORDER
, validator
))
2650 MacSetClipChildren( true ) ;
2653 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
2655 if (HasFlag(wxDV_NO_HEADER
))
2656 m_headerArea
= NULL
;
2658 m_headerArea
= new wxDataViewHeaderWindow( this, wxID_ANY
);
2660 SetTargetWindow( m_clientArea
);
2662 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
2664 sizer
->Add( m_headerArea
, 0, wxGROW
);
2665 sizer
->Add( m_clientArea
, 1, wxGROW
);
2672 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
2676 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
2679 // we need to process arrows ourselves for scrolling
2680 if ( nMsg
== WM_GETDLGCODE
)
2682 rc
|= DLGC_WANTARROWS
;
2690 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2692 // We need to override OnSize so that our scrolled
2693 // window a) does call Layout() to use sizers for
2694 // positioning the controls but b) does not query
2695 // the sizer for their size and use that for setting
2696 // the scrollable area as set that ourselves by
2697 // calling SetScrollbar() further down.
2704 bool wxDataViewCtrl::AssociateModel( wxDataViewListModel
*model
)
2706 if (!wxDataViewCtrlBase::AssociateModel( model
))
2709 m_notifier
= new wxGenericDataViewListModelNotifier( m_clientArea
);
2711 model
->AddNotifier( m_notifier
);
2713 m_clientArea
->UpdateDisplay();
2718 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
2720 if (!wxDataViewCtrlBase::AppendColumn(col
))
2727 void wxDataViewCtrl::OnColumnChange()
2730 m_headerArea
->UpdateDisplay();
2732 m_clientArea
->UpdateDisplay();
2735 void wxDataViewCtrl::SetSelection( int row
)
2737 m_clientArea
->SelectRow(row
, true);
2740 void wxDataViewCtrl::SetSelectionRange( unsigned int from
, unsigned int to
)
2742 m_clientArea
->SelectRows(from
, to
, true);
2745 void wxDataViewCtrl::SetSelections( const wxArrayInt
& aSelections
)
2747 m_clientArea
->Select(aSelections
);
2750 void wxDataViewCtrl::Unselect( unsigned int WXUNUSED(row
) )
2755 bool wxDataViewCtrl::IsSelected( unsigned int WXUNUSED(row
) ) const
2762 int wxDataViewCtrl::GetSelection() const
2769 int wxDataViewCtrl::GetSelections(wxArrayInt
& WXUNUSED(aSelections
) ) const
2777 // !wxUSE_GENERICDATAVIEWCTRL
2780 // wxUSE_DATAVIEWCTRL