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"
34 #include "wx/textfile.h"
37 #include "wx/generic/grid.h"
39 // ----------------------------------------------------------------------------
40 // array classes instantiation
41 // ----------------------------------------------------------------------------
43 struct wxGridCellWithAttr
45 wxGridCellWithAttr(int row
, int col
, const wxGridCellAttr
*pAttr
)
46 : coords(row
, col
), attr(*pAttr
)
50 wxGridCellCoords coords
;
54 WX_DECLARE_OBJARRAY(wxGridCellWithAttr
, wxGridCellWithAttrArray
);
56 #include "wx/arrimpl.cpp"
58 WX_DEFINE_OBJARRAY(wxGridCellCoordsArray
)
59 WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray
)
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 class WXDLLEXPORT wxGridRowLabelWindow
: public wxWindow
68 wxGridRowLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
69 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
70 const wxPoint
&pos
, const wxSize
&size
);
75 void OnPaint( wxPaintEvent
& event
);
76 void OnMouseEvent( wxMouseEvent
& event
);
77 void OnKeyDown( wxKeyEvent
& event
);
79 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
84 class WXDLLEXPORT wxGridColLabelWindow
: public wxWindow
87 wxGridColLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
88 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
89 const wxPoint
&pos
, const wxSize
&size
);
94 void OnPaint( wxPaintEvent
&event
);
95 void OnMouseEvent( wxMouseEvent
& event
);
96 void OnKeyDown( wxKeyEvent
& event
);
98 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
103 class WXDLLEXPORT wxGridCornerLabelWindow
: public wxWindow
106 wxGridCornerLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
107 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
108 const wxPoint
&pos
, const wxSize
&size
);
113 void OnMouseEvent( wxMouseEvent
& event
);
114 void OnKeyDown( wxKeyEvent
& event
);
115 void OnPaint( wxPaintEvent
& event
);
117 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
118 DECLARE_EVENT_TABLE()
121 class WXDLLEXPORT wxGridWindow
: public wxPanel
126 m_owner
= (wxGrid
*)NULL
;
127 m_rowLabelWin
= (wxGridRowLabelWindow
*)NULL
;
128 m_colLabelWin
= (wxGridColLabelWindow
*)NULL
;
131 wxGridWindow( wxGrid
*parent
,
132 wxGridRowLabelWindow
*rowLblWin
,
133 wxGridColLabelWindow
*colLblWin
,
134 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
137 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
141 wxGridRowLabelWindow
*m_rowLabelWin
;
142 wxGridColLabelWindow
*m_colLabelWin
;
144 void OnPaint( wxPaintEvent
&event
);
145 void OnMouseEvent( wxMouseEvent
& event
);
146 void OnKeyDown( wxKeyEvent
& );
148 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
149 DECLARE_EVENT_TABLE()
152 // the internal data representation used by wxGridCellAttrProvider
154 // TODO make it more efficient
155 class WXDLLEXPORT wxGridCellAttrProviderData
158 void SetAttr(const wxGridCellAttr
*attr
, int row
, int col
);
159 wxGridCellAttr
*GetAttr(int row
, int col
) const;
162 // searches for the attr for given cell, returns wxNOT_FOUND if not found
163 int FindIndex(int row
, int col
) const;
165 wxGridCellWithAttrArray m_attrs
;
168 // ----------------------------------------------------------------------------
169 // conditional compilation
170 // ----------------------------------------------------------------------------
172 #ifndef WXGRID_DRAW_LINES
173 #define WXGRID_DRAW_LINES 1
176 //////////////////////////////////////////////////////////////////////
178 wxGridCellCoords
wxGridNoCellCoords( -1, -1 );
179 wxRect
wxGridNoCellRect( -1, -1, -1, -1 );
182 // TODO: fixed so far - make configurable later (and also different for x/y)
183 static const size_t GRID_SCROLL_LINE
= 10;
185 // ----------------------------------------------------------------------------
186 // wxGridCellAttrProviderData
187 // ----------------------------------------------------------------------------
189 void wxGridCellAttrProviderData::SetAttr(const wxGridCellAttr
*attr
,
192 int n
= FindIndex(row
, col
);
193 if ( n
== wxNOT_FOUND
)
196 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
202 // change the attribute
203 m_attrs
[(size_t)n
].attr
= *attr
;
207 // remove this attribute
208 m_attrs
.RemoveAt((size_t)n
);
215 wxGridCellAttr
*wxGridCellAttrProviderData::GetAttr(int row
, int col
) const
217 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
219 int n
= FindIndex(row
, col
);
220 if ( n
!= wxNOT_FOUND
)
222 attr
= new wxGridCellAttr(m_attrs
[(size_t)n
].attr
);
228 int wxGridCellAttrProviderData::FindIndex(int row
, int col
) const
230 size_t count
= m_attrs
.GetCount();
231 for ( size_t n
= 0; n
< count
; n
++ )
233 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
234 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
243 // ----------------------------------------------------------------------------
244 // wxGridCellAttrProvider
245 // ----------------------------------------------------------------------------
247 wxGridCellAttrProvider::wxGridCellAttrProvider()
249 m_data
= (wxGridCellAttrProviderData
*)NULL
;
252 wxGridCellAttrProvider::~wxGridCellAttrProvider()
257 void wxGridCellAttrProvider::InitData()
259 m_data
= new wxGridCellAttrProviderData
;
262 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
) const
264 return m_data
? m_data
->GetAttr(row
, col
) : (wxGridCellAttr
*)NULL
;
267 void wxGridCellAttrProvider::SetAttr(const wxGridCellAttr
*attr
,
273 m_data
->SetAttr(attr
, row
, col
);
276 //////////////////////////////////////////////////////////////////////
278 // Abstract base class for grid data (the model)
280 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
283 wxGridTableBase::wxGridTableBase()
285 m_view
= (wxGrid
*) NULL
;
286 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
289 wxGridTableBase::~wxGridTableBase()
291 delete m_attrProvider
;
294 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
296 delete m_attrProvider
;
297 m_attrProvider
= attrProvider
;
300 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
)
302 if ( m_attrProvider
)
303 return m_attrProvider
->GetAttr(row
, col
);
305 return (wxGridCellAttr
*)NULL
;
308 void wxGridTableBase::SetAttr(const wxGridCellAttr
*attr
, int row
, int col
)
310 if ( m_attrProvider
)
312 m_attrProvider
->SetAttr(attr
, row
, col
);
316 // as we take ownership of the pointer and don't store it, we must
322 bool wxGridTableBase::InsertRows( size_t pos
, size_t numRows
)
324 wxFAIL_MSG( wxT("Called grid table class function InsertRows\n"
325 "but your derived table class does not override this function") );
330 bool wxGridTableBase::AppendRows( size_t numRows
)
332 wxFAIL_MSG( wxT("Called grid table class function AppendRows\n"
333 "but your derived table class does not override this function"));
338 bool wxGridTableBase::DeleteRows( size_t pos
, size_t numRows
)
340 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\n"
341 "but your derived table class does not override this function"));
346 bool wxGridTableBase::InsertCols( size_t pos
, size_t numCols
)
348 wxFAIL_MSG( wxT("Called grid table class function InsertCols\n"
349 "but your derived table class does not override this function"));
354 bool wxGridTableBase::AppendCols( size_t numCols
)
356 wxFAIL_MSG(wxT("Called grid table class function AppendCols\n"
357 "but your derived table class does not override this function"));
362 bool wxGridTableBase::DeleteCols( size_t pos
, size_t numCols
)
364 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\n"
365 "but your derived table class does not override this function"));
371 wxString
wxGridTableBase::GetRowLabelValue( int row
)
378 wxString
wxGridTableBase::GetColLabelValue( int col
)
380 // default col labels are:
381 // cols 0 to 25 : A-Z
382 // cols 26 to 675 : AA-ZZ
389 s
+= (_T('A') + (wxChar
)( col%26
));
391 if ( col
< 0 ) break;
394 // reverse the string...
396 for ( i
= 0; i
< n
; i
++ )
406 //////////////////////////////////////////////////////////////////////
408 // Message class for the grid table to send requests and notifications
412 wxGridTableMessage::wxGridTableMessage()
414 m_table
= (wxGridTableBase
*) NULL
;
420 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
421 int commandInt1
, int commandInt2
)
425 m_comInt1
= commandInt1
;
426 m_comInt2
= commandInt2
;
431 //////////////////////////////////////////////////////////////////////
433 // A basic grid table for string data. An object of this class will
434 // created by wxGrid if you don't specify an alternative table class.
437 WX_DEFINE_OBJARRAY(wxGridStringArray
)
439 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
441 wxGridStringTable::wxGridStringTable()
446 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
451 m_data
.Alloc( numRows
);
455 for ( col
= 0; col
< numCols
; col
++ )
457 sa
.Add( wxEmptyString
);
460 for ( row
= 0; row
< numRows
; row
++ )
466 wxGridStringTable::~wxGridStringTable()
470 long wxGridStringTable::GetNumberRows()
472 return m_data
.GetCount();
475 long wxGridStringTable::GetNumberCols()
477 if ( m_data
.GetCount() > 0 )
478 return m_data
[0].GetCount();
483 wxString
wxGridStringTable::GetValue( int row
, int col
)
485 // TODO: bounds checking
487 return m_data
[row
][col
];
490 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& s
)
492 // TODO: bounds checking
494 m_data
[row
][col
] = s
;
497 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
499 // TODO: bounds checking
501 return (m_data
[row
][col
] == wxEmptyString
);
505 void wxGridStringTable::Clear()
508 int numRows
, numCols
;
510 numRows
= m_data
.GetCount();
513 numCols
= m_data
[0].GetCount();
515 for ( row
= 0; row
< numRows
; row
++ )
517 for ( col
= 0; col
< numCols
; col
++ )
519 m_data
[row
][col
] = wxEmptyString
;
526 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
530 size_t curNumRows
= m_data
.GetCount();
531 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
533 if ( pos
>= curNumRows
)
535 return AppendRows( numRows
);
539 sa
.Alloc( curNumCols
);
540 for ( col
= 0; col
< curNumCols
; col
++ )
542 sa
.Add( wxEmptyString
);
545 for ( row
= pos
; row
< pos
+ numRows
; row
++ )
547 m_data
.Insert( sa
, row
);
552 wxGridTableMessage
msg( this,
553 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
557 GetView()->ProcessTableMessage( msg
);
563 bool wxGridStringTable::AppendRows( size_t numRows
)
567 size_t curNumRows
= m_data
.GetCount();
568 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
571 if ( curNumCols
> 0 )
573 sa
.Alloc( curNumCols
);
574 for ( col
= 0; col
< curNumCols
; col
++ )
576 sa
.Add( wxEmptyString
);
580 for ( row
= 0; row
< numRows
; row
++ )
587 wxGridTableMessage
msg( this,
588 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
591 GetView()->ProcessTableMessage( msg
);
597 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
601 size_t curNumRows
= m_data
.GetCount();
603 if ( pos
>= curNumRows
)
606 errmsg
.Printf("Called wxGridStringTable::DeleteRows(pos=%d, N=%d)\n"
607 "Pos value is invalid for present table with %d rows",
608 pos
, numRows
, curNumRows
);
609 wxFAIL_MSG( wxT(errmsg
) );
613 if ( numRows
> curNumRows
- pos
)
615 numRows
= curNumRows
- pos
;
618 if ( numRows
>= curNumRows
)
620 m_data
.Empty(); // don't release memory just yet
624 for ( n
= 0; n
< numRows
; n
++ )
626 m_data
.Remove( pos
);
632 wxGridTableMessage
msg( this,
633 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
637 GetView()->ProcessTableMessage( msg
);
643 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
647 size_t curNumRows
= m_data
.GetCount();
648 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
650 if ( pos
>= curNumCols
)
652 return AppendCols( numCols
);
655 for ( row
= 0; row
< curNumRows
; row
++ )
657 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
659 m_data
[row
].Insert( wxEmptyString
, col
);
665 wxGridTableMessage
msg( this,
666 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
670 GetView()->ProcessTableMessage( msg
);
676 bool wxGridStringTable::AppendCols( size_t numCols
)
680 size_t curNumRows
= m_data
.GetCount();
683 // TODO: something better than this ?
685 wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\n"
686 "Call AppendRows() first") );
690 for ( row
= 0; row
< curNumRows
; row
++ )
692 for ( n
= 0; n
< numCols
; n
++ )
694 m_data
[row
].Add( wxEmptyString
);
700 wxGridTableMessage
msg( this,
701 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
704 GetView()->ProcessTableMessage( msg
);
710 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
714 size_t curNumRows
= m_data
.GetCount();
715 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
717 if ( pos
>= curNumCols
)
720 errmsg
.Printf( "Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\n"
721 "Pos value is invalid for present table with %d cols",
722 pos
, numCols
, curNumCols
);
723 wxFAIL_MSG( wxT( errmsg
) );
727 if ( numCols
> curNumCols
- pos
)
729 numCols
= curNumCols
- pos
;
732 for ( row
= 0; row
< curNumRows
; row
++ )
734 if ( numCols
>= curNumCols
)
740 for ( n
= 0; n
< numCols
; n
++ )
742 m_data
[row
].Remove( pos
);
749 wxGridTableMessage
msg( this,
750 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
754 GetView()->ProcessTableMessage( msg
);
760 wxString
wxGridStringTable::GetRowLabelValue( int row
)
762 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
764 // using default label
766 return wxGridTableBase::GetRowLabelValue( row
);
770 return m_rowLabels
[ row
];
774 wxString
wxGridStringTable::GetColLabelValue( int col
)
776 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
778 // using default label
780 return wxGridTableBase::GetColLabelValue( col
);
784 return m_colLabels
[ col
];
788 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
790 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
792 int n
= m_rowLabels
.GetCount();
794 for ( i
= n
; i
<= row
; i
++ )
796 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
800 m_rowLabels
[row
] = value
;
803 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
805 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
807 int n
= m_colLabels
.GetCount();
809 for ( i
= n
; i
<= col
; i
++ )
811 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
815 m_colLabels
[col
] = value
;
821 //////////////////////////////////////////////////////////////////////
823 IMPLEMENT_DYNAMIC_CLASS( wxGridTextCtrl
, wxTextCtrl
)
825 BEGIN_EVENT_TABLE( wxGridTextCtrl
, wxTextCtrl
)
826 EVT_KEY_DOWN( wxGridTextCtrl::OnKeyDown
)
830 wxGridTextCtrl::wxGridTextCtrl( wxWindow
*par
,
834 const wxString
& value
,
838 : wxTextCtrl( par
, id
, value
, pos
, size
, style
)
841 m_isCellControl
= isCellControl
;
845 void wxGridTextCtrl::OnKeyDown( wxKeyEvent
& event
)
847 switch ( event
.KeyCode() )
850 m_grid
->SetEditControlValue( startValue
);
851 SetInsertionPointEnd();
861 if ( m_isCellControl
)
863 // send the event to the parent grid, skipping the
864 // event if nothing happens
866 event
.Skip( m_grid
->ProcessEvent( event
) );
870 // default text control response within the top edit
878 if ( m_isCellControl
)
880 if ( !m_grid
->ProcessEvent( event
) )
882 #if defined(__WXMOTIF__) || defined(__WXGTK__)
883 // wxMotif needs a little extra help...
885 int pos
= GetInsertionPoint();
886 wxString
s( GetValue() );
887 s
= s
.Left(pos
) + "\n" + s
.Mid(pos
);
889 SetInsertionPoint( pos
);
891 // the other ports can handle a Return key press
901 if ( m_isCellControl
)
903 // send the event to the parent grid, skipping the
904 // event if nothing happens
906 event
.Skip( m_grid
->ProcessEvent( event
) );
910 // default text control response within the top edit
922 void wxGridTextCtrl::SetStartValue( const wxString
& s
)
925 wxTextCtrl::SetValue(s
);
930 //////////////////////////////////////////////////////////////////////
932 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
934 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
935 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
936 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
937 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
940 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
942 const wxPoint
&pos
, const wxSize
&size
)
943 : wxWindow( parent
, id
, pos
, size
)
948 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
&event
)
952 // NO - don't do this because it will set both the x and y origin
953 // coords to match the parent scrolled window and we just want to
954 // set the y coord - MB
956 // m_owner->PrepareDC( dc );
959 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
960 dc
.SetDeviceOrigin( 0, -y
);
962 m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
963 m_owner
->DrawRowLabels( dc
);
967 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
969 m_owner
->ProcessRowLabelMouseEvent( event
);
973 // This seems to be required for wxMotif otherwise the mouse
974 // cursor must be in the cell edit control to get key events
976 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
978 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
983 //////////////////////////////////////////////////////////////////////
985 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
987 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
988 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
989 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
990 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
993 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
995 const wxPoint
&pos
, const wxSize
&size
)
996 : wxWindow( parent
, id
, pos
, size
)
1001 void wxGridColLabelWindow::OnPaint( wxPaintEvent
&event
)
1005 // NO - don't do this because it will set both the x and y origin
1006 // coords to match the parent scrolled window and we just want to
1007 // set the x coord - MB
1009 // m_owner->PrepareDC( dc );
1012 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
1013 dc
.SetDeviceOrigin( -x
, 0 );
1015 m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
1016 m_owner
->DrawColLabels( dc
);
1020 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1022 m_owner
->ProcessColLabelMouseEvent( event
);
1026 // This seems to be required for wxMotif otherwise the mouse
1027 // cursor must be in the cell edit control to get key events
1029 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
1031 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1036 //////////////////////////////////////////////////////////////////////
1038 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
1040 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
1041 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
1042 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
1043 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
1046 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
1048 const wxPoint
&pos
, const wxSize
&size
)
1049 : wxWindow( parent
, id
, pos
, size
)
1054 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1058 int client_height
= 0;
1059 int client_width
= 0;
1060 GetClientSize( &client_width
, &client_height
);
1062 dc
.SetPen( *wxBLACK_PEN
);
1063 dc
.DrawLine( client_width
-1, client_height
-1, client_width
-1, 0 );
1064 dc
.DrawLine( client_width
-1, client_height
-1, 0, client_height
-1 );
1066 dc
.SetPen( *wxWHITE_PEN
);
1067 dc
.DrawLine( 0, 0, client_width
, 0 );
1068 dc
.DrawLine( 0, 0, 0, client_height
);
1072 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1074 m_owner
->ProcessCornerLabelMouseEvent( event
);
1078 // This seems to be required for wxMotif otherwise the mouse
1079 // cursor must be in the cell edit control to get key events
1081 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
1083 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1088 //////////////////////////////////////////////////////////////////////
1090 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxPanel
)
1092 BEGIN_EVENT_TABLE( wxGridWindow
, wxPanel
)
1093 EVT_PAINT( wxGridWindow::OnPaint
)
1094 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
1095 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
1098 wxGridWindow::wxGridWindow( wxGrid
*parent
,
1099 wxGridRowLabelWindow
*rowLblWin
,
1100 wxGridColLabelWindow
*colLblWin
,
1101 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
)
1102 : wxPanel( parent
, id
, pos
, size
, 0, "grid window" )
1105 m_rowLabelWin
= rowLblWin
;
1106 m_colLabelWin
= colLblWin
;
1108 SetBackgroundColour( "WHITE" );
1112 wxGridWindow::~wxGridWindow()
1117 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1119 wxPaintDC
dc( this );
1120 m_owner
->PrepareDC( dc
);
1121 wxRegion reg
= GetUpdateRegion();
1122 m_owner
->CalcCellsExposed( reg
);
1123 m_owner
->DrawGridCellArea( dc
);
1124 #if WXGRID_DRAW_LINES
1125 m_owner
->DrawAllGridLines( dc
, reg
);
1130 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
1132 wxPanel::ScrollWindow( dx
, dy
, rect
);
1133 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
1134 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
1138 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
1140 m_owner
->ProcessGridCellMouseEvent( event
);
1144 // This seems to be required for wxMotif otherwise the mouse
1145 // cursor must be in the cell edit control to get key events
1147 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
1149 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1154 //////////////////////////////////////////////////////////////////////
1156 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
1158 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
1159 EVT_PAINT( wxGrid::OnPaint
)
1160 EVT_SIZE( wxGrid::OnSize
)
1161 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
1164 wxGrid::wxGrid( wxWindow
*parent
,
1169 const wxString
& name
)
1170 : wxScrolledWindow( parent
, id
, pos
, size
, style
, name
)
1183 // ----- internal init and update functions
1186 void wxGrid::Create()
1188 m_created
= FALSE
; // set to TRUE by CreateGrid
1189 m_displayed
= FALSE
; // set to TRUE by OnPaint
1191 m_table
= (wxGridTableBase
*) NULL
;
1192 m_cellEditCtrl
= (wxWindow
*) NULL
;
1196 m_currentCellCoords
= wxGridNoCellCoords
;
1198 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
1199 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
1201 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
1206 m_rowLabelWin
= new wxGridRowLabelWindow( this,
1211 m_colLabelWin
= new wxGridColLabelWindow( this,
1216 m_gridWin
= new wxGridWindow( this,
1223 SetTargetWindow( m_gridWin
);
1227 bool wxGrid::CreateGrid( int numRows
, int numCols
)
1231 wxFAIL_MSG( wxT("wxGrid::CreateGrid called more than once") );
1236 m_numRows
= numRows
;
1237 m_numCols
= numCols
;
1239 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
1240 m_table
->SetView( this );
1253 if ( m_numRows
<= 0 )
1254 m_numRows
= WXGRID_DEFAULT_NUMBER_ROWS
;
1256 if ( m_numCols
<= 0 )
1257 m_numCols
= WXGRID_DEFAULT_NUMBER_COLS
;
1259 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
1260 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
1262 if ( m_rowLabelWin
)
1264 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
1268 m_labelBackgroundColour
= wxColour( _T("WHITE") );
1271 m_labelTextColour
= wxColour( _T("BLACK") );
1273 // TODO: something better than this ?
1275 m_labelFont
= this->GetFont();
1276 m_labelFont
.SetWeight( m_labelFont
.GetWeight() + 2 );
1278 m_rowLabelHorizAlign
= wxLEFT
;
1279 m_rowLabelVertAlign
= wxCENTRE
;
1281 m_colLabelHorizAlign
= wxCENTRE
;
1282 m_colLabelVertAlign
= wxTOP
;
1284 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
1285 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
1287 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
1288 m_defaultRowHeight
+= 8;
1290 m_defaultRowHeight
+= 4;
1293 m_rowHeights
.Alloc( m_numRows
);
1294 m_rowBottoms
.Alloc( m_numRows
);
1296 for ( i
= 0; i
< m_numRows
; i
++ )
1298 m_rowHeights
.Add( m_defaultRowHeight
);
1299 rowBottom
+= m_defaultRowHeight
;
1300 m_rowBottoms
.Add( rowBottom
);
1303 m_colWidths
.Alloc( m_numCols
);
1304 m_colRights
.Alloc( m_numCols
);
1306 for ( i
= 0; i
< m_numCols
; i
++ )
1308 m_colWidths
.Add( m_defaultColWidth
);
1309 colRight
+= m_defaultColWidth
;
1310 m_colRights
.Add( colRight
);
1313 // TODO: improve this by using wxSystemSettings?
1315 m_defaultCellFont
= GetFont();
1317 m_defaultCellHAlign
= wxLEFT
;
1318 m_defaultCellVAlign
= wxTOP
;
1320 m_gridLineColour
= wxColour( 128, 128, 255 );
1321 m_gridLinesEnabled
= TRUE
;
1323 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
1325 m_dragRowOrCol
= -1;
1326 m_isDragging
= FALSE
;
1328 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
1329 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
1331 m_currentCellCoords
= wxGridNoCellCoords
;
1333 m_selectedTopLeft
= wxGridNoCellCoords
;
1334 m_selectedBottomRight
= wxGridNoCellCoords
;
1336 m_editable
= TRUE
; // default for whole grid
1338 m_inOnKeyDown
= FALSE
;
1341 // TODO: extend this to other types of controls
1343 m_cellEditCtrl
= new wxGridTextCtrl( m_gridWin
,
1350 #if defined(__WXMSW__)
1351 , wxTE_MULTILINE
| wxTE_NO_VSCROLL
1355 m_cellEditCtrl
->Show( FALSE
);
1356 m_cellEditCtrlEnabled
= TRUE
;
1357 m_editCtrlType
= wxGRID_TEXTCTRL
;
1361 void wxGrid::CalcDimensions()
1364 GetClientSize( &cw
, &ch
);
1366 if ( m_numRows
> 0 && m_numCols
> 0 )
1368 int right
= m_colRights
[ m_numCols
-1 ] + 50;
1369 int bottom
= m_rowBottoms
[ m_numRows
-1 ] + 50;
1371 // TODO: restore the scroll position that we had before sizing
1374 GetViewStart( &x
, &y
);
1375 SetScrollbars( GRID_SCROLL_LINE
, GRID_SCROLL_LINE
,
1376 right
/GRID_SCROLL_LINE
, bottom
/GRID_SCROLL_LINE
,
1382 void wxGrid::CalcWindowSizes()
1385 GetClientSize( &cw
, &ch
);
1387 if ( m_cornerLabelWin
->IsShown() )
1388 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
1390 if ( m_colLabelWin
->IsShown() )
1391 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
1393 if ( m_rowLabelWin
->IsShown() )
1394 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
1396 if ( m_gridWin
->IsShown() )
1397 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
1401 // this is called when the grid table sends a message to say that it
1402 // has been redimensioned
1404 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
1408 switch ( msg
.GetId() )
1410 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
1412 size_t pos
= msg
.GetCommandInt();
1413 int numRows
= msg
.GetCommandInt2();
1414 for ( i
= 0; i
< numRows
; i
++ )
1416 m_rowHeights
.Insert( m_defaultRowHeight
, pos
);
1417 m_rowBottoms
.Insert( 0, pos
);
1419 m_numRows
+= numRows
;
1422 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
1424 for ( i
= pos
; i
< m_numRows
; i
++ )
1426 bottom
+= m_rowHeights
[i
];
1427 m_rowBottoms
[i
] = bottom
;
1433 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
1435 int numRows
= msg
.GetCommandInt();
1436 for ( i
= 0; i
< numRows
; i
++ )
1438 m_rowHeights
.Add( m_defaultRowHeight
);
1439 m_rowBottoms
.Add( 0 );
1442 int oldNumRows
= m_numRows
;
1443 m_numRows
+= numRows
;
1446 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
1448 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
1450 bottom
+= m_rowHeights
[i
];
1451 m_rowBottoms
[i
] = bottom
;
1457 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
1459 size_t pos
= msg
.GetCommandInt();
1460 int numRows
= msg
.GetCommandInt2();
1461 for ( i
= 0; i
< numRows
; i
++ )
1463 m_rowHeights
.Remove( pos
);
1464 m_rowBottoms
.Remove( pos
);
1466 m_numRows
-= numRows
;
1471 m_colWidths
.Clear();
1472 m_colRights
.Clear();
1473 m_currentCellCoords
= wxGridNoCellCoords
;
1477 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
1478 m_currentCellCoords
.Set( 0, 0 );
1481 for ( i
= 0; i
< m_numRows
; i
++ )
1483 h
+= m_rowHeights
[i
];
1484 m_rowBottoms
[i
] = h
;
1492 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
1494 size_t pos
= msg
.GetCommandInt();
1495 int numCols
= msg
.GetCommandInt2();
1496 for ( i
= 0; i
< numCols
; i
++ )
1498 m_colWidths
.Insert( m_defaultColWidth
, pos
);
1499 m_colRights
.Insert( 0, pos
);
1501 m_numCols
+= numCols
;
1504 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
1506 for ( i
= pos
; i
< m_numCols
; i
++ )
1508 right
+= m_colWidths
[i
];
1509 m_colRights
[i
] = right
;
1515 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
1517 int numCols
= msg
.GetCommandInt();
1518 for ( i
= 0; i
< numCols
; i
++ )
1520 m_colWidths
.Add( m_defaultColWidth
);
1521 m_colRights
.Add( 0 );
1524 int oldNumCols
= m_numCols
;
1525 m_numCols
+= numCols
;
1528 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
1530 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
1532 right
+= m_colWidths
[i
];
1533 m_colRights
[i
] = right
;
1539 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
1541 size_t pos
= msg
.GetCommandInt();
1542 int numCols
= msg
.GetCommandInt2();
1543 for ( i
= 0; i
< numCols
; i
++ )
1545 m_colWidths
.Remove( pos
);
1546 m_colRights
.Remove( pos
);
1548 m_numCols
-= numCols
;
1552 #if 0 // leave the row alone here so that AppendCols will work subsequently
1554 m_rowHeights
.Clear();
1555 m_rowBottoms
.Clear();
1557 m_currentCellCoords
= wxGridNoCellCoords
;
1561 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
1562 m_currentCellCoords
.Set( 0, 0 );
1565 for ( i
= 0; i
< m_numCols
; i
++ )
1567 w
+= m_colWidths
[i
];
1580 void wxGrid::CalcRowLabelsExposed( wxRegion
& reg
)
1582 wxRegionIterator
iter( reg
);
1585 m_rowLabelsExposed
.Empty();
1592 // TODO: remove this when we can...
1593 // There is a bug in wxMotif that gives garbage update
1594 // rectangles if you jump-scroll a long way by clicking the
1595 // scrollbar with middle button. This is a work-around
1597 #if defined(__WXMOTIF__)
1599 m_gridWin
->GetClientSize( &cw
, &ch
);
1600 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
1601 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
1604 // logical bounds of update region
1607 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
1608 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
1610 // find the row labels within these bounds
1614 for ( row
= 0; row
< m_numRows
; row
++ )
1616 if ( m_rowBottoms
[row
] < top
) continue;
1618 rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
1619 if ( rowTop
> bottom
) break;
1621 m_rowLabelsExposed
.Add( row
);
1629 void wxGrid::CalcColLabelsExposed( wxRegion
& reg
)
1631 wxRegionIterator
iter( reg
);
1634 m_colLabelsExposed
.Empty();
1641 // TODO: remove this when we can...
1642 // There is a bug in wxMotif that gives garbage update
1643 // rectangles if you jump-scroll a long way by clicking the
1644 // scrollbar with middle button. This is a work-around
1646 #if defined(__WXMOTIF__)
1648 m_gridWin
->GetClientSize( &cw
, &ch
);
1649 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
1650 r
.SetRight( wxMin( r
.GetRight(), cw
) );
1653 // logical bounds of update region
1656 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
1657 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
1659 // find the cells within these bounds
1663 for ( col
= 0; col
< m_numCols
; col
++ )
1665 if ( m_colRights
[col
] < left
) continue;
1667 colLeft
= m_colRights
[col
] - m_colWidths
[col
];
1668 if ( colLeft
> right
) break;
1670 m_colLabelsExposed
.Add( col
);
1678 void wxGrid::CalcCellsExposed( wxRegion
& reg
)
1680 wxRegionIterator
iter( reg
);
1683 m_cellsExposed
.Empty();
1684 m_rowsExposed
.Empty();
1685 m_colsExposed
.Empty();
1687 int left
, top
, right
, bottom
;
1692 // TODO: remove this when we can...
1693 // There is a bug in wxMotif that gives garbage update
1694 // rectangles if you jump-scroll a long way by clicking the
1695 // scrollbar with middle button. This is a work-around
1697 #if defined(__WXMOTIF__)
1699 m_gridWin
->GetClientSize( &cw
, &ch
);
1700 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
1701 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
1702 r
.SetRight( wxMin( r
.GetRight(), cw
) );
1703 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
1706 // logical bounds of update region
1708 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
1709 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
1711 // find the cells within these bounds
1714 int colLeft
, rowTop
;
1715 for ( row
= 0; row
< m_numRows
; row
++ )
1717 if ( m_rowBottoms
[row
] < top
) continue;
1719 rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
1720 if ( rowTop
> bottom
) break;
1722 m_rowsExposed
.Add( row
);
1724 for ( col
= 0; col
< m_numCols
; col
++ )
1726 if ( m_colRights
[col
] < left
) continue;
1728 colLeft
= m_colRights
[col
] - m_colWidths
[col
];
1729 if ( colLeft
> right
) break;
1731 if ( m_colsExposed
.Index( col
) == wxNOT_FOUND
) m_colsExposed
.Add( col
);
1732 m_cellsExposed
.Add( wxGridCellCoords( row
, col
) );
1741 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
1744 wxPoint
pos( event
.GetPosition() );
1745 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
1747 if ( event
.Dragging() )
1749 m_isDragging
= TRUE
;
1751 if ( event
.LeftIsDown() )
1753 switch( m_cursorMode
)
1755 case WXGRID_CURSOR_RESIZE_ROW
:
1757 int cw
, ch
, left
, dummy
;
1758 m_gridWin
->GetClientSize( &cw
, &ch
);
1759 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
1761 wxClientDC
dc( m_gridWin
);
1763 dc
.SetLogicalFunction(wxINVERT
);
1764 if ( m_dragLastPos
>= 0 )
1766 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
1768 dc
.DrawLine( left
, y
, left
+cw
, y
);
1773 case WXGRID_CURSOR_SELECT_ROW
:
1775 if ( (row
= YToRow( y
)) >= 0 &&
1776 !IsInSelection( row
, 0 ) )
1778 SelectRow( row
, TRUE
);
1787 m_isDragging
= FALSE
;
1790 // ------------ Left button pressed
1792 if ( event
.LeftDown() )
1794 // don't send a label click event for a hit on the
1795 // edge of the row label - this is probably the user
1796 // wanting to resize the row
1798 if ( YToEdgeOfRow(y
) < 0 )
1802 !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
1804 SelectRow( row
, event
.ShiftDown() );
1805 m_cursorMode
= WXGRID_CURSOR_SELECT_ROW
;
1810 // starting to drag-resize a row
1812 m_rowLabelWin
->CaptureMouse();
1817 // ------------ Left double click
1819 else if (event
.LeftDClick() )
1821 if ( YToEdgeOfRow(y
) < 0 )
1824 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
);
1829 // ------------ Left button released
1831 else if ( event
.LeftUp() )
1833 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
1835 m_rowLabelWin
->ReleaseMouse();
1837 if ( m_dragLastPos
>= 0 )
1839 // erase the last line and resize the row
1841 int cw
, ch
, left
, dummy
;
1842 m_gridWin
->GetClientSize( &cw
, &ch
);
1843 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
1845 wxClientDC
dc( m_gridWin
);
1847 dc
.SetLogicalFunction( wxINVERT
);
1848 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
1849 HideCellEditControl();
1851 int rowTop
= m_rowBottoms
[m_dragRowOrCol
] - m_rowHeights
[m_dragRowOrCol
];
1852 SetRowSize( m_dragRowOrCol
, wxMax( y
- rowTop
, WXGRID_MIN_ROW_HEIGHT
) );
1853 if ( !GetBatchCount() )
1855 // Only needed to get the correct rect.y:
1856 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
1858 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
1859 rect
.width
= m_rowLabelWidth
;
1860 rect
.height
= ch
- rect
.y
;
1861 m_rowLabelWin
->Refresh( TRUE
, &rect
);
1863 m_gridWin
->Refresh( FALSE
, &rect
);
1866 ShowCellEditControl();
1868 // Note: we are ending the event *after* doing
1869 // default processing in this case
1871 SendEvent( EVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
1875 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
1880 // ------------ Right button down
1882 else if ( event
.RightDown() )
1885 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
1887 // no default action at the moment
1892 // ------------ Right double click
1894 else if ( event
.RightDClick() )
1897 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
1899 // no default action at the moment
1904 // ------------ No buttons down and mouse moving
1906 else if ( event
.Moving() )
1908 m_dragRowOrCol
= YToEdgeOfRow( y
);
1909 if ( m_dragRowOrCol
>= 0 )
1911 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
1913 m_cursorMode
= WXGRID_CURSOR_RESIZE_ROW
;
1914 m_rowLabelWin
->SetCursor( m_rowResizeCursor
);
1919 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
1920 if ( m_rowLabelWin
->GetCursor() == m_rowResizeCursor
)
1921 m_rowLabelWin
->SetCursor( *wxSTANDARD_CURSOR
);
1927 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
1930 wxPoint
pos( event
.GetPosition() );
1931 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
1933 if ( event
.Dragging() )
1935 m_isDragging
= TRUE
;
1937 if ( event
.LeftIsDown() )
1939 switch( m_cursorMode
)
1941 case WXGRID_CURSOR_RESIZE_COL
:
1943 int cw
, ch
, dummy
, top
;
1944 m_gridWin
->GetClientSize( &cw
, &ch
);
1945 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
1947 wxClientDC
dc( m_gridWin
);
1949 dc
.SetLogicalFunction(wxINVERT
);
1950 if ( m_dragLastPos
>= 0 )
1952 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
1954 dc
.DrawLine( x
, top
, x
, top
+ch
);
1959 case WXGRID_CURSOR_SELECT_COL
:
1961 if ( (col
= XToCol( x
)) >= 0 &&
1962 !IsInSelection( 0, col
) )
1964 SelectCol( col
, TRUE
);
1973 m_isDragging
= FALSE
;
1976 // ------------ Left button pressed
1978 if ( event
.LeftDown() )
1980 // don't send a label click event for a hit on the
1981 // edge of the col label - this is probably the user
1982 // wanting to resize the col
1984 if ( XToEdgeOfCol(x
) < 0 )
1988 !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
1990 SelectCol( col
, event
.ShiftDown() );
1991 m_cursorMode
= WXGRID_CURSOR_SELECT_COL
;
1996 // starting to drag-resize a col
1998 m_colLabelWin
->CaptureMouse();
2003 // ------------ Left double click
2005 if ( event
.LeftDClick() )
2007 if ( XToEdgeOfCol(x
) < 0 )
2010 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
);
2015 // ------------ Left button released
2017 else if ( event
.LeftUp() )
2019 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
2021 m_colLabelWin
->ReleaseMouse();
2023 if ( m_dragLastPos
>= 0 )
2025 // erase the last line and resize the col
2027 int cw
, ch
, dummy
, top
;
2028 m_gridWin
->GetClientSize( &cw
, &ch
);
2029 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
2031 wxClientDC
dc( m_gridWin
);
2033 dc
.SetLogicalFunction( wxINVERT
);
2034 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
2035 HideCellEditControl();
2037 int colLeft
= m_colRights
[m_dragRowOrCol
] - m_colWidths
[m_dragRowOrCol
];
2038 SetColSize( m_dragRowOrCol
, wxMax( x
- colLeft
, WXGRID_MIN_COL_WIDTH
) );
2040 if ( !GetBatchCount() )
2042 // Only needed to get the correct rect.x:
2043 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
2045 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
2046 rect
.width
= cw
- rect
.x
;
2047 rect
.height
= m_colLabelHeight
;
2048 m_colLabelWin
->Refresh( TRUE
, &rect
);
2050 m_gridWin
->Refresh( FALSE
, &rect
);
2053 ShowCellEditControl();
2055 // Note: we are ending the event *after* doing
2056 // default processing in this case
2058 SendEvent( EVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
2062 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
2067 // ------------ Right button down
2069 else if ( event
.RightDown() )
2072 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
2074 // no default action at the moment
2079 // ------------ Right double click
2081 else if ( event
.RightDClick() )
2084 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
2086 // no default action at the moment
2091 // ------------ No buttons down and mouse moving
2093 else if ( event
.Moving() )
2095 m_dragRowOrCol
= XToEdgeOfCol( x
);
2096 if ( m_dragRowOrCol
>= 0 )
2098 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2100 m_cursorMode
= WXGRID_CURSOR_RESIZE_COL
;
2101 m_colLabelWin
->SetCursor( m_colResizeCursor
);
2106 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
2107 if ( m_colLabelWin
->GetCursor() == m_colResizeCursor
)
2108 m_colLabelWin
->SetCursor( *wxSTANDARD_CURSOR
);
2114 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
2116 if ( event
.LeftDown() )
2118 // indicate corner label by having both row and
2121 if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
2127 else if ( event
.LeftDClick() )
2129 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
2132 else if ( event
.RightDown() )
2134 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
2136 // no default action at the moment
2140 else if ( event
.RightDClick() )
2142 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
2144 // no default action at the moment
2150 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
2153 wxPoint
pos( event
.GetPosition() );
2154 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2156 wxGridCellCoords coords
;
2157 XYToCell( x
, y
, coords
);
2159 if ( event
.Dragging() )
2161 m_isDragging
= TRUE
;
2162 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2164 // Hide the edit control, so it
2165 // won't interfer with drag-shrinking.
2166 if ( IsCellEditControlEnabled() )
2167 HideCellEditControl();
2168 if ( coords
!= wxGridNoCellCoords
)
2170 if ( !IsSelection() )
2172 SelectBlock( coords
, coords
);
2176 SelectBlock( m_currentCellCoords
, coords
);
2184 m_isDragging
= FALSE
;
2186 if ( coords
!= wxGridNoCellCoords
)
2188 if ( event
.LeftDown() )
2190 if ( event
.ShiftDown() )
2192 SelectBlock( m_currentCellCoords
, coords
);
2196 if ( !SendEvent( EVT_GRID_CELL_LEFT_CLICK
,
2201 MakeCellVisible( coords
);
2202 SetCurrentCell( coords
);
2208 // ------------ Left double click
2210 else if ( event
.LeftDClick() )
2212 SendEvent( EVT_GRID_CELL_LEFT_DCLICK
,
2219 // ------------ Left button released
2221 else if ( event
.LeftUp() )
2223 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2225 if ( IsSelection() )
2227 SendEvent( EVT_GRID_RANGE_SELECT
, -1, -1, event
);
2231 // Show the edit control, if it has
2232 // been hidden for drag-shrinking.
2233 if ( IsCellEditControlEnabled() )
2234 ShowCellEditControl();
2240 // ------------ Right button down
2242 else if ( event
.RightDown() )
2244 if ( !SendEvent( EVT_GRID_CELL_RIGHT_CLICK
,
2249 // no default action at the moment
2254 // ------------ Right double click
2256 else if ( event
.RightDClick() )
2258 if ( !SendEvent( EVT_GRID_CELL_RIGHT_DCLICK
,
2263 // no default action at the moment
2267 // ------------ Moving and no button action
2269 else if ( event
.Moving() && !event
.IsButton() )
2271 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
2278 // ------ interaction with data model
2280 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
2282 switch ( msg
.GetId() )
2284 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
2285 return GetModelValues();
2287 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
2288 return SetModelValues();
2290 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
2291 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
2292 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
2293 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
2294 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
2295 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
2296 return Redimension( msg
);
2305 // The behaviour of this function depends on the grid table class
2306 // Clear() function. For the default wxGridStringTable class the
2307 // behavious is to replace all cell contents with wxEmptyString but
2308 // not to change the number of rows or cols.
2310 void wxGrid::ClearGrid()
2315 SetEditControlValue();
2316 if ( !GetBatchCount() ) m_gridWin
->Refresh();
2321 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
2323 // TODO: something with updateLabels flag
2327 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
2333 bool ok
= m_table
->InsertRows( pos
, numRows
);
2335 // the table will have sent the results of the insert row
2336 // operation to this view object as a grid table message
2340 if ( m_numCols
== 0 )
2342 m_table
->AppendCols( WXGRID_DEFAULT_NUMBER_COLS
);
2344 // TODO: perhaps instead of appending the default number of cols
2345 // we should remember what the last non-zero number of cols was ?
2349 if ( m_currentCellCoords
== wxGridNoCellCoords
)
2351 // if we have just inserted cols into an empty grid the current
2352 // cell will be undefined...
2354 SetCurrentCell( 0, 0 );
2358 if ( !GetBatchCount() ) Refresh();
2361 SetEditControlValue();
2371 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
2373 // TODO: something with updateLabels flag
2377 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
2381 if ( m_table
&& m_table
->AppendRows( numRows
) )
2383 if ( m_currentCellCoords
== wxGridNoCellCoords
)
2385 // if we have just inserted cols into an empty grid the current
2386 // cell will be undefined...
2388 SetCurrentCell( 0, 0 );
2391 // the table will have sent the results of the append row
2392 // operation to this view object as a grid table message
2395 if ( !GetBatchCount() ) Refresh();
2405 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
2407 // TODO: something with updateLabels flag
2411 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
2415 if ( m_table
&& m_table
->DeleteRows( pos
, numRows
) )
2417 // the table will have sent the results of the delete row
2418 // operation to this view object as a grid table message
2420 if ( m_numRows
> 0 )
2421 SetEditControlValue();
2423 HideCellEditControl();
2426 if ( !GetBatchCount() ) Refresh();
2436 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
2438 // TODO: something with updateLabels flag
2442 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
2448 HideCellEditControl();
2449 bool ok
= m_table
->InsertCols( pos
, numCols
);
2451 // the table will have sent the results of the insert col
2452 // operation to this view object as a grid table message
2456 if ( m_currentCellCoords
== wxGridNoCellCoords
)
2458 // if we have just inserted cols into an empty grid the current
2459 // cell will be undefined...
2461 SetCurrentCell( 0, 0 );
2465 if ( !GetBatchCount() ) Refresh();
2468 SetEditControlValue();
2478 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
2480 // TODO: something with updateLabels flag
2484 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
2488 if ( m_table
&& m_table
->AppendCols( numCols
) )
2490 // the table will have sent the results of the append col
2491 // operation to this view object as a grid table message
2493 if ( m_currentCellCoords
== wxGridNoCellCoords
)
2495 // if we have just inserted cols into an empty grid the current
2496 // cell will be undefined...
2498 SetCurrentCell( 0, 0 );
2502 if ( !GetBatchCount() ) Refresh();
2512 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
2514 // TODO: something with updateLabels flag
2518 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
2522 if ( m_table
&& m_table
->DeleteCols( pos
, numCols
) )
2524 // the table will have sent the results of the delete col
2525 // operation to this view object as a grid table message
2527 if ( m_numCols
> 0 )
2528 SetEditControlValue();
2530 HideCellEditControl();
2533 if ( !GetBatchCount() ) Refresh();
2545 // ----- event handlers
2548 // Generate a grid event based on a mouse event and
2549 // return the result of ProcessEvent()
2551 bool wxGrid::SendEvent( const wxEventType type
,
2553 wxMouseEvent
& mouseEv
)
2555 if ( type
== EVT_GRID_ROW_SIZE
||
2556 type
== EVT_GRID_COL_SIZE
)
2558 int rowOrCol
= (row
== -1 ? col
: row
);
2560 wxGridSizeEvent
gridEvt( GetId(),
2564 mouseEv
.GetX(), mouseEv
.GetY(),
2565 mouseEv
.ControlDown(),
2566 mouseEv
.ShiftDown(),
2568 mouseEv
.MetaDown() );
2570 return GetEventHandler()->ProcessEvent(gridEvt
);
2572 else if ( type
== EVT_GRID_RANGE_SELECT
)
2574 wxGridRangeSelectEvent
gridEvt( GetId(),
2578 m_selectedBottomRight
,
2579 mouseEv
.ControlDown(),
2580 mouseEv
.ShiftDown(),
2582 mouseEv
.MetaDown() );
2584 return GetEventHandler()->ProcessEvent(gridEvt
);
2588 wxGridEvent
gridEvt( GetId(),
2592 mouseEv
.GetX(), mouseEv
.GetY(),
2593 mouseEv
.ControlDown(),
2594 mouseEv
.ShiftDown(),
2596 mouseEv
.MetaDown() );
2598 return GetEventHandler()->ProcessEvent(gridEvt
);
2603 // Generate a grid event of specified type and return the result
2604 // of ProcessEvent().
2606 bool wxGrid::SendEvent( const wxEventType type
,
2609 if ( type
== EVT_GRID_ROW_SIZE
||
2610 type
== EVT_GRID_COL_SIZE
)
2612 int rowOrCol
= (row
== -1 ? col
: row
);
2614 wxGridSizeEvent
gridEvt( GetId(),
2619 return GetEventHandler()->ProcessEvent(gridEvt
);
2623 wxGridEvent
gridEvt( GetId(),
2628 return GetEventHandler()->ProcessEvent(gridEvt
);
2633 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2635 wxPaintDC
dc( this );
2637 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
2638 m_numRows
&& m_numCols
)
2640 m_currentCellCoords
.Set(0, 0);
2641 SetEditControlValue();
2642 ShowCellEditControl();
2649 // This is just here to make sure that CalcDimensions gets called when
2650 // the grid view is resized... then the size event is skipped to allow
2651 // the box sizers to handle everything
2653 void wxGrid::OnSize( wxSizeEvent
& event
)
2660 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
2662 if ( m_inOnKeyDown
)
2664 // shouldn't be here - we are going round in circles...
2666 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while alread active") );
2669 m_inOnKeyDown
= TRUE
;
2671 // propagate the event up and see if it gets processed
2673 wxWindow
*parent
= GetParent();
2674 wxKeyEvent
keyEvt( event
);
2675 keyEvt
.SetEventObject( parent
);
2677 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
2679 // try local handlers
2681 switch ( event
.KeyCode() )
2684 if ( event
.ControlDown() )
2686 MoveCursorUpBlock();
2695 if ( event
.ControlDown() )
2697 MoveCursorDownBlock();
2706 if ( event
.ControlDown() )
2708 MoveCursorLeftBlock();
2717 if ( event
.ControlDown() )
2719 MoveCursorRightBlock();
2728 if ( !IsEditable() )
2739 if ( event
.ControlDown() )
2741 event
.Skip(); // to let the edit control have the return
2750 if ( event
.ControlDown() )
2752 MakeCellVisible( 0, 0 );
2753 SetCurrentCell( 0, 0 );
2762 if ( event
.ControlDown() )
2764 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
2765 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
2782 // now try the cell edit control
2784 if ( IsCellEditControlEnabled() )
2786 event
.SetEventObject( m_cellEditCtrl
);
2787 m_cellEditCtrl
->GetEventHandler()->ProcessEvent( event
);
2793 m_inOnKeyDown
= FALSE
;
2797 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
2799 if ( SendEvent( EVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
2801 // the event has been intercepted - do nothing
2806 m_currentCellCoords
!= wxGridNoCellCoords
)
2808 HideCellEditControl();
2809 SaveEditControlValue();
2812 m_currentCellCoords
= coords
;
2814 SetEditControlValue();
2818 ShowCellEditControl();
2820 if ( IsSelection() )
2822 wxRect
r( SelectionToDeviceRect() );
2824 if ( !GetBatchCount() ) m_gridWin
->Refresh( FALSE
, &r
);
2831 // ------ functions to get/send data (see also public functions)
2834 bool wxGrid::GetModelValues()
2838 // all we need to do is repaint the grid
2840 m_gridWin
->Refresh();
2848 bool wxGrid::SetModelValues()
2854 for ( row
= 0; row
< m_numRows
; row
++ )
2856 for ( col
= 0; col
< m_numCols
; col
++ )
2858 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
2870 // Note - this function only draws cells that are in the list of
2871 // exposed cells (usually set from the update region by
2872 // CalcExposedCells)
2874 void wxGrid::DrawGridCellArea( wxDC
& dc
)
2876 if ( !m_numRows
|| !m_numCols
) return;
2879 size_t numCells
= m_cellsExposed
.GetCount();
2881 for ( i
= 0; i
< numCells
; i
++ )
2883 DrawCell( dc
, m_cellsExposed
[i
] );
2888 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
2890 if ( m_colWidths
[coords
.GetCol()] <=0 ||
2891 m_rowHeights
[coords
.GetRow()] <= 0 ) return;
2893 #if !WXGRID_DRAW_LINES
2894 if ( m_gridLinesEnabled
)
2895 DrawCellBorder( dc
, coords
);
2898 DrawCellBackground( dc
, coords
);
2900 // TODO: separate functions here for different kinds of cells ?
2903 DrawCellValue( dc
, coords
);
2907 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
2909 if ( m_colWidths
[coords
.GetCol()] <=0 ||
2910 m_rowHeights
[coords
.GetRow()] <= 0 ) return;
2912 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
2913 int row
= coords
.GetRow();
2914 int col
= coords
.GetCol();
2916 // right hand border
2918 dc
.DrawLine( m_colRights
[col
], m_rowBottoms
[row
] - m_rowHeights
[row
],
2919 m_colRights
[col
], m_rowBottoms
[row
] );
2923 dc
.DrawLine( m_colRights
[col
] - m_colWidths
[col
], m_rowBottoms
[row
],
2924 m_colRights
[col
], m_rowBottoms
[row
] );
2928 void wxGrid::DrawCellBackground( wxDC
& dc
, const wxGridCellCoords
& coords
)
2930 if ( m_colWidths
[coords
.GetCol()] <=0 ||
2931 m_rowHeights
[coords
.GetRow()] <= 0 ) return;
2933 int row
= coords
.GetRow();
2934 int col
= coords
.GetCol();
2936 dc
.SetBackgroundMode( wxSOLID
);
2938 if ( IsInSelection( coords
) )
2940 // TODO: improve this
2942 dc
.SetBrush( *wxBLACK_BRUSH
);
2946 dc
.SetBrush( wxBrush(GetCellBackgroundColour(row
, col
), wxSOLID
) );
2949 dc
.SetPen( *wxTRANSPARENT_PEN
);
2951 dc
.DrawRectangle( m_colRights
[col
] - m_colWidths
[col
] + 1,
2952 m_rowBottoms
[row
] - m_rowHeights
[row
] + 1,
2954 m_rowHeights
[row
]-1 );
2958 void wxGrid::DrawCellValue( wxDC
& dc
, const wxGridCellCoords
& coords
)
2960 if ( m_colWidths
[coords
.GetCol()] <=0 ||
2961 m_rowHeights
[coords
.GetRow()] <= 0 ) return;
2963 int row
= coords
.GetRow();
2964 int col
= coords
.GetCol();
2966 dc
.SetBackgroundMode( wxTRANSPARENT
);
2968 if ( IsInSelection( row
, col
) )
2970 // TODO: improve this
2972 dc
.SetTextBackground( wxColour(0, 0, 0) );
2973 dc
.SetTextForeground( wxColour(255, 255, 255) );
2977 dc
.SetTextBackground( GetCellBackgroundColour(row
, col
) );
2978 dc
.SetTextForeground( GetCellTextColour(row
, col
) );
2980 dc
.SetFont( GetCellFont(row
, col
) );
2983 GetCellAlignment( row
, col
, &hAlign
, &vAlign
);
2986 rect
.SetX( m_colRights
[col
] - m_colWidths
[col
] + 2 );
2987 rect
.SetY( m_rowBottoms
[row
] - m_rowHeights
[row
] + 2 );
2988 rect
.SetWidth( m_colWidths
[col
] - 4 );
2989 rect
.SetHeight( m_rowHeights
[row
] - 4 );
2991 DrawTextRectangle( dc
, GetCellValue( row
, col
), rect
, hAlign
, vAlign
);
2996 // TODO: remove this ???
2997 // This is used to redraw all grid lines e.g. when the grid line colour
3000 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
)
3002 if ( !m_gridLinesEnabled
||
3004 !m_numCols
) return;
3006 int top
, bottom
, left
, right
;
3010 m_gridWin
->GetClientSize(&cw
, &ch
);
3012 // virtual coords of visible area
3014 CalcUnscrolledPosition( 0, 0, &left
, &top
);
3015 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
3019 reg
.GetBox(x
, y
, w
, h
);
3020 CalcUnscrolledPosition( x
, y
, &left
, &top
);
3021 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
3024 // avoid drawing grid lines past the last row and col
3026 right
= wxMin( right
, m_colRights
[m_numCols
-1] );
3027 bottom
= wxMin( bottom
, m_rowBottoms
[m_numRows
-1] );
3029 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
3031 // horizontal grid lines
3034 for ( i
= 0; i
< m_numRows
; i
++ )
3036 if ( m_rowBottoms
[i
] > bottom
)
3040 else if ( m_rowBottoms
[i
] >= top
)
3042 dc
.DrawLine( left
, m_rowBottoms
[i
], right
, m_rowBottoms
[i
] );
3047 // vertical grid lines
3049 for ( i
= 0; i
< m_numCols
; i
++ )
3051 if ( m_colRights
[i
] > right
)
3055 else if ( m_colRights
[i
] >= left
)
3057 dc
.DrawLine( m_colRights
[i
], top
, m_colRights
[i
], bottom
);
3063 void wxGrid::DrawRowLabels( wxDC
& dc
)
3065 if ( !m_numRows
|| !m_numCols
) return;
3068 size_t numLabels
= m_rowLabelsExposed
.GetCount();
3070 for ( i
= 0; i
< numLabels
; i
++ )
3072 DrawRowLabel( dc
, m_rowLabelsExposed
[i
] );
3077 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
3079 if ( m_rowHeights
[row
] <= 0 ) return;
3081 int rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3083 dc
.SetPen( *wxBLACK_PEN
);
3084 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
3085 m_rowLabelWidth
-1, m_rowBottoms
[row
]-1 );
3087 dc
.DrawLine( 0, m_rowBottoms
[row
]-1,
3088 m_rowLabelWidth
-1, m_rowBottoms
[row
]-1 );
3090 dc
.SetPen( *wxWHITE_PEN
);
3091 dc
.DrawLine( 0, rowTop
, 0, m_rowBottoms
[row
]-1 );
3092 dc
.DrawLine( 0, rowTop
, m_rowLabelWidth
-1, rowTop
);
3094 dc
.SetBackgroundMode( wxTRANSPARENT
);
3095 dc
.SetTextForeground( GetLabelTextColour() );
3096 dc
.SetFont( GetLabelFont() );
3099 GetRowLabelAlignment( &hAlign
, &vAlign
);
3103 rect
.SetY( m_rowBottoms
[row
] - m_rowHeights
[row
] + 2 );
3104 rect
.SetWidth( m_rowLabelWidth
- 4 );
3105 rect
.SetHeight( m_rowHeights
[row
] - 4 );
3106 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
3110 void wxGrid::DrawColLabels( wxDC
& dc
)
3112 if ( !m_numRows
|| !m_numCols
) return;
3115 size_t numLabels
= m_colLabelsExposed
.GetCount();
3117 for ( i
= 0; i
< numLabels
; i
++ )
3119 DrawColLabel( dc
, m_colLabelsExposed
[i
] );
3124 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
3126 if ( m_colWidths
[col
] <= 0 ) return;
3128 int colLeft
= m_colRights
[col
] - m_colWidths
[col
];
3130 dc
.SetPen( *wxBLACK_PEN
);
3131 dc
.DrawLine( m_colRights
[col
]-1, 0,
3132 m_colRights
[col
]-1, m_colLabelHeight
-1 );
3134 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
3135 m_colRights
[col
]-1, m_colLabelHeight
-1 );
3137 dc
.SetPen( *wxWHITE_PEN
);
3138 dc
.DrawLine( colLeft
, 0, colLeft
, m_colLabelHeight
-1 );
3139 dc
.DrawLine( colLeft
, 0, m_colRights
[col
]-1, 0 );
3141 dc
.SetBackgroundMode( wxTRANSPARENT
);
3142 dc
.SetTextForeground( GetLabelTextColour() );
3143 dc
.SetFont( GetLabelFont() );
3145 dc
.SetBackgroundMode( wxTRANSPARENT
);
3146 dc
.SetTextForeground( GetLabelTextColour() );
3147 dc
.SetFont( GetLabelFont() );
3150 GetColLabelAlignment( &hAlign
, &vAlign
);
3153 rect
.SetX( m_colRights
[col
] - m_colWidths
[col
] + 2 );
3155 rect
.SetWidth( m_colWidths
[col
] - 4 );
3156 rect
.SetHeight( m_colLabelHeight
- 4 );
3157 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
);
3161 void wxGrid::DrawTextRectangle( wxDC
& dc
,
3162 const wxString
& value
,
3167 long textWidth
, textHeight
;
3168 long lineWidth
, lineHeight
;
3169 wxArrayString lines
;
3171 dc
.SetClippingRegion( rect
);
3172 StringToLines( value
, lines
);
3173 if ( lines
.GetCount() )
3175 GetTextBoxSize( dc
, lines
, &textWidth
, &textHeight
);
3176 dc
.GetTextExtent( lines
[0], &lineWidth
, &lineHeight
);
3179 switch ( horizAlign
)
3182 x
= rect
.x
+ (rect
.width
- textWidth
- 1);
3186 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
3195 switch ( vertAlign
)
3198 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
3202 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
3211 for ( size_t i
= 0; i
< lines
.GetCount(); i
++ )
3213 dc
.DrawText( lines
[i
], (long)x
, (long)y
);
3218 dc
.DestroyClippingRegion();
3222 // Split multi line text up into an array of strings. Any existing
3223 // contents of the string array are preserved.
3225 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
3229 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
3230 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
3232 while ( startPos
< (int)tVal
.Length() )
3234 pos
= tVal
.Mid(startPos
).Find( eol
);
3239 else if ( pos
== 0 )
3241 lines
.Add( wxEmptyString
);
3245 lines
.Add( value
.Mid(startPos
, pos
) );
3249 if ( startPos
< (int)value
.Length() )
3251 lines
.Add( value
.Mid( startPos
) );
3256 void wxGrid::GetTextBoxSize( wxDC
& dc
,
3257 wxArrayString
& lines
,
3258 long *width
, long *height
)
3265 for ( i
= 0; i
< lines
.GetCount(); i
++ )
3267 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
3268 w
= wxMax( w
, lineW
);
3278 // ------ Edit control functions
3282 void wxGrid::EnableEditing( bool edit
)
3284 // TODO: improve this ?
3286 if ( edit
!= m_editable
)
3290 // TODO: extend this for other edit control types
3292 if ( m_editCtrlType
== wxGRID_TEXTCTRL
)
3294 ((wxTextCtrl
*)m_cellEditCtrl
)->SetEditable( m_editable
);
3300 #if 0 // disabled for the moment - the cell control is always active
3301 void wxGrid::EnableCellEditControl( bool enable
)
3303 if ( m_cellEditCtrl
&&
3304 enable
!= m_cellEditCtrlEnabled
)
3306 m_cellEditCtrlEnabled
= enable
;
3308 if ( m_cellEditCtrlEnabled
)
3310 SetEditControlValue();
3311 ShowCellEditControl();
3315 HideCellEditControl();
3316 SaveEditControlValue();
3323 void wxGrid::ShowCellEditControl()
3327 if ( IsCellEditControlEnabled() )
3329 if ( !IsVisible( m_currentCellCoords
) )
3335 rect
= CellToRect( m_currentCellCoords
);
3337 // convert to scrolled coords
3339 int left
, top
, right
, bottom
;
3340 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
3341 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
3344 m_gridWin
->GetClientSize( &cw
, &ch
);
3346 // Make the edit control large enough to allow for internal margins
3347 // TODO: remove this if the text ctrl sizing is improved esp. for unix
3350 #if defined(__WXMOTIF__)
3351 if ( m_currentCellCoords
.GetRow() == 0 ||
3352 m_currentCellCoords
.GetCol() == 0 )
3361 if ( m_currentCellCoords
.GetRow() == 0 ||
3362 m_currentCellCoords
.GetCol() == 0 )
3372 #if defined(__WXGTK__)
3375 if (left
!= 0) left_diff
++;
3376 if (top
!= 0) top_diff
++;
3377 rect
.SetLeft( left
+ left_diff
);
3378 rect
.SetTop( top
+ top_diff
);
3379 rect
.SetRight( rect
.GetRight() - left_diff
);
3380 rect
.SetBottom( rect
.GetBottom() - top_diff
);
3382 rect
.SetLeft( wxMax(0, left
- extra
) );
3383 rect
.SetTop( wxMax(0, top
- extra
) );
3384 rect
.SetRight( rect
.GetRight() + 2*extra
);
3385 rect
.SetBottom( rect
.GetBottom() + 2*extra
);
3388 m_cellEditCtrl
->SetSize( rect
);
3389 m_cellEditCtrl
->Show( TRUE
);
3391 switch ( m_editCtrlType
)
3393 case wxGRID_TEXTCTRL
:
3394 ((wxTextCtrl
*) m_cellEditCtrl
)->SetInsertionPointEnd();
3397 case wxGRID_CHECKBOX
:
3398 // TODO: anything ???
3403 // TODO: anything ???
3407 case wxGRID_COMBOBOX
:
3408 // TODO: anything ???
3413 m_cellEditCtrl
->SetFocus();
3419 void wxGrid::HideCellEditControl()
3421 if ( IsCellEditControlEnabled() )
3423 m_cellEditCtrl
->Show( FALSE
);
3428 void wxGrid::SetEditControlValue( const wxString
& value
)
3434 s
= GetCellValue(m_currentCellCoords
);
3438 if ( IsCellEditControlEnabled() )
3440 switch ( m_editCtrlType
)
3442 case wxGRID_TEXTCTRL
:
3443 ((wxGridTextCtrl
*)m_cellEditCtrl
)->SetStartValue(s
);
3446 case wxGRID_CHECKBOX
:
3447 // TODO: implement this
3452 // TODO: implement this
3456 case wxGRID_COMBOBOX
:
3457 // TODO: implement this
3466 void wxGrid::SaveEditControlValue()
3470 wxWindow
*ctrl
= (wxWindow
*)NULL
;
3472 if ( IsCellEditControlEnabled() )
3474 ctrl
= m_cellEditCtrl
;
3481 bool valueChanged
= FALSE
;
3483 switch ( m_editCtrlType
)
3485 case wxGRID_TEXTCTRL
:
3486 valueChanged
= (((wxGridTextCtrl
*)ctrl
)->GetValue() !=
3487 ((wxGridTextCtrl
*)ctrl
)->GetStartValue());
3488 SetCellValue( m_currentCellCoords
,
3489 ((wxTextCtrl
*) ctrl
)->GetValue() );
3492 case wxGRID_CHECKBOX
:
3493 // TODO: implement this
3498 // TODO: implement this
3502 case wxGRID_COMBOBOX
:
3503 // TODO: implement this
3510 SendEvent( EVT_GRID_CELL_CHANGE
,
3511 m_currentCellCoords
.GetRow(),
3512 m_currentCellCoords
.GetCol() );
3519 // ------ Grid location functions
3520 // Note that all of these functions work with the logical coordinates of
3521 // grid cells and labels so you will need to convert from device
3522 // coordinates for mouse events etc.
3525 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
3527 int row
= YToRow(y
);
3528 int col
= XToCol(x
);
3530 if ( row
== -1 || col
== -1 )
3532 coords
= wxGridNoCellCoords
;
3536 coords
.Set( row
, col
);
3541 int wxGrid::YToRow( int y
)
3545 for ( i
= 0; i
< m_numRows
; i
++ )
3547 if ( y
< m_rowBottoms
[i
] ) return i
;
3554 int wxGrid::XToCol( int x
)
3558 for ( i
= 0; i
< m_numCols
; i
++ )
3560 if ( x
< m_colRights
[i
] ) return i
;
3567 // return the row number that that the y coord is near the edge of, or
3568 // -1 if not near an edge
3570 int wxGrid::YToEdgeOfRow( int y
)
3574 for ( i
= 0; i
< m_numRows
; i
++ )
3576 if ( m_rowHeights
[i
] > WXGRID_LABEL_EDGE_ZONE
)
3578 d
= abs( y
- m_rowBottoms
[i
] );
3580 if ( d
< WXGRID_LABEL_EDGE_ZONE
) return i
;
3589 // return the col number that that the x coord is near the edge of, or
3590 // -1 if not near an edge
3592 int wxGrid::XToEdgeOfCol( int x
)
3596 for ( i
= 0; i
< m_numCols
; i
++ )
3598 if ( m_colWidths
[i
] > WXGRID_LABEL_EDGE_ZONE
)
3600 d
= abs( x
- m_colRights
[i
] );
3602 if ( d
< WXGRID_LABEL_EDGE_ZONE
) return i
;
3611 wxRect
wxGrid::CellToRect( int row
, int col
)
3613 wxRect
rect( -1, -1, -1, -1 );
3615 if ( row
>= 0 && row
< m_numRows
&&
3616 col
>= 0 && col
< m_numCols
)
3618 rect
.x
= m_colRights
[col
] - m_colWidths
[col
];
3619 rect
.y
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3620 rect
.width
= m_colWidths
[col
];
3621 rect
.height
= m_rowHeights
[ row
];
3628 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
3630 // get the cell rectangle in logical coords
3632 wxRect
r( CellToRect( row
, col
) );
3634 // convert to device coords
3636 int left
, top
, right
, bottom
;
3637 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
3638 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
3640 // check against the client area of the grid window
3643 m_gridWin
->GetClientSize( &cw
, &ch
);
3645 if ( wholeCellVisible
)
3647 // is the cell wholly visible ?
3649 return ( left
>= 0 && right
<= cw
&&
3650 top
>= 0 && bottom
<= ch
);
3654 // is the cell partly visible ?
3656 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
3657 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
3662 // make the specified cell location visible by doing a minimal amount
3665 void wxGrid::MakeCellVisible( int row
, int col
)
3668 int xpos
= -1, ypos
= -1;
3670 if ( row
>= 0 && row
< m_numRows
&&
3671 col
>= 0 && col
< m_numCols
)
3673 // get the cell rectangle in logical coords
3675 wxRect
r( CellToRect( row
, col
) );
3677 // convert to device coords
3679 int left
, top
, right
, bottom
;
3680 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
3681 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
3684 m_gridWin
->GetClientSize( &cw
, &ch
);
3690 else if ( bottom
> ch
)
3692 int h
= r
.GetHeight();
3694 for ( i
= row
-1; i
>= 0; i
-- )
3696 if ( h
+ m_rowHeights
[i
] > ch
) break;
3698 h
+= m_rowHeights
[i
];
3699 ypos
-= m_rowHeights
[i
];
3702 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
3703 // have rounding errors (this is important, because if we do, we
3704 // might not scroll at all and some cells won't be redrawn)
3705 ypos
+= GRID_SCROLL_LINE
/ 2;
3712 else if ( right
> cw
)
3714 int w
= r
.GetWidth();
3716 for ( i
= col
-1; i
>= 0; i
-- )
3718 if ( w
+ m_colWidths
[i
] > cw
) break;
3720 w
+= m_colWidths
[i
];
3721 xpos
-= m_colWidths
[i
];
3724 // see comment for ypos above
3725 xpos
+= GRID_SCROLL_LINE
/ 2;
3728 if ( xpos
!= -1 || ypos
!= -1 )
3730 if ( xpos
!= -1 ) xpos
/= GRID_SCROLL_LINE
;
3731 if ( ypos
!= -1 ) ypos
/= GRID_SCROLL_LINE
;
3732 Scroll( xpos
, ypos
);
3740 // ------ Grid cursor movement functions
3743 bool wxGrid::MoveCursorUp()
3745 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
3746 m_currentCellCoords
.GetRow() > 0 )
3748 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
3749 m_currentCellCoords
.GetCol() );
3751 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
3752 m_currentCellCoords
.GetCol() );
3761 bool wxGrid::MoveCursorDown()
3763 // TODO: allow for scrolling
3765 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
3766 m_currentCellCoords
.GetRow() < m_numRows
-1 )
3768 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
3769 m_currentCellCoords
.GetCol() );
3771 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
3772 m_currentCellCoords
.GetCol() );
3781 bool wxGrid::MoveCursorLeft()
3783 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
3784 m_currentCellCoords
.GetCol() > 0 )
3786 MakeCellVisible( m_currentCellCoords
.GetRow(),
3787 m_currentCellCoords
.GetCol() - 1 );
3789 SetCurrentCell( m_currentCellCoords
.GetRow(),
3790 m_currentCellCoords
.GetCol() - 1 );
3799 bool wxGrid::MoveCursorRight()
3801 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
3802 m_currentCellCoords
.GetCol() < m_numCols
- 1 )
3804 MakeCellVisible( m_currentCellCoords
.GetRow(),
3805 m_currentCellCoords
.GetCol() + 1 );
3807 SetCurrentCell( m_currentCellCoords
.GetRow(),
3808 m_currentCellCoords
.GetCol() + 1 );
3817 bool wxGrid::MovePageUp()
3819 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
3821 int row
= m_currentCellCoords
.GetRow();
3825 m_gridWin
->GetClientSize( &cw
, &ch
);
3827 int y
= m_rowBottoms
[ row
] - m_rowHeights
[ row
];
3828 int newRow
= YToRow( y
- ch
+ 1 );
3833 else if ( newRow
== row
)
3838 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
3839 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
3847 bool wxGrid::MovePageDown()
3849 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
3851 int row
= m_currentCellCoords
.GetRow();
3852 if ( row
< m_numRows
)
3855 m_gridWin
->GetClientSize( &cw
, &ch
);
3857 int y
= m_rowBottoms
[ row
] - m_rowHeights
[ row
];
3858 int newRow
= YToRow( y
+ ch
);
3861 newRow
= m_numRows
- 1;
3863 else if ( newRow
== row
)
3868 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
3869 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
3877 bool wxGrid::MoveCursorUpBlock()
3880 m_currentCellCoords
!= wxGridNoCellCoords
&&
3881 m_currentCellCoords
.GetRow() > 0 )
3883 int row
= m_currentCellCoords
.GetRow();
3884 int col
= m_currentCellCoords
.GetCol();
3886 if ( m_table
->IsEmptyCell(row
, col
) )
3888 // starting in an empty cell: find the next block of
3894 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
3897 else if ( m_table
->IsEmptyCell(row
-1, col
) )
3899 // starting at the top of a block: find the next block
3905 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
3910 // starting within a block: find the top of the block
3915 if ( m_table
->IsEmptyCell(row
, col
) )
3923 MakeCellVisible( row
, col
);
3924 SetCurrentCell( row
, col
);
3932 bool wxGrid::MoveCursorDownBlock()
3935 m_currentCellCoords
!= wxGridNoCellCoords
&&
3936 m_currentCellCoords
.GetRow() < m_numRows
-1 )
3938 int row
= m_currentCellCoords
.GetRow();
3939 int col
= m_currentCellCoords
.GetCol();
3941 if ( m_table
->IsEmptyCell(row
, col
) )
3943 // starting in an empty cell: find the next block of
3946 while ( row
< m_numRows
-1 )
3949 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
3952 else if ( m_table
->IsEmptyCell(row
+1, col
) )
3954 // starting at the bottom of a block: find the next block
3957 while ( row
< m_numRows
-1 )
3960 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
3965 // starting within a block: find the bottom of the block
3967 while ( row
< m_numRows
-1 )
3970 if ( m_table
->IsEmptyCell(row
, col
) )
3978 MakeCellVisible( row
, col
);
3979 SetCurrentCell( row
, col
);
3987 bool wxGrid::MoveCursorLeftBlock()
3990 m_currentCellCoords
!= wxGridNoCellCoords
&&
3991 m_currentCellCoords
.GetCol() > 0 )
3993 int row
= m_currentCellCoords
.GetRow();
3994 int col
= m_currentCellCoords
.GetCol();
3996 if ( m_table
->IsEmptyCell(row
, col
) )
3998 // starting in an empty cell: find the next block of
4004 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4007 else if ( m_table
->IsEmptyCell(row
, col
-1) )
4009 // starting at the left of a block: find the next block
4015 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4020 // starting within a block: find the left of the block
4025 if ( m_table
->IsEmptyCell(row
, col
) )
4033 MakeCellVisible( row
, col
);
4034 SetCurrentCell( row
, col
);
4042 bool wxGrid::MoveCursorRightBlock()
4045 m_currentCellCoords
!= wxGridNoCellCoords
&&
4046 m_currentCellCoords
.GetCol() < m_numCols
-1 )
4048 int row
= m_currentCellCoords
.GetRow();
4049 int col
= m_currentCellCoords
.GetCol();
4051 if ( m_table
->IsEmptyCell(row
, col
) )
4053 // starting in an empty cell: find the next block of
4056 while ( col
< m_numCols
-1 )
4059 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4062 else if ( m_table
->IsEmptyCell(row
, col
+1) )
4064 // starting at the right of a block: find the next block
4067 while ( col
< m_numCols
-1 )
4070 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4075 // starting within a block: find the right of the block
4077 while ( col
< m_numCols
-1 )
4080 if ( m_table
->IsEmptyCell(row
, col
) )
4088 MakeCellVisible( row
, col
);
4089 SetCurrentCell( row
, col
);
4100 // ------ Label values and formatting
4103 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
4105 *horiz
= m_rowLabelHorizAlign
;
4106 *vert
= m_rowLabelVertAlign
;
4109 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
4111 *horiz
= m_colLabelHorizAlign
;
4112 *vert
= m_colLabelVertAlign
;
4115 wxString
wxGrid::GetRowLabelValue( int row
)
4119 return m_table
->GetRowLabelValue( row
);
4129 wxString
wxGrid::GetColLabelValue( int col
)
4133 return m_table
->GetColLabelValue( col
);
4144 void wxGrid::SetRowLabelSize( int width
)
4146 width
= wxMax( width
, 0 );
4147 if ( width
!= m_rowLabelWidth
)
4151 m_rowLabelWin
->Show( FALSE
);
4152 m_cornerLabelWin
->Show( FALSE
);
4154 else if ( m_rowLabelWidth
== 0 )
4156 m_rowLabelWin
->Show( TRUE
);
4157 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
4160 m_rowLabelWidth
= width
;
4167 void wxGrid::SetColLabelSize( int height
)
4169 height
= wxMax( height
, 0 );
4170 if ( height
!= m_colLabelHeight
)
4174 m_colLabelWin
->Show( FALSE
);
4175 m_cornerLabelWin
->Show( FALSE
);
4177 else if ( m_colLabelHeight
== 0 )
4179 m_colLabelWin
->Show( TRUE
);
4180 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
4183 m_colLabelHeight
= height
;
4190 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
4192 if ( m_labelBackgroundColour
!= colour
)
4194 m_labelBackgroundColour
= colour
;
4195 m_rowLabelWin
->SetBackgroundColour( colour
);
4196 m_colLabelWin
->SetBackgroundColour( colour
);
4197 m_cornerLabelWin
->SetBackgroundColour( colour
);
4199 if ( !GetBatchCount() )
4201 m_rowLabelWin
->Refresh();
4202 m_colLabelWin
->Refresh();
4203 m_cornerLabelWin
->Refresh();
4208 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
4210 if ( m_labelTextColour
!= colour
)
4212 m_labelTextColour
= colour
;
4213 if ( !GetBatchCount() )
4215 m_rowLabelWin
->Refresh();
4216 m_colLabelWin
->Refresh();
4221 void wxGrid::SetLabelFont( const wxFont
& font
)
4224 if ( !GetBatchCount() )
4226 m_rowLabelWin
->Refresh();
4227 m_colLabelWin
->Refresh();
4231 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
4233 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
4235 m_rowLabelHorizAlign
= horiz
;
4238 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
4240 m_rowLabelVertAlign
= vert
;
4243 if ( !GetBatchCount() )
4245 m_rowLabelWin
->Refresh();
4249 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
4251 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
4253 m_colLabelHorizAlign
= horiz
;
4256 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
4258 m_colLabelVertAlign
= vert
;
4261 if ( !GetBatchCount() )
4263 m_colLabelWin
->Refresh();
4267 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
4271 m_table
->SetRowLabelValue( row
, s
);
4272 if ( !GetBatchCount() )
4274 wxRect rect
= CellToRect( row
, 0);
4275 if ( rect
.height
> 0 )
4277 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
4279 rect
.width
= m_rowLabelWidth
;
4280 m_rowLabelWin
->Refresh( TRUE
, &rect
);
4286 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
4290 m_table
->SetColLabelValue( col
, s
);
4291 if ( !GetBatchCount() )
4293 wxRect rect
= CellToRect( 0, col
);
4294 if ( rect
.width
> 0 )
4296 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
4298 rect
.height
= m_colLabelHeight
;
4299 m_colLabelWin
->Refresh( TRUE
, &rect
);
4305 void wxGrid::SetGridLineColour( const wxColour
& colour
)
4307 if ( m_gridLineColour
!= colour
)
4309 m_gridLineColour
= colour
;
4311 wxClientDC
dc( m_gridWin
);
4313 DrawAllGridLines( dc
, wxRegion() );
4317 void wxGrid::EnableGridLines( bool enable
)
4319 if ( enable
!= m_gridLinesEnabled
)
4321 m_gridLinesEnabled
= enable
;
4323 if ( !GetBatchCount() )
4327 wxClientDC
dc( m_gridWin
);
4329 DrawAllGridLines( dc
, wxRegion() );
4333 m_gridWin
->Refresh();
4340 int wxGrid::GetDefaultRowSize()
4342 return m_defaultRowHeight
;
4345 int wxGrid::GetRowSize( int row
)
4347 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
4349 return m_rowHeights
[row
];
4352 int wxGrid::GetDefaultColSize()
4354 return m_defaultColWidth
;
4357 int wxGrid::GetColSize( int col
)
4359 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
4361 return m_colWidths
[col
];
4364 wxColour
wxGrid::GetDefaultCellBackgroundColour()
4366 return m_gridWin
->GetBackgroundColour();
4369 // TODO VZ: this must be optimized to allow only retrieveing attr once!
4371 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
4373 wxGridCellAttr
*attr
= m_table
? m_table
->GetAttr(row
, col
) : NULL
;
4376 if ( attr
&& attr
->HasBackgroundColour() )
4377 colour
= attr
->GetBackgroundColour();
4379 colour
= GetDefaultCellBackgroundColour();
4386 wxColour
wxGrid::GetDefaultCellTextColour()
4388 return m_gridWin
->GetForegroundColour();
4391 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
4393 wxGridCellAttr
*attr
= m_table
? m_table
->GetAttr(row
, col
) : NULL
;
4396 if ( attr
&& attr
->HasTextColour() )
4397 colour
= attr
->GetTextColour();
4399 colour
= GetDefaultCellTextColour();
4407 wxFont
wxGrid::GetDefaultCellFont()
4409 return m_defaultCellFont
;
4412 wxFont
wxGrid::GetCellFont( int row
, int col
)
4414 wxGridCellAttr
*attr
= m_table
? m_table
->GetAttr(row
, col
) : NULL
;
4417 if ( attr
&& attr
->HasFont() )
4418 font
= attr
->GetFont();
4420 font
= GetDefaultCellFont();
4427 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
4430 *horiz
= m_defaultCellHAlign
;
4432 *vert
= m_defaultCellVAlign
;
4435 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
4437 wxGridCellAttr
*attr
= m_table
? m_table
->GetAttr(row
, col
) : NULL
;
4439 if ( attr
&& attr
->HasAlignment() )
4440 attr
->GetAlignment(horiz
, vert
);
4442 GetDefaultCellAlignment(horiz
, vert
);
4447 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
4449 m_defaultRowHeight
= wxMax( height
, WXGRID_MIN_ROW_HEIGHT
);
4451 if ( resizeExistingRows
)
4455 for ( row
= 0; row
< m_numRows
; row
++ )
4457 m_rowHeights
[row
] = m_defaultRowHeight
;
4458 bottom
+= m_defaultRowHeight
;
4459 m_rowBottoms
[row
] = bottom
;
4465 void wxGrid::SetRowSize( int row
, int height
)
4467 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
4471 int h
= wxMax( 0, height
);
4472 int diff
= h
- m_rowHeights
[row
];
4474 m_rowHeights
[row
] = h
;
4475 for ( i
= row
; i
< m_numRows
; i
++ )
4477 m_rowBottoms
[i
] += diff
;
4481 // Note: we are ending the event *after* doing
4482 // default processing in this case
4484 SendEvent( EVT_GRID_ROW_SIZE
,
4488 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
4490 m_defaultColWidth
= wxMax( width
, WXGRID_MIN_COL_WIDTH
);
4492 if ( resizeExistingCols
)
4496 for ( col
= 0; col
< m_numCols
; col
++ )
4498 m_colWidths
[col
] = m_defaultColWidth
;
4499 right
+= m_defaultColWidth
;
4500 m_colRights
[col
] = right
;
4506 void wxGrid::SetColSize( int col
, int width
)
4508 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
4512 int w
= wxMax( 0, width
);
4513 int diff
= w
- m_colWidths
[col
];
4514 m_colWidths
[col
] = w
;
4516 for ( i
= col
; i
< m_numCols
; i
++ )
4518 m_colRights
[i
] += diff
;
4522 // Note: we are ending the event *after* doing
4523 // default processing in this case
4525 SendEvent( EVT_GRID_COL_SIZE
,
4529 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
4531 m_gridWin
->SetBackgroundColour(col
);
4534 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
4536 m_gridWin
->SetForegroundColour(col
);
4539 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
4541 m_defaultCellHAlign
= horiz
;
4542 m_defaultCellVAlign
= vert
;
4545 bool wxGrid::CanHaveAttributes()
4552 if ( !m_table
->GetAttrProvider() )
4554 // use the default attr provider by default
4555 // (another choice would be to just return FALSE thus forcing the user
4557 m_table
->SetAttrProvider(new wxGridCellAttrProvider
);
4563 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
4565 if ( CanHaveAttributes() )
4567 wxGridCellAttr
*attr
= new wxGridCellAttr
;
4568 attr
->SetBackgroundColour(colour
);
4570 m_table
->SetAttr(attr
, row
, col
);
4574 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
4576 if ( CanHaveAttributes() )
4578 wxGridCellAttr
*attr
= new wxGridCellAttr
;
4579 attr
->SetTextColour(colour
);
4581 m_table
->SetAttr(attr
, row
, col
);
4585 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
4587 m_defaultCellFont
= font
;
4590 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
4592 if ( CanHaveAttributes() )
4594 wxGridCellAttr
*attr
= new wxGridCellAttr
;
4595 attr
->SetFont(font
);
4597 m_table
->SetAttr(attr
, row
, col
);
4601 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
4603 if ( CanHaveAttributes() )
4605 wxGridCellAttr
*attr
= new wxGridCellAttr
;
4606 attr
->SetAlignment(horiz
, vert
);
4608 m_table
->SetAttr(attr
, row
, col
);
4615 // ------ cell value accessor functions
4618 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
4622 m_table
->SetValue( row
, col
, s
.c_str() );
4623 if ( !GetBatchCount() )
4625 wxClientDC
dc( m_gridWin
);
4627 DrawCell( dc
, wxGridCellCoords(row
, col
) );
4630 #if 0 // TODO: edit in place
4632 if ( m_currentCellCoords
.GetRow() == row
&&
4633 m_currentCellCoords
.GetCol() == col
)
4635 SetEditControlValue( s
);
4644 // ------ Block, row and col selection
4647 void wxGrid::SelectRow( int row
, bool addToSelected
)
4651 if ( IsSelection() && addToSelected
)
4654 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
4657 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
4658 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
4659 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
4660 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
4664 need_refresh
[0] = TRUE
;
4665 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( row
, 0 ),
4666 wxGridCellCoords ( oldTop
- 1,
4668 m_selectedTopLeft
.SetRow( row
);
4673 need_refresh
[1] = TRUE
;
4674 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
, 0 ),
4675 wxGridCellCoords ( oldBottom
,
4678 m_selectedTopLeft
.SetCol( 0 );
4681 if ( oldBottom
< row
)
4683 need_refresh
[2] = TRUE
;
4684 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1, 0 ),
4685 wxGridCellCoords ( row
,
4687 m_selectedBottomRight
.SetRow( row
);
4690 if ( oldRight
< m_numCols
- 1 )
4692 need_refresh
[3] = TRUE
;
4693 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
4695 wxGridCellCoords ( oldBottom
,
4697 m_selectedBottomRight
.SetCol( m_numCols
- 1 );
4700 for (i
= 0; i
< 4; i
++ )
4701 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
4702 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
4706 r
= SelectionToDeviceRect();
4708 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
4710 m_selectedTopLeft
.Set( row
, 0 );
4711 m_selectedBottomRight
.Set( row
, m_numCols
-1 );
4712 r
= SelectionToDeviceRect();
4713 m_gridWin
->Refresh( FALSE
, &r
);
4716 wxGridRangeSelectEvent
gridEvt( GetId(),
4717 EVT_GRID_RANGE_SELECT
,
4720 m_selectedBottomRight
);
4722 GetEventHandler()->ProcessEvent(gridEvt
);
4726 void wxGrid::SelectCol( int col
, bool addToSelected
)
4728 if ( IsSelection() && addToSelected
)
4731 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
4734 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
4735 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
4736 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
4737 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
4739 if ( oldLeft
> col
)
4741 need_refresh
[0] = TRUE
;
4742 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( 0, col
),
4743 wxGridCellCoords ( m_numRows
- 1,
4745 m_selectedTopLeft
.SetCol( col
);
4750 need_refresh
[1] = TRUE
;
4751 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( 0, oldLeft
),
4752 wxGridCellCoords ( oldTop
- 1,
4754 m_selectedTopLeft
.SetRow( 0 );
4757 if ( oldRight
< col
)
4759 need_refresh
[2] = TRUE
;
4760 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( 0, oldRight
+ 1 ),
4761 wxGridCellCoords ( m_numRows
- 1,
4763 m_selectedBottomRight
.SetCol( col
);
4766 if ( oldBottom
< m_numRows
- 1 )
4768 need_refresh
[3] = TRUE
;
4769 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1,
4771 wxGridCellCoords ( m_numRows
- 1,
4773 m_selectedBottomRight
.SetRow( m_numRows
- 1 );
4776 for (i
= 0; i
< 4; i
++ )
4777 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
4778 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
4784 r
= SelectionToDeviceRect();
4786 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
4788 m_selectedTopLeft
.Set( 0, col
);
4789 m_selectedBottomRight
.Set( m_numRows
-1, col
);
4790 r
= SelectionToDeviceRect();
4791 m_gridWin
->Refresh( FALSE
, &r
);
4794 wxGridRangeSelectEvent
gridEvt( GetId(),
4795 EVT_GRID_RANGE_SELECT
,
4798 m_selectedBottomRight
);
4800 GetEventHandler()->ProcessEvent(gridEvt
);
4804 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
4807 wxGridCellCoords updateTopLeft
, updateBottomRight
;
4809 if ( topRow
> bottomRow
)
4816 if ( leftCol
> rightCol
)
4823 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
4824 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
4826 if ( m_selectedTopLeft
!= updateTopLeft
||
4827 m_selectedBottomRight
!= updateBottomRight
)
4829 // Compute two optimal update rectangles:
4830 // Either one rectangle is a real subset of the
4831 // other, or they are (almost) disjoint!
4833 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
4836 // Store intermediate values
4837 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
4838 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
4839 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
4840 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
4842 // Determine the outer/inner coordinates.
4843 if (oldLeft
> leftCol
)
4849 if (oldTop
> topRow
)
4855 if (oldRight
< rightCol
)
4858 oldRight
= rightCol
;
4861 if (oldBottom
< bottomRow
)
4864 oldBottom
= bottomRow
;
4868 // Now, either the stuff marked old is the outer
4869 // rectangle or we don't have a situation where one
4870 // is contained in the other.
4872 if ( oldLeft
< leftCol
)
4874 need_refresh
[0] = TRUE
;
4875 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
4877 wxGridCellCoords ( oldBottom
,
4881 if ( oldTop
< topRow
)
4883 need_refresh
[1] = TRUE
;
4884 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
4886 wxGridCellCoords ( topRow
- 1,
4890 if ( oldRight
> rightCol
)
4892 need_refresh
[2] = TRUE
;
4893 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
4895 wxGridCellCoords ( oldBottom
,
4899 if ( oldBottom
> bottomRow
)
4901 need_refresh
[3] = TRUE
;
4902 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
4904 wxGridCellCoords ( oldBottom
,
4910 m_selectedTopLeft
= updateTopLeft
;
4911 m_selectedBottomRight
= updateBottomRight
;
4913 // various Refresh() calls
4914 for (i
= 0; i
< 4; i
++ )
4915 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
4916 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
4919 // only generate an event if the block is not being selected by
4920 // dragging the mouse (in which case the event will be generated in
4921 // the mouse event handler)
4922 if ( !m_isDragging
)
4924 wxGridRangeSelectEvent
gridEvt( GetId(),
4925 EVT_GRID_RANGE_SELECT
,
4928 m_selectedBottomRight
);
4930 GetEventHandler()->ProcessEvent(gridEvt
);
4934 void wxGrid::SelectAll()
4936 m_selectedTopLeft
.Set( 0, 0 );
4937 m_selectedBottomRight
.Set( m_numRows
-1, m_numCols
-1 );
4939 m_gridWin
->Refresh();
4943 void wxGrid::ClearSelection()
4945 m_selectedTopLeft
= wxGridNoCellCoords
;
4946 m_selectedBottomRight
= wxGridNoCellCoords
;
4950 // This function returns the rectangle that encloses the given block
4951 // in device coords clipped to the client size of the grid window.
4953 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
4954 const wxGridCellCoords
&bottomRight
)
4956 wxRect
rect( wxGridNoCellRect
);
4959 cellRect
= CellToRect( topLeft
);
4960 if ( cellRect
!= wxGridNoCellRect
)
4966 rect
= wxRect( 0, 0, 0, 0 );
4969 cellRect
= CellToRect( bottomRight
);
4970 if ( cellRect
!= wxGridNoCellRect
)
4976 return wxGridNoCellRect
;
4979 // convert to scrolled coords
4981 int left
, top
, right
, bottom
;
4982 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
4983 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
4986 m_gridWin
->GetClientSize( &cw
, &ch
);
4988 rect
.SetLeft( wxMax(0, left
) );
4989 rect
.SetTop( wxMax(0, top
) );
4990 rect
.SetRight( wxMin(cw
, right
) );
4991 rect
.SetBottom( wxMin(ch
, bottom
) );
4999 // ------ Grid event classes
5002 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxEvent
)
5004 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
5005 int row
, int col
, int x
, int y
,
5006 bool control
, bool shift
, bool alt
, bool meta
)
5007 : wxNotifyEvent( type
, id
)
5013 m_control
= control
;
5018 SetEventObject(obj
);
5022 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxEvent
)
5024 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
5025 int rowOrCol
, int x
, int y
,
5026 bool control
, bool shift
, bool alt
, bool meta
)
5027 : wxNotifyEvent( type
, id
)
5029 m_rowOrCol
= rowOrCol
;
5032 m_control
= control
;
5037 SetEventObject(obj
);
5041 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxEvent
)
5043 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
5044 const wxGridCellCoords
& topLeft
,
5045 const wxGridCellCoords
& bottomRight
,
5046 bool control
, bool shift
, bool alt
, bool meta
)
5047 : wxNotifyEvent( type
, id
)
5049 m_topLeft
= topLeft
;
5050 m_bottomRight
= bottomRight
;
5051 m_control
= control
;
5056 SetEventObject(obj
);
5060 #endif // ifndef wxUSE_NEW_GRID