1 ///////////////////////////////////////////////////////////////////////////
2 // Name: generic/grid.cpp
3 // Purpose: wxGrid and related classes
4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
5 // Modified by: Robin Dunn, Vadim Zeitlin
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"
37 #include "wx/dcclient.h"
38 #include "wx/settings.h"
40 #include "wx/textctrl.h"
41 #include "wx/checkbox.h"
42 #include "wx/combobox.h"
43 #include "wx/valtext.h"
46 #include "wx/textfile.h"
47 #include "wx/spinctrl.h"
48 #include "wx/tokenzr.h"
51 #include "wx/generic/gridsel.h"
53 #if defined(__WXMOTIF__)
54 #define WXUNUSED_MOTIF(identifier) WXUNUSED(identifier)
56 #define WXUNUSED_MOTIF(identifier) identifier
59 #if defined(__WXGTK__)
60 #define WXUNUSED_GTK(identifier) WXUNUSED(identifier)
62 #define WXUNUSED_GTK(identifier) identifier
65 // Required for wxIs... functions
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 WX_DEFINE_EXPORTED_ARRAY(wxGridCellAttr
*, wxArrayAttrs
);
74 struct wxGridCellWithAttr
76 wxGridCellWithAttr(int row
, int col
, wxGridCellAttr
*attr_
)
77 : coords(row
, col
), attr(attr_
)
86 wxGridCellCoords coords
;
90 // DECLARE_NO_COPY_CLASS(wxGridCellWithAttr)
91 // without rewriting the macros, which require a public copy constructor.
94 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellWithAttr
, wxGridCellWithAttrArray
);
96 #include "wx/arrimpl.cpp"
98 WX_DEFINE_OBJARRAY(wxGridCellCoordsArray
)
99 WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray
)
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_CLICK
)
106 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_CLICK
)
107 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_DCLICK
)
108 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_DCLICK
)
109 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_CLICK
)
110 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_CLICK
)
111 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_DCLICK
)
112 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_DCLICK
)
113 DEFINE_EVENT_TYPE(wxEVT_GRID_ROW_SIZE
)
114 DEFINE_EVENT_TYPE(wxEVT_GRID_COL_SIZE
)
115 DEFINE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT
)
116 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGE
)
117 DEFINE_EVENT_TYPE(wxEVT_GRID_SELECT_CELL
)
118 DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN
)
119 DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN
)
120 DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_CREATED
)
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 class WXDLLEXPORT wxGridRowLabelWindow
: public wxWindow
129 wxGridRowLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
130 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
131 const wxPoint
&pos
, const wxSize
&size
);
136 void OnPaint( wxPaintEvent
& event
);
137 void OnMouseEvent( wxMouseEvent
& event
);
138 void OnMouseWheel( wxMouseEvent
& event
);
139 void OnKeyDown( wxKeyEvent
& event
);
140 void OnKeyUp( wxKeyEvent
& );
142 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
143 DECLARE_EVENT_TABLE()
144 DECLARE_NO_COPY_CLASS(wxGridRowLabelWindow
)
148 class WXDLLEXPORT wxGridColLabelWindow
: public wxWindow
151 wxGridColLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
152 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
153 const wxPoint
&pos
, const wxSize
&size
);
158 void OnPaint( wxPaintEvent
&event
);
159 void OnMouseEvent( wxMouseEvent
& event
);
160 void OnMouseWheel( wxMouseEvent
& event
);
161 void OnKeyDown( wxKeyEvent
& event
);
162 void OnKeyUp( wxKeyEvent
& );
164 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
165 DECLARE_EVENT_TABLE()
166 DECLARE_NO_COPY_CLASS(wxGridColLabelWindow
)
170 class WXDLLEXPORT wxGridCornerLabelWindow
: public wxWindow
173 wxGridCornerLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
174 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
175 const wxPoint
&pos
, const wxSize
&size
);
180 void OnMouseEvent( wxMouseEvent
& event
);
181 void OnMouseWheel( wxMouseEvent
& event
);
182 void OnKeyDown( wxKeyEvent
& event
);
183 void OnKeyUp( wxKeyEvent
& );
184 void OnPaint( wxPaintEvent
& event
);
186 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
187 DECLARE_EVENT_TABLE()
188 DECLARE_NO_COPY_CLASS(wxGridCornerLabelWindow
)
191 class WXDLLEXPORT wxGridWindow
: public wxWindow
196 m_owner
= (wxGrid
*)NULL
;
197 m_rowLabelWin
= (wxGridRowLabelWindow
*)NULL
;
198 m_colLabelWin
= (wxGridColLabelWindow
*)NULL
;
201 wxGridWindow( wxGrid
*parent
,
202 wxGridRowLabelWindow
*rowLblWin
,
203 wxGridColLabelWindow
*colLblWin
,
204 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
207 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
209 wxGrid
* GetOwner() { return m_owner
; }
213 wxGridRowLabelWindow
*m_rowLabelWin
;
214 wxGridColLabelWindow
*m_colLabelWin
;
216 void OnPaint( wxPaintEvent
&event
);
217 void OnMouseWheel( wxMouseEvent
& event
);
218 void OnMouseEvent( wxMouseEvent
& event
);
219 void OnKeyDown( wxKeyEvent
& );
220 void OnKeyUp( wxKeyEvent
& );
221 void OnEraseBackground( wxEraseEvent
& );
224 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
225 DECLARE_EVENT_TABLE()
226 DECLARE_NO_COPY_CLASS(wxGridWindow
)
231 class wxGridCellEditorEvtHandler
: public wxEvtHandler
234 wxGridCellEditorEvtHandler()
235 : m_grid(0), m_editor(0)
237 wxGridCellEditorEvtHandler(wxGrid
* grid
, wxGridCellEditor
* editor
)
238 : m_grid(grid
), m_editor(editor
)
241 void OnKeyDown(wxKeyEvent
& event
);
242 void OnChar(wxKeyEvent
& event
);
246 wxGridCellEditor
* m_editor
;
247 DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler
)
248 DECLARE_EVENT_TABLE()
249 DECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler
)
253 IMPLEMENT_DYNAMIC_CLASS( wxGridCellEditorEvtHandler
, wxEvtHandler
)
254 BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler
, wxEvtHandler
)
255 EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown
)
256 EVT_CHAR( wxGridCellEditorEvtHandler::OnChar
)
261 // ----------------------------------------------------------------------------
262 // the internal data representation used by wxGridCellAttrProvider
263 // ----------------------------------------------------------------------------
265 // this class stores attributes set for cells
266 class WXDLLEXPORT wxGridCellAttrData
269 void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
270 wxGridCellAttr
*GetAttr(int row
, int col
) const;
271 void UpdateAttrRows( size_t pos
, int numRows
);
272 void UpdateAttrCols( size_t pos
, int numCols
);
275 // searches for the attr for given cell, returns wxNOT_FOUND if not found
276 int FindIndex(int row
, int col
) const;
278 wxGridCellWithAttrArray m_attrs
;
281 // this class stores attributes set for rows or columns
282 class WXDLLEXPORT wxGridRowOrColAttrData
285 // empty ctor to suppress warnings
286 wxGridRowOrColAttrData() { }
287 ~wxGridRowOrColAttrData();
289 void SetAttr(wxGridCellAttr
*attr
, int rowOrCol
);
290 wxGridCellAttr
*GetAttr(int rowOrCol
) const;
291 void UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
);
294 wxArrayInt m_rowsOrCols
;
295 wxArrayAttrs m_attrs
;
298 // NB: this is just a wrapper around 3 objects: one which stores cell
299 // attributes, and 2 others for row/col ones
300 class WXDLLEXPORT wxGridCellAttrProviderData
303 wxGridCellAttrData m_cellAttrs
;
304 wxGridRowOrColAttrData m_rowAttrs
,
309 // ----------------------------------------------------------------------------
310 // data structures used for the data type registry
311 // ----------------------------------------------------------------------------
313 struct wxGridDataTypeInfo
315 wxGridDataTypeInfo(const wxString
& typeName
,
316 wxGridCellRenderer
* renderer
,
317 wxGridCellEditor
* editor
)
318 : m_typeName(typeName
), m_renderer(renderer
), m_editor(editor
)
321 ~wxGridDataTypeInfo()
323 wxSafeDecRef(m_renderer
);
324 wxSafeDecRef(m_editor
);
328 wxGridCellRenderer
* m_renderer
;
329 wxGridCellEditor
* m_editor
;
331 DECLARE_NO_COPY_CLASS(wxGridDataTypeInfo
)
335 WX_DEFINE_EXPORTED_ARRAY(wxGridDataTypeInfo
*, wxGridDataTypeInfoArray
);
338 class WXDLLEXPORT wxGridTypeRegistry
341 wxGridTypeRegistry() {}
342 ~wxGridTypeRegistry();
344 void RegisterDataType(const wxString
& typeName
,
345 wxGridCellRenderer
* renderer
,
346 wxGridCellEditor
* editor
);
348 // find one of already registered data types
349 int FindRegisteredDataType(const wxString
& typeName
);
351 // try to FindRegisteredDataType(), if this fails and typeName is one of
352 // standard typenames, register it and return its index
353 int FindDataType(const wxString
& typeName
);
355 // try to FindDataType(), if it fails see if it is not one of already
356 // registered data types with some params in which case clone the
357 // registered data type and set params for it
358 int FindOrCloneDataType(const wxString
& typeName
);
360 wxGridCellRenderer
* GetRenderer(int index
);
361 wxGridCellEditor
* GetEditor(int index
);
364 wxGridDataTypeInfoArray m_typeinfo
;
367 // ----------------------------------------------------------------------------
368 // conditional compilation
369 // ----------------------------------------------------------------------------
371 #ifndef WXGRID_DRAW_LINES
372 #define WXGRID_DRAW_LINES 1
375 // ----------------------------------------------------------------------------
377 // ----------------------------------------------------------------------------
379 //#define DEBUG_ATTR_CACHE
380 #ifdef DEBUG_ATTR_CACHE
381 static size_t gs_nAttrCacheHits
= 0;
382 static size_t gs_nAttrCacheMisses
= 0;
383 #endif // DEBUG_ATTR_CACHE
385 // ----------------------------------------------------------------------------
387 // ----------------------------------------------------------------------------
389 wxGridCellCoords
wxGridNoCellCoords( -1, -1 );
390 wxRect
wxGridNoCellRect( -1, -1, -1, -1 );
393 // TODO: this doesn't work at all, grid cells have different sizes and approx
394 // calculations don't work as because of the size mismatch scrollbars
395 // sometimes fail to be shown when they should be or vice versa
397 // The scroll bars may be a little flakey once in a while, but that is
398 // surely much less horrible than having scroll lines of only 1!!!
401 // Well, it's still seriously broken so it might be better but needs
404 static const size_t GRID_SCROLL_LINE_X
= 15; // 1;
405 static const size_t GRID_SCROLL_LINE_Y
= GRID_SCROLL_LINE_X
;
407 // the size of hash tables used a bit everywhere (the max number of elements
408 // in these hash tables is the number of rows/columns)
409 static const int GRID_HASH_SIZE
= 100;
411 // ----------------------------------------------------------------------------
413 // ----------------------------------------------------------------------------
415 static inline int GetScrollX(int x
)
417 return (x
+ GRID_SCROLL_LINE_X
- 1) / GRID_SCROLL_LINE_X
;
420 static inline int GetScrollY(int y
)
422 return (y
+ GRID_SCROLL_LINE_Y
- 1) / GRID_SCROLL_LINE_Y
;
425 // ============================================================================
427 // ============================================================================
429 // ----------------------------------------------------------------------------
431 // ----------------------------------------------------------------------------
433 wxGridCellEditor::wxGridCellEditor()
440 wxGridCellEditor::~wxGridCellEditor()
445 void wxGridCellEditor::Create(wxWindow
* WXUNUSED(parent
),
446 wxWindowID
WXUNUSED(id
),
447 wxEvtHandler
* evtHandler
)
450 m_control
->PushEventHandler(evtHandler
);
453 void wxGridCellEditor::PaintBackground(const wxRect
& rectCell
,
454 wxGridCellAttr
*attr
)
456 // erase the background because we might not fill the cell
457 wxClientDC
dc(m_control
->GetParent());
458 wxGridWindow
* gridWindow
= wxDynamicCast(m_control
->GetParent(), wxGridWindow
);
460 gridWindow
->GetOwner()->PrepareDC(dc
);
462 dc
.SetPen(*wxTRANSPARENT_PEN
);
463 dc
.SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
464 dc
.DrawRectangle(rectCell
);
466 // redraw the control we just painted over
467 m_control
->Refresh();
470 void wxGridCellEditor::Destroy()
474 m_control
->PopEventHandler(TRUE
/* delete it*/);
476 m_control
->Destroy();
481 void wxGridCellEditor::Show(bool show
, wxGridCellAttr
*attr
)
483 wxASSERT_MSG(m_control
,
484 wxT("The wxGridCellEditor must be Created first!"));
485 m_control
->Show(show
);
489 // set the colours/fonts if we have any
492 m_colFgOld
= m_control
->GetForegroundColour();
493 m_control
->SetForegroundColour(attr
->GetTextColour());
495 m_colBgOld
= m_control
->GetBackgroundColour();
496 m_control
->SetBackgroundColour(attr
->GetBackgroundColour());
498 m_fontOld
= m_control
->GetFont();
499 m_control
->SetFont(attr
->GetFont());
501 // can't do anything more in the base class version, the other
502 // attributes may only be used by the derived classes
507 // restore the standard colours fonts
508 if ( m_colFgOld
.Ok() )
510 m_control
->SetForegroundColour(m_colFgOld
);
511 m_colFgOld
= wxNullColour
;
514 if ( m_colBgOld
.Ok() )
516 m_control
->SetBackgroundColour(m_colBgOld
);
517 m_colBgOld
= wxNullColour
;
520 if ( m_fontOld
.Ok() )
522 m_control
->SetFont(m_fontOld
);
523 m_fontOld
= wxNullFont
;
528 void wxGridCellEditor::SetSize(const wxRect
& rect
)
530 wxASSERT_MSG(m_control
,
531 wxT("The wxGridCellEditor must be Created first!"));
532 m_control
->SetSize(rect
, wxSIZE_ALLOW_MINUS_ONE
);
535 void wxGridCellEditor::HandleReturn(wxKeyEvent
& event
)
540 bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent
& event
)
542 // accept the simple key presses, not anything with Ctrl/Alt/Meta
543 return !(event
.ControlDown() || event
.AltDown());
546 void wxGridCellEditor::StartingKey(wxKeyEvent
& event
)
551 void wxGridCellEditor::StartingClick()
557 // ----------------------------------------------------------------------------
558 // wxGridCellTextEditor
559 // ----------------------------------------------------------------------------
561 wxGridCellTextEditor::wxGridCellTextEditor()
566 void wxGridCellTextEditor::Create(wxWindow
* parent
,
568 wxEvtHandler
* evtHandler
)
570 m_control
= new wxTextCtrl(parent
, id
, wxEmptyString
,
571 wxDefaultPosition
, wxDefaultSize
572 #if defined(__WXMSW__)
573 , wxTE_PROCESS_TAB
| wxTE_MULTILINE
|
574 wxTE_NO_VSCROLL
| wxTE_AUTO_SCROLL
578 // TODO: use m_maxChars
580 wxGridCellEditor::Create(parent
, id
, evtHandler
);
583 void wxGridCellTextEditor::PaintBackground(const wxRect
& WXUNUSED(rectCell
),
584 wxGridCellAttr
* WXUNUSED(attr
))
586 // as we fill the entire client area, don't do anything here to minimize
590 void wxGridCellTextEditor::SetSize(const wxRect
& rectOrig
)
592 wxRect
rect(rectOrig
);
594 // Make the edit control large enough to allow for internal
597 // TODO: remove this if the text ctrl sizing is improved esp. for
600 #if defined(__WXGTK__)
609 int extra_x
= ( rect
.x
> 2 )? 2 : 1;
611 // MB: treat MSW separately here otherwise the caret doesn't show
612 // when the editor is in the first row.
613 #if defined(__WXMSW__)
616 int extra_y
= ( rect
.y
> 2 )? 2 : 1;
619 #if defined(__WXMOTIF__)
623 rect
.SetLeft( wxMax(0, rect
.x
- extra_x
) );
624 rect
.SetTop( wxMax(0, rect
.y
- extra_y
) );
625 rect
.SetRight( rect
.GetRight() + 2*extra_x
);
626 rect
.SetBottom( rect
.GetBottom() + 2*extra_y
);
629 wxGridCellEditor::SetSize(rect
);
632 void wxGridCellTextEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
634 wxASSERT_MSG(m_control
,
635 wxT("The wxGridCellEditor must be Created first!"));
637 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
639 DoBeginEdit(m_startValue
);
642 void wxGridCellTextEditor::DoBeginEdit(const wxString
& startValue
)
644 Text()->SetValue(startValue
);
645 Text()->SetInsertionPointEnd();
646 Text()->SetSelection(-1,-1);
650 bool wxGridCellTextEditor::EndEdit(int row
, int col
,
653 wxASSERT_MSG(m_control
,
654 wxT("The wxGridCellEditor must be Created first!"));
656 bool changed
= FALSE
;
657 wxString value
= Text()->GetValue();
658 if (value
!= m_startValue
)
662 grid
->GetTable()->SetValue(row
, col
, value
);
664 m_startValue
= wxEmptyString
;
665 Text()->SetValue(m_startValue
);
671 void wxGridCellTextEditor::Reset()
673 wxASSERT_MSG(m_control
,
674 wxT("The wxGridCellEditor must be Created first!"));
676 DoReset(m_startValue
);
679 void wxGridCellTextEditor::DoReset(const wxString
& startValue
)
681 Text()->SetValue(startValue
);
682 Text()->SetInsertionPointEnd();
685 bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent
& event
)
687 if ( wxGridCellEditor::IsAcceptedKey(event
) )
689 int keycode
= event
.GetKeyCode();
703 case WXK_NUMPAD_MULTIPLY
:
707 case WXK_NUMPAD_SUBTRACT
:
709 case WXK_NUMPAD_DECIMAL
:
711 case WXK_NUMPAD_DIVIDE
:
715 // accept 8 bit chars too if isprint() agrees
716 if ( (keycode
< 255) && (isprint(keycode
)) )
724 void wxGridCellTextEditor::StartingKey(wxKeyEvent
& event
)
726 if ( !Text()->EmulateKeyPress(event
) )
732 void wxGridCellTextEditor::HandleReturn( wxKeyEvent
&
733 WXUNUSED_GTK(WXUNUSED_MOTIF(event
)) )
735 #if defined(__WXMOTIF__) || defined(__WXGTK__)
736 // wxMotif needs a little extra help...
737 size_t pos
= (size_t)( Text()->GetInsertionPoint() );
738 wxString
s( Text()->GetValue() );
739 s
= s
.Left(pos
) + wxT("\n") + s
.Mid(pos
);
741 Text()->SetInsertionPoint( pos
);
743 // the other ports can handle a Return key press
749 void wxGridCellTextEditor::SetParameters(const wxString
& params
)
759 if ( !params
.ToLong(&tmp
) )
761 wxLogDebug(_T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params
.c_str());
765 m_maxChars
= (size_t)tmp
;
770 // return the value in the text control
771 wxString
wxGridCellTextEditor::GetValue() const
773 return Text()->GetValue();
776 // ----------------------------------------------------------------------------
777 // wxGridCellNumberEditor
778 // ----------------------------------------------------------------------------
780 wxGridCellNumberEditor::wxGridCellNumberEditor(int min
, int max
)
786 void wxGridCellNumberEditor::Create(wxWindow
* parent
,
788 wxEvtHandler
* evtHandler
)
792 // create a spin ctrl
793 m_control
= new wxSpinCtrl(parent
, -1, wxEmptyString
,
794 wxDefaultPosition
, wxDefaultSize
,
798 wxGridCellEditor::Create(parent
, id
, evtHandler
);
802 // just a text control
803 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
806 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
807 #endif // wxUSE_VALIDATORS
811 void wxGridCellNumberEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
813 // first get the value
814 wxGridTableBase
*table
= grid
->GetTable();
815 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
817 m_valueOld
= table
->GetValueAsLong(row
, col
);
822 wxString sValue
= table
->GetValue(row
, col
);
823 if (! sValue
.ToLong(&m_valueOld
) && ! sValue
.IsEmpty())
825 wxFAIL_MSG( _T("this cell doesn't have numeric value") );
832 Spin()->SetValue((int)m_valueOld
);
837 DoBeginEdit(GetString());
841 bool wxGridCellNumberEditor::EndEdit(int row
, int col
,
850 value
= Spin()->GetValue();
851 changed
= value
!= m_valueOld
;
853 text
= wxString::Format(wxT("%ld"), value
);
857 text
= Text()->GetValue();
858 changed
= (text
.IsEmpty() || text
.ToLong(&value
)) && (value
!= m_valueOld
);
863 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_NUMBER
))
864 grid
->GetTable()->SetValueAsLong(row
, col
, value
);
866 grid
->GetTable()->SetValue(row
, col
, text
);
872 void wxGridCellNumberEditor::Reset()
876 Spin()->SetValue((int)m_valueOld
);
880 DoReset(GetString());
884 bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent
& event
)
886 if ( wxGridCellEditor::IsAcceptedKey(event
) )
888 int keycode
= event
.GetKeyCode();
904 case WXK_NUMPAD_SUBTRACT
:
910 if ( (keycode
< 128) && isdigit(keycode
) )
918 void wxGridCellNumberEditor::StartingKey(wxKeyEvent
& event
)
922 int keycode
= event
.GetKeyCode();
923 if ( isdigit(keycode
) || keycode
== '+' || keycode
== '-'
924 || keycode
== WXK_NUMPAD0
925 || keycode
== WXK_NUMPAD1
926 || keycode
== WXK_NUMPAD2
927 || keycode
== WXK_NUMPAD3
928 || keycode
== WXK_NUMPAD4
929 || keycode
== WXK_NUMPAD5
930 || keycode
== WXK_NUMPAD6
931 || keycode
== WXK_NUMPAD7
932 || keycode
== WXK_NUMPAD8
933 || keycode
== WXK_NUMPAD9
934 || keycode
== WXK_ADD
935 || keycode
== WXK_NUMPAD_ADD
936 || keycode
== WXK_SUBTRACT
937 || keycode
== WXK_NUMPAD_SUBTRACT
)
939 wxGridCellTextEditor::StartingKey(event
);
949 void wxGridCellNumberEditor::SetParameters(const wxString
& params
)
960 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
964 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
968 // skip the error message below
973 wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string '%s' ignored"), params
.c_str());
977 // return the value in the spin control if it is there (the text control otherwise)
978 wxString
wxGridCellNumberEditor::GetValue() const
984 long value
= Spin()->GetValue();
985 s
.Printf(wxT("%ld"), value
);
989 s
= Text()->GetValue();
994 // ----------------------------------------------------------------------------
995 // wxGridCellFloatEditor
996 // ----------------------------------------------------------------------------
998 wxGridCellFloatEditor::wxGridCellFloatEditor(int width
, int precision
)
1001 m_precision
= precision
;
1004 void wxGridCellFloatEditor::Create(wxWindow
* parent
,
1006 wxEvtHandler
* evtHandler
)
1008 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
1010 #if wxUSE_VALIDATORS
1011 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
1012 #endif // wxUSE_VALIDATORS
1015 void wxGridCellFloatEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1017 // first get the value
1018 wxGridTableBase
*table
= grid
->GetTable();
1019 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
1021 m_valueOld
= table
->GetValueAsDouble(row
, col
);
1026 wxString sValue
= table
->GetValue(row
, col
);
1027 if (! sValue
.ToDouble(&m_valueOld
) && ! sValue
.IsEmpty())
1029 wxFAIL_MSG( _T("this cell doesn't have float value") );
1034 DoBeginEdit(GetString());
1037 bool wxGridCellFloatEditor::EndEdit(int row
, int col
,
1041 wxString
text(Text()->GetValue());
1043 if ( (text
.IsEmpty() || text
.ToDouble(&value
)) && (value
!= m_valueOld
) )
1045 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_FLOAT
))
1046 grid
->GetTable()->SetValueAsDouble(row
, col
, value
);
1048 grid
->GetTable()->SetValue(row
, col
, text
);
1055 void wxGridCellFloatEditor::Reset()
1057 DoReset(GetString());
1060 void wxGridCellFloatEditor::StartingKey(wxKeyEvent
& event
)
1062 int keycode
= event
.GetKeyCode();
1063 if ( isdigit(keycode
) || keycode
== '+' || keycode
== '-' || keycode
== '.'
1064 || keycode
== WXK_NUMPAD0
1065 || keycode
== WXK_NUMPAD1
1066 || keycode
== WXK_NUMPAD2
1067 || keycode
== WXK_NUMPAD3
1068 || keycode
== WXK_NUMPAD4
1069 || keycode
== WXK_NUMPAD5
1070 || keycode
== WXK_NUMPAD6
1071 || keycode
== WXK_NUMPAD7
1072 || keycode
== WXK_NUMPAD8
1073 || keycode
== WXK_NUMPAD9
1074 || keycode
== WXK_ADD
1075 || keycode
== WXK_NUMPAD_ADD
1076 || keycode
== WXK_SUBTRACT
1077 || keycode
== WXK_NUMPAD_SUBTRACT
)
1079 wxGridCellTextEditor::StartingKey(event
);
1081 // skip Skip() below
1088 void wxGridCellFloatEditor::SetParameters(const wxString
& params
)
1099 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
1103 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
1105 m_precision
= (int)tmp
;
1107 // skip the error message below
1112 wxLogDebug(_T("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params
.c_str());
1116 wxString
wxGridCellFloatEditor::GetString() const
1119 if ( m_width
== -1 )
1121 // default width/precision
1124 else if ( m_precision
== -1 )
1126 // default precision
1127 fmt
.Printf(_T("%%%d.f"), m_width
);
1131 fmt
.Printf(_T("%%%d.%df"), m_width
, m_precision
);
1134 return wxString::Format(fmt
, m_valueOld
);
1137 bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent
& event
)
1139 if ( wxGridCellEditor::IsAcceptedKey(event
) )
1141 int keycode
= event
.GetKeyCode();
1155 case WXK_NUMPAD_ADD
:
1157 case WXK_NUMPAD_SUBTRACT
:
1159 case WXK_NUMPAD_DECIMAL
:
1163 // additionally accept 'e' as in '1e+6'
1164 if ( (keycode
< 128) &&
1165 (isdigit(keycode
) || tolower(keycode
) == 'e') )
1173 #endif // wxUSE_TEXTCTRL
1177 // ----------------------------------------------------------------------------
1178 // wxGridCellBoolEditor
1179 // ----------------------------------------------------------------------------
1181 void wxGridCellBoolEditor::Create(wxWindow
* parent
,
1183 wxEvtHandler
* evtHandler
)
1185 m_control
= new wxCheckBox(parent
, id
, wxEmptyString
,
1186 wxDefaultPosition
, wxDefaultSize
,
1189 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1192 void wxGridCellBoolEditor::SetSize(const wxRect
& r
)
1194 bool resize
= FALSE
;
1195 wxSize size
= m_control
->GetSize();
1196 wxCoord minSize
= wxMin(r
.width
, r
.height
);
1198 // check if the checkbox is not too big/small for this cell
1199 wxSize sizeBest
= m_control
->GetBestSize();
1200 if ( !(size
== sizeBest
) )
1202 // reset to default size if it had been made smaller
1208 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
1210 // leave 1 pixel margin
1211 size
.x
= size
.y
= minSize
- 2;
1218 m_control
->SetSize(size
);
1221 // position it in the centre of the rectangle (TODO: support alignment?)
1223 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1224 // the checkbox without label still has some space to the right in wxGTK,
1225 // so shift it to the right
1227 #elif defined(__WXMSW__)
1228 // here too, but in other way
1233 int hAlign
= wxALIGN_CENTRE
;
1234 int vAlign
= wxALIGN_CENTRE
;
1236 GetCellAttr()->GetAlignment(& hAlign
, & vAlign
);
1239 if (hAlign
== wxALIGN_LEFT
)
1245 y
= r
.y
+ r
.height
/2 - size
.y
/2;
1247 else if (hAlign
== wxALIGN_RIGHT
)
1249 x
= r
.x
+ r
.width
- size
.x
- 2;
1250 y
= r
.y
+ r
.height
/2 - size
.y
/2;
1252 else if (hAlign
== wxALIGN_CENTRE
)
1254 x
= r
.x
+ r
.width
/2 - size
.x
/2;
1255 y
= r
.y
+ r
.height
/2 - size
.y
/2;
1258 m_control
->Move(x
, y
);
1261 void wxGridCellBoolEditor::Show(bool show
, wxGridCellAttr
*attr
)
1263 m_control
->Show(show
);
1267 wxColour colBg
= attr
? attr
->GetBackgroundColour() : *wxLIGHT_GREY
;
1268 CBox()->SetBackgroundColour(colBg
);
1272 void wxGridCellBoolEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1274 wxASSERT_MSG(m_control
,
1275 wxT("The wxGridCellEditor must be Created first!"));
1277 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
1278 m_startValue
= grid
->GetTable()->GetValueAsBool(row
, col
);
1281 wxString
cellval( grid
->GetTable()->GetValue(row
, col
) );
1282 m_startValue
= !( !cellval
|| (cellval
== wxT("0")) );
1284 CBox()->SetValue(m_startValue
);
1288 bool wxGridCellBoolEditor::EndEdit(int row
, int col
,
1291 wxASSERT_MSG(m_control
,
1292 wxT("The wxGridCellEditor must be Created first!"));
1294 bool changed
= FALSE
;
1295 bool value
= CBox()->GetValue();
1296 if ( value
!= m_startValue
)
1301 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
1302 grid
->GetTable()->SetValueAsBool(row
, col
, value
);
1304 grid
->GetTable()->SetValue(row
, col
, value
? _T("1") : wxEmptyString
);
1310 void wxGridCellBoolEditor::Reset()
1312 wxASSERT_MSG(m_control
,
1313 wxT("The wxGridCellEditor must be Created first!"));
1315 CBox()->SetValue(m_startValue
);
1318 void wxGridCellBoolEditor::StartingClick()
1320 CBox()->SetValue(!CBox()->GetValue());
1323 bool wxGridCellBoolEditor::IsAcceptedKey(wxKeyEvent
& event
)
1325 if ( wxGridCellEditor::IsAcceptedKey(event
) )
1327 int keycode
= event
.GetKeyCode();
1331 case WXK_NUMPAD_MULTIPLY
:
1333 case WXK_NUMPAD_ADD
:
1335 case WXK_NUMPAD_SUBTRACT
:
1346 // return the value as "1" for true and the empty string for false
1347 wxString
wxGridCellBoolEditor::GetValue() const
1349 bool bSet
= CBox()->GetValue();
1350 return bSet
? _T("1") : wxEmptyString
;
1353 #endif // wxUSE_CHECKBOX
1357 // ----------------------------------------------------------------------------
1358 // wxGridCellChoiceEditor
1359 // ----------------------------------------------------------------------------
1361 wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count
,
1362 const wxString choices
[],
1364 : m_allowOthers(allowOthers
)
1368 m_choices
.Alloc(count
);
1369 for ( size_t n
= 0; n
< count
; n
++ )
1371 m_choices
.Add(choices
[n
]);
1376 wxGridCellEditor
*wxGridCellChoiceEditor::Clone() const
1378 wxGridCellChoiceEditor
*editor
= new wxGridCellChoiceEditor
;
1379 editor
->m_allowOthers
= m_allowOthers
;
1380 editor
->m_choices
= m_choices
;
1385 void wxGridCellChoiceEditor::Create(wxWindow
* parent
,
1387 wxEvtHandler
* evtHandler
)
1389 size_t count
= m_choices
.GetCount();
1390 wxString
*choices
= new wxString
[count
];
1391 for ( size_t n
= 0; n
< count
; n
++ )
1393 choices
[n
] = m_choices
[n
];
1396 m_control
= new wxComboBox(parent
, id
, wxEmptyString
,
1397 wxDefaultPosition
, wxDefaultSize
,
1399 m_allowOthers
? 0 : wxCB_READONLY
);
1403 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1406 void wxGridCellChoiceEditor::PaintBackground(const wxRect
& rectCell
,
1407 wxGridCellAttr
* attr
)
1409 // as we fill the entire client area, don't do anything here to minimize
1412 // TODO: It doesn't actually fill the client area since the height of a
1413 // combo always defaults to the standard... Until someone has time to
1414 // figure out the right rectangle to paint, just do it the normal way...
1415 wxGridCellEditor::PaintBackground(rectCell
, attr
);
1418 void wxGridCellChoiceEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1420 wxASSERT_MSG(m_control
,
1421 wxT("The wxGridCellEditor must be Created first!"));
1423 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
1426 Combo()->SetValue(m_startValue
);
1429 // find the right position, or default to the first if not found
1430 int pos
= Combo()->FindString(m_startValue
);
1433 Combo()->SetSelection(pos
);
1435 Combo()->SetInsertionPointEnd();
1436 Combo()->SetFocus();
1439 bool wxGridCellChoiceEditor::EndEdit(int row
, int col
,
1442 wxString value
= Combo()->GetValue();
1443 bool changed
= value
!= m_startValue
;
1446 grid
->GetTable()->SetValue(row
, col
, value
);
1448 m_startValue
= wxEmptyString
;
1450 Combo()->SetValue(m_startValue
);
1452 Combo()->SetSelection(0);
1457 void wxGridCellChoiceEditor::Reset()
1459 Combo()->SetValue(m_startValue
);
1460 Combo()->SetInsertionPointEnd();
1463 void wxGridCellChoiceEditor::SetParameters(const wxString
& params
)
1473 wxStringTokenizer
tk(params
, _T(','));
1474 while ( tk
.HasMoreTokens() )
1476 m_choices
.Add(tk
.GetNextToken());
1480 // return the value in the text control
1481 wxString
wxGridCellChoiceEditor::GetValue() const
1483 return Combo()->GetValue();
1486 #endif // wxUSE_COMBOBOX
1488 // ----------------------------------------------------------------------------
1489 // wxGridCellEditorEvtHandler
1490 // ----------------------------------------------------------------------------
1492 void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent
& event
)
1494 switch ( event
.GetKeyCode() )
1498 m_grid
->DisableCellEditControl();
1502 m_grid
->GetEventHandler()->ProcessEvent( event
);
1506 case WXK_NUMPAD_ENTER
:
1507 if (!m_grid
->GetEventHandler()->ProcessEvent(event
))
1508 m_editor
->HandleReturn(event
);
1517 void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent
& event
)
1519 switch ( event
.GetKeyCode() )
1524 case WXK_NUMPAD_ENTER
:
1532 // ----------------------------------------------------------------------------
1533 // wxGridCellWorker is an (almost) empty common base class for
1534 // wxGridCellRenderer and wxGridCellEditor managing ref counting
1535 // ----------------------------------------------------------------------------
1537 void wxGridCellWorker::SetParameters(const wxString
& WXUNUSED(params
))
1542 wxGridCellWorker::~wxGridCellWorker()
1546 // ============================================================================
1548 // ============================================================================
1550 // ----------------------------------------------------------------------------
1551 // wxGridCellRenderer
1552 // ----------------------------------------------------------------------------
1554 void wxGridCellRenderer::Draw(wxGrid
& grid
,
1555 wxGridCellAttr
& attr
,
1558 int WXUNUSED(row
), int WXUNUSED(col
),
1561 dc
.SetBackgroundMode( wxSOLID
);
1563 // grey out fields if the grid is disabled
1564 if( grid
.IsEnabled() )
1568 dc
.SetBrush( wxBrush(grid
.GetSelectionBackground(), wxSOLID
) );
1572 dc
.SetBrush( wxBrush(attr
.GetBackgroundColour(), wxSOLID
) );
1577 dc
.SetBrush(wxBrush(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE
), wxSOLID
));
1580 dc
.SetPen( *wxTRANSPARENT_PEN
);
1581 dc
.DrawRectangle(rect
);
1584 // ----------------------------------------------------------------------------
1585 // wxGridCellStringRenderer
1586 // ----------------------------------------------------------------------------
1588 void wxGridCellStringRenderer::SetTextColoursAndFont(wxGrid
& grid
,
1589 wxGridCellAttr
& attr
,
1593 dc
.SetBackgroundMode( wxTRANSPARENT
);
1595 // TODO some special colours for attr.IsReadOnly() case?
1597 // different coloured text when the grid is disabled
1598 if( grid
.IsEnabled() )
1602 dc
.SetTextBackground( grid
.GetSelectionBackground() );
1603 dc
.SetTextForeground( grid
.GetSelectionForeground() );
1607 dc
.SetTextBackground( attr
.GetBackgroundColour() );
1608 dc
.SetTextForeground( attr
.GetTextColour() );
1613 dc
.SetTextBackground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE
));
1614 dc
.SetTextForeground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_GRAYTEXT
));
1617 dc
.SetFont( attr
.GetFont() );
1620 wxSize
wxGridCellStringRenderer::DoGetBestSize(wxGridCellAttr
& attr
,
1622 const wxString
& text
)
1624 wxCoord x
= 0, y
= 0, max_x
= 0;
1625 dc
.SetFont(attr
.GetFont());
1626 wxStringTokenizer
tk(text
, _T('\n'));
1627 while ( tk
.HasMoreTokens() )
1629 dc
.GetTextExtent(tk
.GetNextToken(), &x
, &y
);
1630 max_x
= wxMax(max_x
, x
);
1633 y
*= 1 + text
.Freq(wxT('\n')); // multiply by the number of lines.
1635 return wxSize(max_x
, y
);
1638 wxSize
wxGridCellStringRenderer::GetBestSize(wxGrid
& grid
,
1639 wxGridCellAttr
& attr
,
1643 return DoGetBestSize(attr
, dc
, grid
.GetCellValue(row
, col
));
1646 void wxGridCellStringRenderer::Draw(wxGrid
& grid
,
1647 wxGridCellAttr
& attr
,
1649 const wxRect
& rectCell
,
1653 wxRect rect
= rectCell
;
1656 // erase only this cells background, overflow cells should have been erased
1657 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1660 attr
.GetAlignment(&hAlign
, &vAlign
);
1662 int overflowCols
= 0;
1664 if (attr
.GetOverflow())
1666 int cols
= grid
.GetNumberCols();
1667 int best_width
= GetBestSize(grid
,attr
,dc
,row
,col
).GetWidth();
1668 int cell_rows
, cell_cols
;
1669 attr
.GetSize( &cell_rows
, &cell_cols
); // shouldn't get here if <=0
1670 if ((best_width
> rectCell
.width
) && (col
< cols
) && grid
.GetTable())
1672 int i
, c_cols
, c_rows
;
1673 for (i
= col
+cell_cols
; i
< cols
; i
++)
1675 bool is_empty
= TRUE
;
1676 for (int j
=row
; j
<row
+cell_rows
; j
++)
1678 // check w/ anchor cell for multicell block
1679 grid
.GetCellSize(j
, i
, &c_rows
, &c_cols
);
1680 if (c_rows
> 0) c_rows
= 0;
1681 if (!grid
.GetTable()->IsEmptyCell(j
+c_rows
, i
))
1688 rect
.width
+= grid
.GetColSize(i
);
1694 if (rect
.width
>= best_width
) break;
1696 overflowCols
= i
- col
- cell_cols
+ 1;
1697 if (overflowCols
>= cols
) overflowCols
= cols
- 1;
1700 if (overflowCols
> 0) // redraw overflow cells w/ proper hilight
1702 hAlign
= wxALIGN_LEFT
; // if oveflowed then it's left aligned
1704 clip
.x
+= rectCell
.width
;
1705 // draw each overflow cell individually
1706 int col_end
= col
+cell_cols
+overflowCols
;
1707 if (col_end
>= grid
.GetNumberCols())
1708 col_end
= grid
.GetNumberCols() - 1;
1709 for (int i
= col
+cell_cols
; i
<= col_end
; i
++)
1711 clip
.width
= grid
.GetColSize(i
) - 1;
1712 dc
.DestroyClippingRegion();
1713 dc
.SetClippingRegion(clip
);
1715 SetTextColoursAndFont(grid
, attr
, dc
,
1716 grid
.IsInSelection(row
,i
));
1718 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
1719 rect
, hAlign
, vAlign
);
1720 clip
.x
+= grid
.GetColSize(i
) - 1;
1726 dc
.DestroyClippingRegion();
1730 // now we only have to draw the text
1731 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1733 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
1734 rect
, hAlign
, vAlign
);
1737 // ----------------------------------------------------------------------------
1738 // wxGridCellNumberRenderer
1739 // ----------------------------------------------------------------------------
1741 wxString
wxGridCellNumberRenderer::GetString(wxGrid
& grid
, int row
, int col
)
1743 wxGridTableBase
*table
= grid
.GetTable();
1745 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
1747 text
.Printf(_T("%ld"), table
->GetValueAsLong(row
, col
));
1751 text
= table
->GetValue(row
, col
);
1757 void wxGridCellNumberRenderer::Draw(wxGrid
& grid
,
1758 wxGridCellAttr
& attr
,
1760 const wxRect
& rectCell
,
1764 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1766 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1768 // draw the text right aligned by default
1770 attr
.GetAlignment(&hAlign
, &vAlign
);
1771 hAlign
= wxALIGN_RIGHT
;
1773 wxRect rect
= rectCell
;
1776 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1779 wxSize
wxGridCellNumberRenderer::GetBestSize(wxGrid
& grid
,
1780 wxGridCellAttr
& attr
,
1784 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1787 // ----------------------------------------------------------------------------
1788 // wxGridCellFloatRenderer
1789 // ----------------------------------------------------------------------------
1791 wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width
, int precision
)
1794 SetPrecision(precision
);
1797 wxGridCellRenderer
*wxGridCellFloatRenderer::Clone() const
1799 wxGridCellFloatRenderer
*renderer
= new wxGridCellFloatRenderer
;
1800 renderer
->m_width
= m_width
;
1801 renderer
->m_precision
= m_precision
;
1802 renderer
->m_format
= m_format
;
1807 wxString
wxGridCellFloatRenderer::GetString(wxGrid
& grid
, int row
, int col
)
1809 wxGridTableBase
*table
= grid
.GetTable();
1814 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
1816 val
= table
->GetValueAsDouble(row
, col
);
1821 text
= table
->GetValue(row
, col
);
1822 hasDouble
= text
.ToDouble(&val
);
1829 if ( m_width
== -1 )
1831 if ( m_precision
== -1 )
1833 // default width/precision
1834 m_format
= _T("%f");
1838 m_format
.Printf(_T("%%.%df"), m_precision
);
1841 else if ( m_precision
== -1 )
1843 // default precision
1844 m_format
.Printf(_T("%%%d.f"), m_width
);
1848 m_format
.Printf(_T("%%%d.%df"), m_width
, m_precision
);
1852 text
.Printf(m_format
, val
);
1855 //else: text already contains the string
1860 void wxGridCellFloatRenderer::Draw(wxGrid
& grid
,
1861 wxGridCellAttr
& attr
,
1863 const wxRect
& rectCell
,
1867 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1869 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1871 // draw the text right aligned by default
1873 attr
.GetAlignment(&hAlign
, &vAlign
);
1874 hAlign
= wxALIGN_RIGHT
;
1876 wxRect rect
= rectCell
;
1879 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1882 wxSize
wxGridCellFloatRenderer::GetBestSize(wxGrid
& grid
,
1883 wxGridCellAttr
& attr
,
1887 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1890 void wxGridCellFloatRenderer::SetParameters(const wxString
& params
)
1894 // reset to defaults
1900 wxString tmp
= params
.BeforeFirst(_T(','));
1904 if ( tmp
.ToLong(&width
) )
1906 SetWidth((int)width
);
1910 wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params
.c_str());
1914 tmp
= params
.AfterFirst(_T(','));
1918 if ( tmp
.ToLong(&precision
) )
1920 SetPrecision((int)precision
);
1924 wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params
.c_str());
1932 // ----------------------------------------------------------------------------
1933 // wxGridCellBoolRenderer
1934 // ----------------------------------------------------------------------------
1936 wxSize
wxGridCellBoolRenderer::ms_sizeCheckMark
;
1938 // FIXME these checkbox size calculations are really ugly...
1940 // between checkmark and box
1941 static const wxCoord wxGRID_CHECKMARK_MARGIN
= 2;
1943 wxSize
wxGridCellBoolRenderer::GetBestSize(wxGrid
& grid
,
1944 wxGridCellAttr
& WXUNUSED(attr
),
1949 // compute it only once (no locks for MT safeness in GUI thread...)
1950 if ( !ms_sizeCheckMark
.x
)
1952 // get checkbox size
1953 wxCoord checkSize
= 0;
1954 wxCheckBox
*checkbox
= new wxCheckBox(&grid
, -1, wxEmptyString
);
1955 wxSize size
= checkbox
->GetBestSize();
1956 checkSize
= size
.y
+ 2*wxGRID_CHECKMARK_MARGIN
;
1958 // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result
1959 #if defined(__WXGTK__) || defined(__WXMOTIF__)
1960 checkSize
-= size
.y
/ 2;
1965 ms_sizeCheckMark
.x
= ms_sizeCheckMark
.y
= checkSize
;
1968 return ms_sizeCheckMark
;
1971 void wxGridCellBoolRenderer::Draw(wxGrid
& grid
,
1972 wxGridCellAttr
& attr
,
1978 wxGridCellRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
1980 // draw a check mark in the centre (ignoring alignment - TODO)
1981 wxSize size
= GetBestSize(grid
, attr
, dc
, row
, col
);
1983 // don't draw outside the cell
1984 wxCoord minSize
= wxMin(rect
.width
, rect
.height
);
1985 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
1987 // and even leave (at least) 1 pixel margin
1988 size
.x
= size
.y
= minSize
- 2;
1991 // draw a border around checkmark
1993 attr
.GetAlignment(& hAlign
, &vAlign
);
1996 if (hAlign
== wxALIGN_CENTRE
)
1998 rectBorder
.x
= rect
.x
+ rect
.width
/2 - size
.x
/2;
1999 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
2000 rectBorder
.width
= size
.x
;
2001 rectBorder
.height
= size
.y
;
2003 else if (hAlign
== wxALIGN_LEFT
)
2005 rectBorder
.x
= rect
.x
+ 2;
2006 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
2007 rectBorder
.width
= size
.x
;
2008 rectBorder
.height
= size
.y
;
2010 else if (hAlign
== wxALIGN_RIGHT
)
2012 rectBorder
.x
= rect
.x
+ rect
.width
- size
.x
- 2;
2013 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
2014 rectBorder
.width
= size
.x
;
2015 rectBorder
.height
= size
.y
;
2019 if ( grid
.GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
) )
2020 value
= grid
.GetTable()->GetValueAsBool(row
, col
);
2023 wxString
cellval( grid
.GetTable()->GetValue(row
, col
) );
2024 value
= !( !cellval
|| (cellval
== wxT("0")) );
2029 wxRect rectMark
= rectBorder
;
2031 // MSW DrawCheckMark() is weird (and should probably be changed...)
2032 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
/2);
2036 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
);
2039 dc
.SetTextForeground(attr
.GetTextColour());
2040 dc
.DrawCheckMark(rectMark
);
2043 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2044 dc
.SetPen(wxPen(attr
.GetTextColour(), 1, wxSOLID
));
2045 dc
.DrawRectangle(rectBorder
);
2048 // ----------------------------------------------------------------------------
2050 // ----------------------------------------------------------------------------
2052 void wxGridCellAttr::Init(wxGridCellAttr
*attrDefault
)
2056 m_isReadOnly
= Unset
;
2061 m_attrkind
= wxGridCellAttr::Cell
;
2063 m_sizeRows
= m_sizeCols
= 1;
2064 m_overflow
= UnsetOverflow
;
2066 SetDefAttr(attrDefault
);
2069 wxGridCellAttr
*wxGridCellAttr::Clone() const
2071 wxGridCellAttr
*attr
= new wxGridCellAttr(m_defGridAttr
);
2073 if ( HasTextColour() )
2074 attr
->SetTextColour(GetTextColour());
2075 if ( HasBackgroundColour() )
2076 attr
->SetBackgroundColour(GetBackgroundColour());
2078 attr
->SetFont(GetFont());
2079 if ( HasAlignment() )
2080 attr
->SetAlignment(m_hAlign
, m_vAlign
);
2082 attr
->SetSize( m_sizeRows
, m_sizeCols
);
2086 attr
->SetRenderer(m_renderer
);
2087 m_renderer
->IncRef();
2091 attr
->SetEditor(m_editor
);
2096 attr
->SetReadOnly();
2098 attr
->SetKind( m_attrkind
);
2103 void wxGridCellAttr::MergeWith(wxGridCellAttr
*mergefrom
)
2105 if ( !HasTextColour() && mergefrom
->HasTextColour() )
2106 SetTextColour(mergefrom
->GetTextColour());
2107 if ( !HasBackgroundColour() && mergefrom
->HasBackgroundColour() )
2108 SetBackgroundColour(mergefrom
->GetBackgroundColour());
2109 if ( !HasFont() && mergefrom
->HasFont() )
2110 SetFont(mergefrom
->GetFont());
2111 if ( !HasAlignment() && mergefrom
->HasAlignment() ){
2113 mergefrom
->GetAlignment( &hAlign
, &vAlign
);
2114 SetAlignment(hAlign
, vAlign
);
2117 mergefrom
->GetSize( &m_sizeRows
, &m_sizeCols
);
2119 // Directly access member functions as GetRender/Editor don't just return
2120 // m_renderer/m_editor
2122 // Maybe add support for merge of Render and Editor?
2123 if (!HasRenderer() && mergefrom
->HasRenderer() )
2125 m_renderer
= mergefrom
->m_renderer
;
2126 m_renderer
->IncRef();
2128 if ( !HasEditor() && mergefrom
->HasEditor() )
2130 m_editor
= mergefrom
->m_editor
;
2133 if ( !HasReadWriteMode() && mergefrom
->HasReadWriteMode() )
2134 SetReadOnly(mergefrom
->IsReadOnly());
2136 if (!HasOverflowMode() && mergefrom
->HasOverflowMode() )
2137 SetReadOnly(mergefrom
->GetOverflow());
2139 SetDefAttr(mergefrom
->m_defGridAttr
);
2142 void wxGridCellAttr::SetSize(int num_rows
, int num_cols
)
2144 // The size of a cell is normally 1,1
2146 // If this cell is larger (2,2) then this is the top left cell
2147 // the other cells that will be covered (lower right cells) must be
2148 // set to negative or zero values such that
2149 // row + num_rows of the covered cell points to the larger cell (this cell)
2150 // same goes for the col + num_cols.
2152 // Size of 0,0 is NOT valid, neither is <=0 and any positive value
2154 wxASSERT_MSG( (!((num_rows
>0)&&(num_cols
<=0)) ||
2155 !((num_rows
<=0)&&(num_cols
>0)) ||
2156 !((num_rows
==0)&&(num_cols
==0))),
2157 wxT("wxGridCellAttr::SetSize only takes two postive values or negative/zero values"));
2159 m_sizeRows
= num_rows
;
2160 m_sizeCols
= num_cols
;
2163 const wxColour
& wxGridCellAttr::GetTextColour() const
2165 if (HasTextColour())
2169 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2171 return m_defGridAttr
->GetTextColour();
2175 wxFAIL_MSG(wxT("Missing default cell attribute"));
2176 return wxNullColour
;
2181 const wxColour
& wxGridCellAttr::GetBackgroundColour() const
2183 if (HasBackgroundColour())
2185 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2186 return m_defGridAttr
->GetBackgroundColour();
2189 wxFAIL_MSG(wxT("Missing default cell attribute"));
2190 return wxNullColour
;
2195 const wxFont
& wxGridCellAttr::GetFont() const
2199 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2200 return m_defGridAttr
->GetFont();
2203 wxFAIL_MSG(wxT("Missing default cell attribute"));
2209 void wxGridCellAttr::GetAlignment(int *hAlign
, int *vAlign
) const
2213 if ( hAlign
) *hAlign
= m_hAlign
;
2214 if ( vAlign
) *vAlign
= m_vAlign
;
2216 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2217 m_defGridAttr
->GetAlignment(hAlign
, vAlign
);
2220 wxFAIL_MSG(wxT("Missing default cell attribute"));
2224 void wxGridCellAttr::GetSize( int *num_rows
, int *num_cols
) const
2226 if ( num_rows
) *num_rows
= m_sizeRows
;
2227 if ( num_cols
) *num_cols
= m_sizeCols
;
2230 // GetRenderer and GetEditor use a slightly different decision path about
2231 // which attribute to use. If a non-default attr object has one then it is
2232 // used, otherwise the default editor or renderer is fetched from the grid and
2233 // used. It should be the default for the data type of the cell. If it is
2234 // NULL (because the table has a type that the grid does not have in its
2235 // registry,) then the grid's default editor or renderer is used.
2237 wxGridCellRenderer
* wxGridCellAttr::GetRenderer(wxGrid
* grid
, int row
, int col
) const
2239 wxGridCellRenderer
*renderer
;
2241 if ( m_renderer
&& this != m_defGridAttr
)
2243 // use the cells renderer if it has one
2244 renderer
= m_renderer
;
2247 else // no non default cell renderer
2249 // get default renderer for the data type
2252 // GetDefaultRendererForCell() will do IncRef() for us
2253 renderer
= grid
->GetDefaultRendererForCell(row
, col
);
2262 if (m_defGridAttr
&& this != m_defGridAttr
)
2264 // if we still don't have one then use the grid default
2265 // (no need for IncRef() here neither)
2266 renderer
= m_defGridAttr
->GetRenderer(NULL
, 0, 0);
2268 else // default grid attr
2270 // use m_renderer which we had decided not to use initially
2271 renderer
= m_renderer
;
2278 // we're supposed to always find something
2279 wxASSERT_MSG(renderer
, wxT("Missing default cell renderer"));
2284 // same as above, except for s/renderer/editor/g
2285 wxGridCellEditor
* wxGridCellAttr::GetEditor(wxGrid
* grid
, int row
, int col
) const
2287 wxGridCellEditor
*editor
;
2289 if ( m_editor
&& this != m_defGridAttr
)
2291 // use the cells editor if it has one
2295 else // no non default cell editor
2297 // get default editor for the data type
2300 // GetDefaultEditorForCell() will do IncRef() for us
2301 editor
= grid
->GetDefaultEditorForCell(row
, col
);
2310 if ( m_defGridAttr
&& this != m_defGridAttr
)
2312 // if we still don't have one then use the grid default
2313 // (no need for IncRef() here neither)
2314 editor
= m_defGridAttr
->GetEditor(NULL
, 0, 0);
2316 else // default grid attr
2318 // use m_editor which we had decided not to use initially
2326 // we're supposed to always find something
2327 wxASSERT_MSG(editor
, wxT("Missing default cell editor"));
2332 // ----------------------------------------------------------------------------
2333 // wxGridCellAttrData
2334 // ----------------------------------------------------------------------------
2336 void wxGridCellAttrData::SetAttr(wxGridCellAttr
*attr
, int row
, int col
)
2338 int n
= FindIndex(row
, col
);
2339 if ( n
== wxNOT_FOUND
)
2341 // add the attribute
2342 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
2346 // free the old attribute
2347 m_attrs
[(size_t)n
].attr
->DecRef();
2351 // change the attribute
2352 m_attrs
[(size_t)n
].attr
= attr
;
2356 // remove this attribute
2357 m_attrs
.RemoveAt((size_t)n
);
2362 wxGridCellAttr
*wxGridCellAttrData::GetAttr(int row
, int col
) const
2364 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2366 int n
= FindIndex(row
, col
);
2367 if ( n
!= wxNOT_FOUND
)
2369 attr
= m_attrs
[(size_t)n
].attr
;
2376 void wxGridCellAttrData::UpdateAttrRows( size_t pos
, int numRows
)
2378 size_t count
= m_attrs
.GetCount();
2379 for ( size_t n
= 0; n
< count
; n
++ )
2381 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2382 wxCoord row
= coords
.GetRow();
2383 if ((size_t)row
>= pos
)
2387 // If rows inserted, include row counter where necessary
2388 coords
.SetRow(row
+ numRows
);
2390 else if (numRows
< 0)
2392 // If rows deleted ...
2393 if ((size_t)row
>= pos
- numRows
)
2395 // ...either decrement row counter (if row still exists)...
2396 coords
.SetRow(row
+ numRows
);
2400 // ...or remove the attribute
2401 m_attrs
.RemoveAt((size_t)n
);
2409 void wxGridCellAttrData::UpdateAttrCols( size_t pos
, int numCols
)
2411 size_t count
= m_attrs
.GetCount();
2412 for ( size_t n
= 0; n
< count
; n
++ )
2414 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2415 wxCoord col
= coords
.GetCol();
2416 if ( (size_t)col
>= pos
)
2420 // If rows inserted, include row counter where necessary
2421 coords
.SetCol(col
+ numCols
);
2423 else if (numCols
< 0)
2425 // If rows deleted ...
2426 if ((size_t)col
>= pos
- numCols
)
2428 // ...either decrement row counter (if row still exists)...
2429 coords
.SetCol(col
+ numCols
);
2433 // ...or remove the attribute
2434 m_attrs
.RemoveAt((size_t)n
);
2442 int wxGridCellAttrData::FindIndex(int row
, int col
) const
2444 size_t count
= m_attrs
.GetCount();
2445 for ( size_t n
= 0; n
< count
; n
++ )
2447 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2448 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
2457 // ----------------------------------------------------------------------------
2458 // wxGridRowOrColAttrData
2459 // ----------------------------------------------------------------------------
2461 wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
2463 size_t count
= m_attrs
.Count();
2464 for ( size_t n
= 0; n
< count
; n
++ )
2466 m_attrs
[n
]->DecRef();
2470 wxGridCellAttr
*wxGridRowOrColAttrData::GetAttr(int rowOrCol
) const
2472 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2474 int n
= m_rowsOrCols
.Index(rowOrCol
);
2475 if ( n
!= wxNOT_FOUND
)
2477 attr
= m_attrs
[(size_t)n
];
2484 void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr
*attr
, int rowOrCol
)
2486 int i
= m_rowsOrCols
.Index(rowOrCol
);
2487 if ( i
== wxNOT_FOUND
)
2489 // add the attribute
2490 m_rowsOrCols
.Add(rowOrCol
);
2495 size_t n
= (size_t)i
;
2498 // change the attribute
2499 m_attrs
[n
]->DecRef();
2504 // remove this attribute
2505 m_attrs
[n
]->DecRef();
2506 m_rowsOrCols
.RemoveAt(n
);
2507 m_attrs
.RemoveAt(n
);
2512 void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
)
2514 size_t count
= m_attrs
.GetCount();
2515 for ( size_t n
= 0; n
< count
; n
++ )
2517 int & rowOrCol
= m_rowsOrCols
[n
];
2518 if ( (size_t)rowOrCol
>= pos
)
2520 if ( numRowsOrCols
> 0 )
2522 // If rows inserted, include row counter where necessary
2523 rowOrCol
+= numRowsOrCols
;
2525 else if ( numRowsOrCols
< 0)
2527 // If rows deleted, either decrement row counter (if row still exists)
2528 if ((size_t)rowOrCol
>= pos
- numRowsOrCols
)
2529 rowOrCol
+= numRowsOrCols
;
2532 m_rowsOrCols
.RemoveAt((size_t)n
);
2533 m_attrs
.RemoveAt((size_t)n
);
2541 // ----------------------------------------------------------------------------
2542 // wxGridCellAttrProvider
2543 // ----------------------------------------------------------------------------
2545 wxGridCellAttrProvider::wxGridCellAttrProvider()
2547 m_data
= (wxGridCellAttrProviderData
*)NULL
;
2550 wxGridCellAttrProvider::~wxGridCellAttrProvider()
2555 void wxGridCellAttrProvider::InitData()
2557 m_data
= new wxGridCellAttrProviderData
;
2560 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
,
2561 wxGridCellAttr::wxAttrKind kind
) const
2563 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2568 case (wxGridCellAttr::Any
):
2569 //Get cached merge attributes.
2570 // Currenlty not used as no cache implemented as not mutiable
2571 // attr = m_data->m_mergeAttr.GetAttr(row, col);
2574 //Basicaly implement old version.
2575 //Also check merge cache, so we don't have to re-merge every time..
2576 wxGridCellAttr
*attrcell
= (wxGridCellAttr
*)NULL
,
2577 *attrrow
= (wxGridCellAttr
*)NULL
,
2578 *attrcol
= (wxGridCellAttr
*)NULL
;
2580 attrcell
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
2581 attrcol
= m_data
->m_colAttrs
.GetAttr(col
);
2582 attrrow
= m_data
->m_rowAttrs
.GetAttr(row
);
2584 if((attrcell
!= attrrow
) && (attrrow
!=attrcol
) && (attrcell
!= attrcol
)){
2585 // Two or move are non NULL
2586 attr
= new wxGridCellAttr
;
2587 attr
->SetKind(wxGridCellAttr::Merged
);
2591 attr
->MergeWith(attrcell
);
2595 attr
->MergeWith(attrcol
);
2599 attr
->MergeWith(attrrow
);
2602 //store merge attr if cache implemented
2604 //m_data->m_mergeAttr.SetAttr(attr, row, col);
2608 // one or none is non null return it or null.
2609 if(attrrow
) attr
= attrrow
;
2610 if(attrcol
) attr
= attrcol
;
2611 if(attrcell
) attr
= attrcell
;
2615 case (wxGridCellAttr::Cell
):
2616 attr
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
2618 case (wxGridCellAttr::Col
):
2619 attr
= m_data
->m_colAttrs
.GetAttr(col
);
2621 case (wxGridCellAttr::Row
):
2622 attr
= m_data
->m_rowAttrs
.GetAttr(row
);
2626 // (wxGridCellAttr::Default):
2627 // (wxGridCellAttr::Merged):
2634 void wxGridCellAttrProvider::SetAttr(wxGridCellAttr
*attr
,
2640 m_data
->m_cellAttrs
.SetAttr(attr
, row
, col
);
2643 void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr
*attr
, int row
)
2648 m_data
->m_rowAttrs
.SetAttr(attr
, row
);
2651 void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr
*attr
, int col
)
2656 m_data
->m_colAttrs
.SetAttr(attr
, col
);
2659 void wxGridCellAttrProvider::UpdateAttrRows( size_t pos
, int numRows
)
2663 m_data
->m_cellAttrs
.UpdateAttrRows( pos
, numRows
);
2665 m_data
->m_rowAttrs
.UpdateAttrRowsOrCols( pos
, numRows
);
2669 void wxGridCellAttrProvider::UpdateAttrCols( size_t pos
, int numCols
)
2673 m_data
->m_cellAttrs
.UpdateAttrCols( pos
, numCols
);
2675 m_data
->m_colAttrs
.UpdateAttrRowsOrCols( pos
, numCols
);
2679 // ----------------------------------------------------------------------------
2680 // wxGridTypeRegistry
2681 // ----------------------------------------------------------------------------
2683 wxGridTypeRegistry::~wxGridTypeRegistry()
2685 size_t count
= m_typeinfo
.Count();
2686 for ( size_t i
= 0; i
< count
; i
++ )
2687 delete m_typeinfo
[i
];
2691 void wxGridTypeRegistry::RegisterDataType(const wxString
& typeName
,
2692 wxGridCellRenderer
* renderer
,
2693 wxGridCellEditor
* editor
)
2695 wxGridDataTypeInfo
* info
= new wxGridDataTypeInfo(typeName
, renderer
, editor
);
2697 // is it already registered?
2698 int loc
= FindRegisteredDataType(typeName
);
2699 if ( loc
!= wxNOT_FOUND
)
2701 delete m_typeinfo
[loc
];
2702 m_typeinfo
[loc
] = info
;
2706 m_typeinfo
.Add(info
);
2710 int wxGridTypeRegistry::FindRegisteredDataType(const wxString
& typeName
)
2712 size_t count
= m_typeinfo
.GetCount();
2713 for ( size_t i
= 0; i
< count
; i
++ )
2715 if ( typeName
== m_typeinfo
[i
]->m_typeName
)
2724 int wxGridTypeRegistry::FindDataType(const wxString
& typeName
)
2726 int index
= FindRegisteredDataType(typeName
);
2727 if ( index
== wxNOT_FOUND
)
2729 // check whether this is one of the standard ones, in which case
2730 // register it "on the fly"
2732 if ( typeName
== wxGRID_VALUE_STRING
)
2734 RegisterDataType(wxGRID_VALUE_STRING
,
2735 new wxGridCellStringRenderer
,
2736 new wxGridCellTextEditor
);
2738 #endif // wxUSE_TEXTCTRL
2740 if ( typeName
== wxGRID_VALUE_BOOL
)
2742 RegisterDataType(wxGRID_VALUE_BOOL
,
2743 new wxGridCellBoolRenderer
,
2744 new wxGridCellBoolEditor
);
2746 #endif // wxUSE_CHECKBOX
2748 if ( typeName
== wxGRID_VALUE_NUMBER
)
2750 RegisterDataType(wxGRID_VALUE_NUMBER
,
2751 new wxGridCellNumberRenderer
,
2752 new wxGridCellNumberEditor
);
2754 else if ( typeName
== wxGRID_VALUE_FLOAT
)
2756 RegisterDataType(wxGRID_VALUE_FLOAT
,
2757 new wxGridCellFloatRenderer
,
2758 new wxGridCellFloatEditor
);
2760 #endif // wxUSE_TEXTCTRL
2762 if ( typeName
== wxGRID_VALUE_CHOICE
)
2764 RegisterDataType(wxGRID_VALUE_CHOICE
,
2765 new wxGridCellStringRenderer
,
2766 new wxGridCellChoiceEditor
);
2768 #endif // wxUSE_COMBOBOX
2773 // we get here only if just added the entry for this type, so return
2775 index
= m_typeinfo
.GetCount() - 1;
2781 int wxGridTypeRegistry::FindOrCloneDataType(const wxString
& typeName
)
2783 int index
= FindDataType(typeName
);
2784 if ( index
== wxNOT_FOUND
)
2786 // the first part of the typename is the "real" type, anything after ':'
2787 // are the parameters for the renderer
2788 index
= FindDataType(typeName
.BeforeFirst(_T(':')));
2789 if ( index
== wxNOT_FOUND
)
2794 wxGridCellRenderer
*renderer
= GetRenderer(index
);
2795 wxGridCellRenderer
*rendererOld
= renderer
;
2796 renderer
= renderer
->Clone();
2797 rendererOld
->DecRef();
2799 wxGridCellEditor
*editor
= GetEditor(index
);
2800 wxGridCellEditor
*editorOld
= editor
;
2801 editor
= editor
->Clone();
2802 editorOld
->DecRef();
2804 // do it even if there are no parameters to reset them to defaults
2805 wxString params
= typeName
.AfterFirst(_T(':'));
2806 renderer
->SetParameters(params
);
2807 editor
->SetParameters(params
);
2809 // register the new typename
2810 RegisterDataType(typeName
, renderer
, editor
);
2812 // we just registered it, it's the last one
2813 index
= m_typeinfo
.GetCount() - 1;
2819 wxGridCellRenderer
* wxGridTypeRegistry::GetRenderer(int index
)
2821 wxGridCellRenderer
* renderer
= m_typeinfo
[index
]->m_renderer
;
2827 wxGridCellEditor
* wxGridTypeRegistry::GetEditor(int index
)
2829 wxGridCellEditor
* editor
= m_typeinfo
[index
]->m_editor
;
2835 // ----------------------------------------------------------------------------
2837 // ----------------------------------------------------------------------------
2839 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
2842 wxGridTableBase::wxGridTableBase()
2844 m_view
= (wxGrid
*) NULL
;
2845 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
2848 wxGridTableBase::~wxGridTableBase()
2850 delete m_attrProvider
;
2853 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
2855 delete m_attrProvider
;
2856 m_attrProvider
= attrProvider
;
2859 bool wxGridTableBase::CanHaveAttributes()
2861 if ( ! GetAttrProvider() )
2863 // use the default attr provider by default
2864 SetAttrProvider(new wxGridCellAttrProvider
);
2869 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
, wxGridCellAttr::wxAttrKind kind
)
2871 if ( m_attrProvider
)
2872 return m_attrProvider
->GetAttr(row
, col
, kind
);
2874 return (wxGridCellAttr
*)NULL
;
2877 void wxGridTableBase::SetAttr(wxGridCellAttr
* attr
, int row
, int col
)
2879 if ( m_attrProvider
)
2881 attr
->SetKind(wxGridCellAttr::Cell
);
2882 m_attrProvider
->SetAttr(attr
, row
, col
);
2886 // as we take ownership of the pointer and don't store it, we must
2892 void wxGridTableBase::SetRowAttr(wxGridCellAttr
*attr
, int row
)
2894 if ( m_attrProvider
)
2896 attr
->SetKind(wxGridCellAttr::Row
);
2897 m_attrProvider
->SetRowAttr(attr
, row
);
2901 // as we take ownership of the pointer and don't store it, we must
2907 void wxGridTableBase::SetColAttr(wxGridCellAttr
*attr
, int col
)
2909 if ( m_attrProvider
)
2911 attr
->SetKind(wxGridCellAttr::Col
);
2912 m_attrProvider
->SetColAttr(attr
, col
);
2916 // as we take ownership of the pointer and don't store it, we must
2922 bool wxGridTableBase::InsertRows( size_t WXUNUSED(pos
),
2923 size_t WXUNUSED(numRows
) )
2925 wxFAIL_MSG( wxT("Called grid table class function InsertRows\nbut your derived table class does not override this function") );
2930 bool wxGridTableBase::AppendRows( size_t WXUNUSED(numRows
) )
2932 wxFAIL_MSG( wxT("Called grid table class function AppendRows\nbut your derived table class does not override this function"));
2937 bool wxGridTableBase::DeleteRows( size_t WXUNUSED(pos
),
2938 size_t WXUNUSED(numRows
) )
2940 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\nbut your derived table class does not override this function"));
2945 bool wxGridTableBase::InsertCols( size_t WXUNUSED(pos
),
2946 size_t WXUNUSED(numCols
) )
2948 wxFAIL_MSG( wxT("Called grid table class function InsertCols\nbut your derived table class does not override this function"));
2953 bool wxGridTableBase::AppendCols( size_t WXUNUSED(numCols
) )
2955 wxFAIL_MSG(wxT("Called grid table class function AppendCols\nbut your derived table class does not override this function"));
2960 bool wxGridTableBase::DeleteCols( size_t WXUNUSED(pos
),
2961 size_t WXUNUSED(numCols
) )
2963 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\nbut your derived table class does not override this function"));
2969 wxString
wxGridTableBase::GetRowLabelValue( int row
)
2972 s
<< row
+ 1; // RD: Starting the rows at zero confuses users, no matter
2973 // how much it makes sense to us geeks.
2977 wxString
wxGridTableBase::GetColLabelValue( int col
)
2979 // default col labels are:
2980 // cols 0 to 25 : A-Z
2981 // cols 26 to 675 : AA-ZZ
2986 for ( n
= 1; ; n
++ )
2988 s
+= (_T('A') + (wxChar
)( col%26
));
2990 if ( col
< 0 ) break;
2993 // reverse the string...
2995 for ( i
= 0; i
< n
; i
++ )
3004 wxString
wxGridTableBase::GetTypeName( int WXUNUSED(row
), int WXUNUSED(col
) )
3006 return wxGRID_VALUE_STRING
;
3009 bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row
), int WXUNUSED(col
),
3010 const wxString
& typeName
)
3012 return typeName
== wxGRID_VALUE_STRING
;
3015 bool wxGridTableBase::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
3017 return CanGetValueAs(row
, col
, typeName
);
3020 long wxGridTableBase::GetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
) )
3025 double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
) )
3030 bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
) )
3035 void wxGridTableBase::SetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
),
3036 long WXUNUSED(value
) )
3040 void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
),
3041 double WXUNUSED(value
) )
3045 void wxGridTableBase::SetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
),
3046 bool WXUNUSED(value
) )
3051 void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
3052 const wxString
& WXUNUSED(typeName
) )
3057 void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
3058 const wxString
& WXUNUSED(typeName
),
3059 void* WXUNUSED(value
) )
3063 //////////////////////////////////////////////////////////////////////
3065 // Message class for the grid table to send requests and notifications
3069 wxGridTableMessage::wxGridTableMessage()
3071 m_table
= (wxGridTableBase
*) NULL
;
3077 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
3078 int commandInt1
, int commandInt2
)
3082 m_comInt1
= commandInt1
;
3083 m_comInt2
= commandInt2
;
3088 //////////////////////////////////////////////////////////////////////
3090 // A basic grid table for string data. An object of this class will
3091 // created by wxGrid if you don't specify an alternative table class.
3094 WX_DEFINE_OBJARRAY(wxGridStringArray
)
3096 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
3098 wxGridStringTable::wxGridStringTable()
3103 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
3106 m_data
.Alloc( numRows
);
3109 sa
.Alloc( numCols
);
3110 sa
.Add( wxEmptyString
, numCols
);
3112 m_data
.Add( sa
, numRows
);
3115 wxGridStringTable::~wxGridStringTable()
3119 int wxGridStringTable::GetNumberRows()
3121 return m_data
.GetCount();
3124 int wxGridStringTable::GetNumberCols()
3126 if ( m_data
.GetCount() > 0 )
3127 return m_data
[0].GetCount();
3132 wxString
wxGridStringTable::GetValue( int row
, int col
)
3134 wxASSERT_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3135 _T("invalid row or column index in wxGridStringTable") );
3137 return m_data
[row
][col
];
3140 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& value
)
3142 wxASSERT_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3143 _T("invalid row or column index in wxGridStringTable") );
3145 m_data
[row
][col
] = value
;
3148 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
3150 wxASSERT_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3151 _T("invalid row or column index in wxGridStringTable") );
3153 return (m_data
[row
][col
] == wxEmptyString
);
3156 void wxGridStringTable::Clear()
3159 int numRows
, numCols
;
3161 numRows
= m_data
.GetCount();
3164 numCols
= m_data
[0].GetCount();
3166 for ( row
= 0; row
< numRows
; row
++ )
3168 for ( col
= 0; col
< numCols
; col
++ )
3170 m_data
[row
][col
] = wxEmptyString
;
3177 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
3179 size_t curNumRows
= m_data
.GetCount();
3180 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3181 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3183 if ( pos
>= curNumRows
)
3185 return AppendRows( numRows
);
3189 sa
.Alloc( curNumCols
);
3190 sa
.Add( wxEmptyString
, curNumCols
);
3191 m_data
.Insert( sa
, pos
, numRows
);
3194 wxGridTableMessage
msg( this,
3195 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
3199 GetView()->ProcessTableMessage( msg
);
3205 bool wxGridStringTable::AppendRows( size_t numRows
)
3207 size_t curNumRows
= m_data
.GetCount();
3208 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3209 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3212 if ( curNumCols
> 0 )
3214 sa
.Alloc( curNumCols
);
3215 sa
.Add( wxEmptyString
, curNumCols
);
3218 m_data
.Add( sa
, numRows
);
3222 wxGridTableMessage
msg( this,
3223 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
3226 GetView()->ProcessTableMessage( msg
);
3232 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
3234 size_t curNumRows
= m_data
.GetCount();
3236 if ( pos
>= curNumRows
)
3238 wxFAIL_MSG( wxString::Format
3240 wxT("Called wxGridStringTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows"),
3242 (unsigned long)numRows
,
3243 (unsigned long)curNumRows
3249 if ( numRows
> curNumRows
- pos
)
3251 numRows
= curNumRows
- pos
;
3254 if ( numRows
>= curNumRows
)
3260 m_data
.RemoveAt( pos
, numRows
);
3264 wxGridTableMessage
msg( this,
3265 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
3269 GetView()->ProcessTableMessage( msg
);
3275 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
3279 size_t curNumRows
= m_data
.GetCount();
3280 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3281 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3283 if ( pos
>= curNumCols
)
3285 return AppendCols( numCols
);
3288 for ( row
= 0; row
< curNumRows
; row
++ )
3290 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
3292 m_data
[row
].Insert( wxEmptyString
, col
);
3297 wxGridTableMessage
msg( this,
3298 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
3302 GetView()->ProcessTableMessage( msg
);
3308 bool wxGridStringTable::AppendCols( size_t numCols
)
3312 size_t curNumRows
= m_data
.GetCount();
3316 // TODO: something better than this ?
3318 wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\nCall AppendRows() first") );
3323 for ( row
= 0; row
< curNumRows
; row
++ )
3325 m_data
[row
].Add( wxEmptyString
, numCols
);
3330 wxGridTableMessage
msg( this,
3331 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
3334 GetView()->ProcessTableMessage( msg
);
3340 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
3344 size_t curNumRows
= m_data
.GetCount();
3345 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3346 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3348 if ( pos
>= curNumCols
)
3350 wxFAIL_MSG( wxString::Format
3352 wxT("Called wxGridStringTable::DeleteCols(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu cols"),
3354 (unsigned long)numCols
,
3355 (unsigned long)curNumCols
3360 if ( numCols
> curNumCols
- pos
)
3362 numCols
= curNumCols
- pos
;
3365 for ( row
= 0; row
< curNumRows
; row
++ )
3367 if ( numCols
>= curNumCols
)
3369 m_data
[row
].Clear();
3373 m_data
[row
].RemoveAt( pos
, numCols
);
3378 wxGridTableMessage
msg( this,
3379 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
3383 GetView()->ProcessTableMessage( msg
);
3389 wxString
wxGridStringTable::GetRowLabelValue( int row
)
3391 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
3393 // using default label
3395 return wxGridTableBase::GetRowLabelValue( row
);
3399 return m_rowLabels
[ row
];
3403 wxString
wxGridStringTable::GetColLabelValue( int col
)
3405 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
3407 // using default label
3409 return wxGridTableBase::GetColLabelValue( col
);
3413 return m_colLabels
[ col
];
3417 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
3419 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
3421 int n
= m_rowLabels
.GetCount();
3423 for ( i
= n
; i
<= row
; i
++ )
3425 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
3429 m_rowLabels
[row
] = value
;
3432 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
3434 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
3436 int n
= m_colLabels
.GetCount();
3438 for ( i
= n
; i
<= col
; i
++ )
3440 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
3444 m_colLabels
[col
] = value
;
3449 //////////////////////////////////////////////////////////////////////
3450 //////////////////////////////////////////////////////////////////////
3452 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
3454 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
3455 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
3456 EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel
)
3457 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
3458 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
3459 EVT_KEY_UP( wxGridRowLabelWindow::OnKeyUp
)
3462 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
3464 const wxPoint
&pos
, const wxSize
&size
)
3465 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
)
3470 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3474 // NO - don't do this because it will set both the x and y origin
3475 // coords to match the parent scrolled window and we just want to
3476 // set the y coord - MB
3478 // m_owner->PrepareDC( dc );
3481 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
3482 dc
.SetDeviceOrigin( 0, -y
);
3484 wxArrayInt rows
= m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
3485 m_owner
->DrawRowLabels( dc
, rows
);
3489 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3491 m_owner
->ProcessRowLabelMouseEvent( event
);
3495 void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3497 m_owner
->GetEventHandler()->ProcessEvent(event
);
3501 // This seems to be required for wxMotif otherwise the mouse
3502 // cursor must be in the cell edit control to get key events
3504 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3506 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3509 void wxGridRowLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3511 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3516 //////////////////////////////////////////////////////////////////////
3518 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
3520 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
3521 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
3522 EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel
)
3523 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
3524 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
3525 EVT_KEY_UP( wxGridColLabelWindow::OnKeyUp
)
3528 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
3530 const wxPoint
&pos
, const wxSize
&size
)
3531 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
)
3536 void wxGridColLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3540 // NO - don't do this because it will set both the x and y origin
3541 // coords to match the parent scrolled window and we just want to
3542 // set the x coord - MB
3544 // m_owner->PrepareDC( dc );
3547 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
3548 dc
.SetDeviceOrigin( -x
, 0 );
3550 wxArrayInt cols
= m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
3551 m_owner
->DrawColLabels( dc
, cols
);
3555 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3557 m_owner
->ProcessColLabelMouseEvent( event
);
3560 void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3562 m_owner
->GetEventHandler()->ProcessEvent(event
);
3566 // This seems to be required for wxMotif otherwise the mouse
3567 // cursor must be in the cell edit control to get key events
3569 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3571 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3574 void wxGridColLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3576 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3581 //////////////////////////////////////////////////////////////////////
3583 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
3585 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
3586 EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel
)
3587 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
3588 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
3589 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
3590 EVT_KEY_UP( wxGridCornerLabelWindow::OnKeyUp
)
3593 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
3595 const wxPoint
&pos
, const wxSize
&size
)
3596 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
)
3601 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3605 int client_height
= 0;
3606 int client_width
= 0;
3607 GetClientSize( &client_width
, &client_height
);
3609 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
),1, wxSOLID
) );
3610 dc
.DrawLine( client_width
-1, client_height
-1, client_width
-1, 0 );
3611 dc
.DrawLine( client_width
-1, client_height
-1, 0, client_height
-1 );
3612 dc
.DrawLine( 0, 0, client_width
, 0 );
3613 dc
.DrawLine( 0, 0, 0, client_height
);
3615 dc
.SetPen( *wxWHITE_PEN
);
3616 dc
.DrawLine( 1, 1, client_width
-1, 1 );
3617 dc
.DrawLine( 1, 1, 1, client_height
-1 );
3621 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3623 m_owner
->ProcessCornerLabelMouseEvent( event
);
3627 void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3629 m_owner
->GetEventHandler()->ProcessEvent(event
);
3632 // This seems to be required for wxMotif otherwise the mouse
3633 // cursor must be in the cell edit control to get key events
3635 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3637 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3640 void wxGridCornerLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3642 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3647 //////////////////////////////////////////////////////////////////////
3649 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxWindow
)
3651 BEGIN_EVENT_TABLE( wxGridWindow
, wxWindow
)
3652 EVT_PAINT( wxGridWindow::OnPaint
)
3653 EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel
)
3654 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
3655 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
3656 EVT_KEY_UP( wxGridWindow::OnKeyUp
)
3657 EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground
)
3660 wxGridWindow::wxGridWindow( wxGrid
*parent
,
3661 wxGridRowLabelWindow
*rowLblWin
,
3662 wxGridColLabelWindow
*colLblWin
,
3665 const wxSize
&size
)
3666 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
| wxBORDER_NONE
| wxCLIP_CHILDREN
,
3667 wxT("grid window") )
3671 m_rowLabelWin
= rowLblWin
;
3672 m_colLabelWin
= colLblWin
;
3673 SetBackgroundColour(_T("WHITE"));
3677 wxGridWindow::~wxGridWindow()
3682 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
3684 wxPaintDC
dc( this );
3685 m_owner
->PrepareDC( dc
);
3686 wxRegion reg
= GetUpdateRegion();
3687 wxGridCellCoordsArray DirtyCells
= m_owner
->CalcCellsExposed( reg
);
3688 m_owner
->DrawGridCellArea( dc
, DirtyCells
);
3689 #if WXGRID_DRAW_LINES
3690 m_owner
->DrawAllGridLines( dc
, reg
);
3692 m_owner
->DrawGridSpace( dc
);
3693 m_owner
->DrawHighlight( dc
, DirtyCells
);
3697 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
3699 wxWindow::ScrollWindow( dx
, dy
, rect
);
3700 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
3701 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
3705 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
3707 m_owner
->ProcessGridCellMouseEvent( event
);
3710 void wxGridWindow::OnMouseWheel( wxMouseEvent
& event
)
3712 m_owner
->GetEventHandler()->ProcessEvent(event
);
3715 // This seems to be required for wxMotif/wxGTK otherwise the mouse
3716 // cursor must be in the cell edit control to get key events
3718 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
3720 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3723 void wxGridWindow::OnKeyUp( wxKeyEvent
& event
)
3725 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3728 void wxGridWindow::OnEraseBackground( wxEraseEvent
& WXUNUSED(event
) )
3733 //////////////////////////////////////////////////////////////////////
3735 // Internal Helper function for computing row or column from some
3736 // (unscrolled) coordinate value, using either
3737 // m_defaultRowHeight/m_defaultColWidth or binary search on array
3738 // of m_rowBottoms/m_ColRights to speed up the search!
3740 // Internal helper macros for simpler use of that function
3742 static int CoordToRowOrCol(int coord
, int defaultDist
, int minDist
,
3743 const wxArrayInt
& BorderArray
, int nMax
,
3746 #define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \
3747 WXGRID_MIN_COL_WIDTH, \
3748 m_colRights, m_numCols, TRUE)
3749 #define internalYToRow(y) CoordToRowOrCol(y, m_defaultRowHeight, \
3750 WXGRID_MIN_ROW_HEIGHT, \
3751 m_rowBottoms, m_numRows, TRUE)
3752 /////////////////////////////////////////////////////////////////////
3754 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
3756 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
3757 EVT_PAINT( wxGrid::OnPaint
)
3758 EVT_SIZE( wxGrid::OnSize
)
3759 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
3760 EVT_KEY_UP( wxGrid::OnKeyUp
)
3761 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
3764 wxGrid::wxGrid( wxWindow
*parent
,
3769 const wxString
& name
)
3770 : wxScrolledWindow( parent
, id
, pos
, size
, (style
| wxWANTS_CHARS
), name
),
3771 m_colMinWidths(GRID_HASH_SIZE
),
3772 m_rowMinHeights(GRID_HASH_SIZE
)
3780 // Must do this or ~wxScrollHelper will pop the wrong event handler
3781 SetTargetWindow(this);
3783 wxSafeDecRef(m_defaultCellAttr
);
3785 #ifdef DEBUG_ATTR_CACHE
3786 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
3787 wxPrintf(_T("wxGrid attribute cache statistics: "
3788 "total: %u, hits: %u (%u%%)\n"),
3789 total
, gs_nAttrCacheHits
,
3790 total
? (gs_nAttrCacheHits
*100) / total
: 0);
3796 delete m_typeRegistry
;
3802 // ----- internal init and update functions
3805 void wxGrid::Create()
3807 m_created
= FALSE
; // set to TRUE by CreateGrid
3809 m_table
= (wxGridTableBase
*) NULL
;
3812 m_cellEditCtrlEnabled
= FALSE
;
3814 m_defaultCellAttr
= new wxGridCellAttr();
3816 // Set default cell attributes
3817 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
3818 m_defaultCellAttr
->SetKind(wxGridCellAttr::Default
);
3819 m_defaultCellAttr
->SetFont(GetFont());
3820 m_defaultCellAttr
->SetAlignment(wxALIGN_LEFT
, wxALIGN_TOP
);
3821 m_defaultCellAttr
->SetTextColour(
3822 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
3823 m_defaultCellAttr
->SetBackgroundColour(
3824 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
3825 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
3826 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
3831 m_currentCellCoords
= wxGridNoCellCoords
;
3833 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
3834 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
3836 // create the type registry
3837 m_typeRegistry
= new wxGridTypeRegistry
;
3840 // subwindow components that make up the wxGrid
3841 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
3846 m_rowLabelWin
= new wxGridRowLabelWindow( this,
3851 m_colLabelWin
= new wxGridColLabelWindow( this,
3856 m_gridWin
= new wxGridWindow( this,
3863 SetTargetWindow( m_gridWin
);
3869 bool wxGrid::CreateGrid( int numRows
, int numCols
,
3870 wxGrid::wxGridSelectionModes selmode
)
3872 wxCHECK_MSG( !m_created
,
3874 wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
3876 m_numRows
= numRows
;
3877 m_numCols
= numCols
;
3879 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
3880 m_table
->SetView( this );
3882 m_selection
= new wxGridSelection( this, selmode
);
3891 void wxGrid::SetSelectionMode(wxGrid::wxGridSelectionModes selmode
)
3893 wxCHECK_RET( m_created
,
3894 wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") );
3896 m_selection
->SetSelectionMode( selmode
);
3899 wxGrid::wxGridSelectionModes
wxGrid::GetSelectionMode() const
3901 wxCHECK_MSG( m_created
, wxGrid::wxGridSelectCells
,
3902 wxT("Called wxGrid::GetSelectionMode() before calling CreateGrid()") );
3904 return m_selection
->GetSelectionMode();
3907 bool wxGrid::SetTable( wxGridTableBase
*table
, bool takeOwnership
,
3908 wxGrid::wxGridSelectionModes selmode
)
3912 // RD: Actually, this should probably be allowed. I think it would be
3913 // nice to be able to switch multiple Tables in and out of a single
3914 // View at runtime. Is there anything in the implementation that
3915 // would prevent this?
3917 // At least, you now have to cope with m_selection
3918 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
3923 m_numRows
= table
->GetNumberRows();
3924 m_numCols
= table
->GetNumberCols();
3927 m_table
->SetView( this );
3930 m_selection
= new wxGridSelection( this, selmode
);
3943 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
3944 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
3946 if ( m_rowLabelWin
)
3948 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
3952 m_labelBackgroundColour
= wxColour( _T("WHITE") );
3955 m_labelTextColour
= wxColour( _T("BLACK") );
3958 m_attrCache
.row
= -1;
3959 m_attrCache
.col
= -1;
3960 m_attrCache
.attr
= NULL
;
3962 // TODO: something better than this ?
3964 m_labelFont
= this->GetFont();
3965 m_labelFont
.SetWeight( wxBOLD
);
3967 m_rowLabelHorizAlign
= wxALIGN_CENTRE
;
3968 m_rowLabelVertAlign
= wxALIGN_CENTRE
;
3970 m_colLabelHorizAlign
= wxALIGN_CENTRE
;
3971 m_colLabelVertAlign
= wxALIGN_CENTRE
;
3972 m_colLabelTextOrientation
= wxHORIZONTAL
;
3974 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
3975 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
3977 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
3978 m_defaultRowHeight
+= 8;
3980 m_defaultRowHeight
+= 4;
3983 m_gridLineColour
= wxColour( 192,192,192 );
3984 m_gridLinesEnabled
= TRUE
;
3985 m_cellHighlightColour
= *wxBLACK
;
3986 m_cellHighlightPenWidth
= 2;
3987 m_cellHighlightROPenWidth
= 1;
3989 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
3990 m_winCapture
= (wxWindow
*)NULL
;
3991 m_canDragRowSize
= TRUE
;
3992 m_canDragColSize
= TRUE
;
3993 m_canDragGridSize
= TRUE
;
3995 m_dragRowOrCol
= -1;
3996 m_isDragging
= FALSE
;
3997 m_startDragPos
= wxDefaultPosition
;
3999 m_waitForSlowClick
= FALSE
;
4001 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
4002 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
4004 m_currentCellCoords
= wxGridNoCellCoords
;
4006 m_selectingTopLeft
= wxGridNoCellCoords
;
4007 m_selectingBottomRight
= wxGridNoCellCoords
;
4008 m_selectionBackground
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
4009 m_selectionForeground
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
4011 m_editable
= TRUE
; // default for whole grid
4013 m_inOnKeyDown
= FALSE
;
4020 // ----------------------------------------------------------------------------
4021 // the idea is to call these functions only when necessary because they create
4022 // quite big arrays which eat memory mostly unnecessary - in particular, if
4023 // default widths/heights are used for all rows/columns, we may not use these
4026 // with some extra code, it should be possible to only store the
4027 // widths/heights different from default ones but this will be done later...
4028 // ----------------------------------------------------------------------------
4030 void wxGrid::InitRowHeights()
4032 m_rowHeights
.Empty();
4033 m_rowBottoms
.Empty();
4035 m_rowHeights
.Alloc( m_numRows
);
4036 m_rowBottoms
.Alloc( m_numRows
);
4040 m_rowHeights
.Add( m_defaultRowHeight
, m_numRows
);
4042 for ( int i
= 0; i
< m_numRows
; i
++ )
4044 rowBottom
+= m_defaultRowHeight
;
4045 m_rowBottoms
.Add( rowBottom
);
4049 void wxGrid::InitColWidths()
4051 m_colWidths
.Empty();
4052 m_colRights
.Empty();
4054 m_colWidths
.Alloc( m_numCols
);
4055 m_colRights
.Alloc( m_numCols
);
4058 m_colWidths
.Add( m_defaultColWidth
, m_numCols
);
4060 for ( int i
= 0; i
< m_numCols
; i
++ )
4062 colRight
+= m_defaultColWidth
;
4063 m_colRights
.Add( colRight
);
4067 int wxGrid::GetColWidth(int col
) const
4069 return m_colWidths
.IsEmpty() ? m_defaultColWidth
: m_colWidths
[col
];
4072 int wxGrid::GetColLeft(int col
) const
4074 return m_colRights
.IsEmpty() ? col
* m_defaultColWidth
4075 : m_colRights
[col
] - m_colWidths
[col
];
4078 int wxGrid::GetColRight(int col
) const
4080 return m_colRights
.IsEmpty() ? (col
+ 1) * m_defaultColWidth
4084 int wxGrid::GetRowHeight(int row
) const
4086 return m_rowHeights
.IsEmpty() ? m_defaultRowHeight
: m_rowHeights
[row
];
4089 int wxGrid::GetRowTop(int row
) const
4091 return m_rowBottoms
.IsEmpty() ? row
* m_defaultRowHeight
4092 : m_rowBottoms
[row
] - m_rowHeights
[row
];
4095 int wxGrid::GetRowBottom(int row
) const
4097 return m_rowBottoms
.IsEmpty() ? (row
+ 1) * m_defaultRowHeight
4098 : m_rowBottoms
[row
];
4101 void wxGrid::CalcDimensions()
4104 GetClientSize( &cw
, &ch
);
4106 if ( m_rowLabelWin
->IsShown() )
4107 cw
-= m_rowLabelWidth
;
4108 if ( m_colLabelWin
->IsShown() )
4109 ch
-= m_colLabelHeight
;
4112 int w
= m_numCols
> 0 ? GetColRight(m_numCols
- 1) + m_extraWidth
+ 1 : 0;
4113 int h
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) + m_extraHeight
+ 1 : 0;
4115 // take into account editor if shown
4116 if( IsCellEditControlShown() )
4119 int r
= m_currentCellCoords
.GetRow();
4120 int c
= m_currentCellCoords
.GetCol();
4121 int x
= GetColLeft(c
);
4122 int y
= GetRowTop(r
);
4124 // how big is the editor
4125 wxGridCellAttr
* attr
= GetCellAttr(r
, c
);
4126 wxGridCellEditor
* editor
= attr
->GetEditor(this, r
, c
);
4127 editor
->GetControl()->GetSize(&w2
, &h2
);
4130 if( w2
> w
) w
= w2
;
4131 if( h2
> h
) h
= h2
;
4136 // preserve (more or less) the previous position
4138 GetViewStart( &x
, &y
);
4140 // maybe we don't need scrollbars at all?
4142 // also adjust the position to be valid for the new scroll rangs
4163 // do set scrollbar parameters
4164 SetScrollbars( GRID_SCROLL_LINE_X
, GRID_SCROLL_LINE_Y
,
4165 GetScrollX(w
), GetScrollY(h
), x
, y
,
4166 GetBatchCount() != 0);
4168 // if our OnSize() hadn't been called (it would if we have scrollbars), we
4169 // still must reposition the children
4174 void wxGrid::CalcWindowSizes()
4177 GetClientSize( &cw
, &ch
);
4179 if ( m_cornerLabelWin
->IsShown() )
4180 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
4182 if ( m_colLabelWin
->IsShown() )
4183 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
4185 if ( m_rowLabelWin
->IsShown() )
4186 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
4188 if ( m_gridWin
->IsShown() )
4189 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
4193 // this is called when the grid table sends a message to say that it
4194 // has been redimensioned
4196 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
4199 bool result
= FALSE
;
4201 // Clear the attribute cache as the attribute might refer to a different
4202 // cell than stored in the cache after adding/removing rows/columns.
4204 // By the same reasoning, the editor should be dismissed if columns are
4205 // added or removed. And for consistency, it should IMHO always be
4206 // removed, not only if the cell "underneath" it actually changes.
4207 // For now, I intentionally do not save the editor's content as the
4208 // cell it might want to save that stuff to might no longer exist.
4209 HideCellEditControl();
4211 // if we were using the default widths/heights so far, we must change them
4213 if ( m_colWidths
.IsEmpty() )
4218 if ( m_rowHeights
.IsEmpty() )
4224 switch ( msg
.GetId() )
4226 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
4228 size_t pos
= msg
.GetCommandInt();
4229 int numRows
= msg
.GetCommandInt2();
4231 m_numRows
+= numRows
;
4233 if ( !m_rowHeights
.IsEmpty() )
4235 m_rowHeights
.Insert( m_defaultRowHeight
, pos
, numRows
);
4236 m_rowBottoms
.Insert( 0, pos
, numRows
);
4239 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
4241 for ( i
= pos
; i
< m_numRows
; i
++ )
4243 bottom
+= m_rowHeights
[i
];
4244 m_rowBottoms
[i
] = bottom
;
4247 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4249 // if we have just inserted cols into an empty grid the current
4250 // cell will be undefined...
4252 SetCurrentCell( 0, 0 );
4256 m_selection
->UpdateRows( pos
, numRows
);
4257 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4259 attrProvider
->UpdateAttrRows( pos
, numRows
);
4261 if ( !GetBatchCount() )
4264 m_rowLabelWin
->Refresh();
4270 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
4272 int numRows
= msg
.GetCommandInt();
4273 int oldNumRows
= m_numRows
;
4274 m_numRows
+= numRows
;
4276 if ( !m_rowHeights
.IsEmpty() )
4278 m_rowHeights
.Add( m_defaultRowHeight
, numRows
);
4279 m_rowBottoms
.Add( 0, numRows
);
4282 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
4284 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
4286 bottom
+= m_rowHeights
[i
];
4287 m_rowBottoms
[i
] = bottom
;
4290 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4292 // if we have just inserted cols into an empty grid the current
4293 // cell will be undefined...
4295 SetCurrentCell( 0, 0 );
4297 if ( !GetBatchCount() )
4300 m_rowLabelWin
->Refresh();
4306 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
4308 size_t pos
= msg
.GetCommandInt();
4309 int numRows
= msg
.GetCommandInt2();
4310 m_numRows
-= numRows
;
4312 if ( !m_rowHeights
.IsEmpty() )
4314 m_rowHeights
.RemoveAt( pos
, numRows
);
4315 m_rowBottoms
.RemoveAt( pos
, numRows
);
4318 for ( i
= 0; i
< m_numRows
; i
++ )
4320 h
+= m_rowHeights
[i
];
4321 m_rowBottoms
[i
] = h
;
4326 m_currentCellCoords
= wxGridNoCellCoords
;
4330 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
4331 m_currentCellCoords
.Set( 0, 0 );
4335 m_selection
->UpdateRows( pos
, -((int)numRows
) );
4336 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4338 attrProvider
->UpdateAttrRows( pos
, -((int)numRows
) );
4339 // ifdef'd out following patch from Paul Gammans
4341 // No need to touch column attributes, unless we
4342 // removed _all_ rows, in this case, we remove
4343 // all column attributes.
4344 // I hate to do this here, but the
4345 // needed data is not available inside UpdateAttrRows.
4346 if ( !GetNumberRows() )
4347 attrProvider
->UpdateAttrCols( 0, -GetNumberCols() );
4350 if ( !GetBatchCount() )
4353 m_rowLabelWin
->Refresh();
4359 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
4361 size_t pos
= msg
.GetCommandInt();
4362 int numCols
= msg
.GetCommandInt2();
4363 m_numCols
+= numCols
;
4365 if ( !m_colWidths
.IsEmpty() )
4367 m_colWidths
.Insert( m_defaultColWidth
, pos
, numCols
);
4368 m_colRights
.Insert( 0, pos
, numCols
);
4371 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
4373 for ( i
= pos
; i
< m_numCols
; i
++ )
4375 right
+= m_colWidths
[i
];
4376 m_colRights
[i
] = right
;
4379 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4381 // if we have just inserted cols into an empty grid the current
4382 // cell will be undefined...
4384 SetCurrentCell( 0, 0 );
4388 m_selection
->UpdateCols( pos
, numCols
);
4389 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4391 attrProvider
->UpdateAttrCols( pos
, numCols
);
4392 if ( !GetBatchCount() )
4395 m_colLabelWin
->Refresh();
4402 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
4404 int numCols
= msg
.GetCommandInt();
4405 int oldNumCols
= m_numCols
;
4406 m_numCols
+= numCols
;
4407 if ( !m_colWidths
.IsEmpty() )
4409 m_colWidths
.Add( m_defaultColWidth
, numCols
);
4410 m_colRights
.Add( 0, numCols
);
4413 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
4415 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
4417 right
+= m_colWidths
[i
];
4418 m_colRights
[i
] = right
;
4421 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4423 // if we have just inserted cols into an empty grid the current
4424 // cell will be undefined...
4426 SetCurrentCell( 0, 0 );
4428 if ( !GetBatchCount() )
4431 m_colLabelWin
->Refresh();
4437 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
4439 size_t pos
= msg
.GetCommandInt();
4440 int numCols
= msg
.GetCommandInt2();
4441 m_numCols
-= numCols
;
4443 if ( !m_colWidths
.IsEmpty() )
4445 m_colWidths
.RemoveAt( pos
, numCols
);
4446 m_colRights
.RemoveAt( pos
, numCols
);
4449 for ( i
= 0; i
< m_numCols
; i
++ )
4451 w
+= m_colWidths
[i
];
4457 m_currentCellCoords
= wxGridNoCellCoords
;
4461 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
4462 m_currentCellCoords
.Set( 0, 0 );
4466 m_selection
->UpdateCols( pos
, -((int)numCols
) );
4467 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4469 attrProvider
->UpdateAttrCols( pos
, -((int)numCols
) );
4470 // ifdef'd out following patch from Paul Gammans
4472 // No need to touch row attributes, unless we
4473 // removed _all_ columns, in this case, we remove
4474 // all row attributes.
4475 // I hate to do this here, but the
4476 // needed data is not available inside UpdateAttrCols.
4477 if ( !GetNumberCols() )
4478 attrProvider
->UpdateAttrRows( 0, -GetNumberRows() );
4481 if ( !GetBatchCount() )
4484 m_colLabelWin
->Refresh();
4491 if (result
&& !GetBatchCount() )
4492 m_gridWin
->Refresh();
4497 wxArrayInt
wxGrid::CalcRowLabelsExposed( const wxRegion
& reg
)
4499 wxRegionIterator
iter( reg
);
4502 wxArrayInt rowlabels
;
4509 // TODO: remove this when we can...
4510 // There is a bug in wxMotif that gives garbage update
4511 // rectangles if you jump-scroll a long way by clicking the
4512 // scrollbar with middle button. This is a work-around
4514 #if defined(__WXMOTIF__)
4516 m_gridWin
->GetClientSize( &cw
, &ch
);
4517 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
4518 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
4521 // logical bounds of update region
4524 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
4525 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
4527 // find the row labels within these bounds
4530 for ( row
= internalYToRow(top
); row
< m_numRows
; row
++ )
4532 if ( GetRowBottom(row
) < top
)
4535 if ( GetRowTop(row
) > bottom
)
4538 rowlabels
.Add( row
);
4548 wxArrayInt
wxGrid::CalcColLabelsExposed( const wxRegion
& reg
)
4550 wxRegionIterator
iter( reg
);
4553 wxArrayInt colLabels
;
4560 // TODO: remove this when we can...
4561 // There is a bug in wxMotif that gives garbage update
4562 // rectangles if you jump-scroll a long way by clicking the
4563 // scrollbar with middle button. This is a work-around
4565 #if defined(__WXMOTIF__)
4567 m_gridWin
->GetClientSize( &cw
, &ch
);
4568 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
4569 r
.SetRight( wxMin( r
.GetRight(), cw
) );
4572 // logical bounds of update region
4575 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
4576 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
4578 // find the cells within these bounds
4581 for ( col
= internalXToCol(left
); col
< m_numCols
; col
++ )
4583 if ( GetColRight(col
) < left
)
4586 if ( GetColLeft(col
) > right
)
4589 colLabels
.Add( col
);
4598 wxGridCellCoordsArray
wxGrid::CalcCellsExposed( const wxRegion
& reg
)
4600 wxRegionIterator
iter( reg
);
4603 wxGridCellCoordsArray cellsExposed
;
4605 int left
, top
, right
, bottom
;
4610 // TODO: remove this when we can...
4611 // There is a bug in wxMotif that gives garbage update
4612 // rectangles if you jump-scroll a long way by clicking the
4613 // scrollbar with middle button. This is a work-around
4615 #if defined(__WXMOTIF__)
4617 m_gridWin
->GetClientSize( &cw
, &ch
);
4618 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
4619 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
4620 r
.SetRight( wxMin( r
.GetRight(), cw
) );
4621 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
4624 // logical bounds of update region
4626 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
4627 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
4629 // find the cells within these bounds
4632 for ( row
= internalYToRow(top
); row
< m_numRows
; row
++ )
4634 if ( GetRowBottom(row
) <= top
)
4637 if ( GetRowTop(row
) > bottom
)
4640 for ( col
= internalXToCol(left
); col
< m_numCols
; col
++ )
4642 if ( GetColRight(col
) <= left
)
4645 if ( GetColLeft(col
) > right
)
4648 cellsExposed
.Add( wxGridCellCoords( row
, col
) );
4655 return cellsExposed
;
4659 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
4662 wxPoint
pos( event
.GetPosition() );
4663 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
4665 if ( event
.Dragging() )
4669 m_isDragging
= TRUE
;
4670 m_rowLabelWin
->CaptureMouse();
4673 if ( event
.LeftIsDown() )
4675 switch( m_cursorMode
)
4677 case WXGRID_CURSOR_RESIZE_ROW
:
4679 int cw
, ch
, left
, dummy
;
4680 m_gridWin
->GetClientSize( &cw
, &ch
);
4681 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
4683 wxClientDC
dc( m_gridWin
);
4686 GetRowTop(m_dragRowOrCol
) +
4687 GetRowMinimalHeight(m_dragRowOrCol
) );
4688 dc
.SetLogicalFunction(wxINVERT
);
4689 if ( m_dragLastPos
>= 0 )
4691 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
4693 dc
.DrawLine( left
, y
, left
+cw
, y
);
4698 case WXGRID_CURSOR_SELECT_ROW
:
4699 if ( (row
= YToRow( y
)) >= 0 )
4703 m_selection
->SelectRow( row
,
4704 event
.ControlDown(),
4711 // default label to suppress warnings about "enumeration value
4712 // 'xxx' not handled in switch
4720 if ( m_isDragging
&& (event
.Entering() || event
.Leaving()) )
4725 if (m_rowLabelWin
->HasCapture()) m_rowLabelWin
->ReleaseMouse();
4726 m_isDragging
= FALSE
;
4729 // ------------ Entering or leaving the window
4731 if ( event
.Entering() || event
.Leaving() )
4733 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
4737 // ------------ Left button pressed
4739 else if ( event
.LeftDown() )
4741 // don't send a label click event for a hit on the
4742 // edge of the row label - this is probably the user
4743 // wanting to resize the row
4745 if ( YToEdgeOfRow(y
) < 0 )
4749 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
4751 if ( !event
.ShiftDown() && !event
.ControlDown() )
4755 if ( event
.ShiftDown() )
4757 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
4760 GetNumberCols() - 1,
4761 event
.ControlDown(),
4768 m_selection
->SelectRow( row
,
4769 event
.ControlDown(),
4776 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
4781 // starting to drag-resize a row
4783 if ( CanDragRowSize() )
4784 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
4789 // ------------ Left double click
4791 else if (event
.LeftDClick() )
4793 int row
= YToEdgeOfRow(y
);
4798 !SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
) )
4800 // no default action at the moment
4805 // adjust row height depending on label text
4806 AutoSizeRowLabelSize( row
);
4808 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
4814 // ------------ Left button released
4816 else if ( event
.LeftUp() )
4818 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
4820 DoEndDragResizeRow();
4822 // Note: we are ending the event *after* doing
4823 // default processing in this case
4825 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
4828 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
4833 // ------------ Right button down
4835 else if ( event
.RightDown() )
4839 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
4841 // no default action at the moment
4846 // ------------ Right double click
4848 else if ( event
.RightDClick() )
4852 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
4854 // no default action at the moment
4859 // ------------ No buttons down and mouse moving
4861 else if ( event
.Moving() )
4863 m_dragRowOrCol
= YToEdgeOfRow( y
);
4864 if ( m_dragRowOrCol
>= 0 )
4866 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4868 // don't capture the mouse yet
4869 if ( CanDragRowSize() )
4870 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, FALSE
);
4873 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
4875 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, FALSE
);
4881 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
4884 wxPoint
pos( event
.GetPosition() );
4885 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
4887 if ( event
.Dragging() )
4891 m_isDragging
= TRUE
;
4892 m_colLabelWin
->CaptureMouse();
4895 if ( event
.LeftIsDown() )
4897 switch( m_cursorMode
)
4899 case WXGRID_CURSOR_RESIZE_COL
:
4901 int cw
, ch
, dummy
, top
;
4902 m_gridWin
->GetClientSize( &cw
, &ch
);
4903 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
4905 wxClientDC
dc( m_gridWin
);
4908 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
4909 GetColMinimalWidth(m_dragRowOrCol
));
4910 dc
.SetLogicalFunction(wxINVERT
);
4911 if ( m_dragLastPos
>= 0 )
4913 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
4915 dc
.DrawLine( x
, top
, x
, top
+ch
);
4920 case WXGRID_CURSOR_SELECT_COL
:
4921 if ( (col
= XToCol( x
)) >= 0 )
4925 m_selection
->SelectCol( col
,
4926 event
.ControlDown(),
4933 // default label to suppress warnings about "enumeration value
4934 // 'xxx' not handled in switch
4942 if ( m_isDragging
&& (event
.Entering() || event
.Leaving()) )
4947 if (m_colLabelWin
->HasCapture()) m_colLabelWin
->ReleaseMouse();
4948 m_isDragging
= FALSE
;
4951 // ------------ Entering or leaving the window
4953 if ( event
.Entering() || event
.Leaving() )
4955 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
4959 // ------------ Left button pressed
4961 else if ( event
.LeftDown() )
4963 // don't send a label click event for a hit on the
4964 // edge of the col label - this is probably the user
4965 // wanting to resize the col
4967 if ( XToEdgeOfCol(x
) < 0 )
4971 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
4973 if ( !event
.ShiftDown() && !event
.ControlDown() )
4977 if ( event
.ShiftDown() )
4979 m_selection
->SelectBlock( 0,
4980 m_currentCellCoords
.GetCol(),
4981 GetNumberRows() - 1, col
,
4982 event
.ControlDown(),
4989 m_selection
->SelectCol( col
,
4990 event
.ControlDown(),
4997 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, m_colLabelWin
);
5002 // starting to drag-resize a col
5004 if ( CanDragColSize() )
5005 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
);
5010 // ------------ Left double click
5012 if ( event
.LeftDClick() )
5014 int col
= XToEdgeOfCol(x
);
5019 ! SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
) )
5021 // no default action at the moment
5026 // adjust column width depending on label text
5027 AutoSizeColLabelSize( col
);
5029 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
5035 // ------------ Left button released
5037 else if ( event
.LeftUp() )
5039 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5041 DoEndDragResizeCol();
5043 // Note: we are ending the event *after* doing
5044 // default processing in this case
5046 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
5049 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
5054 // ------------ Right button down
5056 else if ( event
.RightDown() )
5060 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
5062 // no default action at the moment
5067 // ------------ Right double click
5069 else if ( event
.RightDClick() )
5073 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
5075 // no default action at the moment
5080 // ------------ No buttons down and mouse moving
5082 else if ( event
.Moving() )
5084 m_dragRowOrCol
= XToEdgeOfCol( x
);
5085 if ( m_dragRowOrCol
>= 0 )
5087 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5089 // don't capture the cursor yet
5090 if ( CanDragColSize() )
5091 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
, FALSE
);
5094 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
5096 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
, FALSE
);
5102 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
5104 if ( event
.LeftDown() )
5106 // indicate corner label by having both row and
5109 if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
5115 else if ( event
.LeftDClick() )
5117 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
5120 else if ( event
.RightDown() )
5122 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
5124 // no default action at the moment
5128 else if ( event
.RightDClick() )
5130 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
5132 // no default action at the moment
5137 void wxGrid::ChangeCursorMode(CursorMode mode
,
5142 static const wxChar
*cursorModes
[] =
5151 wxLogTrace(_T("grid"),
5152 _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
5153 win
== m_colLabelWin
? _T("colLabelWin")
5154 : win
? _T("rowLabelWin")
5156 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
5157 #endif // __WXDEBUG__
5159 if ( mode
== m_cursorMode
&&
5160 win
== m_winCapture
&&
5161 captureMouse
== (m_winCapture
!= NULL
))
5166 // by default use the grid itself
5172 if (m_winCapture
->HasCapture()) m_winCapture
->ReleaseMouse();
5173 m_winCapture
= (wxWindow
*)NULL
;
5176 m_cursorMode
= mode
;
5178 switch ( m_cursorMode
)
5180 case WXGRID_CURSOR_RESIZE_ROW
:
5181 win
->SetCursor( m_rowResizeCursor
);
5184 case WXGRID_CURSOR_RESIZE_COL
:
5185 win
->SetCursor( m_colResizeCursor
);
5189 win
->SetCursor( *wxSTANDARD_CURSOR
);
5192 // we need to capture mouse when resizing
5193 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
5194 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
5196 if ( captureMouse
&& resize
)
5198 win
->CaptureMouse();
5203 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
5206 wxPoint
pos( event
.GetPosition() );
5207 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
5209 wxGridCellCoords coords
;
5210 XYToCell( x
, y
, coords
);
5212 int cell_rows
, cell_cols
;
5213 GetCellSize( coords
.GetRow(), coords
.GetCol(), &cell_rows
, &cell_cols
);
5214 if ((cell_rows
< 0) || (cell_cols
< 0))
5216 coords
.SetRow(coords
.GetRow() + cell_rows
);
5217 coords
.SetCol(coords
.GetCol() + cell_cols
);
5220 if ( event
.Dragging() )
5222 //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
5224 // Don't start doing anything until the mouse has been drug at
5225 // least 3 pixels in any direction...
5228 if (m_startDragPos
== wxDefaultPosition
)
5230 m_startDragPos
= pos
;
5233 if (abs(m_startDragPos
.x
- pos
.x
) < 4 && abs(m_startDragPos
.y
- pos
.y
) < 4)
5237 m_isDragging
= TRUE
;
5238 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5240 // Hide the edit control, so it
5241 // won't interfer with drag-shrinking.
5242 if ( IsCellEditControlShown() )
5244 HideCellEditControl();
5245 SaveEditControlValue();
5248 // Have we captured the mouse yet?
5251 m_winCapture
= m_gridWin
;
5252 m_winCapture
->CaptureMouse();
5255 if ( coords
!= wxGridNoCellCoords
)
5257 if ( event
.ControlDown() )
5259 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
5260 m_selectingKeyboard
= coords
;
5261 HighlightBlock ( m_selectingKeyboard
, coords
);
5265 if ( !IsSelection() )
5267 HighlightBlock( coords
, coords
);
5271 HighlightBlock( m_currentCellCoords
, coords
);
5275 if (! IsVisible(coords
))
5277 MakeCellVisible(coords
);
5278 // TODO: need to introduce a delay or something here. The
5279 // scrolling is way to fast, at least on MSW - also on GTK.
5283 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
5285 int cw
, ch
, left
, dummy
;
5286 m_gridWin
->GetClientSize( &cw
, &ch
);
5287 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
5289 wxClientDC
dc( m_gridWin
);
5291 y
= wxMax( y
, GetRowTop(m_dragRowOrCol
) +
5292 GetRowMinimalHeight(m_dragRowOrCol
) );
5293 dc
.SetLogicalFunction(wxINVERT
);
5294 if ( m_dragLastPos
>= 0 )
5296 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
5298 dc
.DrawLine( left
, y
, left
+cw
, y
);
5301 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5303 int cw
, ch
, dummy
, top
;
5304 m_gridWin
->GetClientSize( &cw
, &ch
);
5305 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
5307 wxClientDC
dc( m_gridWin
);
5309 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
5310 GetColMinimalWidth(m_dragRowOrCol
) );
5311 dc
.SetLogicalFunction(wxINVERT
);
5312 if ( m_dragLastPos
>= 0 )
5314 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
5316 dc
.DrawLine( x
, top
, x
, top
+ch
);
5323 m_isDragging
= FALSE
;
5324 m_startDragPos
= wxDefaultPosition
;
5326 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
5327 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
5330 if ( event
.Entering() || event
.Leaving() )
5332 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5333 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
5338 // ------------ Left button pressed
5340 if ( event
.LeftDown() && coords
!= wxGridNoCellCoords
)
5342 if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK
,
5347 if ( !event
.ControlDown() )
5349 if ( event
.ShiftDown() )
5353 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
5354 m_currentCellCoords
.GetCol(),
5357 event
.ControlDown(),
5363 else if ( XToEdgeOfCol(x
) < 0 &&
5364 YToEdgeOfRow(y
) < 0 )
5366 DisableCellEditControl();
5367 MakeCellVisible( coords
);
5369 if ( event
.ControlDown() )
5373 m_selection
->ToggleCellSelection( coords
.GetRow(),
5375 event
.ControlDown(),
5380 m_selectingTopLeft
= wxGridNoCellCoords
;
5381 m_selectingBottomRight
= wxGridNoCellCoords
;
5382 m_selectingKeyboard
= coords
;
5386 m_waitForSlowClick
= m_currentCellCoords
== coords
&& coords
!= wxGridNoCellCoords
;
5387 SetCurrentCell( coords
);
5390 if ( m_selection
->GetSelectionMode() !=
5391 wxGrid::wxGridSelectCells
)
5393 HighlightBlock( coords
, coords
);
5402 // ------------ Left double click
5404 else if ( event
.LeftDClick() && coords
!= wxGridNoCellCoords
)
5406 DisableCellEditControl();
5408 if ( XToEdgeOfCol(x
) < 0 && YToEdgeOfRow(y
) < 0 )
5410 SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK
,
5418 // ------------ Left button released
5420 else if ( event
.LeftUp() )
5422 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5426 if (m_winCapture
->HasCapture()) m_winCapture
->ReleaseMouse();
5427 m_winCapture
= NULL
;
5430 if ( coords
== m_currentCellCoords
&& m_waitForSlowClick
&& CanEnableCellControl())
5433 EnableCellEditControl();
5435 wxGridCellAttr
* attr
= GetCellAttr(coords
);
5436 wxGridCellEditor
*editor
= attr
->GetEditor(this, coords
.GetRow(), coords
.GetCol());
5437 editor
->StartingClick();
5441 m_waitForSlowClick
= FALSE
;
5443 else if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
5444 m_selectingBottomRight
!= wxGridNoCellCoords
)
5448 m_selection
->SelectBlock( m_selectingTopLeft
.GetRow(),
5449 m_selectingTopLeft
.GetCol(),
5450 m_selectingBottomRight
.GetRow(),
5451 m_selectingBottomRight
.GetCol(),
5452 event
.ControlDown(),
5458 m_selectingTopLeft
= wxGridNoCellCoords
;
5459 m_selectingBottomRight
= wxGridNoCellCoords
;
5461 // Show the edit control, if it has been hidden for
5463 ShowCellEditControl();
5466 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
5468 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5469 DoEndDragResizeRow();
5471 // Note: we are ending the event *after* doing
5472 // default processing in this case
5474 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
5476 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5478 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5479 DoEndDragResizeCol();
5481 // Note: we are ending the event *after* doing
5482 // default processing in this case
5484 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
5491 // ------------ Right button down
5493 else if ( event
.RightDown() && coords
!= wxGridNoCellCoords
)
5495 DisableCellEditControl();
5496 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK
,
5501 // no default action at the moment
5506 // ------------ Right double click
5508 else if ( event
.RightDClick() && coords
!= wxGridNoCellCoords
)
5510 DisableCellEditControl();
5511 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK
,
5516 // no default action at the moment
5520 // ------------ Moving and no button action
5522 else if ( event
.Moving() && !event
.IsButton() )
5524 if( coords
.GetRow() < 0 || coords
.GetCol() < 0 )
5526 // out of grid cell area
5527 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5531 int dragRow
= YToEdgeOfRow( y
);
5532 int dragCol
= XToEdgeOfCol( x
);
5534 // Dragging on the corner of a cell to resize in both
5535 // directions is not implemented yet...
5537 if ( dragRow
>= 0 && dragCol
>= 0 )
5539 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5545 m_dragRowOrCol
= dragRow
;
5547 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5549 if ( CanDragRowSize() && CanDragGridSize() )
5550 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
);
5555 m_dragRowOrCol
= dragCol
;
5563 m_dragRowOrCol
= dragCol
;
5565 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5567 if ( CanDragColSize() && CanDragGridSize() )
5568 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
);
5574 // Neither on a row or col edge
5576 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
5578 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5584 void wxGrid::DoEndDragResizeRow()
5586 if ( m_dragLastPos
>= 0 )
5588 // erase the last line and resize the row
5590 int cw
, ch
, left
, dummy
;
5591 m_gridWin
->GetClientSize( &cw
, &ch
);
5592 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
5594 wxClientDC
dc( m_gridWin
);
5596 dc
.SetLogicalFunction( wxINVERT
);
5597 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
5598 HideCellEditControl();
5599 SaveEditControlValue();
5601 int rowTop
= GetRowTop(m_dragRowOrCol
);
5602 SetRowSize( m_dragRowOrCol
,
5603 wxMax( m_dragLastPos
- rowTop
, WXGRID_MIN_ROW_HEIGHT
) );
5605 if ( !GetBatchCount() )
5607 // Only needed to get the correct rect.y:
5608 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
5610 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
5611 rect
.width
= m_rowLabelWidth
;
5612 rect
.height
= ch
- rect
.y
;
5613 m_rowLabelWin
->Refresh( TRUE
, &rect
);
5615 // if there is a multicell block, paint all of it
5618 int i
, cell_rows
, cell_cols
, subtract_rows
= 0;
5619 int leftCol
= XToCol(left
);
5620 int rightCol
= internalXToCol(left
+cw
);
5623 for (i
=leftCol
; i
<rightCol
; i
++)
5625 GetCellSize(m_dragRowOrCol
, i
, &cell_rows
, &cell_cols
);
5626 if (cell_rows
< subtract_rows
)
5627 subtract_rows
= cell_rows
;
5629 rect
.y
= GetRowTop(m_dragRowOrCol
+ subtract_rows
);
5630 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
5631 rect
.height
= ch
- rect
.y
;
5634 m_gridWin
->Refresh( FALSE
, &rect
);
5637 ShowCellEditControl();
5642 void wxGrid::DoEndDragResizeCol()
5644 if ( m_dragLastPos
>= 0 )
5646 // erase the last line and resize the col
5648 int cw
, ch
, dummy
, top
;
5649 m_gridWin
->GetClientSize( &cw
, &ch
);
5650 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
5652 wxClientDC
dc( m_gridWin
);
5654 dc
.SetLogicalFunction( wxINVERT
);
5655 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
5656 HideCellEditControl();
5657 SaveEditControlValue();
5659 int colLeft
= GetColLeft(m_dragRowOrCol
);
5660 SetColSize( m_dragRowOrCol
,
5661 wxMax( m_dragLastPos
- colLeft
,
5662 GetColMinimalWidth(m_dragRowOrCol
) ) );
5664 if ( !GetBatchCount() )
5666 // Only needed to get the correct rect.x:
5667 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
5669 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
5670 rect
.width
= cw
- rect
.x
;
5671 rect
.height
= m_colLabelHeight
;
5672 m_colLabelWin
->Refresh( TRUE
, &rect
);
5674 // if there is a multicell block, paint all of it
5677 int i
, cell_rows
, cell_cols
, subtract_cols
= 0;
5678 int topRow
= YToRow(top
);
5679 int bottomRow
= internalYToRow(top
+cw
);
5682 for (i
=topRow
; i
<bottomRow
; i
++)
5684 GetCellSize(i
, m_dragRowOrCol
, &cell_rows
, &cell_cols
);
5685 if (cell_cols
< subtract_cols
)
5686 subtract_cols
= cell_cols
;
5688 rect
.x
= GetColLeft(m_dragRowOrCol
+ subtract_cols
);
5689 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
5690 rect
.width
= cw
- rect
.x
;
5693 m_gridWin
->Refresh( FALSE
, &rect
);
5696 ShowCellEditControl();
5703 // ------ interaction with data model
5705 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
5707 switch ( msg
.GetId() )
5709 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
5710 return GetModelValues();
5712 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
5713 return SetModelValues();
5715 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
5716 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
5717 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
5718 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
5719 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
5720 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
5721 return Redimension( msg
);
5730 // The behaviour of this function depends on the grid table class
5731 // Clear() function. For the default wxGridStringTable class the
5732 // behavious is to replace all cell contents with wxEmptyString but
5733 // not to change the number of rows or cols.
5735 void wxGrid::ClearGrid()
5739 if (IsCellEditControlEnabled())
5740 DisableCellEditControl();
5743 if ( !GetBatchCount() ) m_gridWin
->Refresh();
5748 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
5750 // TODO: something with updateLabels flag
5754 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
5760 if (IsCellEditControlEnabled())
5761 DisableCellEditControl();
5763 return m_table
->InsertRows( pos
, numRows
);
5765 // the table will have sent the results of the insert row
5766 // operation to this view object as a grid table message
5772 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
5774 // TODO: something with updateLabels flag
5778 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
5782 return ( m_table
&& m_table
->AppendRows( numRows
) );
5783 // the table will have sent the results of the append row
5784 // operation to this view object as a grid table message
5788 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
5790 // TODO: something with updateLabels flag
5794 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
5800 if (IsCellEditControlEnabled())
5801 DisableCellEditControl();
5803 return (m_table
->DeleteRows( pos
, numRows
));
5804 // the table will have sent the results of the delete row
5805 // operation to this view object as a grid table message
5811 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
5813 // TODO: something with updateLabels flag
5817 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
5823 if (IsCellEditControlEnabled())
5824 DisableCellEditControl();
5826 return m_table
->InsertCols( pos
, numCols
);
5827 // the table will have sent the results of the insert col
5828 // operation to this view object as a grid table message
5834 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
5836 // TODO: something with updateLabels flag
5840 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
5844 return ( m_table
&& m_table
->AppendCols( numCols
) );
5845 // the table will have sent the results of the append col
5846 // operation to this view object as a grid table message
5850 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
5852 // TODO: something with updateLabels flag
5856 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
5862 if (IsCellEditControlEnabled())
5863 DisableCellEditControl();
5865 return ( m_table
->DeleteCols( pos
, numCols
) );
5866 // the table will have sent the results of the delete col
5867 // operation to this view object as a grid table message
5875 // ----- event handlers
5878 // Generate a grid event based on a mouse event and
5879 // return the result of ProcessEvent()
5881 int wxGrid::SendEvent( const wxEventType type
,
5883 wxMouseEvent
& mouseEv
)
5888 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
5890 int rowOrCol
= (row
== -1 ? col
: row
);
5892 wxGridSizeEvent
gridEvt( GetId(),
5896 mouseEv
.GetX() + GetRowLabelSize(),
5897 mouseEv
.GetY() + GetColLabelSize(),
5898 mouseEv
.ControlDown(),
5899 mouseEv
.ShiftDown(),
5901 mouseEv
.MetaDown() );
5903 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5904 vetoed
= !gridEvt
.IsAllowed();
5906 else if ( type
== wxEVT_GRID_RANGE_SELECT
)
5908 // Right now, it should _never_ end up here!
5909 wxGridRangeSelectEvent
gridEvt( GetId(),
5913 m_selectingBottomRight
,
5915 mouseEv
.ControlDown(),
5916 mouseEv
.ShiftDown(),
5918 mouseEv
.MetaDown() );
5920 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5921 vetoed
= !gridEvt
.IsAllowed();
5925 wxGridEvent
gridEvt( GetId(),
5929 mouseEv
.GetX() + GetRowLabelSize(),
5930 mouseEv
.GetY() + GetColLabelSize(),
5932 mouseEv
.ControlDown(),
5933 mouseEv
.ShiftDown(),
5935 mouseEv
.MetaDown() );
5936 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5937 vetoed
= !gridEvt
.IsAllowed();
5940 // A Veto'd event may not be `claimed' so test this first
5941 if (vetoed
) return -1;
5942 return claimed
? 1 : 0;
5946 // Generate a grid event of specified type and return the result
5947 // of ProcessEvent().
5949 int wxGrid::SendEvent( const wxEventType type
,
5955 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
5957 int rowOrCol
= (row
== -1 ? col
: row
);
5959 wxGridSizeEvent
gridEvt( GetId(),
5964 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5965 vetoed
= !gridEvt
.IsAllowed();
5969 wxGridEvent
gridEvt( GetId(),
5974 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5975 vetoed
= !gridEvt
.IsAllowed();
5978 // A Veto'd event may not be `claimed' so test this first
5979 if (vetoed
) return -1;
5980 return claimed
? 1 : 0;
5984 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
5986 wxPaintDC
dc(this); // needed to prevent zillions of paint events on MSW
5989 void wxGrid::Refresh(bool eraseb
, const wxRect
* rect
)
5991 // Don't do anything if between Begin/EndBatch...
5992 // EndBatch() will do all this on the last nested one anyway.
5993 if (! GetBatchCount())
5995 // Refresh to get correct scrolled position:
5996 wxScrolledWindow::Refresh(eraseb
,rect
);
6000 int rect_x
, rect_y
, rectWidth
, rectHeight
;
6001 int width_label
, width_cell
, height_label
, height_cell
;
6004 //Copy rectangle can get scroll offsets..
6005 rect_x
= rect
->GetX();
6006 rect_y
= rect
->GetY();
6007 rectWidth
= rect
->GetWidth();
6008 rectHeight
= rect
->GetHeight();
6010 width_label
= m_rowLabelWidth
- rect_x
;
6011 if (width_label
> rectWidth
) width_label
= rectWidth
;
6013 height_label
= m_colLabelHeight
- rect_y
;
6014 if (height_label
> rectHeight
) height_label
= rectHeight
;
6016 if (rect_x
> m_rowLabelWidth
)
6018 x
= rect_x
- m_rowLabelWidth
;
6019 width_cell
= rectWidth
;
6024 width_cell
= rectWidth
- (m_rowLabelWidth
- rect_x
);
6027 if (rect_y
> m_colLabelHeight
)
6029 y
= rect_y
- m_colLabelHeight
;
6030 height_cell
= rectHeight
;
6035 height_cell
= rectHeight
- (m_colLabelHeight
- rect_y
);
6038 // Paint corner label part intersecting rect.
6039 if ( width_label
> 0 && height_label
> 0 )
6041 wxRect
anotherrect(rect_x
, rect_y
, width_label
, height_label
);
6042 m_cornerLabelWin
->Refresh(eraseb
, &anotherrect
);
6045 // Paint col labels part intersecting rect.
6046 if ( width_cell
> 0 && height_label
> 0 )
6048 wxRect
anotherrect(x
, rect_y
, width_cell
, height_label
);
6049 m_colLabelWin
->Refresh(eraseb
, &anotherrect
);
6052 // Paint row labels part intersecting rect.
6053 if ( width_label
> 0 && height_cell
> 0 )
6055 wxRect
anotherrect(rect_x
, y
, width_label
, height_cell
);
6056 m_rowLabelWin
->Refresh(eraseb
, &anotherrect
);
6059 // Paint cell area part intersecting rect.
6060 if ( width_cell
> 0 && height_cell
> 0 )
6062 wxRect
anotherrect(x
, y
, width_cell
, height_cell
);
6063 m_gridWin
->Refresh(eraseb
, &anotherrect
);
6068 m_cornerLabelWin
->Refresh(eraseb
, NULL
);
6069 m_colLabelWin
->Refresh(eraseb
, NULL
);
6070 m_rowLabelWin
->Refresh(eraseb
, NULL
);
6071 m_gridWin
->Refresh(eraseb
, NULL
);
6076 void wxGrid::OnSize( wxSizeEvent
& event
)
6078 // position the child windows
6081 // don't call CalcDimensions() from here, the base class handles the size
6087 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
6089 if ( m_inOnKeyDown
)
6091 // shouldn't be here - we are going round in circles...
6093 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
6096 m_inOnKeyDown
= TRUE
;
6098 // propagate the event up and see if it gets processed
6100 wxWindow
*parent
= GetParent();
6101 wxKeyEvent
keyEvt( event
);
6102 keyEvt
.SetEventObject( parent
);
6104 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
6107 // try local handlers
6109 switch ( event
.GetKeyCode() )
6112 if ( event
.ControlDown() )
6114 MoveCursorUpBlock( event
.ShiftDown() );
6118 MoveCursorUp( event
.ShiftDown() );
6123 if ( event
.ControlDown() )
6125 MoveCursorDownBlock( event
.ShiftDown() );
6129 MoveCursorDown( event
.ShiftDown() );
6134 if ( event
.ControlDown() )
6136 MoveCursorLeftBlock( event
.ShiftDown() );
6140 MoveCursorLeft( event
.ShiftDown() );
6145 if ( event
.ControlDown() )
6147 MoveCursorRightBlock( event
.ShiftDown() );
6151 MoveCursorRight( event
.ShiftDown() );
6156 case WXK_NUMPAD_ENTER
:
6157 if ( event
.ControlDown() )
6159 event
.Skip(); // to let the edit control have the return
6163 if ( GetGridCursorRow() < GetNumberRows()-1 )
6165 MoveCursorDown( event
.ShiftDown() );
6169 // at the bottom of a column
6170 HideCellEditControl();
6171 SaveEditControlValue();
6181 if (event
.ShiftDown())
6183 if ( GetGridCursorCol() > 0 )
6185 MoveCursorLeft( FALSE
);
6190 HideCellEditControl();
6191 SaveEditControlValue();
6196 if ( GetGridCursorCol() < GetNumberCols()-1 )
6198 MoveCursorRight( FALSE
);
6203 HideCellEditControl();
6204 SaveEditControlValue();
6210 if ( event
.ControlDown() )
6212 MakeCellVisible( 0, 0 );
6213 SetCurrentCell( 0, 0 );
6222 if ( event
.ControlDown() )
6224 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
6225 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
6242 if ( event
.ControlDown() )
6246 m_selection
->ToggleCellSelection( m_currentCellCoords
.GetRow(),
6247 m_currentCellCoords
.GetCol(),
6248 event
.ControlDown(),
6255 if ( !IsEditable() )
6257 MoveCursorRight( FALSE
);
6260 // Otherwise fall through to default
6263 // is it possible to edit the current cell at all?
6264 if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
6266 // yes, now check whether the cells editor accepts the key
6267 int row
= m_currentCellCoords
.GetRow();
6268 int col
= m_currentCellCoords
.GetCol();
6269 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6270 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
6272 // <F2> is special and will always start editing, for
6273 // other keys - ask the editor itself
6274 if ( (event
.GetKeyCode() == WXK_F2
&& !event
.HasModifiers())
6275 || editor
->IsAcceptedKey(event
) )
6277 // ensure cell is visble
6278 MakeCellVisible(row
, col
);
6279 EnableCellEditControl();
6281 // a problem can arise if the cell is not completely
6282 // visible (even after calling MakeCellVisible the
6283 // control is not created and calling StartingKey will
6285 if( editor
->IsCreated() && m_cellEditCtrlEnabled
) editor
->StartingKey(event
);
6297 // let others process char events with modifiers or all
6298 // char events for readonly cells
6305 m_inOnKeyDown
= FALSE
;
6308 void wxGrid::OnKeyUp( wxKeyEvent
& event
)
6310 // try local handlers
6312 if ( event
.GetKeyCode() == WXK_SHIFT
)
6314 if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
6315 m_selectingBottomRight
!= wxGridNoCellCoords
)
6319 m_selection
->SelectBlock( m_selectingTopLeft
.GetRow(),
6320 m_selectingTopLeft
.GetCol(),
6321 m_selectingBottomRight
.GetRow(),
6322 m_selectingBottomRight
.GetCol(),
6323 event
.ControlDown(),
6330 m_selectingTopLeft
= wxGridNoCellCoords
;
6331 m_selectingBottomRight
= wxGridNoCellCoords
;
6332 m_selectingKeyboard
= wxGridNoCellCoords
;
6336 void wxGrid::OnEraseBackground(wxEraseEvent
&)
6340 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
6342 if ( SendEvent( wxEVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
6344 // the event has been intercepted - do nothing
6348 wxClientDC
dc(m_gridWin
);
6351 if ( m_currentCellCoords
!= wxGridNoCellCoords
)
6353 HideCellEditControl();
6354 DisableCellEditControl();
6356 if ( IsVisible( m_currentCellCoords
, FALSE
) )
6359 r
= BlockToDeviceRect(m_currentCellCoords
, m_currentCellCoords
);
6360 if ( !m_gridLinesEnabled
)
6368 wxGridCellCoordsArray cells
= CalcCellsExposed( r
);
6370 // Otherwise refresh redraws the highlight!
6371 m_currentCellCoords
= coords
;
6373 DrawGridCellArea(dc
,cells
);
6374 DrawAllGridLines( dc
, r
);
6378 m_currentCellCoords
= coords
;
6380 wxGridCellAttr
* attr
= GetCellAttr(coords
);
6381 DrawCellHighlight(dc
, attr
);
6386 void wxGrid::HighlightBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
6389 wxGridCellCoords updateTopLeft
, updateBottomRight
;
6393 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectRows
)
6396 rightCol
= GetNumberCols() - 1;
6398 else if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectColumns
)
6401 bottomRow
= GetNumberRows() - 1;
6405 if ( topRow
> bottomRow
)
6412 if ( leftCol
> rightCol
)
6419 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
6420 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
6422 // First the case that we selected a completely new area
6423 if ( m_selectingTopLeft
== wxGridNoCellCoords
||
6424 m_selectingBottomRight
== wxGridNoCellCoords
)
6427 rect
= BlockToDeviceRect( wxGridCellCoords ( topRow
, leftCol
),
6428 wxGridCellCoords ( bottomRow
, rightCol
) );
6429 m_gridWin
->Refresh( FALSE
, &rect
);
6431 // Now handle changing an existing selection area.
6432 else if ( m_selectingTopLeft
!= updateTopLeft
||
6433 m_selectingBottomRight
!= updateBottomRight
)
6435 // Compute two optimal update rectangles:
6436 // Either one rectangle is a real subset of the
6437 // other, or they are (almost) disjoint!
6439 bool need_refresh
[4];
6443 need_refresh
[3] = FALSE
;
6446 // Store intermediate values
6447 wxCoord oldLeft
= m_selectingTopLeft
.GetCol();
6448 wxCoord oldTop
= m_selectingTopLeft
.GetRow();
6449 wxCoord oldRight
= m_selectingBottomRight
.GetCol();
6450 wxCoord oldBottom
= m_selectingBottomRight
.GetRow();
6452 // Determine the outer/inner coordinates.
6453 if (oldLeft
> leftCol
)
6459 if (oldTop
> topRow
)
6465 if (oldRight
< rightCol
)
6468 oldRight
= rightCol
;
6471 if (oldBottom
< bottomRow
)
6474 oldBottom
= bottomRow
;
6478 // Now, either the stuff marked old is the outer
6479 // rectangle or we don't have a situation where one
6480 // is contained in the other.
6482 if ( oldLeft
< leftCol
)
6484 // Refresh the newly selected or deselected
6485 // area to the left of the old or new selection.
6486 need_refresh
[0] = TRUE
;
6487 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6489 wxGridCellCoords ( oldBottom
,
6493 if ( oldTop
< topRow
)
6495 // Refresh the newly selected or deselected
6496 // area above the old or new selection.
6497 need_refresh
[1] = TRUE
;
6498 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6500 wxGridCellCoords ( topRow
- 1,
6504 if ( oldRight
> rightCol
)
6506 // Refresh the newly selected or deselected
6507 // area to the right of the old or new selection.
6508 need_refresh
[2] = TRUE
;
6509 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6511 wxGridCellCoords ( oldBottom
,
6515 if ( oldBottom
> bottomRow
)
6517 // Refresh the newly selected or deselected
6518 // area below the old or new selection.
6519 need_refresh
[3] = TRUE
;
6520 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
6522 wxGridCellCoords ( oldBottom
,
6526 // various Refresh() calls
6527 for (i
= 0; i
< 4; i
++ )
6528 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
6529 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
6532 m_selectingTopLeft
= updateTopLeft
;
6533 m_selectingBottomRight
= updateBottomRight
;
6537 // ------ functions to get/send data (see also public functions)
6540 bool wxGrid::GetModelValues()
6542 // Hide the editor, so it won't hide a changed value.
6543 HideCellEditControl();
6547 // all we need to do is repaint the grid
6549 m_gridWin
->Refresh();
6557 bool wxGrid::SetModelValues()
6561 // Disable the editor, so it won't hide a changed value.
6562 // Do we also want to save the current value of the editor first?
6564 DisableCellEditControl();
6568 for ( row
= 0; row
< m_numRows
; row
++ )
6570 for ( col
= 0; col
< m_numCols
; col
++ )
6572 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
6584 // Note - this function only draws cells that are in the list of
6585 // exposed cells (usually set from the update region by
6586 // CalcExposedCells)
6588 void wxGrid::DrawGridCellArea( wxDC
& dc
, const wxGridCellCoordsArray
& cells
)
6590 if ( !m_numRows
|| !m_numCols
) return;
6592 int i
, numCells
= cells
.GetCount();
6593 int row
, col
, cell_rows
, cell_cols
;
6594 wxGridCellCoordsArray redrawCells
;
6596 for ( i
= numCells
-1; i
>= 0; i
-- )
6598 row
= cells
[i
].GetRow();
6599 col
= cells
[i
].GetCol();
6600 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
6602 // If this cell is part of a multicell block, find owner for repaint
6603 if ( cell_rows
<= 0 || cell_cols
<= 0 )
6605 wxGridCellCoords
cell(row
+cell_rows
, col
+cell_cols
);
6606 bool marked
= FALSE
;
6607 for ( int j
= 0; j
< numCells
; j
++ )
6609 if ( cell
== cells
[j
] )
6617 int count
= redrawCells
.GetCount();
6618 for (int j
= 0; j
< count
; j
++)
6620 if ( cell
== redrawCells
[j
] )
6626 if (!marked
) redrawCells
.Add( cell
);
6628 continue; // don't bother drawing this cell
6631 // If this cell is empty, find cell to left that might want to overflow
6632 if (m_table
&& m_table
->IsEmptyCell(row
, col
))
6634 for ( int l
= 0; l
< cell_rows
; l
++ )
6636 // find a cell in this row to left alreay marked for repaint
6638 for (int k
= 0; k
< int(redrawCells
.GetCount()); k
++)
6639 if ((redrawCells
[k
].GetCol() < left
) &&
6640 (redrawCells
[k
].GetRow() == row
))
6641 left
=redrawCells
[k
].GetCol();
6643 if (left
== col
) left
= 0; // oh well
6645 for (int j
= col
-1; j
>= left
; j
--)
6647 if (!m_table
->IsEmptyCell(row
+l
, j
))
6649 if (GetCellOverflow(row
+l
, j
))
6651 wxGridCellCoords
cell(row
+l
, j
);
6652 bool marked
= FALSE
;
6654 for (int k
= 0; k
< numCells
; k
++)
6656 if ( cell
== cells
[k
] )
6664 int count
= redrawCells
.GetCount();
6665 for (int k
= 0; k
< count
; k
++)
6667 if ( cell
== redrawCells
[k
] )
6673 if (!marked
) redrawCells
.Add( cell
);
6681 DrawCell( dc
, cells
[i
] );
6684 numCells
= redrawCells
.GetCount();
6686 for ( i
= numCells
- 1; i
>= 0; i
-- )
6688 DrawCell( dc
, redrawCells
[i
] );
6693 void wxGrid::DrawGridSpace( wxDC
& dc
)
6696 m_gridWin
->GetClientSize( &cw
, &ch
);
6699 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6701 int rightCol
= m_numCols
> 0 ? GetColRight(m_numCols
- 1) : 0;
6702 int bottomRow
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) : 0 ;
6704 if ( right
> rightCol
|| bottom
> bottomRow
)
6707 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6709 dc
.SetBrush( wxBrush(GetDefaultCellBackgroundColour(), wxSOLID
) );
6710 dc
.SetPen( *wxTRANSPARENT_PEN
);
6712 if ( right
> rightCol
)
6714 dc
.DrawRectangle( rightCol
, top
, right
- rightCol
, ch
);
6717 if ( bottom
> bottomRow
)
6719 dc
.DrawRectangle( left
, bottomRow
, cw
, bottom
- bottomRow
);
6725 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
6727 int row
= coords
.GetRow();
6728 int col
= coords
.GetCol();
6730 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6733 // we draw the cell border ourselves
6734 #if !WXGRID_DRAW_LINES
6735 if ( m_gridLinesEnabled
)
6736 DrawCellBorder( dc
, coords
);
6739 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6741 bool isCurrent
= coords
== m_currentCellCoords
;
6743 wxRect rect
= CellToRect( row
, col
);
6745 // if the editor is shown, we should use it and not the renderer
6746 // Note: However, only if it is really _shown_, i.e. not hidden!
6747 if ( isCurrent
&& IsCellEditControlShown() )
6749 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
6750 editor
->PaintBackground(rect
, attr
);
6755 // but all the rest is drawn by the cell renderer and hence may be
6757 wxGridCellRenderer
*renderer
= attr
->GetRenderer(this, row
, col
);
6758 renderer
->Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
6765 void wxGrid::DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
)
6767 int row
= m_currentCellCoords
.GetRow();
6768 int col
= m_currentCellCoords
.GetCol();
6770 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6773 wxRect rect
= CellToRect(row
, col
);
6775 // hmmm... what could we do here to show that the cell is disabled?
6776 // for now, I just draw a thinner border than for the other ones, but
6777 // it doesn't look really good
6779 int penWidth
= attr
->IsReadOnly() ? m_cellHighlightROPenWidth
: m_cellHighlightPenWidth
;
6783 // The center of th drawn line is where the position/width/height of
6784 // the rectangle is actually at, (on wxMSW atr least,) so we will
6785 // reduce the size of the rectangle to compensate for the thickness of
6786 // the line. If this is too strange on non wxMSW platforms then
6787 // please #ifdef this appropriately.
6788 rect
.x
+= penWidth
/2;
6789 rect
.y
+= penWidth
/2;
6790 rect
.width
-= penWidth
-1;
6791 rect
.height
-= penWidth
-1;
6794 // Now draw the rectangle
6795 // use the cellHighlightColour if the cell is inside a selection, this
6796 // will ensure the cell is always visible.
6797 dc
.SetPen(wxPen(IsInSelection(row
,col
)?m_selectionForeground
:m_cellHighlightColour
, penWidth
, wxSOLID
));
6798 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
6799 dc
.DrawRectangle(rect
);
6803 // VZ: my experiments with 3d borders...
6805 // how to properly set colours for arbitrary bg?
6806 wxCoord x1
= rect
.x
,
6808 x2
= rect
.x
+ rect
.width
-1,
6809 y2
= rect
.y
+ rect
.height
-1;
6811 dc
.SetPen(*wxWHITE_PEN
);
6812 dc
.DrawLine(x1
, y1
, x2
, y1
);
6813 dc
.DrawLine(x1
, y1
, x1
, y2
);
6815 dc
.DrawLine(x1
+ 1, y2
- 1, x2
- 1, y2
- 1);
6816 dc
.DrawLine(x2
- 1, y1
+ 1, x2
- 1, y2
);
6818 dc
.SetPen(*wxBLACK_PEN
);
6819 dc
.DrawLine(x1
, y2
, x2
, y2
);
6820 dc
.DrawLine(x2
, y1
, x2
, y2
+1);
6825 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
6827 int row
= coords
.GetRow();
6828 int col
= coords
.GetCol();
6829 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6832 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
6834 wxRect rect
= CellToRect( row
, col
);
6836 // right hand border
6838 dc
.DrawLine( rect
.x
+ rect
.width
, rect
.y
,
6839 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
+ 1 );
6843 dc
.DrawLine( rect
.x
, rect
.y
+ rect
.height
,
6844 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
6847 void wxGrid::DrawHighlight(wxDC
& dc
,const wxGridCellCoordsArray
& cells
)
6849 // This if block was previously in wxGrid::OnPaint but that doesn't
6850 // seem to get called under wxGTK - MB
6852 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
6853 m_numRows
&& m_numCols
)
6855 m_currentCellCoords
.Set(0, 0);
6858 if ( IsCellEditControlShown() )
6860 // don't show highlight when the edit control is shown
6864 // if the active cell was repainted, repaint its highlight too because it
6865 // might have been damaged by the grid lines
6866 size_t count
= cells
.GetCount();
6867 for ( size_t n
= 0; n
< count
; n
++ )
6869 if ( cells
[n
] == m_currentCellCoords
)
6871 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
6872 DrawCellHighlight(dc
, attr
);
6880 // TODO: remove this ???
6881 // This is used to redraw all grid lines e.g. when the grid line colour
6884 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& WXUNUSED(reg
) )
6886 #if !WXGRID_DRAW_LINES
6890 if ( !m_gridLinesEnabled
||
6892 !m_numCols
) return;
6894 int top
, bottom
, left
, right
;
6896 #if 0 //#ifndef __WXGTK__
6900 m_gridWin
->GetClientSize(&cw
, &ch
);
6902 // virtual coords of visible area
6904 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6905 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6910 reg
.GetBox(x
, y
, w
, h
);
6911 CalcUnscrolledPosition( x
, y
, &left
, &top
);
6912 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
6916 m_gridWin
->GetClientSize(&cw
, &ch
);
6917 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6918 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6921 // avoid drawing grid lines past the last row and col
6923 right
= wxMin( right
, GetColRight(m_numCols
- 1) );
6924 bottom
= wxMin( bottom
, GetRowBottom(m_numRows
- 1) );
6926 // no gridlines inside multicells, clip them out
6927 int leftCol
= internalXToCol(left
);
6928 int topRow
= internalYToRow(top
);
6929 int rightCol
= internalXToCol(right
);
6930 int bottomRow
= internalYToRow(bottom
);
6931 wxRegion
clippedcells(0, 0, cw
, ch
);
6934 int i
, j
, cell_rows
, cell_cols
;
6937 for (j
=topRow
; j
<bottomRow
; j
++)
6939 for (i
=leftCol
; i
<rightCol
; i
++)
6941 GetCellSize( j
, i
, &cell_rows
, &cell_cols
);
6942 if ((cell_rows
> 1) || (cell_cols
> 1))
6944 rect
= CellToRect(j
,i
);
6945 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
6946 clippedcells
.Subtract(rect
);
6948 else if ((cell_rows
< 0) || (cell_cols
< 0))
6950 rect
= CellToRect(j
+cell_rows
, i
+cell_cols
);
6951 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
6952 clippedcells
.Subtract(rect
);
6956 dc
.SetClippingRegion( clippedcells
);
6958 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
6960 // horizontal grid lines
6962 // already declared above - int i;
6963 for ( i
= internalYToRow(top
); i
< m_numRows
; i
++ )
6965 int bot
= GetRowBottom(i
) - 1;
6974 dc
.DrawLine( left
, bot
, right
, bot
);
6979 // vertical grid lines
6981 for ( i
= internalXToCol(left
); i
< m_numCols
; i
++ )
6983 int colRight
= GetColRight(i
) - 1;
6984 if ( colRight
> right
)
6989 if ( colRight
>= left
)
6991 dc
.DrawLine( colRight
, top
, colRight
, bottom
);
6994 dc
.DestroyClippingRegion();
6998 void wxGrid::DrawRowLabels( wxDC
& dc
,const wxArrayInt
& rows
)
7000 if ( !m_numRows
) return;
7003 size_t numLabels
= rows
.GetCount();
7005 for ( i
= 0; i
< numLabels
; i
++ )
7007 DrawRowLabel( dc
, rows
[i
] );
7012 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
7014 if ( GetRowHeight(row
) <= 0 )
7017 int rowTop
= GetRowTop(row
),
7018 rowBottom
= GetRowBottom(row
) - 1;
7020 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
),1, wxSOLID
) );
7021 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
7022 m_rowLabelWidth
-1, rowBottom
);
7024 dc
.DrawLine( 0, rowTop
, 0, rowBottom
);
7026 dc
.DrawLine( 0, rowBottom
, m_rowLabelWidth
, rowBottom
);
7028 dc
.SetPen( *wxWHITE_PEN
);
7029 dc
.DrawLine( 1, rowTop
, 1, rowBottom
);
7030 dc
.DrawLine( 1, rowTop
, m_rowLabelWidth
-1, rowTop
);
7032 dc
.SetBackgroundMode( wxTRANSPARENT
);
7033 dc
.SetTextForeground( GetLabelTextColour() );
7034 dc
.SetFont( GetLabelFont() );
7037 GetRowLabelAlignment( &hAlign
, &vAlign
);
7041 rect
.SetY( GetRowTop(row
) + 2 );
7042 rect
.SetWidth( m_rowLabelWidth
- 4 );
7043 rect
.SetHeight( GetRowHeight(row
) - 4 );
7044 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
7048 void wxGrid::DrawColLabels( wxDC
& dc
,const wxArrayInt
& cols
)
7050 if ( !m_numCols
) return;
7053 size_t numLabels
= cols
.GetCount();
7055 for ( i
= 0; i
< numLabels
; i
++ )
7057 DrawColLabel( dc
, cols
[i
] );
7062 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
7064 if ( GetColWidth(col
) <= 0 )
7067 int colLeft
= GetColLeft(col
),
7068 colRight
= GetColRight(col
) - 1;
7070 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
),1, wxSOLID
) );
7071 dc
.DrawLine( colRight
, 0,
7072 colRight
, m_colLabelHeight
-1 );
7074 dc
.DrawLine( colLeft
, 0, colRight
, 0 );
7076 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
7077 colRight
+1, m_colLabelHeight
-1 );
7079 dc
.SetPen( *wxWHITE_PEN
);
7080 dc
.DrawLine( colLeft
, 1, colLeft
, m_colLabelHeight
-1 );
7081 dc
.DrawLine( colLeft
, 1, colRight
, 1 );
7083 dc
.SetBackgroundMode( wxTRANSPARENT
);
7084 dc
.SetTextForeground( GetLabelTextColour() );
7085 dc
.SetFont( GetLabelFont() );
7087 int hAlign
, vAlign
, orient
;
7088 GetColLabelAlignment( &hAlign
, &vAlign
);
7089 orient
= GetColLabelTextOrientation();
7092 rect
.SetX( colLeft
+ 2 );
7094 rect
.SetWidth( GetColWidth(col
) - 4 );
7095 rect
.SetHeight( m_colLabelHeight
- 4 );
7096 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
, orient
);
7099 void wxGrid::DrawTextRectangle( wxDC
& dc
,
7100 const wxString
& value
,
7104 int textOrientation
)
7106 wxArrayString lines
;
7108 StringToLines( value
, lines
);
7111 //Forward to new API.
7112 DrawTextRectangle( dc
,
7121 void wxGrid::DrawTextRectangle( wxDC
& dc
,
7122 const wxArrayString
& lines
,
7126 int textOrientation
)
7128 long textWidth
, textHeight
;
7129 long lineWidth
, lineHeight
;
7132 dc
.SetClippingRegion( rect
);
7134 nLines
= lines
.GetCount();
7138 float x
= 0.0, y
= 0.0;
7140 if( textOrientation
== wxHORIZONTAL
)
7141 GetTextBoxSize(dc
, lines
, &textWidth
, &textHeight
);
7143 GetTextBoxSize( dc
, lines
, &textHeight
, &textWidth
);
7147 case wxALIGN_BOTTOM
:
7148 if( textOrientation
== wxHORIZONTAL
)
7149 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
7151 x
= rect
.x
+ rect
.width
- textWidth
;
7154 case wxALIGN_CENTRE
:
7155 if( textOrientation
== wxHORIZONTAL
)
7156 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
7158 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
7163 if( textOrientation
== wxHORIZONTAL
)
7170 // Align each line of a multi-line label
7171 for( l
= 0; l
< nLines
; l
++ )
7173 dc
.GetTextExtent(lines
[l
], &lineWidth
, &lineHeight
);
7175 switch( horizAlign
)
7178 if( textOrientation
== wxHORIZONTAL
)
7179 x
= rect
.x
+ (rect
.width
- lineWidth
- 1);
7181 y
= rect
.y
+ lineWidth
+ 1;
7184 case wxALIGN_CENTRE
:
7185 if( textOrientation
== wxHORIZONTAL
)
7186 x
= rect
.x
+ ((rect
.width
- lineWidth
)/2);
7188 y
= rect
.y
+ rect
.height
- ((rect
.height
- lineWidth
)/2);
7193 if( textOrientation
== wxHORIZONTAL
)
7196 y
= rect
.y
+ rect
.height
- 1;
7200 if( textOrientation
== wxHORIZONTAL
)
7202 dc
.DrawText( lines
[l
], (int)x
, (int)y
);
7207 dc
.DrawRotatedText( lines
[l
], (int)x
, (int)y
, 90.0 );
7212 dc
.DestroyClippingRegion();
7216 // Split multi line text up into an array of strings. Any existing
7217 // contents of the string array are preserved.
7219 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
7223 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
7224 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
7226 while ( startPos
< (int)tVal
.Length() )
7228 pos
= tVal
.Mid(startPos
).Find( eol
);
7233 else if ( pos
== 0 )
7235 lines
.Add( wxEmptyString
);
7239 lines
.Add( value
.Mid(startPos
, pos
) );
7243 if ( startPos
< (int)value
.Length() )
7245 lines
.Add( value
.Mid( startPos
) );
7250 void wxGrid::GetTextBoxSize( wxDC
& dc
,
7251 const wxArrayString
& lines
,
7252 long *width
, long *height
)
7259 for ( i
= 0; i
< lines
.GetCount(); i
++ )
7261 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
7262 w
= wxMax( w
, lineW
);
7271 // ------ Batch processing.
7273 void wxGrid::EndBatch()
7275 if ( m_batchCount
> 0 )
7278 if ( !m_batchCount
)
7281 m_rowLabelWin
->Refresh();
7282 m_colLabelWin
->Refresh();
7283 m_cornerLabelWin
->Refresh();
7284 m_gridWin
->Refresh();
7289 // Use this, rather than wxWindow::Refresh(), to force an immediate
7290 // repainting of the grid. Has no effect if you are already inside a
7291 // BeginBatch / EndBatch block.
7293 void wxGrid::ForceRefresh()
7301 // ------ Edit control functions
7305 void wxGrid::EnableEditing( bool edit
)
7307 // TODO: improve this ?
7309 if ( edit
!= m_editable
)
7311 if(!edit
) EnableCellEditControl(edit
);
7317 void wxGrid::EnableCellEditControl( bool enable
)
7322 if ( m_currentCellCoords
== wxGridNoCellCoords
)
7323 SetCurrentCell( 0, 0 );
7325 if ( enable
!= m_cellEditCtrlEnabled
)
7329 if (SendEvent( wxEVT_GRID_EDITOR_SHOWN
) <0)
7332 // this should be checked by the caller!
7333 wxASSERT_MSG( CanEnableCellControl(),
7334 _T("can't enable editing for this cell!") );
7336 // do it before ShowCellEditControl()
7337 m_cellEditCtrlEnabled
= enable
;
7339 ShowCellEditControl();
7343 //FIXME:add veto support
7344 SendEvent( wxEVT_GRID_EDITOR_HIDDEN
);
7346 HideCellEditControl();
7347 SaveEditControlValue();
7349 // do it after HideCellEditControl()
7350 m_cellEditCtrlEnabled
= enable
;
7355 bool wxGrid::IsCurrentCellReadOnly() const
7358 wxGridCellAttr
* attr
= ((wxGrid
*)this)->GetCellAttr(m_currentCellCoords
);
7359 bool readonly
= attr
->IsReadOnly();
7365 bool wxGrid::CanEnableCellControl() const
7367 return m_editable
&& !IsCurrentCellReadOnly();
7370 bool wxGrid::IsCellEditControlEnabled() const
7372 // the cell edit control might be disable for all cells or just for the
7373 // current one if it's read only
7374 return m_cellEditCtrlEnabled
? !IsCurrentCellReadOnly() : FALSE
;
7377 bool wxGrid::IsCellEditControlShown() const
7379 bool isShown
= FALSE
;
7381 if ( m_cellEditCtrlEnabled
)
7383 int row
= m_currentCellCoords
.GetRow();
7384 int col
= m_currentCellCoords
.GetCol();
7385 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7386 wxGridCellEditor
* editor
= attr
->GetEditor((wxGrid
*) this, row
, col
);
7391 if ( editor
->IsCreated() )
7393 isShown
= editor
->GetControl()->IsShown();
7403 void wxGrid::ShowCellEditControl()
7405 if ( IsCellEditControlEnabled() )
7407 if ( !IsVisible( m_currentCellCoords
) )
7409 m_cellEditCtrlEnabled
= FALSE
;
7414 wxRect rect
= CellToRect( m_currentCellCoords
);
7415 int row
= m_currentCellCoords
.GetRow();
7416 int col
= m_currentCellCoords
.GetCol();
7418 // if this is part of a multicell, find owner (topleft)
7419 int cell_rows
, cell_cols
;
7420 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7421 if ( cell_rows
<= 0 || cell_cols
<= 0 )
7425 m_currentCellCoords
.SetRow( row
);
7426 m_currentCellCoords
.SetCol( col
);
7429 // convert to scrolled coords
7431 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
7433 // done in PaintBackground()
7435 // erase the highlight and the cell contents because the editor
7436 // might not cover the entire cell
7437 wxClientDC
dc( m_gridWin
);
7439 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
); //wxBrush(attr->GetBackgroundColour(), wxSOLID));
7440 dc
.SetPen(*wxTRANSPARENT_PEN
);
7441 dc
.DrawRectangle(rect
);
7444 // cell is shifted by one pixel
7445 // However, don't allow x or y to become negative
7446 // since the SetSize() method interprets that as
7453 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7454 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
7455 if ( !editor
->IsCreated() )
7457 editor
->Create(m_gridWin
, -1,
7458 new wxGridCellEditorEvtHandler(this, editor
));
7460 wxGridEditorCreatedEvent
evt(GetId(),
7461 wxEVT_GRID_EDITOR_CREATED
,
7465 editor
->GetControl());
7466 GetEventHandler()->ProcessEvent(evt
);
7470 // resize editor to overflow into righthand cells if allowed
7471 int maxWidth
= rect
.width
;
7472 wxString value
= GetCellValue(row
, col
);
7473 if ( (value
!= wxEmptyString
) && (attr
->GetOverflow()) )
7476 GetTextExtent(value
, &maxWidth
, &y
,
7477 NULL
, NULL
, &attr
->GetFont());
7478 if (maxWidth
< rect
.width
) maxWidth
= rect
.width
;
7480 int client_right
= m_gridWin
->GetClientSize().GetWidth();
7481 if (rect
.x
+maxWidth
> client_right
)
7482 maxWidth
= client_right
- rect
.x
;
7484 if ((maxWidth
> rect
.width
) && (col
< m_numCols
) && m_table
)
7486 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7487 // may have changed earlier
7488 for (int i
= col
+cell_cols
; i
< m_numCols
; i
++)
7491 GetCellSize( row
, i
, &c_rows
, &c_cols
);
7492 // looks weird going over a multicell
7493 if (m_table
->IsEmptyCell(row
,i
) &&
7494 (rect
.width
< maxWidth
) && (c_rows
== 1))
7495 rect
.width
+= GetColWidth(i
);
7499 if (rect
.GetRight() > client_right
)
7500 rect
.SetRight(client_right
-1);
7503 editor
->SetCellAttr(attr
);
7504 editor
->SetSize( rect
);
7505 editor
->Show( TRUE
, attr
);
7507 // recalc dimensions in case we need to
7508 // expand the scrolled window to account for editor
7511 editor
->BeginEdit(row
, col
, this);
7512 editor
->SetCellAttr(NULL
);
7521 void wxGrid::HideCellEditControl()
7523 if ( IsCellEditControlEnabled() )
7525 int row
= m_currentCellCoords
.GetRow();
7526 int col
= m_currentCellCoords
.GetCol();
7528 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7529 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
7530 editor
->Show( FALSE
);
7533 m_gridWin
->SetFocus();
7534 // refresh whole row to the right
7535 wxRect
rect( CellToRect(row
, col
) );
7536 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
7537 rect
.width
= m_gridWin
->GetClientSize().GetWidth() - rect
.x
;
7538 m_gridWin
->Refresh( FALSE
, &rect
);
7543 void wxGrid::SaveEditControlValue()
7545 if ( IsCellEditControlEnabled() )
7547 int row
= m_currentCellCoords
.GetRow();
7548 int col
= m_currentCellCoords
.GetCol();
7550 wxString oldval
= GetCellValue(row
,col
);
7552 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7553 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
7554 bool changed
= editor
->EndEdit(row
, col
, this);
7561 if ( SendEvent( wxEVT_GRID_CELL_CHANGE
,
7562 m_currentCellCoords
.GetRow(),
7563 m_currentCellCoords
.GetCol() ) < 0 ) {
7565 // Event has been vetoed, set the data back.
7566 SetCellValue(row
,col
,oldval
);
7574 // ------ Grid location functions
7575 // Note that all of these functions work with the logical coordinates of
7576 // grid cells and labels so you will need to convert from device
7577 // coordinates for mouse events etc.
7580 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
7582 int row
= YToRow(y
);
7583 int col
= XToCol(x
);
7585 if ( row
== -1 || col
== -1 )
7587 coords
= wxGridNoCellCoords
;
7591 coords
.Set( row
, col
);
7596 // Internal Helper function for computing row or column from some
7597 // (unscrolled) coordinate value, using either
7598 // m_defaultRowHeight/m_defaultColWidth or binary search on array
7599 // of m_rowBottoms/m_ColRights to speed up the search!
7601 static int CoordToRowOrCol(int coord
, int defaultDist
, int minDist
,
7602 const wxArrayInt
& BorderArray
, int nMax
,
7607 return clipToMinMax
&& (nMax
> 0) ? 0 : -1;
7613 size_t i_max
= coord
/ defaultDist
,
7616 if (BorderArray
.IsEmpty())
7618 if((int) i_max
< nMax
)
7620 return clipToMinMax
? nMax
- 1 : -1;
7623 if ( i_max
>= BorderArray
.GetCount())
7624 i_max
= BorderArray
.GetCount() - 1;
7627 if ( coord
>= BorderArray
[i_max
])
7630 i_max
= coord
/ minDist
;
7632 if ( i_max
>= BorderArray
.GetCount())
7633 i_max
= BorderArray
.GetCount() - 1;
7635 if ( coord
>= BorderArray
[i_max
])
7636 return clipToMinMax
? (int)i_max
: -1;
7637 if ( coord
< BorderArray
[0] )
7640 while ( i_max
- i_min
> 0 )
7642 wxCHECK_MSG(BorderArray
[i_min
] <= coord
&& coord
< BorderArray
[i_max
],
7643 0, _T("wxGrid: internal error in CoordToRowOrCol"));
7644 if (coord
>= BorderArray
[ i_max
- 1])
7648 int median
= i_min
+ (i_max
- i_min
+ 1) / 2;
7649 if (coord
< BorderArray
[median
])
7657 int wxGrid::YToRow( int y
)
7659 return CoordToRowOrCol(y
, m_defaultRowHeight
,
7660 WXGRID_MIN_ROW_HEIGHT
, m_rowBottoms
, m_numRows
, FALSE
);
7664 int wxGrid::XToCol( int x
)
7666 return CoordToRowOrCol(x
, m_defaultColWidth
,
7667 WXGRID_MIN_COL_WIDTH
, m_colRights
, m_numCols
, FALSE
);
7671 // return the row number that that the y coord is near the edge of, or
7672 // -1 if not near an edge
7674 int wxGrid::YToEdgeOfRow( int y
)
7677 i
= internalYToRow(y
);
7679 if ( GetRowHeight(i
) > WXGRID_LABEL_EDGE_ZONE
)
7681 // We know that we are in row i, test whether we are
7682 // close enough to lower or upper border, respectively.
7683 if ( abs(GetRowBottom(i
) - y
) < WXGRID_LABEL_EDGE_ZONE
)
7685 else if( i
> 0 && y
- GetRowTop(i
) < WXGRID_LABEL_EDGE_ZONE
)
7693 // return the col number that that the x coord is near the edge of, or
7694 // -1 if not near an edge
7696 int wxGrid::XToEdgeOfCol( int x
)
7699 i
= internalXToCol(x
);
7701 if ( GetColWidth(i
) > WXGRID_LABEL_EDGE_ZONE
)
7703 // We know that we are in column i, test whether we are
7704 // close enough to right or left border, respectively.
7705 if ( abs(GetColRight(i
) - x
) < WXGRID_LABEL_EDGE_ZONE
)
7707 else if( i
> 0 && x
- GetColLeft(i
) < WXGRID_LABEL_EDGE_ZONE
)
7715 wxRect
wxGrid::CellToRect( int row
, int col
)
7717 wxRect
rect( -1, -1, -1, -1 );
7719 if ( row
>= 0 && row
< m_numRows
&&
7720 col
>= 0 && col
< m_numCols
)
7722 int i
, cell_rows
, cell_cols
;
7723 rect
.width
= rect
.height
= 0;
7724 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7725 // if negative then find multicell owner
7726 if (cell_rows
< 0) row
+= cell_rows
;
7727 if (cell_cols
< 0) col
+= cell_cols
;
7728 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7730 rect
.x
= GetColLeft(col
);
7731 rect
.y
= GetRowTop(row
);
7732 for (i
=col
; i
<col
+cell_cols
; i
++)
7733 rect
.width
+= GetColWidth(i
);
7734 for (i
=row
; i
<row
+cell_rows
; i
++)
7735 rect
.height
+= GetRowHeight(i
);
7738 // if grid lines are enabled, then the area of the cell is a bit smaller
7739 if (m_gridLinesEnabled
) {
7747 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
7749 // get the cell rectangle in logical coords
7751 wxRect
r( CellToRect( row
, col
) );
7753 // convert to device coords
7755 int left
, top
, right
, bottom
;
7756 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
7757 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
7759 // check against the client area of the grid window
7762 m_gridWin
->GetClientSize( &cw
, &ch
);
7764 if ( wholeCellVisible
)
7766 // is the cell wholly visible ?
7768 return ( left
>= 0 && right
<= cw
&&
7769 top
>= 0 && bottom
<= ch
);
7773 // is the cell partly visible ?
7775 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
7776 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
7781 // make the specified cell location visible by doing a minimal amount
7784 void wxGrid::MakeCellVisible( int row
, int col
)
7788 int xpos
= -1, ypos
= -1;
7790 if ( row
>= 0 && row
< m_numRows
&&
7791 col
>= 0 && col
< m_numCols
)
7793 // get the cell rectangle in logical coords
7795 wxRect
r( CellToRect( row
, col
) );
7797 // convert to device coords
7799 int left
, top
, right
, bottom
;
7800 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
7801 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
7804 m_gridWin
->GetClientSize( &cw
, &ch
);
7810 else if ( bottom
> ch
)
7812 int h
= r
.GetHeight();
7814 for ( i
= row
-1; i
>= 0; i
-- )
7816 int rowHeight
= GetRowHeight(i
);
7817 if ( h
+ rowHeight
> ch
)
7824 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
7825 // have rounding errors (this is important, because if we do, we
7826 // might not scroll at all and some cells won't be redrawn)
7828 // Sometimes GRID_SCROLL_LINE/2 is not enough, so just add a full
7830 ypos
+= GRID_SCROLL_LINE_Y
;
7837 else if ( right
> cw
)
7839 // position the view so that the cell is on the right
7841 CalcUnscrolledPosition(0, 0, &x0
, &y0
);
7842 xpos
= x0
+ (right
- cw
);
7844 // see comment for ypos above
7845 xpos
+= GRID_SCROLL_LINE_X
;
7848 if ( xpos
!= -1 || ypos
!= -1 )
7851 xpos
/= GRID_SCROLL_LINE_X
;
7853 ypos
/= GRID_SCROLL_LINE_Y
;
7854 Scroll( xpos
, ypos
);
7862 // ------ Grid cursor movement functions
7865 bool wxGrid::MoveCursorUp( bool expandSelection
)
7867 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7868 m_currentCellCoords
.GetRow() >= 0 )
7870 if ( expandSelection
)
7872 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7873 m_selectingKeyboard
= m_currentCellCoords
;
7874 if ( m_selectingKeyboard
.GetRow() > 0 )
7876 m_selectingKeyboard
.SetRow( m_selectingKeyboard
.GetRow() - 1 );
7877 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7878 m_selectingKeyboard
.GetCol() );
7879 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7882 else if ( m_currentCellCoords
.GetRow() > 0 )
7885 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
7886 m_currentCellCoords
.GetCol() );
7887 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
7888 m_currentCellCoords
.GetCol() );
7899 bool wxGrid::MoveCursorDown( bool expandSelection
)
7901 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7902 m_currentCellCoords
.GetRow() < m_numRows
)
7904 if ( expandSelection
)
7906 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7907 m_selectingKeyboard
= m_currentCellCoords
;
7908 if ( m_selectingKeyboard
.GetRow() < m_numRows
-1 )
7910 m_selectingKeyboard
.SetRow( m_selectingKeyboard
.GetRow() + 1 );
7911 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7912 m_selectingKeyboard
.GetCol() );
7913 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7916 else if ( m_currentCellCoords
.GetRow() < m_numRows
- 1 )
7919 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
7920 m_currentCellCoords
.GetCol() );
7921 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
7922 m_currentCellCoords
.GetCol() );
7933 bool wxGrid::MoveCursorLeft( bool expandSelection
)
7935 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7936 m_currentCellCoords
.GetCol() >= 0 )
7938 if ( expandSelection
)
7940 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7941 m_selectingKeyboard
= m_currentCellCoords
;
7942 if ( m_selectingKeyboard
.GetCol() > 0 )
7944 m_selectingKeyboard
.SetCol( m_selectingKeyboard
.GetCol() - 1 );
7945 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7946 m_selectingKeyboard
.GetCol() );
7947 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7950 else if ( m_currentCellCoords
.GetCol() > 0 )
7953 MakeCellVisible( m_currentCellCoords
.GetRow(),
7954 m_currentCellCoords
.GetCol() - 1 );
7955 SetCurrentCell( m_currentCellCoords
.GetRow(),
7956 m_currentCellCoords
.GetCol() - 1 );
7967 bool wxGrid::MoveCursorRight( bool expandSelection
)
7969 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7970 m_currentCellCoords
.GetCol() < m_numCols
)
7972 if ( expandSelection
)
7974 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7975 m_selectingKeyboard
= m_currentCellCoords
;
7976 if ( m_selectingKeyboard
.GetCol() < m_numCols
- 1 )
7978 m_selectingKeyboard
.SetCol( m_selectingKeyboard
.GetCol() + 1 );
7979 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7980 m_selectingKeyboard
.GetCol() );
7981 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7984 else if ( m_currentCellCoords
.GetCol() < m_numCols
- 1 )
7987 MakeCellVisible( m_currentCellCoords
.GetRow(),
7988 m_currentCellCoords
.GetCol() + 1 );
7989 SetCurrentCell( m_currentCellCoords
.GetRow(),
7990 m_currentCellCoords
.GetCol() + 1 );
8001 bool wxGrid::MovePageUp()
8003 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
8005 int row
= m_currentCellCoords
.GetRow();
8009 m_gridWin
->GetClientSize( &cw
, &ch
);
8011 int y
= GetRowTop(row
);
8012 int newRow
= internalYToRow( y
- ch
+ 1 );
8014 if ( newRow
== row
)
8016 //row > 0 , so newrow can never be less than 0 here.
8020 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
8021 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
8029 bool wxGrid::MovePageDown()
8031 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
8033 int row
= m_currentCellCoords
.GetRow();
8034 if ( (row
+1) < m_numRows
)
8037 m_gridWin
->GetClientSize( &cw
, &ch
);
8039 int y
= GetRowTop(row
);
8040 int newRow
= internalYToRow( y
+ ch
);
8041 if ( newRow
== row
)
8043 // row < m_numRows , so newrow can't overflow here.
8047 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
8048 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
8056 bool wxGrid::MoveCursorUpBlock( bool expandSelection
)
8059 m_currentCellCoords
!= wxGridNoCellCoords
&&
8060 m_currentCellCoords
.GetRow() > 0 )
8062 int row
= m_currentCellCoords
.GetRow();
8063 int col
= m_currentCellCoords
.GetCol();
8065 if ( m_table
->IsEmptyCell(row
, col
) )
8067 // starting in an empty cell: find the next block of
8073 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8076 else if ( m_table
->IsEmptyCell(row
-1, col
) )
8078 // starting at the top of a block: find the next block
8084 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8089 // starting within a block: find the top of the block
8094 if ( m_table
->IsEmptyCell(row
, col
) )
8102 MakeCellVisible( row
, col
);
8103 if ( expandSelection
)
8105 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8106 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8111 SetCurrentCell( row
, col
);
8119 bool wxGrid::MoveCursorDownBlock( bool expandSelection
)
8122 m_currentCellCoords
!= wxGridNoCellCoords
&&
8123 m_currentCellCoords
.GetRow() < m_numRows
-1 )
8125 int row
= m_currentCellCoords
.GetRow();
8126 int col
= m_currentCellCoords
.GetCol();
8128 if ( m_table
->IsEmptyCell(row
, col
) )
8130 // starting in an empty cell: find the next block of
8133 while ( row
< m_numRows
-1 )
8136 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8139 else if ( m_table
->IsEmptyCell(row
+1, col
) )
8141 // starting at the bottom of a block: find the next block
8144 while ( row
< m_numRows
-1 )
8147 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8152 // starting within a block: find the bottom of the block
8154 while ( row
< m_numRows
-1 )
8157 if ( m_table
->IsEmptyCell(row
, col
) )
8165 MakeCellVisible( row
, col
);
8166 if ( expandSelection
)
8168 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8169 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8174 SetCurrentCell( row
, col
);
8183 bool wxGrid::MoveCursorLeftBlock( bool expandSelection
)
8186 m_currentCellCoords
!= wxGridNoCellCoords
&&
8187 m_currentCellCoords
.GetCol() > 0 )
8189 int row
= m_currentCellCoords
.GetRow();
8190 int col
= m_currentCellCoords
.GetCol();
8192 if ( m_table
->IsEmptyCell(row
, col
) )
8194 // starting in an empty cell: find the next block of
8200 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8203 else if ( m_table
->IsEmptyCell(row
, col
-1) )
8205 // starting at the left of a block: find the next block
8211 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8216 // starting within a block: find the left of the block
8221 if ( m_table
->IsEmptyCell(row
, col
) )
8229 MakeCellVisible( row
, col
);
8230 if ( expandSelection
)
8232 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8233 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8238 SetCurrentCell( row
, col
);
8247 bool wxGrid::MoveCursorRightBlock( bool expandSelection
)
8250 m_currentCellCoords
!= wxGridNoCellCoords
&&
8251 m_currentCellCoords
.GetCol() < m_numCols
-1 )
8253 int row
= m_currentCellCoords
.GetRow();
8254 int col
= m_currentCellCoords
.GetCol();
8256 if ( m_table
->IsEmptyCell(row
, col
) )
8258 // starting in an empty cell: find the next block of
8261 while ( col
< m_numCols
-1 )
8264 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8267 else if ( m_table
->IsEmptyCell(row
, col
+1) )
8269 // starting at the right of a block: find the next block
8272 while ( col
< m_numCols
-1 )
8275 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8280 // starting within a block: find the right of the block
8282 while ( col
< m_numCols
-1 )
8285 if ( m_table
->IsEmptyCell(row
, col
) )
8293 MakeCellVisible( row
, col
);
8294 if ( expandSelection
)
8296 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8297 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8302 SetCurrentCell( row
, col
);
8314 // ------ Label values and formatting
8317 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
8319 *horiz
= m_rowLabelHorizAlign
;
8320 *vert
= m_rowLabelVertAlign
;
8323 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
8325 *horiz
= m_colLabelHorizAlign
;
8326 *vert
= m_colLabelVertAlign
;
8329 int wxGrid::GetColLabelTextOrientation()
8331 return m_colLabelTextOrientation
;
8334 wxString
wxGrid::GetRowLabelValue( int row
)
8338 return m_table
->GetRowLabelValue( row
);
8348 wxString
wxGrid::GetColLabelValue( int col
)
8352 return m_table
->GetColLabelValue( col
);
8363 void wxGrid::SetRowLabelSize( int width
)
8365 width
= wxMax( width
, 0 );
8366 if ( width
!= m_rowLabelWidth
)
8370 m_rowLabelWin
->Show( FALSE
);
8371 m_cornerLabelWin
->Show( FALSE
);
8373 else if ( m_rowLabelWidth
== 0 )
8375 m_rowLabelWin
->Show( TRUE
);
8376 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
8379 m_rowLabelWidth
= width
;
8381 wxScrolledWindow::Refresh( TRUE
);
8386 void wxGrid::SetColLabelSize( int height
)
8388 height
= wxMax( height
, 0 );
8389 if ( height
!= m_colLabelHeight
)
8393 m_colLabelWin
->Show( FALSE
);
8394 m_cornerLabelWin
->Show( FALSE
);
8396 else if ( m_colLabelHeight
== 0 )
8398 m_colLabelWin
->Show( TRUE
);
8399 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
8402 m_colLabelHeight
= height
;
8404 wxScrolledWindow::Refresh( TRUE
);
8409 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
8411 if ( m_labelBackgroundColour
!= colour
)
8413 m_labelBackgroundColour
= colour
;
8414 m_rowLabelWin
->SetBackgroundColour( colour
);
8415 m_colLabelWin
->SetBackgroundColour( colour
);
8416 m_cornerLabelWin
->SetBackgroundColour( colour
);
8418 if ( !GetBatchCount() )
8420 m_rowLabelWin
->Refresh();
8421 m_colLabelWin
->Refresh();
8422 m_cornerLabelWin
->Refresh();
8427 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
8429 if ( m_labelTextColour
!= colour
)
8431 m_labelTextColour
= colour
;
8432 if ( !GetBatchCount() )
8434 m_rowLabelWin
->Refresh();
8435 m_colLabelWin
->Refresh();
8440 void wxGrid::SetLabelFont( const wxFont
& font
)
8443 if ( !GetBatchCount() )
8445 m_rowLabelWin
->Refresh();
8446 m_colLabelWin
->Refresh();
8450 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
8452 // allow old (incorrect) defs to be used
8455 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
8456 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
8457 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
8462 case wxTOP
: vert
= wxALIGN_TOP
; break;
8463 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
8464 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
8467 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
8469 m_rowLabelHorizAlign
= horiz
;
8472 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
8474 m_rowLabelVertAlign
= vert
;
8477 if ( !GetBatchCount() )
8479 m_rowLabelWin
->Refresh();
8483 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
8485 // allow old (incorrect) defs to be used
8488 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
8489 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
8490 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
8495 case wxTOP
: vert
= wxALIGN_TOP
; break;
8496 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
8497 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
8500 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
8502 m_colLabelHorizAlign
= horiz
;
8505 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
8507 m_colLabelVertAlign
= vert
;
8510 if ( !GetBatchCount() )
8512 m_colLabelWin
->Refresh();
8516 // Note: under MSW, the default column label font must be changed because it
8517 // does not support vertical printing
8519 // Example: wxFont font(9, wxSWISS, wxNORMAL, wxBOLD);
8520 // pGrid->SetLabelFont(font);
8521 // pGrid->SetColLabelTextOrientation(wxVERTICAL);
8523 void wxGrid::SetColLabelTextOrientation( int textOrientation
)
8525 if( textOrientation
== wxHORIZONTAL
|| textOrientation
== wxVERTICAL
)
8527 m_colLabelTextOrientation
= textOrientation
;
8530 if ( !GetBatchCount() )
8532 m_colLabelWin
->Refresh();
8536 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
8540 m_table
->SetRowLabelValue( row
, s
);
8541 if ( !GetBatchCount() )
8543 wxRect rect
= CellToRect( row
, 0);
8544 if ( rect
.height
> 0 )
8546 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
8548 rect
.width
= m_rowLabelWidth
;
8549 m_rowLabelWin
->Refresh( TRUE
, &rect
);
8555 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
8559 m_table
->SetColLabelValue( col
, s
);
8560 if ( !GetBatchCount() )
8562 wxRect rect
= CellToRect( 0, col
);
8563 if ( rect
.width
> 0 )
8565 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
8567 rect
.height
= m_colLabelHeight
;
8568 m_colLabelWin
->Refresh( TRUE
, &rect
);
8574 void wxGrid::SetGridLineColour( const wxColour
& colour
)
8576 if ( m_gridLineColour
!= colour
)
8578 m_gridLineColour
= colour
;
8580 wxClientDC
dc( m_gridWin
);
8582 DrawAllGridLines( dc
, wxRegion() );
8587 void wxGrid::SetCellHighlightColour( const wxColour
& colour
)
8589 if ( m_cellHighlightColour
!= colour
)
8591 m_cellHighlightColour
= colour
;
8593 wxClientDC
dc( m_gridWin
);
8595 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
8596 DrawCellHighlight(dc
, attr
);
8601 void wxGrid::SetCellHighlightPenWidth(int width
)
8603 if (m_cellHighlightPenWidth
!= width
) {
8604 m_cellHighlightPenWidth
= width
;
8606 // Just redrawing the cell highlight is not enough since that won't
8607 // make any visible change if the the thickness is getting smaller.
8608 int row
= m_currentCellCoords
.GetRow();
8609 int col
= m_currentCellCoords
.GetCol();
8610 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
8612 wxRect rect
= CellToRect(row
, col
);
8613 m_gridWin
->Refresh(TRUE
, &rect
);
8617 void wxGrid::SetCellHighlightROPenWidth(int width
)
8619 if (m_cellHighlightROPenWidth
!= width
) {
8620 m_cellHighlightROPenWidth
= width
;
8622 // Just redrawing the cell highlight is not enough since that won't
8623 // make any visible change if the the thickness is getting smaller.
8624 int row
= m_currentCellCoords
.GetRow();
8625 int col
= m_currentCellCoords
.GetCol();
8626 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
8628 wxRect rect
= CellToRect(row
, col
);
8629 m_gridWin
->Refresh(TRUE
, &rect
);
8633 void wxGrid::EnableGridLines( bool enable
)
8635 if ( enable
!= m_gridLinesEnabled
)
8637 m_gridLinesEnabled
= enable
;
8639 if ( !GetBatchCount() )
8643 wxClientDC
dc( m_gridWin
);
8645 DrawAllGridLines( dc
, wxRegion() );
8649 m_gridWin
->Refresh();
8656 int wxGrid::GetDefaultRowSize()
8658 return m_defaultRowHeight
;
8661 int wxGrid::GetRowSize( int row
)
8663 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
8665 return GetRowHeight(row
);
8668 int wxGrid::GetDefaultColSize()
8670 return m_defaultColWidth
;
8673 int wxGrid::GetColSize( int col
)
8675 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
8677 return GetColWidth(col
);
8680 // ============================================================================
8681 // access to the grid attributes: each of them has a default value in the grid
8682 // itself and may be overidden on a per-cell basis
8683 // ============================================================================
8685 // ----------------------------------------------------------------------------
8686 // setting default attributes
8687 // ----------------------------------------------------------------------------
8689 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
8691 m_defaultCellAttr
->SetBackgroundColour(col
);
8693 m_gridWin
->SetBackgroundColour(col
);
8697 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
8699 m_defaultCellAttr
->SetTextColour(col
);
8702 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
8704 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
8707 void wxGrid::SetDefaultCellOverflow( bool allow
)
8709 m_defaultCellAttr
->SetOverflow(allow
);
8712 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
8714 m_defaultCellAttr
->SetFont(font
);
8717 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
8719 m_defaultCellAttr
->SetRenderer(renderer
);
8722 void wxGrid::SetDefaultEditor(wxGridCellEditor
*editor
)
8724 m_defaultCellAttr
->SetEditor(editor
);
8727 // ----------------------------------------------------------------------------
8728 // access to the default attrbiutes
8729 // ----------------------------------------------------------------------------
8731 wxColour
wxGrid::GetDefaultCellBackgroundColour()
8733 return m_defaultCellAttr
->GetBackgroundColour();
8736 wxColour
wxGrid::GetDefaultCellTextColour()
8738 return m_defaultCellAttr
->GetTextColour();
8741 wxFont
wxGrid::GetDefaultCellFont()
8743 return m_defaultCellAttr
->GetFont();
8746 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
8748 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
8751 bool wxGrid::GetDefaultCellOverflow()
8753 return m_defaultCellAttr
->GetOverflow();
8756 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
8758 return m_defaultCellAttr
->GetRenderer(NULL
, 0, 0);
8761 wxGridCellEditor
*wxGrid::GetDefaultEditor() const
8763 return m_defaultCellAttr
->GetEditor(NULL
,0,0);
8766 // ----------------------------------------------------------------------------
8767 // access to cell attributes
8768 // ----------------------------------------------------------------------------
8770 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
8772 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8773 wxColour colour
= attr
->GetBackgroundColour();
8778 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
8780 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8781 wxColour colour
= attr
->GetTextColour();
8786 wxFont
wxGrid::GetCellFont( int row
, int col
)
8788 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8789 wxFont font
= attr
->GetFont();
8794 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
8796 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8797 attr
->GetAlignment(horiz
, vert
);
8801 bool wxGrid::GetCellOverflow( int row
, int col
)
8803 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8804 bool allow
= attr
->GetOverflow();
8809 void wxGrid::GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
)
8811 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8812 attr
->GetSize( num_rows
, num_cols
);
8816 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
)
8818 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8819 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
8825 wxGridCellEditor
* wxGrid::GetCellEditor(int row
, int col
)
8827 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8828 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
8834 bool wxGrid::IsReadOnly(int row
, int col
) const
8836 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8837 bool isReadOnly
= attr
->IsReadOnly();
8842 // ----------------------------------------------------------------------------
8843 // attribute support: cache, automatic provider creation, ...
8844 // ----------------------------------------------------------------------------
8846 bool wxGrid::CanHaveAttributes()
8853 return m_table
->CanHaveAttributes();
8856 void wxGrid::ClearAttrCache()
8858 if ( m_attrCache
.row
!= -1 )
8860 wxSafeDecRef(m_attrCache
.attr
);
8861 m_attrCache
.attr
= NULL
;
8862 m_attrCache
.row
= -1;
8866 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
8870 wxGrid
*self
= (wxGrid
*)this; // const_cast
8872 self
->ClearAttrCache();
8873 self
->m_attrCache
.row
= row
;
8874 self
->m_attrCache
.col
= col
;
8875 self
->m_attrCache
.attr
= attr
;
8880 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
8882 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
8884 *attr
= m_attrCache
.attr
;
8885 wxSafeIncRef(m_attrCache
.attr
);
8887 #ifdef DEBUG_ATTR_CACHE
8888 gs_nAttrCacheHits
++;
8895 #ifdef DEBUG_ATTR_CACHE
8896 gs_nAttrCacheMisses
++;
8902 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
8904 wxGridCellAttr
*attr
= NULL
;
8905 // Additional test to avoid looking at the cache e.g. for
8906 // wxNoCellCoords, as this will confuse memory management.
8909 if ( !LookupAttr(row
, col
, &attr
) )
8911 attr
= m_table
? m_table
->GetAttr(row
, col
, wxGridCellAttr::Any
)
8912 : (wxGridCellAttr
*)NULL
;
8913 CacheAttr(row
, col
, attr
);
8918 attr
->SetDefAttr(m_defaultCellAttr
);
8922 attr
= m_defaultCellAttr
;
8929 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
8931 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
8933 wxCHECK_MSG( m_table
, attr
,
8934 _T("we may only be called if CanHaveAttributes() returned TRUE and then m_table should be !NULL") );
8936 attr
= m_table
->GetAttr(row
, col
, wxGridCellAttr::Cell
);
8939 attr
= new wxGridCellAttr(m_defaultCellAttr
);
8941 // artificially inc the ref count to match DecRef() in caller
8943 m_table
->SetAttr(attr
, row
, col
);
8949 // ----------------------------------------------------------------------------
8950 // setting column attributes (wrappers around SetColAttr)
8951 // ----------------------------------------------------------------------------
8953 void wxGrid::SetColFormatBool(int col
)
8955 SetColFormatCustom(col
, wxGRID_VALUE_BOOL
);
8958 void wxGrid::SetColFormatNumber(int col
)
8960 SetColFormatCustom(col
, wxGRID_VALUE_NUMBER
);
8963 void wxGrid::SetColFormatFloat(int col
, int width
, int precision
)
8965 wxString typeName
= wxGRID_VALUE_FLOAT
;
8966 if ( (width
!= -1) || (precision
!= -1) )
8968 typeName
<< _T(':') << width
<< _T(',') << precision
;
8971 SetColFormatCustom(col
, typeName
);
8974 void wxGrid::SetColFormatCustom(int col
, const wxString
& typeName
)
8976 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
8978 attr
= m_table
->GetAttr(-1, col
, wxGridCellAttr::Col
);
8980 attr
= new wxGridCellAttr
;
8981 wxGridCellRenderer
*renderer
= GetDefaultRendererForType(typeName
);
8982 attr
->SetRenderer(renderer
);
8984 SetColAttr(col
, attr
);
8988 // ----------------------------------------------------------------------------
8989 // setting cell attributes: this is forwarded to the table
8990 // ----------------------------------------------------------------------------
8992 void wxGrid::SetAttr(int row
, int col
, wxGridCellAttr
*attr
)
8994 if ( CanHaveAttributes() )
8996 m_table
->SetAttr(attr
, row
, col
);
9005 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
9007 if ( CanHaveAttributes() )
9009 m_table
->SetRowAttr(attr
, row
);
9018 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
9020 if ( CanHaveAttributes() )
9022 m_table
->SetColAttr(attr
, col
);
9031 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
9033 if ( CanHaveAttributes() )
9035 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9036 attr
->SetBackgroundColour(colour
);
9041 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
9043 if ( CanHaveAttributes() )
9045 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9046 attr
->SetTextColour(colour
);
9051 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
9053 if ( CanHaveAttributes() )
9055 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9056 attr
->SetFont(font
);
9061 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
9063 if ( CanHaveAttributes() )
9065 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9066 attr
->SetAlignment(horiz
, vert
);
9071 void wxGrid::SetCellOverflow( int row
, int col
, bool allow
)
9073 if ( CanHaveAttributes() )
9075 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9076 attr
->SetOverflow(allow
);
9081 void wxGrid::SetCellSize( int row
, int col
, int num_rows
, int num_cols
)
9083 if ( CanHaveAttributes() )
9085 int cell_rows
, cell_cols
;
9087 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9088 attr
->GetSize(&cell_rows
, &cell_cols
);
9089 attr
->SetSize(num_rows
, num_cols
);
9092 // Cannot set the size of a cell to 0 or negative values
9093 // While it is perfectly legal to do that, this function cannot
9094 // handle all the possibilies, do it by hand by getting the CellAttr.
9095 // You can only set the size of a cell to 1,1 or greater with this fn
9096 wxASSERT_MSG( !((cell_rows
< 1) || (cell_cols
< 1)),
9097 wxT("wxGrid::SetCellSize setting cell size that is already part of another cell"));
9098 wxASSERT_MSG( !((num_rows
< 1) || (num_cols
< 1)),
9099 wxT("wxGrid::SetCellSize setting cell size to < 1"));
9101 // if this was already a multicell then "turn off" the other cells first
9102 if ((cell_rows
> 1) || (cell_rows
> 1))
9105 for (j
=row
; j
<row
+cell_rows
; j
++)
9107 for (i
=col
; i
<col
+cell_cols
; i
++)
9109 if ((i
!= col
) || (j
!= row
))
9111 wxGridCellAttr
*attr_stub
= GetOrCreateCellAttr(j
, i
);
9112 attr_stub
->SetSize( 1, 1 );
9113 attr_stub
->DecRef();
9119 // mark the cells that will be covered by this cell to
9120 // negative or zero values to point back at this cell
9121 if (((num_rows
> 1) || (num_cols
> 1)) && (num_rows
>= 1) && (num_cols
>= 1))
9124 for (j
=row
; j
<row
+num_rows
; j
++)
9126 for (i
=col
; i
<col
+num_cols
; i
++)
9128 if ((i
!= col
) || (j
!= row
))
9130 wxGridCellAttr
*attr_stub
= GetOrCreateCellAttr(j
, i
);
9131 attr_stub
->SetSize( row
-j
, col
-i
);
9132 attr_stub
->DecRef();
9140 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
9142 if ( CanHaveAttributes() )
9144 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9145 attr
->SetRenderer(renderer
);
9150 void wxGrid::SetCellEditor(int row
, int col
, wxGridCellEditor
* editor
)
9152 if ( CanHaveAttributes() )
9154 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9155 attr
->SetEditor(editor
);
9160 void wxGrid::SetReadOnly(int row
, int col
, bool isReadOnly
)
9162 if ( CanHaveAttributes() )
9164 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9165 attr
->SetReadOnly(isReadOnly
);
9170 // ----------------------------------------------------------------------------
9171 // Data type registration
9172 // ----------------------------------------------------------------------------
9174 void wxGrid::RegisterDataType(const wxString
& typeName
,
9175 wxGridCellRenderer
* renderer
,
9176 wxGridCellEditor
* editor
)
9178 m_typeRegistry
->RegisterDataType(typeName
, renderer
, editor
);
9182 wxGridCellEditor
* wxGrid::GetDefaultEditorForCell(int row
, int col
) const
9184 wxString typeName
= m_table
->GetTypeName(row
, col
);
9185 return GetDefaultEditorForType(typeName
);
9188 wxGridCellRenderer
* wxGrid::GetDefaultRendererForCell(int row
, int col
) const
9190 wxString typeName
= m_table
->GetTypeName(row
, col
);
9191 return GetDefaultRendererForType(typeName
);
9195 wxGrid::GetDefaultEditorForType(const wxString
& typeName
) const
9197 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
9198 if ( index
== wxNOT_FOUND
)
9200 wxFAIL_MSG(wxT("Unknown data type name"));
9205 return m_typeRegistry
->GetEditor(index
);
9209 wxGrid::GetDefaultRendererForType(const wxString
& typeName
) const
9211 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
9212 if ( index
== wxNOT_FOUND
)
9214 wxFAIL_MSG(wxT("Unknown data type name"));
9219 return m_typeRegistry
->GetRenderer(index
);
9223 // ----------------------------------------------------------------------------
9225 // ----------------------------------------------------------------------------
9227 void wxGrid::EnableDragRowSize( bool enable
)
9229 m_canDragRowSize
= enable
;
9233 void wxGrid::EnableDragColSize( bool enable
)
9235 m_canDragColSize
= enable
;
9238 void wxGrid::EnableDragGridSize( bool enable
)
9240 m_canDragGridSize
= enable
;
9244 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
9246 m_defaultRowHeight
= wxMax( height
, WXGRID_MIN_ROW_HEIGHT
);
9248 if ( resizeExistingRows
)
9250 // since we are resizing all rows to the default row size,
9251 // we can simply clear the row heights and row bottoms
9252 // arrays (which also allows us to take advantage of
9253 // some speed optimisations)
9254 m_rowHeights
.Empty();
9255 m_rowBottoms
.Empty();
9256 if ( !GetBatchCount() )
9261 void wxGrid::SetRowSize( int row
, int height
)
9263 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
9265 if ( m_rowHeights
.IsEmpty() )
9267 // need to really create the array
9271 int h
= wxMax( 0, height
);
9272 int diff
= h
- m_rowHeights
[row
];
9274 m_rowHeights
[row
] = h
;
9276 for ( i
= row
; i
< m_numRows
; i
++ )
9278 m_rowBottoms
[i
] += diff
;
9280 if ( !GetBatchCount() )
9284 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
9286 m_defaultColWidth
= wxMax( width
, WXGRID_MIN_COL_WIDTH
);
9288 if ( resizeExistingCols
)
9290 // since we are resizing all columns to the default column size,
9291 // we can simply clear the col widths and col rights
9292 // arrays (which also allows us to take advantage of
9293 // some speed optimisations)
9294 m_colWidths
.Empty();
9295 m_colRights
.Empty();
9296 if ( !GetBatchCount() )
9301 void wxGrid::SetColSize( int col
, int width
)
9303 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
9305 // should we check that it's bigger than GetColMinimalWidth(col) here?
9307 if ( m_colWidths
.IsEmpty() )
9309 // need to really create the array
9313 // if < 0 calc new width from label
9317 wxArrayString lines
;
9318 wxClientDC
dc(m_colLabelWin
);
9319 dc
.SetFont(GetLabelFont());
9320 StringToLines(GetColLabelValue(col
), lines
);
9321 GetTextBoxSize(dc
, lines
, &w
, &h
);
9324 int w
= wxMax( 0, width
);
9325 int diff
= w
- m_colWidths
[col
];
9326 m_colWidths
[col
] = w
;
9329 for ( i
= col
; i
< m_numCols
; i
++ )
9331 m_colRights
[i
] += diff
;
9333 if ( !GetBatchCount() )
9338 void wxGrid::SetColMinimalWidth( int col
, int width
)
9340 m_colMinWidths
.Put(col
, width
);
9343 void wxGrid::SetRowMinimalHeight( int row
, int width
)
9345 m_rowMinHeights
.Put(row
, width
);
9348 int wxGrid::GetColMinimalWidth(int col
) const
9350 long value
= m_colMinWidths
.Get(col
);
9351 return value
!= wxNOT_FOUND
? (int)value
: WXGRID_MIN_COL_WIDTH
;
9354 int wxGrid::GetRowMinimalHeight(int row
) const
9356 long value
= m_rowMinHeights
.Get(row
);
9357 return value
!= wxNOT_FOUND
? (int)value
: WXGRID_MIN_ROW_HEIGHT
;
9360 // ----------------------------------------------------------------------------
9362 // ----------------------------------------------------------------------------
9364 void wxGrid::AutoSizeColOrRow( int colOrRow
, bool setAsMin
, bool column
)
9366 wxClientDC
dc(m_gridWin
);
9368 // init both of them to avoid compiler warnings, even if weo nly need one
9376 wxCoord extent
, extentMax
= 0;
9377 int max
= column
? m_numRows
: m_numCols
;
9378 for ( int rowOrCol
= 0; rowOrCol
< max
; rowOrCol
++ )
9385 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
9386 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
9389 wxSize size
= renderer
->GetBestSize(*this, *attr
, dc
, row
, col
);
9390 extent
= column
? size
.x
: size
.y
;
9391 if ( extent
> extentMax
)
9402 // now also compare with the column label extent
9404 dc
.SetFont( GetLabelFont() );
9408 dc
.GetTextExtent( GetColLabelValue(col
), &w
, &h
);
9409 if( GetColLabelTextOrientation() == wxVERTICAL
)
9413 dc
.GetTextExtent( GetRowLabelValue(row
), &w
, &h
);
9415 extent
= column
? w
: h
;
9416 if ( extent
> extentMax
)
9423 // empty column - give default extent (notice that if extentMax is less
9424 // than default extent but != 0, it's ok)
9425 extentMax
= column
? m_defaultColWidth
: m_defaultRowHeight
;
9431 // leave some space around text
9442 SetColSize(col
, extentMax
);
9443 if ( !GetBatchCount() )
9446 m_gridWin
->GetClientSize( &cw
, &ch
);
9447 wxRect
rect ( CellToRect( 0, col
) );
9449 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
9450 rect
.width
= cw
- rect
.x
;
9451 rect
.height
= m_colLabelHeight
;
9452 m_colLabelWin
->Refresh( TRUE
, &rect
);
9457 SetRowSize(row
, extentMax
);
9458 if ( !GetBatchCount() )
9461 m_gridWin
->GetClientSize( &cw
, &ch
);
9462 wxRect
rect ( CellToRect( row
, 0 ) );
9464 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
9465 rect
.width
= m_rowLabelWidth
;
9466 rect
.height
= ch
- rect
.y
;
9467 m_rowLabelWin
->Refresh( TRUE
, &rect
);
9473 SetColMinimalWidth(col
, extentMax
);
9475 SetRowMinimalHeight(row
, extentMax
);
9479 int wxGrid::SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
)
9481 int width
= m_rowLabelWidth
;
9486 for ( int col
= 0; col
< m_numCols
; col
++ )
9490 AutoSizeColumn(col
, setAsMin
);
9493 width
+= GetColWidth(col
);
9502 int wxGrid::SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
)
9504 int height
= m_colLabelHeight
;
9509 for ( int row
= 0; row
< m_numRows
; row
++ )
9513 AutoSizeRow(row
, setAsMin
);
9516 height
+= GetRowHeight(row
);
9525 void wxGrid::AutoSize()
9529 wxSize
size(SetOrCalcColumnSizes(FALSE
), SetOrCalcRowSizes(FALSE
));
9531 // round up the size to a multiple of scroll step - this ensures that we
9532 // won't get the scrollbars if we're sized exactly to this width
9533 // CalcDimension adds m_extraWidth + 1 etc. to calculate the necessary
9535 wxSize
sizeFit(GetScrollX(size
.x
+ m_extraWidth
+ 1) * GRID_SCROLL_LINE_X
,
9536 GetScrollY(size
.y
+ m_extraHeight
+ 1) * GRID_SCROLL_LINE_Y
);
9538 // distribute the extra space between the columns/rows to avoid having
9539 // extra white space
9541 // Remove the extra m_extraWidth + 1 added above
9542 wxCoord diff
= sizeFit
.x
- size
.x
+ (m_extraWidth
+ 1);
9543 if ( diff
&& m_numCols
)
9545 // try to resize the columns uniformly
9546 wxCoord diffPerCol
= diff
/ m_numCols
;
9549 for ( int col
= 0; col
< m_numCols
; col
++ )
9551 SetColSize(col
, GetColWidth(col
) + diffPerCol
);
9555 // add remaining amount to the last columns
9556 diff
-= diffPerCol
* m_numCols
;
9559 for ( int col
= m_numCols
- 1; col
>= m_numCols
- diff
; col
-- )
9561 SetColSize(col
, GetColWidth(col
) + 1);
9567 diff
= sizeFit
.y
- size
.y
- (m_extraHeight
+ 1);
9568 if ( diff
&& m_numRows
)
9570 // try to resize the columns uniformly
9571 wxCoord diffPerRow
= diff
/ m_numRows
;
9574 for ( int row
= 0; row
< m_numRows
; row
++ )
9576 SetRowSize(row
, GetRowHeight(row
) + diffPerRow
);
9580 // add remaining amount to the last rows
9581 diff
-= diffPerRow
* m_numRows
;
9584 for ( int row
= m_numRows
- 1; row
>= m_numRows
- diff
; row
-- )
9586 SetRowSize(row
, GetRowHeight(row
) + 1);
9593 SetClientSize(sizeFit
);
9596 void wxGrid::AutoSizeRowLabelSize( int row
)
9598 wxArrayString lines
;
9601 // Hide the edit control, so it
9602 // won't interfer with drag-shrinking.
9603 if( IsCellEditControlShown() )
9605 HideCellEditControl();
9606 SaveEditControlValue();
9609 // autosize row height depending on label text
9610 StringToLines( GetRowLabelValue( row
), lines
);
9611 wxClientDC
dc( m_rowLabelWin
);
9612 GetTextBoxSize( dc
, lines
, &w
, &h
);
9613 if( h
< m_defaultRowHeight
)
9614 h
= m_defaultRowHeight
;
9619 void wxGrid::AutoSizeColLabelSize( int col
)
9621 wxArrayString lines
;
9624 // Hide the edit control, so it
9625 // won't interfer with drag-shrinking.
9626 if( IsCellEditControlShown() )
9628 HideCellEditControl();
9629 SaveEditControlValue();
9632 // autosize column width depending on label text
9633 StringToLines( GetColLabelValue( col
), lines
);
9634 wxClientDC
dc( m_colLabelWin
);
9635 if( GetColLabelTextOrientation() == wxHORIZONTAL
)
9636 GetTextBoxSize( dc
, lines
, &w
, &h
);
9638 GetTextBoxSize( dc
, lines
, &h
, &w
);
9639 if( w
< m_defaultColWidth
)
9640 w
= m_defaultColWidth
;
9645 wxSize
wxGrid::DoGetBestSize() const
9647 // don't set sizes, only calculate them
9648 wxGrid
*self
= (wxGrid
*)this; // const_cast
9651 width
= self
->SetOrCalcColumnSizes(TRUE
);
9652 height
= self
->SetOrCalcRowSizes(TRUE
);
9654 int maxwidth
, maxheight
;
9655 wxDisplaySize( & maxwidth
, & maxheight
);
9657 if ( width
> maxwidth
) width
= maxwidth
;
9658 if ( height
> maxheight
) height
= maxheight
;
9660 return wxSize( width
, height
);
9669 wxPen
& wxGrid::GetDividerPen() const
9674 // ----------------------------------------------------------------------------
9675 // cell value accessor functions
9676 // ----------------------------------------------------------------------------
9678 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
9682 m_table
->SetValue( row
, col
, s
);
9683 if ( !GetBatchCount() )
9686 wxRect
rect( CellToRect( row
, col
) );
9688 rect
.width
= m_gridWin
->GetClientSize().GetWidth();
9689 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
9690 m_gridWin
->Refresh( FALSE
, &rect
);
9693 if ( m_currentCellCoords
.GetRow() == row
&&
9694 m_currentCellCoords
.GetCol() == col
&&
9695 IsCellEditControlShown())
9696 // Note: If we are using IsCellEditControlEnabled,
9697 // this interacts badly with calling SetCellValue from
9698 // an EVT_GRID_CELL_CHANGE handler.
9700 HideCellEditControl();
9701 ShowCellEditControl(); // will reread data from table
9708 // ------ Block, row and col selection
9711 void wxGrid::SelectRow( int row
, bool addToSelected
)
9713 if ( IsSelection() && !addToSelected
)
9717 m_selection
->SelectRow( row
, FALSE
, addToSelected
);
9721 void wxGrid::SelectCol( int col
, bool addToSelected
)
9723 if ( IsSelection() && !addToSelected
)
9727 m_selection
->SelectCol( col
, FALSE
, addToSelected
);
9731 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
9732 bool addToSelected
)
9734 if ( IsSelection() && !addToSelected
)
9738 m_selection
->SelectBlock( topRow
, leftCol
, bottomRow
, rightCol
,
9739 FALSE
, addToSelected
);
9743 void wxGrid::SelectAll()
9745 if ( m_numRows
> 0 && m_numCols
> 0 )
9748 m_selection
->SelectBlock( 0, 0, m_numRows
-1, m_numCols
-1 );
9753 // ------ Cell, row and col deselection
9756 void wxGrid::DeselectRow( int row
)
9761 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectRows
)
9763 if ( m_selection
->IsInSelection(row
, 0 ) )
9764 m_selection
->ToggleCellSelection( row
, 0);
9768 int nCols
= GetNumberCols();
9769 for ( int i
= 0; i
< nCols
; i
++ )
9771 if ( m_selection
->IsInSelection(row
, i
) )
9772 m_selection
->ToggleCellSelection( row
, i
);
9777 void wxGrid::DeselectCol( int col
)
9782 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectColumns
)
9784 if ( m_selection
->IsInSelection(0, col
) )
9785 m_selection
->ToggleCellSelection( 0, col
);
9789 int nRows
= GetNumberRows();
9790 for ( int i
= 0; i
< nRows
; i
++ )
9792 if ( m_selection
->IsInSelection(i
, col
) )
9793 m_selection
->ToggleCellSelection(i
, col
);
9798 void wxGrid::DeselectCell( int row
, int col
)
9800 if ( m_selection
&& m_selection
->IsInSelection(row
, col
) )
9801 m_selection
->ToggleCellSelection(row
, col
);
9804 bool wxGrid::IsSelection()
9806 return ( m_selection
&& (m_selection
->IsSelection() ||
9807 ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
9808 m_selectingBottomRight
!= wxGridNoCellCoords
) ) );
9811 bool wxGrid::IsInSelection( int row
, int col
) const
9813 return ( m_selection
&& (m_selection
->IsInSelection( row
, col
) ||
9814 ( row
>= m_selectingTopLeft
.GetRow() &&
9815 col
>= m_selectingTopLeft
.GetCol() &&
9816 row
<= m_selectingBottomRight
.GetRow() &&
9817 col
<= m_selectingBottomRight
.GetCol() )) );
9820 wxGridCellCoordsArray
wxGrid::GetSelectedCells() const
9822 if (!m_selection
) { wxGridCellCoordsArray a
; return a
; }
9823 return m_selection
->m_cellSelection
;
9825 wxGridCellCoordsArray
wxGrid::GetSelectionBlockTopLeft() const
9827 if (!m_selection
) { wxGridCellCoordsArray a
; return a
; }
9828 return m_selection
->m_blockSelectionTopLeft
;
9830 wxGridCellCoordsArray
wxGrid::GetSelectionBlockBottomRight() const
9832 if (!m_selection
) { wxGridCellCoordsArray a
; return a
; }
9833 return m_selection
->m_blockSelectionBottomRight
;
9835 wxArrayInt
wxGrid::GetSelectedRows() const
9837 if (!m_selection
) { wxArrayInt a
; return a
; }
9838 return m_selection
->m_rowSelection
;
9840 wxArrayInt
wxGrid::GetSelectedCols() const
9842 if (!m_selection
) { wxArrayInt a
; return a
; }
9843 return m_selection
->m_colSelection
;
9847 void wxGrid::ClearSelection()
9849 m_selectingTopLeft
= wxGridNoCellCoords
;
9850 m_selectingBottomRight
= wxGridNoCellCoords
;
9852 m_selection
->ClearSelection();
9856 // This function returns the rectangle that encloses the given block
9857 // in device coords clipped to the client size of the grid window.
9859 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
9860 const wxGridCellCoords
&bottomRight
)
9862 wxRect
rect( wxGridNoCellRect
);
9865 cellRect
= CellToRect( topLeft
);
9866 if ( cellRect
!= wxGridNoCellRect
)
9872 rect
= wxRect( 0, 0, 0, 0 );
9875 cellRect
= CellToRect( bottomRight
);
9876 if ( cellRect
!= wxGridNoCellRect
)
9882 return wxGridNoCellRect
;
9886 int left
= rect
.GetLeft();
9887 int top
= rect
.GetTop();
9888 int right
= rect
.GetRight();
9889 int bottom
= rect
.GetBottom();
9891 int leftCol
= topLeft
.GetCol();
9892 int topRow
= topLeft
.GetRow();
9893 int rightCol
= bottomRight
.GetCol();
9894 int bottomRow
= bottomRight
.GetRow();
9917 for ( j
= topRow
; j
<= bottomRow
; j
++ )
9919 for ( i
= leftCol
; i
<= rightCol
; i
++ )
9921 if ((j
==topRow
) || (j
==bottomRow
) || (i
==leftCol
) || (i
==rightCol
))
9923 cellRect
= CellToRect( j
, i
);
9925 if (cellRect
.x
< left
)
9927 if (cellRect
.y
< top
)
9929 if (cellRect
.x
+ cellRect
.width
> right
)
9930 right
= cellRect
.x
+ cellRect
.width
;
9931 if (cellRect
.y
+ cellRect
.height
> bottom
)
9932 bottom
= cellRect
.y
+ cellRect
.height
;
9934 else i
= rightCol
; // jump over inner cells.
9938 // convert to scrolled coords
9940 CalcScrolledPosition( left
, top
, &left
, &top
);
9941 CalcScrolledPosition( right
, bottom
, &right
, &bottom
);
9944 m_gridWin
->GetClientSize( &cw
, &ch
);
9946 if (right
< 0 || bottom
< 0 || left
> cw
|| top
> ch
)
9947 return wxRect( 0, 0, 0, 0);
9949 rect
.SetLeft( wxMax(0, left
) );
9950 rect
.SetTop( wxMax(0, top
) );
9951 rect
.SetRight( wxMin(cw
, right
) );
9952 rect
.SetBottom( wxMin(ch
, bottom
) );
9960 // ------ Grid event classes
9963 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxNotifyEvent
)
9965 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
9966 int row
, int col
, int x
, int y
, bool sel
,
9967 bool control
, bool shift
, bool alt
, bool meta
)
9968 : wxNotifyEvent( type
, id
)
9975 m_control
= control
;
9980 SetEventObject(obj
);
9984 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxNotifyEvent
)
9986 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
9987 int rowOrCol
, int x
, int y
,
9988 bool control
, bool shift
, bool alt
, bool meta
)
9989 : wxNotifyEvent( type
, id
)
9991 m_rowOrCol
= rowOrCol
;
9994 m_control
= control
;
9999 SetEventObject(obj
);
10003 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxNotifyEvent
)
10005 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
10006 const wxGridCellCoords
& topLeft
,
10007 const wxGridCellCoords
& bottomRight
,
10008 bool sel
, bool control
,
10009 bool shift
, bool alt
, bool meta
)
10010 : wxNotifyEvent( type
, id
)
10012 m_topLeft
= topLeft
;
10013 m_bottomRight
= bottomRight
;
10015 m_control
= control
;
10020 SetEventObject(obj
);
10024 IMPLEMENT_DYNAMIC_CLASS(wxGridEditorCreatedEvent
, wxCommandEvent
)
10026 wxGridEditorCreatedEvent::wxGridEditorCreatedEvent(int id
, wxEventType type
,
10027 wxObject
* obj
, int row
,
10028 int col
, wxControl
* ctrl
)
10029 : wxCommandEvent(type
, id
)
10031 SetEventObject(obj
);
10037 #endif // wxUSE_GRID