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"
36 #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
)
3230 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
3231 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
3233 while ( startPos
< (int)tVal
.Length() )
3235 pos
= tVal
.Mid(startPos
).Find( eol
);
3240 else if ( pos
== 0 )
3242 lines
.Add( wxEmptyString
);
3246 lines
.Add( value
.Mid(startPos
, pos
) );
3250 if ( startPos
< (int)value
.Length() )
3252 lines
.Add( value
.Mid( startPos
) );
3257 void wxGrid::GetTextBoxSize( wxDC
& dc
,
3258 wxArrayString
& lines
,
3259 long *width
, long *height
)
3266 for ( i
= 0; i
< lines
.GetCount(); i
++ )
3268 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
3269 w
= wxMax( w
, lineW
);
3279 // ------ Edit control functions
3283 void wxGrid::EnableEditing( bool edit
)
3285 // TODO: improve this ?
3287 if ( edit
!= m_editable
)
3291 // TODO: extend this for other edit control types
3293 if ( m_editCtrlType
== wxGRID_TEXTCTRL
)
3295 ((wxTextCtrl
*)m_cellEditCtrl
)->SetEditable( m_editable
);
3301 #if 0 // disabled for the moment - the cell control is always active
3302 void wxGrid::EnableCellEditControl( bool enable
)
3304 if ( m_cellEditCtrl
&&
3305 enable
!= m_cellEditCtrlEnabled
)
3307 m_cellEditCtrlEnabled
= enable
;
3309 if ( m_cellEditCtrlEnabled
)
3311 SetEditControlValue();
3312 ShowCellEditControl();
3316 HideCellEditControl();
3317 SaveEditControlValue();
3324 void wxGrid::ShowCellEditControl()
3328 if ( IsCellEditControlEnabled() )
3330 if ( !IsVisible( m_currentCellCoords
) )
3336 rect
= CellToRect( m_currentCellCoords
);
3338 // convert to scrolled coords
3340 int left
, top
, right
, bottom
;
3341 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
3342 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
3345 m_gridWin
->GetClientSize( &cw
, &ch
);
3347 // Make the edit control large enough to allow for internal margins
3348 // TODO: remove this if the text ctrl sizing is improved esp. for unix
3351 #if defined(__WXMOTIF__)
3352 if ( m_currentCellCoords
.GetRow() == 0 ||
3353 m_currentCellCoords
.GetCol() == 0 )
3362 if ( m_currentCellCoords
.GetRow() == 0 ||
3363 m_currentCellCoords
.GetCol() == 0 )
3373 #if defined(__WXGTK__)
3376 if (left
!= 0) left_diff
++;
3377 if (top
!= 0) top_diff
++;
3378 rect
.SetLeft( left
+ left_diff
);
3379 rect
.SetTop( top
+ top_diff
);
3380 rect
.SetRight( rect
.GetRight() - left_diff
);
3381 rect
.SetBottom( rect
.GetBottom() - top_diff
);
3383 rect
.SetLeft( wxMax(0, left
- extra
) );
3384 rect
.SetTop( wxMax(0, top
- extra
) );
3385 rect
.SetRight( rect
.GetRight() + 2*extra
);
3386 rect
.SetBottom( rect
.GetBottom() + 2*extra
);
3389 m_cellEditCtrl
->SetSize( rect
);
3390 m_cellEditCtrl
->Show( TRUE
);
3392 switch ( m_editCtrlType
)
3394 case wxGRID_TEXTCTRL
:
3395 ((wxTextCtrl
*) m_cellEditCtrl
)->SetInsertionPointEnd();
3398 case wxGRID_CHECKBOX
:
3399 // TODO: anything ???
3404 // TODO: anything ???
3408 case wxGRID_COMBOBOX
:
3409 // TODO: anything ???
3414 m_cellEditCtrl
->SetFocus();
3420 void wxGrid::HideCellEditControl()
3422 if ( IsCellEditControlEnabled() )
3424 m_cellEditCtrl
->Show( FALSE
);
3429 void wxGrid::SetEditControlValue( const wxString
& value
)
3435 s
= GetCellValue(m_currentCellCoords
);
3439 if ( IsCellEditControlEnabled() )
3441 switch ( m_editCtrlType
)
3443 case wxGRID_TEXTCTRL
:
3444 ((wxGridTextCtrl
*)m_cellEditCtrl
)->SetStartValue(s
);
3447 case wxGRID_CHECKBOX
:
3448 // TODO: implement this
3453 // TODO: implement this
3457 case wxGRID_COMBOBOX
:
3458 // TODO: implement this
3467 void wxGrid::SaveEditControlValue()
3471 wxWindow
*ctrl
= (wxWindow
*)NULL
;
3473 if ( IsCellEditControlEnabled() )
3475 ctrl
= m_cellEditCtrl
;
3482 bool valueChanged
= FALSE
;
3484 switch ( m_editCtrlType
)
3486 case wxGRID_TEXTCTRL
:
3487 valueChanged
= (((wxGridTextCtrl
*)ctrl
)->GetValue() !=
3488 ((wxGridTextCtrl
*)ctrl
)->GetStartValue());
3489 SetCellValue( m_currentCellCoords
,
3490 ((wxTextCtrl
*) ctrl
)->GetValue() );
3493 case wxGRID_CHECKBOX
:
3494 // TODO: implement this
3499 // TODO: implement this
3503 case wxGRID_COMBOBOX
:
3504 // TODO: implement this
3511 SendEvent( EVT_GRID_CELL_CHANGE
,
3512 m_currentCellCoords
.GetRow(),
3513 m_currentCellCoords
.GetCol() );
3520 // ------ Grid location functions
3521 // Note that all of these functions work with the logical coordinates of
3522 // grid cells and labels so you will need to convert from device
3523 // coordinates for mouse events etc.
3526 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
3528 int row
= YToRow(y
);
3529 int col
= XToCol(x
);
3531 if ( row
== -1 || col
== -1 )
3533 coords
= wxGridNoCellCoords
;
3537 coords
.Set( row
, col
);
3542 int wxGrid::YToRow( int y
)
3546 for ( i
= 0; i
< m_numRows
; i
++ )
3548 if ( y
< m_rowBottoms
[i
] ) return i
;
3555 int wxGrid::XToCol( int x
)
3559 for ( i
= 0; i
< m_numCols
; i
++ )
3561 if ( x
< m_colRights
[i
] ) return i
;
3568 // return the row number that that the y coord is near the edge of, or
3569 // -1 if not near an edge
3571 int wxGrid::YToEdgeOfRow( int y
)
3575 for ( i
= 0; i
< m_numRows
; i
++ )
3577 if ( m_rowHeights
[i
] > WXGRID_LABEL_EDGE_ZONE
)
3579 d
= abs( y
- m_rowBottoms
[i
] );
3581 if ( d
< WXGRID_LABEL_EDGE_ZONE
) return i
;
3590 // return the col number that that the x coord is near the edge of, or
3591 // -1 if not near an edge
3593 int wxGrid::XToEdgeOfCol( int x
)
3597 for ( i
= 0; i
< m_numCols
; i
++ )
3599 if ( m_colWidths
[i
] > WXGRID_LABEL_EDGE_ZONE
)
3601 d
= abs( x
- m_colRights
[i
] );
3603 if ( d
< WXGRID_LABEL_EDGE_ZONE
) return i
;
3612 wxRect
wxGrid::CellToRect( int row
, int col
)
3614 wxRect
rect( -1, -1, -1, -1 );
3616 if ( row
>= 0 && row
< m_numRows
&&
3617 col
>= 0 && col
< m_numCols
)
3619 rect
.x
= m_colRights
[col
] - m_colWidths
[col
];
3620 rect
.y
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3621 rect
.width
= m_colWidths
[col
];
3622 rect
.height
= m_rowHeights
[ row
];
3629 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
3631 // get the cell rectangle in logical coords
3633 wxRect
r( CellToRect( row
, col
) );
3635 // convert to device coords
3637 int left
, top
, right
, bottom
;
3638 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
3639 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
3641 // check against the client area of the grid window
3644 m_gridWin
->GetClientSize( &cw
, &ch
);
3646 if ( wholeCellVisible
)
3648 // is the cell wholly visible ?
3650 return ( left
>= 0 && right
<= cw
&&
3651 top
>= 0 && bottom
<= ch
);
3655 // is the cell partly visible ?
3657 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
3658 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
3663 // make the specified cell location visible by doing a minimal amount
3666 void wxGrid::MakeCellVisible( int row
, int col
)
3669 int xpos
= -1, ypos
= -1;
3671 if ( row
>= 0 && row
< m_numRows
&&
3672 col
>= 0 && col
< m_numCols
)
3674 // get the cell rectangle in logical coords
3676 wxRect
r( CellToRect( row
, col
) );
3678 // convert to device coords
3680 int left
, top
, right
, bottom
;
3681 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
3682 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
3685 m_gridWin
->GetClientSize( &cw
, &ch
);
3691 else if ( bottom
> ch
)
3693 int h
= r
.GetHeight();
3695 for ( i
= row
-1; i
>= 0; i
-- )
3697 if ( h
+ m_rowHeights
[i
] > ch
) break;
3699 h
+= m_rowHeights
[i
];
3700 ypos
-= m_rowHeights
[i
];
3703 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
3704 // have rounding errors (this is important, because if we do, we
3705 // might not scroll at all and some cells won't be redrawn)
3706 ypos
+= GRID_SCROLL_LINE
/ 2;
3713 else if ( right
> cw
)
3715 int w
= r
.GetWidth();
3717 for ( i
= col
-1; i
>= 0; i
-- )
3719 if ( w
+ m_colWidths
[i
] > cw
) break;
3721 w
+= m_colWidths
[i
];
3722 xpos
-= m_colWidths
[i
];
3725 // see comment for ypos above
3726 xpos
+= GRID_SCROLL_LINE
/ 2;
3729 if ( xpos
!= -1 || ypos
!= -1 )
3731 if ( xpos
!= -1 ) xpos
/= GRID_SCROLL_LINE
;
3732 if ( ypos
!= -1 ) ypos
/= GRID_SCROLL_LINE
;
3733 Scroll( xpos
, ypos
);
3741 // ------ Grid cursor movement functions
3744 bool wxGrid::MoveCursorUp()
3746 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
3747 m_currentCellCoords
.GetRow() > 0 )
3749 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
3750 m_currentCellCoords
.GetCol() );
3752 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
3753 m_currentCellCoords
.GetCol() );
3762 bool wxGrid::MoveCursorDown()
3764 // TODO: allow for scrolling
3766 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
3767 m_currentCellCoords
.GetRow() < m_numRows
-1 )
3769 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
3770 m_currentCellCoords
.GetCol() );
3772 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
3773 m_currentCellCoords
.GetCol() );
3782 bool wxGrid::MoveCursorLeft()
3784 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
3785 m_currentCellCoords
.GetCol() > 0 )
3787 MakeCellVisible( m_currentCellCoords
.GetRow(),
3788 m_currentCellCoords
.GetCol() - 1 );
3790 SetCurrentCell( m_currentCellCoords
.GetRow(),
3791 m_currentCellCoords
.GetCol() - 1 );
3800 bool wxGrid::MoveCursorRight()
3802 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
3803 m_currentCellCoords
.GetCol() < m_numCols
- 1 )
3805 MakeCellVisible( m_currentCellCoords
.GetRow(),
3806 m_currentCellCoords
.GetCol() + 1 );
3808 SetCurrentCell( m_currentCellCoords
.GetRow(),
3809 m_currentCellCoords
.GetCol() + 1 );
3818 bool wxGrid::MovePageUp()
3820 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
3822 int row
= m_currentCellCoords
.GetRow();
3826 m_gridWin
->GetClientSize( &cw
, &ch
);
3828 int y
= m_rowBottoms
[ row
] - m_rowHeights
[ row
];
3829 int newRow
= YToRow( y
- ch
+ 1 );
3834 else if ( newRow
== row
)
3839 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
3840 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
3848 bool wxGrid::MovePageDown()
3850 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
3852 int row
= m_currentCellCoords
.GetRow();
3853 if ( row
< m_numRows
)
3856 m_gridWin
->GetClientSize( &cw
, &ch
);
3858 int y
= m_rowBottoms
[ row
] - m_rowHeights
[ row
];
3859 int newRow
= YToRow( y
+ ch
);
3862 newRow
= m_numRows
- 1;
3864 else if ( newRow
== row
)
3869 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
3870 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
3878 bool wxGrid::MoveCursorUpBlock()
3881 m_currentCellCoords
!= wxGridNoCellCoords
&&
3882 m_currentCellCoords
.GetRow() > 0 )
3884 int row
= m_currentCellCoords
.GetRow();
3885 int col
= m_currentCellCoords
.GetCol();
3887 if ( m_table
->IsEmptyCell(row
, col
) )
3889 // starting in an empty cell: find the next block of
3895 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
3898 else if ( m_table
->IsEmptyCell(row
-1, col
) )
3900 // starting at the top of a block: find the next block
3906 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
3911 // starting within a block: find the top of the block
3916 if ( m_table
->IsEmptyCell(row
, col
) )
3924 MakeCellVisible( row
, col
);
3925 SetCurrentCell( row
, col
);
3933 bool wxGrid::MoveCursorDownBlock()
3936 m_currentCellCoords
!= wxGridNoCellCoords
&&
3937 m_currentCellCoords
.GetRow() < m_numRows
-1 )
3939 int row
= m_currentCellCoords
.GetRow();
3940 int col
= m_currentCellCoords
.GetCol();
3942 if ( m_table
->IsEmptyCell(row
, col
) )
3944 // starting in an empty cell: find the next block of
3947 while ( row
< m_numRows
-1 )
3950 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
3953 else if ( m_table
->IsEmptyCell(row
+1, col
) )
3955 // starting at the bottom of a block: find the next block
3958 while ( row
< m_numRows
-1 )
3961 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
3966 // starting within a block: find the bottom of the block
3968 while ( row
< m_numRows
-1 )
3971 if ( m_table
->IsEmptyCell(row
, col
) )
3979 MakeCellVisible( row
, col
);
3980 SetCurrentCell( row
, col
);
3988 bool wxGrid::MoveCursorLeftBlock()
3991 m_currentCellCoords
!= wxGridNoCellCoords
&&
3992 m_currentCellCoords
.GetCol() > 0 )
3994 int row
= m_currentCellCoords
.GetRow();
3995 int col
= m_currentCellCoords
.GetCol();
3997 if ( m_table
->IsEmptyCell(row
, col
) )
3999 // starting in an empty cell: find the next block of
4005 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4008 else if ( m_table
->IsEmptyCell(row
, col
-1) )
4010 // starting at the left of a block: find the next block
4016 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4021 // starting within a block: find the left of the block
4026 if ( m_table
->IsEmptyCell(row
, col
) )
4034 MakeCellVisible( row
, col
);
4035 SetCurrentCell( row
, col
);
4043 bool wxGrid::MoveCursorRightBlock()
4046 m_currentCellCoords
!= wxGridNoCellCoords
&&
4047 m_currentCellCoords
.GetCol() < m_numCols
-1 )
4049 int row
= m_currentCellCoords
.GetRow();
4050 int col
= m_currentCellCoords
.GetCol();
4052 if ( m_table
->IsEmptyCell(row
, col
) )
4054 // starting in an empty cell: find the next block of
4057 while ( col
< m_numCols
-1 )
4060 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4063 else if ( m_table
->IsEmptyCell(row
, col
+1) )
4065 // starting at the right of a block: find the next block
4068 while ( col
< m_numCols
-1 )
4071 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4076 // starting within a block: find the right of the block
4078 while ( col
< m_numCols
-1 )
4081 if ( m_table
->IsEmptyCell(row
, col
) )
4089 MakeCellVisible( row
, col
);
4090 SetCurrentCell( row
, col
);
4101 // ------ Label values and formatting
4104 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
4106 *horiz
= m_rowLabelHorizAlign
;
4107 *vert
= m_rowLabelVertAlign
;
4110 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
4112 *horiz
= m_colLabelHorizAlign
;
4113 *vert
= m_colLabelVertAlign
;
4116 wxString
wxGrid::GetRowLabelValue( int row
)
4120 return m_table
->GetRowLabelValue( row
);
4130 wxString
wxGrid::GetColLabelValue( int col
)
4134 return m_table
->GetColLabelValue( col
);
4145 void wxGrid::SetRowLabelSize( int width
)
4147 width
= wxMax( width
, 0 );
4148 if ( width
!= m_rowLabelWidth
)
4152 m_rowLabelWin
->Show( FALSE
);
4153 m_cornerLabelWin
->Show( FALSE
);
4155 else if ( m_rowLabelWidth
== 0 )
4157 m_rowLabelWin
->Show( TRUE
);
4158 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
4161 m_rowLabelWidth
= width
;
4168 void wxGrid::SetColLabelSize( int height
)
4170 height
= wxMax( height
, 0 );
4171 if ( height
!= m_colLabelHeight
)
4175 m_colLabelWin
->Show( FALSE
);
4176 m_cornerLabelWin
->Show( FALSE
);
4178 else if ( m_colLabelHeight
== 0 )
4180 m_colLabelWin
->Show( TRUE
);
4181 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
4184 m_colLabelHeight
= height
;
4191 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
4193 if ( m_labelBackgroundColour
!= colour
)
4195 m_labelBackgroundColour
= colour
;
4196 m_rowLabelWin
->SetBackgroundColour( colour
);
4197 m_colLabelWin
->SetBackgroundColour( colour
);
4198 m_cornerLabelWin
->SetBackgroundColour( colour
);
4200 if ( !GetBatchCount() )
4202 m_rowLabelWin
->Refresh();
4203 m_colLabelWin
->Refresh();
4204 m_cornerLabelWin
->Refresh();
4209 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
4211 if ( m_labelTextColour
!= colour
)
4213 m_labelTextColour
= colour
;
4214 if ( !GetBatchCount() )
4216 m_rowLabelWin
->Refresh();
4217 m_colLabelWin
->Refresh();
4222 void wxGrid::SetLabelFont( const wxFont
& font
)
4225 if ( !GetBatchCount() )
4227 m_rowLabelWin
->Refresh();
4228 m_colLabelWin
->Refresh();
4232 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
4234 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
4236 m_rowLabelHorizAlign
= horiz
;
4239 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
4241 m_rowLabelVertAlign
= vert
;
4244 if ( !GetBatchCount() )
4246 m_rowLabelWin
->Refresh();
4250 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
4252 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
4254 m_colLabelHorizAlign
= horiz
;
4257 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
4259 m_colLabelVertAlign
= vert
;
4262 if ( !GetBatchCount() )
4264 m_colLabelWin
->Refresh();
4268 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
4272 m_table
->SetRowLabelValue( row
, s
);
4273 if ( !GetBatchCount() )
4275 wxRect rect
= CellToRect( row
, 0);
4276 if ( rect
.height
> 0 )
4278 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
4280 rect
.width
= m_rowLabelWidth
;
4281 m_rowLabelWin
->Refresh( TRUE
, &rect
);
4287 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
4291 m_table
->SetColLabelValue( col
, s
);
4292 if ( !GetBatchCount() )
4294 wxRect rect
= CellToRect( 0, col
);
4295 if ( rect
.width
> 0 )
4297 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
4299 rect
.height
= m_colLabelHeight
;
4300 m_colLabelWin
->Refresh( TRUE
, &rect
);
4306 void wxGrid::SetGridLineColour( const wxColour
& colour
)
4308 if ( m_gridLineColour
!= colour
)
4310 m_gridLineColour
= colour
;
4312 wxClientDC
dc( m_gridWin
);
4314 DrawAllGridLines( dc
, wxRegion() );
4318 void wxGrid::EnableGridLines( bool enable
)
4320 if ( enable
!= m_gridLinesEnabled
)
4322 m_gridLinesEnabled
= enable
;
4324 if ( !GetBatchCount() )
4328 wxClientDC
dc( m_gridWin
);
4330 DrawAllGridLines( dc
, wxRegion() );
4334 m_gridWin
->Refresh();
4341 int wxGrid::GetDefaultRowSize()
4343 return m_defaultRowHeight
;
4346 int wxGrid::GetRowSize( int row
)
4348 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
4350 return m_rowHeights
[row
];
4353 int wxGrid::GetDefaultColSize()
4355 return m_defaultColWidth
;
4358 int wxGrid::GetColSize( int col
)
4360 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
4362 return m_colWidths
[col
];
4365 wxColour
wxGrid::GetDefaultCellBackgroundColour()
4367 return m_gridWin
->GetBackgroundColour();
4370 // TODO VZ: this must be optimized to allow only retrieveing attr once!
4372 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
4374 wxGridCellAttr
*attr
= m_table
? m_table
->GetAttr(row
, col
) : NULL
;
4377 if ( attr
&& attr
->HasBackgroundColour() )
4378 colour
= attr
->GetBackgroundColour();
4380 colour
= GetDefaultCellBackgroundColour();
4387 wxColour
wxGrid::GetDefaultCellTextColour()
4389 return m_gridWin
->GetForegroundColour();
4392 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
4394 wxGridCellAttr
*attr
= m_table
? m_table
->GetAttr(row
, col
) : NULL
;
4397 if ( attr
&& attr
->HasTextColour() )
4398 colour
= attr
->GetTextColour();
4400 colour
= GetDefaultCellTextColour();
4408 wxFont
wxGrid::GetDefaultCellFont()
4410 return m_defaultCellFont
;
4413 wxFont
wxGrid::GetCellFont( int row
, int col
)
4415 wxGridCellAttr
*attr
= m_table
? m_table
->GetAttr(row
, col
) : NULL
;
4418 if ( attr
&& attr
->HasFont() )
4419 font
= attr
->GetFont();
4421 font
= GetDefaultCellFont();
4428 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
4431 *horiz
= m_defaultCellHAlign
;
4433 *vert
= m_defaultCellVAlign
;
4436 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
4438 wxGridCellAttr
*attr
= m_table
? m_table
->GetAttr(row
, col
) : NULL
;
4440 if ( attr
&& attr
->HasAlignment() )
4441 attr
->GetAlignment(horiz
, vert
);
4443 GetDefaultCellAlignment(horiz
, vert
);
4448 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
4450 m_defaultRowHeight
= wxMax( height
, WXGRID_MIN_ROW_HEIGHT
);
4452 if ( resizeExistingRows
)
4456 for ( row
= 0; row
< m_numRows
; row
++ )
4458 m_rowHeights
[row
] = m_defaultRowHeight
;
4459 bottom
+= m_defaultRowHeight
;
4460 m_rowBottoms
[row
] = bottom
;
4466 void wxGrid::SetRowSize( int row
, int height
)
4468 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
4472 int h
= wxMax( 0, height
);
4473 int diff
= h
- m_rowHeights
[row
];
4475 m_rowHeights
[row
] = h
;
4476 for ( i
= row
; i
< m_numRows
; i
++ )
4478 m_rowBottoms
[i
] += diff
;
4482 // Note: we are ending the event *after* doing
4483 // default processing in this case
4485 SendEvent( EVT_GRID_ROW_SIZE
,
4489 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
4491 m_defaultColWidth
= wxMax( width
, WXGRID_MIN_COL_WIDTH
);
4493 if ( resizeExistingCols
)
4497 for ( col
= 0; col
< m_numCols
; col
++ )
4499 m_colWidths
[col
] = m_defaultColWidth
;
4500 right
+= m_defaultColWidth
;
4501 m_colRights
[col
] = right
;
4507 void wxGrid::SetColSize( int col
, int width
)
4509 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
4513 int w
= wxMax( 0, width
);
4514 int diff
= w
- m_colWidths
[col
];
4515 m_colWidths
[col
] = w
;
4517 for ( i
= col
; i
< m_numCols
; i
++ )
4519 m_colRights
[i
] += diff
;
4523 // Note: we are ending the event *after* doing
4524 // default processing in this case
4526 SendEvent( EVT_GRID_COL_SIZE
,
4530 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
4532 m_gridWin
->SetBackgroundColour(col
);
4535 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
4537 m_gridWin
->SetForegroundColour(col
);
4540 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
4542 m_defaultCellHAlign
= horiz
;
4543 m_defaultCellVAlign
= vert
;
4546 bool wxGrid::CanHaveAttributes()
4553 if ( !m_table
->GetAttrProvider() )
4555 // use the default attr provider by default
4556 // (another choice would be to just return FALSE thus forcing the user
4558 m_table
->SetAttrProvider(new wxGridCellAttrProvider
);
4564 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
4566 if ( CanHaveAttributes() )
4568 wxGridCellAttr
*attr
= new wxGridCellAttr
;
4569 attr
->SetBackgroundColour(colour
);
4571 m_table
->SetAttr(attr
, row
, col
);
4575 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
4577 if ( CanHaveAttributes() )
4579 wxGridCellAttr
*attr
= new wxGridCellAttr
;
4580 attr
->SetTextColour(colour
);
4582 m_table
->SetAttr(attr
, row
, col
);
4586 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
4588 m_defaultCellFont
= font
;
4591 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
4593 if ( CanHaveAttributes() )
4595 wxGridCellAttr
*attr
= new wxGridCellAttr
;
4596 attr
->SetFont(font
);
4598 m_table
->SetAttr(attr
, row
, col
);
4602 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
4604 if ( CanHaveAttributes() )
4606 wxGridCellAttr
*attr
= new wxGridCellAttr
;
4607 attr
->SetAlignment(horiz
, vert
);
4609 m_table
->SetAttr(attr
, row
, col
);
4616 // ------ cell value accessor functions
4619 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
4623 m_table
->SetValue( row
, col
, s
.c_str() );
4624 if ( !GetBatchCount() )
4626 wxClientDC
dc( m_gridWin
);
4628 DrawCell( dc
, wxGridCellCoords(row
, col
) );
4631 #if 0 // TODO: edit in place
4633 if ( m_currentCellCoords
.GetRow() == row
&&
4634 m_currentCellCoords
.GetCol() == col
)
4636 SetEditControlValue( s
);
4645 // ------ Block, row and col selection
4648 void wxGrid::SelectRow( int row
, bool addToSelected
)
4652 if ( IsSelection() && addToSelected
)
4655 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
4658 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
4659 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
4660 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
4661 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
4665 need_refresh
[0] = TRUE
;
4666 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( row
, 0 ),
4667 wxGridCellCoords ( oldTop
- 1,
4669 m_selectedTopLeft
.SetRow( row
);
4674 need_refresh
[1] = TRUE
;
4675 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
, 0 ),
4676 wxGridCellCoords ( oldBottom
,
4679 m_selectedTopLeft
.SetCol( 0 );
4682 if ( oldBottom
< row
)
4684 need_refresh
[2] = TRUE
;
4685 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1, 0 ),
4686 wxGridCellCoords ( row
,
4688 m_selectedBottomRight
.SetRow( row
);
4691 if ( oldRight
< m_numCols
- 1 )
4693 need_refresh
[3] = TRUE
;
4694 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
4696 wxGridCellCoords ( oldBottom
,
4698 m_selectedBottomRight
.SetCol( m_numCols
- 1 );
4701 for (i
= 0; i
< 4; i
++ )
4702 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
4703 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
4707 r
= SelectionToDeviceRect();
4709 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
4711 m_selectedTopLeft
.Set( row
, 0 );
4712 m_selectedBottomRight
.Set( row
, m_numCols
-1 );
4713 r
= SelectionToDeviceRect();
4714 m_gridWin
->Refresh( FALSE
, &r
);
4717 wxGridRangeSelectEvent
gridEvt( GetId(),
4718 EVT_GRID_RANGE_SELECT
,
4721 m_selectedBottomRight
);
4723 GetEventHandler()->ProcessEvent(gridEvt
);
4727 void wxGrid::SelectCol( int col
, bool addToSelected
)
4729 if ( IsSelection() && addToSelected
)
4732 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
4735 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
4736 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
4737 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
4738 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
4740 if ( oldLeft
> col
)
4742 need_refresh
[0] = TRUE
;
4743 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( 0, col
),
4744 wxGridCellCoords ( m_numRows
- 1,
4746 m_selectedTopLeft
.SetCol( col
);
4751 need_refresh
[1] = TRUE
;
4752 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( 0, oldLeft
),
4753 wxGridCellCoords ( oldTop
- 1,
4755 m_selectedTopLeft
.SetRow( 0 );
4758 if ( oldRight
< col
)
4760 need_refresh
[2] = TRUE
;
4761 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( 0, oldRight
+ 1 ),
4762 wxGridCellCoords ( m_numRows
- 1,
4764 m_selectedBottomRight
.SetCol( col
);
4767 if ( oldBottom
< m_numRows
- 1 )
4769 need_refresh
[3] = TRUE
;
4770 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1,
4772 wxGridCellCoords ( m_numRows
- 1,
4774 m_selectedBottomRight
.SetRow( m_numRows
- 1 );
4777 for (i
= 0; i
< 4; i
++ )
4778 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
4779 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
4785 r
= SelectionToDeviceRect();
4787 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
4789 m_selectedTopLeft
.Set( 0, col
);
4790 m_selectedBottomRight
.Set( m_numRows
-1, col
);
4791 r
= SelectionToDeviceRect();
4792 m_gridWin
->Refresh( FALSE
, &r
);
4795 wxGridRangeSelectEvent
gridEvt( GetId(),
4796 EVT_GRID_RANGE_SELECT
,
4799 m_selectedBottomRight
);
4801 GetEventHandler()->ProcessEvent(gridEvt
);
4805 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
4808 wxGridCellCoords updateTopLeft
, updateBottomRight
;
4810 if ( topRow
> bottomRow
)
4817 if ( leftCol
> rightCol
)
4824 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
4825 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
4827 if ( m_selectedTopLeft
!= updateTopLeft
||
4828 m_selectedBottomRight
!= updateBottomRight
)
4830 // Compute two optimal update rectangles:
4831 // Either one rectangle is a real subset of the
4832 // other, or they are (almost) disjoint!
4834 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
4837 // Store intermediate values
4838 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
4839 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
4840 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
4841 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
4843 // Determine the outer/inner coordinates.
4844 if (oldLeft
> leftCol
)
4850 if (oldTop
> topRow
)
4856 if (oldRight
< rightCol
)
4859 oldRight
= rightCol
;
4862 if (oldBottom
< bottomRow
)
4865 oldBottom
= bottomRow
;
4869 // Now, either the stuff marked old is the outer
4870 // rectangle or we don't have a situation where one
4871 // is contained in the other.
4873 if ( oldLeft
< leftCol
)
4875 need_refresh
[0] = TRUE
;
4876 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
4878 wxGridCellCoords ( oldBottom
,
4882 if ( oldTop
< topRow
)
4884 need_refresh
[1] = TRUE
;
4885 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
4887 wxGridCellCoords ( topRow
- 1,
4891 if ( oldRight
> rightCol
)
4893 need_refresh
[2] = TRUE
;
4894 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
4896 wxGridCellCoords ( oldBottom
,
4900 if ( oldBottom
> bottomRow
)
4902 need_refresh
[3] = TRUE
;
4903 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
4905 wxGridCellCoords ( oldBottom
,
4911 m_selectedTopLeft
= updateTopLeft
;
4912 m_selectedBottomRight
= updateBottomRight
;
4914 // various Refresh() calls
4915 for (i
= 0; i
< 4; i
++ )
4916 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
4917 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
4920 // only generate an event if the block is not being selected by
4921 // dragging the mouse (in which case the event will be generated in
4922 // the mouse event handler)
4923 if ( !m_isDragging
)
4925 wxGridRangeSelectEvent
gridEvt( GetId(),
4926 EVT_GRID_RANGE_SELECT
,
4929 m_selectedBottomRight
);
4931 GetEventHandler()->ProcessEvent(gridEvt
);
4935 void wxGrid::SelectAll()
4937 m_selectedTopLeft
.Set( 0, 0 );
4938 m_selectedBottomRight
.Set( m_numRows
-1, m_numCols
-1 );
4940 m_gridWin
->Refresh();
4944 void wxGrid::ClearSelection()
4946 m_selectedTopLeft
= wxGridNoCellCoords
;
4947 m_selectedBottomRight
= wxGridNoCellCoords
;
4951 // This function returns the rectangle that encloses the given block
4952 // in device coords clipped to the client size of the grid window.
4954 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
4955 const wxGridCellCoords
&bottomRight
)
4957 wxRect
rect( wxGridNoCellRect
);
4960 cellRect
= CellToRect( topLeft
);
4961 if ( cellRect
!= wxGridNoCellRect
)
4967 rect
= wxRect( 0, 0, 0, 0 );
4970 cellRect
= CellToRect( bottomRight
);
4971 if ( cellRect
!= wxGridNoCellRect
)
4977 return wxGridNoCellRect
;
4980 // convert to scrolled coords
4982 int left
, top
, right
, bottom
;
4983 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
4984 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
4987 m_gridWin
->GetClientSize( &cw
, &ch
);
4989 rect
.SetLeft( wxMax(0, left
) );
4990 rect
.SetTop( wxMax(0, top
) );
4991 rect
.SetRight( wxMin(cw
, right
) );
4992 rect
.SetBottom( wxMin(ch
, bottom
) );
5000 // ------ Grid event classes
5003 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxEvent
)
5005 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
5006 int row
, int col
, int x
, int y
,
5007 bool control
, bool shift
, bool alt
, bool meta
)
5008 : wxNotifyEvent( type
, id
)
5014 m_control
= control
;
5019 SetEventObject(obj
);
5023 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxEvent
)
5025 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
5026 int rowOrCol
, int x
, int y
,
5027 bool control
, bool shift
, bool alt
, bool meta
)
5028 : wxNotifyEvent( type
, id
)
5030 m_rowOrCol
= rowOrCol
;
5033 m_control
= control
;
5038 SetEventObject(obj
);
5042 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxEvent
)
5044 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
5045 const wxGridCellCoords
& topLeft
,
5046 const wxGridCellCoords
& bottomRight
,
5047 bool control
, bool shift
, bool alt
, bool meta
)
5048 : wxNotifyEvent( type
, id
)
5050 m_topLeft
= topLeft
;
5051 m_bottomRight
= bottomRight
;
5052 m_control
= control
;
5057 SetEventObject(obj
);
5061 #endif // ifndef wxUSE_NEW_GRID