1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGrid and related classes
4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
8 // Copyright: (c) Michael Bedward (mbedward@ozemail.com.au)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "grid.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
25 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
31 #include "wx/dcclient.h"
32 #include "wx/settings.h"
35 #include "wx/layout.h"
38 #include "wx/generic/grid.h"
40 // ----------------------------------------------------------------------------
41 // array classes instantiation
42 // ----------------------------------------------------------------------------
44 struct wxGridCellWithAttr
46 wxGridCellWithAttr(int row
, int col
, const wxGridCellAttr
*pAttr
)
47 : coords(row
, col
), attr(*pAttr
)
51 wxGridCellCoords coords
;
55 WX_DECLARE_OBJARRAY(wxGridCellWithAttr
, wxGridCellWithAttrArray
);
57 #include "wx/arrimpl.cpp"
59 WX_DEFINE_OBJARRAY(wxGridCellCoordsArray
)
60 WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray
)
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 class WXDLLEXPORT wxGridRowLabelWindow
: public wxWindow
69 wxGridRowLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
70 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
71 const wxPoint
&pos
, const wxSize
&size
);
76 void OnPaint( wxPaintEvent
& event
);
77 void OnMouseEvent( wxMouseEvent
& event
);
78 void OnKeyDown( wxKeyEvent
& event
);
80 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
85 class WXDLLEXPORT wxGridColLabelWindow
: public wxWindow
88 wxGridColLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
89 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
90 const wxPoint
&pos
, const wxSize
&size
);
95 void OnPaint( wxPaintEvent
&event
);
96 void OnMouseEvent( wxMouseEvent
& event
);
97 void OnKeyDown( wxKeyEvent
& event
);
99 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
100 DECLARE_EVENT_TABLE()
104 class WXDLLEXPORT wxGridCornerLabelWindow
: public wxWindow
107 wxGridCornerLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
108 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
109 const wxPoint
&pos
, const wxSize
&size
);
114 void OnMouseEvent( wxMouseEvent
& event
);
115 void OnKeyDown( wxKeyEvent
& event
);
116 void OnPaint( wxPaintEvent
& event
);
118 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
119 DECLARE_EVENT_TABLE()
122 class WXDLLEXPORT wxGridWindow
: public wxPanel
127 m_owner
= (wxGrid
*)NULL
;
128 m_rowLabelWin
= (wxGridRowLabelWindow
*)NULL
;
129 m_colLabelWin
= (wxGridColLabelWindow
*)NULL
;
132 wxGridWindow( wxGrid
*parent
,
133 wxGridRowLabelWindow
*rowLblWin
,
134 wxGridColLabelWindow
*colLblWin
,
135 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
138 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
142 wxGridRowLabelWindow
*m_rowLabelWin
;
143 wxGridColLabelWindow
*m_colLabelWin
;
145 void OnPaint( wxPaintEvent
&event
);
146 void OnMouseEvent( wxMouseEvent
& event
);
147 void OnKeyDown( wxKeyEvent
& );
149 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
150 DECLARE_EVENT_TABLE()
153 // the internal data representation used by wxGridCellAttrProvider
155 // TODO make it more efficient
156 class WXDLLEXPORT wxGridCellAttrProviderData
159 void SetAttr(const wxGridCellAttr
*attr
, int row
, int col
);
160 wxGridCellAttr
*GetAttr(int row
, int col
) const;
163 // searches for the attr for given cell, returns wxNOT_FOUND if not found
164 int FindIndex(int row
, int col
) const;
166 wxGridCellWithAttrArray m_attrs
;
169 // ----------------------------------------------------------------------------
170 // conditional compilation
171 // ----------------------------------------------------------------------------
173 #ifndef WXGRID_DRAW_LINES
174 #define WXGRID_DRAW_LINES 1
177 //////////////////////////////////////////////////////////////////////
179 wxGridCellCoords
wxGridNoCellCoords( -1, -1 );
180 wxRect
wxGridNoCellRect( -1, -1, -1, -1 );
183 // TODO: fixed so far - make configurable later (and also different for x/y)
184 static const size_t GRID_SCROLL_LINE
= 10;
186 // ----------------------------------------------------------------------------
187 // wxGridCellAttrProviderData
188 // ----------------------------------------------------------------------------
190 void wxGridCellAttrProviderData::SetAttr(const wxGridCellAttr
*attr
,
193 int n
= FindIndex(row
, col
);
194 if ( n
== wxNOT_FOUND
)
197 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
203 // change the attribute
204 m_attrs
[(size_t)n
].attr
= *attr
;
208 // remove this attribute
209 m_attrs
.RemoveAt((size_t)n
);
216 wxGridCellAttr
*wxGridCellAttrProviderData::GetAttr(int row
, int col
) const
218 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
220 int n
= FindIndex(row
, col
);
221 if ( n
!= wxNOT_FOUND
)
223 attr
= new wxGridCellAttr(m_attrs
[(size_t)n
].attr
);
229 int wxGridCellAttrProviderData::FindIndex(int row
, int col
) const
231 size_t count
= m_attrs
.GetCount();
232 for ( size_t n
= 0; n
< count
; n
++ )
234 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
235 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
244 // ----------------------------------------------------------------------------
245 // wxGridCellAttrProvider
246 // ----------------------------------------------------------------------------
248 wxGridCellAttrProvider::wxGridCellAttrProvider()
250 m_data
= (wxGridCellAttrProviderData
*)NULL
;
253 wxGridCellAttrProvider::~wxGridCellAttrProvider()
258 void wxGridCellAttrProvider::InitData()
260 m_data
= new wxGridCellAttrProviderData
;
263 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
) const
265 return m_data
? m_data
->GetAttr(row
, col
) : (wxGridCellAttr
*)NULL
;
268 void wxGridCellAttrProvider::SetAttr(const wxGridCellAttr
*attr
,
274 m_data
->SetAttr(attr
, row
, col
);
277 //////////////////////////////////////////////////////////////////////
279 // Abstract base class for grid data (the model)
281 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
284 wxGridTableBase::wxGridTableBase()
286 m_view
= (wxGrid
*) NULL
;
287 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
290 wxGridTableBase::~wxGridTableBase()
292 delete m_attrProvider
;
295 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
297 delete m_attrProvider
;
298 m_attrProvider
= attrProvider
;
301 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
)
303 if ( m_attrProvider
)
304 return m_attrProvider
->GetAttr(row
, col
);
306 return (wxGridCellAttr
*)NULL
;
309 void wxGridTableBase::SetAttr(const wxGridCellAttr
*attr
, int row
, int col
)
311 if ( m_attrProvider
)
313 m_attrProvider
->SetAttr(attr
, row
, col
);
317 // as we take ownership of the pointer and don't store it, we must
323 // FIXME VZ: these should be wxFAIL_MSG(), not wxLogWarning, they're for the
324 // programmer, not the user!
326 bool wxGridTableBase::InsertRows( size_t pos
, size_t numRows
)
328 wxLogWarning( wxT("Called grid table class function InsertRows(pos=%d, N=%d)\n"
329 "but your derived table class does not override this function"),
335 bool wxGridTableBase::AppendRows( size_t numRows
)
337 wxLogWarning( wxT("Called grid table class function AppendRows(N=%d)\n"
338 "but your derived table class does not override this function"),
344 bool wxGridTableBase::DeleteRows( size_t pos
, size_t numRows
)
346 wxLogWarning( wxT("Called grid table class function DeleteRows(pos=%d, N=%d)\n"
347 "but your derived table class does not override this function"),
353 bool wxGridTableBase::InsertCols( size_t pos
, size_t numCols
)
355 wxLogWarning( wxT("Called grid table class function InsertCols(pos=%d, N=%d)\n"
356 "but your derived table class does not override this function"),
362 bool wxGridTableBase::AppendCols( size_t numCols
)
364 wxLogWarning( wxT("Called grid table class function AppendCols(N=%d)\n"
365 "but your derived table class does not override this function"),
371 bool wxGridTableBase::DeleteCols( size_t pos
, size_t numCols
)
373 wxLogWarning( wxT("Called grid table class function DeleteCols(pos=%d, N=%d)\n"
374 "but your derived table class does not override this function"),
381 wxString
wxGridTableBase::GetRowLabelValue( int row
)
388 wxString
wxGridTableBase::GetColLabelValue( int col
)
390 // default col labels are:
391 // cols 0 to 25 : A-Z
392 // cols 26 to 675 : AA-ZZ
399 s
+= (_T('A') + (wxChar
)( col%26
));
401 if ( col
< 0 ) break;
404 // reverse the string...
406 for ( i
= 0; i
< n
; i
++ )
416 //////////////////////////////////////////////////////////////////////
418 // Message class for the grid table to send requests and notifications
422 wxGridTableMessage::wxGridTableMessage()
424 m_table
= (wxGridTableBase
*) NULL
;
430 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
431 int commandInt1
, int commandInt2
)
435 m_comInt1
= commandInt1
;
436 m_comInt2
= commandInt2
;
441 //////////////////////////////////////////////////////////////////////
443 // A basic grid table for string data. An object of this class will
444 // created by wxGrid if you don't specify an alternative table class.
447 WX_DEFINE_OBJARRAY(wxGridStringArray
)
449 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
451 wxGridStringTable::wxGridStringTable()
456 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
461 m_data
.Alloc( numRows
);
465 for ( col
= 0; col
< numCols
; col
++ )
467 sa
.Add( wxEmptyString
);
470 for ( row
= 0; row
< numRows
; row
++ )
476 wxGridStringTable::~wxGridStringTable()
480 long wxGridStringTable::GetNumberRows()
482 return m_data
.GetCount();
485 long wxGridStringTable::GetNumberCols()
487 if ( m_data
.GetCount() > 0 )
488 return m_data
[0].GetCount();
493 wxString
wxGridStringTable::GetValue( int row
, int col
)
495 // TODO: bounds checking
497 return m_data
[row
][col
];
500 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& s
)
502 // TODO: bounds checking
504 m_data
[row
][col
] = s
;
507 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
509 // TODO: bounds checking
511 return (m_data
[row
][col
] == wxEmptyString
);
515 void wxGridStringTable::Clear()
518 int numRows
, numCols
;
520 numRows
= m_data
.GetCount();
523 numCols
= m_data
[0].GetCount();
525 for ( row
= 0; row
< numRows
; row
++ )
527 for ( col
= 0; col
< numCols
; col
++ )
529 m_data
[row
][col
] = wxEmptyString
;
536 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
540 size_t curNumRows
= m_data
.GetCount();
541 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
543 if ( pos
>= curNumRows
)
545 return AppendRows( numRows
);
549 sa
.Alloc( curNumCols
);
550 for ( col
= 0; col
< curNumCols
; col
++ )
552 sa
.Add( wxEmptyString
);
555 for ( row
= pos
; row
< pos
+ numRows
; row
++ )
557 m_data
.Insert( sa
, row
);
562 wxGridTableMessage
msg( this,
563 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
567 GetView()->ProcessTableMessage( msg
);
573 bool wxGridStringTable::AppendRows( size_t numRows
)
577 size_t curNumRows
= m_data
.GetCount();
578 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
581 if ( curNumCols
> 0 )
583 sa
.Alloc( curNumCols
);
584 for ( col
= 0; col
< curNumCols
; col
++ )
586 sa
.Add( wxEmptyString
);
590 for ( row
= 0; row
< numRows
; row
++ )
597 wxGridTableMessage
msg( this,
598 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
601 GetView()->ProcessTableMessage( msg
);
607 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
611 size_t curNumRows
= m_data
.GetCount();
613 if ( pos
>= curNumRows
)
615 wxLogError( wxT("Called wxGridStringTable::DeleteRows(pos=%d, N=%d)...\n"
616 "Pos value is invalid for present table with %d rows"),
617 pos
, numRows
, curNumRows
);
621 if ( numRows
> curNumRows
- pos
)
623 numRows
= curNumRows
- pos
;
626 if ( numRows
>= curNumRows
)
628 m_data
.Empty(); // don't release memory just yet
632 for ( n
= 0; n
< numRows
; n
++ )
634 m_data
.Remove( pos
);
640 wxGridTableMessage
msg( this,
641 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
645 GetView()->ProcessTableMessage( msg
);
651 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
655 size_t curNumRows
= m_data
.GetCount();
656 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
658 if ( pos
>= curNumCols
)
660 return AppendCols( numCols
);
663 for ( row
= 0; row
< curNumRows
; row
++ )
665 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
667 m_data
[row
].Insert( wxEmptyString
, col
);
673 wxGridTableMessage
msg( this,
674 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
678 GetView()->ProcessTableMessage( msg
);
684 bool wxGridStringTable::AppendCols( size_t numCols
)
688 size_t curNumRows
= m_data
.GetCount();
691 // TODO: something better than this ?
693 wxLogError( wxT("Unable to append cols to a grid table with no rows.\n"
694 "Call AppendRows() first") );
698 for ( row
= 0; row
< curNumRows
; row
++ )
700 for ( n
= 0; n
< numCols
; n
++ )
702 m_data
[row
].Add( wxEmptyString
);
708 wxGridTableMessage
msg( this,
709 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
712 GetView()->ProcessTableMessage( msg
);
718 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
722 size_t curNumRows
= m_data
.GetCount();
723 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
725 if ( pos
>= curNumCols
)
727 wxLogError( wxT("Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\n"
728 "Pos value is invalid for present table with %d cols"),
729 pos
, numCols
, curNumCols
);
733 if ( numCols
> curNumCols
- pos
)
735 numCols
= curNumCols
- pos
;
738 for ( row
= 0; row
< curNumRows
; row
++ )
740 if ( numCols
>= curNumCols
)
746 for ( n
= 0; n
< numCols
; n
++ )
748 m_data
[row
].Remove( pos
);
755 wxGridTableMessage
msg( this,
756 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
760 GetView()->ProcessTableMessage( msg
);
766 wxString
wxGridStringTable::GetRowLabelValue( int row
)
768 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
770 // using default label
772 return wxGridTableBase::GetRowLabelValue( row
);
776 return m_rowLabels
[ row
];
780 wxString
wxGridStringTable::GetColLabelValue( int col
)
782 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
784 // using default label
786 return wxGridTableBase::GetColLabelValue( col
);
790 return m_colLabels
[ col
];
794 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
796 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
798 int n
= m_rowLabels
.GetCount();
800 for ( i
= n
; i
<= row
; i
++ )
802 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
806 m_rowLabels
[row
] = value
;
809 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
811 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
813 int n
= m_colLabels
.GetCount();
815 for ( i
= n
; i
<= col
; i
++ )
817 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
821 m_colLabels
[col
] = value
;
827 //////////////////////////////////////////////////////////////////////
829 IMPLEMENT_DYNAMIC_CLASS( wxGridTextCtrl
, wxTextCtrl
)
831 BEGIN_EVENT_TABLE( wxGridTextCtrl
, wxTextCtrl
)
832 EVT_KEY_DOWN( wxGridTextCtrl::OnKeyDown
)
836 wxGridTextCtrl::wxGridTextCtrl( wxWindow
*par
,
840 const wxString
& value
,
844 : wxTextCtrl( par
, id
, value
, pos
, size
, style
)
847 m_isCellControl
= isCellControl
;
851 void wxGridTextCtrl::OnKeyDown( wxKeyEvent
& event
)
853 switch ( event
.KeyCode() )
856 m_grid
->SetEditControlValue( startValue
);
857 SetInsertionPointEnd();
867 if ( m_isCellControl
)
869 // send the event to the parent grid, skipping the
870 // event if nothing happens
872 event
.Skip( m_grid
->ProcessEvent( event
) );
876 // default text control response within the top edit
884 if ( m_isCellControl
)
886 if ( !m_grid
->ProcessEvent( event
) )
888 #if defined(__WXMOTIF__) || defined(__WXGTK__)
889 // wxMotif needs a little extra help...
891 int pos
= GetInsertionPoint();
892 wxString
s( GetValue() );
893 s
= s
.Left(pos
) + "\n" + s
.Mid(pos
);
895 SetInsertionPoint( pos
);
897 // the other ports can handle a Return key press
907 if ( m_isCellControl
)
909 // send the event to the parent grid, skipping the
910 // event if nothing happens
912 event
.Skip( m_grid
->ProcessEvent( event
) );
916 // default text control response within the top edit
928 void wxGridTextCtrl::SetStartValue( const wxString
& s
)
931 wxTextCtrl::SetValue(s
);
936 //////////////////////////////////////////////////////////////////////
938 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
940 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
941 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
942 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
943 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
946 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
948 const wxPoint
&pos
, const wxSize
&size
)
949 : wxWindow( parent
, id
, pos
, size
)
954 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
&event
)
958 // NO - don't do this because it will set both the x and y origin
959 // coords to match the parent scrolled window and we just want to
960 // set the y coord - MB
962 // m_owner->PrepareDC( dc );
965 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
966 dc
.SetDeviceOrigin( 0, -y
);
968 m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
969 m_owner
->DrawRowLabels( dc
);
973 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
975 m_owner
->ProcessRowLabelMouseEvent( event
);
979 // This seems to be required for wxMotif otherwise the mouse
980 // cursor must be in the cell edit control to get key events
982 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
984 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
989 //////////////////////////////////////////////////////////////////////
991 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
993 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
994 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
995 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
996 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
999 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
1001 const wxPoint
&pos
, const wxSize
&size
)
1002 : wxWindow( parent
, id
, pos
, size
)
1007 void wxGridColLabelWindow::OnPaint( wxPaintEvent
&event
)
1011 // NO - don't do this because it will set both the x and y origin
1012 // coords to match the parent scrolled window and we just want to
1013 // set the x coord - MB
1015 // m_owner->PrepareDC( dc );
1018 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
1019 dc
.SetDeviceOrigin( -x
, 0 );
1021 m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
1022 m_owner
->DrawColLabels( dc
);
1026 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1028 m_owner
->ProcessColLabelMouseEvent( event
);
1032 // This seems to be required for wxMotif otherwise the mouse
1033 // cursor must be in the cell edit control to get key events
1035 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
1037 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1042 //////////////////////////////////////////////////////////////////////
1044 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
1046 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
1047 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
1048 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
1049 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
1052 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
1054 const wxPoint
&pos
, const wxSize
&size
)
1055 : wxWindow( parent
, id
, pos
, size
)
1060 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1064 int client_height
= 0;
1065 int client_width
= 0;
1066 GetClientSize( &client_width
, &client_height
);
1068 dc
.SetPen( *wxBLACK_PEN
);
1069 dc
.DrawLine( client_width
-1, client_height
-1, client_width
-1, 0 );
1070 dc
.DrawLine( client_width
-1, client_height
-1, 0, client_height
-1 );
1072 dc
.SetPen( *wxWHITE_PEN
);
1073 dc
.DrawLine( 0, 0, client_width
, 0 );
1074 dc
.DrawLine( 0, 0, 0, client_height
);
1078 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1080 m_owner
->ProcessCornerLabelMouseEvent( event
);
1084 // This seems to be required for wxMotif otherwise the mouse
1085 // cursor must be in the cell edit control to get key events
1087 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
1089 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1094 //////////////////////////////////////////////////////////////////////
1096 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxPanel
)
1098 BEGIN_EVENT_TABLE( wxGridWindow
, wxPanel
)
1099 EVT_PAINT( wxGridWindow::OnPaint
)
1100 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
1101 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
1104 wxGridWindow::wxGridWindow( wxGrid
*parent
,
1105 wxGridRowLabelWindow
*rowLblWin
,
1106 wxGridColLabelWindow
*colLblWin
,
1107 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
)
1108 : wxPanel( parent
, id
, pos
, size
, 0, "grid window" )
1111 m_rowLabelWin
= rowLblWin
;
1112 m_colLabelWin
= colLblWin
;
1114 SetBackgroundColour( "WHITE" );
1118 wxGridWindow::~wxGridWindow()
1123 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1125 wxPaintDC
dc( this );
1126 m_owner
->PrepareDC( dc
);
1127 wxRegion reg
= GetUpdateRegion();
1128 m_owner
->CalcCellsExposed( reg
);
1129 m_owner
->DrawGridCellArea( dc
);
1130 #if WXGRID_DRAW_LINES
1131 m_owner
->DrawAllGridLines( dc
, reg
);
1136 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
1138 wxPanel::ScrollWindow( dx
, dy
, rect
);
1139 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
1140 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
1144 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
1146 m_owner
->ProcessGridCellMouseEvent( event
);
1150 // This seems to be required for wxMotif otherwise the mouse
1151 // cursor must be in the cell edit control to get key events
1153 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
1155 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1160 //////////////////////////////////////////////////////////////////////
1162 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
1164 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
1165 EVT_PAINT( wxGrid::OnPaint
)
1166 EVT_SIZE( wxGrid::OnSize
)
1167 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
1170 wxGrid::wxGrid( wxWindow
*parent
,
1175 const wxString
& name
)
1176 : wxScrolledWindow( parent
, id
, pos
, size
, style
, name
)
1189 // ----- internal init and update functions
1192 void wxGrid::Create()
1194 m_created
= FALSE
; // set to TRUE by CreateGrid
1195 m_displayed
= FALSE
; // set to TRUE by OnPaint
1197 m_table
= (wxGridTableBase
*) NULL
;
1198 m_cellEditCtrl
= (wxWindow
*) NULL
;
1202 m_currentCellCoords
= wxGridNoCellCoords
;
1204 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
1205 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
1207 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
1212 m_rowLabelWin
= new wxGridRowLabelWindow( this,
1217 m_colLabelWin
= new wxGridColLabelWindow( this,
1222 m_gridWin
= new wxGridWindow( this,
1229 SetTargetWindow( m_gridWin
);
1233 bool wxGrid::CreateGrid( int numRows
, int numCols
)
1237 wxLogError( wxT("wxGrid::CreateGrid(numRows, numCols) called more than once") );
1242 m_numRows
= numRows
;
1243 m_numCols
= numCols
;
1245 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
1246 m_table
->SetView( this );
1259 if ( m_numRows
<= 0 )
1260 m_numRows
= WXGRID_DEFAULT_NUMBER_ROWS
;
1262 if ( m_numCols
<= 0 )
1263 m_numCols
= WXGRID_DEFAULT_NUMBER_COLS
;
1265 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
1266 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
1268 if ( m_rowLabelWin
)
1270 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
1274 m_labelBackgroundColour
= wxColour( _T("WHITE") );
1277 m_labelTextColour
= wxColour( _T("BLACK") );
1279 // TODO: something better than this ?
1281 m_labelFont
= this->GetFont();
1282 m_labelFont
.SetWeight( m_labelFont
.GetWeight() + 2 );
1284 m_rowLabelHorizAlign
= wxLEFT
;
1285 m_rowLabelVertAlign
= wxCENTRE
;
1287 m_colLabelHorizAlign
= wxCENTRE
;
1288 m_colLabelVertAlign
= wxTOP
;
1290 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
1291 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
1293 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
1294 m_defaultRowHeight
+= 8;
1296 m_defaultRowHeight
+= 4;
1299 m_rowHeights
.Alloc( m_numRows
);
1300 m_rowBottoms
.Alloc( m_numRows
);
1302 for ( i
= 0; i
< m_numRows
; i
++ )
1304 m_rowHeights
.Add( m_defaultRowHeight
);
1305 rowBottom
+= m_defaultRowHeight
;
1306 m_rowBottoms
.Add( rowBottom
);
1309 m_colWidths
.Alloc( m_numCols
);
1310 m_colRights
.Alloc( m_numCols
);
1312 for ( i
= 0; i
< m_numCols
; i
++ )
1314 m_colWidths
.Add( m_defaultColWidth
);
1315 colRight
+= m_defaultColWidth
;
1316 m_colRights
.Add( colRight
);
1319 // TODO: improve this by using wxSystemSettings?
1321 m_defaultCellFont
= GetFont();
1323 m_defaultCellHAlign
= wxLEFT
;
1324 m_defaultCellVAlign
= wxTOP
;
1326 m_gridLineColour
= wxColour( 128, 128, 255 );
1327 m_gridLinesEnabled
= TRUE
;
1329 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
1331 m_dragRowOrCol
= -1;
1332 m_isDragging
= FALSE
;
1334 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
1335 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
1337 m_currentCellCoords
= wxGridNoCellCoords
;
1339 m_selectedTopLeft
= wxGridNoCellCoords
;
1340 m_selectedBottomRight
= wxGridNoCellCoords
;
1342 m_editable
= TRUE
; // default for whole grid
1344 m_inOnKeyDown
= FALSE
;
1347 // TODO: extend this to other types of controls
1349 m_cellEditCtrl
= new wxGridTextCtrl( m_gridWin
,
1356 #if defined(__WXMSW__)
1357 , wxTE_MULTILINE
| wxTE_NO_VSCROLL
1361 m_cellEditCtrl
->Show( FALSE
);
1362 m_cellEditCtrlEnabled
= TRUE
;
1363 m_editCtrlType
= wxGRID_TEXTCTRL
;
1367 void wxGrid::CalcDimensions()
1370 GetClientSize( &cw
, &ch
);
1372 if ( m_numRows
> 0 && m_numCols
> 0 )
1374 int right
= m_colRights
[ m_numCols
-1 ] + 50;
1375 int bottom
= m_rowBottoms
[ m_numRows
-1 ] + 50;
1377 // TODO: restore the scroll position that we had before sizing
1380 GetViewStart( &x
, &y
);
1381 SetScrollbars( GRID_SCROLL_LINE
, GRID_SCROLL_LINE
,
1382 right
/GRID_SCROLL_LINE
, bottom
/GRID_SCROLL_LINE
,
1388 void wxGrid::CalcWindowSizes()
1391 GetClientSize( &cw
, &ch
);
1393 if ( m_cornerLabelWin
->IsShown() )
1394 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
1396 if ( m_colLabelWin
->IsShown() )
1397 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
1399 if ( m_rowLabelWin
->IsShown() )
1400 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
1402 if ( m_gridWin
->IsShown() )
1403 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
1407 // this is called when the grid table sends a message to say that it
1408 // has been redimensioned
1410 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
1414 switch ( msg
.GetId() )
1416 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
1418 size_t pos
= msg
.GetCommandInt();
1419 int numRows
= msg
.GetCommandInt2();
1420 for ( i
= 0; i
< numRows
; i
++ )
1422 m_rowHeights
.Insert( m_defaultRowHeight
, pos
);
1423 m_rowBottoms
.Insert( 0, pos
);
1425 m_numRows
+= numRows
;
1428 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
1430 for ( i
= pos
; i
< m_numRows
; i
++ )
1432 bottom
+= m_rowHeights
[i
];
1433 m_rowBottoms
[i
] = bottom
;
1439 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
1441 int numRows
= msg
.GetCommandInt();
1442 for ( i
= 0; i
< numRows
; i
++ )
1444 m_rowHeights
.Add( m_defaultRowHeight
);
1445 m_rowBottoms
.Add( 0 );
1448 int oldNumRows
= m_numRows
;
1449 m_numRows
+= numRows
;
1452 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
1454 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
1456 bottom
+= m_rowHeights
[i
];
1457 m_rowBottoms
[i
] = bottom
;
1463 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
1465 size_t pos
= msg
.GetCommandInt();
1466 int numRows
= msg
.GetCommandInt2();
1467 for ( i
= 0; i
< numRows
; i
++ )
1469 m_rowHeights
.Remove( pos
);
1470 m_rowBottoms
.Remove( pos
);
1472 m_numRows
-= numRows
;
1477 m_colWidths
.Clear();
1478 m_colRights
.Clear();
1479 m_currentCellCoords
= wxGridNoCellCoords
;
1483 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
1484 m_currentCellCoords
.Set( 0, 0 );
1487 for ( i
= 0; i
< m_numRows
; i
++ )
1489 h
+= m_rowHeights
[i
];
1490 m_rowBottoms
[i
] = h
;
1498 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
1500 size_t pos
= msg
.GetCommandInt();
1501 int numCols
= msg
.GetCommandInt2();
1502 for ( i
= 0; i
< numCols
; i
++ )
1504 m_colWidths
.Insert( m_defaultColWidth
, pos
);
1505 m_colRights
.Insert( 0, pos
);
1507 m_numCols
+= numCols
;
1510 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
1512 for ( i
= pos
; i
< m_numCols
; i
++ )
1514 right
+= m_colWidths
[i
];
1515 m_colRights
[i
] = right
;
1521 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
1523 int numCols
= msg
.GetCommandInt();
1524 for ( i
= 0; i
< numCols
; i
++ )
1526 m_colWidths
.Add( m_defaultColWidth
);
1527 m_colRights
.Add( 0 );
1530 int oldNumCols
= m_numCols
;
1531 m_numCols
+= numCols
;
1534 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
1536 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
1538 right
+= m_colWidths
[i
];
1539 m_colRights
[i
] = right
;
1545 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
1547 size_t pos
= msg
.GetCommandInt();
1548 int numCols
= msg
.GetCommandInt2();
1549 for ( i
= 0; i
< numCols
; i
++ )
1551 m_colWidths
.Remove( pos
);
1552 m_colRights
.Remove( pos
);
1554 m_numCols
-= numCols
;
1558 #if 0 // leave the row alone here so that AppendCols will work subsequently
1560 m_rowHeights
.Clear();
1561 m_rowBottoms
.Clear();
1563 m_currentCellCoords
= wxGridNoCellCoords
;
1567 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
1568 m_currentCellCoords
.Set( 0, 0 );
1571 for ( i
= 0; i
< m_numCols
; i
++ )
1573 w
+= m_colWidths
[i
];
1586 void wxGrid::CalcRowLabelsExposed( wxRegion
& reg
)
1588 wxRegionIterator
iter( reg
);
1591 m_rowLabelsExposed
.Empty();
1598 // TODO: remove this when we can...
1599 // There is a bug in wxMotif that gives garbage update
1600 // rectangles if you jump-scroll a long way by clicking the
1601 // scrollbar with middle button. This is a work-around
1603 #if defined(__WXMOTIF__)
1605 m_gridWin
->GetClientSize( &cw
, &ch
);
1606 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
1607 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
1610 // logical bounds of update region
1613 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
1614 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
1616 // find the row labels within these bounds
1620 for ( row
= 0; row
< m_numRows
; row
++ )
1622 if ( m_rowBottoms
[row
] < top
) continue;
1624 rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
1625 if ( rowTop
> bottom
) break;
1627 m_rowLabelsExposed
.Add( row
);
1635 void wxGrid::CalcColLabelsExposed( wxRegion
& reg
)
1637 wxRegionIterator
iter( reg
);
1640 m_colLabelsExposed
.Empty();
1647 // TODO: remove this when we can...
1648 // There is a bug in wxMotif that gives garbage update
1649 // rectangles if you jump-scroll a long way by clicking the
1650 // scrollbar with middle button. This is a work-around
1652 #if defined(__WXMOTIF__)
1654 m_gridWin
->GetClientSize( &cw
, &ch
);
1655 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
1656 r
.SetRight( wxMin( r
.GetRight(), cw
) );
1659 // logical bounds of update region
1662 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
1663 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
1665 // find the cells within these bounds
1669 for ( col
= 0; col
< m_numCols
; col
++ )
1671 if ( m_colRights
[col
] < left
) continue;
1673 colLeft
= m_colRights
[col
] - m_colWidths
[col
];
1674 if ( colLeft
> right
) break;
1676 m_colLabelsExposed
.Add( col
);
1684 void wxGrid::CalcCellsExposed( wxRegion
& reg
)
1686 wxRegionIterator
iter( reg
);
1689 m_cellsExposed
.Empty();
1690 m_rowsExposed
.Empty();
1691 m_colsExposed
.Empty();
1693 int left
, top
, right
, bottom
;
1698 // TODO: remove this when we can...
1699 // There is a bug in wxMotif that gives garbage update
1700 // rectangles if you jump-scroll a long way by clicking the
1701 // scrollbar with middle button. This is a work-around
1703 #if defined(__WXMOTIF__)
1705 m_gridWin
->GetClientSize( &cw
, &ch
);
1706 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
1707 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
1708 r
.SetRight( wxMin( r
.GetRight(), cw
) );
1709 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
1712 // logical bounds of update region
1714 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
1715 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
1718 // find the cells within these bounds
1721 int colLeft
, rowTop
;
1722 for ( row
= 0; row
< m_numRows
; row
++ )
1724 if ( m_rowBottoms
[row
] < top
) continue;
1726 rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
1727 if ( rowTop
> bottom
) break;
1729 m_rowsExposed
.Add( row
);
1731 for ( col
= 0; col
< m_numCols
; col
++ )
1733 if ( m_colRights
[col
] < left
) continue;
1735 colLeft
= m_colRights
[col
] - m_colWidths
[col
];
1736 if ( colLeft
> right
) break;
1738 if ( m_colsExposed
.Index( col
) == wxNOT_FOUND
) m_colsExposed
.Add( col
);
1739 m_cellsExposed
.Add( wxGridCellCoords( row
, col
) );
1748 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
1751 wxPoint
pos( event
.GetPosition() );
1752 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
1754 if ( event
.Dragging() )
1756 m_isDragging
= TRUE
;
1758 if ( event
.LeftIsDown() )
1760 switch( m_cursorMode
)
1762 case WXGRID_CURSOR_RESIZE_ROW
:
1764 int cw
, ch
, left
, dummy
;
1765 m_gridWin
->GetClientSize( &cw
, &ch
);
1766 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
1768 wxClientDC
dc( m_gridWin
);
1770 dc
.SetLogicalFunction(wxINVERT
);
1771 if ( m_dragLastPos
>= 0 )
1773 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
1775 dc
.DrawLine( left
, y
, left
+cw
, y
);
1780 case WXGRID_CURSOR_SELECT_ROW
:
1782 if ( (row
= YToRow( y
)) >= 0 &&
1783 !IsInSelection( row
, 0 ) )
1785 SelectRow( row
, TRUE
);
1794 m_isDragging
= FALSE
;
1797 // ------------ Left button pressed
1799 if ( event
.LeftDown() )
1801 // don't send a label click event for a hit on the
1802 // edge of the row label - this is probably the user
1803 // wanting to resize the row
1805 if ( YToEdgeOfRow(y
) < 0 )
1809 !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
1811 SelectRow( row
, event
.ShiftDown() );
1812 m_cursorMode
= WXGRID_CURSOR_SELECT_ROW
;
1817 // starting to drag-resize a row
1819 m_rowLabelWin
->CaptureMouse();
1824 // ------------ Left double click
1826 else if (event
.LeftDClick() )
1828 if ( YToEdgeOfRow(y
) < 0 )
1831 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
);
1836 // ------------ Left button released
1838 else if ( event
.LeftUp() )
1840 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
1842 m_rowLabelWin
->ReleaseMouse();
1844 if ( m_dragLastPos
>= 0 )
1846 // erase the last line and resize the row
1848 int cw
, ch
, left
, dummy
;
1849 m_gridWin
->GetClientSize( &cw
, &ch
);
1850 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
1852 wxClientDC
dc( m_gridWin
);
1854 dc
.SetLogicalFunction( wxINVERT
);
1855 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
1856 HideCellEditControl();
1858 int rowTop
= m_rowBottoms
[m_dragRowOrCol
] - m_rowHeights
[m_dragRowOrCol
];
1859 SetRowSize( m_dragRowOrCol
, wxMax( y
- rowTop
, WXGRID_MIN_ROW_HEIGHT
) );
1860 if ( !GetBatchCount() )
1862 // Only needed to get the correct rect.y:
1863 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
1865 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
1866 rect
.width
= m_rowLabelWidth
;
1867 rect
.height
= ch
- rect
.y
;
1868 m_rowLabelWin
->Refresh( TRUE
, &rect
);
1870 m_gridWin
->Refresh( FALSE
, &rect
);
1873 ShowCellEditControl();
1875 // Note: we are ending the event *after* doing
1876 // default processing in this case
1878 SendEvent( EVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
1882 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
1887 // ------------ Right button down
1889 else if ( event
.RightDown() )
1892 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
1894 // no default action at the moment
1899 // ------------ Right double click
1901 else if ( event
.RightDClick() )
1904 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
1906 // no default action at the moment
1911 // ------------ No buttons down and mouse moving
1913 else if ( event
.Moving() )
1915 m_dragRowOrCol
= YToEdgeOfRow( y
);
1916 if ( m_dragRowOrCol
>= 0 )
1918 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
1920 m_cursorMode
= WXGRID_CURSOR_RESIZE_ROW
;
1921 m_rowLabelWin
->SetCursor( m_rowResizeCursor
);
1926 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
1927 if ( m_rowLabelWin
->GetCursor() == m_rowResizeCursor
)
1928 m_rowLabelWin
->SetCursor( *wxSTANDARD_CURSOR
);
1934 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
1937 wxPoint
pos( event
.GetPosition() );
1938 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
1940 if ( event
.Dragging() )
1942 m_isDragging
= TRUE
;
1944 if ( event
.LeftIsDown() )
1946 switch( m_cursorMode
)
1948 case WXGRID_CURSOR_RESIZE_COL
:
1950 int cw
, ch
, dummy
, top
;
1951 m_gridWin
->GetClientSize( &cw
, &ch
);
1952 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
1954 wxClientDC
dc( m_gridWin
);
1956 dc
.SetLogicalFunction(wxINVERT
);
1957 if ( m_dragLastPos
>= 0 )
1959 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
1961 dc
.DrawLine( x
, top
, x
, top
+ch
);
1966 case WXGRID_CURSOR_SELECT_COL
:
1968 if ( (col
= XToCol( x
)) >= 0 &&
1969 !IsInSelection( 0, col
) )
1971 SelectCol( col
, TRUE
);
1980 m_isDragging
= FALSE
;
1983 // ------------ Left button pressed
1985 if ( event
.LeftDown() )
1987 // don't send a label click event for a hit on the
1988 // edge of the col label - this is probably the user
1989 // wanting to resize the col
1991 if ( XToEdgeOfCol(x
) < 0 )
1995 !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
1997 SelectCol( col
, event
.ShiftDown() );
1998 m_cursorMode
= WXGRID_CURSOR_SELECT_COL
;
2003 // starting to drag-resize a col
2005 m_colLabelWin
->CaptureMouse();
2010 // ------------ Left double click
2012 if ( event
.LeftDClick() )
2014 if ( XToEdgeOfCol(x
) < 0 )
2017 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
);
2022 // ------------ Left button released
2024 else if ( event
.LeftUp() )
2026 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
2028 m_colLabelWin
->ReleaseMouse();
2030 if ( m_dragLastPos
>= 0 )
2032 // erase the last line and resize the col
2034 int cw
, ch
, dummy
, top
;
2035 m_gridWin
->GetClientSize( &cw
, &ch
);
2036 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
2038 wxClientDC
dc( m_gridWin
);
2040 dc
.SetLogicalFunction( wxINVERT
);
2041 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
2042 HideCellEditControl();
2044 int colLeft
= m_colRights
[m_dragRowOrCol
] - m_colWidths
[m_dragRowOrCol
];
2045 SetColSize( m_dragRowOrCol
, wxMax( x
- colLeft
, WXGRID_MIN_COL_WIDTH
) );
2047 if ( !GetBatchCount() )
2049 // Only needed to get the correct rect.x:
2050 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
2052 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
2053 rect
.width
= cw
- rect
.x
;
2054 rect
.height
= m_colLabelHeight
;
2055 m_colLabelWin
->Refresh( TRUE
, &rect
);
2057 m_gridWin
->Refresh( FALSE
, &rect
);
2060 ShowCellEditControl();
2062 // Note: we are ending the event *after* doing
2063 // default processing in this case
2065 SendEvent( EVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
2069 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
2074 // ------------ Right button down
2076 else if ( event
.RightDown() )
2079 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
2081 // no default action at the moment
2086 // ------------ Right double click
2088 else if ( event
.RightDClick() )
2091 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
2093 // no default action at the moment
2098 // ------------ No buttons down and mouse moving
2100 else if ( event
.Moving() )
2102 m_dragRowOrCol
= XToEdgeOfCol( x
);
2103 if ( m_dragRowOrCol
>= 0 )
2105 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2107 m_cursorMode
= WXGRID_CURSOR_RESIZE_COL
;
2108 m_colLabelWin
->SetCursor( m_colResizeCursor
);
2113 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
2114 if ( m_colLabelWin
->GetCursor() == m_colResizeCursor
)
2115 m_colLabelWin
->SetCursor( *wxSTANDARD_CURSOR
);
2121 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
2123 if ( event
.LeftDown() )
2125 // indicate corner label by having both row and
2128 if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
2134 else if ( event
.LeftDClick() )
2136 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
2139 else if ( event
.RightDown() )
2141 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
2143 // no default action at the moment
2147 else if ( event
.RightDClick() )
2149 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
2151 // no default action at the moment
2157 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
2160 wxPoint
pos( event
.GetPosition() );
2161 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2163 wxGridCellCoords coords
;
2164 XYToCell( x
, y
, coords
);
2166 if ( event
.Dragging() )
2168 m_isDragging
= TRUE
;
2169 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2171 // Hide the edit control, so it
2172 // won't interfer with drag-shrinking.
2173 if ( IsCellEditControlEnabled() )
2174 HideCellEditControl();
2175 if ( coords
!= wxGridNoCellCoords
)
2177 if ( !IsSelection() )
2179 SelectBlock( coords
, coords
);
2183 SelectBlock( m_currentCellCoords
, coords
);
2191 m_isDragging
= FALSE
;
2193 if ( coords
!= wxGridNoCellCoords
)
2195 if ( event
.LeftDown() )
2197 if ( event
.ShiftDown() )
2199 SelectBlock( m_currentCellCoords
, coords
);
2203 if ( !SendEvent( EVT_GRID_CELL_LEFT_CLICK
,
2208 MakeCellVisible( coords
);
2209 SetCurrentCell( coords
);
2215 // ------------ Left double click
2217 else if ( event
.LeftDClick() )
2219 SendEvent( EVT_GRID_CELL_LEFT_DCLICK
,
2226 // ------------ Left button released
2228 else if ( event
.LeftUp() )
2230 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2232 if ( IsSelection() )
2234 SendEvent( EVT_GRID_RANGE_SELECT
, -1, -1, event
);
2238 // Show the edit control, if it has
2239 // been hidden for drag-shrinking.
2240 if ( IsCellEditControlEnabled() )
2241 ShowCellEditControl();
2247 // ------------ Right button down
2249 else if ( event
.RightDown() )
2251 if ( !SendEvent( EVT_GRID_CELL_RIGHT_CLICK
,
2256 // no default action at the moment
2261 // ------------ Right double click
2263 else if ( event
.RightDClick() )
2265 if ( !SendEvent( EVT_GRID_CELL_RIGHT_DCLICK
,
2270 // no default action at the moment
2274 // ------------ Moving and no button action
2276 else if ( event
.Moving() && !event
.IsButton() )
2278 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
2285 // ------ interaction with data model
2287 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
2289 switch ( msg
.GetId() )
2291 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
2292 return GetModelValues();
2294 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
2295 return SetModelValues();
2297 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
2298 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
2299 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
2300 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
2301 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
2302 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
2303 return Redimension( msg
);
2312 // The behaviour of this function depends on the grid table class
2313 // Clear() function. For the default wxGridStringTable class the
2314 // behavious is to replace all cell contents with wxEmptyString but
2315 // not to change the number of rows or cols.
2317 void wxGrid::ClearGrid()
2322 SetEditControlValue();
2323 if ( !GetBatchCount() ) m_gridWin
->Refresh();
2328 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
2330 // TODO: something with updateLabels flag
2334 wxLogError( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
2340 bool ok
= m_table
->InsertRows( pos
, numRows
);
2342 // the table will have sent the results of the insert row
2343 // operation to this view object as a grid table message
2347 if ( m_numCols
== 0 )
2349 m_table
->AppendCols( WXGRID_DEFAULT_NUMBER_COLS
);
2351 // TODO: perhaps instead of appending the default number of cols
2352 // we should remember what the last non-zero number of cols was ?
2356 if ( m_currentCellCoords
== wxGridNoCellCoords
)
2358 // if we have just inserted cols into an empty grid the current
2359 // cell will be undefined...
2361 SetCurrentCell( 0, 0 );
2365 if ( !GetBatchCount() ) Refresh();
2368 SetEditControlValue();
2378 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
2380 // TODO: something with updateLabels flag
2384 wxLogError( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
2388 if ( m_table
&& m_table
->AppendRows( numRows
) )
2390 if ( m_currentCellCoords
== wxGridNoCellCoords
)
2392 // if we have just inserted cols into an empty grid the current
2393 // cell will be undefined...
2395 SetCurrentCell( 0, 0 );
2398 // the table will have sent the results of the append row
2399 // operation to this view object as a grid table message
2402 if ( !GetBatchCount() ) Refresh();
2412 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
2414 // TODO: something with updateLabels flag
2418 wxLogError( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
2422 if ( m_table
&& m_table
->DeleteRows( pos
, numRows
) )
2424 // the table will have sent the results of the delete row
2425 // operation to this view object as a grid table message
2427 if ( m_numRows
> 0 )
2428 SetEditControlValue();
2430 HideCellEditControl();
2433 if ( !GetBatchCount() ) Refresh();
2443 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
2445 // TODO: something with updateLabels flag
2449 wxLogError( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
2455 HideCellEditControl();
2456 bool ok
= m_table
->InsertCols( pos
, numCols
);
2458 // the table will have sent the results of the insert col
2459 // operation to this view object as a grid table message
2463 if ( m_currentCellCoords
== wxGridNoCellCoords
)
2465 // if we have just inserted cols into an empty grid the current
2466 // cell will be undefined...
2468 SetCurrentCell( 0, 0 );
2472 if ( !GetBatchCount() ) Refresh();
2475 SetEditControlValue();
2485 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
2487 // TODO: something with updateLabels flag
2491 wxLogError( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
2495 if ( m_table
&& m_table
->AppendCols( numCols
) )
2497 // the table will have sent the results of the append col
2498 // operation to this view object as a grid table message
2500 if ( m_currentCellCoords
== wxGridNoCellCoords
)
2502 // if we have just inserted cols into an empty grid the current
2503 // cell will be undefined...
2505 SetCurrentCell( 0, 0 );
2509 if ( !GetBatchCount() ) Refresh();
2519 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
2521 // TODO: something with updateLabels flag
2525 wxLogError( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
2529 if ( m_table
&& m_table
->DeleteCols( pos
, numCols
) )
2531 // the table will have sent the results of the delete col
2532 // operation to this view object as a grid table message
2534 if ( m_numCols
> 0 )
2535 SetEditControlValue();
2537 HideCellEditControl();
2540 if ( !GetBatchCount() ) Refresh();
2552 // ----- event handlers
2555 // Generate a grid event based on a mouse event and
2556 // return the result of ProcessEvent()
2558 bool wxGrid::SendEvent( const wxEventType type
,
2560 wxMouseEvent
& mouseEv
)
2562 if ( type
== EVT_GRID_ROW_SIZE
||
2563 type
== EVT_GRID_COL_SIZE
)
2565 int rowOrCol
= (row
== -1 ? col
: row
);
2567 wxGridSizeEvent
gridEvt( GetId(),
2571 mouseEv
.GetX(), mouseEv
.GetY(),
2572 mouseEv
.ControlDown(),
2573 mouseEv
.ShiftDown(),
2575 mouseEv
.MetaDown() );
2577 return GetEventHandler()->ProcessEvent(gridEvt
);
2579 else if ( type
== EVT_GRID_RANGE_SELECT
)
2581 wxGridRangeSelectEvent
gridEvt( GetId(),
2585 m_selectedBottomRight
,
2586 mouseEv
.ControlDown(),
2587 mouseEv
.ShiftDown(),
2589 mouseEv
.MetaDown() );
2591 return GetEventHandler()->ProcessEvent(gridEvt
);
2595 wxGridEvent
gridEvt( GetId(),
2599 mouseEv
.GetX(), mouseEv
.GetY(),
2600 mouseEv
.ControlDown(),
2601 mouseEv
.ShiftDown(),
2603 mouseEv
.MetaDown() );
2605 return GetEventHandler()->ProcessEvent(gridEvt
);
2610 // Generate a grid event of specified type and return the result
2611 // of ProcessEvent().
2613 bool wxGrid::SendEvent( const wxEventType type
,
2616 if ( type
== EVT_GRID_ROW_SIZE
||
2617 type
== EVT_GRID_COL_SIZE
)
2619 int rowOrCol
= (row
== -1 ? col
: row
);
2621 wxGridSizeEvent
gridEvt( GetId(),
2626 return GetEventHandler()->ProcessEvent(gridEvt
);
2630 wxGridEvent
gridEvt( GetId(),
2635 return GetEventHandler()->ProcessEvent(gridEvt
);
2640 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2642 wxPaintDC
dc( this );
2644 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
2645 m_numRows
&& m_numCols
)
2647 m_currentCellCoords
.Set(0, 0);
2648 SetEditControlValue();
2649 ShowCellEditControl();
2656 // This is just here to make sure that CalcDimensions gets called when
2657 // the grid view is resized... then the size event is skipped to allow
2658 // the box sizers to handle everything
2660 void wxGrid::OnSize( wxSizeEvent
& event
)
2667 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
2669 if ( m_inOnKeyDown
)
2671 // shouldn't be here - we are going round in circles...
2673 wxLogFatalError( wxT("wxGrid::OnKeyDown called while alread active") );
2676 m_inOnKeyDown
= TRUE
;
2678 // propagate the event up and see if it gets processed
2680 wxWindow
*parent
= GetParent();
2681 wxKeyEvent
keyEvt( event
);
2682 keyEvt
.SetEventObject( parent
);
2684 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
2686 // try local handlers
2688 switch ( event
.KeyCode() )
2691 if ( event
.ControlDown() )
2693 MoveCursorUpBlock();
2702 if ( event
.ControlDown() )
2704 MoveCursorDownBlock();
2713 if ( event
.ControlDown() )
2715 MoveCursorLeftBlock();
2724 if ( event
.ControlDown() )
2726 MoveCursorRightBlock();
2735 if ( !IsEditable() )
2746 if ( event
.ControlDown() )
2748 event
.Skip(); // to let the edit control have the return
2757 if ( event
.ControlDown() )
2759 MakeCellVisible( 0, 0 );
2760 SetCurrentCell( 0, 0 );
2769 if ( event
.ControlDown() )
2771 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
2772 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
2789 // now try the cell edit control
2791 if ( IsCellEditControlEnabled() )
2793 event
.SetEventObject( m_cellEditCtrl
);
2794 m_cellEditCtrl
->GetEventHandler()->ProcessEvent( event
);
2800 m_inOnKeyDown
= FALSE
;
2804 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
2806 if ( SendEvent( EVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
2808 // the event has been intercepted - do nothing
2813 m_currentCellCoords
!= wxGridNoCellCoords
)
2815 HideCellEditControl();
2816 SaveEditControlValue();
2819 m_currentCellCoords
= coords
;
2821 SetEditControlValue();
2825 ShowCellEditControl();
2827 if ( IsSelection() )
2829 wxRect
r( SelectionToDeviceRect() );
2831 if ( !GetBatchCount() ) m_gridWin
->Refresh( FALSE
, &r
);
2838 // ------ functions to get/send data (see also public functions)
2841 bool wxGrid::GetModelValues()
2845 // all we need to do is repaint the grid
2847 m_gridWin
->Refresh();
2855 bool wxGrid::SetModelValues()
2861 for ( row
= 0; row
< m_numRows
; row
++ )
2863 for ( col
= 0; col
< m_numCols
; col
++ )
2865 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
2877 // Note - this function only draws cells that are in the list of
2878 // exposed cells (usually set from the update region by
2879 // CalcExposedCells)
2881 void wxGrid::DrawGridCellArea( wxDC
& dc
)
2883 if ( !m_numRows
|| !m_numCols
) return;
2886 size_t numCells
= m_cellsExposed
.GetCount();
2888 for ( i
= 0; i
< numCells
; i
++ )
2890 DrawCell( dc
, m_cellsExposed
[i
] );
2895 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
2897 if ( m_colWidths
[coords
.GetCol()] <=0 ||
2898 m_rowHeights
[coords
.GetRow()] <= 0 ) return;
2900 #if !WXGRID_DRAW_LINES
2901 if ( m_gridLinesEnabled
)
2902 DrawCellBorder( dc
, coords
);
2905 DrawCellBackground( dc
, coords
);
2907 // TODO: separate functions here for different kinds of cells ?
2910 DrawCellValue( dc
, coords
);
2914 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
2916 if ( m_colWidths
[coords
.GetCol()] <=0 ||
2917 m_rowHeights
[coords
.GetRow()] <= 0 ) return;
2919 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
2920 int row
= coords
.GetRow();
2921 int col
= coords
.GetCol();
2923 // right hand border
2925 dc
.DrawLine( m_colRights
[col
]-1, m_rowBottoms
[row
] - m_rowHeights
[row
],
2926 m_colRights
[col
]-1, m_rowBottoms
[row
]-1 );
2930 dc
.DrawLine( m_colRights
[col
] - m_colWidths
[col
], m_rowBottoms
[row
]-1,
2931 m_colRights
[col
]-1, m_rowBottoms
[row
]-1 );
2935 void wxGrid::DrawCellBackground( wxDC
& dc
, const wxGridCellCoords
& coords
)
2937 if ( m_colWidths
[coords
.GetCol()] <=0 ||
2938 m_rowHeights
[coords
.GetRow()] <= 0 ) return;
2940 int row
= coords
.GetRow();
2941 int col
= coords
.GetCol();
2943 dc
.SetBackgroundMode( wxSOLID
);
2945 if ( IsInSelection( coords
) )
2947 // TODO: improve this
2949 dc
.SetBrush( *wxBLACK_BRUSH
);
2953 dc
.SetBrush( wxBrush(GetCellBackgroundColour(row
, col
), wxSOLID
) );
2956 dc
.SetPen( *wxTRANSPARENT_PEN
);
2958 dc
.DrawRectangle( m_colRights
[col
] - m_colWidths
[col
] + 1,
2959 m_rowBottoms
[row
] - m_rowHeights
[row
] + 1,
2961 m_rowHeights
[row
]-1 );
2965 void wxGrid::DrawCellValue( wxDC
& dc
, const wxGridCellCoords
& coords
)
2967 if ( m_colWidths
[coords
.GetCol()] <=0 ||
2968 m_rowHeights
[coords
.GetRow()] <= 0 ) return;
2970 int row
= coords
.GetRow();
2971 int col
= coords
.GetCol();
2973 dc
.SetBackgroundMode( wxTRANSPARENT
);
2975 if ( IsInSelection( row
, col
) )
2977 // TODO: improve this
2979 dc
.SetTextBackground( wxColour(0, 0, 0) );
2980 dc
.SetTextForeground( wxColour(255, 255, 255) );
2984 dc
.SetTextBackground( GetCellBackgroundColour(row
, col
) );
2985 dc
.SetTextForeground( GetCellTextColour(row
, col
) );
2987 dc
.SetFont( GetCellFont(row
, col
) );
2990 GetCellAlignment( row
, col
, &hAlign
, &vAlign
);
2993 rect
.SetX( m_colRights
[col
] - m_colWidths
[col
] + 2 );
2994 rect
.SetY( m_rowBottoms
[row
] - m_rowHeights
[row
] + 2 );
2995 rect
.SetWidth( m_colWidths
[col
] - 4 );
2996 rect
.SetHeight( m_rowHeights
[row
] - 4 );
2998 DrawTextRectangle( dc
, GetCellValue( row
, col
), rect
, hAlign
, vAlign
);
3003 // TODO: remove this ???
3004 // This is used to redraw all grid lines e.g. when the grid line colour
3007 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
)
3009 if ( !m_gridLinesEnabled
||
3011 !m_numCols
) return;
3013 int top
, bottom
, left
, right
;
3017 m_gridWin
->GetClientSize(&cw
, &ch
);
3019 // virtual coords of visible area
3021 CalcUnscrolledPosition( 0, 0, &left
, &top
);
3022 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
3026 reg
.GetBox(x
, y
, w
, h
);
3027 CalcUnscrolledPosition( x
, y
, &left
, &top
);
3028 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
3031 // avoid drawing grid lines past the last row and col
3033 right
= wxMin( right
, m_colRights
[m_numCols
-1] );
3034 bottom
= wxMin( bottom
, m_rowBottoms
[m_numRows
-1] );
3036 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
3038 // horizontal grid lines
3041 for ( i
= 0; i
< m_numRows
; i
++ )
3043 if ( m_rowBottoms
[i
]-1 > bottom
)
3047 else if ( m_rowBottoms
[i
]-1 >= top
)
3049 dc
.DrawLine( left
, m_rowBottoms
[i
]-1, right
, m_rowBottoms
[i
]-1 );
3054 // vertical grid lines
3056 for ( i
= 0; i
< m_numCols
; i
++ )
3058 if ( m_colRights
[i
]-1 > right
)
3062 else if ( m_colRights
[i
]-1 >= left
)
3064 dc
.DrawLine( m_colRights
[i
]-1, top
, m_colRights
[i
]-1, bottom
);
3070 void wxGrid::DrawRowLabels( wxDC
& dc
)
3072 if ( !m_numRows
|| !m_numCols
) return;
3075 size_t numLabels
= m_rowLabelsExposed
.GetCount();
3077 for ( i
= 0; i
< numLabels
; i
++ )
3079 DrawRowLabel( dc
, m_rowLabelsExposed
[i
] );
3084 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
3086 if ( m_rowHeights
[row
] <= 0 ) return;
3088 int rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3090 dc
.SetPen( *wxBLACK_PEN
);
3091 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
3092 m_rowLabelWidth
-1, m_rowBottoms
[row
]-1 );
3094 dc
.DrawLine( 0, m_rowBottoms
[row
]-1,
3095 m_rowLabelWidth
-1, m_rowBottoms
[row
]-1 );
3097 dc
.SetPen( *wxWHITE_PEN
);
3098 dc
.DrawLine( 0, rowTop
, 0, m_rowBottoms
[row
]-1 );
3099 dc
.DrawLine( 0, rowTop
, m_rowLabelWidth
-1, rowTop
);
3101 dc
.SetBackgroundMode( wxTRANSPARENT
);
3102 dc
.SetTextForeground( GetLabelTextColour() );
3103 dc
.SetFont( GetLabelFont() );
3106 GetRowLabelAlignment( &hAlign
, &vAlign
);
3110 rect
.SetY( m_rowBottoms
[row
] - m_rowHeights
[row
] + 2 );
3111 rect
.SetWidth( m_rowLabelWidth
- 4 );
3112 rect
.SetHeight( m_rowHeights
[row
] - 4 );
3113 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
3117 void wxGrid::DrawColLabels( wxDC
& dc
)
3119 if ( !m_numRows
|| !m_numCols
) return;
3122 size_t numLabels
= m_colLabelsExposed
.GetCount();
3124 for ( i
= 0; i
< numLabels
; i
++ )
3126 DrawColLabel( dc
, m_colLabelsExposed
[i
] );
3131 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
3133 if ( m_colWidths
[col
] <= 0 ) return;
3135 int colLeft
= m_colRights
[col
] - m_colWidths
[col
];
3137 dc
.SetPen( *wxBLACK_PEN
);
3138 dc
.DrawLine( m_colRights
[col
]-1, 0,
3139 m_colRights
[col
]-1, m_colLabelHeight
-1 );
3141 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
3142 m_colRights
[col
]-1, m_colLabelHeight
-1 );
3144 dc
.SetPen( *wxWHITE_PEN
);
3145 dc
.DrawLine( colLeft
, 0, colLeft
, m_colLabelHeight
-1 );
3146 dc
.DrawLine( colLeft
, 0, m_colRights
[col
]-1, 0 );
3148 dc
.SetBackgroundMode( wxTRANSPARENT
);
3149 dc
.SetTextForeground( GetLabelTextColour() );
3150 dc
.SetFont( GetLabelFont() );
3152 dc
.SetBackgroundMode( wxTRANSPARENT
);
3153 dc
.SetTextForeground( GetLabelTextColour() );
3154 dc
.SetFont( GetLabelFont() );
3157 GetColLabelAlignment( &hAlign
, &vAlign
);
3160 rect
.SetX( m_colRights
[col
] - m_colWidths
[col
] + 2 );
3162 rect
.SetWidth( m_colWidths
[col
] - 4 );
3163 rect
.SetHeight( m_colLabelHeight
- 4 );
3164 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
);
3168 void wxGrid::DrawTextRectangle( wxDC
& dc
,
3169 const wxString
& value
,
3174 long textWidth
, textHeight
;
3175 long lineWidth
, lineHeight
;
3176 wxArrayString lines
;
3178 dc
.SetClippingRegion( rect
);
3179 StringToLines( value
, lines
);
3180 if ( lines
.GetCount() )
3182 GetTextBoxSize( dc
, lines
, &textWidth
, &textHeight
);
3183 dc
.GetTextExtent( lines
[0], &lineWidth
, &lineHeight
);
3186 switch ( horizAlign
)
3189 x
= rect
.x
+ (rect
.width
- textWidth
- 1);
3193 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
3202 switch ( vertAlign
)
3205 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
3209 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
3218 for ( size_t i
= 0; i
< lines
.GetCount(); i
++ )
3220 dc
.DrawText( lines
[i
], (long)x
, (long)y
);
3225 dc
.DestroyClippingRegion();
3229 // Split multi line text up into an array of strings. Any existing
3230 // contents of the string array are preserved.
3232 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
3234 // TODO: this won't work for WXMAC ? (lines end with '\r')
3235 // => use wxTextFile functions then (VZ)
3238 while ( startPos
< (int)value
.Length() )
3240 pos
= value
.Mid(startPos
).Find( '\n' );
3245 else if ( pos
== 0 )
3247 lines
.Add( wxEmptyString
);
3251 if ( value
[startPos
+pos
-1] == '\r' )
3253 lines
.Add( value
.Mid(startPos
, pos
-1) );
3257 lines
.Add( value
.Mid(startPos
, pos
) );
3262 if ( startPos
< (int)value
.Length() )
3264 lines
.Add( value
.Mid( startPos
) );
3269 void wxGrid::GetTextBoxSize( wxDC
& dc
,
3270 wxArrayString
& lines
,
3271 long *width
, long *height
)
3278 for ( i
= 0; i
< lines
.GetCount(); i
++ )
3280 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
3281 w
= wxMax( w
, lineW
);
3291 // ------ Edit control functions
3295 void wxGrid::EnableEditing( bool edit
)
3297 // TODO: improve this ?
3299 if ( edit
!= m_editable
)
3303 // TODO: extend this for other edit control types
3305 if ( m_editCtrlType
== wxGRID_TEXTCTRL
)
3307 ((wxTextCtrl
*)m_cellEditCtrl
)->SetEditable( m_editable
);
3313 #if 0 // disabled for the moment - the cell control is always active
3314 void wxGrid::EnableCellEditControl( bool enable
)
3316 if ( m_cellEditCtrl
&&
3317 enable
!= m_cellEditCtrlEnabled
)
3319 m_cellEditCtrlEnabled
= enable
;
3321 if ( m_cellEditCtrlEnabled
)
3323 SetEditControlValue();
3324 ShowCellEditControl();
3328 HideCellEditControl();
3329 SaveEditControlValue();
3336 void wxGrid::ShowCellEditControl()
3340 if ( IsCellEditControlEnabled() )
3342 if ( !IsVisible( m_currentCellCoords
) )
3348 rect
= CellToRect( m_currentCellCoords
);
3350 // convert to scrolled coords
3352 int left
, top
, right
, bottom
;
3353 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
3354 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
3357 m_gridWin
->GetClientSize( &cw
, &ch
);
3359 // Make the edit control large enough to allow for internal margins
3360 // TODO: remove this if the text ctrl sizing is improved esp. for unix
3363 #if defined(__WXMOTIF__)
3364 if ( m_currentCellCoords
.GetRow() == 0 ||
3365 m_currentCellCoords
.GetCol() == 0 )
3374 if ( m_currentCellCoords
.GetRow() == 0 ||
3375 m_currentCellCoords
.GetCol() == 0 )
3385 #if defined(__WXGTK__)
3388 if (left
!= 0) left_diff
++;
3389 if (top
!= 0) top_diff
++;
3390 rect
.SetLeft( left
+ left_diff
);
3391 rect
.SetTop( top
+ top_diff
);
3392 rect
.SetRight( rect
.GetRight() - left_diff
);
3393 rect
.SetBottom( rect
.GetBottom() - top_diff
);
3395 rect
.SetLeft( wxMax(0, left
- extra
) );
3396 rect
.SetTop( wxMax(0, top
- extra
) );
3397 rect
.SetRight( rect
.GetRight() + 2*extra
);
3398 rect
.SetBottom( rect
.GetBottom() + 2*extra
);
3401 m_cellEditCtrl
->SetSize( rect
);
3402 m_cellEditCtrl
->Show( TRUE
);
3404 switch ( m_editCtrlType
)
3406 case wxGRID_TEXTCTRL
:
3407 ((wxTextCtrl
*) m_cellEditCtrl
)->SetInsertionPointEnd();
3410 case wxGRID_CHECKBOX
:
3411 // TODO: anything ???
3416 // TODO: anything ???
3420 case wxGRID_COMBOBOX
:
3421 // TODO: anything ???
3426 m_cellEditCtrl
->SetFocus();
3432 void wxGrid::HideCellEditControl()
3434 if ( IsCellEditControlEnabled() )
3436 m_cellEditCtrl
->Show( FALSE
);
3441 void wxGrid::SetEditControlValue( const wxString
& value
)
3447 s
= GetCellValue(m_currentCellCoords
);
3451 if ( IsCellEditControlEnabled() )
3453 switch ( m_editCtrlType
)
3455 case wxGRID_TEXTCTRL
:
3456 ((wxGridTextCtrl
*)m_cellEditCtrl
)->SetStartValue(s
);
3459 case wxGRID_CHECKBOX
:
3460 // TODO: implement this
3465 // TODO: implement this
3469 case wxGRID_COMBOBOX
:
3470 // TODO: implement this
3479 void wxGrid::SaveEditControlValue()
3483 wxWindow
*ctrl
= (wxWindow
*)NULL
;
3485 if ( IsCellEditControlEnabled() )
3487 ctrl
= m_cellEditCtrl
;
3494 bool valueChanged
= FALSE
;
3496 switch ( m_editCtrlType
)
3498 case wxGRID_TEXTCTRL
:
3499 valueChanged
= (((wxGridTextCtrl
*)ctrl
)->GetValue() !=
3500 ((wxGridTextCtrl
*)ctrl
)->GetStartValue());
3501 SetCellValue( m_currentCellCoords
,
3502 ((wxTextCtrl
*) ctrl
)->GetValue() );
3505 case wxGRID_CHECKBOX
:
3506 // TODO: implement this
3511 // TODO: implement this
3515 case wxGRID_COMBOBOX
:
3516 // TODO: implement this
3523 SendEvent( EVT_GRID_CELL_CHANGE
,
3524 m_currentCellCoords
.GetRow(),
3525 m_currentCellCoords
.GetCol() );
3532 // ------ Grid location functions
3533 // Note that all of these functions work with the logical coordinates of
3534 // grid cells and labels so you will need to convert from device
3535 // coordinates for mouse events etc.
3538 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
3540 int row
= YToRow(y
);
3541 int col
= XToCol(x
);
3543 if ( row
== -1 || col
== -1 )
3545 coords
= wxGridNoCellCoords
;
3549 coords
.Set( row
, col
);
3554 int wxGrid::YToRow( int y
)
3558 for ( i
= 0; i
< m_numRows
; i
++ )
3560 if ( y
< m_rowBottoms
[i
] ) return i
;
3567 int wxGrid::XToCol( int x
)
3571 for ( i
= 0; i
< m_numCols
; i
++ )
3573 if ( x
< m_colRights
[i
] ) return i
;
3580 // return the row number that that the y coord is near the edge of, or
3581 // -1 if not near an edge
3583 int wxGrid::YToEdgeOfRow( int y
)
3587 for ( i
= 0; i
< m_numRows
; i
++ )
3589 if ( m_rowHeights
[i
] > WXGRID_LABEL_EDGE_ZONE
)
3591 d
= abs( y
- m_rowBottoms
[i
] );
3593 if ( d
< WXGRID_LABEL_EDGE_ZONE
) return i
;
3602 // return the col number that that the x coord is near the edge of, or
3603 // -1 if not near an edge
3605 int wxGrid::XToEdgeOfCol( int x
)
3609 for ( i
= 0; i
< m_numCols
; i
++ )
3611 if ( m_colWidths
[i
] > WXGRID_LABEL_EDGE_ZONE
)
3613 d
= abs( x
- m_colRights
[i
] );
3615 if ( d
< WXGRID_LABEL_EDGE_ZONE
) return i
;
3624 wxRect
wxGrid::CellToRect( int row
, int col
)
3626 wxRect
rect( -1, -1, -1, -1 );
3628 if ( row
>= 0 && row
< m_numRows
&&
3629 col
>= 0 && col
< m_numCols
)
3631 rect
.x
= m_colRights
[col
] - m_colWidths
[col
];
3632 rect
.y
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3633 rect
.width
= m_colWidths
[col
];
3634 rect
.height
= m_rowHeights
[ row
];
3641 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
3643 // get the cell rectangle in logical coords
3645 wxRect
r( CellToRect( row
, col
) );
3647 // convert to device coords
3649 int left
, top
, right
, bottom
;
3650 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
3651 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
3653 // check against the client area of the grid window
3656 m_gridWin
->GetClientSize( &cw
, &ch
);
3658 if ( wholeCellVisible
)
3660 // is the cell wholly visible ?
3662 return ( left
>= 0 && right
<= cw
&&
3663 top
>= 0 && bottom
<= ch
);
3667 // is the cell partly visible ?
3669 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
3670 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
3675 // make the specified cell location visible by doing a minimal amount
3678 void wxGrid::MakeCellVisible( int row
, int col
)
3681 int xpos
= -1, ypos
= -1;
3683 if ( row
>= 0 && row
< m_numRows
&&
3684 col
>= 0 && col
< m_numCols
)
3686 // get the cell rectangle in logical coords
3688 wxRect
r( CellToRect( row
, col
) );
3690 // convert to device coords
3692 int left
, top
, right
, bottom
;
3693 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
3694 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
3697 m_gridWin
->GetClientSize( &cw
, &ch
);
3703 else if ( bottom
> ch
)
3705 int h
= r
.GetHeight();
3707 for ( i
= row
-1; i
>= 0; i
-- )
3709 if ( h
+ m_rowHeights
[i
] > ch
) break;
3711 h
+= m_rowHeights
[i
];
3712 ypos
-= m_rowHeights
[i
];
3715 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
3716 // have rounding errors (this is important, because if we do, we
3717 // might not scroll at all and some cells won't be redrawn)
3718 ypos
+= GRID_SCROLL_LINE
/ 2;
3725 else if ( right
> cw
)
3727 int w
= r
.GetWidth();
3729 for ( i
= col
-1; i
>= 0; i
-- )
3731 if ( w
+ m_colWidths
[i
] > cw
) break;
3733 w
+= m_colWidths
[i
];
3734 xpos
-= m_colWidths
[i
];
3737 // see comment for ypos above
3738 xpos
+= GRID_SCROLL_LINE
/ 2;
3741 if ( xpos
!= -1 || ypos
!= -1 )
3743 if ( xpos
!= -1 ) xpos
/= GRID_SCROLL_LINE
;
3744 if ( ypos
!= -1 ) ypos
/= GRID_SCROLL_LINE
;
3745 Scroll( xpos
, ypos
);
3753 // ------ Grid cursor movement functions
3756 bool wxGrid::MoveCursorUp()
3758 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
3759 m_currentCellCoords
.GetRow() > 0 )
3761 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
3762 m_currentCellCoords
.GetCol() );
3764 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
3765 m_currentCellCoords
.GetCol() );
3774 bool wxGrid::MoveCursorDown()
3776 // TODO: allow for scrolling
3778 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
3779 m_currentCellCoords
.GetRow() < m_numRows
-1 )
3781 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
3782 m_currentCellCoords
.GetCol() );
3784 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
3785 m_currentCellCoords
.GetCol() );
3794 bool wxGrid::MoveCursorLeft()
3796 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
3797 m_currentCellCoords
.GetCol() > 0 )
3799 MakeCellVisible( m_currentCellCoords
.GetRow(),
3800 m_currentCellCoords
.GetCol() - 1 );
3802 SetCurrentCell( m_currentCellCoords
.GetRow(),
3803 m_currentCellCoords
.GetCol() - 1 );
3812 bool wxGrid::MoveCursorRight()
3814 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
3815 m_currentCellCoords
.GetCol() < m_numCols
- 1 )
3817 MakeCellVisible( m_currentCellCoords
.GetRow(),
3818 m_currentCellCoords
.GetCol() + 1 );
3820 SetCurrentCell( m_currentCellCoords
.GetRow(),
3821 m_currentCellCoords
.GetCol() + 1 );
3830 bool wxGrid::MovePageUp()
3832 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
3834 int row
= m_currentCellCoords
.GetRow();
3838 m_gridWin
->GetClientSize( &cw
, &ch
);
3840 int y
= m_rowBottoms
[ row
] - m_rowHeights
[ row
];
3841 int newRow
= YToRow( y
- ch
+ 1 );
3846 else if ( newRow
== row
)
3851 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
3852 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
3860 bool wxGrid::MovePageDown()
3862 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
3864 int row
= m_currentCellCoords
.GetRow();
3865 if ( row
< m_numRows
)
3868 m_gridWin
->GetClientSize( &cw
, &ch
);
3870 int y
= m_rowBottoms
[ row
] - m_rowHeights
[ row
];
3871 int newRow
= YToRow( y
+ ch
);
3874 newRow
= m_numRows
- 1;
3876 else if ( newRow
== row
)
3881 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
3882 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
3890 bool wxGrid::MoveCursorUpBlock()
3893 m_currentCellCoords
!= wxGridNoCellCoords
&&
3894 m_currentCellCoords
.GetRow() > 0 )
3896 int row
= m_currentCellCoords
.GetRow();
3897 int col
= m_currentCellCoords
.GetCol();
3899 if ( m_table
->IsEmptyCell(row
, col
) )
3901 // starting in an empty cell: find the next block of
3907 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
3910 else if ( m_table
->IsEmptyCell(row
-1, col
) )
3912 // starting at the top of a block: find the next block
3918 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
3923 // starting within a block: find the top of the block
3928 if ( m_table
->IsEmptyCell(row
, col
) )
3936 MakeCellVisible( row
, col
);
3937 SetCurrentCell( row
, col
);
3945 bool wxGrid::MoveCursorDownBlock()
3948 m_currentCellCoords
!= wxGridNoCellCoords
&&
3949 m_currentCellCoords
.GetRow() < m_numRows
-1 )
3951 int row
= m_currentCellCoords
.GetRow();
3952 int col
= m_currentCellCoords
.GetCol();
3954 if ( m_table
->IsEmptyCell(row
, col
) )
3956 // starting in an empty cell: find the next block of
3959 while ( row
< m_numRows
-1 )
3962 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
3965 else if ( m_table
->IsEmptyCell(row
+1, col
) )
3967 // starting at the bottom of a block: find the next block
3970 while ( row
< m_numRows
-1 )
3973 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
3978 // starting within a block: find the bottom of the block
3980 while ( row
< m_numRows
-1 )
3983 if ( m_table
->IsEmptyCell(row
, col
) )
3991 MakeCellVisible( row
, col
);
3992 SetCurrentCell( row
, col
);
4000 bool wxGrid::MoveCursorLeftBlock()
4003 m_currentCellCoords
!= wxGridNoCellCoords
&&
4004 m_currentCellCoords
.GetCol() > 0 )
4006 int row
= m_currentCellCoords
.GetRow();
4007 int col
= m_currentCellCoords
.GetCol();
4009 if ( m_table
->IsEmptyCell(row
, col
) )
4011 // starting in an empty cell: find the next block of
4017 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4020 else if ( m_table
->IsEmptyCell(row
, col
-1) )
4022 // starting at the left of a block: find the next block
4028 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4033 // starting within a block: find the left of the block
4038 if ( m_table
->IsEmptyCell(row
, col
) )
4046 MakeCellVisible( row
, col
);
4047 SetCurrentCell( row
, col
);
4055 bool wxGrid::MoveCursorRightBlock()
4058 m_currentCellCoords
!= wxGridNoCellCoords
&&
4059 m_currentCellCoords
.GetCol() < m_numCols
-1 )
4061 int row
= m_currentCellCoords
.GetRow();
4062 int col
= m_currentCellCoords
.GetCol();
4064 if ( m_table
->IsEmptyCell(row
, col
) )
4066 // starting in an empty cell: find the next block of
4069 while ( col
< m_numCols
-1 )
4072 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4075 else if ( m_table
->IsEmptyCell(row
, col
+1) )
4077 // starting at the right of a block: find the next block
4080 while ( col
< m_numCols
-1 )
4083 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4088 // starting within a block: find the right of the block
4090 while ( col
< m_numCols
-1 )
4093 if ( m_table
->IsEmptyCell(row
, col
) )
4101 MakeCellVisible( row
, col
);
4102 SetCurrentCell( row
, col
);
4113 // ------ Label values and formatting
4116 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
4118 *horiz
= m_rowLabelHorizAlign
;
4119 *vert
= m_rowLabelVertAlign
;
4122 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
4124 *horiz
= m_colLabelHorizAlign
;
4125 *vert
= m_colLabelVertAlign
;
4128 wxString
wxGrid::GetRowLabelValue( int row
)
4132 return m_table
->GetRowLabelValue( row
);
4142 wxString
wxGrid::GetColLabelValue( int col
)
4146 return m_table
->GetColLabelValue( col
);
4157 void wxGrid::SetRowLabelSize( int width
)
4159 width
= wxMax( width
, 0 );
4160 if ( width
!= m_rowLabelWidth
)
4164 m_rowLabelWin
->Show( FALSE
);
4165 m_cornerLabelWin
->Show( FALSE
);
4167 else if ( m_rowLabelWidth
== 0 )
4169 m_rowLabelWin
->Show( TRUE
);
4170 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
4173 m_rowLabelWidth
= width
;
4180 void wxGrid::SetColLabelSize( int height
)
4182 height
= wxMax( height
, 0 );
4183 if ( height
!= m_colLabelHeight
)
4187 m_colLabelWin
->Show( FALSE
);
4188 m_cornerLabelWin
->Show( FALSE
);
4190 else if ( m_colLabelHeight
== 0 )
4192 m_colLabelWin
->Show( TRUE
);
4193 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
4196 m_colLabelHeight
= height
;
4203 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
4205 if ( m_labelBackgroundColour
!= colour
)
4207 m_labelBackgroundColour
= colour
;
4208 m_rowLabelWin
->SetBackgroundColour( colour
);
4209 m_colLabelWin
->SetBackgroundColour( colour
);
4210 m_cornerLabelWin
->SetBackgroundColour( colour
);
4212 if ( !GetBatchCount() )
4214 m_rowLabelWin
->Refresh();
4215 m_colLabelWin
->Refresh();
4216 m_cornerLabelWin
->Refresh();
4221 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
4223 if ( m_labelTextColour
!= colour
)
4225 m_labelTextColour
= colour
;
4226 if ( !GetBatchCount() )
4228 m_rowLabelWin
->Refresh();
4229 m_colLabelWin
->Refresh();
4234 void wxGrid::SetLabelFont( const wxFont
& font
)
4237 if ( !GetBatchCount() )
4239 m_rowLabelWin
->Refresh();
4240 m_colLabelWin
->Refresh();
4244 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
4246 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
4248 m_rowLabelHorizAlign
= horiz
;
4251 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
4253 m_rowLabelVertAlign
= vert
;
4256 if ( !GetBatchCount() )
4258 m_rowLabelWin
->Refresh();
4262 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
4264 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
4266 m_colLabelHorizAlign
= horiz
;
4269 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
4271 m_colLabelVertAlign
= vert
;
4274 if ( !GetBatchCount() )
4276 m_colLabelWin
->Refresh();
4280 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
4284 m_table
->SetRowLabelValue( row
, s
);
4285 if ( !GetBatchCount() )
4287 wxRect rect
= CellToRect( row
, 0);
4288 if ( rect
.height
> 0 )
4290 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
4292 rect
.width
= m_rowLabelWidth
;
4293 m_rowLabelWin
->Refresh( TRUE
, &rect
);
4299 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
4303 m_table
->SetColLabelValue( col
, s
);
4304 if ( !GetBatchCount() )
4306 wxRect rect
= CellToRect( 0, col
);
4307 if ( rect
.width
> 0 )
4309 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
4311 rect
.height
= m_colLabelHeight
;
4312 m_colLabelWin
->Refresh( TRUE
, &rect
);
4318 void wxGrid::SetGridLineColour( const wxColour
& colour
)
4320 if ( m_gridLineColour
!= colour
)
4322 m_gridLineColour
= colour
;
4324 wxClientDC
dc( m_gridWin
);
4326 DrawAllGridLines( dc
, wxRegion() );
4330 void wxGrid::EnableGridLines( bool enable
)
4332 if ( enable
!= m_gridLinesEnabled
)
4334 m_gridLinesEnabled
= enable
;
4336 if ( !GetBatchCount() )
4340 wxClientDC
dc( m_gridWin
);
4342 DrawAllGridLines( dc
, wxRegion() );
4346 m_gridWin
->Refresh();
4353 int wxGrid::GetDefaultRowSize()
4355 return m_defaultRowHeight
;
4358 int wxGrid::GetRowSize( int row
)
4360 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
4362 return m_rowHeights
[row
];
4365 int wxGrid::GetDefaultColSize()
4367 return m_defaultColWidth
;
4370 int wxGrid::GetColSize( int col
)
4372 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
4374 return m_colWidths
[col
];
4377 wxColour
wxGrid::GetDefaultCellBackgroundColour()
4379 return GetBackgroundColour();
4382 // TODO VZ: this must be optimized to allow only retrieveing attr once!
4384 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
4386 wxGridCellAttr
*attr
= m_table
? m_table
->GetAttr(row
, col
) : NULL
;
4389 if ( attr
&& attr
->HasBackgroundColour() )
4390 colour
= attr
->GetBackgroundColour();
4392 colour
= GetDefaultCellBackgroundColour();
4399 wxColour
wxGrid::GetDefaultCellTextColour()
4401 return GetForegroundColour();
4404 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
4406 wxGridCellAttr
*attr
= m_table
? m_table
->GetAttr(row
, col
) : NULL
;
4409 if ( attr
&& attr
->HasTextColour() )
4410 colour
= attr
->GetTextColour();
4412 colour
= GetDefaultCellTextColour();
4420 wxFont
wxGrid::GetDefaultCellFont()
4422 return m_defaultCellFont
;
4425 wxFont
wxGrid::GetCellFont( int row
, int col
)
4427 wxGridCellAttr
*attr
= m_table
? m_table
->GetAttr(row
, col
) : NULL
;
4430 if ( attr
&& attr
->HasFont() )
4431 font
= attr
->GetFont();
4433 font
= GetDefaultCellFont();
4440 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
4443 *horiz
= m_defaultCellHAlign
;
4445 *vert
= m_defaultCellVAlign
;
4448 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
4450 wxGridCellAttr
*attr
= m_table
? m_table
->GetAttr(row
, col
) : NULL
;
4452 if ( attr
&& attr
->HasAlignment() )
4453 attr
->GetAlignment(horiz
, vert
);
4455 GetDefaultCellAlignment(horiz
, vert
);
4460 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
4462 m_defaultRowHeight
= wxMax( height
, WXGRID_MIN_ROW_HEIGHT
);
4464 if ( resizeExistingRows
)
4468 for ( row
= 0; row
< m_numRows
; row
++ )
4470 m_rowHeights
[row
] = m_defaultRowHeight
;
4471 bottom
+= m_defaultRowHeight
;
4472 m_rowBottoms
[row
] = bottom
;
4478 void wxGrid::SetRowSize( int row
, int height
)
4480 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
4484 int h
= wxMax( 0, height
);
4485 int diff
= h
- m_rowHeights
[row
];
4487 m_rowHeights
[row
] = h
;
4488 for ( i
= row
; i
< m_numRows
; i
++ )
4490 m_rowBottoms
[i
] += diff
;
4494 // Note: we are ending the event *after* doing
4495 // default processing in this case
4497 SendEvent( EVT_GRID_ROW_SIZE
,
4501 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
4503 m_defaultColWidth
= wxMax( width
, WXGRID_MIN_COL_WIDTH
);
4505 if ( resizeExistingCols
)
4509 for ( col
= 0; col
< m_numCols
; col
++ )
4511 m_colWidths
[col
] = m_defaultColWidth
;
4512 right
+= m_defaultColWidth
;
4513 m_colRights
[col
] = right
;
4519 void wxGrid::SetColSize( int col
, int width
)
4521 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
4525 int w
= wxMax( 0, width
);
4526 int diff
= w
- m_colWidths
[col
];
4527 m_colWidths
[col
] = w
;
4529 for ( i
= col
; i
< m_numCols
; i
++ )
4531 m_colRights
[i
] += diff
;
4535 // Note: we are ending the event *after* doing
4536 // default processing in this case
4538 SendEvent( EVT_GRID_COL_SIZE
,
4542 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
4544 SetBackgroundColour(col
);
4547 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
4549 SetForegroundColour(col
);
4552 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
4554 m_defaultCellHAlign
= horiz
;
4555 m_defaultCellVAlign
= vert
;
4558 bool wxGrid::CanHaveAttributes()
4565 if ( !m_table
->GetAttrProvider() )
4567 // use the default attr provider by default
4568 // (another choice would be to just return FALSE thus forcing the user
4570 m_table
->SetAttrProvider(new wxGridCellAttrProvider
);
4576 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
4578 if ( CanHaveAttributes() )
4580 wxGridCellAttr
*attr
= new wxGridCellAttr
;
4581 attr
->SetBackgroundColour(colour
);
4583 m_table
->SetAttr(attr
, row
, col
);
4587 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
4589 if ( CanHaveAttributes() )
4591 wxGridCellAttr
*attr
= new wxGridCellAttr
;
4592 attr
->SetTextColour(colour
);
4594 m_table
->SetAttr(attr
, row
, col
);
4598 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
4600 m_defaultCellFont
= font
;
4603 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
4605 if ( CanHaveAttributes() )
4607 wxGridCellAttr
*attr
= new wxGridCellAttr
;
4608 attr
->SetFont(font
);
4610 m_table
->SetAttr(attr
, row
, col
);
4614 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
4616 if ( CanHaveAttributes() )
4618 wxGridCellAttr
*attr
= new wxGridCellAttr
;
4619 attr
->SetAlignment(horiz
, vert
);
4621 m_table
->SetAttr(attr
, row
, col
);
4628 // ------ cell value accessor functions
4631 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
4635 m_table
->SetValue( row
, col
, s
.c_str() );
4636 if ( !GetBatchCount() )
4638 wxClientDC
dc( m_gridWin
);
4640 DrawCell( dc
, wxGridCellCoords(row
, col
) );
4643 #if 0 // TODO: edit in place
4645 if ( m_currentCellCoords
.GetRow() == row
&&
4646 m_currentCellCoords
.GetCol() == col
)
4648 SetEditControlValue( s
);
4657 // ------ Block, row and col selection
4660 void wxGrid::SelectRow( int row
, bool addToSelected
)
4664 if ( IsSelection() && addToSelected
)
4667 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
4670 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
4671 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
4672 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
4673 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
4677 need_refresh
[0] = TRUE
;
4678 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( row
, 0 ),
4679 wxGridCellCoords ( oldTop
- 1,
4681 m_selectedTopLeft
.SetRow( row
);
4686 need_refresh
[1] = TRUE
;
4687 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
, 0 ),
4688 wxGridCellCoords ( oldBottom
,
4691 m_selectedTopLeft
.SetCol( 0 );
4694 if ( oldBottom
< row
)
4696 need_refresh
[2] = TRUE
;
4697 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1, 0 ),
4698 wxGridCellCoords ( row
,
4700 m_selectedBottomRight
.SetRow( row
);
4703 if ( oldRight
< m_numCols
- 1 )
4705 need_refresh
[3] = TRUE
;
4706 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
4708 wxGridCellCoords ( oldBottom
,
4710 m_selectedBottomRight
.SetCol( m_numCols
- 1 );
4713 for (i
= 0; i
< 4; i
++ )
4714 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
4715 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
4719 r
= SelectionToDeviceRect();
4721 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
4723 m_selectedTopLeft
.Set( row
, 0 );
4724 m_selectedBottomRight
.Set( row
, m_numCols
-1 );
4725 r
= SelectionToDeviceRect();
4726 m_gridWin
->Refresh( FALSE
, &r
);
4729 wxGridRangeSelectEvent
gridEvt( GetId(),
4730 EVT_GRID_RANGE_SELECT
,
4733 m_selectedBottomRight
);
4735 GetEventHandler()->ProcessEvent(gridEvt
);
4739 void wxGrid::SelectCol( int col
, bool addToSelected
)
4741 if ( IsSelection() && addToSelected
)
4744 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
4747 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
4748 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
4749 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
4750 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
4752 if ( oldLeft
> col
)
4754 need_refresh
[0] = TRUE
;
4755 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( 0, col
),
4756 wxGridCellCoords ( m_numRows
- 1,
4758 m_selectedTopLeft
.SetCol( col
);
4763 need_refresh
[1] = TRUE
;
4764 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( 0, oldLeft
),
4765 wxGridCellCoords ( oldTop
- 1,
4767 m_selectedTopLeft
.SetRow( 0 );
4770 if ( oldRight
< col
)
4772 need_refresh
[2] = TRUE
;
4773 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( 0, oldRight
+ 1 ),
4774 wxGridCellCoords ( m_numRows
- 1,
4776 m_selectedBottomRight
.SetCol( col
);
4779 if ( oldBottom
< m_numRows
- 1 )
4781 need_refresh
[3] = TRUE
;
4782 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1,
4784 wxGridCellCoords ( m_numRows
- 1,
4786 m_selectedBottomRight
.SetRow( m_numRows
- 1 );
4789 for (i
= 0; i
< 4; i
++ )
4790 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
4791 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
4797 r
= SelectionToDeviceRect();
4799 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
4801 m_selectedTopLeft
.Set( 0, col
);
4802 m_selectedBottomRight
.Set( m_numRows
-1, col
);
4803 r
= SelectionToDeviceRect();
4804 m_gridWin
->Refresh( FALSE
, &r
);
4807 wxGridRangeSelectEvent
gridEvt( GetId(),
4808 EVT_GRID_RANGE_SELECT
,
4811 m_selectedBottomRight
);
4813 GetEventHandler()->ProcessEvent(gridEvt
);
4817 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
4820 wxGridCellCoords updateTopLeft
, updateBottomRight
;
4822 if ( topRow
> bottomRow
)
4829 if ( leftCol
> rightCol
)
4836 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
4837 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
4839 if ( m_selectedTopLeft
!= updateTopLeft
||
4840 m_selectedBottomRight
!= updateBottomRight
)
4842 // Compute two optimal update rectangles:
4843 // Either one rectangle is a real subset of the
4844 // other, or they are (almost) disjoint!
4846 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
4849 // Store intermediate values
4850 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
4851 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
4852 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
4853 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
4855 // Determine the outer/inner coordinates.
4856 if (oldLeft
> leftCol
)
4862 if (oldTop
> topRow
)
4868 if (oldRight
< rightCol
)
4871 oldRight
= rightCol
;
4874 if (oldBottom
< bottomRow
)
4877 oldBottom
= bottomRow
;
4881 // Now, either the stuff marked old is the outer
4882 // rectangle or we don't have a situation where one
4883 // is contained in the other.
4885 if ( oldLeft
< leftCol
)
4887 need_refresh
[0] = TRUE
;
4888 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
4890 wxGridCellCoords ( oldBottom
,
4894 if ( oldTop
< topRow
)
4896 need_refresh
[1] = TRUE
;
4897 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
4899 wxGridCellCoords ( topRow
- 1,
4903 if ( oldRight
> rightCol
)
4905 need_refresh
[2] = TRUE
;
4906 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
4908 wxGridCellCoords ( oldBottom
,
4912 if ( oldBottom
> bottomRow
)
4914 need_refresh
[3] = TRUE
;
4915 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
4917 wxGridCellCoords ( oldBottom
,
4923 m_selectedTopLeft
= updateTopLeft
;
4924 m_selectedBottomRight
= updateBottomRight
;
4926 // various Refresh() calls
4927 for (i
= 0; i
< 4; i
++ )
4928 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
4929 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
4932 // only generate an event if the block is not being selected by
4933 // dragging the mouse (in which case the event will be generated in
4934 // the mouse event handler)
4935 if ( !m_isDragging
)
4937 wxGridRangeSelectEvent
gridEvt( GetId(),
4938 EVT_GRID_RANGE_SELECT
,
4941 m_selectedBottomRight
);
4943 GetEventHandler()->ProcessEvent(gridEvt
);
4947 void wxGrid::SelectAll()
4949 m_selectedTopLeft
.Set( 0, 0 );
4950 m_selectedBottomRight
.Set( m_numRows
-1, m_numCols
-1 );
4952 m_gridWin
->Refresh();
4956 void wxGrid::ClearSelection()
4958 m_selectedTopLeft
= wxGridNoCellCoords
;
4959 m_selectedBottomRight
= wxGridNoCellCoords
;
4963 // This function returns the rectangle that encloses the given block
4964 // in device coords clipped to the client size of the grid window.
4966 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
4967 const wxGridCellCoords
&bottomRight
)
4969 wxRect
rect( wxGridNoCellRect
);
4972 cellRect
= CellToRect( topLeft
);
4973 if ( cellRect
!= wxGridNoCellRect
)
4979 rect
= wxRect( 0, 0, 0, 0 );
4982 cellRect
= CellToRect( bottomRight
);
4983 if ( cellRect
!= wxGridNoCellRect
)
4989 return wxGridNoCellRect
;
4992 // convert to scrolled coords
4994 int left
, top
, right
, bottom
;
4995 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
4996 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
4999 m_gridWin
->GetClientSize( &cw
, &ch
);
5001 rect
.SetLeft( wxMax(0, left
) );
5002 rect
.SetTop( wxMax(0, top
) );
5003 rect
.SetRight( wxMin(cw
, right
) );
5004 rect
.SetBottom( wxMin(ch
, bottom
) );
5012 // ------ Grid event classes
5015 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxEvent
)
5017 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
5018 int row
, int col
, int x
, int y
,
5019 bool control
, bool shift
, bool alt
, bool meta
)
5020 : wxNotifyEvent( type
, id
)
5026 m_control
= control
;
5031 SetEventObject(obj
);
5035 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxEvent
)
5037 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
5038 int rowOrCol
, int x
, int y
,
5039 bool control
, bool shift
, bool alt
, bool meta
)
5040 : wxNotifyEvent( type
, id
)
5042 m_rowOrCol
= rowOrCol
;
5045 m_control
= control
;
5050 SetEventObject(obj
);
5054 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxEvent
)
5056 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
5057 const wxGridCellCoords
& topLeft
,
5058 const wxGridCellCoords
& bottomRight
,
5059 bool control
, bool shift
, bool alt
, bool meta
)
5060 : wxNotifyEvent( type
, id
)
5062 m_topLeft
= topLeft
;
5063 m_bottomRight
= bottomRight
;
5064 m_control
= control
;
5069 SetEventObject(obj
);
5073 #endif // ifndef wxUSE_NEW_GRID