1 ///////////////////////////////////////////////////////////////////////////
2 // Name: generic/grid.cpp
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 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "grid.h"
24 // For compilers that support precompilatixon, includes "wx/wx.h".
25 #include "wx/wxprec.h"
33 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
39 #include "wx/dcclient.h"
40 #include "wx/settings.h"
42 #include "wx/textctrl.h"
43 #include "wx/checkbox.h"
44 #include "wx/combobox.h"
45 #include "wx/valtext.h"
48 #include "wx/textfile.h"
49 #include "wx/spinctrl.h"
50 #include "wx/tokenzr.h"
53 #include "wx/generic/gridsel.h"
55 #if defined(__WXMOTIF__)
56 #define WXUNUSED_MOTIF(identifier) WXUNUSED(identifier)
58 #define WXUNUSED_MOTIF(identifier) identifier
61 #if defined(__WXGTK__)
62 #define WXUNUSED_GTK(identifier) WXUNUSED(identifier)
64 #define WXUNUSED_GTK(identifier) identifier
67 // Required for wxIs... functions
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 WX_DEFINE_EXPORTED_ARRAY(wxGridCellAttr
*, wxArrayAttrs
);
76 struct wxGridCellWithAttr
78 wxGridCellWithAttr(int row
, int col
, wxGridCellAttr
*attr_
)
79 : coords(row
, col
), attr(attr_
)
88 wxGridCellCoords coords
;
92 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellWithAttr
, wxGridCellWithAttrArray
);
94 #include "wx/arrimpl.cpp"
96 WX_DEFINE_OBJARRAY(wxGridCellCoordsArray
)
97 WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray
)
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_CLICK
)
104 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_CLICK
)
105 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_DCLICK
)
106 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_DCLICK
)
107 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_CLICK
)
108 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_CLICK
)
109 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_DCLICK
)
110 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_DCLICK
)
111 DEFINE_EVENT_TYPE(wxEVT_GRID_ROW_SIZE
)
112 DEFINE_EVENT_TYPE(wxEVT_GRID_COL_SIZE
)
113 DEFINE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT
)
114 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGE
)
115 DEFINE_EVENT_TYPE(wxEVT_GRID_SELECT_CELL
)
116 DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN
)
117 DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN
)
119 // ----------------------------------------------------------------------------
121 // ----------------------------------------------------------------------------
123 class WXDLLEXPORT wxGridRowLabelWindow
: public wxWindow
126 wxGridRowLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
127 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
128 const wxPoint
&pos
, const wxSize
&size
);
133 void OnPaint( wxPaintEvent
& event
);
134 void OnMouseEvent( wxMouseEvent
& event
);
135 void OnMouseWheel( wxMouseEvent
& event
);
136 void OnKeyDown( wxKeyEvent
& event
);
137 void OnKeyUp( wxKeyEvent
& );
139 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
140 DECLARE_EVENT_TABLE()
144 class WXDLLEXPORT wxGridColLabelWindow
: public wxWindow
147 wxGridColLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
148 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
149 const wxPoint
&pos
, const wxSize
&size
);
154 void OnPaint( wxPaintEvent
&event
);
155 void OnMouseEvent( wxMouseEvent
& event
);
156 void OnMouseWheel( wxMouseEvent
& event
);
157 void OnKeyDown( wxKeyEvent
& event
);
158 void OnKeyUp( wxKeyEvent
& );
160 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
161 DECLARE_EVENT_TABLE()
165 class WXDLLEXPORT wxGridCornerLabelWindow
: public wxWindow
168 wxGridCornerLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
169 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
170 const wxPoint
&pos
, const wxSize
&size
);
175 void OnMouseEvent( wxMouseEvent
& event
);
176 void OnMouseWheel( wxMouseEvent
& event
);
177 void OnKeyDown( wxKeyEvent
& event
);
178 void OnKeyUp( wxKeyEvent
& );
179 void OnPaint( wxPaintEvent
& event
);
181 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
182 DECLARE_EVENT_TABLE()
185 class WXDLLEXPORT wxGridWindow
: public wxPanel
190 m_owner
= (wxGrid
*)NULL
;
191 m_rowLabelWin
= (wxGridRowLabelWindow
*)NULL
;
192 m_colLabelWin
= (wxGridColLabelWindow
*)NULL
;
195 wxGridWindow( wxGrid
*parent
,
196 wxGridRowLabelWindow
*rowLblWin
,
197 wxGridColLabelWindow
*colLblWin
,
198 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
201 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
205 wxGridRowLabelWindow
*m_rowLabelWin
;
206 wxGridColLabelWindow
*m_colLabelWin
;
208 void OnPaint( wxPaintEvent
&event
);
209 void OnMouseWheel( wxMouseEvent
& event
);
210 void OnMouseEvent( wxMouseEvent
& event
);
211 void OnKeyDown( wxKeyEvent
& );
212 void OnKeyUp( wxKeyEvent
& );
213 void OnEraseBackground( wxEraseEvent
& );
216 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
217 DECLARE_EVENT_TABLE()
222 class wxGridCellEditorEvtHandler
: public wxEvtHandler
225 wxGridCellEditorEvtHandler()
226 : m_grid(0), m_editor(0)
228 wxGridCellEditorEvtHandler(wxGrid
* grid
, wxGridCellEditor
* editor
)
229 : m_grid(grid
), m_editor(editor
)
232 void OnKeyDown(wxKeyEvent
& event
);
233 void OnChar(wxKeyEvent
& event
);
237 wxGridCellEditor
* m_editor
;
238 DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler
)
239 DECLARE_EVENT_TABLE()
243 IMPLEMENT_DYNAMIC_CLASS( wxGridCellEditorEvtHandler
, wxEvtHandler
)
244 BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler
, wxEvtHandler
)
245 EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown
)
246 EVT_CHAR( wxGridCellEditorEvtHandler::OnChar
)
251 // ----------------------------------------------------------------------------
252 // the internal data representation used by wxGridCellAttrProvider
253 // ----------------------------------------------------------------------------
255 // this class stores attributes set for cells
256 class WXDLLEXPORT wxGridCellAttrData
259 void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
260 wxGridCellAttr
*GetAttr(int row
, int col
) const;
261 void UpdateAttrRows( size_t pos
, int numRows
);
262 void UpdateAttrCols( size_t pos
, int numCols
);
265 // searches for the attr for given cell, returns wxNOT_FOUND if not found
266 int FindIndex(int row
, int col
) const;
268 wxGridCellWithAttrArray m_attrs
;
271 // this class stores attributes set for rows or columns
272 class WXDLLEXPORT wxGridRowOrColAttrData
275 // empty ctor to suppress warnings
276 wxGridRowOrColAttrData() { }
277 ~wxGridRowOrColAttrData();
279 void SetAttr(wxGridCellAttr
*attr
, int rowOrCol
);
280 wxGridCellAttr
*GetAttr(int rowOrCol
) const;
281 void UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
);
284 wxArrayInt m_rowsOrCols
;
285 wxArrayAttrs m_attrs
;
288 // NB: this is just a wrapper around 3 objects: one which stores cell
289 // attributes, and 2 others for row/col ones
290 class WXDLLEXPORT wxGridCellAttrProviderData
293 wxGridCellAttrData m_cellAttrs
;
294 wxGridRowOrColAttrData m_rowAttrs
,
299 // ----------------------------------------------------------------------------
300 // data structures used for the data type registry
301 // ----------------------------------------------------------------------------
303 struct wxGridDataTypeInfo
305 wxGridDataTypeInfo(const wxString
& typeName
,
306 wxGridCellRenderer
* renderer
,
307 wxGridCellEditor
* editor
)
308 : m_typeName(typeName
), m_renderer(renderer
), m_editor(editor
)
311 ~wxGridDataTypeInfo()
313 wxSafeDecRef(m_renderer
);
314 wxSafeDecRef(m_editor
);
318 wxGridCellRenderer
* m_renderer
;
319 wxGridCellEditor
* m_editor
;
323 WX_DEFINE_EXPORTED_ARRAY(wxGridDataTypeInfo
*, wxGridDataTypeInfoArray
);
326 class WXDLLEXPORT wxGridTypeRegistry
329 wxGridTypeRegistry() {}
330 ~wxGridTypeRegistry();
332 void RegisterDataType(const wxString
& typeName
,
333 wxGridCellRenderer
* renderer
,
334 wxGridCellEditor
* editor
);
336 // find one of already registered data types
337 int FindRegisteredDataType(const wxString
& typeName
);
339 // try to FindRegisteredDataType(), if this fails and typeName is one of
340 // standard typenames, register it and return its index
341 int FindDataType(const wxString
& typeName
);
343 // try to FindDataType(), if it fails see if it is not one of already
344 // registered data types with some params in which case clone the
345 // registered data type and set params for it
346 int FindOrCloneDataType(const wxString
& typeName
);
348 wxGridCellRenderer
* GetRenderer(int index
);
349 wxGridCellEditor
* GetEditor(int index
);
352 wxGridDataTypeInfoArray m_typeinfo
;
355 // ----------------------------------------------------------------------------
356 // conditional compilation
357 // ----------------------------------------------------------------------------
359 #ifndef WXGRID_DRAW_LINES
360 #define WXGRID_DRAW_LINES 1
363 // ----------------------------------------------------------------------------
365 // ----------------------------------------------------------------------------
367 //#define DEBUG_ATTR_CACHE
368 #ifdef DEBUG_ATTR_CACHE
369 static size_t gs_nAttrCacheHits
= 0;
370 static size_t gs_nAttrCacheMisses
= 0;
371 #endif // DEBUG_ATTR_CACHE
373 // ----------------------------------------------------------------------------
375 // ----------------------------------------------------------------------------
377 wxGridCellCoords
wxGridNoCellCoords( -1, -1 );
378 wxRect
wxGridNoCellRect( -1, -1, -1, -1 );
381 // TODO: this doesn't work at all, grid cells have different sizes and approx
382 // calculations don't work as because of the size mismatch scrollbars
383 // sometimes fail to be shown when they should be or vice versa
385 // The scroll bars may be a little flakey once in a while, but that is
386 // surely much less horrible than having scroll lines of only 1!!!
388 static const size_t GRID_SCROLL_LINE
= 15; // 1;
391 // the size of hash tables used a bit everywhere (the max number of elements
392 // in these hash tables is the number of rows/columns)
393 static const int GRID_HASH_SIZE
= 100;
395 // ============================================================================
397 // ============================================================================
399 // ----------------------------------------------------------------------------
401 // ----------------------------------------------------------------------------
403 wxGridCellEditor::wxGridCellEditor()
409 wxGridCellEditor::~wxGridCellEditor()
414 void wxGridCellEditor::Create(wxWindow
* WXUNUSED(parent
),
415 wxWindowID
WXUNUSED(id
),
416 wxEvtHandler
* evtHandler
)
419 m_control
->PushEventHandler(evtHandler
);
422 void wxGridCellEditor::PaintBackground(const wxRect
& rectCell
,
423 wxGridCellAttr
*attr
)
425 // erase the background because we might not fill the cell
426 wxClientDC
dc(m_control
->GetParent());
427 dc
.SetPen(*wxTRANSPARENT_PEN
);
428 dc
.SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
429 dc
.DrawRectangle(rectCell
);
431 // redraw the control we just painted over
432 m_control
->Refresh();
435 void wxGridCellEditor::Destroy()
439 m_control
->PopEventHandler(TRUE
/* delete it*/);
441 m_control
->Destroy();
446 void wxGridCellEditor::Show(bool show
, wxGridCellAttr
*attr
)
448 wxASSERT_MSG(m_control
,
449 wxT("The wxGridCellEditor must be Created first!"));
450 m_control
->Show(show
);
454 // set the colours/fonts if we have any
457 m_colFgOld
= m_control
->GetForegroundColour();
458 m_control
->SetForegroundColour(attr
->GetTextColour());
460 m_colBgOld
= m_control
->GetBackgroundColour();
461 m_control
->SetBackgroundColour(attr
->GetBackgroundColour());
463 m_fontOld
= m_control
->GetFont();
464 m_control
->SetFont(attr
->GetFont());
466 // can't do anything more in the base class version, the other
467 // attributes may only be used by the derived classes
472 // restore the standard colours fonts
473 if ( m_colFgOld
.Ok() )
475 m_control
->SetForegroundColour(m_colFgOld
);
476 m_colFgOld
= wxNullColour
;
479 if ( m_colBgOld
.Ok() )
481 m_control
->SetBackgroundColour(m_colBgOld
);
482 m_colBgOld
= wxNullColour
;
485 if ( m_fontOld
.Ok() )
487 m_control
->SetFont(m_fontOld
);
488 m_fontOld
= wxNullFont
;
493 void wxGridCellEditor::SetSize(const wxRect
& rect
)
495 wxASSERT_MSG(m_control
,
496 wxT("The wxGridCellEditor must be Created first!"));
497 m_control
->SetSize(rect
, wxSIZE_ALLOW_MINUS_ONE
);
500 void wxGridCellEditor::HandleReturn(wxKeyEvent
& event
)
505 bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent
& event
)
507 // accept the simple key presses, not anything with Ctrl/Alt/Meta
508 return !(event
.ControlDown() || event
.AltDown());
511 void wxGridCellEditor::StartingKey(wxKeyEvent
& event
)
516 void wxGridCellEditor::StartingClick()
520 // ----------------------------------------------------------------------------
521 // wxGridCellTextEditor
522 // ----------------------------------------------------------------------------
524 wxGridCellTextEditor::wxGridCellTextEditor()
529 void wxGridCellTextEditor::Create(wxWindow
* parent
,
531 wxEvtHandler
* evtHandler
)
533 m_control
= new wxTextCtrl(parent
, id
, wxEmptyString
,
534 wxDefaultPosition
, wxDefaultSize
535 #if defined(__WXMSW__)
536 , wxTE_PROCESS_TAB
| wxTE_MULTILINE
|
537 wxTE_NO_VSCROLL
| wxTE_AUTO_SCROLL
541 // TODO: use m_maxChars
543 wxGridCellEditor::Create(parent
, id
, evtHandler
);
546 void wxGridCellTextEditor::PaintBackground(const wxRect
& WXUNUSED(rectCell
),
547 wxGridCellAttr
* WXUNUSED(attr
))
549 // as we fill the entire client area, don't do anything here to minimize
553 void wxGridCellTextEditor::SetSize(const wxRect
& rectOrig
)
555 wxRect
rect(rectOrig
);
557 // Make the edit control large enough to allow for internal
560 // TODO: remove this if the text ctrl sizing is improved esp. for
563 #if defined(__WXGTK__)
572 int extra_x
= ( rect
.x
> 2 )? 2 : 1;
574 // MB: treat MSW separately here otherwise the caret doesn't show
575 // when the editor is in the first row.
576 #if defined(__WXMSW__)
579 int extra_y
= ( rect
.y
> 2 )? 2 : 1;
582 #if defined(__WXMOTIF__)
586 rect
.SetLeft( wxMax(0, rect
.x
- extra_x
) );
587 rect
.SetTop( wxMax(0, rect
.y
- extra_y
) );
588 rect
.SetRight( rect
.GetRight() + 2*extra_x
);
589 rect
.SetBottom( rect
.GetBottom() + 2*extra_y
);
592 wxGridCellEditor::SetSize(rect
);
595 void wxGridCellTextEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
597 wxASSERT_MSG(m_control
,
598 wxT("The wxGridCellEditor must be Created first!"));
600 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
602 DoBeginEdit(m_startValue
);
605 void wxGridCellTextEditor::DoBeginEdit(const wxString
& startValue
)
607 Text()->SetValue(startValue
);
608 Text()->SetInsertionPointEnd();
612 bool wxGridCellTextEditor::EndEdit(int row
, int col
,
615 wxASSERT_MSG(m_control
,
616 wxT("The wxGridCellEditor must be Created first!"));
618 bool changed
= FALSE
;
619 wxString value
= Text()->GetValue();
620 if (value
!= m_startValue
)
624 grid
->GetTable()->SetValue(row
, col
, value
);
626 m_startValue
= wxEmptyString
;
627 Text()->SetValue(m_startValue
);
633 void wxGridCellTextEditor::Reset()
635 wxASSERT_MSG(m_control
,
636 wxT("The wxGridCellEditor must be Created first!"));
638 DoReset(m_startValue
);
641 void wxGridCellTextEditor::DoReset(const wxString
& startValue
)
643 Text()->SetValue(startValue
);
644 Text()->SetInsertionPointEnd();
647 bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent
& event
)
649 if ( wxGridCellEditor::IsAcceptedKey(event
) )
651 int keycode
= event
.GetKeyCode();
665 case WXK_NUMPAD_MULTIPLY
:
669 case WXK_NUMPAD_SUBTRACT
:
671 case WXK_NUMPAD_DECIMAL
:
673 case WXK_NUMPAD_DIVIDE
:
677 // accept 8 bit chars too if isprint() agrees
678 if ( (keycode
< 255) && (isprint(keycode
)) )
686 void wxGridCellTextEditor::StartingKey(wxKeyEvent
& event
)
688 // we don't check for !HasModifiers() because IsAcceptedKey() did it
690 // insert the key in the control
692 int keycode
= event
.GetKeyCode();
705 ch
= _T('0') + keycode
- WXK_NUMPAD0
;
709 case WXK_NUMPAD_MULTIPLY
:
719 case WXK_NUMPAD_SUBTRACT
:
724 case WXK_NUMPAD_DECIMAL
:
729 case WXK_NUMPAD_DIVIDE
:
734 if ( keycode
< 256 && keycode
>= 0 && isprint(keycode
) )
736 // FIXME this is not going to work for non letters...
737 if ( !event
.ShiftDown() )
739 keycode
= tolower(keycode
);
742 ch
= (wxChar
)keycode
;
752 Text()->AppendText(ch
);
760 void wxGridCellTextEditor::HandleReturn( wxKeyEvent
&
761 WXUNUSED_GTK(WXUNUSED_MOTIF(event
)) )
763 #if defined(__WXMOTIF__) || defined(__WXGTK__)
764 // wxMotif needs a little extra help...
765 size_t pos
= (size_t)( Text()->GetInsertionPoint() );
766 wxString
s( Text()->GetValue() );
767 s
= s
.Left(pos
) + "\n" + s
.Mid(pos
);
769 Text()->SetInsertionPoint( pos
);
771 // the other ports can handle a Return key press
777 void wxGridCellTextEditor::SetParameters(const wxString
& params
)
787 if ( !params
.ToLong(&tmp
) )
789 wxLogDebug(_T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params
.c_str());
793 m_maxChars
= (size_t)tmp
;
798 // ----------------------------------------------------------------------------
799 // wxGridCellNumberEditor
800 // ----------------------------------------------------------------------------
802 wxGridCellNumberEditor::wxGridCellNumberEditor(int min
, int max
)
808 void wxGridCellNumberEditor::Create(wxWindow
* parent
,
810 wxEvtHandler
* evtHandler
)
814 // create a spin ctrl
815 m_control
= new wxSpinCtrl(parent
, -1, wxEmptyString
,
816 wxDefaultPosition
, wxDefaultSize
,
820 wxGridCellEditor::Create(parent
, id
, evtHandler
);
824 // just a text control
825 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
828 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
829 #endif // wxUSE_VALIDATORS
833 void wxGridCellNumberEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
835 // first get the value
836 wxGridTableBase
*table
= grid
->GetTable();
837 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
839 m_valueOld
= table
->GetValueAsLong(row
, col
);
843 wxString sValue
= table
->GetValue(row
, col
);
844 if (! sValue
.ToLong(&m_valueOld
))
846 wxFAIL_MSG( _T("this cell doesn't have numeric value") );
853 Spin()->SetValue((int)m_valueOld
);
858 DoBeginEdit(GetString());
862 bool wxGridCellNumberEditor::EndEdit(int row
, int col
,
870 value
= Spin()->GetValue();
871 changed
= value
!= m_valueOld
;
875 changed
= Text()->GetValue().ToLong(&value
) && (value
!= m_valueOld
);
880 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_NUMBER
))
881 grid
->GetTable()->SetValueAsLong(row
, col
, value
);
883 grid
->GetTable()->SetValue(row
, col
, wxString::Format(wxT("%ld"), value
));
889 void wxGridCellNumberEditor::Reset()
893 Spin()->SetValue((int)m_valueOld
);
897 DoReset(GetString());
901 bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent
& event
)
903 if ( wxGridCellEditor::IsAcceptedKey(event
) )
905 int keycode
= event
.GetKeyCode();
921 case WXK_NUMPAD_SUBTRACT
:
927 if ( (keycode
< 128) && isdigit(keycode
) )
935 void wxGridCellNumberEditor::StartingKey(wxKeyEvent
& event
)
939 int keycode
= (int) event
.KeyCode();
940 if ( isdigit(keycode
) || keycode
== '+' || keycode
== '-' )
942 wxGridCellTextEditor::StartingKey(event
);
952 void wxGridCellNumberEditor::SetParameters(const wxString
& params
)
963 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
967 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
971 // skip the error message below
976 wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string '%s' ignored"), params
.c_str());
980 // ----------------------------------------------------------------------------
981 // wxGridCellFloatEditor
982 // ----------------------------------------------------------------------------
984 wxGridCellFloatEditor::wxGridCellFloatEditor(int width
, int precision
)
987 m_precision
= precision
;
990 void wxGridCellFloatEditor::Create(wxWindow
* parent
,
992 wxEvtHandler
* evtHandler
)
994 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
997 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
998 #endif // wxUSE_VALIDATORS
1001 void wxGridCellFloatEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1003 // first get the value
1004 wxGridTableBase
*table
= grid
->GetTable();
1005 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
1007 m_valueOld
= table
->GetValueAsDouble(row
, col
);
1011 wxString sValue
= table
->GetValue(row
, col
);
1012 if (! sValue
.ToDouble(&m_valueOld
))
1014 wxFAIL_MSG( _T("this cell doesn't have float value") );
1019 DoBeginEdit(GetString());
1022 bool wxGridCellFloatEditor::EndEdit(int row
, int col
,
1026 if ( Text()->GetValue().ToDouble(&value
) && (value
!= m_valueOld
) )
1028 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_FLOAT
))
1029 grid
->GetTable()->SetValueAsDouble(row
, col
, value
);
1031 grid
->GetTable()->SetValue(row
, col
, wxString::Format(wxT("%f"), value
));
1041 void wxGridCellFloatEditor::Reset()
1043 DoReset(GetString());
1046 void wxGridCellFloatEditor::StartingKey(wxKeyEvent
& event
)
1048 int keycode
= (int)event
.KeyCode();
1049 if ( isdigit(keycode
) ||
1050 keycode
== '+' || keycode
== '-' || keycode
== '.' )
1052 wxGridCellTextEditor::StartingKey(event
);
1054 // skip Skip() below
1061 void wxGridCellFloatEditor::SetParameters(const wxString
& params
)
1072 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
1076 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
1078 m_precision
= (int)tmp
;
1080 // skip the error message below
1085 wxLogDebug(_T("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params
.c_str());
1089 wxString
wxGridCellFloatEditor::GetString() const
1092 if ( m_width
== -1 )
1094 // default width/precision
1097 else if ( m_precision
== -1 )
1099 // default precision
1100 fmt
.Printf(_T("%%%d.g"), m_width
);
1104 fmt
.Printf(_T("%%%d.%dg"), m_width
, m_precision
);
1107 return wxString::Format(fmt
, m_valueOld
);
1110 bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent
& event
)
1112 if ( wxGridCellEditor::IsAcceptedKey(event
) )
1114 int keycode
= event
.GetKeyCode();
1128 case WXK_NUMPAD_ADD
:
1130 case WXK_NUMPAD_SUBTRACT
:
1132 case WXK_NUMPAD_DECIMAL
:
1136 // additionally accept 'e' as in '1e+6'
1137 if ( (keycode
< 128) &&
1138 (isdigit(keycode
) || tolower(keycode
) == 'e') )
1146 // ----------------------------------------------------------------------------
1147 // wxGridCellBoolEditor
1148 // ----------------------------------------------------------------------------
1150 void wxGridCellBoolEditor::Create(wxWindow
* parent
,
1152 wxEvtHandler
* evtHandler
)
1154 m_control
= new wxCheckBox(parent
, id
, wxEmptyString
,
1155 wxDefaultPosition
, wxDefaultSize
,
1158 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1161 void wxGridCellBoolEditor::SetSize(const wxRect
& r
)
1163 bool resize
= FALSE
;
1164 wxSize size
= m_control
->GetSize();
1165 wxCoord minSize
= wxMin(r
.width
, r
.height
);
1167 // check if the checkbox is not too big/small for this cell
1168 wxSize sizeBest
= m_control
->GetBestSize();
1169 if ( !(size
== sizeBest
) )
1171 // reset to default size if it had been made smaller
1177 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
1179 // leave 1 pixel margin
1180 size
.x
= size
.y
= minSize
- 2;
1187 m_control
->SetSize(size
);
1190 // position it in the centre of the rectangle (TODO: support alignment?)
1192 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1193 // the checkbox without label still has some space to the right in wxGTK,
1194 // so shift it to the right
1196 #elif defined(__WXMSW__)
1197 // here too, but in other way
1202 m_control
->Move(r
.x
+ r
.width
/2 - size
.x
/2, r
.y
+ r
.height
/2 - size
.y
/2);
1205 void wxGridCellBoolEditor::Show(bool show
, wxGridCellAttr
*attr
)
1207 m_control
->Show(show
);
1211 wxColour colBg
= attr
? attr
->GetBackgroundColour() : *wxLIGHT_GREY
;
1212 CBox()->SetBackgroundColour(colBg
);
1216 void wxGridCellBoolEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1218 wxASSERT_MSG(m_control
,
1219 wxT("The wxGridCellEditor must be Created first!"));
1221 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
1222 m_startValue
= grid
->GetTable()->GetValueAsBool(row
, col
);
1225 wxString
cellval( grid
->GetTable()->GetValue(row
, col
) );
1226 m_startValue
= !( !cellval
|| (cellval
== "0") );
1228 CBox()->SetValue(m_startValue
);
1232 bool wxGridCellBoolEditor::EndEdit(int row
, int col
,
1235 wxASSERT_MSG(m_control
,
1236 wxT("The wxGridCellEditor must be Created first!"));
1238 bool changed
= FALSE
;
1239 bool value
= CBox()->GetValue();
1240 if ( value
!= m_startValue
)
1245 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
1246 grid
->GetTable()->SetValueAsBool(row
, col
, value
);
1248 grid
->GetTable()->SetValue(row
, col
, value
? _T("1") : wxEmptyString
);
1254 void wxGridCellBoolEditor::Reset()
1256 wxASSERT_MSG(m_control
,
1257 wxT("The wxGridCellEditor must be Created first!"));
1259 CBox()->SetValue(m_startValue
);
1262 void wxGridCellBoolEditor::StartingClick()
1264 CBox()->SetValue(!CBox()->GetValue());
1267 bool wxGridCellBoolEditor::IsAcceptedKey(wxKeyEvent
& event
)
1269 if ( wxGridCellEditor::IsAcceptedKey(event
) )
1271 int keycode
= event
.GetKeyCode();
1275 case WXK_NUMPAD_MULTIPLY
:
1277 case WXK_NUMPAD_ADD
:
1279 case WXK_NUMPAD_SUBTRACT
:
1290 // ----------------------------------------------------------------------------
1291 // wxGridCellChoiceEditor
1292 // ----------------------------------------------------------------------------
1294 wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count
,
1295 const wxString choices
[],
1297 : m_allowOthers(allowOthers
)
1301 m_choices
.Alloc(count
);
1302 for ( size_t n
= 0; n
< count
; n
++ )
1304 m_choices
.Add(choices
[n
]);
1309 wxGridCellEditor
*wxGridCellChoiceEditor::Clone() const
1311 wxGridCellChoiceEditor
*editor
= new wxGridCellChoiceEditor
;
1312 editor
->m_allowOthers
= m_allowOthers
;
1313 editor
->m_choices
= m_choices
;
1318 void wxGridCellChoiceEditor::Create(wxWindow
* parent
,
1320 wxEvtHandler
* evtHandler
)
1322 size_t count
= m_choices
.GetCount();
1323 wxString
*choices
= new wxString
[count
];
1324 for ( size_t n
= 0; n
< count
; n
++ )
1326 choices
[n
] = m_choices
[n
];
1329 m_control
= new wxComboBox(parent
, id
, wxEmptyString
,
1330 wxDefaultPosition
, wxDefaultSize
,
1332 m_allowOthers
? 0 : wxCB_READONLY
);
1336 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1339 void wxGridCellChoiceEditor::PaintBackground(const wxRect
& rectCell
,
1340 wxGridCellAttr
* attr
)
1342 // as we fill the entire client area, don't do anything here to minimize
1345 // TODO: It doesn't actually fill the client area since the height of a
1346 // combo always defaults to the standard... Until someone has time to
1347 // figure out the right rectangle to paint, just do it the normal way...
1348 wxGridCellEditor::PaintBackground(rectCell
, attr
);
1351 void wxGridCellChoiceEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1353 wxASSERT_MSG(m_control
,
1354 wxT("The wxGridCellEditor must be Created first!"));
1356 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
1358 Combo()->SetValue(m_startValue
);
1359 size_t count
= m_choices
.GetCount();
1360 for (size_t i
=0; i
<count
; i
++)
1362 if (m_startValue
== m_choices
[i
])
1364 Combo()->SetSelection(i
);
1368 Combo()->SetInsertionPointEnd();
1369 Combo()->SetFocus();
1372 bool wxGridCellChoiceEditor::EndEdit(int row
, int col
,
1375 wxString value
= Combo()->GetValue();
1376 bool changed
= value
!= m_startValue
;
1379 grid
->GetTable()->SetValue(row
, col
, value
);
1381 m_startValue
= wxEmptyString
;
1382 Combo()->SetValue(m_startValue
);
1387 void wxGridCellChoiceEditor::Reset()
1389 Combo()->SetValue(m_startValue
);
1390 Combo()->SetInsertionPointEnd();
1393 void wxGridCellChoiceEditor::SetParameters(const wxString
& params
)
1403 wxStringTokenizer
tk(params
, _T(','));
1404 while ( tk
.HasMoreTokens() )
1406 m_choices
.Add(tk
.GetNextToken());
1410 // ----------------------------------------------------------------------------
1411 // wxGridCellEditorEvtHandler
1412 // ----------------------------------------------------------------------------
1414 void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent
& event
)
1416 switch ( event
.KeyCode() )
1420 m_grid
->DisableCellEditControl();
1424 m_grid
->GetEventHandler()->ProcessEvent( event
);
1428 case WXK_NUMPAD_ENTER
:
1429 if (!m_grid
->GetEventHandler()->ProcessEvent(event
))
1430 m_editor
->HandleReturn(event
);
1439 void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent
& event
)
1441 switch ( event
.KeyCode() )
1446 case WXK_NUMPAD_ENTER
:
1454 // ----------------------------------------------------------------------------
1455 // wxGridCellWorker is an (almost) empty common base class for
1456 // wxGridCellRenderer and wxGridCellEditor managing ref counting
1457 // ----------------------------------------------------------------------------
1459 void wxGridCellWorker::SetParameters(const wxString
& WXUNUSED(params
))
1464 wxGridCellWorker::~wxGridCellWorker()
1468 // ============================================================================
1470 // ============================================================================
1472 // ----------------------------------------------------------------------------
1473 // wxGridCellRenderer
1474 // ----------------------------------------------------------------------------
1476 void wxGridCellRenderer::Draw(wxGrid
& grid
,
1477 wxGridCellAttr
& attr
,
1480 int WXUNUSED(row
), int WXUNUSED(col
),
1483 dc
.SetBackgroundMode( wxSOLID
);
1487 dc
.SetBrush( wxBrush(grid
.GetSelectionBackground(), wxSOLID
) );
1491 dc
.SetBrush( wxBrush(attr
.GetBackgroundColour(), wxSOLID
) );
1494 dc
.SetPen( *wxTRANSPARENT_PEN
);
1495 dc
.DrawRectangle(rect
);
1498 // ----------------------------------------------------------------------------
1499 // wxGridCellStringRenderer
1500 // ----------------------------------------------------------------------------
1502 void wxGridCellStringRenderer::SetTextColoursAndFont(wxGrid
& grid
,
1503 wxGridCellAttr
& attr
,
1507 dc
.SetBackgroundMode( wxTRANSPARENT
);
1509 // TODO some special colours for attr.IsReadOnly() case?
1513 dc
.SetTextBackground( grid
.GetSelectionBackground() );
1514 dc
.SetTextForeground( grid
.GetSelectionForeground() );
1518 dc
.SetTextBackground( attr
.GetBackgroundColour() );
1519 dc
.SetTextForeground( attr
.GetTextColour() );
1522 dc
.SetFont( attr
.GetFont() );
1525 wxSize
wxGridCellStringRenderer::DoGetBestSize(wxGridCellAttr
& attr
,
1527 const wxString
& text
)
1529 wxCoord x
= 0, y
= 0, max_x
= 0;
1530 dc
.SetFont(attr
.GetFont());
1531 wxStringTokenizer
tk(text
, _T('\n'));
1532 while ( tk
.HasMoreTokens() )
1534 dc
.GetTextExtent(tk
.GetNextToken(), &x
, &y
);
1535 max_x
= wxMax(max_x
, x
);
1538 y
*= 1 + text
.Freq(wxT('\n')); // multiply by the number of lines.
1540 return wxSize(max_x
, y
);
1543 wxSize
wxGridCellStringRenderer::GetBestSize(wxGrid
& grid
,
1544 wxGridCellAttr
& attr
,
1548 return DoGetBestSize(attr
, dc
, grid
.GetCellValue(row
, col
));
1551 void wxGridCellStringRenderer::Draw(wxGrid
& grid
,
1552 wxGridCellAttr
& attr
,
1554 const wxRect
& rectCell
,
1558 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1560 // now we only have to draw the text
1561 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1564 attr
.GetAlignment(&hAlign
, &vAlign
);
1566 wxRect rect
= rectCell
;
1569 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
1570 rect
, hAlign
, vAlign
);
1573 // ----------------------------------------------------------------------------
1574 // wxGridCellNumberRenderer
1575 // ----------------------------------------------------------------------------
1577 wxString
wxGridCellNumberRenderer::GetString(wxGrid
& grid
, int row
, int col
)
1579 wxGridTableBase
*table
= grid
.GetTable();
1581 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
1583 text
.Printf(_T("%ld"), table
->GetValueAsLong(row
, col
));
1587 text
= table
->GetValue(row
, col
);
1593 void wxGridCellNumberRenderer::Draw(wxGrid
& grid
,
1594 wxGridCellAttr
& attr
,
1596 const wxRect
& rectCell
,
1600 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1602 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1604 // draw the text right aligned by default
1606 attr
.GetAlignment(&hAlign
, &vAlign
);
1607 hAlign
= wxALIGN_RIGHT
;
1609 wxRect rect
= rectCell
;
1612 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1615 wxSize
wxGridCellNumberRenderer::GetBestSize(wxGrid
& grid
,
1616 wxGridCellAttr
& attr
,
1620 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1623 // ----------------------------------------------------------------------------
1624 // wxGridCellFloatRenderer
1625 // ----------------------------------------------------------------------------
1627 wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width
, int precision
)
1630 SetPrecision(precision
);
1633 wxGridCellRenderer
*wxGridCellFloatRenderer::Clone() const
1635 wxGridCellFloatRenderer
*renderer
= new wxGridCellFloatRenderer
;
1636 renderer
->m_width
= m_width
;
1637 renderer
->m_precision
= m_precision
;
1638 renderer
->m_format
= m_format
;
1643 wxString
wxGridCellFloatRenderer::GetString(wxGrid
& grid
, int row
, int col
)
1645 wxGridTableBase
*table
= grid
.GetTable();
1650 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
1652 val
= table
->GetValueAsDouble(row
, col
);
1657 text
= table
->GetValue(row
, col
);
1658 hasDouble
= text
.ToDouble(&val
);
1665 if ( m_width
== -1 )
1667 // default width/precision
1668 m_format
= _T("%f");
1670 else if ( m_precision
== -1 )
1672 // default precision
1673 m_format
.Printf(_T("%%%d.f"), m_width
);
1677 m_format
.Printf(_T("%%%d.%df"), m_width
, m_precision
);
1681 text
.Printf(m_format
, val
);
1683 //else: text already contains the string
1688 void wxGridCellFloatRenderer::Draw(wxGrid
& grid
,
1689 wxGridCellAttr
& attr
,
1691 const wxRect
& rectCell
,
1695 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1697 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1699 // draw the text right aligned by default
1701 attr
.GetAlignment(&hAlign
, &vAlign
);
1702 hAlign
= wxALIGN_RIGHT
;
1704 wxRect rect
= rectCell
;
1707 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1710 wxSize
wxGridCellFloatRenderer::GetBestSize(wxGrid
& grid
,
1711 wxGridCellAttr
& attr
,
1715 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1718 void wxGridCellFloatRenderer::SetParameters(const wxString
& params
)
1724 // reset to defaults
1730 wxString tmp
= params
.BeforeFirst(_T(','));
1734 if ( !tmp
.ToLong(&width
) )
1740 SetWidth((int)width
);
1742 tmp
= params
.AfterFirst(_T(','));
1746 if ( !tmp
.ToLong(&precision
) )
1752 SetPrecision((int)precision
);
1760 wxLogDebug(_T("Invalid wxGridCellFloatRenderer parameter string '%s ignored"), params
.c_str());
1765 // ----------------------------------------------------------------------------
1766 // wxGridCellBoolRenderer
1767 // ----------------------------------------------------------------------------
1769 wxSize
wxGridCellBoolRenderer::ms_sizeCheckMark
;
1771 // FIXME these checkbox size calculations are really ugly...
1773 // between checkmark and box
1774 static const wxCoord wxGRID_CHECKMARK_MARGIN
= 2;
1776 wxSize
wxGridCellBoolRenderer::GetBestSize(wxGrid
& grid
,
1777 wxGridCellAttr
& WXUNUSED(attr
),
1782 // compute it only once (no locks for MT safeness in GUI thread...)
1783 if ( !ms_sizeCheckMark
.x
)
1785 // get checkbox size
1786 wxCoord checkSize
= 0;
1787 wxCheckBox
*checkbox
= new wxCheckBox(&grid
, -1, wxEmptyString
);
1788 wxSize size
= checkbox
->GetBestSize();
1789 checkSize
= size
.y
+ 2*wxGRID_CHECKMARK_MARGIN
;
1791 // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result
1792 #if defined(__WXGTK__) || defined(__WXMOTIF__)
1793 checkSize
-= size
.y
/ 2;
1798 ms_sizeCheckMark
.x
= ms_sizeCheckMark
.y
= checkSize
;
1801 return ms_sizeCheckMark
;
1804 void wxGridCellBoolRenderer::Draw(wxGrid
& grid
,
1805 wxGridCellAttr
& attr
,
1811 wxGridCellRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
1813 // draw a check mark in the centre (ignoring alignment - TODO)
1814 wxSize size
= GetBestSize(grid
, attr
, dc
, row
, col
);
1816 // don't draw outside the cell
1817 wxCoord minSize
= wxMin(rect
.width
, rect
.height
);
1818 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
1820 // and even leave (at least) 1 pixel margin
1821 size
.x
= size
.y
= minSize
- 2;
1824 // draw a border around checkmark
1826 rectBorder
.x
= rect
.x
+ rect
.width
/2 - size
.x
/2;
1827 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
1828 rectBorder
.width
= size
.x
;
1829 rectBorder
.height
= size
.y
;
1832 if ( grid
.GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
) )
1833 value
= grid
.GetTable()->GetValueAsBool(row
, col
);
1836 wxString
cellval( grid
.GetTable()->GetValue(row
, col
) );
1837 value
= !( !cellval
|| (cellval
== "0") );
1842 wxRect rectMark
= rectBorder
;
1844 // MSW DrawCheckMark() is weird (and should probably be changed...)
1845 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
/2);
1849 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
);
1852 dc
.SetTextForeground(attr
.GetTextColour());
1853 dc
.DrawCheckMark(rectMark
);
1856 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1857 dc
.SetPen(wxPen(attr
.GetTextColour(), 1, wxSOLID
));
1858 dc
.DrawRectangle(rectBorder
);
1861 // ----------------------------------------------------------------------------
1863 // ----------------------------------------------------------------------------
1865 wxGridCellAttr
*wxGridCellAttr::Clone() const
1867 wxGridCellAttr
*attr
= new wxGridCellAttr
;
1868 if ( HasTextColour() )
1869 attr
->SetTextColour(GetTextColour());
1870 if ( HasBackgroundColour() )
1871 attr
->SetBackgroundColour(GetBackgroundColour());
1873 attr
->SetFont(GetFont());
1874 if ( HasAlignment() )
1875 attr
->SetAlignment(m_hAlign
, m_vAlign
);
1879 attr
->SetRenderer(m_renderer
);
1880 m_renderer
->IncRef();
1884 attr
->SetEditor(m_editor
);
1889 attr
->SetReadOnly();
1891 attr
->SetDefAttr(m_defGridAttr
);
1896 const wxColour
& wxGridCellAttr::GetTextColour() const
1898 if (HasTextColour())
1902 else if (m_defGridAttr
!= this)
1904 return m_defGridAttr
->GetTextColour();
1908 wxFAIL_MSG(wxT("Missing default cell attribute"));
1909 return wxNullColour
;
1914 const wxColour
& wxGridCellAttr::GetBackgroundColour() const
1916 if (HasBackgroundColour())
1918 else if (m_defGridAttr
!= this)
1919 return m_defGridAttr
->GetBackgroundColour();
1922 wxFAIL_MSG(wxT("Missing default cell attribute"));
1923 return wxNullColour
;
1928 const wxFont
& wxGridCellAttr::GetFont() const
1932 else if (m_defGridAttr
!= this)
1933 return m_defGridAttr
->GetFont();
1936 wxFAIL_MSG(wxT("Missing default cell attribute"));
1942 void wxGridCellAttr::GetAlignment(int *hAlign
, int *vAlign
) const
1946 if ( hAlign
) *hAlign
= m_hAlign
;
1947 if ( vAlign
) *vAlign
= m_vAlign
;
1949 else if (m_defGridAttr
!= this)
1950 m_defGridAttr
->GetAlignment(hAlign
, vAlign
);
1953 wxFAIL_MSG(wxT("Missing default cell attribute"));
1958 // GetRenderer and GetEditor use a slightly different decision path about
1959 // which attribute to use. If a non-default attr object has one then it is
1960 // used, otherwise the default editor or renderer is fetched from the grid and
1961 // used. It should be the default for the data type of the cell. If it is
1962 // NULL (because the table has a type that the grid does not have in its
1963 // registry,) then the grid's default editor or renderer is used.
1965 wxGridCellRenderer
* wxGridCellAttr::GetRenderer(wxGrid
* grid
, int row
, int col
) const
1967 wxGridCellRenderer
* renderer
= NULL
;
1969 if ( m_defGridAttr
!= this || grid
== NULL
)
1971 renderer
= m_renderer
; // use local attribute
1976 if ( !renderer
&& grid
) // get renderer for the data type
1978 // GetDefaultRendererForCell() will do IncRef() for us
1979 renderer
= grid
->GetDefaultRendererForCell(row
, col
);
1984 // if we still don't have one then use the grid default
1985 // (no need for IncRef() here neither)
1986 renderer
= m_defGridAttr
->GetRenderer(NULL
,0,0);
1991 wxFAIL_MSG(wxT("Missing default cell attribute"));
1997 wxGridCellEditor
* wxGridCellAttr::GetEditor(wxGrid
* grid
, int row
, int col
) const
1999 wxGridCellEditor
* editor
= NULL
;
2001 if ( m_defGridAttr
!= this || grid
== NULL
)
2003 editor
= m_editor
; // use local attribute
2008 if ( !editor
&& grid
) // get renderer for the data type
2009 editor
= grid
->GetDefaultEditorForCell(row
, col
);
2012 // if we still don't have one then use the grid default
2013 editor
= m_defGridAttr
->GetEditor(NULL
,0,0);
2017 wxFAIL_MSG(wxT("Missing default cell attribute"));
2023 // ----------------------------------------------------------------------------
2024 // wxGridCellAttrData
2025 // ----------------------------------------------------------------------------
2027 void wxGridCellAttrData::SetAttr(wxGridCellAttr
*attr
, int row
, int col
)
2029 int n
= FindIndex(row
, col
);
2030 if ( n
== wxNOT_FOUND
)
2032 // add the attribute
2033 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
2039 // change the attribute
2040 m_attrs
[(size_t)n
].attr
= attr
;
2044 // remove this attribute
2045 m_attrs
.RemoveAt((size_t)n
);
2050 wxGridCellAttr
*wxGridCellAttrData::GetAttr(int row
, int col
) const
2052 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2054 int n
= FindIndex(row
, col
);
2055 if ( n
!= wxNOT_FOUND
)
2057 attr
= m_attrs
[(size_t)n
].attr
;
2064 void wxGridCellAttrData::UpdateAttrRows( size_t pos
, int numRows
)
2066 size_t count
= m_attrs
.GetCount();
2067 for ( size_t n
= 0; n
< count
; n
++ )
2069 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2070 wxCoord row
= coords
.GetRow();
2071 if ((size_t)row
>= pos
)
2075 // If rows inserted, include row counter where necessary
2076 coords
.SetRow(row
+ numRows
);
2078 else if (numRows
< 0)
2080 // If rows deleted ...
2081 if ((size_t)row
>= pos
- numRows
)
2083 // ...either decrement row counter (if row still exists)...
2084 coords
.SetRow(row
+ numRows
);
2088 // ...or remove the attribute
2089 m_attrs
.RemoveAt((size_t)n
);
2097 void wxGridCellAttrData::UpdateAttrCols( size_t pos
, int numCols
)
2099 size_t count
= m_attrs
.GetCount();
2100 for ( size_t n
= 0; n
< count
; n
++ )
2102 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2103 wxCoord col
= coords
.GetCol();
2104 if ( (size_t)col
>= pos
)
2108 // If rows inserted, include row counter where necessary
2109 coords
.SetCol(col
+ numCols
);
2111 else if (numCols
< 0)
2113 // If rows deleted ...
2114 if ((size_t)col
>= pos
- numCols
)
2116 // ...either decrement row counter (if row still exists)...
2117 coords
.SetCol(col
+ numCols
);
2121 // ...or remove the attribute
2122 m_attrs
.RemoveAt((size_t)n
);
2130 int wxGridCellAttrData::FindIndex(int row
, int col
) const
2132 size_t count
= m_attrs
.GetCount();
2133 for ( size_t n
= 0; n
< count
; n
++ )
2135 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2136 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
2145 // ----------------------------------------------------------------------------
2146 // wxGridRowOrColAttrData
2147 // ----------------------------------------------------------------------------
2149 wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
2151 size_t count
= m_attrs
.Count();
2152 for ( size_t n
= 0; n
< count
; n
++ )
2154 m_attrs
[n
]->DecRef();
2158 wxGridCellAttr
*wxGridRowOrColAttrData::GetAttr(int rowOrCol
) const
2160 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2162 int n
= m_rowsOrCols
.Index(rowOrCol
);
2163 if ( n
!= wxNOT_FOUND
)
2165 attr
= m_attrs
[(size_t)n
];
2172 void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr
*attr
, int rowOrCol
)
2174 int i
= m_rowsOrCols
.Index(rowOrCol
);
2175 if ( i
== wxNOT_FOUND
)
2177 // add the attribute
2178 m_rowsOrCols
.Add(rowOrCol
);
2183 size_t n
= (size_t)i
;
2186 // change the attribute
2187 m_attrs
[n
]->DecRef();
2192 // remove this attribute
2193 m_attrs
[n
]->DecRef();
2194 m_rowsOrCols
.RemoveAt(n
);
2195 m_attrs
.RemoveAt(n
);
2200 void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
)
2202 size_t count
= m_attrs
.GetCount();
2203 for ( size_t n
= 0; n
< count
; n
++ )
2205 int & rowOrCol
= m_rowsOrCols
[n
];
2206 if ( (size_t)rowOrCol
>= pos
)
2208 if ( numRowsOrCols
> 0 )
2210 // If rows inserted, include row counter where necessary
2211 rowOrCol
+= numRowsOrCols
;
2213 else if ( numRowsOrCols
< 0)
2215 // If rows deleted, either decrement row counter (if row still exists)
2216 if ((size_t)rowOrCol
>= pos
- numRowsOrCols
)
2217 rowOrCol
+= numRowsOrCols
;
2220 m_rowsOrCols
.RemoveAt((size_t)n
);
2221 m_attrs
.RemoveAt((size_t)n
);
2229 // ----------------------------------------------------------------------------
2230 // wxGridCellAttrProvider
2231 // ----------------------------------------------------------------------------
2233 wxGridCellAttrProvider::wxGridCellAttrProvider()
2235 m_data
= (wxGridCellAttrProviderData
*)NULL
;
2238 wxGridCellAttrProvider::~wxGridCellAttrProvider()
2243 void wxGridCellAttrProvider::InitData()
2245 m_data
= new wxGridCellAttrProviderData
;
2248 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
) const
2250 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2253 // first look for the attribute of this specific cell
2254 attr
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
2258 // then look for the col attr (col attributes are more common than
2259 // the row ones, hence they have priority)
2260 attr
= m_data
->m_colAttrs
.GetAttr(col
);
2265 // finally try the row attributes
2266 attr
= m_data
->m_rowAttrs
.GetAttr(row
);
2273 void wxGridCellAttrProvider::SetAttr(wxGridCellAttr
*attr
,
2279 m_data
->m_cellAttrs
.SetAttr(attr
, row
, col
);
2282 void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr
*attr
, int row
)
2287 m_data
->m_rowAttrs
.SetAttr(attr
, row
);
2290 void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr
*attr
, int col
)
2295 m_data
->m_colAttrs
.SetAttr(attr
, col
);
2298 void wxGridCellAttrProvider::UpdateAttrRows( size_t pos
, int numRows
)
2302 m_data
->m_cellAttrs
.UpdateAttrRows( pos
, numRows
);
2304 m_data
->m_rowAttrs
.UpdateAttrRowsOrCols( pos
, numRows
);
2308 void wxGridCellAttrProvider::UpdateAttrCols( size_t pos
, int numCols
)
2312 m_data
->m_cellAttrs
.UpdateAttrCols( pos
, numCols
);
2314 m_data
->m_colAttrs
.UpdateAttrRowsOrCols( pos
, numCols
);
2318 // ----------------------------------------------------------------------------
2319 // wxGridTypeRegistry
2320 // ----------------------------------------------------------------------------
2322 wxGridTypeRegistry::~wxGridTypeRegistry()
2324 size_t count
= m_typeinfo
.Count();
2325 for ( size_t i
= 0; i
< count
; i
++ )
2326 delete m_typeinfo
[i
];
2330 void wxGridTypeRegistry::RegisterDataType(const wxString
& typeName
,
2331 wxGridCellRenderer
* renderer
,
2332 wxGridCellEditor
* editor
)
2334 wxGridDataTypeInfo
* info
= new wxGridDataTypeInfo(typeName
, renderer
, editor
);
2336 // is it already registered?
2337 int loc
= FindRegisteredDataType(typeName
);
2338 if ( loc
!= wxNOT_FOUND
)
2340 delete m_typeinfo
[loc
];
2341 m_typeinfo
[loc
] = info
;
2345 m_typeinfo
.Add(info
);
2349 int wxGridTypeRegistry::FindRegisteredDataType(const wxString
& typeName
)
2351 size_t count
= m_typeinfo
.GetCount();
2352 for ( size_t i
= 0; i
< count
; i
++ )
2354 if ( typeName
== m_typeinfo
[i
]->m_typeName
)
2363 int wxGridTypeRegistry::FindDataType(const wxString
& typeName
)
2365 int index
= FindRegisteredDataType(typeName
);
2366 if ( index
== wxNOT_FOUND
)
2368 // check whether this is one of the standard ones, in which case
2369 // register it "on the fly"
2370 if ( typeName
== wxGRID_VALUE_STRING
)
2372 RegisterDataType(wxGRID_VALUE_STRING
,
2373 new wxGridCellStringRenderer
,
2374 new wxGridCellTextEditor
);
2376 else if ( typeName
== wxGRID_VALUE_BOOL
)
2378 RegisterDataType(wxGRID_VALUE_BOOL
,
2379 new wxGridCellBoolRenderer
,
2380 new wxGridCellBoolEditor
);
2382 else if ( typeName
== wxGRID_VALUE_NUMBER
)
2384 RegisterDataType(wxGRID_VALUE_NUMBER
,
2385 new wxGridCellNumberRenderer
,
2386 new wxGridCellNumberEditor
);
2388 else if ( typeName
== wxGRID_VALUE_FLOAT
)
2390 RegisterDataType(wxGRID_VALUE_FLOAT
,
2391 new wxGridCellFloatRenderer
,
2392 new wxGridCellFloatEditor
);
2394 else if ( typeName
== wxGRID_VALUE_CHOICE
)
2396 RegisterDataType(wxGRID_VALUE_CHOICE
,
2397 new wxGridCellStringRenderer
,
2398 new wxGridCellChoiceEditor
);
2405 // we get here only if just added the entry for this type, so return
2407 index
= m_typeinfo
.GetCount() - 1;
2413 int wxGridTypeRegistry::FindOrCloneDataType(const wxString
& typeName
)
2415 int index
= FindDataType(typeName
);
2416 if ( index
== wxNOT_FOUND
)
2418 // the first part of the typename is the "real" type, anything after ':'
2419 // are the parameters for the renderer
2420 index
= FindDataType(typeName
.BeforeFirst(_T(':')));
2421 if ( index
== wxNOT_FOUND
)
2426 wxGridCellRenderer
*renderer
= GetRenderer(index
);
2427 wxGridCellRenderer
*rendererOld
= renderer
;
2428 renderer
= renderer
->Clone();
2429 rendererOld
->DecRef();
2431 wxGridCellEditor
*editor
= GetEditor(index
);
2432 wxGridCellEditor
*editorOld
= editor
;
2433 editor
= editor
->Clone();
2434 editorOld
->DecRef();
2436 // do it even if there are no parameters to reset them to defaults
2437 wxString params
= typeName
.AfterFirst(_T(':'));
2438 renderer
->SetParameters(params
);
2439 editor
->SetParameters(params
);
2441 // register the new typename
2442 RegisterDataType(typeName
, renderer
, editor
);
2444 // we just registered it, it's the last one
2445 index
= m_typeinfo
.GetCount() - 1;
2451 wxGridCellRenderer
* wxGridTypeRegistry::GetRenderer(int index
)
2453 wxGridCellRenderer
* renderer
= m_typeinfo
[index
]->m_renderer
;
2459 wxGridCellEditor
* wxGridTypeRegistry::GetEditor(int index
)
2461 wxGridCellEditor
* editor
= m_typeinfo
[index
]->m_editor
;
2467 // ----------------------------------------------------------------------------
2469 // ----------------------------------------------------------------------------
2471 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
2474 wxGridTableBase::wxGridTableBase()
2476 m_view
= (wxGrid
*) NULL
;
2477 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
2480 wxGridTableBase::~wxGridTableBase()
2482 delete m_attrProvider
;
2485 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
2487 delete m_attrProvider
;
2488 m_attrProvider
= attrProvider
;
2491 bool wxGridTableBase::CanHaveAttributes()
2493 if ( ! GetAttrProvider() )
2495 // use the default attr provider by default
2496 SetAttrProvider(new wxGridCellAttrProvider
);
2501 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
)
2503 if ( m_attrProvider
)
2504 return m_attrProvider
->GetAttr(row
, col
);
2506 return (wxGridCellAttr
*)NULL
;
2509 void wxGridTableBase::SetAttr(wxGridCellAttr
* attr
, int row
, int col
)
2511 if ( m_attrProvider
)
2513 m_attrProvider
->SetAttr(attr
, row
, col
);
2517 // as we take ownership of the pointer and don't store it, we must
2523 void wxGridTableBase::SetRowAttr(wxGridCellAttr
*attr
, int row
)
2525 if ( m_attrProvider
)
2527 m_attrProvider
->SetRowAttr(attr
, row
);
2531 // as we take ownership of the pointer and don't store it, we must
2537 void wxGridTableBase::SetColAttr(wxGridCellAttr
*attr
, int col
)
2539 if ( m_attrProvider
)
2541 m_attrProvider
->SetColAttr(attr
, col
);
2545 // as we take ownership of the pointer and don't store it, we must
2551 bool wxGridTableBase::InsertRows( size_t WXUNUSED(pos
),
2552 size_t WXUNUSED(numRows
) )
2554 wxFAIL_MSG( wxT("Called grid table class function InsertRows\nbut your derived table class does not override this function") );
2559 bool wxGridTableBase::AppendRows( size_t WXUNUSED(numRows
) )
2561 wxFAIL_MSG( wxT("Called grid table class function AppendRows\nbut your derived table class does not override this function"));
2566 bool wxGridTableBase::DeleteRows( size_t WXUNUSED(pos
),
2567 size_t WXUNUSED(numRows
) )
2569 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\nbut your derived table class does not override this function"));
2574 bool wxGridTableBase::InsertCols( size_t WXUNUSED(pos
),
2575 size_t WXUNUSED(numCols
) )
2577 wxFAIL_MSG( wxT("Called grid table class function InsertCols\nbut your derived table class does not override this function"));
2582 bool wxGridTableBase::AppendCols( size_t WXUNUSED(numCols
) )
2584 wxFAIL_MSG(wxT("Called grid table class function AppendCols\nbut your derived table class does not override this function"));
2589 bool wxGridTableBase::DeleteCols( size_t WXUNUSED(pos
),
2590 size_t WXUNUSED(numCols
) )
2592 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\nbut your derived table class does not override this function"));
2598 wxString
wxGridTableBase::GetRowLabelValue( int row
)
2601 s
<< row
+ 1; // RD: Starting the rows at zero confuses users, no matter
2602 // how much it makes sense to us geeks.
2606 wxString
wxGridTableBase::GetColLabelValue( int col
)
2608 // default col labels are:
2609 // cols 0 to 25 : A-Z
2610 // cols 26 to 675 : AA-ZZ
2615 for ( n
= 1; ; n
++ )
2617 s
+= (_T('A') + (wxChar
)( col%26
));
2619 if ( col
< 0 ) break;
2622 // reverse the string...
2624 for ( i
= 0; i
< n
; i
++ )
2633 wxString
wxGridTableBase::GetTypeName( int WXUNUSED(row
), int WXUNUSED(col
) )
2635 return wxGRID_VALUE_STRING
;
2638 bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row
), int WXUNUSED(col
),
2639 const wxString
& typeName
)
2641 return typeName
== wxGRID_VALUE_STRING
;
2644 bool wxGridTableBase::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
2646 return CanGetValueAs(row
, col
, typeName
);
2649 long wxGridTableBase::GetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
) )
2654 double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
) )
2659 bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
) )
2664 void wxGridTableBase::SetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
),
2665 long WXUNUSED(value
) )
2669 void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
),
2670 double WXUNUSED(value
) )
2674 void wxGridTableBase::SetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
),
2675 bool WXUNUSED(value
) )
2680 void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
2681 const wxString
& WXUNUSED(typeName
) )
2686 void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
2687 const wxString
& WXUNUSED(typeName
),
2688 void* WXUNUSED(value
) )
2692 //////////////////////////////////////////////////////////////////////
2694 // Message class for the grid table to send requests and notifications
2698 wxGridTableMessage::wxGridTableMessage()
2700 m_table
= (wxGridTableBase
*) NULL
;
2706 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
2707 int commandInt1
, int commandInt2
)
2711 m_comInt1
= commandInt1
;
2712 m_comInt2
= commandInt2
;
2717 //////////////////////////////////////////////////////////////////////
2719 // A basic grid table for string data. An object of this class will
2720 // created by wxGrid if you don't specify an alternative table class.
2723 WX_DEFINE_OBJARRAY(wxGridStringArray
)
2725 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
2727 wxGridStringTable::wxGridStringTable()
2732 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
2737 m_data
.Alloc( numRows
);
2740 sa
.Alloc( numCols
);
2741 for ( col
= 0; col
< numCols
; col
++ )
2743 sa
.Add( wxEmptyString
);
2746 for ( row
= 0; row
< numRows
; row
++ )
2752 wxGridStringTable::~wxGridStringTable()
2756 int wxGridStringTable::GetNumberRows()
2758 return m_data
.GetCount();
2761 int wxGridStringTable::GetNumberCols()
2763 if ( m_data
.GetCount() > 0 )
2764 return m_data
[0].GetCount();
2769 wxString
wxGridStringTable::GetValue( int row
, int col
)
2771 wxASSERT_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
2772 _T("invalid row or column index in wxGridStringTable") );
2774 return m_data
[row
][col
];
2777 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& value
)
2779 wxASSERT_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
2780 _T("invalid row or column index in wxGridStringTable") );
2782 m_data
[row
][col
] = value
;
2785 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
2787 wxASSERT_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
2788 _T("invalid row or column index in wxGridStringTable") );
2790 return (m_data
[row
][col
] == wxEmptyString
);
2793 void wxGridStringTable::Clear()
2796 int numRows
, numCols
;
2798 numRows
= m_data
.GetCount();
2801 numCols
= m_data
[0].GetCount();
2803 for ( row
= 0; row
< numRows
; row
++ )
2805 for ( col
= 0; col
< numCols
; col
++ )
2807 m_data
[row
][col
] = wxEmptyString
;
2814 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
2818 size_t curNumRows
= m_data
.GetCount();
2819 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
2820 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
2822 if ( pos
>= curNumRows
)
2824 return AppendRows( numRows
);
2828 sa
.Alloc( curNumCols
);
2829 for ( col
= 0; col
< curNumCols
; col
++ )
2831 sa
.Add( wxEmptyString
);
2834 for ( row
= pos
; row
< pos
+ numRows
; row
++ )
2836 m_data
.Insert( sa
, row
);
2840 wxGridTableMessage
msg( this,
2841 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
2845 GetView()->ProcessTableMessage( msg
);
2851 bool wxGridStringTable::AppendRows( size_t numRows
)
2855 size_t curNumRows
= m_data
.GetCount();
2856 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
2857 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
2860 if ( curNumCols
> 0 )
2862 sa
.Alloc( curNumCols
);
2863 for ( col
= 0; col
< curNumCols
; col
++ )
2865 sa
.Add( wxEmptyString
);
2869 for ( row
= 0; row
< numRows
; row
++ )
2876 wxGridTableMessage
msg( this,
2877 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
2880 GetView()->ProcessTableMessage( msg
);
2886 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
2890 size_t curNumRows
= m_data
.GetCount();
2892 if ( pos
>= curNumRows
)
2895 errmsg
.Printf(wxT("Called wxGridStringTable::DeleteRows(pos=%d, N=%d)\nPos value is invalid for present table with %d rows"),
2896 pos
, numRows
, curNumRows
);
2897 wxFAIL_MSG( errmsg
);
2901 if ( numRows
> curNumRows
- pos
)
2903 numRows
= curNumRows
- pos
;
2906 if ( numRows
>= curNumRows
)
2908 m_data
.Empty(); // don't release memory just yet
2912 for ( n
= 0; n
< numRows
; n
++ )
2914 m_data
.Remove( pos
);
2919 wxGridTableMessage
msg( this,
2920 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
2924 GetView()->ProcessTableMessage( msg
);
2930 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
2934 size_t curNumRows
= m_data
.GetCount();
2935 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
2936 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
2938 if ( pos
>= curNumCols
)
2940 return AppendCols( numCols
);
2943 for ( row
= 0; row
< curNumRows
; row
++ )
2945 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
2947 m_data
[row
].Insert( wxEmptyString
, col
);
2952 wxGridTableMessage
msg( this,
2953 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
2957 GetView()->ProcessTableMessage( msg
);
2963 bool wxGridStringTable::AppendCols( size_t numCols
)
2967 size_t curNumRows
= m_data
.GetCount();
2971 // TODO: something better than this ?
2973 wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\nCall AppendRows() first") );
2978 for ( row
= 0; row
< curNumRows
; row
++ )
2980 for ( n
= 0; n
< numCols
; n
++ )
2982 m_data
[row
].Add( wxEmptyString
);
2988 wxGridTableMessage
msg( this,
2989 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
2992 GetView()->ProcessTableMessage( msg
);
2998 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
3002 size_t curNumRows
= m_data
.GetCount();
3003 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3004 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3006 if ( pos
>= curNumCols
)
3009 errmsg
.Printf( wxT("Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\nPos value is invalid for present table with %d cols"),
3010 pos
, numCols
, curNumCols
);
3011 wxFAIL_MSG( errmsg
);
3015 if ( numCols
> curNumCols
- pos
)
3017 numCols
= curNumCols
- pos
;
3020 for ( row
= 0; row
< curNumRows
; row
++ )
3022 if ( numCols
>= curNumCols
)
3024 m_data
[row
].Clear();
3028 for ( n
= 0; n
< numCols
; n
++ )
3030 m_data
[row
].Remove( pos
);
3036 wxGridTableMessage
msg( this,
3037 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
3041 GetView()->ProcessTableMessage( msg
);
3047 wxString
wxGridStringTable::GetRowLabelValue( int row
)
3049 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
3051 // using default label
3053 return wxGridTableBase::GetRowLabelValue( row
);
3057 return m_rowLabels
[ row
];
3061 wxString
wxGridStringTable::GetColLabelValue( int col
)
3063 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
3065 // using default label
3067 return wxGridTableBase::GetColLabelValue( col
);
3071 return m_colLabels
[ col
];
3075 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
3077 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
3079 int n
= m_rowLabels
.GetCount();
3081 for ( i
= n
; i
<= row
; i
++ )
3083 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
3087 m_rowLabels
[row
] = value
;
3090 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
3092 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
3094 int n
= m_colLabels
.GetCount();
3096 for ( i
= n
; i
<= col
; i
++ )
3098 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
3102 m_colLabels
[col
] = value
;
3107 //////////////////////////////////////////////////////////////////////
3108 //////////////////////////////////////////////////////////////////////
3110 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
3112 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
3113 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
3114 EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel
)
3115 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
3116 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
3117 EVT_KEY_UP( wxGridRowLabelWindow::OnKeyUp
)
3120 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
3122 const wxPoint
&pos
, const wxSize
&size
)
3123 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
)
3128 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3132 // NO - don't do this because it will set both the x and y origin
3133 // coords to match the parent scrolled window and we just want to
3134 // set the y coord - MB
3136 // m_owner->PrepareDC( dc );
3139 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
3140 dc
.SetDeviceOrigin( 0, -y
);
3142 m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
3143 m_owner
->DrawRowLabels( dc
);
3147 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3149 m_owner
->ProcessRowLabelMouseEvent( event
);
3153 void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3155 m_owner
->GetEventHandler()->ProcessEvent(event
);
3159 // This seems to be required for wxMotif otherwise the mouse
3160 // cursor must be in the cell edit control to get key events
3162 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3164 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3167 void wxGridRowLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3169 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3174 //////////////////////////////////////////////////////////////////////
3176 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
3178 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
3179 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
3180 EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel
)
3181 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
3182 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
3183 EVT_KEY_UP( wxGridColLabelWindow::OnKeyUp
)
3186 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
3188 const wxPoint
&pos
, const wxSize
&size
)
3189 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
)
3194 void wxGridColLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3198 // NO - don't do this because it will set both the x and y origin
3199 // coords to match the parent scrolled window and we just want to
3200 // set the x coord - MB
3202 // m_owner->PrepareDC( dc );
3205 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
3206 dc
.SetDeviceOrigin( -x
, 0 );
3208 m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
3209 m_owner
->DrawColLabels( dc
);
3213 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3215 m_owner
->ProcessColLabelMouseEvent( event
);
3218 void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3220 m_owner
->GetEventHandler()->ProcessEvent(event
);
3224 // This seems to be required for wxMotif otherwise the mouse
3225 // cursor must be in the cell edit control to get key events
3227 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3229 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3232 void wxGridColLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3234 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3239 //////////////////////////////////////////////////////////////////////
3241 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
3243 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
3244 EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel
)
3245 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
3246 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
3247 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
3248 EVT_KEY_UP( wxGridCornerLabelWindow::OnKeyUp
)
3251 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
3253 const wxPoint
&pos
, const wxSize
&size
)
3254 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
)
3259 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3263 int client_height
= 0;
3264 int client_width
= 0;
3265 GetClientSize( &client_width
, &client_height
);
3267 dc
.SetPen( *wxBLACK_PEN
);
3268 dc
.DrawLine( client_width
-1, client_height
-1, client_width
-1, 0 );
3269 dc
.DrawLine( client_width
-1, client_height
-1, 0, client_height
-1 );
3271 dc
.SetPen( *wxWHITE_PEN
);
3272 dc
.DrawLine( 0, 0, client_width
, 0 );
3273 dc
.DrawLine( 0, 0, 0, client_height
);
3277 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3279 m_owner
->ProcessCornerLabelMouseEvent( event
);
3283 void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3285 m_owner
->GetEventHandler()->ProcessEvent(event
);
3288 // This seems to be required for wxMotif otherwise the mouse
3289 // cursor must be in the cell edit control to get key events
3291 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3293 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3296 void wxGridCornerLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3298 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3303 //////////////////////////////////////////////////////////////////////
3305 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxPanel
)
3307 BEGIN_EVENT_TABLE( wxGridWindow
, wxPanel
)
3308 EVT_PAINT( wxGridWindow::OnPaint
)
3309 EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel
)
3310 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
3311 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
3312 EVT_KEY_UP( wxGridWindow::OnKeyUp
)
3313 EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground
)
3316 wxGridWindow::wxGridWindow( wxGrid
*parent
,
3317 wxGridRowLabelWindow
*rowLblWin
,
3318 wxGridColLabelWindow
*colLblWin
,
3319 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
)
3320 : wxPanel( parent
, id
, pos
, size
, wxWANTS_CHARS
, "grid window" )
3323 m_rowLabelWin
= rowLblWin
;
3324 m_colLabelWin
= colLblWin
;
3325 SetBackgroundColour( "WHITE" );
3329 wxGridWindow::~wxGridWindow()
3334 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
3336 wxPaintDC
dc( this );
3337 m_owner
->PrepareDC( dc
);
3338 wxRegion reg
= GetUpdateRegion();
3339 m_owner
->CalcCellsExposed( reg
);
3340 m_owner
->DrawGridCellArea( dc
);
3341 #if WXGRID_DRAW_LINES
3342 m_owner
->DrawAllGridLines( dc
, reg
);
3344 m_owner
->DrawGridSpace( dc
);
3345 m_owner
->DrawHighlight( dc
);
3349 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
3351 wxPanel::ScrollWindow( dx
, dy
, rect
);
3352 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
3353 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
3357 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
3359 m_owner
->ProcessGridCellMouseEvent( event
);
3362 void wxGridWindow::OnMouseWheel( wxMouseEvent
& event
)
3364 m_owner
->GetEventHandler()->ProcessEvent(event
);
3367 // This seems to be required for wxMotif/wxGTK otherwise the mouse
3368 // cursor must be in the cell edit control to get key events
3370 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
3372 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3375 void wxGridWindow::OnKeyUp( wxKeyEvent
& event
)
3377 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3380 void wxGridWindow::OnEraseBackground( wxEraseEvent
& WXUNUSED(event
) )
3385 //////////////////////////////////////////////////////////////////////
3388 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
3390 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
3391 EVT_PAINT( wxGrid::OnPaint
)
3392 EVT_SIZE( wxGrid::OnSize
)
3393 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
3394 EVT_KEY_UP( wxGrid::OnKeyUp
)
3395 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
3398 wxGrid::wxGrid( wxWindow
*parent
,
3403 const wxString
& name
)
3404 : wxScrolledWindow( parent
, id
, pos
, size
, (style
| wxWANTS_CHARS
), name
),
3405 m_colMinWidths(GRID_HASH_SIZE
),
3406 m_rowMinHeights(GRID_HASH_SIZE
)
3415 wxSafeDecRef(m_defaultCellAttr
);
3417 #ifdef DEBUG_ATTR_CACHE
3418 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
3419 wxPrintf(_T("wxGrid attribute cache statistics: "
3420 "total: %u, hits: %u (%u%%)\n"),
3421 total
, gs_nAttrCacheHits
,
3422 total
? (gs_nAttrCacheHits
*100) / total
: 0);
3428 delete m_typeRegistry
;
3434 // ----- internal init and update functions
3437 void wxGrid::Create()
3439 m_created
= FALSE
; // set to TRUE by CreateGrid
3441 m_table
= (wxGridTableBase
*) NULL
;
3444 m_cellEditCtrlEnabled
= FALSE
;
3446 m_defaultCellAttr
= new wxGridCellAttr
;
3447 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
3449 // Set default cell attributes
3450 m_defaultCellAttr
->SetFont(GetFont());
3451 m_defaultCellAttr
->SetAlignment(wxALIGN_LEFT
, wxALIGN_TOP
);
3452 m_defaultCellAttr
->SetTextColour(
3453 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT
));
3454 m_defaultCellAttr
->SetBackgroundColour(
3455 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
3456 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
3457 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
3462 m_currentCellCoords
= wxGridNoCellCoords
;
3464 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
3465 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
3467 // create the type registry
3468 m_typeRegistry
= new wxGridTypeRegistry
;
3470 // subwindow components that make up the wxGrid
3471 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
3476 m_rowLabelWin
= new wxGridRowLabelWindow( this,
3481 m_colLabelWin
= new wxGridColLabelWindow( this,
3486 m_gridWin
= new wxGridWindow( this,
3493 SetTargetWindow( m_gridWin
);
3497 bool wxGrid::CreateGrid( int numRows
, int numCols
,
3498 wxGrid::wxGridSelectionModes selmode
)
3500 wxCHECK_MSG( !m_created
,
3502 wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
3504 m_numRows
= numRows
;
3505 m_numCols
= numCols
;
3507 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
3508 m_table
->SetView( this );
3510 m_selection
= new wxGridSelection( this, selmode
);
3517 void wxGrid::SetSelectionMode(wxGrid::wxGridSelectionModes selmode
)
3521 wxFAIL_MSG( wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") );
3524 m_selection
->SetSelectionMode( selmode
);
3527 bool wxGrid::SetTable( wxGridTableBase
*table
, bool takeOwnership
,
3528 wxGrid::wxGridSelectionModes selmode
)
3532 // RD: Actually, this should probably be allowed. I think it would be
3533 // nice to be able to switch multiple Tables in and out of a single
3534 // View at runtime. Is there anything in the implmentation that would
3537 // At least, you now have to cope with m_selection
3538 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
3543 m_numRows
= table
->GetNumberRows();
3544 m_numCols
= table
->GetNumberCols();
3547 m_table
->SetView( this );
3550 m_selection
= new wxGridSelection( this, selmode
);
3561 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
3562 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
3564 if ( m_rowLabelWin
)
3566 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
3570 m_labelBackgroundColour
= wxColour( _T("WHITE") );
3573 m_labelTextColour
= wxColour( _T("BLACK") );
3576 m_attrCache
.row
= -1;
3578 // TODO: something better than this ?
3580 m_labelFont
= this->GetFont();
3581 m_labelFont
.SetWeight( m_labelFont
.GetWeight() + 2 );
3583 m_rowLabelHorizAlign
= wxALIGN_LEFT
;
3584 m_rowLabelVertAlign
= wxALIGN_CENTRE
;
3586 m_colLabelHorizAlign
= wxALIGN_CENTRE
;
3587 m_colLabelVertAlign
= wxALIGN_TOP
;
3589 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
3590 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
3592 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
3593 m_defaultRowHeight
+= 8;
3595 m_defaultRowHeight
+= 4;
3598 m_gridLineColour
= wxColour( 128, 128, 255 );
3599 m_gridLinesEnabled
= TRUE
;
3600 m_cellHighlightColour
= m_gridLineColour
;
3602 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
3603 m_winCapture
= (wxWindow
*)NULL
;
3604 m_canDragRowSize
= TRUE
;
3605 m_canDragColSize
= TRUE
;
3606 m_canDragGridSize
= TRUE
;
3608 m_dragRowOrCol
= -1;
3609 m_isDragging
= FALSE
;
3610 m_startDragPos
= wxDefaultPosition
;
3612 m_waitForSlowClick
= FALSE
;
3614 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
3615 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
3617 m_currentCellCoords
= wxGridNoCellCoords
;
3619 m_selectingTopLeft
= wxGridNoCellCoords
;
3620 m_selectingBottomRight
= wxGridNoCellCoords
;
3621 m_selectionBackground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
);
3622 m_selectionForeground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
3624 m_editable
= TRUE
; // default for whole grid
3626 m_inOnKeyDown
= FALSE
;
3635 // ----------------------------------------------------------------------------
3636 // the idea is to call these functions only when necessary because they create
3637 // quite big arrays which eat memory mostly unnecessary - in particular, if
3638 // default widths/heights are used for all rows/columns, we may not use these
3641 // with some extra code, it should be possible to only store the
3642 // widths/heights different from default ones but this will be done later...
3643 // ----------------------------------------------------------------------------
3645 void wxGrid::InitRowHeights()
3647 m_rowHeights
.Empty();
3648 m_rowBottoms
.Empty();
3650 m_rowHeights
.Alloc( m_numRows
);
3651 m_rowBottoms
.Alloc( m_numRows
);
3654 for ( int i
= 0; i
< m_numRows
; i
++ )
3656 m_rowHeights
.Add( m_defaultRowHeight
);
3657 rowBottom
+= m_defaultRowHeight
;
3658 m_rowBottoms
.Add( rowBottom
);
3662 void wxGrid::InitColWidths()
3664 m_colWidths
.Empty();
3665 m_colRights
.Empty();
3667 m_colWidths
.Alloc( m_numCols
);
3668 m_colRights
.Alloc( m_numCols
);
3670 for ( int i
= 0; i
< m_numCols
; i
++ )
3672 m_colWidths
.Add( m_defaultColWidth
);
3673 colRight
+= m_defaultColWidth
;
3674 m_colRights
.Add( colRight
);
3678 int wxGrid::GetColWidth(int col
) const
3680 return m_colWidths
.IsEmpty() ? m_defaultColWidth
: m_colWidths
[col
];
3683 int wxGrid::GetColLeft(int col
) const
3685 return m_colRights
.IsEmpty() ? col
* m_defaultColWidth
3686 : m_colRights
[col
] - m_colWidths
[col
];
3689 int wxGrid::GetColRight(int col
) const
3691 return m_colRights
.IsEmpty() ? (col
+ 1) * m_defaultColWidth
3695 int wxGrid::GetRowHeight(int row
) const
3697 return m_rowHeights
.IsEmpty() ? m_defaultRowHeight
: m_rowHeights
[row
];
3700 int wxGrid::GetRowTop(int row
) const
3702 return m_rowBottoms
.IsEmpty() ? row
* m_defaultRowHeight
3703 : m_rowBottoms
[row
] - m_rowHeights
[row
];
3706 int wxGrid::GetRowBottom(int row
) const
3708 return m_rowBottoms
.IsEmpty() ? (row
+ 1) * m_defaultRowHeight
3709 : m_rowBottoms
[row
];
3712 void wxGrid::CalcDimensions()
3715 GetClientSize( &cw
, &ch
);
3717 if ( m_colLabelWin
->IsShown() )
3718 cw
-= m_rowLabelWidth
;
3719 if ( m_rowLabelWin
->IsShown() )
3720 ch
-= m_colLabelHeight
;
3723 int w
= m_numCols
> 0 ? GetColRight(m_numCols
- 1) + m_extraWidth
+ 1 : 0;
3724 int h
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) + m_extraHeight
+ 1 : 0;
3726 // preserve (more or less) the previous position
3728 GetViewStart( &x
, &y
);
3729 // maybe we don't need scrollbars at all? and if we do, transform w and h
3730 // from pixels into logical units
3737 w
= (w
+ GRID_SCROLL_LINE
- 1)/GRID_SCROLL_LINE
;
3747 h
= (h
+ GRID_SCROLL_LINE
- 1)/GRID_SCROLL_LINE
;
3752 // do set scrollbar parameters
3753 SetScrollbars( GRID_SCROLL_LINE
, GRID_SCROLL_LINE
,
3754 w
, h
, x
, y
, (GetBatchCount() != 0));
3758 void wxGrid::CalcWindowSizes()
3761 GetClientSize( &cw
, &ch
);
3763 if ( m_cornerLabelWin
->IsShown() )
3764 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
3766 if ( m_colLabelWin
->IsShown() )
3767 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
3769 if ( m_rowLabelWin
->IsShown() )
3770 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
3772 if ( m_gridWin
->IsShown() )
3773 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
3777 // this is called when the grid table sends a message to say that it
3778 // has been redimensioned
3780 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
3783 bool result
= FALSE
;
3786 // if we were using the default widths/heights so far, we must change them
3788 if ( m_colWidths
.IsEmpty() )
3793 if ( m_rowHeights
.IsEmpty() )
3799 switch ( msg
.GetId() )
3801 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
3803 size_t pos
= msg
.GetCommandInt();
3804 int numRows
= msg
.GetCommandInt2();
3806 m_numRows
+= numRows
;
3808 if ( !m_rowHeights
.IsEmpty() )
3810 for ( i
= 0; i
< numRows
; i
++ )
3812 m_rowHeights
.Insert( m_defaultRowHeight
, pos
);
3813 m_rowBottoms
.Insert( 0, pos
);
3817 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
3819 for ( i
= pos
; i
< m_numRows
; i
++ )
3821 bottom
+= m_rowHeights
[i
];
3822 m_rowBottoms
[i
] = bottom
;
3825 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3827 // if we have just inserted cols into an empty grid the current
3828 // cell will be undefined...
3830 SetCurrentCell( 0, 0 );
3832 m_selection
->UpdateRows( pos
, numRows
);
3833 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
3835 attrProvider
->UpdateAttrRows( pos
, numRows
);
3837 if ( !GetBatchCount() )
3840 m_rowLabelWin
->Refresh();
3846 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
3848 int numRows
= msg
.GetCommandInt();
3849 int oldNumRows
= m_numRows
;
3850 m_numRows
+= numRows
;
3852 if ( !m_rowHeights
.IsEmpty() )
3854 for ( i
= 0; i
< numRows
; i
++ )
3856 m_rowHeights
.Add( m_defaultRowHeight
);
3857 m_rowBottoms
.Add( 0 );
3861 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
3863 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
3865 bottom
+= m_rowHeights
[i
];
3866 m_rowBottoms
[i
] = bottom
;
3869 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3871 // if we have just inserted cols into an empty grid the current
3872 // cell will be undefined...
3874 SetCurrentCell( 0, 0 );
3876 if ( !GetBatchCount() )
3879 m_rowLabelWin
->Refresh();
3885 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
3887 size_t pos
= msg
.GetCommandInt();
3888 int numRows
= msg
.GetCommandInt2();
3889 m_numRows
-= numRows
;
3891 if ( !m_rowHeights
.IsEmpty() )
3893 for ( i
= 0; i
< numRows
; i
++ )
3895 m_rowHeights
.Remove( pos
);
3896 m_rowBottoms
.Remove( pos
);
3900 for ( i
= 0; i
< m_numRows
; i
++ )
3902 h
+= m_rowHeights
[i
];
3903 m_rowBottoms
[i
] = h
;
3908 m_currentCellCoords
= wxGridNoCellCoords
;
3912 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
3913 m_currentCellCoords
.Set( 0, 0 );
3915 m_selection
->UpdateRows( pos
, -((int)numRows
) );
3916 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
3918 attrProvider
->UpdateAttrRows( pos
, -((int)numRows
) );
3919 // ifdef'd out following patch from Paul Gammans
3921 // No need to touch column attributes, unless we
3922 // removed _all_ rows, in this case, we remove
3923 // all column attributes.
3924 // I hate to do this here, but the
3925 // needed data is not available inside UpdateAttrRows.
3926 if ( !GetNumberRows() )
3927 attrProvider
->UpdateAttrCols( 0, -GetNumberCols() );
3930 if ( !GetBatchCount() )
3933 m_rowLabelWin
->Refresh();
3939 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
3941 size_t pos
= msg
.GetCommandInt();
3942 int numCols
= msg
.GetCommandInt2();
3943 m_numCols
+= numCols
;
3945 if ( !m_colWidths
.IsEmpty() )
3947 for ( i
= 0; i
< numCols
; i
++ )
3949 m_colWidths
.Insert( m_defaultColWidth
, pos
);
3950 m_colRights
.Insert( 0, pos
);
3954 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
3956 for ( i
= pos
; i
< m_numCols
; i
++ )
3958 right
+= m_colWidths
[i
];
3959 m_colRights
[i
] = right
;
3962 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3964 // if we have just inserted cols into an empty grid the current
3965 // cell will be undefined...
3967 SetCurrentCell( 0, 0 );
3969 m_selection
->UpdateCols( pos
, numCols
);
3970 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
3972 attrProvider
->UpdateAttrCols( pos
, numCols
);
3973 if ( !GetBatchCount() )
3976 m_colLabelWin
->Refresh();
3983 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
3985 int numCols
= msg
.GetCommandInt();
3986 int oldNumCols
= m_numCols
;
3987 m_numCols
+= numCols
;
3988 if ( !m_colWidths
.IsEmpty() )
3990 for ( i
= 0; i
< numCols
; i
++ )
3992 m_colWidths
.Add( m_defaultColWidth
);
3993 m_colRights
.Add( 0 );
3997 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
3999 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
4001 right
+= m_colWidths
[i
];
4002 m_colRights
[i
] = right
;
4005 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4007 // if we have just inserted cols into an empty grid the current
4008 // cell will be undefined...
4010 SetCurrentCell( 0, 0 );
4012 if ( !GetBatchCount() )
4015 m_colLabelWin
->Refresh();
4021 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
4023 size_t pos
= msg
.GetCommandInt();
4024 int numCols
= msg
.GetCommandInt2();
4025 m_numCols
-= numCols
;
4027 if ( !m_colWidths
.IsEmpty() )
4029 for ( i
= 0; i
< numCols
; i
++ )
4031 m_colWidths
.Remove( pos
);
4032 m_colRights
.Remove( pos
);
4036 for ( i
= 0; i
< m_numCols
; i
++ )
4038 w
+= m_colWidths
[i
];
4044 m_currentCellCoords
= wxGridNoCellCoords
;
4048 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
4049 m_currentCellCoords
.Set( 0, 0 );
4051 m_selection
->UpdateCols( pos
, -((int)numCols
) );
4052 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4054 attrProvider
->UpdateAttrCols( pos
, -((int)numCols
) );
4055 // ifdef'd out following patch from Paul Gammans
4057 // No need to touch row attributes, unless we
4058 // removed _all_ columns, in this case, we remove
4059 // all row attributes.
4060 // I hate to do this here, but the
4061 // needed data is not available inside UpdateAttrCols.
4062 if ( !GetNumberCols() )
4063 attrProvider
->UpdateAttrRows( 0, -GetNumberRows() );
4066 if ( !GetBatchCount() )
4069 m_colLabelWin
->Refresh();
4076 if (result
&& !GetBatchCount() )
4077 m_gridWin
->Refresh();
4082 void wxGrid::CalcRowLabelsExposed( const wxRegion
& reg
)
4084 wxRegionIterator
iter( reg
);
4087 m_rowLabelsExposed
.Empty();
4094 // TODO: remove this when we can...
4095 // There is a bug in wxMotif that gives garbage update
4096 // rectangles if you jump-scroll a long way by clicking the
4097 // scrollbar with middle button. This is a work-around
4099 #if defined(__WXMOTIF__)
4101 m_gridWin
->GetClientSize( &cw
, &ch
);
4102 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
4103 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
4106 // logical bounds of update region
4109 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
4110 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
4112 // find the row labels within these bounds
4115 for ( row
= 0; row
< m_numRows
; row
++ )
4117 if ( GetRowBottom(row
) < top
)
4120 if ( GetRowTop(row
) > bottom
)
4123 m_rowLabelsExposed
.Add( row
);
4131 void wxGrid::CalcColLabelsExposed( const wxRegion
& reg
)
4133 wxRegionIterator
iter( reg
);
4136 m_colLabelsExposed
.Empty();
4143 // TODO: remove this when we can...
4144 // There is a bug in wxMotif that gives garbage update
4145 // rectangles if you jump-scroll a long way by clicking the
4146 // scrollbar with middle button. This is a work-around
4148 #if defined(__WXMOTIF__)
4150 m_gridWin
->GetClientSize( &cw
, &ch
);
4151 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
4152 r
.SetRight( wxMin( r
.GetRight(), cw
) );
4155 // logical bounds of update region
4158 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
4159 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
4161 // find the cells within these bounds
4164 for ( col
= 0; col
< m_numCols
; col
++ )
4166 if ( GetColRight(col
) < left
)
4169 if ( GetColLeft(col
) > right
)
4172 m_colLabelsExposed
.Add( col
);
4180 void wxGrid::CalcCellsExposed( const wxRegion
& reg
)
4182 wxRegionIterator
iter( reg
);
4185 m_cellsExposed
.Empty();
4186 m_rowsExposed
.Empty();
4187 m_colsExposed
.Empty();
4189 int left
, top
, right
, bottom
;
4194 // TODO: remove this when we can...
4195 // There is a bug in wxMotif that gives garbage update
4196 // rectangles if you jump-scroll a long way by clicking the
4197 // scrollbar with middle button. This is a work-around
4199 #if defined(__WXMOTIF__)
4201 m_gridWin
->GetClientSize( &cw
, &ch
);
4202 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
4203 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
4204 r
.SetRight( wxMin( r
.GetRight(), cw
) );
4205 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
4208 // logical bounds of update region
4210 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
4211 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
4213 // find the cells within these bounds
4216 for ( row
= 0; row
< m_numRows
; row
++ )
4218 if ( GetRowBottom(row
) <= top
)
4221 if ( GetRowTop(row
) > bottom
)
4224 m_rowsExposed
.Add( row
);
4226 for ( col
= 0; col
< m_numCols
; col
++ )
4228 if ( GetColRight(col
) <= left
)
4231 if ( GetColLeft(col
) > right
)
4234 if ( m_colsExposed
.Index( col
) == wxNOT_FOUND
)
4235 m_colsExposed
.Add( col
);
4236 m_cellsExposed
.Add( wxGridCellCoords( row
, col
) );
4245 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
4248 wxPoint
pos( event
.GetPosition() );
4249 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
4251 if ( event
.Dragging() )
4253 m_isDragging
= TRUE
;
4255 if ( event
.LeftIsDown() )
4257 switch( m_cursorMode
)
4259 case WXGRID_CURSOR_RESIZE_ROW
:
4261 int cw
, ch
, left
, dummy
;
4262 m_gridWin
->GetClientSize( &cw
, &ch
);
4263 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
4265 wxClientDC
dc( m_gridWin
);
4268 GetRowTop(m_dragRowOrCol
) +
4269 GetRowMinimalHeight(m_dragRowOrCol
) );
4270 dc
.SetLogicalFunction(wxINVERT
);
4271 if ( m_dragLastPos
>= 0 )
4273 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
4275 dc
.DrawLine( left
, y
, left
+cw
, y
);
4280 case WXGRID_CURSOR_SELECT_ROW
:
4281 if ( (row
= YToRow( y
)) >= 0 )
4283 m_selection
->SelectRow( row
,
4284 event
.ControlDown(),
4290 // default label to suppress warnings about "enumeration value
4291 // 'xxx' not handled in switch
4299 m_isDragging
= FALSE
;
4302 // ------------ Entering or leaving the window
4304 if ( event
.Entering() || event
.Leaving() )
4306 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
4310 // ------------ Left button pressed
4312 else if ( event
.LeftDown() )
4314 // don't send a label click event for a hit on the
4315 // edge of the row label - this is probably the user
4316 // wanting to resize the row
4318 if ( YToEdgeOfRow(y
) < 0 )
4322 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
4324 if ( !event
.ShiftDown() && !event
.ControlDown() )
4326 if ( event
.ShiftDown() )
4327 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
4330 GetNumberCols() - 1,
4331 event
.ControlDown(),
4336 m_selection
->SelectRow( row
,
4337 event
.ControlDown(),
4341 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
4346 // starting to drag-resize a row
4348 if ( CanDragRowSize() )
4349 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
4354 // ------------ Left double click
4356 else if (event
.LeftDClick() )
4358 if ( YToEdgeOfRow(y
) < 0 )
4361 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
);
4366 // ------------ Left button released
4368 else if ( event
.LeftUp() )
4370 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
4372 DoEndDragResizeRow();
4374 // Note: we are ending the event *after* doing
4375 // default processing in this case
4377 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
4380 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
4385 // ------------ Right button down
4387 else if ( event
.RightDown() )
4390 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
4392 // no default action at the moment
4397 // ------------ Right double click
4399 else if ( event
.RightDClick() )
4402 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
4404 // no default action at the moment
4409 // ------------ No buttons down and mouse moving
4411 else if ( event
.Moving() )
4413 m_dragRowOrCol
= YToEdgeOfRow( y
);
4414 if ( m_dragRowOrCol
>= 0 )
4416 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4418 // don't capture the mouse yet
4419 if ( CanDragRowSize() )
4420 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, FALSE
);
4423 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
4425 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, FALSE
);
4431 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
4434 wxPoint
pos( event
.GetPosition() );
4435 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
4437 if ( event
.Dragging() )
4439 m_isDragging
= TRUE
;
4441 if ( event
.LeftIsDown() )
4443 switch( m_cursorMode
)
4445 case WXGRID_CURSOR_RESIZE_COL
:
4447 int cw
, ch
, dummy
, top
;
4448 m_gridWin
->GetClientSize( &cw
, &ch
);
4449 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
4451 wxClientDC
dc( m_gridWin
);
4454 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
4455 GetColMinimalWidth(m_dragRowOrCol
));
4456 dc
.SetLogicalFunction(wxINVERT
);
4457 if ( m_dragLastPos
>= 0 )
4459 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
4461 dc
.DrawLine( x
, top
, x
, top
+ch
);
4466 case WXGRID_CURSOR_SELECT_COL
:
4467 if ( (col
= XToCol( x
)) >= 0 )
4469 m_selection
->SelectCol( col
,
4470 event
.ControlDown(),
4476 // default label to suppress warnings about "enumeration value
4477 // 'xxx' not handled in switch
4485 m_isDragging
= FALSE
;
4488 // ------------ Entering or leaving the window
4490 if ( event
.Entering() || event
.Leaving() )
4492 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
4496 // ------------ Left button pressed
4498 else if ( event
.LeftDown() )
4500 // don't send a label click event for a hit on the
4501 // edge of the col label - this is probably the user
4502 // wanting to resize the col
4504 if ( XToEdgeOfCol(x
) < 0 )
4508 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
4510 if ( !event
.ShiftDown() && !event
.ControlDown() )
4512 if ( event
.ShiftDown() )
4513 m_selection
->SelectBlock( 0,
4514 m_currentCellCoords
.GetCol(),
4515 GetNumberRows() - 1, col
,
4516 event
.ControlDown(),
4521 m_selection
->SelectCol( col
,
4522 event
.ControlDown(),
4526 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, m_colLabelWin
);
4531 // starting to drag-resize a col
4533 if ( CanDragColSize() )
4534 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
);
4539 // ------------ Left double click
4541 if ( event
.LeftDClick() )
4543 if ( XToEdgeOfCol(x
) < 0 )
4546 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
);
4551 // ------------ Left button released
4553 else if ( event
.LeftUp() )
4555 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
4557 DoEndDragResizeCol();
4559 // Note: we are ending the event *after* doing
4560 // default processing in this case
4562 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
4565 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
4570 // ------------ Right button down
4572 else if ( event
.RightDown() )
4575 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
4577 // no default action at the moment
4582 // ------------ Right double click
4584 else if ( event
.RightDClick() )
4587 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
4589 // no default action at the moment
4594 // ------------ No buttons down and mouse moving
4596 else if ( event
.Moving() )
4598 m_dragRowOrCol
= XToEdgeOfCol( x
);
4599 if ( m_dragRowOrCol
>= 0 )
4601 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4603 // don't capture the cursor yet
4604 if ( CanDragColSize() )
4605 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
, FALSE
);
4608 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
4610 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
, FALSE
);
4616 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
4618 if ( event
.LeftDown() )
4620 // indicate corner label by having both row and
4623 if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
4629 else if ( event
.LeftDClick() )
4631 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
4634 else if ( event
.RightDown() )
4636 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
4638 // no default action at the moment
4642 else if ( event
.RightDClick() )
4644 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
4646 // no default action at the moment
4651 void wxGrid::ChangeCursorMode(CursorMode mode
,
4656 static const wxChar
*cursorModes
[] =
4665 wxLogTrace(_T("grid"),
4666 _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
4667 win
== m_colLabelWin
? _T("colLabelWin")
4668 : win
? _T("rowLabelWin")
4670 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
4671 #endif // __WXDEBUG__
4673 if ( mode
== m_cursorMode
&&
4674 win
== m_winCapture
&&
4675 captureMouse
== (m_winCapture
!= NULL
))
4680 // by default use the grid itself
4686 m_winCapture
->ReleaseMouse();
4687 m_winCapture
= (wxWindow
*)NULL
;
4690 m_cursorMode
= mode
;
4692 switch ( m_cursorMode
)
4694 case WXGRID_CURSOR_RESIZE_ROW
:
4695 win
->SetCursor( m_rowResizeCursor
);
4698 case WXGRID_CURSOR_RESIZE_COL
:
4699 win
->SetCursor( m_colResizeCursor
);
4703 win
->SetCursor( *wxSTANDARD_CURSOR
);
4706 // we need to capture mouse when resizing
4707 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
4708 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
4710 if ( captureMouse
&& resize
)
4712 win
->CaptureMouse();
4717 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
4720 wxPoint
pos( event
.GetPosition() );
4721 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
4723 wxGridCellCoords coords
;
4724 XYToCell( x
, y
, coords
);
4726 if ( event
.Dragging() )
4728 //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
4730 // Don't start doing anything until the mouse has been drug at
4731 // least 3 pixels in any direction...
4734 if (m_startDragPos
== wxDefaultPosition
)
4736 m_startDragPos
= pos
;
4739 if (abs(m_startDragPos
.x
- pos
.x
) < 4 && abs(m_startDragPos
.y
- pos
.y
) < 4)
4743 m_isDragging
= TRUE
;
4744 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4746 // Hide the edit control, so it
4747 // won't interfer with drag-shrinking.
4748 if ( IsCellEditControlShown() )
4750 HideCellEditControl();
4751 SaveEditControlValue();
4754 // Have we captured the mouse yet?
4757 m_winCapture
= m_gridWin
;
4758 m_winCapture
->CaptureMouse();
4761 if ( coords
!= wxGridNoCellCoords
)
4763 if ( event
.ControlDown() )
4765 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
4766 m_selectingKeyboard
= coords
;
4767 HighlightBlock ( m_selectingKeyboard
, coords
);
4771 if ( !IsSelection() )
4773 HighlightBlock( coords
, coords
);
4777 HighlightBlock( m_currentCellCoords
, coords
);
4781 if (! IsVisible(coords
))
4783 MakeCellVisible(coords
);
4784 // TODO: need to introduce a delay or something here. The
4785 // scrolling is way to fast, at least on MSW - also on GTK.
4789 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
4791 int cw
, ch
, left
, dummy
;
4792 m_gridWin
->GetClientSize( &cw
, &ch
);
4793 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
4795 wxClientDC
dc( m_gridWin
);
4797 y
= wxMax( y
, GetRowTop(m_dragRowOrCol
) +
4798 GetRowMinimalHeight(m_dragRowOrCol
) );
4799 dc
.SetLogicalFunction(wxINVERT
);
4800 if ( m_dragLastPos
>= 0 )
4802 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
4804 dc
.DrawLine( left
, y
, left
+cw
, y
);
4807 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
4809 int cw
, ch
, dummy
, top
;
4810 m_gridWin
->GetClientSize( &cw
, &ch
);
4811 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
4813 wxClientDC
dc( m_gridWin
);
4815 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
4816 GetColMinimalWidth(m_dragRowOrCol
) );
4817 dc
.SetLogicalFunction(wxINVERT
);
4818 if ( m_dragLastPos
>= 0 )
4820 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
4822 dc
.DrawLine( x
, top
, x
, top
+ch
);
4829 m_isDragging
= FALSE
;
4830 m_startDragPos
= wxDefaultPosition
;
4832 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
4833 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
4836 if ( event
.Entering() || event
.Leaving() )
4838 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
4839 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
4844 // ------------ Left button pressed
4846 if ( event
.LeftDown() && coords
!= wxGridNoCellCoords
)
4848 if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK
,
4853 if ( !event
.ControlDown() )
4855 if ( event
.ShiftDown() )
4857 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
4858 m_currentCellCoords
.GetCol(),
4861 event
.ControlDown(),
4866 else if ( XToEdgeOfCol(x
) < 0 &&
4867 YToEdgeOfRow(y
) < 0 )
4869 DisableCellEditControl();
4870 MakeCellVisible( coords
);
4872 // if this is the second click on this cell then start
4874 if ( m_waitForSlowClick
&&
4875 (coords
== m_currentCellCoords
) &&
4876 CanEnableCellControl())
4878 EnableCellEditControl();
4880 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
4881 wxGridCellEditor
*editor
= attr
->GetEditor(this,
4884 editor
->StartingClick();
4888 m_waitForSlowClick
= FALSE
;
4892 if ( event
.ControlDown() )
4894 m_selection
->ToggleCellSelection( coords
.GetRow(),
4896 event
.ControlDown(),
4900 m_selectingTopLeft
= wxGridNoCellCoords
;
4901 m_selectingBottomRight
= wxGridNoCellCoords
;
4902 m_selectingKeyboard
= coords
;
4906 SetCurrentCell( coords
);
4907 if ( m_selection
->GetSelectionMode()
4908 != wxGrid::wxGridSelectCells
)
4909 HighlightBlock( coords
, coords
);
4911 m_waitForSlowClick
= TRUE
;
4918 // ------------ Left double click
4920 else if ( event
.LeftDClick() && coords
!= wxGridNoCellCoords
)
4922 DisableCellEditControl();
4924 if ( XToEdgeOfCol(x
) < 0 && YToEdgeOfRow(y
) < 0 )
4926 SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK
,
4934 // ------------ Left button released
4936 else if ( event
.LeftUp() )
4938 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4940 if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
4941 m_selectingBottomRight
!= wxGridNoCellCoords
)
4945 m_winCapture
->ReleaseMouse();
4946 m_winCapture
= NULL
;
4948 m_selection
->SelectBlock( m_selectingTopLeft
.GetRow(),
4949 m_selectingTopLeft
.GetCol(),
4950 m_selectingBottomRight
.GetRow(),
4951 m_selectingBottomRight
.GetCol(),
4952 event
.ControlDown(),
4956 m_selectingTopLeft
= wxGridNoCellCoords
;
4957 m_selectingBottomRight
= wxGridNoCellCoords
;
4960 // Show the edit control, if it has been hidden for
4962 ShowCellEditControl();
4964 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
4966 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
4967 DoEndDragResizeRow();
4969 // Note: we are ending the event *after* doing
4970 // default processing in this case
4972 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
4974 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
4976 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
4977 DoEndDragResizeCol();
4979 // Note: we are ending the event *after* doing
4980 // default processing in this case
4982 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
4989 // ------------ Right button down
4991 else if ( event
.RightDown() && coords
!= wxGridNoCellCoords
)
4993 DisableCellEditControl();
4994 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK
,
4999 // no default action at the moment
5004 // ------------ Right double click
5006 else if ( event
.RightDClick() && coords
!= wxGridNoCellCoords
)
5008 DisableCellEditControl();
5009 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK
,
5014 // no default action at the moment
5018 // ------------ Moving and no button action
5020 else if ( event
.Moving() && !event
.IsButton() )
5022 int dragRow
= YToEdgeOfRow( y
);
5023 int dragCol
= XToEdgeOfCol( x
);
5025 // Dragging on the corner of a cell to resize in both
5026 // directions is not implemented yet...
5028 if ( dragRow
>= 0 && dragCol
>= 0 )
5030 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5036 m_dragRowOrCol
= dragRow
;
5038 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5040 if ( CanDragRowSize() && CanDragGridSize() )
5041 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
);
5046 m_dragRowOrCol
= dragCol
;
5054 m_dragRowOrCol
= dragCol
;
5056 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5058 if ( CanDragColSize() && CanDragGridSize() )
5059 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
);
5065 // Neither on a row or col edge
5067 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
5069 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5075 void wxGrid::DoEndDragResizeRow()
5077 if ( m_dragLastPos
>= 0 )
5079 // erase the last line and resize the row
5081 int cw
, ch
, left
, dummy
;
5082 m_gridWin
->GetClientSize( &cw
, &ch
);
5083 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
5085 wxClientDC
dc( m_gridWin
);
5087 dc
.SetLogicalFunction( wxINVERT
);
5088 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
5089 HideCellEditControl();
5090 SaveEditControlValue();
5092 int rowTop
= GetRowTop(m_dragRowOrCol
);
5093 SetRowSize( m_dragRowOrCol
,
5094 wxMax( m_dragLastPos
- rowTop
, WXGRID_MIN_ROW_HEIGHT
) );
5096 if ( !GetBatchCount() )
5098 // Only needed to get the correct rect.y:
5099 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
5101 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
5102 rect
.width
= m_rowLabelWidth
;
5103 rect
.height
= ch
- rect
.y
;
5104 m_rowLabelWin
->Refresh( TRUE
, &rect
);
5106 m_gridWin
->Refresh( FALSE
, &rect
);
5109 ShowCellEditControl();
5114 void wxGrid::DoEndDragResizeCol()
5116 if ( m_dragLastPos
>= 0 )
5118 // erase the last line and resize the col
5120 int cw
, ch
, dummy
, top
;
5121 m_gridWin
->GetClientSize( &cw
, &ch
);
5122 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
5124 wxClientDC
dc( m_gridWin
);
5126 dc
.SetLogicalFunction( wxINVERT
);
5127 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
5128 HideCellEditControl();
5129 SaveEditControlValue();
5131 int colLeft
= GetColLeft(m_dragRowOrCol
);
5132 SetColSize( m_dragRowOrCol
,
5133 wxMax( m_dragLastPos
- colLeft
,
5134 GetColMinimalWidth(m_dragRowOrCol
) ) );
5136 if ( !GetBatchCount() )
5138 // Only needed to get the correct rect.x:
5139 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
5141 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
5142 rect
.width
= cw
- rect
.x
;
5143 rect
.height
= m_colLabelHeight
;
5144 m_colLabelWin
->Refresh( TRUE
, &rect
);
5146 m_gridWin
->Refresh( FALSE
, &rect
);
5149 ShowCellEditControl();
5156 // ------ interaction with data model
5158 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
5160 switch ( msg
.GetId() )
5162 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
5163 return GetModelValues();
5165 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
5166 return SetModelValues();
5168 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
5169 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
5170 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
5171 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
5172 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
5173 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
5174 return Redimension( msg
);
5183 // The behaviour of this function depends on the grid table class
5184 // Clear() function. For the default wxGridStringTable class the
5185 // behavious is to replace all cell contents with wxEmptyString but
5186 // not to change the number of rows or cols.
5188 void wxGrid::ClearGrid()
5192 if (IsCellEditControlEnabled())
5193 DisableCellEditControl();
5196 if ( !GetBatchCount() ) m_gridWin
->Refresh();
5201 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
5203 // TODO: something with updateLabels flag
5207 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
5213 if (IsCellEditControlEnabled())
5214 DisableCellEditControl();
5216 return m_table
->InsertRows( pos
, numRows
);
5218 // the table will have sent the results of the insert row
5219 // operation to this view object as a grid table message
5225 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
5227 // TODO: something with updateLabels flag
5231 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
5235 return ( m_table
&& m_table
->AppendRows( numRows
) );
5236 // the table will have sent the results of the append row
5237 // operation to this view object as a grid table message
5241 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
5243 // TODO: something with updateLabels flag
5247 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
5253 if (IsCellEditControlEnabled())
5254 DisableCellEditControl();
5256 return (m_table
->DeleteRows( pos
, numRows
));
5257 // the table will have sent the results of the delete row
5258 // operation to this view object as a grid table message
5264 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
5266 // TODO: something with updateLabels flag
5270 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
5276 if (IsCellEditControlEnabled())
5277 DisableCellEditControl();
5279 return m_table
->InsertCols( pos
, numCols
);
5280 // the table will have sent the results of the insert col
5281 // operation to this view object as a grid table message
5287 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
5289 // TODO: something with updateLabels flag
5293 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
5297 return ( m_table
&& m_table
->AppendCols( numCols
) );
5298 // the table will have sent the results of the append col
5299 // operation to this view object as a grid table message
5303 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
5305 // TODO: something with updateLabels flag
5309 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
5315 if (IsCellEditControlEnabled())
5316 DisableCellEditControl();
5318 return ( m_table
->DeleteCols( pos
, numCols
) );
5319 // the table will have sent the results of the delete col
5320 // operation to this view object as a grid table message
5328 // ----- event handlers
5331 // Generate a grid event based on a mouse event and
5332 // return the result of ProcessEvent()
5334 bool wxGrid::SendEvent( const wxEventType type
,
5336 wxMouseEvent
& mouseEv
)
5338 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
5340 int rowOrCol
= (row
== -1 ? col
: row
);
5342 wxGridSizeEvent
gridEvt( GetId(),
5346 mouseEv
.GetX() + GetRowLabelSize(),
5347 mouseEv
.GetY() + GetColLabelSize(),
5348 mouseEv
.ControlDown(),
5349 mouseEv
.ShiftDown(),
5351 mouseEv
.MetaDown() );
5352 return GetEventHandler()->ProcessEvent(gridEvt
);
5354 else if ( type
== wxEVT_GRID_RANGE_SELECT
)
5356 // Right now, it should _never_ end up here!
5357 wxGridRangeSelectEvent
gridEvt( GetId(),
5361 m_selectingBottomRight
,
5363 mouseEv
.ControlDown(),
5364 mouseEv
.ShiftDown(),
5366 mouseEv
.MetaDown() );
5368 return GetEventHandler()->ProcessEvent(gridEvt
);
5372 wxGridEvent
gridEvt( GetId(),
5376 mouseEv
.GetX() + GetRowLabelSize(),
5377 mouseEv
.GetY() + GetColLabelSize(),
5379 mouseEv
.ControlDown(),
5380 mouseEv
.ShiftDown(),
5382 mouseEv
.MetaDown() );
5383 return GetEventHandler()->ProcessEvent(gridEvt
);
5388 // Generate a grid event of specified type and return the result
5389 // of ProcessEvent().
5391 bool wxGrid::SendEvent( const wxEventType type
,
5394 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
5396 int rowOrCol
= (row
== -1 ? col
: row
);
5398 wxGridSizeEvent
gridEvt( GetId(),
5403 return GetEventHandler()->ProcessEvent(gridEvt
);
5407 wxGridEvent
gridEvt( GetId(),
5412 return GetEventHandler()->ProcessEvent(gridEvt
);
5417 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
5419 wxPaintDC
dc(this); // needed to prevent zillions of paint events on MSW
5423 // This is just here to make sure that CalcDimensions gets called when
5424 // the grid view is resized... then the size event is skipped to allow
5425 // the box sizers to handle everything
5427 void wxGrid::OnSize( wxSizeEvent
& WXUNUSED(event
) )
5434 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
5436 if ( m_inOnKeyDown
)
5438 // shouldn't be here - we are going round in circles...
5440 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
5443 m_inOnKeyDown
= TRUE
;
5445 // propagate the event up and see if it gets processed
5447 wxWindow
*parent
= GetParent();
5448 wxKeyEvent
keyEvt( event
);
5449 keyEvt
.SetEventObject( parent
);
5451 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
5454 // try local handlers
5456 switch ( event
.KeyCode() )
5459 if ( event
.ControlDown() )
5461 MoveCursorUpBlock( event
.ShiftDown() );
5465 MoveCursorUp( event
.ShiftDown() );
5470 if ( event
.ControlDown() )
5472 MoveCursorDownBlock( event
.ShiftDown() );
5476 MoveCursorDown( event
.ShiftDown() );
5481 if ( event
.ControlDown() )
5483 MoveCursorLeftBlock( event
.ShiftDown() );
5487 MoveCursorLeft( event
.ShiftDown() );
5492 if ( event
.ControlDown() )
5494 MoveCursorRightBlock( event
.ShiftDown() );
5498 MoveCursorRight( event
.ShiftDown() );
5503 case WXK_NUMPAD_ENTER
:
5504 if ( event
.ControlDown() )
5506 event
.Skip(); // to let the edit control have the return
5510 if ( GetGridCursorRow() < GetNumberRows()-1 )
5512 MoveCursorDown( event
.ShiftDown() );
5516 // at the bottom of a column
5517 HideCellEditControl();
5518 SaveEditControlValue();
5528 if (event
.ShiftDown())
5530 if ( GetGridCursorCol() > 0 )
5532 MoveCursorLeft( FALSE
);
5537 HideCellEditControl();
5538 SaveEditControlValue();
5543 if ( GetGridCursorCol() < GetNumberCols()-1 )
5545 MoveCursorRight( FALSE
);
5550 HideCellEditControl();
5551 SaveEditControlValue();
5557 if ( event
.ControlDown() )
5559 MakeCellVisible( 0, 0 );
5560 SetCurrentCell( 0, 0 );
5569 if ( event
.ControlDown() )
5571 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
5572 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
5589 if ( event
.ControlDown() )
5591 m_selection
->ToggleCellSelection( m_currentCellCoords
.GetRow(),
5592 m_currentCellCoords
.GetCol(),
5593 event
.ControlDown(),
5599 if ( !IsEditable() )
5601 MoveCursorRight( FALSE
);
5604 // Otherwise fall through to default
5607 // is it possible to edit the current cell at all?
5608 if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
5610 // yes, now check whether the cells editor accepts the key
5611 int row
= m_currentCellCoords
.GetRow();
5612 int col
= m_currentCellCoords
.GetCol();
5613 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5614 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
5616 // <F2> is special and will always start editing, for
5617 // other keys - ask the editor itself
5618 if ( (event
.KeyCode() == WXK_F2
&& !event
.HasModifiers())
5619 || editor
->IsAcceptedKey(event
) )
5621 EnableCellEditControl();
5622 editor
->StartingKey(event
);
5634 // let others process char events with modifiers or all
5635 // char events for readonly cells
5642 m_inOnKeyDown
= FALSE
;
5645 void wxGrid::OnKeyUp( wxKeyEvent
& event
)
5647 // try local handlers
5649 if ( event
.KeyCode() == WXK_SHIFT
)
5651 if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
5652 m_selectingBottomRight
!= wxGridNoCellCoords
)
5653 m_selection
->SelectBlock( m_selectingTopLeft
.GetRow(),
5654 m_selectingTopLeft
.GetCol(),
5655 m_selectingBottomRight
.GetRow(),
5656 m_selectingBottomRight
.GetCol(),
5657 event
.ControlDown(),
5661 m_selectingTopLeft
= wxGridNoCellCoords
;
5662 m_selectingBottomRight
= wxGridNoCellCoords
;
5663 m_selectingKeyboard
= wxGridNoCellCoords
;
5667 void wxGrid::OnEraseBackground(wxEraseEvent
&)
5671 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
5673 if ( SendEvent( wxEVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
5675 // the event has been intercepted - do nothing
5679 wxClientDC
dc(m_gridWin
);
5682 if ( m_currentCellCoords
!= wxGridNoCellCoords
)
5684 HideCellEditControl();
5685 DisableCellEditControl();
5687 if ( IsVisible( m_currentCellCoords
, FALSE
) )
5690 r
= BlockToDeviceRect(m_currentCellCoords
, m_currentCellCoords
);
5691 if ( !m_gridLinesEnabled
)
5699 CalcCellsExposed( r
);
5701 // Otherwise refresh redraws the highlight!
5702 m_currentCellCoords
= coords
;
5704 DrawGridCellArea(dc
);
5705 DrawAllGridLines( dc
, r
);
5709 m_currentCellCoords
= coords
;
5711 wxGridCellAttr
* attr
= GetCellAttr(coords
);
5712 DrawCellHighlight(dc
, attr
);
5717 void wxGrid::HighlightBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
5720 wxGridCellCoords updateTopLeft
, updateBottomRight
;
5722 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectRows
)
5725 rightCol
= GetNumberCols() - 1;
5727 else if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectColumns
)
5730 bottomRow
= GetNumberRows() - 1;
5732 if ( topRow
> bottomRow
)
5739 if ( leftCol
> rightCol
)
5746 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
5747 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
5749 if ( m_selectingTopLeft
!= updateTopLeft
||
5750 m_selectingBottomRight
!= updateBottomRight
)
5752 // Compute two optimal update rectangles:
5753 // Either one rectangle is a real subset of the
5754 // other, or they are (almost) disjoint!
5756 bool need_refresh
[4];
5760 need_refresh
[3] = FALSE
;
5763 // Store intermediate values
5764 wxCoord oldLeft
= m_selectingTopLeft
.GetCol();
5765 wxCoord oldTop
= m_selectingTopLeft
.GetRow();
5766 wxCoord oldRight
= m_selectingBottomRight
.GetCol();
5767 wxCoord oldBottom
= m_selectingBottomRight
.GetRow();
5769 // Determine the outer/inner coordinates.
5770 if (oldLeft
> leftCol
)
5776 if (oldTop
> topRow
)
5782 if (oldRight
< rightCol
)
5785 oldRight
= rightCol
;
5788 if (oldBottom
< bottomRow
)
5791 oldBottom
= bottomRow
;
5795 // Now, either the stuff marked old is the outer
5796 // rectangle or we don't have a situation where one
5797 // is contained in the other.
5799 if ( oldLeft
< leftCol
)
5801 need_refresh
[0] = TRUE
;
5802 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5804 wxGridCellCoords ( oldBottom
,
5808 if ( oldTop
< topRow
)
5810 need_refresh
[1] = TRUE
;
5811 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5813 wxGridCellCoords ( topRow
- 1,
5817 if ( oldRight
> rightCol
)
5819 need_refresh
[2] = TRUE
;
5820 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5822 wxGridCellCoords ( oldBottom
,
5826 if ( oldBottom
> bottomRow
)
5828 need_refresh
[3] = TRUE
;
5829 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
5831 wxGridCellCoords ( oldBottom
,
5837 m_selectingTopLeft
= updateTopLeft
;
5838 m_selectingBottomRight
= updateBottomRight
;
5840 // various Refresh() calls
5841 for (i
= 0; i
< 4; i
++ )
5842 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
5843 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
5846 // never generate an event as it will be generated from
5847 // wxGridSelection::SelectBlock!
5848 // (old comment from when this was the body of SelectBlock)
5852 // ------ functions to get/send data (see also public functions)
5855 bool wxGrid::GetModelValues()
5859 // all we need to do is repaint the grid
5861 m_gridWin
->Refresh();
5869 bool wxGrid::SetModelValues()
5875 for ( row
= 0; row
< m_numRows
; row
++ )
5877 for ( col
= 0; col
< m_numCols
; col
++ )
5879 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
5891 // Note - this function only draws cells that are in the list of
5892 // exposed cells (usually set from the update region by
5893 // CalcExposedCells)
5895 void wxGrid::DrawGridCellArea( wxDC
& dc
)
5897 if ( !m_numRows
|| !m_numCols
) return;
5900 size_t numCells
= m_cellsExposed
.GetCount();
5902 for ( i
= 0; i
< numCells
; i
++ )
5904 DrawCell( dc
, m_cellsExposed
[i
] );
5909 void wxGrid::DrawGridSpace( wxDC
& dc
)
5912 m_gridWin
->GetClientSize( &cw
, &ch
);
5915 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
5917 int rightCol
= m_numCols
> 0 ? GetColRight(m_numCols
- 1) : 0;
5918 int bottomRow
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) : 0 ;
5920 if ( right
> rightCol
|| bottom
> bottomRow
)
5923 CalcUnscrolledPosition( 0, 0, &left
, &top
);
5925 dc
.SetBrush( wxBrush(GetDefaultCellBackgroundColour(), wxSOLID
) );
5926 dc
.SetPen( *wxTRANSPARENT_PEN
);
5928 if ( right
> rightCol
)
5930 dc
.DrawRectangle( rightCol
, top
, right
- rightCol
, ch
);
5933 if ( bottom
> bottomRow
)
5935 dc
.DrawRectangle( left
, bottomRow
, cw
, bottom
- bottomRow
);
5941 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
5943 int row
= coords
.GetRow();
5944 int col
= coords
.GetCol();
5946 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
5949 // we draw the cell border ourselves
5950 #if !WXGRID_DRAW_LINES
5951 if ( m_gridLinesEnabled
)
5952 DrawCellBorder( dc
, coords
);
5955 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5957 bool isCurrent
= coords
== m_currentCellCoords
;
5959 wxRect rect
= CellToRect( row
, col
);
5961 // if the editor is shown, we should use it and not the renderer
5962 // Note: However, only if it is really _shown_, i.e. not hidden!
5963 if ( isCurrent
&& IsCellEditControlShown() )
5965 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
5966 editor
->PaintBackground(rect
, attr
);
5971 // but all the rest is drawn by the cell renderer and hence may be
5973 wxGridCellRenderer
*renderer
= attr
->GetRenderer(this, row
, col
);
5974 renderer
->Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
5981 void wxGrid::DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
)
5983 int row
= m_currentCellCoords
.GetRow();
5984 int col
= m_currentCellCoords
.GetCol();
5986 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
5989 wxRect rect
= CellToRect(row
, col
);
5991 // hmmm... what could we do here to show that the cell is disabled?
5992 // for now, I just draw a thinner border than for the other ones, but
5993 // it doesn't look really good
5994 dc
.SetPen(wxPen(m_cellHighlightColour
, attr
->IsReadOnly() ? 1 : 3, wxSOLID
));
5995 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
5997 dc
.DrawRectangle(rect
);
6000 // VZ: my experiments with 3d borders...
6002 // how to properly set colours for arbitrary bg?
6003 wxCoord x1
= rect
.x
,
6005 x2
= rect
.x
+ rect
.width
-1,
6006 y2
= rect
.y
+ rect
.height
-1;
6008 dc
.SetPen(*wxWHITE_PEN
);
6009 dc
.DrawLine(x1
, y1
, x2
, y1
);
6010 dc
.DrawLine(x1
, y1
, x1
, y2
);
6012 dc
.DrawLine(x1
+ 1, y2
- 1, x2
- 1, y2
- 1);
6013 dc
.DrawLine(x2
- 1, y1
+ 1, x2
- 1, y2
);
6015 dc
.SetPen(*wxBLACK_PEN
);
6016 dc
.DrawLine(x1
, y2
, x2
, y2
);
6017 dc
.DrawLine(x2
, y1
, x2
, y2
+1);
6022 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
6024 int row
= coords
.GetRow();
6025 int col
= coords
.GetCol();
6026 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6029 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
6031 // right hand border
6033 dc
.DrawLine( GetColRight(col
), GetRowTop(row
),
6034 GetColRight(col
), GetRowBottom(row
) );
6038 dc
.DrawLine( GetColLeft(col
), GetRowBottom(row
),
6039 GetColRight(col
), GetRowBottom(row
) );
6042 void wxGrid::DrawHighlight(wxDC
& dc
)
6044 // This if block was previously in wxGrid::OnPaint but that doesn't
6045 // seem to get called under wxGTK - MB
6047 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
6048 m_numRows
&& m_numCols
)
6050 m_currentCellCoords
.Set(0, 0);
6053 if ( IsCellEditControlShown() )
6055 // don't show highlight when the edit control is shown
6059 // if the active cell was repainted, repaint its highlight too because it
6060 // might have been damaged by the grid lines
6061 size_t count
= m_cellsExposed
.GetCount();
6062 for ( size_t n
= 0; n
< count
; n
++ )
6064 if ( m_cellsExposed
[n
] == m_currentCellCoords
)
6066 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
6067 DrawCellHighlight(dc
, attr
);
6075 // TODO: remove this ???
6076 // This is used to redraw all grid lines e.g. when the grid line colour
6079 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& WXUNUSED(reg
) )
6081 if ( !m_gridLinesEnabled
||
6083 !m_numCols
) return;
6085 int top
, bottom
, left
, right
;
6087 #if 0 //#ifndef __WXGTK__
6091 m_gridWin
->GetClientSize(&cw
, &ch
);
6093 // virtual coords of visible area
6095 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6096 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6101 reg
.GetBox(x
, y
, w
, h
);
6102 CalcUnscrolledPosition( x
, y
, &left
, &top
);
6103 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
6107 m_gridWin
->GetClientSize(&cw
, &ch
);
6108 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6109 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6112 // avoid drawing grid lines past the last row and col
6114 right
= wxMin( right
, GetColRight(m_numCols
- 1) );
6115 bottom
= wxMin( bottom
, GetRowBottom(m_numRows
- 1) );
6117 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
6119 // horizontal grid lines
6122 for ( i
= 0; i
< m_numRows
; i
++ )
6124 int bot
= GetRowBottom(i
) - 1;
6133 dc
.DrawLine( left
, bot
, right
, bot
);
6138 // vertical grid lines
6140 for ( i
= 0; i
< m_numCols
; i
++ )
6142 int colRight
= GetColRight(i
) - 1;
6143 if ( colRight
> right
)
6148 if ( colRight
>= left
)
6150 dc
.DrawLine( colRight
, top
, colRight
, bottom
);
6156 void wxGrid::DrawRowLabels( wxDC
& dc
)
6158 if ( !m_numRows
) return;
6161 size_t numLabels
= m_rowLabelsExposed
.GetCount();
6163 for ( i
= 0; i
< numLabels
; i
++ )
6165 DrawRowLabel( dc
, m_rowLabelsExposed
[i
] );
6170 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
6172 if ( GetRowHeight(row
) <= 0 )
6175 int rowTop
= GetRowTop(row
),
6176 rowBottom
= GetRowBottom(row
) - 1;
6178 dc
.SetPen( *wxBLACK_PEN
);
6179 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
6180 m_rowLabelWidth
-1, rowBottom
);
6182 dc
.DrawLine( 0, rowBottom
, m_rowLabelWidth
-1, rowBottom
);
6184 dc
.SetPen( *wxWHITE_PEN
);
6185 dc
.DrawLine( 0, rowTop
, 0, rowBottom
);
6186 dc
.DrawLine( 0, rowTop
, m_rowLabelWidth
-1, rowTop
);
6188 dc
.SetBackgroundMode( wxTRANSPARENT
);
6189 dc
.SetTextForeground( GetLabelTextColour() );
6190 dc
.SetFont( GetLabelFont() );
6193 GetRowLabelAlignment( &hAlign
, &vAlign
);
6197 rect
.SetY( GetRowTop(row
) + 2 );
6198 rect
.SetWidth( m_rowLabelWidth
- 4 );
6199 rect
.SetHeight( GetRowHeight(row
) - 4 );
6200 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
6204 void wxGrid::DrawColLabels( wxDC
& dc
)
6206 if ( !m_numCols
) return;
6209 size_t numLabels
= m_colLabelsExposed
.GetCount();
6211 for ( i
= 0; i
< numLabels
; i
++ )
6213 DrawColLabel( dc
, m_colLabelsExposed
[i
] );
6218 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
6220 if ( GetColWidth(col
) <= 0 )
6223 int colLeft
= GetColLeft(col
),
6224 colRight
= GetColRight(col
) - 1;
6226 dc
.SetPen( *wxBLACK_PEN
);
6227 dc
.DrawLine( colRight
, 0,
6228 colRight
, m_colLabelHeight
-1 );
6230 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
6231 colRight
, m_colLabelHeight
-1 );
6233 dc
.SetPen( *wxWHITE_PEN
);
6234 dc
.DrawLine( colLeft
, 0, colLeft
, m_colLabelHeight
-1 );
6235 dc
.DrawLine( colLeft
, 0, colRight
, 0 );
6237 dc
.SetBackgroundMode( wxTRANSPARENT
);
6238 dc
.SetTextForeground( GetLabelTextColour() );
6239 dc
.SetFont( GetLabelFont() );
6241 dc
.SetBackgroundMode( wxTRANSPARENT
);
6242 dc
.SetTextForeground( GetLabelTextColour() );
6243 dc
.SetFont( GetLabelFont() );
6246 GetColLabelAlignment( &hAlign
, &vAlign
);
6249 rect
.SetX( colLeft
+ 2 );
6251 rect
.SetWidth( GetColWidth(col
) - 4 );
6252 rect
.SetHeight( m_colLabelHeight
- 4 );
6253 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
);
6257 void wxGrid::DrawTextRectangle( wxDC
& dc
,
6258 const wxString
& value
,
6263 long textWidth
, textHeight
;
6264 long lineWidth
, lineHeight
;
6265 wxArrayString lines
;
6267 dc
.SetClippingRegion( rect
);
6268 StringToLines( value
, lines
);
6269 if ( lines
.GetCount() )
6271 GetTextBoxSize( dc
, lines
, &textWidth
, &textHeight
);
6272 dc
.GetTextExtent( lines
[0], &lineWidth
, &lineHeight
);
6275 switch ( horizAlign
)
6278 x
= rect
.x
+ (rect
.width
- textWidth
- 1);
6281 case wxALIGN_CENTRE
:
6282 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
6291 switch ( vertAlign
)
6293 case wxALIGN_BOTTOM
:
6294 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
6297 case wxALIGN_CENTRE
:
6298 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
6307 for ( size_t i
= 0; i
< lines
.GetCount(); i
++ )
6309 dc
.DrawText( lines
[i
], (int)x
, (int)y
);
6314 dc
.DestroyClippingRegion();
6318 // Split multi line text up into an array of strings. Any existing
6319 // contents of the string array are preserved.
6321 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
6325 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
6326 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
6328 while ( startPos
< (int)tVal
.Length() )
6330 pos
= tVal
.Mid(startPos
).Find( eol
);
6335 else if ( pos
== 0 )
6337 lines
.Add( wxEmptyString
);
6341 lines
.Add( value
.Mid(startPos
, pos
) );
6345 if ( startPos
< (int)value
.Length() )
6347 lines
.Add( value
.Mid( startPos
) );
6352 void wxGrid::GetTextBoxSize( wxDC
& dc
,
6353 wxArrayString
& lines
,
6354 long *width
, long *height
)
6361 for ( i
= 0; i
< lines
.GetCount(); i
++ )
6363 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
6364 w
= wxMax( w
, lineW
);
6373 // ------ Batch processing.
6375 void wxGrid::EndBatch()
6377 if ( m_batchCount
> 0 )
6380 if ( !m_batchCount
)
6383 m_rowLabelWin
->Refresh();
6384 m_colLabelWin
->Refresh();
6385 m_cornerLabelWin
->Refresh();
6386 m_gridWin
->Refresh();
6391 // Use this, rather than wxWindow::Refresh(), to force an immediate
6392 // repainting of the grid. Has no effect if you are already inside a
6393 // BeginBatch / EndBatch block.
6395 void wxGrid::ForceRefresh()
6403 // ------ Edit control functions
6407 void wxGrid::EnableEditing( bool edit
)
6409 // TODO: improve this ?
6411 if ( edit
!= m_editable
)
6413 if(!edit
) EnableCellEditControl(edit
);
6419 void wxGrid::EnableCellEditControl( bool enable
)
6424 if ( m_currentCellCoords
== wxGridNoCellCoords
)
6425 SetCurrentCell( 0, 0 );
6427 if ( enable
!= m_cellEditCtrlEnabled
)
6429 // TODO allow the app to Veto() this event?
6430 SendEvent(enable
? wxEVT_GRID_EDITOR_SHOWN
: wxEVT_GRID_EDITOR_HIDDEN
);
6434 // this should be checked by the caller!
6435 wxASSERT_MSG( CanEnableCellControl(),
6436 _T("can't enable editing for this cell!") );
6438 // do it before ShowCellEditControl()
6439 m_cellEditCtrlEnabled
= enable
;
6441 ShowCellEditControl();
6445 HideCellEditControl();
6446 SaveEditControlValue();
6448 // do it after HideCellEditControl()
6449 m_cellEditCtrlEnabled
= enable
;
6454 bool wxGrid::IsCurrentCellReadOnly() const
6457 wxGridCellAttr
* attr
= ((wxGrid
*)this)->GetCellAttr(m_currentCellCoords
);
6458 bool readonly
= attr
->IsReadOnly();
6464 bool wxGrid::CanEnableCellControl() const
6466 return m_editable
&& !IsCurrentCellReadOnly();
6469 bool wxGrid::IsCellEditControlEnabled() const
6471 // the cell edit control might be disable for all cells or just for the
6472 // current one if it's read only
6473 return m_cellEditCtrlEnabled
? !IsCurrentCellReadOnly() : FALSE
;
6476 bool wxGrid::IsCellEditControlShown() const
6478 bool isShown
= FALSE
;
6480 if ( m_cellEditCtrlEnabled
)
6482 int row
= m_currentCellCoords
.GetRow();
6483 int col
= m_currentCellCoords
.GetCol();
6484 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6485 wxGridCellEditor
* editor
= attr
->GetEditor((wxGrid
*) this, row
, col
);
6490 if ( editor
->IsCreated() )
6492 isShown
= editor
->GetControl()->IsShown();
6502 void wxGrid::ShowCellEditControl()
6504 if ( IsCellEditControlEnabled() )
6506 if ( !IsVisible( m_currentCellCoords
) )
6508 m_cellEditCtrlEnabled
= FALSE
;
6513 wxRect rect
= CellToRect( m_currentCellCoords
);
6514 int row
= m_currentCellCoords
.GetRow();
6515 int col
= m_currentCellCoords
.GetCol();
6517 // convert to scrolled coords
6519 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
6521 // done in PaintBackground()
6523 // erase the highlight and the cell contents because the editor
6524 // might not cover the entire cell
6525 wxClientDC
dc( m_gridWin
);
6527 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
); //wxBrush(attr->GetBackgroundColour(), wxSOLID));
6528 dc
.SetPen(*wxTRANSPARENT_PEN
);
6529 dc
.DrawRectangle(rect
);
6532 // cell is shifted by one pixel
6536 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6537 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
6538 if ( !editor
->IsCreated() )
6540 editor
->Create(m_gridWin
, -1,
6541 new wxGridCellEditorEvtHandler(this, editor
));
6544 editor
->Show( TRUE
, attr
);
6546 editor
->SetSize( rect
);
6548 editor
->BeginEdit(row
, col
, this);
6557 void wxGrid::HideCellEditControl()
6559 if ( IsCellEditControlEnabled() )
6561 int row
= m_currentCellCoords
.GetRow();
6562 int col
= m_currentCellCoords
.GetCol();
6564 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6565 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
6566 editor
->Show( FALSE
);
6569 m_gridWin
->SetFocus();
6570 wxRect
rect( CellToRect( row
, col
) );
6571 m_gridWin
->Refresh( FALSE
, &rect
);
6576 void wxGrid::SaveEditControlValue()
6578 if ( IsCellEditControlEnabled() )
6580 int row
= m_currentCellCoords
.GetRow();
6581 int col
= m_currentCellCoords
.GetCol();
6583 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6584 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
6585 bool changed
= editor
->EndEdit(row
, col
, this);
6592 SendEvent( wxEVT_GRID_CELL_CHANGE
,
6593 m_currentCellCoords
.GetRow(),
6594 m_currentCellCoords
.GetCol() );
6601 // ------ Grid location functions
6602 // Note that all of these functions work with the logical coordinates of
6603 // grid cells and labels so you will need to convert from device
6604 // coordinates for mouse events etc.
6607 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
6609 int row
= YToRow(y
);
6610 int col
= XToCol(x
);
6612 if ( row
== -1 || col
== -1 )
6614 coords
= wxGridNoCellCoords
;
6618 coords
.Set( row
, col
);
6623 int wxGrid::YToRow( int y
)
6627 for ( i
= 0; i
< m_numRows
; i
++ )
6629 if ( y
< GetRowBottom(i
) )
6637 int wxGrid::XToCol( int x
)
6641 for ( i
= 0; i
< m_numCols
; i
++ )
6643 if ( x
< GetColRight(i
) )
6651 // return the row number that that the y coord is near the edge of, or
6652 // -1 if not near an edge
6654 int wxGrid::YToEdgeOfRow( int y
)
6658 for ( i
= 0; i
< m_numRows
; i
++ )
6660 if ( GetRowHeight(i
) > WXGRID_LABEL_EDGE_ZONE
)
6662 d
= abs( y
- GetRowBottom(i
) );
6663 if ( d
< WXGRID_LABEL_EDGE_ZONE
)
6672 // return the col number that that the x coord is near the edge of, or
6673 // -1 if not near an edge
6675 int wxGrid::XToEdgeOfCol( int x
)
6679 for ( i
= 0; i
< m_numCols
; i
++ )
6681 if ( GetColWidth(i
) > WXGRID_LABEL_EDGE_ZONE
)
6683 d
= abs( x
- GetColRight(i
) );
6684 if ( d
< WXGRID_LABEL_EDGE_ZONE
)
6693 wxRect
wxGrid::CellToRect( int row
, int col
)
6695 wxRect
rect( -1, -1, -1, -1 );
6697 if ( row
>= 0 && row
< m_numRows
&&
6698 col
>= 0 && col
< m_numCols
)
6700 rect
.x
= GetColLeft(col
);
6701 rect
.y
= GetRowTop(row
);
6702 rect
.width
= GetColWidth(col
);
6703 rect
.height
= GetRowHeight(row
);
6706 // if grid lines are enabled, then the area of the cell is a bit smaller
6707 if (m_gridLinesEnabled
) {
6715 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
6717 // get the cell rectangle in logical coords
6719 wxRect
r( CellToRect( row
, col
) );
6721 // convert to device coords
6723 int left
, top
, right
, bottom
;
6724 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
6725 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
6727 // check against the client area of the grid window
6730 m_gridWin
->GetClientSize( &cw
, &ch
);
6732 if ( wholeCellVisible
)
6734 // is the cell wholly visible ?
6736 return ( left
>= 0 && right
<= cw
&&
6737 top
>= 0 && bottom
<= ch
);
6741 // is the cell partly visible ?
6743 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
6744 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
6749 // make the specified cell location visible by doing a minimal amount
6752 void wxGrid::MakeCellVisible( int row
, int col
)
6755 int xpos
= -1, ypos
= -1;
6757 if ( row
>= 0 && row
< m_numRows
&&
6758 col
>= 0 && col
< m_numCols
)
6760 // get the cell rectangle in logical coords
6762 wxRect
r( CellToRect( row
, col
) );
6764 // convert to device coords
6766 int left
, top
, right
, bottom
;
6767 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
6768 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
6771 m_gridWin
->GetClientSize( &cw
, &ch
);
6777 else if ( bottom
> ch
)
6779 int h
= r
.GetHeight();
6781 for ( i
= row
-1; i
>= 0; i
-- )
6783 int rowHeight
= GetRowHeight(i
);
6784 if ( h
+ rowHeight
> ch
)
6791 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
6792 // have rounding errors (this is important, because if we do, we
6793 // might not scroll at all and some cells won't be redrawn)
6794 ypos
+= GRID_SCROLL_LINE
/ 2;
6801 else if ( right
> cw
)
6803 int w
= r
.GetWidth();
6805 for ( i
= col
-1; i
>= 0; i
-- )
6807 int colWidth
= GetColWidth(i
);
6808 if ( w
+ colWidth
> cw
)
6815 // see comment for ypos above
6816 xpos
+= GRID_SCROLL_LINE
/ 2;
6819 if ( xpos
!= -1 || ypos
!= -1 )
6821 if ( xpos
!= -1 ) xpos
/= GRID_SCROLL_LINE
;
6822 if ( ypos
!= -1 ) ypos
/= GRID_SCROLL_LINE
;
6823 Scroll( xpos
, ypos
);
6831 // ------ Grid cursor movement functions
6834 bool wxGrid::MoveCursorUp( bool expandSelection
)
6836 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
6837 m_currentCellCoords
.GetRow() >= 0 )
6839 if ( expandSelection
)
6841 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
6842 m_selectingKeyboard
= m_currentCellCoords
;
6843 if ( m_selectingKeyboard
.GetRow() > 0 )
6845 m_selectingKeyboard
.SetRow( m_selectingKeyboard
.GetRow() - 1 );
6846 MakeCellVisible( m_selectingKeyboard
.GetRow(),
6847 m_selectingKeyboard
.GetCol() );
6848 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
6851 else if ( m_currentCellCoords
.GetRow() > 0 )
6854 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
6855 m_currentCellCoords
.GetCol() );
6856 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
6857 m_currentCellCoords
.GetCol() );
6868 bool wxGrid::MoveCursorDown( bool expandSelection
)
6870 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
6871 m_currentCellCoords
.GetRow() < m_numRows
)
6873 if ( expandSelection
)
6875 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
6876 m_selectingKeyboard
= m_currentCellCoords
;
6877 if ( m_selectingKeyboard
.GetRow() < m_numRows
-1 )
6879 m_selectingKeyboard
.SetRow( m_selectingKeyboard
.GetRow() + 1 );
6880 MakeCellVisible( m_selectingKeyboard
.GetRow(),
6881 m_selectingKeyboard
.GetCol() );
6882 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
6885 else if ( m_currentCellCoords
.GetRow() < m_numRows
- 1 )
6888 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
6889 m_currentCellCoords
.GetCol() );
6890 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
6891 m_currentCellCoords
.GetCol() );
6902 bool wxGrid::MoveCursorLeft( bool expandSelection
)
6904 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
6905 m_currentCellCoords
.GetCol() >= 0 )
6907 if ( expandSelection
)
6909 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
6910 m_selectingKeyboard
= m_currentCellCoords
;
6911 if ( m_selectingKeyboard
.GetCol() > 0 )
6913 m_selectingKeyboard
.SetCol( m_selectingKeyboard
.GetCol() - 1 );
6914 MakeCellVisible( m_selectingKeyboard
.GetRow(),
6915 m_selectingKeyboard
.GetCol() );
6916 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
6919 else if ( m_currentCellCoords
.GetCol() > 0 )
6922 MakeCellVisible( m_currentCellCoords
.GetRow(),
6923 m_currentCellCoords
.GetCol() - 1 );
6924 SetCurrentCell( m_currentCellCoords
.GetRow(),
6925 m_currentCellCoords
.GetCol() - 1 );
6936 bool wxGrid::MoveCursorRight( bool expandSelection
)
6938 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
6939 m_currentCellCoords
.GetCol() < m_numCols
)
6941 if ( expandSelection
)
6943 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
6944 m_selectingKeyboard
= m_currentCellCoords
;
6945 if ( m_selectingKeyboard
.GetCol() < m_numCols
- 1 )
6947 m_selectingKeyboard
.SetCol( m_selectingKeyboard
.GetCol() + 1 );
6948 MakeCellVisible( m_selectingKeyboard
.GetRow(),
6949 m_selectingKeyboard
.GetCol() );
6950 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
6953 else if ( m_currentCellCoords
.GetCol() < m_numCols
- 1 )
6956 MakeCellVisible( m_currentCellCoords
.GetRow(),
6957 m_currentCellCoords
.GetCol() + 1 );
6958 SetCurrentCell( m_currentCellCoords
.GetRow(),
6959 m_currentCellCoords
.GetCol() + 1 );
6970 bool wxGrid::MovePageUp()
6972 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
6974 int row
= m_currentCellCoords
.GetRow();
6978 m_gridWin
->GetClientSize( &cw
, &ch
);
6980 int y
= GetRowTop(row
);
6981 int newRow
= YToRow( y
- ch
+ 1 );
6986 else if ( newRow
== row
)
6991 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
6992 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
7000 bool wxGrid::MovePageDown()
7002 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
7004 int row
= m_currentCellCoords
.GetRow();
7005 if ( row
< m_numRows
)
7008 m_gridWin
->GetClientSize( &cw
, &ch
);
7010 int y
= GetRowTop(row
);
7011 int newRow
= YToRow( y
+ ch
);
7014 newRow
= m_numRows
- 1;
7016 else if ( newRow
== row
)
7021 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
7022 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
7030 bool wxGrid::MoveCursorUpBlock( bool expandSelection
)
7033 m_currentCellCoords
!= wxGridNoCellCoords
&&
7034 m_currentCellCoords
.GetRow() > 0 )
7036 int row
= m_currentCellCoords
.GetRow();
7037 int col
= m_currentCellCoords
.GetCol();
7039 if ( m_table
->IsEmptyCell(row
, col
) )
7041 // starting in an empty cell: find the next block of
7047 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
7050 else if ( m_table
->IsEmptyCell(row
-1, col
) )
7052 // starting at the top of a block: find the next block
7058 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
7063 // starting within a block: find the top of the block
7068 if ( m_table
->IsEmptyCell(row
, col
) )
7076 MakeCellVisible( row
, col
);
7077 if ( expandSelection
)
7079 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
7080 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7085 SetCurrentCell( row
, col
);
7093 bool wxGrid::MoveCursorDownBlock( bool expandSelection
)
7096 m_currentCellCoords
!= wxGridNoCellCoords
&&
7097 m_currentCellCoords
.GetRow() < m_numRows
-1 )
7099 int row
= m_currentCellCoords
.GetRow();
7100 int col
= m_currentCellCoords
.GetCol();
7102 if ( m_table
->IsEmptyCell(row
, col
) )
7104 // starting in an empty cell: find the next block of
7107 while ( row
< m_numRows
-1 )
7110 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
7113 else if ( m_table
->IsEmptyCell(row
+1, col
) )
7115 // starting at the bottom of a block: find the next block
7118 while ( row
< m_numRows
-1 )
7121 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
7126 // starting within a block: find the bottom of the block
7128 while ( row
< m_numRows
-1 )
7131 if ( m_table
->IsEmptyCell(row
, col
) )
7139 MakeCellVisible( row
, col
);
7140 if ( expandSelection
)
7142 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
7143 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7148 SetCurrentCell( row
, col
);
7157 bool wxGrid::MoveCursorLeftBlock( bool expandSelection
)
7160 m_currentCellCoords
!= wxGridNoCellCoords
&&
7161 m_currentCellCoords
.GetCol() > 0 )
7163 int row
= m_currentCellCoords
.GetRow();
7164 int col
= m_currentCellCoords
.GetCol();
7166 if ( m_table
->IsEmptyCell(row
, col
) )
7168 // starting in an empty cell: find the next block of
7174 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
7177 else if ( m_table
->IsEmptyCell(row
, col
-1) )
7179 // starting at the left of a block: find the next block
7185 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
7190 // starting within a block: find the left of the block
7195 if ( m_table
->IsEmptyCell(row
, col
) )
7203 MakeCellVisible( row
, col
);
7204 if ( expandSelection
)
7206 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
7207 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7212 SetCurrentCell( row
, col
);
7221 bool wxGrid::MoveCursorRightBlock( bool expandSelection
)
7224 m_currentCellCoords
!= wxGridNoCellCoords
&&
7225 m_currentCellCoords
.GetCol() < m_numCols
-1 )
7227 int row
= m_currentCellCoords
.GetRow();
7228 int col
= m_currentCellCoords
.GetCol();
7230 if ( m_table
->IsEmptyCell(row
, col
) )
7232 // starting in an empty cell: find the next block of
7235 while ( col
< m_numCols
-1 )
7238 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
7241 else if ( m_table
->IsEmptyCell(row
, col
+1) )
7243 // starting at the right of a block: find the next block
7246 while ( col
< m_numCols
-1 )
7249 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
7254 // starting within a block: find the right of the block
7256 while ( col
< m_numCols
-1 )
7259 if ( m_table
->IsEmptyCell(row
, col
) )
7267 MakeCellVisible( row
, col
);
7268 if ( expandSelection
)
7270 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
7271 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7276 SetCurrentCell( row
, col
);
7288 // ------ Label values and formatting
7291 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
7293 *horiz
= m_rowLabelHorizAlign
;
7294 *vert
= m_rowLabelVertAlign
;
7297 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
7299 *horiz
= m_colLabelHorizAlign
;
7300 *vert
= m_colLabelVertAlign
;
7303 wxString
wxGrid::GetRowLabelValue( int row
)
7307 return m_table
->GetRowLabelValue( row
);
7317 wxString
wxGrid::GetColLabelValue( int col
)
7321 return m_table
->GetColLabelValue( col
);
7332 void wxGrid::SetRowLabelSize( int width
)
7334 width
= wxMax( width
, 0 );
7335 if ( width
!= m_rowLabelWidth
)
7339 m_rowLabelWin
->Show( FALSE
);
7340 m_cornerLabelWin
->Show( FALSE
);
7342 else if ( m_rowLabelWidth
== 0 )
7344 m_rowLabelWin
->Show( TRUE
);
7345 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
7348 m_rowLabelWidth
= width
;
7355 void wxGrid::SetColLabelSize( int height
)
7357 height
= wxMax( height
, 0 );
7358 if ( height
!= m_colLabelHeight
)
7362 m_colLabelWin
->Show( FALSE
);
7363 m_cornerLabelWin
->Show( FALSE
);
7365 else if ( m_colLabelHeight
== 0 )
7367 m_colLabelWin
->Show( TRUE
);
7368 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
7371 m_colLabelHeight
= height
;
7378 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
7380 if ( m_labelBackgroundColour
!= colour
)
7382 m_labelBackgroundColour
= colour
;
7383 m_rowLabelWin
->SetBackgroundColour( colour
);
7384 m_colLabelWin
->SetBackgroundColour( colour
);
7385 m_cornerLabelWin
->SetBackgroundColour( colour
);
7387 if ( !GetBatchCount() )
7389 m_rowLabelWin
->Refresh();
7390 m_colLabelWin
->Refresh();
7391 m_cornerLabelWin
->Refresh();
7396 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
7398 if ( m_labelTextColour
!= colour
)
7400 m_labelTextColour
= colour
;
7401 if ( !GetBatchCount() )
7403 m_rowLabelWin
->Refresh();
7404 m_colLabelWin
->Refresh();
7409 void wxGrid::SetLabelFont( const wxFont
& font
)
7412 if ( !GetBatchCount() )
7414 m_rowLabelWin
->Refresh();
7415 m_colLabelWin
->Refresh();
7419 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
7421 // allow old (incorrect) defs to be used
7424 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
7425 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
7426 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
7431 case wxTOP
: vert
= wxALIGN_TOP
; break;
7432 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
7433 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
7436 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
7438 m_rowLabelHorizAlign
= horiz
;
7441 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
7443 m_rowLabelVertAlign
= vert
;
7446 if ( !GetBatchCount() )
7448 m_rowLabelWin
->Refresh();
7452 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
7454 // allow old (incorrect) defs to be used
7457 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
7458 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
7459 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
7464 case wxTOP
: vert
= wxALIGN_TOP
; break;
7465 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
7466 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
7469 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
7471 m_colLabelHorizAlign
= horiz
;
7474 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
7476 m_colLabelVertAlign
= vert
;
7479 if ( !GetBatchCount() )
7481 m_colLabelWin
->Refresh();
7485 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
7489 m_table
->SetRowLabelValue( row
, s
);
7490 if ( !GetBatchCount() )
7492 wxRect rect
= CellToRect( row
, 0);
7493 if ( rect
.height
> 0 )
7495 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
7497 rect
.width
= m_rowLabelWidth
;
7498 m_rowLabelWin
->Refresh( TRUE
, &rect
);
7504 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
7508 m_table
->SetColLabelValue( col
, s
);
7509 if ( !GetBatchCount() )
7511 wxRect rect
= CellToRect( 0, col
);
7512 if ( rect
.width
> 0 )
7514 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
7516 rect
.height
= m_colLabelHeight
;
7517 m_colLabelWin
->Refresh( TRUE
, &rect
);
7523 void wxGrid::SetGridLineColour( const wxColour
& colour
)
7525 if ( m_gridLineColour
!= colour
)
7527 m_gridLineColour
= colour
;
7529 wxClientDC
dc( m_gridWin
);
7531 DrawAllGridLines( dc
, wxRegion() );
7536 void wxGrid::SetCellHighlightColour( const wxColour
& colour
)
7538 if ( m_cellHighlightColour
!= colour
)
7540 m_cellHighlightColour
= colour
;
7542 wxClientDC
dc( m_gridWin
);
7544 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
7545 DrawCellHighlight(dc
, attr
);
7550 void wxGrid::EnableGridLines( bool enable
)
7552 if ( enable
!= m_gridLinesEnabled
)
7554 m_gridLinesEnabled
= enable
;
7556 if ( !GetBatchCount() )
7560 wxClientDC
dc( m_gridWin
);
7562 DrawAllGridLines( dc
, wxRegion() );
7566 m_gridWin
->Refresh();
7573 int wxGrid::GetDefaultRowSize()
7575 return m_defaultRowHeight
;
7578 int wxGrid::GetRowSize( int row
)
7580 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
7582 return GetRowHeight(row
);
7585 int wxGrid::GetDefaultColSize()
7587 return m_defaultColWidth
;
7590 int wxGrid::GetColSize( int col
)
7592 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
7594 return GetColWidth(col
);
7597 // ============================================================================
7598 // access to the grid attributes: each of them has a default value in the grid
7599 // itself and may be overidden on a per-cell basis
7600 // ============================================================================
7602 // ----------------------------------------------------------------------------
7603 // setting default attributes
7604 // ----------------------------------------------------------------------------
7606 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
7608 m_defaultCellAttr
->SetBackgroundColour(col
);
7610 m_gridWin
->SetBackgroundColour(col
);
7614 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
7616 m_defaultCellAttr
->SetTextColour(col
);
7619 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
7621 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
7624 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
7626 m_defaultCellAttr
->SetFont(font
);
7629 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
7631 m_defaultCellAttr
->SetRenderer(renderer
);
7634 void wxGrid::SetDefaultEditor(wxGridCellEditor
*editor
)
7636 m_defaultCellAttr
->SetEditor(editor
);
7639 // ----------------------------------------------------------------------------
7640 // access to the default attrbiutes
7641 // ----------------------------------------------------------------------------
7643 wxColour
wxGrid::GetDefaultCellBackgroundColour()
7645 return m_defaultCellAttr
->GetBackgroundColour();
7648 wxColour
wxGrid::GetDefaultCellTextColour()
7650 return m_defaultCellAttr
->GetTextColour();
7653 wxFont
wxGrid::GetDefaultCellFont()
7655 return m_defaultCellAttr
->GetFont();
7658 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
7660 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
7663 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
7665 return m_defaultCellAttr
->GetRenderer(NULL
, 0, 0);
7668 wxGridCellEditor
*wxGrid::GetDefaultEditor() const
7670 return m_defaultCellAttr
->GetEditor(NULL
,0,0);
7673 // ----------------------------------------------------------------------------
7674 // access to cell attributes
7675 // ----------------------------------------------------------------------------
7677 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
7679 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
7680 wxColour colour
= attr
->GetBackgroundColour();
7685 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
7687 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
7688 wxColour colour
= attr
->GetTextColour();
7693 wxFont
wxGrid::GetCellFont( int row
, int col
)
7695 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
7696 wxFont font
= attr
->GetFont();
7701 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
7703 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
7704 attr
->GetAlignment(horiz
, vert
);
7708 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
)
7710 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7711 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
7717 wxGridCellEditor
* wxGrid::GetCellEditor(int row
, int col
)
7719 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7720 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
7726 bool wxGrid::IsReadOnly(int row
, int col
) const
7728 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7729 bool isReadOnly
= attr
->IsReadOnly();
7734 // ----------------------------------------------------------------------------
7735 // attribute support: cache, automatic provider creation, ...
7736 // ----------------------------------------------------------------------------
7738 bool wxGrid::CanHaveAttributes()
7745 return m_table
->CanHaveAttributes();
7748 void wxGrid::ClearAttrCache()
7750 if ( m_attrCache
.row
!= -1 )
7752 wxSafeDecRef(m_attrCache
.attr
);
7753 m_attrCache
.row
= -1;
7757 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
7759 wxGrid
*self
= (wxGrid
*)this; // const_cast
7761 self
->ClearAttrCache();
7762 self
->m_attrCache
.row
= row
;
7763 self
->m_attrCache
.col
= col
;
7764 self
->m_attrCache
.attr
= attr
;
7768 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
7770 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
7772 *attr
= m_attrCache
.attr
;
7773 wxSafeIncRef(m_attrCache
.attr
);
7775 #ifdef DEBUG_ATTR_CACHE
7776 gs_nAttrCacheHits
++;
7783 #ifdef DEBUG_ATTR_CACHE
7784 gs_nAttrCacheMisses
++;
7790 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
7792 wxGridCellAttr
*attr
;
7793 if ( !LookupAttr(row
, col
, &attr
) )
7795 attr
= m_table
? m_table
->GetAttr(row
, col
) : (wxGridCellAttr
*)NULL
;
7796 CacheAttr(row
, col
, attr
);
7800 attr
->SetDefAttr(m_defaultCellAttr
);
7804 attr
= m_defaultCellAttr
;
7811 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
7813 wxGridCellAttr
*attr
;
7814 if ( !LookupAttr(row
, col
, &attr
) || !attr
)
7816 wxASSERT_MSG( m_table
,
7817 _T("we may only be called if CanHaveAttributes() returned TRUE and then m_table should be !NULL") );
7819 attr
= m_table
->GetAttr(row
, col
);
7822 attr
= new wxGridCellAttr
;
7824 // artificially inc the ref count to match DecRef() in caller
7827 m_table
->SetAttr(attr
, row
, col
);
7830 CacheAttr(row
, col
, attr
);
7832 attr
->SetDefAttr(m_defaultCellAttr
);
7836 // ----------------------------------------------------------------------------
7837 // setting column attributes (wrappers around SetColAttr)
7838 // ----------------------------------------------------------------------------
7840 void wxGrid::SetColFormatBool(int col
)
7842 SetColFormatCustom(col
, wxGRID_VALUE_BOOL
);
7845 void wxGrid::SetColFormatNumber(int col
)
7847 SetColFormatCustom(col
, wxGRID_VALUE_NUMBER
);
7850 void wxGrid::SetColFormatFloat(int col
, int width
, int precision
)
7852 wxString typeName
= wxGRID_VALUE_FLOAT
;
7853 if ( (width
!= -1) || (precision
!= -1) )
7855 typeName
<< _T(':') << width
<< _T(',') << precision
;
7858 SetColFormatCustom(col
, typeName
);
7861 void wxGrid::SetColFormatCustom(int col
, const wxString
& typeName
)
7863 wxGridCellAttr
*attr
= new wxGridCellAttr
;
7864 wxGridCellRenderer
*renderer
= GetDefaultRendererForType(typeName
);
7865 attr
->SetRenderer(renderer
);
7867 SetColAttr(col
, attr
);
7870 // ----------------------------------------------------------------------------
7871 // setting cell attributes: this is forwarded to the table
7872 // ----------------------------------------------------------------------------
7874 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
7876 if ( CanHaveAttributes() )
7878 m_table
->SetRowAttr(attr
, row
);
7886 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
7888 if ( CanHaveAttributes() )
7890 m_table
->SetColAttr(attr
, col
);
7898 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
7900 if ( CanHaveAttributes() )
7902 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7903 attr
->SetBackgroundColour(colour
);
7908 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
7910 if ( CanHaveAttributes() )
7912 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7913 attr
->SetTextColour(colour
);
7918 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
7920 if ( CanHaveAttributes() )
7922 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7923 attr
->SetFont(font
);
7928 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
7930 if ( CanHaveAttributes() )
7932 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7933 attr
->SetAlignment(horiz
, vert
);
7938 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
7940 if ( CanHaveAttributes() )
7942 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7943 attr
->SetRenderer(renderer
);
7948 void wxGrid::SetCellEditor(int row
, int col
, wxGridCellEditor
* editor
)
7950 if ( CanHaveAttributes() )
7952 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7953 attr
->SetEditor(editor
);
7958 void wxGrid::SetReadOnly(int row
, int col
, bool isReadOnly
)
7960 if ( CanHaveAttributes() )
7962 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7963 attr
->SetReadOnly(isReadOnly
);
7968 // ----------------------------------------------------------------------------
7969 // Data type registration
7970 // ----------------------------------------------------------------------------
7972 void wxGrid::RegisterDataType(const wxString
& typeName
,
7973 wxGridCellRenderer
* renderer
,
7974 wxGridCellEditor
* editor
)
7976 m_typeRegistry
->RegisterDataType(typeName
, renderer
, editor
);
7980 wxGridCellEditor
* wxGrid::GetDefaultEditorForCell(int row
, int col
) const
7982 wxString typeName
= m_table
->GetTypeName(row
, col
);
7983 return GetDefaultEditorForType(typeName
);
7986 wxGridCellRenderer
* wxGrid::GetDefaultRendererForCell(int row
, int col
) const
7988 wxString typeName
= m_table
->GetTypeName(row
, col
);
7989 return GetDefaultRendererForType(typeName
);
7993 wxGrid::GetDefaultEditorForType(const wxString
& typeName
) const
7995 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
7996 if ( index
== wxNOT_FOUND
)
7998 wxFAIL_MSG(wxT("Unknown data type name"));
8003 return m_typeRegistry
->GetEditor(index
);
8007 wxGrid::GetDefaultRendererForType(const wxString
& typeName
) const
8009 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
8010 if ( index
== wxNOT_FOUND
)
8012 wxFAIL_MSG(wxT("Unknown data type name"));
8017 return m_typeRegistry
->GetRenderer(index
);
8021 // ----------------------------------------------------------------------------
8023 // ----------------------------------------------------------------------------
8025 void wxGrid::EnableDragRowSize( bool enable
)
8027 m_canDragRowSize
= enable
;
8031 void wxGrid::EnableDragColSize( bool enable
)
8033 m_canDragColSize
= enable
;
8036 void wxGrid::EnableDragGridSize( bool enable
)
8038 m_canDragGridSize
= enable
;
8042 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
8044 m_defaultRowHeight
= wxMax( height
, WXGRID_MIN_ROW_HEIGHT
);
8046 if ( resizeExistingRows
)
8049 if ( !GetBatchCount() )
8054 void wxGrid::SetRowSize( int row
, int height
)
8056 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
8058 if ( m_rowHeights
.IsEmpty() )
8060 // need to really create the array
8064 int h
= wxMax( 0, height
);
8065 int diff
= h
- m_rowHeights
[row
];
8067 m_rowHeights
[row
] = h
;
8069 for ( i
= row
; i
< m_numRows
; i
++ )
8071 m_rowBottoms
[i
] += diff
;
8073 if ( !GetBatchCount() )
8077 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
8079 m_defaultColWidth
= wxMax( width
, WXGRID_MIN_COL_WIDTH
);
8081 if ( resizeExistingCols
)
8084 if ( !GetBatchCount() )
8089 void wxGrid::SetColSize( int col
, int width
)
8091 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
8093 // should we check that it's bigger than GetColMinimalWidth(col) here?
8095 if ( m_colWidths
.IsEmpty() )
8097 // need to really create the array
8101 int w
= wxMax( 0, width
);
8102 int diff
= w
- m_colWidths
[col
];
8103 m_colWidths
[col
] = w
;
8106 for ( i
= col
; i
< m_numCols
; i
++ )
8108 m_colRights
[i
] += diff
;
8110 if ( !GetBatchCount() )
8115 void wxGrid::SetColMinimalWidth( int col
, int width
)
8117 m_colMinWidths
.Put(col
, width
);
8120 void wxGrid::SetRowMinimalHeight( int row
, int width
)
8122 m_rowMinHeights
.Put(row
, width
);
8125 int wxGrid::GetColMinimalWidth(int col
) const
8127 long value
= m_colMinWidths
.Get(col
);
8128 return value
!= wxNOT_FOUND
? (int)value
: WXGRID_MIN_COL_WIDTH
;
8131 int wxGrid::GetRowMinimalHeight(int row
) const
8133 long value
= m_rowMinHeights
.Get(row
);
8134 return value
!= wxNOT_FOUND
? (int)value
: WXGRID_MIN_ROW_HEIGHT
;
8137 // ----------------------------------------------------------------------------
8139 // ----------------------------------------------------------------------------
8141 void wxGrid::AutoSizeColOrRow( int colOrRow
, bool setAsMin
, bool column
)
8143 wxClientDC
dc(m_gridWin
);
8145 // init both of them to avoid compiler warnings, even if weo nly need one
8153 wxCoord extent
, extentMax
= 0;
8154 int max
= column
? m_numRows
: m_numCols
;
8155 for ( int rowOrCol
= 0; rowOrCol
< max
; rowOrCol
++ )
8162 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8163 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
8166 wxSize size
= renderer
->GetBestSize(*this, *attr
, dc
, row
, col
);
8167 extent
= column
? size
.x
: size
.y
;
8168 if ( extent
> extentMax
)
8179 // now also compare with the column label extent
8181 dc
.SetFont( GetLabelFont() );
8184 dc
.GetTextExtent( GetColLabelValue(col
), &w
, &h
);
8186 dc
.GetTextExtent( GetRowLabelValue(row
), &w
, &h
);
8188 extent
= column
? w
: h
;
8189 if ( extent
> extentMax
)
8196 // empty column - give default extent (notice that if extentMax is less
8197 // than default extent but != 0, it's ok)
8198 extentMax
= column
? m_defaultColWidth
: m_defaultRowHeight
;
8204 // leave some space around text
8214 SetColSize(col
, extentMax
);
8215 if ( !GetBatchCount() )
8218 m_gridWin
->GetClientSize( &cw
, &ch
);
8219 wxRect
rect ( CellToRect( 0, col
) );
8221 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
8222 rect
.width
= cw
- rect
.x
;
8223 rect
.height
= m_colLabelHeight
;
8224 m_colLabelWin
->Refresh( TRUE
, &rect
);
8228 SetRowSize(row
, extentMax
);
8229 if ( !GetBatchCount() )
8232 m_gridWin
->GetClientSize( &cw
, &ch
);
8233 wxRect
rect ( CellToRect( row
, 0 ) );
8235 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
8236 rect
.width
= m_rowLabelWidth
;
8237 rect
.height
= ch
- rect
.y
;
8238 m_rowLabelWin
->Refresh( TRUE
, &rect
);
8244 SetColMinimalWidth(col
, extentMax
);
8246 SetRowMinimalHeight(row
, extentMax
);
8250 int wxGrid::SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
)
8252 int width
= m_rowLabelWidth
;
8256 for ( int col
= 0; col
< m_numCols
; col
++ )
8260 AutoSizeColumn(col
, setAsMin
);
8263 width
+= GetColWidth(col
);
8270 int wxGrid::SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
)
8272 int height
= m_colLabelHeight
;
8276 for ( int row
= 0; row
< m_numRows
; row
++ )
8280 AutoSizeRow(row
, setAsMin
);
8283 height
+= GetRowHeight(row
);
8290 void wxGrid::AutoSize()
8293 SetClientSize(SetOrCalcColumnSizes(FALSE
), SetOrCalcRowSizes(FALSE
));
8296 wxSize
wxGrid::DoGetBestSize() const
8298 // don't set sizes, only calculate them
8299 wxGrid
*self
= (wxGrid
*)this; // const_cast
8301 return wxSize(self
->SetOrCalcColumnSizes(TRUE
),
8302 self
->SetOrCalcRowSizes(TRUE
));
8311 wxPen
& wxGrid::GetDividerPen() const
8316 // ----------------------------------------------------------------------------
8317 // cell value accessor functions
8318 // ----------------------------------------------------------------------------
8320 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
8324 m_table
->SetValue( row
, col
, s
);
8325 if ( !GetBatchCount() )
8327 wxClientDC
dc( m_gridWin
);
8329 DrawCell( dc
, wxGridCellCoords(row
, col
) );
8332 if ( m_currentCellCoords
.GetRow() == row
&&
8333 m_currentCellCoords
.GetCol() == col
&&
8334 IsCellEditControlShown())
8335 // Note: If we are using IsCellEditControlEnabled,
8336 // this interacts badly with calling SetCellValue from
8337 // an EVT_GRID_CELL_CHANGE handler.
8339 HideCellEditControl();
8340 ShowCellEditControl(); // will reread data from table
8347 // ------ Block, row and col selection
8350 void wxGrid::SelectRow( int row
, bool addToSelected
)
8352 if ( IsSelection() && !addToSelected
)
8355 m_selection
->SelectRow( row
, FALSE
, addToSelected
);
8359 void wxGrid::SelectCol( int col
, bool addToSelected
)
8361 if ( IsSelection() && !addToSelected
)
8364 m_selection
->SelectCol( col
, FALSE
, addToSelected
);
8368 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
8369 bool addToSelected
)
8371 if ( IsSelection() && !addToSelected
)
8374 m_selection
->SelectBlock( topRow
, leftCol
, bottomRow
, rightCol
,
8375 FALSE
, addToSelected
);
8379 void wxGrid::SelectAll()
8381 if ( m_numRows
> 0 && m_numCols
> 0 )
8382 m_selection
->SelectBlock( 0, 0, m_numRows
-1, m_numCols
-1 );
8386 // ------ Cell, row and col deselection
8389 void wxGrid::DeselectRow( int row
)
8391 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectRows
)
8393 if ( m_selection
->IsInSelection(row
, 0 ) )
8394 m_selection
->ToggleCellSelection( row
, 0);
8398 int nCols
= GetNumberCols();
8399 for ( int i
= 0; i
< nCols
; i
++ )
8401 if ( m_selection
->IsInSelection(row
, i
) )
8402 m_selection
->ToggleCellSelection( row
, i
);
8407 void wxGrid::DeselectCol( int col
)
8409 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectColumns
)
8411 if ( m_selection
->IsInSelection(0, col
) )
8412 m_selection
->ToggleCellSelection( 0, col
);
8416 int nRows
= GetNumberRows();
8417 for ( int i
= 0; i
< nRows
; i
++ )
8419 if ( m_selection
->IsInSelection(i
, col
) )
8420 m_selection
->ToggleCellSelection(i
, col
);
8425 void wxGrid::DeselectCell( int row
, int col
)
8427 if ( m_selection
->IsInSelection(row
, col
) )
8428 m_selection
->ToggleCellSelection(row
, col
);
8431 bool wxGrid::IsSelection()
8433 return ( m_selection
->IsSelection() ||
8434 ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
8435 m_selectingBottomRight
!= wxGridNoCellCoords
) );
8438 bool wxGrid::IsInSelection( int row
, int col
)
8440 return ( m_selection
->IsInSelection( row
, col
) ||
8441 ( row
>= m_selectingTopLeft
.GetRow() &&
8442 col
>= m_selectingTopLeft
.GetCol() &&
8443 row
<= m_selectingBottomRight
.GetRow() &&
8444 col
<= m_selectingBottomRight
.GetCol() ) );
8447 void wxGrid::ClearSelection()
8449 m_selectingTopLeft
= wxGridNoCellCoords
;
8450 m_selectingBottomRight
= wxGridNoCellCoords
;
8451 m_selection
->ClearSelection();
8455 // This function returns the rectangle that encloses the given block
8456 // in device coords clipped to the client size of the grid window.
8458 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
8459 const wxGridCellCoords
&bottomRight
)
8461 wxRect
rect( wxGridNoCellRect
);
8464 cellRect
= CellToRect( topLeft
);
8465 if ( cellRect
!= wxGridNoCellRect
)
8471 rect
= wxRect( 0, 0, 0, 0 );
8474 cellRect
= CellToRect( bottomRight
);
8475 if ( cellRect
!= wxGridNoCellRect
)
8481 return wxGridNoCellRect
;
8484 // convert to scrolled coords
8486 int left
, top
, right
, bottom
;
8487 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
8488 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
8491 m_gridWin
->GetClientSize( &cw
, &ch
);
8493 if (right
< 0 || bottom
< 0 || left
> cw
|| top
> ch
)
8494 return wxRect( 0, 0, 0, 0);
8496 rect
.SetLeft( wxMax(0, left
) );
8497 rect
.SetTop( wxMax(0, top
) );
8498 rect
.SetRight( wxMin(cw
, right
) );
8499 rect
.SetBottom( wxMin(ch
, bottom
) );
8507 // ------ Grid event classes
8510 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxEvent
)
8512 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
8513 int row
, int col
, int x
, int y
, bool sel
,
8514 bool control
, bool shift
, bool alt
, bool meta
)
8515 : wxNotifyEvent( type
, id
)
8522 m_control
= control
;
8527 SetEventObject(obj
);
8531 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxEvent
)
8533 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
8534 int rowOrCol
, int x
, int y
,
8535 bool control
, bool shift
, bool alt
, bool meta
)
8536 : wxNotifyEvent( type
, id
)
8538 m_rowOrCol
= rowOrCol
;
8541 m_control
= control
;
8546 SetEventObject(obj
);
8550 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxEvent
)
8552 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
8553 const wxGridCellCoords
& topLeft
,
8554 const wxGridCellCoords
& bottomRight
,
8555 bool sel
, bool control
,
8556 bool shift
, bool alt
, bool meta
)
8557 : wxNotifyEvent( type
, id
)
8559 m_topLeft
= topLeft
;
8560 m_bottomRight
= bottomRight
;
8562 m_control
= control
;
8567 SetEventObject(obj
);
8571 #endif // ifndef wxUSE_NEW_GRID