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 // set max length allowed in the textctrl, if the parameter was set
581 ((wxTextCtrl
*)m_control
)->SetMaxLength(m_maxChars
);
584 wxGridCellEditor::Create(parent
, id
, evtHandler
);
587 void wxGridCellTextEditor::PaintBackground(const wxRect
& WXUNUSED(rectCell
),
588 wxGridCellAttr
* WXUNUSED(attr
))
590 // as we fill the entire client area, don't do anything here to minimize
594 void wxGridCellTextEditor::SetSize(const wxRect
& rectOrig
)
596 wxRect
rect(rectOrig
);
598 // Make the edit control large enough to allow for internal
601 // TODO: remove this if the text ctrl sizing is improved esp. for
604 #if defined(__WXGTK__)
613 int extra_x
= ( rect
.x
> 2 )? 2 : 1;
615 // MB: treat MSW separately here otherwise the caret doesn't show
616 // when the editor is in the first row.
617 #if defined(__WXMSW__)
620 int extra_y
= ( rect
.y
> 2 )? 2 : 1;
623 #if defined(__WXMOTIF__)
627 rect
.SetLeft( wxMax(0, rect
.x
- extra_x
) );
628 rect
.SetTop( wxMax(0, rect
.y
- extra_y
) );
629 rect
.SetRight( rect
.GetRight() + 2*extra_x
);
630 rect
.SetBottom( rect
.GetBottom() + 2*extra_y
);
633 wxGridCellEditor::SetSize(rect
);
636 void wxGridCellTextEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
638 wxASSERT_MSG(m_control
,
639 wxT("The wxGridCellEditor must be Created first!"));
641 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
643 DoBeginEdit(m_startValue
);
646 void wxGridCellTextEditor::DoBeginEdit(const wxString
& startValue
)
648 Text()->SetValue(startValue
);
649 Text()->SetInsertionPointEnd();
650 Text()->SetSelection(-1,-1);
654 bool wxGridCellTextEditor::EndEdit(int row
, int col
,
657 wxASSERT_MSG(m_control
,
658 wxT("The wxGridCellEditor must be Created first!"));
660 bool changed
= FALSE
;
661 wxString value
= Text()->GetValue();
662 if (value
!= m_startValue
)
666 grid
->GetTable()->SetValue(row
, col
, value
);
668 m_startValue
= wxEmptyString
;
669 Text()->SetValue(m_startValue
);
675 void wxGridCellTextEditor::Reset()
677 wxASSERT_MSG(m_control
,
678 wxT("The wxGridCellEditor must be Created first!"));
680 DoReset(m_startValue
);
683 void wxGridCellTextEditor::DoReset(const wxString
& startValue
)
685 Text()->SetValue(startValue
);
686 Text()->SetInsertionPointEnd();
689 bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent
& event
)
691 if ( wxGridCellEditor::IsAcceptedKey(event
) )
693 int keycode
= event
.GetKeyCode();
707 case WXK_NUMPAD_MULTIPLY
:
711 case WXK_NUMPAD_SUBTRACT
:
713 case WXK_NUMPAD_DECIMAL
:
715 case WXK_NUMPAD_DIVIDE
:
719 // accept 8 bit chars too if isprint() agrees
720 if ( (keycode
< 255) && (isprint(keycode
)) )
728 void wxGridCellTextEditor::StartingKey(wxKeyEvent
& event
)
730 if ( !Text()->EmulateKeyPress(event
) )
736 void wxGridCellTextEditor::HandleReturn( wxKeyEvent
&
737 WXUNUSED_GTK(WXUNUSED_MOTIF(event
)) )
739 #if defined(__WXMOTIF__) || defined(__WXGTK__)
740 // wxMotif needs a little extra help...
741 size_t pos
= (size_t)( Text()->GetInsertionPoint() );
742 wxString
s( Text()->GetValue() );
743 s
= s
.Left(pos
) + wxT("\n") + s
.Mid(pos
);
745 Text()->SetInsertionPoint( pos
);
747 // the other ports can handle a Return key press
753 void wxGridCellTextEditor::SetParameters(const wxString
& params
)
763 if ( !params
.ToLong(&tmp
) )
765 wxLogDebug(_T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params
.c_str());
769 m_maxChars
= (size_t)tmp
;
774 // return the value in the text control
775 wxString
wxGridCellTextEditor::GetValue() const
777 return Text()->GetValue();
780 // ----------------------------------------------------------------------------
781 // wxGridCellNumberEditor
782 // ----------------------------------------------------------------------------
784 wxGridCellNumberEditor::wxGridCellNumberEditor(int min
, int max
)
790 void wxGridCellNumberEditor::Create(wxWindow
* parent
,
792 wxEvtHandler
* evtHandler
)
796 // create a spin ctrl
797 m_control
= new wxSpinCtrl(parent
, -1, wxEmptyString
,
798 wxDefaultPosition
, wxDefaultSize
,
802 wxGridCellEditor::Create(parent
, id
, evtHandler
);
806 // just a text control
807 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
810 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
811 #endif // wxUSE_VALIDATORS
815 void wxGridCellNumberEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
817 // first get the value
818 wxGridTableBase
*table
= grid
->GetTable();
819 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
821 m_valueOld
= table
->GetValueAsLong(row
, col
);
826 wxString sValue
= table
->GetValue(row
, col
);
827 if (! sValue
.ToLong(&m_valueOld
) && ! sValue
.IsEmpty())
829 wxFAIL_MSG( _T("this cell doesn't have numeric value") );
836 Spin()->SetValue((int)m_valueOld
);
841 DoBeginEdit(GetString());
845 bool wxGridCellNumberEditor::EndEdit(int row
, int col
,
854 value
= Spin()->GetValue();
855 changed
= value
!= m_valueOld
;
857 text
= wxString::Format(wxT("%ld"), value
);
861 text
= Text()->GetValue();
862 changed
= (text
.IsEmpty() || text
.ToLong(&value
)) && (value
!= m_valueOld
);
867 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_NUMBER
))
868 grid
->GetTable()->SetValueAsLong(row
, col
, value
);
870 grid
->GetTable()->SetValue(row
, col
, text
);
876 void wxGridCellNumberEditor::Reset()
880 Spin()->SetValue((int)m_valueOld
);
884 DoReset(GetString());
888 bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent
& event
)
890 if ( wxGridCellEditor::IsAcceptedKey(event
) )
892 int keycode
= event
.GetKeyCode();
908 case WXK_NUMPAD_SUBTRACT
:
914 if ( (keycode
< 128) && isdigit(keycode
) )
922 void wxGridCellNumberEditor::StartingKey(wxKeyEvent
& event
)
926 int keycode
= event
.GetKeyCode();
927 if ( isdigit(keycode
) || keycode
== '+' || keycode
== '-'
928 || keycode
== WXK_NUMPAD0
929 || keycode
== WXK_NUMPAD1
930 || keycode
== WXK_NUMPAD2
931 || keycode
== WXK_NUMPAD3
932 || keycode
== WXK_NUMPAD4
933 || keycode
== WXK_NUMPAD5
934 || keycode
== WXK_NUMPAD6
935 || keycode
== WXK_NUMPAD7
936 || keycode
== WXK_NUMPAD8
937 || keycode
== WXK_NUMPAD9
938 || keycode
== WXK_ADD
939 || keycode
== WXK_NUMPAD_ADD
940 || keycode
== WXK_SUBTRACT
941 || keycode
== WXK_NUMPAD_SUBTRACT
)
943 wxGridCellTextEditor::StartingKey(event
);
953 void wxGridCellNumberEditor::SetParameters(const wxString
& params
)
964 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
968 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
972 // skip the error message below
977 wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string '%s' ignored"), params
.c_str());
981 // return the value in the spin control if it is there (the text control otherwise)
982 wxString
wxGridCellNumberEditor::GetValue() const
988 long value
= Spin()->GetValue();
989 s
.Printf(wxT("%ld"), value
);
993 s
= Text()->GetValue();
998 // ----------------------------------------------------------------------------
999 // wxGridCellFloatEditor
1000 // ----------------------------------------------------------------------------
1002 wxGridCellFloatEditor::wxGridCellFloatEditor(int width
, int precision
)
1005 m_precision
= precision
;
1008 void wxGridCellFloatEditor::Create(wxWindow
* parent
,
1010 wxEvtHandler
* evtHandler
)
1012 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
1014 #if wxUSE_VALIDATORS
1015 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
1016 #endif // wxUSE_VALIDATORS
1019 void wxGridCellFloatEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1021 // first get the value
1022 wxGridTableBase
*table
= grid
->GetTable();
1023 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
1025 m_valueOld
= table
->GetValueAsDouble(row
, col
);
1030 wxString sValue
= table
->GetValue(row
, col
);
1031 if (! sValue
.ToDouble(&m_valueOld
) && ! sValue
.IsEmpty())
1033 wxFAIL_MSG( _T("this cell doesn't have float value") );
1038 DoBeginEdit(GetString());
1041 bool wxGridCellFloatEditor::EndEdit(int row
, int col
,
1045 wxString
text(Text()->GetValue());
1047 if ( (text
.IsEmpty() || text
.ToDouble(&value
)) && (value
!= m_valueOld
) )
1049 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_FLOAT
))
1050 grid
->GetTable()->SetValueAsDouble(row
, col
, value
);
1052 grid
->GetTable()->SetValue(row
, col
, text
);
1059 void wxGridCellFloatEditor::Reset()
1061 DoReset(GetString());
1064 void wxGridCellFloatEditor::StartingKey(wxKeyEvent
& event
)
1066 int keycode
= event
.GetKeyCode();
1067 if ( isdigit(keycode
) || keycode
== '+' || keycode
== '-' || keycode
== '.'
1068 || keycode
== WXK_NUMPAD0
1069 || keycode
== WXK_NUMPAD1
1070 || keycode
== WXK_NUMPAD2
1071 || keycode
== WXK_NUMPAD3
1072 || keycode
== WXK_NUMPAD4
1073 || keycode
== WXK_NUMPAD5
1074 || keycode
== WXK_NUMPAD6
1075 || keycode
== WXK_NUMPAD7
1076 || keycode
== WXK_NUMPAD8
1077 || keycode
== WXK_NUMPAD9
1078 || keycode
== WXK_ADD
1079 || keycode
== WXK_NUMPAD_ADD
1080 || keycode
== WXK_SUBTRACT
1081 || keycode
== WXK_NUMPAD_SUBTRACT
)
1083 wxGridCellTextEditor::StartingKey(event
);
1085 // skip Skip() below
1092 void wxGridCellFloatEditor::SetParameters(const wxString
& params
)
1103 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
1107 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
1109 m_precision
= (int)tmp
;
1111 // skip the error message below
1116 wxLogDebug(_T("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params
.c_str());
1120 wxString
wxGridCellFloatEditor::GetString() const
1123 if ( m_width
== -1 )
1125 // default width/precision
1128 else if ( m_precision
== -1 )
1130 // default precision
1131 fmt
.Printf(_T("%%%d.f"), m_width
);
1135 fmt
.Printf(_T("%%%d.%df"), m_width
, m_precision
);
1138 return wxString::Format(fmt
, m_valueOld
);
1141 bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent
& event
)
1143 if ( wxGridCellEditor::IsAcceptedKey(event
) )
1145 int keycode
= event
.GetKeyCode();
1159 case WXK_NUMPAD_ADD
:
1161 case WXK_NUMPAD_SUBTRACT
:
1163 case WXK_NUMPAD_DECIMAL
:
1167 // additionally accept 'e' as in '1e+6'
1168 if ( (keycode
< 128) &&
1169 (isdigit(keycode
) || tolower(keycode
) == 'e') )
1177 #endif // wxUSE_TEXTCTRL
1181 // ----------------------------------------------------------------------------
1182 // wxGridCellBoolEditor
1183 // ----------------------------------------------------------------------------
1185 void wxGridCellBoolEditor::Create(wxWindow
* parent
,
1187 wxEvtHandler
* evtHandler
)
1189 m_control
= new wxCheckBox(parent
, id
, wxEmptyString
,
1190 wxDefaultPosition
, wxDefaultSize
,
1193 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1196 void wxGridCellBoolEditor::SetSize(const wxRect
& r
)
1198 bool resize
= FALSE
;
1199 wxSize size
= m_control
->GetSize();
1200 wxCoord minSize
= wxMin(r
.width
, r
.height
);
1202 // check if the checkbox is not too big/small for this cell
1203 wxSize sizeBest
= m_control
->GetBestSize();
1204 if ( !(size
== sizeBest
) )
1206 // reset to default size if it had been made smaller
1212 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
1214 // leave 1 pixel margin
1215 size
.x
= size
.y
= minSize
- 2;
1222 m_control
->SetSize(size
);
1225 // position it in the centre of the rectangle (TODO: support alignment?)
1227 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1228 // the checkbox without label still has some space to the right in wxGTK,
1229 // so shift it to the right
1231 #elif defined(__WXMSW__)
1232 // here too, but in other way
1237 int hAlign
= wxALIGN_CENTRE
;
1238 int vAlign
= wxALIGN_CENTRE
;
1240 GetCellAttr()->GetAlignment(& hAlign
, & vAlign
);
1243 if (hAlign
== wxALIGN_LEFT
)
1249 y
= r
.y
+ r
.height
/2 - size
.y
/2;
1251 else if (hAlign
== wxALIGN_RIGHT
)
1253 x
= r
.x
+ r
.width
- size
.x
- 2;
1254 y
= r
.y
+ r
.height
/2 - size
.y
/2;
1256 else if (hAlign
== wxALIGN_CENTRE
)
1258 x
= r
.x
+ r
.width
/2 - size
.x
/2;
1259 y
= r
.y
+ r
.height
/2 - size
.y
/2;
1262 m_control
->Move(x
, y
);
1265 void wxGridCellBoolEditor::Show(bool show
, wxGridCellAttr
*attr
)
1267 m_control
->Show(show
);
1271 wxColour colBg
= attr
? attr
->GetBackgroundColour() : *wxLIGHT_GREY
;
1272 CBox()->SetBackgroundColour(colBg
);
1276 void wxGridCellBoolEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1278 wxASSERT_MSG(m_control
,
1279 wxT("The wxGridCellEditor must be Created first!"));
1281 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
1282 m_startValue
= grid
->GetTable()->GetValueAsBool(row
, col
);
1285 wxString
cellval( grid
->GetTable()->GetValue(row
, col
) );
1286 m_startValue
= !( !cellval
|| (cellval
== wxT("0")) );
1288 CBox()->SetValue(m_startValue
);
1292 bool wxGridCellBoolEditor::EndEdit(int row
, int col
,
1295 wxASSERT_MSG(m_control
,
1296 wxT("The wxGridCellEditor must be Created first!"));
1298 bool changed
= FALSE
;
1299 bool value
= CBox()->GetValue();
1300 if ( value
!= m_startValue
)
1305 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
1306 grid
->GetTable()->SetValueAsBool(row
, col
, value
);
1308 grid
->GetTable()->SetValue(row
, col
, value
? _T("1") : wxEmptyString
);
1314 void wxGridCellBoolEditor::Reset()
1316 wxASSERT_MSG(m_control
,
1317 wxT("The wxGridCellEditor must be Created first!"));
1319 CBox()->SetValue(m_startValue
);
1322 void wxGridCellBoolEditor::StartingClick()
1324 CBox()->SetValue(!CBox()->GetValue());
1327 bool wxGridCellBoolEditor::IsAcceptedKey(wxKeyEvent
& event
)
1329 if ( wxGridCellEditor::IsAcceptedKey(event
) )
1331 int keycode
= event
.GetKeyCode();
1335 case WXK_NUMPAD_MULTIPLY
:
1337 case WXK_NUMPAD_ADD
:
1339 case WXK_NUMPAD_SUBTRACT
:
1350 // return the value as "1" for true and the empty string for false
1351 wxString
wxGridCellBoolEditor::GetValue() const
1353 bool bSet
= CBox()->GetValue();
1354 return bSet
? _T("1") : wxEmptyString
;
1357 #endif // wxUSE_CHECKBOX
1361 // ----------------------------------------------------------------------------
1362 // wxGridCellChoiceEditor
1363 // ----------------------------------------------------------------------------
1365 wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count
,
1366 const wxString choices
[],
1368 : m_allowOthers(allowOthers
)
1372 m_choices
.Alloc(count
);
1373 for ( size_t n
= 0; n
< count
; n
++ )
1375 m_choices
.Add(choices
[n
]);
1380 wxGridCellEditor
*wxGridCellChoiceEditor::Clone() const
1382 wxGridCellChoiceEditor
*editor
= new wxGridCellChoiceEditor
;
1383 editor
->m_allowOthers
= m_allowOthers
;
1384 editor
->m_choices
= m_choices
;
1389 void wxGridCellChoiceEditor::Create(wxWindow
* parent
,
1391 wxEvtHandler
* evtHandler
)
1393 size_t count
= m_choices
.GetCount();
1394 wxString
*choices
= new wxString
[count
];
1395 for ( size_t n
= 0; n
< count
; n
++ )
1397 choices
[n
] = m_choices
[n
];
1400 m_control
= new wxComboBox(parent
, id
, wxEmptyString
,
1401 wxDefaultPosition
, wxDefaultSize
,
1403 m_allowOthers
? 0 : wxCB_READONLY
);
1407 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1410 void wxGridCellChoiceEditor::PaintBackground(const wxRect
& rectCell
,
1411 wxGridCellAttr
* attr
)
1413 // as we fill the entire client area, don't do anything here to minimize
1416 // TODO: It doesn't actually fill the client area since the height of a
1417 // combo always defaults to the standard... Until someone has time to
1418 // figure out the right rectangle to paint, just do it the normal way...
1419 wxGridCellEditor::PaintBackground(rectCell
, attr
);
1422 void wxGridCellChoiceEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1424 wxASSERT_MSG(m_control
,
1425 wxT("The wxGridCellEditor must be Created first!"));
1427 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
1430 Combo()->SetValue(m_startValue
);
1433 // find the right position, or default to the first if not found
1434 int pos
= Combo()->FindString(m_startValue
);
1437 Combo()->SetSelection(pos
);
1439 Combo()->SetInsertionPointEnd();
1440 Combo()->SetFocus();
1443 bool wxGridCellChoiceEditor::EndEdit(int row
, int col
,
1446 wxString value
= Combo()->GetValue();
1447 bool changed
= value
!= m_startValue
;
1450 grid
->GetTable()->SetValue(row
, col
, value
);
1452 m_startValue
= wxEmptyString
;
1454 Combo()->SetValue(m_startValue
);
1456 Combo()->SetSelection(0);
1461 void wxGridCellChoiceEditor::Reset()
1463 Combo()->SetValue(m_startValue
);
1464 Combo()->SetInsertionPointEnd();
1467 void wxGridCellChoiceEditor::SetParameters(const wxString
& params
)
1477 wxStringTokenizer
tk(params
, _T(','));
1478 while ( tk
.HasMoreTokens() )
1480 m_choices
.Add(tk
.GetNextToken());
1484 // return the value in the text control
1485 wxString
wxGridCellChoiceEditor::GetValue() const
1487 return Combo()->GetValue();
1490 #endif // wxUSE_COMBOBOX
1492 // ----------------------------------------------------------------------------
1493 // wxGridCellEditorEvtHandler
1494 // ----------------------------------------------------------------------------
1496 void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent
& event
)
1498 switch ( event
.GetKeyCode() )
1502 m_grid
->DisableCellEditControl();
1506 m_grid
->GetEventHandler()->ProcessEvent( event
);
1510 case WXK_NUMPAD_ENTER
:
1511 if (!m_grid
->GetEventHandler()->ProcessEvent(event
))
1512 m_editor
->HandleReturn(event
);
1521 void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent
& event
)
1523 switch ( event
.GetKeyCode() )
1528 case WXK_NUMPAD_ENTER
:
1536 // ----------------------------------------------------------------------------
1537 // wxGridCellWorker is an (almost) empty common base class for
1538 // wxGridCellRenderer and wxGridCellEditor managing ref counting
1539 // ----------------------------------------------------------------------------
1541 void wxGridCellWorker::SetParameters(const wxString
& WXUNUSED(params
))
1546 wxGridCellWorker::~wxGridCellWorker()
1550 // ============================================================================
1552 // ============================================================================
1554 // ----------------------------------------------------------------------------
1555 // wxGridCellRenderer
1556 // ----------------------------------------------------------------------------
1558 void wxGridCellRenderer::Draw(wxGrid
& grid
,
1559 wxGridCellAttr
& attr
,
1562 int WXUNUSED(row
), int WXUNUSED(col
),
1565 dc
.SetBackgroundMode( wxSOLID
);
1567 // grey out fields if the grid is disabled
1568 if( grid
.IsEnabled() )
1572 dc
.SetBrush( wxBrush(grid
.GetSelectionBackground(), wxSOLID
) );
1576 dc
.SetBrush( wxBrush(attr
.GetBackgroundColour(), wxSOLID
) );
1581 dc
.SetBrush(wxBrush(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE
), wxSOLID
));
1584 dc
.SetPen( *wxTRANSPARENT_PEN
);
1585 dc
.DrawRectangle(rect
);
1588 // ----------------------------------------------------------------------------
1589 // wxGridCellStringRenderer
1590 // ----------------------------------------------------------------------------
1592 void wxGridCellStringRenderer::SetTextColoursAndFont(wxGrid
& grid
,
1593 wxGridCellAttr
& attr
,
1597 dc
.SetBackgroundMode( wxTRANSPARENT
);
1599 // TODO some special colours for attr.IsReadOnly() case?
1601 // different coloured text when the grid is disabled
1602 if( grid
.IsEnabled() )
1606 dc
.SetTextBackground( grid
.GetSelectionBackground() );
1607 dc
.SetTextForeground( grid
.GetSelectionForeground() );
1611 dc
.SetTextBackground( attr
.GetBackgroundColour() );
1612 dc
.SetTextForeground( attr
.GetTextColour() );
1617 dc
.SetTextBackground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE
));
1618 dc
.SetTextForeground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_GRAYTEXT
));
1621 dc
.SetFont( attr
.GetFont() );
1624 wxSize
wxGridCellStringRenderer::DoGetBestSize(wxGridCellAttr
& attr
,
1626 const wxString
& text
)
1628 wxCoord x
= 0, y
= 0, max_x
= 0;
1629 dc
.SetFont(attr
.GetFont());
1630 wxStringTokenizer
tk(text
, _T('\n'));
1631 while ( tk
.HasMoreTokens() )
1633 dc
.GetTextExtent(tk
.GetNextToken(), &x
, &y
);
1634 max_x
= wxMax(max_x
, x
);
1637 y
*= 1 + text
.Freq(wxT('\n')); // multiply by the number of lines.
1639 return wxSize(max_x
, y
);
1642 wxSize
wxGridCellStringRenderer::GetBestSize(wxGrid
& grid
,
1643 wxGridCellAttr
& attr
,
1647 return DoGetBestSize(attr
, dc
, grid
.GetCellValue(row
, col
));
1650 void wxGridCellStringRenderer::Draw(wxGrid
& grid
,
1651 wxGridCellAttr
& attr
,
1653 const wxRect
& rectCell
,
1657 wxRect rect
= rectCell
;
1660 // erase only this cells background, overflow cells should have been erased
1661 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1664 attr
.GetAlignment(&hAlign
, &vAlign
);
1666 int overflowCols
= 0;
1668 if (attr
.GetOverflow())
1670 int cols
= grid
.GetNumberCols();
1671 int best_width
= GetBestSize(grid
,attr
,dc
,row
,col
).GetWidth();
1672 int cell_rows
, cell_cols
;
1673 attr
.GetSize( &cell_rows
, &cell_cols
); // shouldn't get here if <=0
1674 if ((best_width
> rectCell
.width
) && (col
< cols
) && grid
.GetTable())
1676 int i
, c_cols
, c_rows
;
1677 for (i
= col
+cell_cols
; i
< cols
; i
++)
1679 bool is_empty
= TRUE
;
1680 for (int j
=row
; j
<row
+cell_rows
; j
++)
1682 // check w/ anchor cell for multicell block
1683 grid
.GetCellSize(j
, i
, &c_rows
, &c_cols
);
1684 if (c_rows
> 0) c_rows
= 0;
1685 if (!grid
.GetTable()->IsEmptyCell(j
+c_rows
, i
))
1692 rect
.width
+= grid
.GetColSize(i
);
1698 if (rect
.width
>= best_width
) break;
1700 overflowCols
= i
- col
- cell_cols
+ 1;
1701 if (overflowCols
>= cols
) overflowCols
= cols
- 1;
1704 if (overflowCols
> 0) // redraw overflow cells w/ proper hilight
1706 hAlign
= wxALIGN_LEFT
; // if oveflowed then it's left aligned
1708 clip
.x
+= rectCell
.width
;
1709 // draw each overflow cell individually
1710 int col_end
= col
+cell_cols
+overflowCols
;
1711 if (col_end
>= grid
.GetNumberCols())
1712 col_end
= grid
.GetNumberCols() - 1;
1713 for (int i
= col
+cell_cols
; i
<= col_end
; i
++)
1715 clip
.width
= grid
.GetColSize(i
) - 1;
1716 dc
.DestroyClippingRegion();
1717 dc
.SetClippingRegion(clip
);
1719 SetTextColoursAndFont(grid
, attr
, dc
,
1720 grid
.IsInSelection(row
,i
));
1722 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
1723 rect
, hAlign
, vAlign
);
1724 clip
.x
+= grid
.GetColSize(i
) - 1;
1730 dc
.DestroyClippingRegion();
1734 // now we only have to draw the text
1735 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1737 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
1738 rect
, hAlign
, vAlign
);
1741 // ----------------------------------------------------------------------------
1742 // wxGridCellNumberRenderer
1743 // ----------------------------------------------------------------------------
1745 wxString
wxGridCellNumberRenderer::GetString(wxGrid
& grid
, int row
, int col
)
1747 wxGridTableBase
*table
= grid
.GetTable();
1749 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
1751 text
.Printf(_T("%ld"), table
->GetValueAsLong(row
, col
));
1755 text
= table
->GetValue(row
, col
);
1761 void wxGridCellNumberRenderer::Draw(wxGrid
& grid
,
1762 wxGridCellAttr
& attr
,
1764 const wxRect
& rectCell
,
1768 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1770 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1772 // draw the text right aligned by default
1774 attr
.GetAlignment(&hAlign
, &vAlign
);
1775 hAlign
= wxALIGN_RIGHT
;
1777 wxRect rect
= rectCell
;
1780 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1783 wxSize
wxGridCellNumberRenderer::GetBestSize(wxGrid
& grid
,
1784 wxGridCellAttr
& attr
,
1788 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1791 // ----------------------------------------------------------------------------
1792 // wxGridCellFloatRenderer
1793 // ----------------------------------------------------------------------------
1795 wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width
, int precision
)
1798 SetPrecision(precision
);
1801 wxGridCellRenderer
*wxGridCellFloatRenderer::Clone() const
1803 wxGridCellFloatRenderer
*renderer
= new wxGridCellFloatRenderer
;
1804 renderer
->m_width
= m_width
;
1805 renderer
->m_precision
= m_precision
;
1806 renderer
->m_format
= m_format
;
1811 wxString
wxGridCellFloatRenderer::GetString(wxGrid
& grid
, int row
, int col
)
1813 wxGridTableBase
*table
= grid
.GetTable();
1818 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
1820 val
= table
->GetValueAsDouble(row
, col
);
1825 text
= table
->GetValue(row
, col
);
1826 hasDouble
= text
.ToDouble(&val
);
1833 if ( m_width
== -1 )
1835 if ( m_precision
== -1 )
1837 // default width/precision
1838 m_format
= _T("%f");
1842 m_format
.Printf(_T("%%.%df"), m_precision
);
1845 else if ( m_precision
== -1 )
1847 // default precision
1848 m_format
.Printf(_T("%%%d.f"), m_width
);
1852 m_format
.Printf(_T("%%%d.%df"), m_width
, m_precision
);
1856 text
.Printf(m_format
, val
);
1859 //else: text already contains the string
1864 void wxGridCellFloatRenderer::Draw(wxGrid
& grid
,
1865 wxGridCellAttr
& attr
,
1867 const wxRect
& rectCell
,
1871 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1873 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1875 // draw the text right aligned by default
1877 attr
.GetAlignment(&hAlign
, &vAlign
);
1878 hAlign
= wxALIGN_RIGHT
;
1880 wxRect rect
= rectCell
;
1883 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1886 wxSize
wxGridCellFloatRenderer::GetBestSize(wxGrid
& grid
,
1887 wxGridCellAttr
& attr
,
1891 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1894 void wxGridCellFloatRenderer::SetParameters(const wxString
& params
)
1898 // reset to defaults
1904 wxString tmp
= params
.BeforeFirst(_T(','));
1908 if ( tmp
.ToLong(&width
) )
1910 SetWidth((int)width
);
1914 wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params
.c_str());
1918 tmp
= params
.AfterFirst(_T(','));
1922 if ( tmp
.ToLong(&precision
) )
1924 SetPrecision((int)precision
);
1928 wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params
.c_str());
1936 // ----------------------------------------------------------------------------
1937 // wxGridCellBoolRenderer
1938 // ----------------------------------------------------------------------------
1940 wxSize
wxGridCellBoolRenderer::ms_sizeCheckMark
;
1942 // FIXME these checkbox size calculations are really ugly...
1944 // between checkmark and box
1945 static const wxCoord wxGRID_CHECKMARK_MARGIN
= 2;
1947 wxSize
wxGridCellBoolRenderer::GetBestSize(wxGrid
& grid
,
1948 wxGridCellAttr
& WXUNUSED(attr
),
1953 // compute it only once (no locks for MT safeness in GUI thread...)
1954 if ( !ms_sizeCheckMark
.x
)
1956 // get checkbox size
1957 wxCoord checkSize
= 0;
1958 wxCheckBox
*checkbox
= new wxCheckBox(&grid
, -1, wxEmptyString
);
1959 wxSize size
= checkbox
->GetBestSize();
1960 checkSize
= size
.y
+ 2*wxGRID_CHECKMARK_MARGIN
;
1962 // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result
1963 #if defined(__WXGTK__) || defined(__WXMOTIF__)
1964 checkSize
-= size
.y
/ 2;
1969 ms_sizeCheckMark
.x
= ms_sizeCheckMark
.y
= checkSize
;
1972 return ms_sizeCheckMark
;
1975 void wxGridCellBoolRenderer::Draw(wxGrid
& grid
,
1976 wxGridCellAttr
& attr
,
1982 wxGridCellRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
1984 // draw a check mark in the centre (ignoring alignment - TODO)
1985 wxSize size
= GetBestSize(grid
, attr
, dc
, row
, col
);
1987 // don't draw outside the cell
1988 wxCoord minSize
= wxMin(rect
.width
, rect
.height
);
1989 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
1991 // and even leave (at least) 1 pixel margin
1992 size
.x
= size
.y
= minSize
- 2;
1995 // draw a border around checkmark
1997 attr
.GetAlignment(& hAlign
, &vAlign
);
2000 if (hAlign
== wxALIGN_CENTRE
)
2002 rectBorder
.x
= rect
.x
+ rect
.width
/2 - size
.x
/2;
2003 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
2004 rectBorder
.width
= size
.x
;
2005 rectBorder
.height
= size
.y
;
2007 else if (hAlign
== wxALIGN_LEFT
)
2009 rectBorder
.x
= rect
.x
+ 2;
2010 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
2011 rectBorder
.width
= size
.x
;
2012 rectBorder
.height
= size
.y
;
2014 else if (hAlign
== wxALIGN_RIGHT
)
2016 rectBorder
.x
= rect
.x
+ rect
.width
- size
.x
- 2;
2017 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
2018 rectBorder
.width
= size
.x
;
2019 rectBorder
.height
= size
.y
;
2023 if ( grid
.GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
) )
2024 value
= grid
.GetTable()->GetValueAsBool(row
, col
);
2027 wxString
cellval( grid
.GetTable()->GetValue(row
, col
) );
2028 value
= !( !cellval
|| (cellval
== wxT("0")) );
2033 wxRect rectMark
= rectBorder
;
2035 // MSW DrawCheckMark() is weird (and should probably be changed...)
2036 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
/2);
2040 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
);
2043 dc
.SetTextForeground(attr
.GetTextColour());
2044 dc
.DrawCheckMark(rectMark
);
2047 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2048 dc
.SetPen(wxPen(attr
.GetTextColour(), 1, wxSOLID
));
2049 dc
.DrawRectangle(rectBorder
);
2052 // ----------------------------------------------------------------------------
2054 // ----------------------------------------------------------------------------
2056 void wxGridCellAttr::Init(wxGridCellAttr
*attrDefault
)
2060 m_isReadOnly
= Unset
;
2065 m_attrkind
= wxGridCellAttr::Cell
;
2067 m_sizeRows
= m_sizeCols
= 1;
2068 m_overflow
= UnsetOverflow
;
2070 SetDefAttr(attrDefault
);
2073 wxGridCellAttr
*wxGridCellAttr::Clone() const
2075 wxGridCellAttr
*attr
= new wxGridCellAttr(m_defGridAttr
);
2077 if ( HasTextColour() )
2078 attr
->SetTextColour(GetTextColour());
2079 if ( HasBackgroundColour() )
2080 attr
->SetBackgroundColour(GetBackgroundColour());
2082 attr
->SetFont(GetFont());
2083 if ( HasAlignment() )
2084 attr
->SetAlignment(m_hAlign
, m_vAlign
);
2086 attr
->SetSize( m_sizeRows
, m_sizeCols
);
2090 attr
->SetRenderer(m_renderer
);
2091 m_renderer
->IncRef();
2095 attr
->SetEditor(m_editor
);
2100 attr
->SetReadOnly();
2102 attr
->SetKind( m_attrkind
);
2107 void wxGridCellAttr::MergeWith(wxGridCellAttr
*mergefrom
)
2109 if ( !HasTextColour() && mergefrom
->HasTextColour() )
2110 SetTextColour(mergefrom
->GetTextColour());
2111 if ( !HasBackgroundColour() && mergefrom
->HasBackgroundColour() )
2112 SetBackgroundColour(mergefrom
->GetBackgroundColour());
2113 if ( !HasFont() && mergefrom
->HasFont() )
2114 SetFont(mergefrom
->GetFont());
2115 if ( !HasAlignment() && mergefrom
->HasAlignment() ){
2117 mergefrom
->GetAlignment( &hAlign
, &vAlign
);
2118 SetAlignment(hAlign
, vAlign
);
2121 mergefrom
->GetSize( &m_sizeRows
, &m_sizeCols
);
2123 // Directly access member functions as GetRender/Editor don't just return
2124 // m_renderer/m_editor
2126 // Maybe add support for merge of Render and Editor?
2127 if (!HasRenderer() && mergefrom
->HasRenderer() )
2129 m_renderer
= mergefrom
->m_renderer
;
2130 m_renderer
->IncRef();
2132 if ( !HasEditor() && mergefrom
->HasEditor() )
2134 m_editor
= mergefrom
->m_editor
;
2137 if ( !HasReadWriteMode() && mergefrom
->HasReadWriteMode() )
2138 SetReadOnly(mergefrom
->IsReadOnly());
2140 if (!HasOverflowMode() && mergefrom
->HasOverflowMode() )
2141 SetOverflow(mergefrom
->GetOverflow());
2143 SetDefAttr(mergefrom
->m_defGridAttr
);
2146 void wxGridCellAttr::SetSize(int num_rows
, int num_cols
)
2148 // The size of a cell is normally 1,1
2150 // If this cell is larger (2,2) then this is the top left cell
2151 // the other cells that will be covered (lower right cells) must be
2152 // set to negative or zero values such that
2153 // row + num_rows of the covered cell points to the larger cell (this cell)
2154 // same goes for the col + num_cols.
2156 // Size of 0,0 is NOT valid, neither is <=0 and any positive value
2158 wxASSERT_MSG( (!((num_rows
>0)&&(num_cols
<=0)) ||
2159 !((num_rows
<=0)&&(num_cols
>0)) ||
2160 !((num_rows
==0)&&(num_cols
==0))),
2161 wxT("wxGridCellAttr::SetSize only takes two postive values or negative/zero values"));
2163 m_sizeRows
= num_rows
;
2164 m_sizeCols
= num_cols
;
2167 const wxColour
& wxGridCellAttr::GetTextColour() const
2169 if (HasTextColour())
2173 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2175 return m_defGridAttr
->GetTextColour();
2179 wxFAIL_MSG(wxT("Missing default cell attribute"));
2180 return wxNullColour
;
2185 const wxColour
& wxGridCellAttr::GetBackgroundColour() const
2187 if (HasBackgroundColour())
2189 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2190 return m_defGridAttr
->GetBackgroundColour();
2193 wxFAIL_MSG(wxT("Missing default cell attribute"));
2194 return wxNullColour
;
2199 const wxFont
& wxGridCellAttr::GetFont() const
2203 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2204 return m_defGridAttr
->GetFont();
2207 wxFAIL_MSG(wxT("Missing default cell attribute"));
2213 void wxGridCellAttr::GetAlignment(int *hAlign
, int *vAlign
) const
2217 if ( hAlign
) *hAlign
= m_hAlign
;
2218 if ( vAlign
) *vAlign
= m_vAlign
;
2220 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2221 m_defGridAttr
->GetAlignment(hAlign
, vAlign
);
2224 wxFAIL_MSG(wxT("Missing default cell attribute"));
2228 void wxGridCellAttr::GetSize( int *num_rows
, int *num_cols
) const
2230 if ( num_rows
) *num_rows
= m_sizeRows
;
2231 if ( num_cols
) *num_cols
= m_sizeCols
;
2234 // GetRenderer and GetEditor use a slightly different decision path about
2235 // which attribute to use. If a non-default attr object has one then it is
2236 // used, otherwise the default editor or renderer is fetched from the grid and
2237 // used. It should be the default for the data type of the cell. If it is
2238 // NULL (because the table has a type that the grid does not have in its
2239 // registry,) then the grid's default editor or renderer is used.
2241 wxGridCellRenderer
* wxGridCellAttr::GetRenderer(wxGrid
* grid
, int row
, int col
) const
2243 wxGridCellRenderer
*renderer
;
2245 if ( m_renderer
&& this != m_defGridAttr
)
2247 // use the cells renderer if it has one
2248 renderer
= m_renderer
;
2251 else // no non default cell renderer
2253 // get default renderer for the data type
2256 // GetDefaultRendererForCell() will do IncRef() for us
2257 renderer
= grid
->GetDefaultRendererForCell(row
, col
);
2266 if (m_defGridAttr
&& this != m_defGridAttr
)
2268 // if we still don't have one then use the grid default
2269 // (no need for IncRef() here neither)
2270 renderer
= m_defGridAttr
->GetRenderer(NULL
, 0, 0);
2272 else // default grid attr
2274 // use m_renderer which we had decided not to use initially
2275 renderer
= m_renderer
;
2282 // we're supposed to always find something
2283 wxASSERT_MSG(renderer
, wxT("Missing default cell renderer"));
2288 // same as above, except for s/renderer/editor/g
2289 wxGridCellEditor
* wxGridCellAttr::GetEditor(wxGrid
* grid
, int row
, int col
) const
2291 wxGridCellEditor
*editor
;
2293 if ( m_editor
&& this != m_defGridAttr
)
2295 // use the cells editor if it has one
2299 else // no non default cell editor
2301 // get default editor for the data type
2304 // GetDefaultEditorForCell() will do IncRef() for us
2305 editor
= grid
->GetDefaultEditorForCell(row
, col
);
2314 if ( m_defGridAttr
&& this != m_defGridAttr
)
2316 // if we still don't have one then use the grid default
2317 // (no need for IncRef() here neither)
2318 editor
= m_defGridAttr
->GetEditor(NULL
, 0, 0);
2320 else // default grid attr
2322 // use m_editor which we had decided not to use initially
2330 // we're supposed to always find something
2331 wxASSERT_MSG(editor
, wxT("Missing default cell editor"));
2336 // ----------------------------------------------------------------------------
2337 // wxGridCellAttrData
2338 // ----------------------------------------------------------------------------
2340 void wxGridCellAttrData::SetAttr(wxGridCellAttr
*attr
, int row
, int col
)
2342 int n
= FindIndex(row
, col
);
2343 if ( n
== wxNOT_FOUND
)
2345 // add the attribute
2346 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
2350 // free the old attribute
2351 m_attrs
[(size_t)n
].attr
->DecRef();
2355 // change the attribute
2356 m_attrs
[(size_t)n
].attr
= attr
;
2360 // remove this attribute
2361 m_attrs
.RemoveAt((size_t)n
);
2366 wxGridCellAttr
*wxGridCellAttrData::GetAttr(int row
, int col
) const
2368 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2370 int n
= FindIndex(row
, col
);
2371 if ( n
!= wxNOT_FOUND
)
2373 attr
= m_attrs
[(size_t)n
].attr
;
2380 void wxGridCellAttrData::UpdateAttrRows( size_t pos
, int numRows
)
2382 size_t count
= m_attrs
.GetCount();
2383 for ( size_t n
= 0; n
< count
; n
++ )
2385 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2386 wxCoord row
= coords
.GetRow();
2387 if ((size_t)row
>= pos
)
2391 // If rows inserted, include row counter where necessary
2392 coords
.SetRow(row
+ numRows
);
2394 else if (numRows
< 0)
2396 // If rows deleted ...
2397 if ((size_t)row
>= pos
- numRows
)
2399 // ...either decrement row counter (if row still exists)...
2400 coords
.SetRow(row
+ numRows
);
2404 // ...or remove the attribute
2405 m_attrs
.RemoveAt((size_t)n
);
2413 void wxGridCellAttrData::UpdateAttrCols( size_t pos
, int numCols
)
2415 size_t count
= m_attrs
.GetCount();
2416 for ( size_t n
= 0; n
< count
; n
++ )
2418 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2419 wxCoord col
= coords
.GetCol();
2420 if ( (size_t)col
>= pos
)
2424 // If rows inserted, include row counter where necessary
2425 coords
.SetCol(col
+ numCols
);
2427 else if (numCols
< 0)
2429 // If rows deleted ...
2430 if ((size_t)col
>= pos
- numCols
)
2432 // ...either decrement row counter (if row still exists)...
2433 coords
.SetCol(col
+ numCols
);
2437 // ...or remove the attribute
2438 m_attrs
.RemoveAt((size_t)n
);
2446 int wxGridCellAttrData::FindIndex(int row
, int col
) const
2448 size_t count
= m_attrs
.GetCount();
2449 for ( size_t n
= 0; n
< count
; n
++ )
2451 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2452 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
2461 // ----------------------------------------------------------------------------
2462 // wxGridRowOrColAttrData
2463 // ----------------------------------------------------------------------------
2465 wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
2467 size_t count
= m_attrs
.Count();
2468 for ( size_t n
= 0; n
< count
; n
++ )
2470 m_attrs
[n
]->DecRef();
2474 wxGridCellAttr
*wxGridRowOrColAttrData::GetAttr(int rowOrCol
) const
2476 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2478 int n
= m_rowsOrCols
.Index(rowOrCol
);
2479 if ( n
!= wxNOT_FOUND
)
2481 attr
= m_attrs
[(size_t)n
];
2488 void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr
*attr
, int rowOrCol
)
2490 int i
= m_rowsOrCols
.Index(rowOrCol
);
2491 if ( i
== wxNOT_FOUND
)
2493 // add the attribute
2494 m_rowsOrCols
.Add(rowOrCol
);
2499 size_t n
= (size_t)i
;
2502 // change the attribute
2503 m_attrs
[n
]->DecRef();
2508 // remove this attribute
2509 m_attrs
[n
]->DecRef();
2510 m_rowsOrCols
.RemoveAt(n
);
2511 m_attrs
.RemoveAt(n
);
2516 void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
)
2518 size_t count
= m_attrs
.GetCount();
2519 for ( size_t n
= 0; n
< count
; n
++ )
2521 int & rowOrCol
= m_rowsOrCols
[n
];
2522 if ( (size_t)rowOrCol
>= pos
)
2524 if ( numRowsOrCols
> 0 )
2526 // If rows inserted, include row counter where necessary
2527 rowOrCol
+= numRowsOrCols
;
2529 else if ( numRowsOrCols
< 0)
2531 // If rows deleted, either decrement row counter (if row still exists)
2532 if ((size_t)rowOrCol
>= pos
- numRowsOrCols
)
2533 rowOrCol
+= numRowsOrCols
;
2536 m_rowsOrCols
.RemoveAt((size_t)n
);
2537 m_attrs
.RemoveAt((size_t)n
);
2545 // ----------------------------------------------------------------------------
2546 // wxGridCellAttrProvider
2547 // ----------------------------------------------------------------------------
2549 wxGridCellAttrProvider::wxGridCellAttrProvider()
2551 m_data
= (wxGridCellAttrProviderData
*)NULL
;
2554 wxGridCellAttrProvider::~wxGridCellAttrProvider()
2559 void wxGridCellAttrProvider::InitData()
2561 m_data
= new wxGridCellAttrProviderData
;
2564 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
,
2565 wxGridCellAttr::wxAttrKind kind
) const
2567 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2572 case (wxGridCellAttr::Any
):
2573 //Get cached merge attributes.
2574 // Currenlty not used as no cache implemented as not mutiable
2575 // attr = m_data->m_mergeAttr.GetAttr(row, col);
2578 //Basicaly implement old version.
2579 //Also check merge cache, so we don't have to re-merge every time..
2580 wxGridCellAttr
*attrcell
= (wxGridCellAttr
*)NULL
,
2581 *attrrow
= (wxGridCellAttr
*)NULL
,
2582 *attrcol
= (wxGridCellAttr
*)NULL
;
2584 attrcell
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
2585 attrcol
= m_data
->m_colAttrs
.GetAttr(col
);
2586 attrrow
= m_data
->m_rowAttrs
.GetAttr(row
);
2588 if((attrcell
!= attrrow
) && (attrrow
!=attrcol
) && (attrcell
!= attrcol
)){
2589 // Two or move are non NULL
2590 attr
= new wxGridCellAttr
;
2591 attr
->SetKind(wxGridCellAttr::Merged
);
2595 attr
->MergeWith(attrcell
);
2599 attr
->MergeWith(attrcol
);
2603 attr
->MergeWith(attrrow
);
2606 //store merge attr if cache implemented
2608 //m_data->m_mergeAttr.SetAttr(attr, row, col);
2612 // one or none is non null return it or null.
2613 if(attrrow
) attr
= attrrow
;
2614 if(attrcol
) attr
= attrcol
;
2615 if(attrcell
) attr
= attrcell
;
2619 case (wxGridCellAttr::Cell
):
2620 attr
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
2622 case (wxGridCellAttr::Col
):
2623 attr
= m_data
->m_colAttrs
.GetAttr(col
);
2625 case (wxGridCellAttr::Row
):
2626 attr
= m_data
->m_rowAttrs
.GetAttr(row
);
2630 // (wxGridCellAttr::Default):
2631 // (wxGridCellAttr::Merged):
2638 void wxGridCellAttrProvider::SetAttr(wxGridCellAttr
*attr
,
2644 m_data
->m_cellAttrs
.SetAttr(attr
, row
, col
);
2647 void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr
*attr
, int row
)
2652 m_data
->m_rowAttrs
.SetAttr(attr
, row
);
2655 void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr
*attr
, int col
)
2660 m_data
->m_colAttrs
.SetAttr(attr
, col
);
2663 void wxGridCellAttrProvider::UpdateAttrRows( size_t pos
, int numRows
)
2667 m_data
->m_cellAttrs
.UpdateAttrRows( pos
, numRows
);
2669 m_data
->m_rowAttrs
.UpdateAttrRowsOrCols( pos
, numRows
);
2673 void wxGridCellAttrProvider::UpdateAttrCols( size_t pos
, int numCols
)
2677 m_data
->m_cellAttrs
.UpdateAttrCols( pos
, numCols
);
2679 m_data
->m_colAttrs
.UpdateAttrRowsOrCols( pos
, numCols
);
2683 // ----------------------------------------------------------------------------
2684 // wxGridTypeRegistry
2685 // ----------------------------------------------------------------------------
2687 wxGridTypeRegistry::~wxGridTypeRegistry()
2689 size_t count
= m_typeinfo
.Count();
2690 for ( size_t i
= 0; i
< count
; i
++ )
2691 delete m_typeinfo
[i
];
2695 void wxGridTypeRegistry::RegisterDataType(const wxString
& typeName
,
2696 wxGridCellRenderer
* renderer
,
2697 wxGridCellEditor
* editor
)
2699 wxGridDataTypeInfo
* info
= new wxGridDataTypeInfo(typeName
, renderer
, editor
);
2701 // is it already registered?
2702 int loc
= FindRegisteredDataType(typeName
);
2703 if ( loc
!= wxNOT_FOUND
)
2705 delete m_typeinfo
[loc
];
2706 m_typeinfo
[loc
] = info
;
2710 m_typeinfo
.Add(info
);
2714 int wxGridTypeRegistry::FindRegisteredDataType(const wxString
& typeName
)
2716 size_t count
= m_typeinfo
.GetCount();
2717 for ( size_t i
= 0; i
< count
; i
++ )
2719 if ( typeName
== m_typeinfo
[i
]->m_typeName
)
2728 int wxGridTypeRegistry::FindDataType(const wxString
& typeName
)
2730 int index
= FindRegisteredDataType(typeName
);
2731 if ( index
== wxNOT_FOUND
)
2733 // check whether this is one of the standard ones, in which case
2734 // register it "on the fly"
2736 if ( typeName
== wxGRID_VALUE_STRING
)
2738 RegisterDataType(wxGRID_VALUE_STRING
,
2739 new wxGridCellStringRenderer
,
2740 new wxGridCellTextEditor
);
2742 #endif // wxUSE_TEXTCTRL
2744 if ( typeName
== wxGRID_VALUE_BOOL
)
2746 RegisterDataType(wxGRID_VALUE_BOOL
,
2747 new wxGridCellBoolRenderer
,
2748 new wxGridCellBoolEditor
);
2750 #endif // wxUSE_CHECKBOX
2752 if ( typeName
== wxGRID_VALUE_NUMBER
)
2754 RegisterDataType(wxGRID_VALUE_NUMBER
,
2755 new wxGridCellNumberRenderer
,
2756 new wxGridCellNumberEditor
);
2758 else if ( typeName
== wxGRID_VALUE_FLOAT
)
2760 RegisterDataType(wxGRID_VALUE_FLOAT
,
2761 new wxGridCellFloatRenderer
,
2762 new wxGridCellFloatEditor
);
2764 #endif // wxUSE_TEXTCTRL
2766 if ( typeName
== wxGRID_VALUE_CHOICE
)
2768 RegisterDataType(wxGRID_VALUE_CHOICE
,
2769 new wxGridCellStringRenderer
,
2770 new wxGridCellChoiceEditor
);
2772 #endif // wxUSE_COMBOBOX
2777 // we get here only if just added the entry for this type, so return
2779 index
= m_typeinfo
.GetCount() - 1;
2785 int wxGridTypeRegistry::FindOrCloneDataType(const wxString
& typeName
)
2787 int index
= FindDataType(typeName
);
2788 if ( index
== wxNOT_FOUND
)
2790 // the first part of the typename is the "real" type, anything after ':'
2791 // are the parameters for the renderer
2792 index
= FindDataType(typeName
.BeforeFirst(_T(':')));
2793 if ( index
== wxNOT_FOUND
)
2798 wxGridCellRenderer
*renderer
= GetRenderer(index
);
2799 wxGridCellRenderer
*rendererOld
= renderer
;
2800 renderer
= renderer
->Clone();
2801 rendererOld
->DecRef();
2803 wxGridCellEditor
*editor
= GetEditor(index
);
2804 wxGridCellEditor
*editorOld
= editor
;
2805 editor
= editor
->Clone();
2806 editorOld
->DecRef();
2808 // do it even if there are no parameters to reset them to defaults
2809 wxString params
= typeName
.AfterFirst(_T(':'));
2810 renderer
->SetParameters(params
);
2811 editor
->SetParameters(params
);
2813 // register the new typename
2814 RegisterDataType(typeName
, renderer
, editor
);
2816 // we just registered it, it's the last one
2817 index
= m_typeinfo
.GetCount() - 1;
2823 wxGridCellRenderer
* wxGridTypeRegistry::GetRenderer(int index
)
2825 wxGridCellRenderer
* renderer
= m_typeinfo
[index
]->m_renderer
;
2831 wxGridCellEditor
* wxGridTypeRegistry::GetEditor(int index
)
2833 wxGridCellEditor
* editor
= m_typeinfo
[index
]->m_editor
;
2839 // ----------------------------------------------------------------------------
2841 // ----------------------------------------------------------------------------
2843 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
2846 wxGridTableBase::wxGridTableBase()
2848 m_view
= (wxGrid
*) NULL
;
2849 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
2852 wxGridTableBase::~wxGridTableBase()
2854 delete m_attrProvider
;
2857 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
2859 delete m_attrProvider
;
2860 m_attrProvider
= attrProvider
;
2863 bool wxGridTableBase::CanHaveAttributes()
2865 if ( ! GetAttrProvider() )
2867 // use the default attr provider by default
2868 SetAttrProvider(new wxGridCellAttrProvider
);
2873 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
, wxGridCellAttr::wxAttrKind kind
)
2875 if ( m_attrProvider
)
2876 return m_attrProvider
->GetAttr(row
, col
, kind
);
2878 return (wxGridCellAttr
*)NULL
;
2881 void wxGridTableBase::SetAttr(wxGridCellAttr
* attr
, int row
, int col
)
2883 if ( m_attrProvider
)
2885 attr
->SetKind(wxGridCellAttr::Cell
);
2886 m_attrProvider
->SetAttr(attr
, row
, col
);
2890 // as we take ownership of the pointer and don't store it, we must
2896 void wxGridTableBase::SetRowAttr(wxGridCellAttr
*attr
, int row
)
2898 if ( m_attrProvider
)
2900 attr
->SetKind(wxGridCellAttr::Row
);
2901 m_attrProvider
->SetRowAttr(attr
, row
);
2905 // as we take ownership of the pointer and don't store it, we must
2911 void wxGridTableBase::SetColAttr(wxGridCellAttr
*attr
, int col
)
2913 if ( m_attrProvider
)
2915 attr
->SetKind(wxGridCellAttr::Col
);
2916 m_attrProvider
->SetColAttr(attr
, col
);
2920 // as we take ownership of the pointer and don't store it, we must
2926 bool wxGridTableBase::InsertRows( size_t WXUNUSED(pos
),
2927 size_t WXUNUSED(numRows
) )
2929 wxFAIL_MSG( wxT("Called grid table class function InsertRows\nbut your derived table class does not override this function") );
2934 bool wxGridTableBase::AppendRows( size_t WXUNUSED(numRows
) )
2936 wxFAIL_MSG( wxT("Called grid table class function AppendRows\nbut your derived table class does not override this function"));
2941 bool wxGridTableBase::DeleteRows( size_t WXUNUSED(pos
),
2942 size_t WXUNUSED(numRows
) )
2944 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\nbut your derived table class does not override this function"));
2949 bool wxGridTableBase::InsertCols( size_t WXUNUSED(pos
),
2950 size_t WXUNUSED(numCols
) )
2952 wxFAIL_MSG( wxT("Called grid table class function InsertCols\nbut your derived table class does not override this function"));
2957 bool wxGridTableBase::AppendCols( size_t WXUNUSED(numCols
) )
2959 wxFAIL_MSG(wxT("Called grid table class function AppendCols\nbut your derived table class does not override this function"));
2964 bool wxGridTableBase::DeleteCols( size_t WXUNUSED(pos
),
2965 size_t WXUNUSED(numCols
) )
2967 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\nbut your derived table class does not override this function"));
2973 wxString
wxGridTableBase::GetRowLabelValue( int row
)
2976 s
<< row
+ 1; // RD: Starting the rows at zero confuses users, no matter
2977 // how much it makes sense to us geeks.
2981 wxString
wxGridTableBase::GetColLabelValue( int col
)
2983 // default col labels are:
2984 // cols 0 to 25 : A-Z
2985 // cols 26 to 675 : AA-ZZ
2990 for ( n
= 1; ; n
++ )
2992 s
+= (_T('A') + (wxChar
)( col%26
));
2994 if ( col
< 0 ) break;
2997 // reverse the string...
2999 for ( i
= 0; i
< n
; i
++ )
3008 wxString
wxGridTableBase::GetTypeName( int WXUNUSED(row
), int WXUNUSED(col
) )
3010 return wxGRID_VALUE_STRING
;
3013 bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row
), int WXUNUSED(col
),
3014 const wxString
& typeName
)
3016 return typeName
== wxGRID_VALUE_STRING
;
3019 bool wxGridTableBase::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
3021 return CanGetValueAs(row
, col
, typeName
);
3024 long wxGridTableBase::GetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
) )
3029 double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
) )
3034 bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
) )
3039 void wxGridTableBase::SetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
),
3040 long WXUNUSED(value
) )
3044 void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
),
3045 double WXUNUSED(value
) )
3049 void wxGridTableBase::SetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
),
3050 bool WXUNUSED(value
) )
3055 void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
3056 const wxString
& WXUNUSED(typeName
) )
3061 void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
3062 const wxString
& WXUNUSED(typeName
),
3063 void* WXUNUSED(value
) )
3067 //////////////////////////////////////////////////////////////////////
3069 // Message class for the grid table to send requests and notifications
3073 wxGridTableMessage::wxGridTableMessage()
3075 m_table
= (wxGridTableBase
*) NULL
;
3081 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
3082 int commandInt1
, int commandInt2
)
3086 m_comInt1
= commandInt1
;
3087 m_comInt2
= commandInt2
;
3092 //////////////////////////////////////////////////////////////////////
3094 // A basic grid table for string data. An object of this class will
3095 // created by wxGrid if you don't specify an alternative table class.
3098 WX_DEFINE_OBJARRAY(wxGridStringArray
)
3100 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
3102 wxGridStringTable::wxGridStringTable()
3107 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
3110 m_data
.Alloc( numRows
);
3113 sa
.Alloc( numCols
);
3114 sa
.Add( wxEmptyString
, numCols
);
3116 m_data
.Add( sa
, numRows
);
3119 wxGridStringTable::~wxGridStringTable()
3123 int wxGridStringTable::GetNumberRows()
3125 return m_data
.GetCount();
3128 int wxGridStringTable::GetNumberCols()
3130 if ( m_data
.GetCount() > 0 )
3131 return m_data
[0].GetCount();
3136 wxString
wxGridStringTable::GetValue( int row
, int col
)
3138 wxASSERT_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3139 _T("invalid row or column index in wxGridStringTable") );
3141 return m_data
[row
][col
];
3144 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& value
)
3146 wxASSERT_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3147 _T("invalid row or column index in wxGridStringTable") );
3149 m_data
[row
][col
] = value
;
3152 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
3154 wxASSERT_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3155 _T("invalid row or column index in wxGridStringTable") );
3157 return (m_data
[row
][col
] == wxEmptyString
);
3160 void wxGridStringTable::Clear()
3163 int numRows
, numCols
;
3165 numRows
= m_data
.GetCount();
3168 numCols
= m_data
[0].GetCount();
3170 for ( row
= 0; row
< numRows
; row
++ )
3172 for ( col
= 0; col
< numCols
; col
++ )
3174 m_data
[row
][col
] = wxEmptyString
;
3181 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
3183 size_t curNumRows
= m_data
.GetCount();
3184 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3185 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3187 if ( pos
>= curNumRows
)
3189 return AppendRows( numRows
);
3193 sa
.Alloc( curNumCols
);
3194 sa
.Add( wxEmptyString
, curNumCols
);
3195 m_data
.Insert( sa
, pos
, numRows
);
3198 wxGridTableMessage
msg( this,
3199 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
3203 GetView()->ProcessTableMessage( msg
);
3209 bool wxGridStringTable::AppendRows( size_t numRows
)
3211 size_t curNumRows
= m_data
.GetCount();
3212 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3213 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3216 if ( curNumCols
> 0 )
3218 sa
.Alloc( curNumCols
);
3219 sa
.Add( wxEmptyString
, curNumCols
);
3222 m_data
.Add( sa
, numRows
);
3226 wxGridTableMessage
msg( this,
3227 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
3230 GetView()->ProcessTableMessage( msg
);
3236 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
3238 size_t curNumRows
= m_data
.GetCount();
3240 if ( pos
>= curNumRows
)
3242 wxFAIL_MSG( wxString::Format
3244 wxT("Called wxGridStringTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows"),
3246 (unsigned long)numRows
,
3247 (unsigned long)curNumRows
3253 if ( numRows
> curNumRows
- pos
)
3255 numRows
= curNumRows
- pos
;
3258 if ( numRows
>= curNumRows
)
3264 m_data
.RemoveAt( pos
, numRows
);
3268 wxGridTableMessage
msg( this,
3269 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
3273 GetView()->ProcessTableMessage( msg
);
3279 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
3283 size_t curNumRows
= m_data
.GetCount();
3284 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3285 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3287 if ( pos
>= curNumCols
)
3289 return AppendCols( numCols
);
3292 for ( row
= 0; row
< curNumRows
; row
++ )
3294 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
3296 m_data
[row
].Insert( wxEmptyString
, col
);
3301 wxGridTableMessage
msg( this,
3302 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
3306 GetView()->ProcessTableMessage( msg
);
3312 bool wxGridStringTable::AppendCols( size_t numCols
)
3316 size_t curNumRows
= m_data
.GetCount();
3320 // TODO: something better than this ?
3322 wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\nCall AppendRows() first") );
3327 for ( row
= 0; row
< curNumRows
; row
++ )
3329 m_data
[row
].Add( wxEmptyString
, numCols
);
3334 wxGridTableMessage
msg( this,
3335 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
3338 GetView()->ProcessTableMessage( msg
);
3344 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
3348 size_t curNumRows
= m_data
.GetCount();
3349 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3350 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3352 if ( pos
>= curNumCols
)
3354 wxFAIL_MSG( wxString::Format
3356 wxT("Called wxGridStringTable::DeleteCols(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu cols"),
3358 (unsigned long)numCols
,
3359 (unsigned long)curNumCols
3364 if ( numCols
> curNumCols
- pos
)
3366 numCols
= curNumCols
- pos
;
3369 for ( row
= 0; row
< curNumRows
; row
++ )
3371 if ( numCols
>= curNumCols
)
3373 m_data
[row
].Clear();
3377 m_data
[row
].RemoveAt( pos
, numCols
);
3382 wxGridTableMessage
msg( this,
3383 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
3387 GetView()->ProcessTableMessage( msg
);
3393 wxString
wxGridStringTable::GetRowLabelValue( int row
)
3395 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
3397 // using default label
3399 return wxGridTableBase::GetRowLabelValue( row
);
3403 return m_rowLabels
[ row
];
3407 wxString
wxGridStringTable::GetColLabelValue( int col
)
3409 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
3411 // using default label
3413 return wxGridTableBase::GetColLabelValue( col
);
3417 return m_colLabels
[ col
];
3421 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
3423 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
3425 int n
= m_rowLabels
.GetCount();
3427 for ( i
= n
; i
<= row
; i
++ )
3429 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
3433 m_rowLabels
[row
] = value
;
3436 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
3438 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
3440 int n
= m_colLabels
.GetCount();
3442 for ( i
= n
; i
<= col
; i
++ )
3444 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
3448 m_colLabels
[col
] = value
;
3453 //////////////////////////////////////////////////////////////////////
3454 //////////////////////////////////////////////////////////////////////
3456 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
3458 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
3459 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
3460 EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel
)
3461 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
3462 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
3463 EVT_KEY_UP( wxGridRowLabelWindow::OnKeyUp
)
3466 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
3468 const wxPoint
&pos
, const wxSize
&size
)
3469 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
)
3474 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3478 // NO - don't do this because it will set both the x and y origin
3479 // coords to match the parent scrolled window and we just want to
3480 // set the y coord - MB
3482 // m_owner->PrepareDC( dc );
3485 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
3486 dc
.SetDeviceOrigin( 0, -y
);
3488 wxArrayInt rows
= m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
3489 m_owner
->DrawRowLabels( dc
, rows
);
3493 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3495 m_owner
->ProcessRowLabelMouseEvent( event
);
3499 void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3501 m_owner
->GetEventHandler()->ProcessEvent(event
);
3505 // This seems to be required for wxMotif otherwise the mouse
3506 // cursor must be in the cell edit control to get key events
3508 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3510 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3513 void wxGridRowLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3515 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3520 //////////////////////////////////////////////////////////////////////
3522 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
3524 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
3525 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
3526 EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel
)
3527 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
3528 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
3529 EVT_KEY_UP( wxGridColLabelWindow::OnKeyUp
)
3532 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
3534 const wxPoint
&pos
, const wxSize
&size
)
3535 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
)
3540 void wxGridColLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3544 // NO - don't do this because it will set both the x and y origin
3545 // coords to match the parent scrolled window and we just want to
3546 // set the x coord - MB
3548 // m_owner->PrepareDC( dc );
3551 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
3552 dc
.SetDeviceOrigin( -x
, 0 );
3554 wxArrayInt cols
= m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
3555 m_owner
->DrawColLabels( dc
, cols
);
3559 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3561 m_owner
->ProcessColLabelMouseEvent( event
);
3564 void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3566 m_owner
->GetEventHandler()->ProcessEvent(event
);
3570 // This seems to be required for wxMotif otherwise the mouse
3571 // cursor must be in the cell edit control to get key events
3573 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3575 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3578 void wxGridColLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3580 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3585 //////////////////////////////////////////////////////////////////////
3587 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
3589 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
3590 EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel
)
3591 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
3592 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
3593 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
3594 EVT_KEY_UP( wxGridCornerLabelWindow::OnKeyUp
)
3597 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
3599 const wxPoint
&pos
, const wxSize
&size
)
3600 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
)
3605 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3609 int client_height
= 0;
3610 int client_width
= 0;
3611 GetClientSize( &client_width
, &client_height
);
3613 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
),1, wxSOLID
) );
3614 dc
.DrawLine( client_width
-1, client_height
-1, client_width
-1, 0 );
3615 dc
.DrawLine( client_width
-1, client_height
-1, 0, client_height
-1 );
3616 dc
.DrawLine( 0, 0, client_width
, 0 );
3617 dc
.DrawLine( 0, 0, 0, client_height
);
3619 dc
.SetPen( *wxWHITE_PEN
);
3620 dc
.DrawLine( 1, 1, client_width
-1, 1 );
3621 dc
.DrawLine( 1, 1, 1, client_height
-1 );
3625 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3627 m_owner
->ProcessCornerLabelMouseEvent( event
);
3631 void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3633 m_owner
->GetEventHandler()->ProcessEvent(event
);
3636 // This seems to be required for wxMotif otherwise the mouse
3637 // cursor must be in the cell edit control to get key events
3639 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3641 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3644 void wxGridCornerLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3646 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3651 //////////////////////////////////////////////////////////////////////
3653 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxWindow
)
3655 BEGIN_EVENT_TABLE( wxGridWindow
, wxWindow
)
3656 EVT_PAINT( wxGridWindow::OnPaint
)
3657 EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel
)
3658 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
3659 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
3660 EVT_KEY_UP( wxGridWindow::OnKeyUp
)
3661 EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground
)
3664 wxGridWindow::wxGridWindow( wxGrid
*parent
,
3665 wxGridRowLabelWindow
*rowLblWin
,
3666 wxGridColLabelWindow
*colLblWin
,
3669 const wxSize
&size
)
3670 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
| wxBORDER_NONE
| wxCLIP_CHILDREN
,
3671 wxT("grid window") )
3675 m_rowLabelWin
= rowLblWin
;
3676 m_colLabelWin
= colLblWin
;
3677 SetBackgroundColour(_T("WHITE"));
3681 wxGridWindow::~wxGridWindow()
3686 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
3688 wxPaintDC
dc( this );
3689 m_owner
->PrepareDC( dc
);
3690 wxRegion reg
= GetUpdateRegion();
3691 wxGridCellCoordsArray DirtyCells
= m_owner
->CalcCellsExposed( reg
);
3692 m_owner
->DrawGridCellArea( dc
, DirtyCells
);
3693 #if WXGRID_DRAW_LINES
3694 m_owner
->DrawAllGridLines( dc
, reg
);
3696 m_owner
->DrawGridSpace( dc
);
3697 m_owner
->DrawHighlight( dc
, DirtyCells
);
3701 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
3703 wxWindow::ScrollWindow( dx
, dy
, rect
);
3704 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
3705 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
3709 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
3711 m_owner
->ProcessGridCellMouseEvent( event
);
3714 void wxGridWindow::OnMouseWheel( wxMouseEvent
& event
)
3716 m_owner
->GetEventHandler()->ProcessEvent(event
);
3719 // This seems to be required for wxMotif/wxGTK otherwise the mouse
3720 // cursor must be in the cell edit control to get key events
3722 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
3724 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3727 void wxGridWindow::OnKeyUp( wxKeyEvent
& event
)
3729 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3732 void wxGridWindow::OnEraseBackground( wxEraseEvent
& WXUNUSED(event
) )
3737 //////////////////////////////////////////////////////////////////////
3739 // Internal Helper function for computing row or column from some
3740 // (unscrolled) coordinate value, using either
3741 // m_defaultRowHeight/m_defaultColWidth or binary search on array
3742 // of m_rowBottoms/m_ColRights to speed up the search!
3744 // Internal helper macros for simpler use of that function
3746 static int CoordToRowOrCol(int coord
, int defaultDist
, int minDist
,
3747 const wxArrayInt
& BorderArray
, int nMax
,
3750 #define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \
3751 m_minAcceptableColWidth, \
3752 m_colRights, m_numCols, TRUE)
3753 #define internalYToRow(y) CoordToRowOrCol(y, m_defaultRowHeight, \
3754 m_minAcceptableRowHeight, \
3755 m_rowBottoms, m_numRows, TRUE)
3756 /////////////////////////////////////////////////////////////////////
3758 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
3760 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
3761 EVT_PAINT( wxGrid::OnPaint
)
3762 EVT_SIZE( wxGrid::OnSize
)
3763 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
3764 EVT_KEY_UP( wxGrid::OnKeyUp
)
3765 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
3768 wxGrid::wxGrid( wxWindow
*parent
,
3773 const wxString
& name
)
3774 : wxScrolledWindow( parent
, id
, pos
, size
, (style
| wxWANTS_CHARS
), name
),
3775 m_colMinWidths(GRID_HASH_SIZE
),
3776 m_rowMinHeights(GRID_HASH_SIZE
)
3784 // Must do this or ~wxScrollHelper will pop the wrong event handler
3785 SetTargetWindow(this);
3787 wxSafeDecRef(m_defaultCellAttr
);
3789 #ifdef DEBUG_ATTR_CACHE
3790 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
3791 wxPrintf(_T("wxGrid attribute cache statistics: "
3792 "total: %u, hits: %u (%u%%)\n"),
3793 total
, gs_nAttrCacheHits
,
3794 total
? (gs_nAttrCacheHits
*100) / total
: 0);
3800 delete m_typeRegistry
;
3806 // ----- internal init and update functions
3809 void wxGrid::Create()
3811 m_created
= FALSE
; // set to TRUE by CreateGrid
3813 m_table
= (wxGridTableBase
*) NULL
;
3816 m_cellEditCtrlEnabled
= FALSE
;
3818 m_defaultCellAttr
= new wxGridCellAttr();
3820 // Set default cell attributes
3821 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
3822 m_defaultCellAttr
->SetKind(wxGridCellAttr::Default
);
3823 m_defaultCellAttr
->SetFont(GetFont());
3824 m_defaultCellAttr
->SetAlignment(wxALIGN_LEFT
, wxALIGN_TOP
);
3825 m_defaultCellAttr
->SetTextColour(
3826 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
3827 m_defaultCellAttr
->SetBackgroundColour(
3828 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
3829 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
3830 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
3835 m_currentCellCoords
= wxGridNoCellCoords
;
3837 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
3838 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
3840 // create the type registry
3841 m_typeRegistry
= new wxGridTypeRegistry
;
3844 // subwindow components that make up the wxGrid
3845 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
3850 m_rowLabelWin
= new wxGridRowLabelWindow( this,
3855 m_colLabelWin
= new wxGridColLabelWindow( this,
3860 m_gridWin
= new wxGridWindow( this,
3867 SetTargetWindow( m_gridWin
);
3873 bool wxGrid::CreateGrid( int numRows
, int numCols
,
3874 wxGrid::wxGridSelectionModes selmode
)
3876 wxCHECK_MSG( !m_created
,
3878 wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
3880 m_numRows
= numRows
;
3881 m_numCols
= numCols
;
3883 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
3884 m_table
->SetView( this );
3886 m_selection
= new wxGridSelection( this, selmode
);
3895 void wxGrid::SetSelectionMode(wxGrid::wxGridSelectionModes selmode
)
3897 wxCHECK_RET( m_created
,
3898 wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") );
3900 m_selection
->SetSelectionMode( selmode
);
3903 wxGrid::wxGridSelectionModes
wxGrid::GetSelectionMode() const
3905 wxCHECK_MSG( m_created
, wxGrid::wxGridSelectCells
,
3906 wxT("Called wxGrid::GetSelectionMode() before calling CreateGrid()") );
3908 return m_selection
->GetSelectionMode();
3911 bool wxGrid::SetTable( wxGridTableBase
*table
, bool takeOwnership
,
3912 wxGrid::wxGridSelectionModes selmode
)
3920 // stop all processing
3929 m_numRows
= table
->GetNumberRows();
3930 m_numCols
= table
->GetNumberCols();
3933 m_table
->SetView( this );
3936 m_selection
= new wxGridSelection( this, selmode
);
3949 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
3950 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
3952 if ( m_rowLabelWin
)
3954 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
3958 m_labelBackgroundColour
= wxColour( _T("WHITE") );
3961 m_labelTextColour
= wxColour( _T("BLACK") );
3964 m_attrCache
.row
= -1;
3965 m_attrCache
.col
= -1;
3966 m_attrCache
.attr
= NULL
;
3968 // TODO: something better than this ?
3970 m_labelFont
= this->GetFont();
3971 m_labelFont
.SetWeight( wxBOLD
);
3973 m_rowLabelHorizAlign
= wxALIGN_CENTRE
;
3974 m_rowLabelVertAlign
= wxALIGN_CENTRE
;
3976 m_colLabelHorizAlign
= wxALIGN_CENTRE
;
3977 m_colLabelVertAlign
= wxALIGN_CENTRE
;
3978 m_colLabelTextOrientation
= wxHORIZONTAL
;
3980 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
3981 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
3983 m_minAcceptableColWidth
= WXGRID_MIN_COL_WIDTH
;
3984 m_minAcceptableRowHeight
= WXGRID_MIN_ROW_HEIGHT
;
3986 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
3987 m_defaultRowHeight
+= 8;
3989 m_defaultRowHeight
+= 4;
3992 m_gridLineColour
= wxColour( 192,192,192 );
3993 m_gridLinesEnabled
= TRUE
;
3994 m_cellHighlightColour
= *wxBLACK
;
3995 m_cellHighlightPenWidth
= 2;
3996 m_cellHighlightROPenWidth
= 1;
3998 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
3999 m_winCapture
= (wxWindow
*)NULL
;
4000 m_canDragRowSize
= TRUE
;
4001 m_canDragColSize
= TRUE
;
4002 m_canDragGridSize
= TRUE
;
4004 m_dragRowOrCol
= -1;
4005 m_isDragging
= FALSE
;
4006 m_startDragPos
= wxDefaultPosition
;
4008 m_waitForSlowClick
= FALSE
;
4010 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
4011 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
4013 m_currentCellCoords
= wxGridNoCellCoords
;
4015 m_selectingTopLeft
= wxGridNoCellCoords
;
4016 m_selectingBottomRight
= wxGridNoCellCoords
;
4017 m_selectionBackground
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
4018 m_selectionForeground
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
4020 m_editable
= TRUE
; // default for whole grid
4022 m_inOnKeyDown
= FALSE
;
4029 // ----------------------------------------------------------------------------
4030 // the idea is to call these functions only when necessary because they create
4031 // quite big arrays which eat memory mostly unnecessary - in particular, if
4032 // default widths/heights are used for all rows/columns, we may not use these
4035 // with some extra code, it should be possible to only store the
4036 // widths/heights different from default ones but this will be done later...
4037 // ----------------------------------------------------------------------------
4039 void wxGrid::InitRowHeights()
4041 m_rowHeights
.Empty();
4042 m_rowBottoms
.Empty();
4044 m_rowHeights
.Alloc( m_numRows
);
4045 m_rowBottoms
.Alloc( m_numRows
);
4049 m_rowHeights
.Add( m_defaultRowHeight
, m_numRows
);
4051 for ( int i
= 0; i
< m_numRows
; i
++ )
4053 rowBottom
+= m_defaultRowHeight
;
4054 m_rowBottoms
.Add( rowBottom
);
4058 void wxGrid::InitColWidths()
4060 m_colWidths
.Empty();
4061 m_colRights
.Empty();
4063 m_colWidths
.Alloc( m_numCols
);
4064 m_colRights
.Alloc( m_numCols
);
4067 m_colWidths
.Add( m_defaultColWidth
, m_numCols
);
4069 for ( int i
= 0; i
< m_numCols
; i
++ )
4071 colRight
+= m_defaultColWidth
;
4072 m_colRights
.Add( colRight
);
4076 int wxGrid::GetColWidth(int col
) const
4078 return m_colWidths
.IsEmpty() ? m_defaultColWidth
: m_colWidths
[col
];
4081 int wxGrid::GetColLeft(int col
) const
4083 return m_colRights
.IsEmpty() ? col
* m_defaultColWidth
4084 : m_colRights
[col
] - m_colWidths
[col
];
4087 int wxGrid::GetColRight(int col
) const
4089 return m_colRights
.IsEmpty() ? (col
+ 1) * m_defaultColWidth
4093 int wxGrid::GetRowHeight(int row
) const
4095 return m_rowHeights
.IsEmpty() ? m_defaultRowHeight
: m_rowHeights
[row
];
4098 int wxGrid::GetRowTop(int row
) const
4100 return m_rowBottoms
.IsEmpty() ? row
* m_defaultRowHeight
4101 : m_rowBottoms
[row
] - m_rowHeights
[row
];
4104 int wxGrid::GetRowBottom(int row
) const
4106 return m_rowBottoms
.IsEmpty() ? (row
+ 1) * m_defaultRowHeight
4107 : m_rowBottoms
[row
];
4110 void wxGrid::CalcDimensions()
4113 GetClientSize( &cw
, &ch
);
4115 if ( m_rowLabelWin
->IsShown() )
4116 cw
-= m_rowLabelWidth
;
4117 if ( m_colLabelWin
->IsShown() )
4118 ch
-= m_colLabelHeight
;
4121 int w
= m_numCols
> 0 ? GetColRight(m_numCols
- 1) + m_extraWidth
+ 1 : 0;
4122 int h
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) + m_extraHeight
+ 1 : 0;
4124 // take into account editor if shown
4125 if( IsCellEditControlShown() )
4128 int r
= m_currentCellCoords
.GetRow();
4129 int c
= m_currentCellCoords
.GetCol();
4130 int x
= GetColLeft(c
);
4131 int y
= GetRowTop(r
);
4133 // how big is the editor
4134 wxGridCellAttr
* attr
= GetCellAttr(r
, c
);
4135 wxGridCellEditor
* editor
= attr
->GetEditor(this, r
, c
);
4136 editor
->GetControl()->GetSize(&w2
, &h2
);
4139 if( w2
> w
) w
= w2
;
4140 if( h2
> h
) h
= h2
;
4145 // preserve (more or less) the previous position
4147 GetViewStart( &x
, &y
);
4149 // maybe we don't need scrollbars at all?
4151 // also adjust the position to be valid for the new scroll rangs
4172 // do set scrollbar parameters
4173 SetScrollbars( GRID_SCROLL_LINE_X
, GRID_SCROLL_LINE_Y
,
4174 GetScrollX(w
), GetScrollY(h
), x
, y
,
4175 GetBatchCount() != 0);
4177 // if our OnSize() hadn't been called (it would if we have scrollbars), we
4178 // still must reposition the children
4183 void wxGrid::CalcWindowSizes()
4186 GetClientSize( &cw
, &ch
);
4188 if ( m_cornerLabelWin
->IsShown() )
4189 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
4191 if ( m_colLabelWin
->IsShown() )
4192 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
4194 if ( m_rowLabelWin
->IsShown() )
4195 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
4197 if ( m_gridWin
->IsShown() )
4198 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
4202 // this is called when the grid table sends a message to say that it
4203 // has been redimensioned
4205 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
4208 bool result
= FALSE
;
4210 // Clear the attribute cache as the attribute might refer to a different
4211 // cell than stored in the cache after adding/removing rows/columns.
4213 // By the same reasoning, the editor should be dismissed if columns are
4214 // added or removed. And for consistency, it should IMHO always be
4215 // removed, not only if the cell "underneath" it actually changes.
4216 // For now, I intentionally do not save the editor's content as the
4217 // cell it might want to save that stuff to might no longer exist.
4218 HideCellEditControl();
4220 // if we were using the default widths/heights so far, we must change them
4222 if ( m_colWidths
.IsEmpty() )
4227 if ( m_rowHeights
.IsEmpty() )
4233 switch ( msg
.GetId() )
4235 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
4237 size_t pos
= msg
.GetCommandInt();
4238 int numRows
= msg
.GetCommandInt2();
4240 m_numRows
+= numRows
;
4242 if ( !m_rowHeights
.IsEmpty() )
4244 m_rowHeights
.Insert( m_defaultRowHeight
, pos
, numRows
);
4245 m_rowBottoms
.Insert( 0, pos
, numRows
);
4248 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
4250 for ( i
= pos
; i
< m_numRows
; i
++ )
4252 bottom
+= m_rowHeights
[i
];
4253 m_rowBottoms
[i
] = bottom
;
4256 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4258 // if we have just inserted cols into an empty grid the current
4259 // cell will be undefined...
4261 SetCurrentCell( 0, 0 );
4265 m_selection
->UpdateRows( pos
, numRows
);
4266 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4268 attrProvider
->UpdateAttrRows( pos
, numRows
);
4270 if ( !GetBatchCount() )
4273 m_rowLabelWin
->Refresh();
4279 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
4281 int numRows
= msg
.GetCommandInt();
4282 int oldNumRows
= m_numRows
;
4283 m_numRows
+= numRows
;
4285 if ( !m_rowHeights
.IsEmpty() )
4287 m_rowHeights
.Add( m_defaultRowHeight
, numRows
);
4288 m_rowBottoms
.Add( 0, numRows
);
4291 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
4293 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
4295 bottom
+= m_rowHeights
[i
];
4296 m_rowBottoms
[i
] = bottom
;
4299 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4301 // if we have just inserted cols into an empty grid the current
4302 // cell will be undefined...
4304 SetCurrentCell( 0, 0 );
4306 if ( !GetBatchCount() )
4309 m_rowLabelWin
->Refresh();
4315 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
4317 size_t pos
= msg
.GetCommandInt();
4318 int numRows
= msg
.GetCommandInt2();
4319 m_numRows
-= numRows
;
4321 if ( !m_rowHeights
.IsEmpty() )
4323 m_rowHeights
.RemoveAt( pos
, numRows
);
4324 m_rowBottoms
.RemoveAt( pos
, numRows
);
4327 for ( i
= 0; i
< m_numRows
; i
++ )
4329 h
+= m_rowHeights
[i
];
4330 m_rowBottoms
[i
] = h
;
4335 m_currentCellCoords
= wxGridNoCellCoords
;
4339 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
4340 m_currentCellCoords
.Set( 0, 0 );
4344 m_selection
->UpdateRows( pos
, -((int)numRows
) );
4345 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4347 attrProvider
->UpdateAttrRows( pos
, -((int)numRows
) );
4348 // ifdef'd out following patch from Paul Gammans
4350 // No need to touch column attributes, unless we
4351 // removed _all_ rows, in this case, we remove
4352 // all column attributes.
4353 // I hate to do this here, but the
4354 // needed data is not available inside UpdateAttrRows.
4355 if ( !GetNumberRows() )
4356 attrProvider
->UpdateAttrCols( 0, -GetNumberCols() );
4359 if ( !GetBatchCount() )
4362 m_rowLabelWin
->Refresh();
4368 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
4370 size_t pos
= msg
.GetCommandInt();
4371 int numCols
= msg
.GetCommandInt2();
4372 m_numCols
+= numCols
;
4374 if ( !m_colWidths
.IsEmpty() )
4376 m_colWidths
.Insert( m_defaultColWidth
, pos
, numCols
);
4377 m_colRights
.Insert( 0, pos
, numCols
);
4380 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
4382 for ( i
= pos
; i
< m_numCols
; i
++ )
4384 right
+= m_colWidths
[i
];
4385 m_colRights
[i
] = right
;
4388 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4390 // if we have just inserted cols into an empty grid the current
4391 // cell will be undefined...
4393 SetCurrentCell( 0, 0 );
4397 m_selection
->UpdateCols( pos
, numCols
);
4398 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4400 attrProvider
->UpdateAttrCols( pos
, numCols
);
4401 if ( !GetBatchCount() )
4404 m_colLabelWin
->Refresh();
4411 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
4413 int numCols
= msg
.GetCommandInt();
4414 int oldNumCols
= m_numCols
;
4415 m_numCols
+= numCols
;
4416 if ( !m_colWidths
.IsEmpty() )
4418 m_colWidths
.Add( m_defaultColWidth
, numCols
);
4419 m_colRights
.Add( 0, numCols
);
4422 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
4424 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
4426 right
+= m_colWidths
[i
];
4427 m_colRights
[i
] = right
;
4430 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4432 // if we have just inserted cols into an empty grid the current
4433 // cell will be undefined...
4435 SetCurrentCell( 0, 0 );
4437 if ( !GetBatchCount() )
4440 m_colLabelWin
->Refresh();
4446 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
4448 size_t pos
= msg
.GetCommandInt();
4449 int numCols
= msg
.GetCommandInt2();
4450 m_numCols
-= numCols
;
4452 if ( !m_colWidths
.IsEmpty() )
4454 m_colWidths
.RemoveAt( pos
, numCols
);
4455 m_colRights
.RemoveAt( pos
, numCols
);
4458 for ( i
= 0; i
< m_numCols
; i
++ )
4460 w
+= m_colWidths
[i
];
4466 m_currentCellCoords
= wxGridNoCellCoords
;
4470 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
4471 m_currentCellCoords
.Set( 0, 0 );
4475 m_selection
->UpdateCols( pos
, -((int)numCols
) );
4476 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4478 attrProvider
->UpdateAttrCols( pos
, -((int)numCols
) );
4479 // ifdef'd out following patch from Paul Gammans
4481 // No need to touch row attributes, unless we
4482 // removed _all_ columns, in this case, we remove
4483 // all row attributes.
4484 // I hate to do this here, but the
4485 // needed data is not available inside UpdateAttrCols.
4486 if ( !GetNumberCols() )
4487 attrProvider
->UpdateAttrRows( 0, -GetNumberRows() );
4490 if ( !GetBatchCount() )
4493 m_colLabelWin
->Refresh();
4500 if (result
&& !GetBatchCount() )
4501 m_gridWin
->Refresh();
4506 wxArrayInt
wxGrid::CalcRowLabelsExposed( const wxRegion
& reg
)
4508 wxRegionIterator
iter( reg
);
4511 wxArrayInt rowlabels
;
4518 // TODO: remove this when we can...
4519 // There is a bug in wxMotif that gives garbage update
4520 // rectangles if you jump-scroll a long way by clicking the
4521 // scrollbar with middle button. This is a work-around
4523 #if defined(__WXMOTIF__)
4525 m_gridWin
->GetClientSize( &cw
, &ch
);
4526 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
4527 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
4530 // logical bounds of update region
4533 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
4534 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
4536 // find the row labels within these bounds
4539 for ( row
= internalYToRow(top
); row
< m_numRows
; row
++ )
4541 if ( GetRowBottom(row
) < top
)
4544 if ( GetRowTop(row
) > bottom
)
4547 rowlabels
.Add( row
);
4557 wxArrayInt
wxGrid::CalcColLabelsExposed( const wxRegion
& reg
)
4559 wxRegionIterator
iter( reg
);
4562 wxArrayInt colLabels
;
4569 // TODO: remove this when we can...
4570 // There is a bug in wxMotif that gives garbage update
4571 // rectangles if you jump-scroll a long way by clicking the
4572 // scrollbar with middle button. This is a work-around
4574 #if defined(__WXMOTIF__)
4576 m_gridWin
->GetClientSize( &cw
, &ch
);
4577 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
4578 r
.SetRight( wxMin( r
.GetRight(), cw
) );
4581 // logical bounds of update region
4584 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
4585 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
4587 // find the cells within these bounds
4590 for ( col
= internalXToCol(left
); col
< m_numCols
; col
++ )
4592 if ( GetColRight(col
) < left
)
4595 if ( GetColLeft(col
) > right
)
4598 colLabels
.Add( col
);
4607 wxGridCellCoordsArray
wxGrid::CalcCellsExposed( const wxRegion
& reg
)
4609 wxRegionIterator
iter( reg
);
4612 wxGridCellCoordsArray cellsExposed
;
4614 int left
, top
, right
, bottom
;
4619 // TODO: remove this when we can...
4620 // There is a bug in wxMotif that gives garbage update
4621 // rectangles if you jump-scroll a long way by clicking the
4622 // scrollbar with middle button. This is a work-around
4624 #if defined(__WXMOTIF__)
4626 m_gridWin
->GetClientSize( &cw
, &ch
);
4627 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
4628 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
4629 r
.SetRight( wxMin( r
.GetRight(), cw
) );
4630 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
4633 // logical bounds of update region
4635 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
4636 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
4638 // find the cells within these bounds
4641 for ( row
= internalYToRow(top
); row
< m_numRows
; row
++ )
4643 if ( GetRowBottom(row
) <= top
)
4646 if ( GetRowTop(row
) > bottom
)
4649 for ( col
= internalXToCol(left
); col
< m_numCols
; col
++ )
4651 if ( GetColRight(col
) <= left
)
4654 if ( GetColLeft(col
) > right
)
4657 cellsExposed
.Add( wxGridCellCoords( row
, col
) );
4664 return cellsExposed
;
4668 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
4671 wxPoint
pos( event
.GetPosition() );
4672 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
4674 if ( event
.Dragging() )
4678 m_isDragging
= TRUE
;
4679 m_rowLabelWin
->CaptureMouse();
4682 if ( event
.LeftIsDown() )
4684 switch( m_cursorMode
)
4686 case WXGRID_CURSOR_RESIZE_ROW
:
4688 int cw
, ch
, left
, dummy
;
4689 m_gridWin
->GetClientSize( &cw
, &ch
);
4690 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
4692 wxClientDC
dc( m_gridWin
);
4695 GetRowTop(m_dragRowOrCol
) +
4696 GetRowMinimalHeight(m_dragRowOrCol
) );
4697 dc
.SetLogicalFunction(wxINVERT
);
4698 if ( m_dragLastPos
>= 0 )
4700 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
4702 dc
.DrawLine( left
, y
, left
+cw
, y
);
4707 case WXGRID_CURSOR_SELECT_ROW
:
4708 if ( (row
= YToRow( y
)) >= 0 )
4712 m_selection
->SelectRow( row
,
4713 event
.ControlDown(),
4720 // default label to suppress warnings about "enumeration value
4721 // 'xxx' not handled in switch
4729 if ( m_isDragging
&& (event
.Entering() || event
.Leaving()) )
4734 if (m_rowLabelWin
->HasCapture()) m_rowLabelWin
->ReleaseMouse();
4735 m_isDragging
= FALSE
;
4738 // ------------ Entering or leaving the window
4740 if ( event
.Entering() || event
.Leaving() )
4742 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
4746 // ------------ Left button pressed
4748 else if ( event
.LeftDown() )
4750 // don't send a label click event for a hit on the
4751 // edge of the row label - this is probably the user
4752 // wanting to resize the row
4754 if ( YToEdgeOfRow(y
) < 0 )
4758 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
4760 if ( !event
.ShiftDown() && !event
.ControlDown() )
4764 if ( event
.ShiftDown() )
4766 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
4769 GetNumberCols() - 1,
4770 event
.ControlDown(),
4777 m_selection
->SelectRow( row
,
4778 event
.ControlDown(),
4785 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
4790 // starting to drag-resize a row
4792 if ( CanDragRowSize() )
4793 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
4798 // ------------ Left double click
4800 else if (event
.LeftDClick() )
4802 int row
= YToEdgeOfRow(y
);
4807 !SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
) )
4809 // no default action at the moment
4814 // adjust row height depending on label text
4815 AutoSizeRowLabelSize( row
);
4817 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
4823 // ------------ Left button released
4825 else if ( event
.LeftUp() )
4827 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
4829 DoEndDragResizeRow();
4831 // Note: we are ending the event *after* doing
4832 // default processing in this case
4834 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
4837 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
4842 // ------------ Right button down
4844 else if ( event
.RightDown() )
4848 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
4850 // no default action at the moment
4855 // ------------ Right double click
4857 else if ( event
.RightDClick() )
4861 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
4863 // no default action at the moment
4868 // ------------ No buttons down and mouse moving
4870 else if ( event
.Moving() )
4872 m_dragRowOrCol
= YToEdgeOfRow( y
);
4873 if ( m_dragRowOrCol
>= 0 )
4875 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4877 // don't capture the mouse yet
4878 if ( CanDragRowSize() )
4879 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, FALSE
);
4882 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
4884 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, FALSE
);
4890 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
4893 wxPoint
pos( event
.GetPosition() );
4894 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
4896 if ( event
.Dragging() )
4900 m_isDragging
= TRUE
;
4901 m_colLabelWin
->CaptureMouse();
4904 if ( event
.LeftIsDown() )
4906 switch( m_cursorMode
)
4908 case WXGRID_CURSOR_RESIZE_COL
:
4910 int cw
, ch
, dummy
, top
;
4911 m_gridWin
->GetClientSize( &cw
, &ch
);
4912 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
4914 wxClientDC
dc( m_gridWin
);
4917 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
4918 GetColMinimalWidth(m_dragRowOrCol
));
4919 dc
.SetLogicalFunction(wxINVERT
);
4920 if ( m_dragLastPos
>= 0 )
4922 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
4924 dc
.DrawLine( x
, top
, x
, top
+ch
);
4929 case WXGRID_CURSOR_SELECT_COL
:
4930 if ( (col
= XToCol( x
)) >= 0 )
4934 m_selection
->SelectCol( col
,
4935 event
.ControlDown(),
4942 // default label to suppress warnings about "enumeration value
4943 // 'xxx' not handled in switch
4951 if ( m_isDragging
&& (event
.Entering() || event
.Leaving()) )
4956 if (m_colLabelWin
->HasCapture()) m_colLabelWin
->ReleaseMouse();
4957 m_isDragging
= FALSE
;
4960 // ------------ Entering or leaving the window
4962 if ( event
.Entering() || event
.Leaving() )
4964 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
4968 // ------------ Left button pressed
4970 else if ( event
.LeftDown() )
4972 // don't send a label click event for a hit on the
4973 // edge of the col label - this is probably the user
4974 // wanting to resize the col
4976 if ( XToEdgeOfCol(x
) < 0 )
4980 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
4982 if ( !event
.ShiftDown() && !event
.ControlDown() )
4986 if ( event
.ShiftDown() )
4988 m_selection
->SelectBlock( 0,
4989 m_currentCellCoords
.GetCol(),
4990 GetNumberRows() - 1, col
,
4991 event
.ControlDown(),
4998 m_selection
->SelectCol( col
,
4999 event
.ControlDown(),
5006 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, m_colLabelWin
);
5011 // starting to drag-resize a col
5013 if ( CanDragColSize() )
5014 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
);
5019 // ------------ Left double click
5021 if ( event
.LeftDClick() )
5023 int col
= XToEdgeOfCol(x
);
5028 ! SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
) )
5030 // no default action at the moment
5035 // adjust column width depending on label text
5036 AutoSizeColLabelSize( col
);
5038 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
5044 // ------------ Left button released
5046 else if ( event
.LeftUp() )
5048 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5050 DoEndDragResizeCol();
5052 // Note: we are ending the event *after* doing
5053 // default processing in this case
5055 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
5058 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
5063 // ------------ Right button down
5065 else if ( event
.RightDown() )
5069 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
5071 // no default action at the moment
5076 // ------------ Right double click
5078 else if ( event
.RightDClick() )
5082 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
5084 // no default action at the moment
5089 // ------------ No buttons down and mouse moving
5091 else if ( event
.Moving() )
5093 m_dragRowOrCol
= XToEdgeOfCol( x
);
5094 if ( m_dragRowOrCol
>= 0 )
5096 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5098 // don't capture the cursor yet
5099 if ( CanDragColSize() )
5100 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
, FALSE
);
5103 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
5105 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
, FALSE
);
5111 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
5113 if ( event
.LeftDown() )
5115 // indicate corner label by having both row and
5118 if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
5124 else if ( event
.LeftDClick() )
5126 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
5129 else if ( event
.RightDown() )
5131 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
5133 // no default action at the moment
5137 else if ( event
.RightDClick() )
5139 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
5141 // no default action at the moment
5146 void wxGrid::ChangeCursorMode(CursorMode mode
,
5151 static const wxChar
*cursorModes
[] =
5160 wxLogTrace(_T("grid"),
5161 _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
5162 win
== m_colLabelWin
? _T("colLabelWin")
5163 : win
? _T("rowLabelWin")
5165 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
5166 #endif // __WXDEBUG__
5168 if ( mode
== m_cursorMode
&&
5169 win
== m_winCapture
&&
5170 captureMouse
== (m_winCapture
!= NULL
))
5175 // by default use the grid itself
5181 if (m_winCapture
->HasCapture()) m_winCapture
->ReleaseMouse();
5182 m_winCapture
= (wxWindow
*)NULL
;
5185 m_cursorMode
= mode
;
5187 switch ( m_cursorMode
)
5189 case WXGRID_CURSOR_RESIZE_ROW
:
5190 win
->SetCursor( m_rowResizeCursor
);
5193 case WXGRID_CURSOR_RESIZE_COL
:
5194 win
->SetCursor( m_colResizeCursor
);
5198 win
->SetCursor( *wxSTANDARD_CURSOR
);
5201 // we need to capture mouse when resizing
5202 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
5203 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
5205 if ( captureMouse
&& resize
)
5207 win
->CaptureMouse();
5212 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
5215 wxPoint
pos( event
.GetPosition() );
5216 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
5218 wxGridCellCoords coords
;
5219 XYToCell( x
, y
, coords
);
5221 int cell_rows
, cell_cols
;
5222 GetCellSize( coords
.GetRow(), coords
.GetCol(), &cell_rows
, &cell_cols
);
5223 if ((cell_rows
< 0) || (cell_cols
< 0))
5225 coords
.SetRow(coords
.GetRow() + cell_rows
);
5226 coords
.SetCol(coords
.GetCol() + cell_cols
);
5229 if ( event
.Dragging() )
5231 //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
5233 // Don't start doing anything until the mouse has been drug at
5234 // least 3 pixels in any direction...
5237 if (m_startDragPos
== wxDefaultPosition
)
5239 m_startDragPos
= pos
;
5242 if (abs(m_startDragPos
.x
- pos
.x
) < 4 && abs(m_startDragPos
.y
- pos
.y
) < 4)
5246 m_isDragging
= TRUE
;
5247 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5249 // Hide the edit control, so it
5250 // won't interfer with drag-shrinking.
5251 if ( IsCellEditControlShown() )
5253 HideCellEditControl();
5254 SaveEditControlValue();
5257 // Have we captured the mouse yet?
5260 m_winCapture
= m_gridWin
;
5261 m_winCapture
->CaptureMouse();
5264 if ( coords
!= wxGridNoCellCoords
)
5266 if ( event
.ControlDown() )
5268 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
5269 m_selectingKeyboard
= coords
;
5270 HighlightBlock ( m_selectingKeyboard
, coords
);
5274 if ( !IsSelection() )
5276 HighlightBlock( coords
, coords
);
5280 HighlightBlock( m_currentCellCoords
, coords
);
5284 if (! IsVisible(coords
))
5286 MakeCellVisible(coords
);
5287 // TODO: need to introduce a delay or something here. The
5288 // scrolling is way to fast, at least on MSW - also on GTK.
5292 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
5294 int cw
, ch
, left
, dummy
;
5295 m_gridWin
->GetClientSize( &cw
, &ch
);
5296 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
5298 wxClientDC
dc( m_gridWin
);
5300 y
= wxMax( y
, GetRowTop(m_dragRowOrCol
) +
5301 GetRowMinimalHeight(m_dragRowOrCol
) );
5302 dc
.SetLogicalFunction(wxINVERT
);
5303 if ( m_dragLastPos
>= 0 )
5305 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
5307 dc
.DrawLine( left
, y
, left
+cw
, y
);
5310 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5312 int cw
, ch
, dummy
, top
;
5313 m_gridWin
->GetClientSize( &cw
, &ch
);
5314 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
5316 wxClientDC
dc( m_gridWin
);
5318 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
5319 GetColMinimalWidth(m_dragRowOrCol
) );
5320 dc
.SetLogicalFunction(wxINVERT
);
5321 if ( m_dragLastPos
>= 0 )
5323 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
5325 dc
.DrawLine( x
, top
, x
, top
+ch
);
5332 m_isDragging
= FALSE
;
5333 m_startDragPos
= wxDefaultPosition
;
5335 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
5336 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
5339 if ( event
.Entering() || event
.Leaving() )
5341 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5342 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
5347 // ------------ Left button pressed
5349 if ( event
.LeftDown() && coords
!= wxGridNoCellCoords
)
5351 if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK
,
5356 if ( !event
.ControlDown() )
5358 if ( event
.ShiftDown() )
5362 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
5363 m_currentCellCoords
.GetCol(),
5366 event
.ControlDown(),
5372 else if ( XToEdgeOfCol(x
) < 0 &&
5373 YToEdgeOfRow(y
) < 0 )
5375 DisableCellEditControl();
5376 MakeCellVisible( coords
);
5378 if ( event
.ControlDown() )
5382 m_selection
->ToggleCellSelection( coords
.GetRow(),
5384 event
.ControlDown(),
5389 m_selectingTopLeft
= wxGridNoCellCoords
;
5390 m_selectingBottomRight
= wxGridNoCellCoords
;
5391 m_selectingKeyboard
= coords
;
5395 m_waitForSlowClick
= m_currentCellCoords
== coords
&& coords
!= wxGridNoCellCoords
;
5396 SetCurrentCell( coords
);
5399 if ( m_selection
->GetSelectionMode() !=
5400 wxGrid::wxGridSelectCells
)
5402 HighlightBlock( coords
, coords
);
5411 // ------------ Left double click
5413 else if ( event
.LeftDClick() && coords
!= wxGridNoCellCoords
)
5415 DisableCellEditControl();
5417 if ( XToEdgeOfCol(x
) < 0 && YToEdgeOfRow(y
) < 0 )
5419 SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK
,
5427 // ------------ Left button released
5429 else if ( event
.LeftUp() )
5431 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5435 if (m_winCapture
->HasCapture()) m_winCapture
->ReleaseMouse();
5436 m_winCapture
= NULL
;
5439 if ( coords
== m_currentCellCoords
&& m_waitForSlowClick
&& CanEnableCellControl())
5442 EnableCellEditControl();
5444 wxGridCellAttr
* attr
= GetCellAttr(coords
);
5445 wxGridCellEditor
*editor
= attr
->GetEditor(this, coords
.GetRow(), coords
.GetCol());
5446 editor
->StartingClick();
5450 m_waitForSlowClick
= FALSE
;
5452 else if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
5453 m_selectingBottomRight
!= wxGridNoCellCoords
)
5457 m_selection
->SelectBlock( m_selectingTopLeft
.GetRow(),
5458 m_selectingTopLeft
.GetCol(),
5459 m_selectingBottomRight
.GetRow(),
5460 m_selectingBottomRight
.GetCol(),
5461 event
.ControlDown(),
5467 m_selectingTopLeft
= wxGridNoCellCoords
;
5468 m_selectingBottomRight
= wxGridNoCellCoords
;
5470 // Show the edit control, if it has been hidden for
5472 ShowCellEditControl();
5475 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
5477 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5478 DoEndDragResizeRow();
5480 // Note: we are ending the event *after* doing
5481 // default processing in this case
5483 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
5485 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5487 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5488 DoEndDragResizeCol();
5490 // Note: we are ending the event *after* doing
5491 // default processing in this case
5493 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
5500 // ------------ Right button down
5502 else if ( event
.RightDown() && coords
!= wxGridNoCellCoords
)
5504 DisableCellEditControl();
5505 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK
,
5510 // no default action at the moment
5515 // ------------ Right double click
5517 else if ( event
.RightDClick() && coords
!= wxGridNoCellCoords
)
5519 DisableCellEditControl();
5520 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK
,
5525 // no default action at the moment
5529 // ------------ Moving and no button action
5531 else if ( event
.Moving() && !event
.IsButton() )
5533 if( coords
.GetRow() < 0 || coords
.GetCol() < 0 )
5535 // out of grid cell area
5536 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5540 int dragRow
= YToEdgeOfRow( y
);
5541 int dragCol
= XToEdgeOfCol( x
);
5543 // Dragging on the corner of a cell to resize in both
5544 // directions is not implemented yet...
5546 if ( dragRow
>= 0 && dragCol
>= 0 )
5548 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5554 m_dragRowOrCol
= dragRow
;
5556 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5558 if ( CanDragRowSize() && CanDragGridSize() )
5559 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
);
5564 m_dragRowOrCol
= dragCol
;
5572 m_dragRowOrCol
= dragCol
;
5574 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5576 if ( CanDragColSize() && CanDragGridSize() )
5577 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
);
5583 // Neither on a row or col edge
5585 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
5587 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5593 void wxGrid::DoEndDragResizeRow()
5595 if ( m_dragLastPos
>= 0 )
5597 // erase the last line and resize the row
5599 int cw
, ch
, left
, dummy
;
5600 m_gridWin
->GetClientSize( &cw
, &ch
);
5601 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
5603 wxClientDC
dc( m_gridWin
);
5605 dc
.SetLogicalFunction( wxINVERT
);
5606 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
5607 HideCellEditControl();
5608 SaveEditControlValue();
5610 int rowTop
= GetRowTop(m_dragRowOrCol
);
5611 SetRowSize( m_dragRowOrCol
,
5612 wxMax( m_dragLastPos
- rowTop
, m_minAcceptableRowHeight
) );
5614 if ( !GetBatchCount() )
5616 // Only needed to get the correct rect.y:
5617 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
5619 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
5620 rect
.width
= m_rowLabelWidth
;
5621 rect
.height
= ch
- rect
.y
;
5622 m_rowLabelWin
->Refresh( TRUE
, &rect
);
5624 // if there is a multicell block, paint all of it
5627 int i
, cell_rows
, cell_cols
, subtract_rows
= 0;
5628 int leftCol
= XToCol(left
);
5629 int rightCol
= internalXToCol(left
+cw
);
5632 for (i
=leftCol
; i
<rightCol
; i
++)
5634 GetCellSize(m_dragRowOrCol
, i
, &cell_rows
, &cell_cols
);
5635 if (cell_rows
< subtract_rows
)
5636 subtract_rows
= cell_rows
;
5638 rect
.y
= GetRowTop(m_dragRowOrCol
+ subtract_rows
);
5639 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
5640 rect
.height
= ch
- rect
.y
;
5643 m_gridWin
->Refresh( FALSE
, &rect
);
5646 ShowCellEditControl();
5651 void wxGrid::DoEndDragResizeCol()
5653 if ( m_dragLastPos
>= 0 )
5655 // erase the last line and resize the col
5657 int cw
, ch
, dummy
, top
;
5658 m_gridWin
->GetClientSize( &cw
, &ch
);
5659 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
5661 wxClientDC
dc( m_gridWin
);
5663 dc
.SetLogicalFunction( wxINVERT
);
5664 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
5665 HideCellEditControl();
5666 SaveEditControlValue();
5668 int colLeft
= GetColLeft(m_dragRowOrCol
);
5669 SetColSize( m_dragRowOrCol
,
5670 wxMax( m_dragLastPos
- colLeft
,
5671 GetColMinimalWidth(m_dragRowOrCol
) ) );
5673 if ( !GetBatchCount() )
5675 // Only needed to get the correct rect.x:
5676 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
5678 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
5679 rect
.width
= cw
- rect
.x
;
5680 rect
.height
= m_colLabelHeight
;
5681 m_colLabelWin
->Refresh( TRUE
, &rect
);
5683 // if there is a multicell block, paint all of it
5686 int i
, cell_rows
, cell_cols
, subtract_cols
= 0;
5687 int topRow
= YToRow(top
);
5688 int bottomRow
= internalYToRow(top
+cw
);
5691 for (i
=topRow
; i
<bottomRow
; i
++)
5693 GetCellSize(i
, m_dragRowOrCol
, &cell_rows
, &cell_cols
);
5694 if (cell_cols
< subtract_cols
)
5695 subtract_cols
= cell_cols
;
5697 rect
.x
= GetColLeft(m_dragRowOrCol
+ subtract_cols
);
5698 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
5699 rect
.width
= cw
- rect
.x
;
5702 m_gridWin
->Refresh( FALSE
, &rect
);
5705 ShowCellEditControl();
5712 // ------ interaction with data model
5714 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
5716 switch ( msg
.GetId() )
5718 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
5719 return GetModelValues();
5721 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
5722 return SetModelValues();
5724 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
5725 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
5726 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
5727 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
5728 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
5729 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
5730 return Redimension( msg
);
5739 // The behaviour of this function depends on the grid table class
5740 // Clear() function. For the default wxGridStringTable class the
5741 // behavious is to replace all cell contents with wxEmptyString but
5742 // not to change the number of rows or cols.
5744 void wxGrid::ClearGrid()
5748 if (IsCellEditControlEnabled())
5749 DisableCellEditControl();
5752 if ( !GetBatchCount() ) m_gridWin
->Refresh();
5757 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
5759 // TODO: something with updateLabels flag
5763 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
5769 if (IsCellEditControlEnabled())
5770 DisableCellEditControl();
5772 bool done
= m_table
->InsertRows( pos
, numRows
);
5773 m_numRows
= m_table
->GetNumberRows();
5776 // the table will have sent the results of the insert row
5777 // operation to this view object as a grid table message
5783 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
5785 // TODO: something with updateLabels flag
5789 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
5795 bool done
= m_table
&& m_table
->AppendRows( numRows
);
5796 m_numRows
= m_table
->GetNumberRows();
5798 // the table will have sent the results of the append row
5799 // operation to this view object as a grid table message
5805 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
5807 // TODO: something with updateLabels flag
5811 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
5817 if (IsCellEditControlEnabled())
5818 DisableCellEditControl();
5820 bool done
= m_table
->DeleteRows( pos
, numRows
);
5821 m_numRows
= m_table
->GetNumberRows();
5823 // the table will have sent the results of the delete row
5824 // operation to this view object as a grid table message
5830 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
5832 // TODO: something with updateLabels flag
5836 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
5842 if (IsCellEditControlEnabled())
5843 DisableCellEditControl();
5845 bool done
= m_table
->InsertCols( pos
, numCols
);
5846 m_numCols
= m_table
->GetNumberCols();
5848 // the table will have sent the results of the insert col
5849 // operation to this view object as a grid table message
5855 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
5857 // TODO: something with updateLabels flag
5861 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
5867 bool done
= m_table
->AppendCols( numCols
);
5868 m_numCols
= m_table
->GetNumberCols();
5870 // the table will have sent the results of the append col
5871 // operation to this view object as a grid table message
5877 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
5879 // TODO: something with updateLabels flag
5883 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
5889 if (IsCellEditControlEnabled())
5890 DisableCellEditControl();
5892 bool done
= m_table
->DeleteCols( pos
, numCols
);
5893 m_numCols
= m_table
->GetNumberCols();
5895 // the table will have sent the results of the delete col
5896 // operation to this view object as a grid table message
5904 // ----- event handlers
5907 // Generate a grid event based on a mouse event and
5908 // return the result of ProcessEvent()
5910 int wxGrid::SendEvent( const wxEventType type
,
5912 wxMouseEvent
& mouseEv
)
5917 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
5919 int rowOrCol
= (row
== -1 ? col
: row
);
5921 wxGridSizeEvent
gridEvt( GetId(),
5925 mouseEv
.GetX() + GetRowLabelSize(),
5926 mouseEv
.GetY() + GetColLabelSize(),
5927 mouseEv
.ControlDown(),
5928 mouseEv
.ShiftDown(),
5930 mouseEv
.MetaDown() );
5932 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5933 vetoed
= !gridEvt
.IsAllowed();
5935 else if ( type
== wxEVT_GRID_RANGE_SELECT
)
5937 // Right now, it should _never_ end up here!
5938 wxGridRangeSelectEvent
gridEvt( GetId(),
5942 m_selectingBottomRight
,
5944 mouseEv
.ControlDown(),
5945 mouseEv
.ShiftDown(),
5947 mouseEv
.MetaDown() );
5949 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5950 vetoed
= !gridEvt
.IsAllowed();
5954 wxGridEvent
gridEvt( GetId(),
5958 mouseEv
.GetX() + GetRowLabelSize(),
5959 mouseEv
.GetY() + GetColLabelSize(),
5961 mouseEv
.ControlDown(),
5962 mouseEv
.ShiftDown(),
5964 mouseEv
.MetaDown() );
5965 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5966 vetoed
= !gridEvt
.IsAllowed();
5969 // A Veto'd event may not be `claimed' so test this first
5970 if (vetoed
) return -1;
5971 return claimed
? 1 : 0;
5975 // Generate a grid event of specified type and return the result
5976 // of ProcessEvent().
5978 int wxGrid::SendEvent( const wxEventType type
,
5984 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
5986 int rowOrCol
= (row
== -1 ? col
: row
);
5988 wxGridSizeEvent
gridEvt( GetId(),
5993 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5994 vetoed
= !gridEvt
.IsAllowed();
5998 wxGridEvent
gridEvt( GetId(),
6003 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
6004 vetoed
= !gridEvt
.IsAllowed();
6007 // A Veto'd event may not be `claimed' so test this first
6008 if (vetoed
) return -1;
6009 return claimed
? 1 : 0;
6013 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
6015 wxPaintDC
dc(this); // needed to prevent zillions of paint events on MSW
6018 void wxGrid::Refresh(bool eraseb
, const wxRect
* rect
)
6020 // Don't do anything if between Begin/EndBatch...
6021 // EndBatch() will do all this on the last nested one anyway.
6022 if (! GetBatchCount())
6024 // Refresh to get correct scrolled position:
6025 wxScrolledWindow::Refresh(eraseb
,rect
);
6029 int rect_x
, rect_y
, rectWidth
, rectHeight
;
6030 int width_label
, width_cell
, height_label
, height_cell
;
6033 //Copy rectangle can get scroll offsets..
6034 rect_x
= rect
->GetX();
6035 rect_y
= rect
->GetY();
6036 rectWidth
= rect
->GetWidth();
6037 rectHeight
= rect
->GetHeight();
6039 width_label
= m_rowLabelWidth
- rect_x
;
6040 if (width_label
> rectWidth
) width_label
= rectWidth
;
6042 height_label
= m_colLabelHeight
- rect_y
;
6043 if (height_label
> rectHeight
) height_label
= rectHeight
;
6045 if (rect_x
> m_rowLabelWidth
)
6047 x
= rect_x
- m_rowLabelWidth
;
6048 width_cell
= rectWidth
;
6053 width_cell
= rectWidth
- (m_rowLabelWidth
- rect_x
);
6056 if (rect_y
> m_colLabelHeight
)
6058 y
= rect_y
- m_colLabelHeight
;
6059 height_cell
= rectHeight
;
6064 height_cell
= rectHeight
- (m_colLabelHeight
- rect_y
);
6067 // Paint corner label part intersecting rect.
6068 if ( width_label
> 0 && height_label
> 0 )
6070 wxRect
anotherrect(rect_x
, rect_y
, width_label
, height_label
);
6071 m_cornerLabelWin
->Refresh(eraseb
, &anotherrect
);
6074 // Paint col labels part intersecting rect.
6075 if ( width_cell
> 0 && height_label
> 0 )
6077 wxRect
anotherrect(x
, rect_y
, width_cell
, height_label
);
6078 m_colLabelWin
->Refresh(eraseb
, &anotherrect
);
6081 // Paint row labels part intersecting rect.
6082 if ( width_label
> 0 && height_cell
> 0 )
6084 wxRect
anotherrect(rect_x
, y
, width_label
, height_cell
);
6085 m_rowLabelWin
->Refresh(eraseb
, &anotherrect
);
6088 // Paint cell area part intersecting rect.
6089 if ( width_cell
> 0 && height_cell
> 0 )
6091 wxRect
anotherrect(x
, y
, width_cell
, height_cell
);
6092 m_gridWin
->Refresh(eraseb
, &anotherrect
);
6097 m_cornerLabelWin
->Refresh(eraseb
, NULL
);
6098 m_colLabelWin
->Refresh(eraseb
, NULL
);
6099 m_rowLabelWin
->Refresh(eraseb
, NULL
);
6100 m_gridWin
->Refresh(eraseb
, NULL
);
6105 void wxGrid::OnSize( wxSizeEvent
& event
)
6107 // position the child windows
6110 // don't call CalcDimensions() from here, the base class handles the size
6116 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
6118 if ( m_inOnKeyDown
)
6120 // shouldn't be here - we are going round in circles...
6122 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
6125 m_inOnKeyDown
= TRUE
;
6127 // propagate the event up and see if it gets processed
6129 wxWindow
*parent
= GetParent();
6130 wxKeyEvent
keyEvt( event
);
6131 keyEvt
.SetEventObject( parent
);
6133 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
6136 // try local handlers
6138 switch ( event
.GetKeyCode() )
6141 if ( event
.ControlDown() )
6143 MoveCursorUpBlock( event
.ShiftDown() );
6147 MoveCursorUp( event
.ShiftDown() );
6152 if ( event
.ControlDown() )
6154 MoveCursorDownBlock( event
.ShiftDown() );
6158 MoveCursorDown( event
.ShiftDown() );
6163 if ( event
.ControlDown() )
6165 MoveCursorLeftBlock( event
.ShiftDown() );
6169 MoveCursorLeft( event
.ShiftDown() );
6174 if ( event
.ControlDown() )
6176 MoveCursorRightBlock( event
.ShiftDown() );
6180 MoveCursorRight( event
.ShiftDown() );
6185 case WXK_NUMPAD_ENTER
:
6186 if ( event
.ControlDown() )
6188 event
.Skip(); // to let the edit control have the return
6192 if ( GetGridCursorRow() < GetNumberRows()-1 )
6194 MoveCursorDown( event
.ShiftDown() );
6198 // at the bottom of a column
6199 HideCellEditControl();
6200 SaveEditControlValue();
6210 if (event
.ShiftDown())
6212 if ( GetGridCursorCol() > 0 )
6214 MoveCursorLeft( FALSE
);
6219 HideCellEditControl();
6220 SaveEditControlValue();
6225 if ( GetGridCursorCol() < GetNumberCols()-1 )
6227 MoveCursorRight( FALSE
);
6232 HideCellEditControl();
6233 SaveEditControlValue();
6239 if ( event
.ControlDown() )
6241 MakeCellVisible( 0, 0 );
6242 SetCurrentCell( 0, 0 );
6251 if ( event
.ControlDown() )
6253 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
6254 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
6271 if ( event
.ControlDown() )
6275 m_selection
->ToggleCellSelection( m_currentCellCoords
.GetRow(),
6276 m_currentCellCoords
.GetCol(),
6277 event
.ControlDown(),
6284 if ( !IsEditable() )
6286 MoveCursorRight( FALSE
);
6289 // Otherwise fall through to default
6292 // is it possible to edit the current cell at all?
6293 if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
6295 // yes, now check whether the cells editor accepts the key
6296 int row
= m_currentCellCoords
.GetRow();
6297 int col
= m_currentCellCoords
.GetCol();
6298 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6299 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
6301 // <F2> is special and will always start editing, for
6302 // other keys - ask the editor itself
6303 if ( (event
.GetKeyCode() == WXK_F2
&& !event
.HasModifiers())
6304 || editor
->IsAcceptedKey(event
) )
6306 // ensure cell is visble
6307 MakeCellVisible(row
, col
);
6308 EnableCellEditControl();
6310 // a problem can arise if the cell is not completely
6311 // visible (even after calling MakeCellVisible the
6312 // control is not created and calling StartingKey will
6314 if( editor
->IsCreated() && m_cellEditCtrlEnabled
) editor
->StartingKey(event
);
6326 // let others process char events with modifiers or all
6327 // char events for readonly cells
6334 m_inOnKeyDown
= FALSE
;
6337 void wxGrid::OnKeyUp( wxKeyEvent
& event
)
6339 // try local handlers
6341 if ( event
.GetKeyCode() == WXK_SHIFT
)
6343 if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
6344 m_selectingBottomRight
!= wxGridNoCellCoords
)
6348 m_selection
->SelectBlock( m_selectingTopLeft
.GetRow(),
6349 m_selectingTopLeft
.GetCol(),
6350 m_selectingBottomRight
.GetRow(),
6351 m_selectingBottomRight
.GetCol(),
6352 event
.ControlDown(),
6359 m_selectingTopLeft
= wxGridNoCellCoords
;
6360 m_selectingBottomRight
= wxGridNoCellCoords
;
6361 m_selectingKeyboard
= wxGridNoCellCoords
;
6365 void wxGrid::OnEraseBackground(wxEraseEvent
&)
6369 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
6371 if ( SendEvent( wxEVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
6373 // the event has been intercepted - do nothing
6377 wxClientDC
dc(m_gridWin
);
6380 if ( m_currentCellCoords
!= wxGridNoCellCoords
)
6382 HideCellEditControl();
6383 DisableCellEditControl();
6385 if ( IsVisible( m_currentCellCoords
, FALSE
) )
6388 r
= BlockToDeviceRect(m_currentCellCoords
, m_currentCellCoords
);
6389 if ( !m_gridLinesEnabled
)
6397 wxGridCellCoordsArray cells
= CalcCellsExposed( r
);
6399 // Otherwise refresh redraws the highlight!
6400 m_currentCellCoords
= coords
;
6402 DrawGridCellArea(dc
,cells
);
6403 DrawAllGridLines( dc
, r
);
6407 m_currentCellCoords
= coords
;
6409 wxGridCellAttr
* attr
= GetCellAttr(coords
);
6410 DrawCellHighlight(dc
, attr
);
6415 void wxGrid::HighlightBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
6418 wxGridCellCoords updateTopLeft
, updateBottomRight
;
6422 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectRows
)
6425 rightCol
= GetNumberCols() - 1;
6427 else if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectColumns
)
6430 bottomRow
= GetNumberRows() - 1;
6434 if ( topRow
> bottomRow
)
6441 if ( leftCol
> rightCol
)
6448 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
6449 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
6451 // First the case that we selected a completely new area
6452 if ( m_selectingTopLeft
== wxGridNoCellCoords
||
6453 m_selectingBottomRight
== wxGridNoCellCoords
)
6456 rect
= BlockToDeviceRect( wxGridCellCoords ( topRow
, leftCol
),
6457 wxGridCellCoords ( bottomRow
, rightCol
) );
6458 m_gridWin
->Refresh( FALSE
, &rect
);
6460 // Now handle changing an existing selection area.
6461 else if ( m_selectingTopLeft
!= updateTopLeft
||
6462 m_selectingBottomRight
!= updateBottomRight
)
6464 // Compute two optimal update rectangles:
6465 // Either one rectangle is a real subset of the
6466 // other, or they are (almost) disjoint!
6468 bool need_refresh
[4];
6472 need_refresh
[3] = FALSE
;
6475 // Store intermediate values
6476 wxCoord oldLeft
= m_selectingTopLeft
.GetCol();
6477 wxCoord oldTop
= m_selectingTopLeft
.GetRow();
6478 wxCoord oldRight
= m_selectingBottomRight
.GetCol();
6479 wxCoord oldBottom
= m_selectingBottomRight
.GetRow();
6481 // Determine the outer/inner coordinates.
6482 if (oldLeft
> leftCol
)
6488 if (oldTop
> topRow
)
6494 if (oldRight
< rightCol
)
6497 oldRight
= rightCol
;
6500 if (oldBottom
< bottomRow
)
6503 oldBottom
= bottomRow
;
6507 // Now, either the stuff marked old is the outer
6508 // rectangle or we don't have a situation where one
6509 // is contained in the other.
6511 if ( oldLeft
< leftCol
)
6513 // Refresh the newly selected or deselected
6514 // area to the left of the old or new selection.
6515 need_refresh
[0] = TRUE
;
6516 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6518 wxGridCellCoords ( oldBottom
,
6522 if ( oldTop
< topRow
)
6524 // Refresh the newly selected or deselected
6525 // area above the old or new selection.
6526 need_refresh
[1] = TRUE
;
6527 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6529 wxGridCellCoords ( topRow
- 1,
6533 if ( oldRight
> rightCol
)
6535 // Refresh the newly selected or deselected
6536 // area to the right of the old or new selection.
6537 need_refresh
[2] = TRUE
;
6538 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6540 wxGridCellCoords ( oldBottom
,
6544 if ( oldBottom
> bottomRow
)
6546 // Refresh the newly selected or deselected
6547 // area below the old or new selection.
6548 need_refresh
[3] = TRUE
;
6549 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
6551 wxGridCellCoords ( oldBottom
,
6555 // various Refresh() calls
6556 for (i
= 0; i
< 4; i
++ )
6557 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
6558 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
6561 m_selectingTopLeft
= updateTopLeft
;
6562 m_selectingBottomRight
= updateBottomRight
;
6566 // ------ functions to get/send data (see also public functions)
6569 bool wxGrid::GetModelValues()
6571 // Hide the editor, so it won't hide a changed value.
6572 HideCellEditControl();
6576 // all we need to do is repaint the grid
6578 m_gridWin
->Refresh();
6586 bool wxGrid::SetModelValues()
6590 // Disable the editor, so it won't hide a changed value.
6591 // Do we also want to save the current value of the editor first?
6593 DisableCellEditControl();
6597 for ( row
= 0; row
< m_numRows
; row
++ )
6599 for ( col
= 0; col
< m_numCols
; col
++ )
6601 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
6613 // Note - this function only draws cells that are in the list of
6614 // exposed cells (usually set from the update region by
6615 // CalcExposedCells)
6617 void wxGrid::DrawGridCellArea( wxDC
& dc
, const wxGridCellCoordsArray
& cells
)
6619 if ( !m_numRows
|| !m_numCols
) return;
6621 int i
, numCells
= cells
.GetCount();
6622 int row
, col
, cell_rows
, cell_cols
;
6623 wxGridCellCoordsArray redrawCells
;
6625 for ( i
= numCells
-1; i
>= 0; i
-- )
6627 row
= cells
[i
].GetRow();
6628 col
= cells
[i
].GetCol();
6629 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
6631 // If this cell is part of a multicell block, find owner for repaint
6632 if ( cell_rows
<= 0 || cell_cols
<= 0 )
6634 wxGridCellCoords
cell(row
+cell_rows
, col
+cell_cols
);
6635 bool marked
= FALSE
;
6636 for ( int j
= 0; j
< numCells
; j
++ )
6638 if ( cell
== cells
[j
] )
6646 int count
= redrawCells
.GetCount();
6647 for (int j
= 0; j
< count
; j
++)
6649 if ( cell
== redrawCells
[j
] )
6655 if (!marked
) redrawCells
.Add( cell
);
6657 continue; // don't bother drawing this cell
6660 // If this cell is empty, find cell to left that might want to overflow
6661 if (m_table
&& m_table
->IsEmptyCell(row
, col
))
6663 for ( int l
= 0; l
< cell_rows
; l
++ )
6665 // find a cell in this row to left alreay marked for repaint
6667 for (int k
= 0; k
< int(redrawCells
.GetCount()); k
++)
6668 if ((redrawCells
[k
].GetCol() < left
) &&
6669 (redrawCells
[k
].GetRow() == row
))
6670 left
=redrawCells
[k
].GetCol();
6672 if (left
== col
) left
= 0; // oh well
6674 for (int j
= col
-1; j
>= left
; j
--)
6676 if (!m_table
->IsEmptyCell(row
+l
, j
))
6678 if (GetCellOverflow(row
+l
, j
))
6680 wxGridCellCoords
cell(row
+l
, j
);
6681 bool marked
= FALSE
;
6683 for (int k
= 0; k
< numCells
; k
++)
6685 if ( cell
== cells
[k
] )
6693 int count
= redrawCells
.GetCount();
6694 for (int k
= 0; k
< count
; k
++)
6696 if ( cell
== redrawCells
[k
] )
6702 if (!marked
) redrawCells
.Add( cell
);
6710 DrawCell( dc
, cells
[i
] );
6713 numCells
= redrawCells
.GetCount();
6715 for ( i
= numCells
- 1; i
>= 0; i
-- )
6717 DrawCell( dc
, redrawCells
[i
] );
6722 void wxGrid::DrawGridSpace( wxDC
& dc
)
6725 m_gridWin
->GetClientSize( &cw
, &ch
);
6728 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6730 int rightCol
= m_numCols
> 0 ? GetColRight(m_numCols
- 1) : 0;
6731 int bottomRow
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) : 0 ;
6733 if ( right
> rightCol
|| bottom
> bottomRow
)
6736 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6738 dc
.SetBrush( wxBrush(GetDefaultCellBackgroundColour(), wxSOLID
) );
6739 dc
.SetPen( *wxTRANSPARENT_PEN
);
6741 if ( right
> rightCol
)
6743 dc
.DrawRectangle( rightCol
, top
, right
- rightCol
, ch
);
6746 if ( bottom
> bottomRow
)
6748 dc
.DrawRectangle( left
, bottomRow
, cw
, bottom
- bottomRow
);
6754 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
6756 int row
= coords
.GetRow();
6757 int col
= coords
.GetCol();
6759 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6762 // we draw the cell border ourselves
6763 #if !WXGRID_DRAW_LINES
6764 if ( m_gridLinesEnabled
)
6765 DrawCellBorder( dc
, coords
);
6768 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6770 bool isCurrent
= coords
== m_currentCellCoords
;
6772 wxRect rect
= CellToRect( row
, col
);
6774 // if the editor is shown, we should use it and not the renderer
6775 // Note: However, only if it is really _shown_, i.e. not hidden!
6776 if ( isCurrent
&& IsCellEditControlShown() )
6778 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
6779 editor
->PaintBackground(rect
, attr
);
6784 // but all the rest is drawn by the cell renderer and hence may be
6786 wxGridCellRenderer
*renderer
= attr
->GetRenderer(this, row
, col
);
6787 renderer
->Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
6794 void wxGrid::DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
)
6796 int row
= m_currentCellCoords
.GetRow();
6797 int col
= m_currentCellCoords
.GetCol();
6799 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6802 wxRect rect
= CellToRect(row
, col
);
6804 // hmmm... what could we do here to show that the cell is disabled?
6805 // for now, I just draw a thinner border than for the other ones, but
6806 // it doesn't look really good
6808 int penWidth
= attr
->IsReadOnly() ? m_cellHighlightROPenWidth
: m_cellHighlightPenWidth
;
6812 // The center of th drawn line is where the position/width/height of
6813 // the rectangle is actually at, (on wxMSW atr least,) so we will
6814 // reduce the size of the rectangle to compensate for the thickness of
6815 // the line. If this is too strange on non wxMSW platforms then
6816 // please #ifdef this appropriately.
6817 rect
.x
+= penWidth
/2;
6818 rect
.y
+= penWidth
/2;
6819 rect
.width
-= penWidth
-1;
6820 rect
.height
-= penWidth
-1;
6823 // Now draw the rectangle
6824 // use the cellHighlightColour if the cell is inside a selection, this
6825 // will ensure the cell is always visible.
6826 dc
.SetPen(wxPen(IsInSelection(row
,col
)?m_selectionForeground
:m_cellHighlightColour
, penWidth
, wxSOLID
));
6827 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
6828 dc
.DrawRectangle(rect
);
6832 // VZ: my experiments with 3d borders...
6834 // how to properly set colours for arbitrary bg?
6835 wxCoord x1
= rect
.x
,
6837 x2
= rect
.x
+ rect
.width
-1,
6838 y2
= rect
.y
+ rect
.height
-1;
6840 dc
.SetPen(*wxWHITE_PEN
);
6841 dc
.DrawLine(x1
, y1
, x2
, y1
);
6842 dc
.DrawLine(x1
, y1
, x1
, y2
);
6844 dc
.DrawLine(x1
+ 1, y2
- 1, x2
- 1, y2
- 1);
6845 dc
.DrawLine(x2
- 1, y1
+ 1, x2
- 1, y2
);
6847 dc
.SetPen(*wxBLACK_PEN
);
6848 dc
.DrawLine(x1
, y2
, x2
, y2
);
6849 dc
.DrawLine(x2
, y1
, x2
, y2
+1);
6854 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
6856 int row
= coords
.GetRow();
6857 int col
= coords
.GetCol();
6858 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6861 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
6863 wxRect rect
= CellToRect( row
, col
);
6865 // right hand border
6867 dc
.DrawLine( rect
.x
+ rect
.width
, rect
.y
,
6868 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
+ 1 );
6872 dc
.DrawLine( rect
.x
, rect
.y
+ rect
.height
,
6873 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
6876 void wxGrid::DrawHighlight(wxDC
& dc
,const wxGridCellCoordsArray
& cells
)
6878 // This if block was previously in wxGrid::OnPaint but that doesn't
6879 // seem to get called under wxGTK - MB
6881 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
6882 m_numRows
&& m_numCols
)
6884 m_currentCellCoords
.Set(0, 0);
6887 if ( IsCellEditControlShown() )
6889 // don't show highlight when the edit control is shown
6893 // if the active cell was repainted, repaint its highlight too because it
6894 // might have been damaged by the grid lines
6895 size_t count
= cells
.GetCount();
6896 for ( size_t n
= 0; n
< count
; n
++ )
6898 if ( cells
[n
] == m_currentCellCoords
)
6900 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
6901 DrawCellHighlight(dc
, attr
);
6909 // TODO: remove this ???
6910 // This is used to redraw all grid lines e.g. when the grid line colour
6913 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& WXUNUSED(reg
) )
6915 #if !WXGRID_DRAW_LINES
6919 if ( !m_gridLinesEnabled
||
6921 !m_numCols
) return;
6923 int top
, bottom
, left
, right
;
6925 #if 0 //#ifndef __WXGTK__
6929 m_gridWin
->GetClientSize(&cw
, &ch
);
6931 // virtual coords of visible area
6933 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6934 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6939 reg
.GetBox(x
, y
, w
, h
);
6940 CalcUnscrolledPosition( x
, y
, &left
, &top
);
6941 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
6945 m_gridWin
->GetClientSize(&cw
, &ch
);
6946 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6947 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6950 // avoid drawing grid lines past the last row and col
6952 right
= wxMin( right
, GetColRight(m_numCols
- 1) );
6953 bottom
= wxMin( bottom
, GetRowBottom(m_numRows
- 1) );
6955 // no gridlines inside multicells, clip them out
6956 int leftCol
= internalXToCol(left
);
6957 int topRow
= internalYToRow(top
);
6958 int rightCol
= internalXToCol(right
);
6959 int bottomRow
= internalYToRow(bottom
);
6960 wxRegion
clippedcells(0, 0, cw
, ch
);
6963 int i
, j
, cell_rows
, cell_cols
;
6966 for (j
=topRow
; j
<bottomRow
; j
++)
6968 for (i
=leftCol
; i
<rightCol
; i
++)
6970 GetCellSize( j
, i
, &cell_rows
, &cell_cols
);
6971 if ((cell_rows
> 1) || (cell_cols
> 1))
6973 rect
= CellToRect(j
,i
);
6974 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
6975 clippedcells
.Subtract(rect
);
6977 else if ((cell_rows
< 0) || (cell_cols
< 0))
6979 rect
= CellToRect(j
+cell_rows
, i
+cell_cols
);
6980 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
6981 clippedcells
.Subtract(rect
);
6985 dc
.SetClippingRegion( clippedcells
);
6987 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
6989 // horizontal grid lines
6991 // already declared above - int i;
6992 for ( i
= internalYToRow(top
); i
< m_numRows
; i
++ )
6994 int bot
= GetRowBottom(i
) - 1;
7003 dc
.DrawLine( left
, bot
, right
, bot
);
7008 // vertical grid lines
7010 for ( i
= internalXToCol(left
); i
< m_numCols
; i
++ )
7012 int colRight
= GetColRight(i
) - 1;
7013 if ( colRight
> right
)
7018 if ( colRight
>= left
)
7020 dc
.DrawLine( colRight
, top
, colRight
, bottom
);
7023 dc
.DestroyClippingRegion();
7027 void wxGrid::DrawRowLabels( wxDC
& dc
,const wxArrayInt
& rows
)
7029 if ( !m_numRows
) return;
7032 size_t numLabels
= rows
.GetCount();
7034 for ( i
= 0; i
< numLabels
; i
++ )
7036 DrawRowLabel( dc
, rows
[i
] );
7041 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
7043 if ( GetRowHeight(row
) <= 0 )
7046 int rowTop
= GetRowTop(row
),
7047 rowBottom
= GetRowBottom(row
) - 1;
7049 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
),1, wxSOLID
) );
7050 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
7051 m_rowLabelWidth
-1, rowBottom
);
7053 dc
.DrawLine( 0, rowTop
, 0, rowBottom
);
7055 dc
.DrawLine( 0, rowBottom
, m_rowLabelWidth
, rowBottom
);
7057 dc
.SetPen( *wxWHITE_PEN
);
7058 dc
.DrawLine( 1, rowTop
, 1, rowBottom
);
7059 dc
.DrawLine( 1, rowTop
, m_rowLabelWidth
-1, rowTop
);
7061 dc
.SetBackgroundMode( wxTRANSPARENT
);
7062 dc
.SetTextForeground( GetLabelTextColour() );
7063 dc
.SetFont( GetLabelFont() );
7066 GetRowLabelAlignment( &hAlign
, &vAlign
);
7070 rect
.SetY( GetRowTop(row
) + 2 );
7071 rect
.SetWidth( m_rowLabelWidth
- 4 );
7072 rect
.SetHeight( GetRowHeight(row
) - 4 );
7073 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
7077 void wxGrid::DrawColLabels( wxDC
& dc
,const wxArrayInt
& cols
)
7079 if ( !m_numCols
) return;
7082 size_t numLabels
= cols
.GetCount();
7084 for ( i
= 0; i
< numLabels
; i
++ )
7086 DrawColLabel( dc
, cols
[i
] );
7091 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
7093 if ( GetColWidth(col
) <= 0 )
7096 int colLeft
= GetColLeft(col
),
7097 colRight
= GetColRight(col
) - 1;
7099 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
),1, wxSOLID
) );
7100 dc
.DrawLine( colRight
, 0,
7101 colRight
, m_colLabelHeight
-1 );
7103 dc
.DrawLine( colLeft
, 0, colRight
, 0 );
7105 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
7106 colRight
+1, m_colLabelHeight
-1 );
7108 dc
.SetPen( *wxWHITE_PEN
);
7109 dc
.DrawLine( colLeft
, 1, colLeft
, m_colLabelHeight
-1 );
7110 dc
.DrawLine( colLeft
, 1, colRight
, 1 );
7112 dc
.SetBackgroundMode( wxTRANSPARENT
);
7113 dc
.SetTextForeground( GetLabelTextColour() );
7114 dc
.SetFont( GetLabelFont() );
7116 int hAlign
, vAlign
, orient
;
7117 GetColLabelAlignment( &hAlign
, &vAlign
);
7118 orient
= GetColLabelTextOrientation();
7121 rect
.SetX( colLeft
+ 2 );
7123 rect
.SetWidth( GetColWidth(col
) - 4 );
7124 rect
.SetHeight( m_colLabelHeight
- 4 );
7125 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
, orient
);
7128 void wxGrid::DrawTextRectangle( wxDC
& dc
,
7129 const wxString
& value
,
7133 int textOrientation
)
7135 wxArrayString lines
;
7137 StringToLines( value
, lines
);
7140 //Forward to new API.
7141 DrawTextRectangle( dc
,
7150 void wxGrid::DrawTextRectangle( wxDC
& dc
,
7151 const wxArrayString
& lines
,
7155 int textOrientation
)
7157 long textWidth
, textHeight
;
7158 long lineWidth
, lineHeight
;
7161 dc
.SetClippingRegion( rect
);
7163 nLines
= lines
.GetCount();
7167 float x
= 0.0, y
= 0.0;
7169 if( textOrientation
== wxHORIZONTAL
)
7170 GetTextBoxSize(dc
, lines
, &textWidth
, &textHeight
);
7172 GetTextBoxSize( dc
, lines
, &textHeight
, &textWidth
);
7176 case wxALIGN_BOTTOM
:
7177 if( textOrientation
== wxHORIZONTAL
)
7178 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
7180 x
= rect
.x
+ rect
.width
- textWidth
;
7183 case wxALIGN_CENTRE
:
7184 if( textOrientation
== wxHORIZONTAL
)
7185 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
7187 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
7192 if( textOrientation
== wxHORIZONTAL
)
7199 // Align each line of a multi-line label
7200 for( l
= 0; l
< nLines
; l
++ )
7202 dc
.GetTextExtent(lines
[l
], &lineWidth
, &lineHeight
);
7204 switch( horizAlign
)
7207 if( textOrientation
== wxHORIZONTAL
)
7208 x
= rect
.x
+ (rect
.width
- lineWidth
- 1);
7210 y
= rect
.y
+ lineWidth
+ 1;
7213 case wxALIGN_CENTRE
:
7214 if( textOrientation
== wxHORIZONTAL
)
7215 x
= rect
.x
+ ((rect
.width
- lineWidth
)/2);
7217 y
= rect
.y
+ rect
.height
- ((rect
.height
- lineWidth
)/2);
7222 if( textOrientation
== wxHORIZONTAL
)
7225 y
= rect
.y
+ rect
.height
- 1;
7229 if( textOrientation
== wxHORIZONTAL
)
7231 dc
.DrawText( lines
[l
], (int)x
, (int)y
);
7236 dc
.DrawRotatedText( lines
[l
], (int)x
, (int)y
, 90.0 );
7241 dc
.DestroyClippingRegion();
7245 // Split multi line text up into an array of strings. Any existing
7246 // contents of the string array are preserved.
7248 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
7252 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
7253 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
7255 while ( startPos
< (int)tVal
.Length() )
7257 pos
= tVal
.Mid(startPos
).Find( eol
);
7262 else if ( pos
== 0 )
7264 lines
.Add( wxEmptyString
);
7268 lines
.Add( value
.Mid(startPos
, pos
) );
7272 if ( startPos
< (int)value
.Length() )
7274 lines
.Add( value
.Mid( startPos
) );
7279 void wxGrid::GetTextBoxSize( wxDC
& dc
,
7280 const wxArrayString
& lines
,
7281 long *width
, long *height
)
7288 for ( i
= 0; i
< lines
.GetCount(); i
++ )
7290 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
7291 w
= wxMax( w
, lineW
);
7300 // ------ Batch processing.
7302 void wxGrid::EndBatch()
7304 if ( m_batchCount
> 0 )
7307 if ( !m_batchCount
)
7310 m_rowLabelWin
->Refresh();
7311 m_colLabelWin
->Refresh();
7312 m_cornerLabelWin
->Refresh();
7313 m_gridWin
->Refresh();
7318 // Use this, rather than wxWindow::Refresh(), to force an immediate
7319 // repainting of the grid. Has no effect if you are already inside a
7320 // BeginBatch / EndBatch block.
7322 void wxGrid::ForceRefresh()
7330 // ------ Edit control functions
7334 void wxGrid::EnableEditing( bool edit
)
7336 // TODO: improve this ?
7338 if ( edit
!= m_editable
)
7340 if(!edit
) EnableCellEditControl(edit
);
7346 void wxGrid::EnableCellEditControl( bool enable
)
7351 if ( m_currentCellCoords
== wxGridNoCellCoords
)
7352 SetCurrentCell( 0, 0 );
7354 if ( enable
!= m_cellEditCtrlEnabled
)
7358 if (SendEvent( wxEVT_GRID_EDITOR_SHOWN
) <0)
7361 // this should be checked by the caller!
7362 wxASSERT_MSG( CanEnableCellControl(),
7363 _T("can't enable editing for this cell!") );
7365 // do it before ShowCellEditControl()
7366 m_cellEditCtrlEnabled
= enable
;
7368 ShowCellEditControl();
7372 //FIXME:add veto support
7373 SendEvent( wxEVT_GRID_EDITOR_HIDDEN
);
7375 HideCellEditControl();
7376 SaveEditControlValue();
7378 // do it after HideCellEditControl()
7379 m_cellEditCtrlEnabled
= enable
;
7384 bool wxGrid::IsCurrentCellReadOnly() const
7387 wxGridCellAttr
* attr
= ((wxGrid
*)this)->GetCellAttr(m_currentCellCoords
);
7388 bool readonly
= attr
->IsReadOnly();
7394 bool wxGrid::CanEnableCellControl() const
7396 return m_editable
&& !IsCurrentCellReadOnly();
7399 bool wxGrid::IsCellEditControlEnabled() const
7401 // the cell edit control might be disable for all cells or just for the
7402 // current one if it's read only
7403 return m_cellEditCtrlEnabled
? !IsCurrentCellReadOnly() : FALSE
;
7406 bool wxGrid::IsCellEditControlShown() const
7408 bool isShown
= FALSE
;
7410 if ( m_cellEditCtrlEnabled
)
7412 int row
= m_currentCellCoords
.GetRow();
7413 int col
= m_currentCellCoords
.GetCol();
7414 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7415 wxGridCellEditor
* editor
= attr
->GetEditor((wxGrid
*) this, row
, col
);
7420 if ( editor
->IsCreated() )
7422 isShown
= editor
->GetControl()->IsShown();
7432 void wxGrid::ShowCellEditControl()
7434 if ( IsCellEditControlEnabled() )
7436 if ( !IsVisible( m_currentCellCoords
) )
7438 m_cellEditCtrlEnabled
= FALSE
;
7443 wxRect rect
= CellToRect( m_currentCellCoords
);
7444 int row
= m_currentCellCoords
.GetRow();
7445 int col
= m_currentCellCoords
.GetCol();
7447 // if this is part of a multicell, find owner (topleft)
7448 int cell_rows
, cell_cols
;
7449 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7450 if ( cell_rows
<= 0 || cell_cols
<= 0 )
7454 m_currentCellCoords
.SetRow( row
);
7455 m_currentCellCoords
.SetCol( col
);
7458 // convert to scrolled coords
7460 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
7462 // done in PaintBackground()
7464 // erase the highlight and the cell contents because the editor
7465 // might not cover the entire cell
7466 wxClientDC
dc( m_gridWin
);
7468 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
); //wxBrush(attr->GetBackgroundColour(), wxSOLID));
7469 dc
.SetPen(*wxTRANSPARENT_PEN
);
7470 dc
.DrawRectangle(rect
);
7473 // cell is shifted by one pixel
7474 // However, don't allow x or y to become negative
7475 // since the SetSize() method interprets that as
7482 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7483 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
7484 if ( !editor
->IsCreated() )
7486 editor
->Create(m_gridWin
, -1,
7487 new wxGridCellEditorEvtHandler(this, editor
));
7489 wxGridEditorCreatedEvent
evt(GetId(),
7490 wxEVT_GRID_EDITOR_CREATED
,
7494 editor
->GetControl());
7495 GetEventHandler()->ProcessEvent(evt
);
7499 // resize editor to overflow into righthand cells if allowed
7500 int maxWidth
= rect
.width
;
7501 wxString value
= GetCellValue(row
, col
);
7502 if ( (value
!= wxEmptyString
) && (attr
->GetOverflow()) )
7505 GetTextExtent(value
, &maxWidth
, &y
,
7506 NULL
, NULL
, &attr
->GetFont());
7507 if (maxWidth
< rect
.width
) maxWidth
= rect
.width
;
7509 int client_right
= m_gridWin
->GetClientSize().GetWidth();
7510 if (rect
.x
+maxWidth
> client_right
)
7511 maxWidth
= client_right
- rect
.x
;
7513 if ((maxWidth
> rect
.width
) && (col
< m_numCols
) && m_table
)
7515 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7516 // may have changed earlier
7517 for (int i
= col
+cell_cols
; i
< m_numCols
; i
++)
7520 GetCellSize( row
, i
, &c_rows
, &c_cols
);
7521 // looks weird going over a multicell
7522 if (m_table
->IsEmptyCell(row
,i
) &&
7523 (rect
.width
< maxWidth
) && (c_rows
== 1))
7524 rect
.width
+= GetColWidth(i
);
7528 if (rect
.GetRight() > client_right
)
7529 rect
.SetRight(client_right
-1);
7532 editor
->SetCellAttr(attr
);
7533 editor
->SetSize( rect
);
7534 editor
->Show( TRUE
, attr
);
7536 // recalc dimensions in case we need to
7537 // expand the scrolled window to account for editor
7540 editor
->BeginEdit(row
, col
, this);
7541 editor
->SetCellAttr(NULL
);
7550 void wxGrid::HideCellEditControl()
7552 if ( IsCellEditControlEnabled() )
7554 int row
= m_currentCellCoords
.GetRow();
7555 int col
= m_currentCellCoords
.GetCol();
7557 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7558 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
7559 editor
->Show( FALSE
);
7562 m_gridWin
->SetFocus();
7563 // refresh whole row to the right
7564 wxRect
rect( CellToRect(row
, col
) );
7565 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
7566 rect
.width
= m_gridWin
->GetClientSize().GetWidth() - rect
.x
;
7567 m_gridWin
->Refresh( FALSE
, &rect
);
7572 void wxGrid::SaveEditControlValue()
7574 if ( IsCellEditControlEnabled() )
7576 int row
= m_currentCellCoords
.GetRow();
7577 int col
= m_currentCellCoords
.GetCol();
7579 wxString oldval
= GetCellValue(row
,col
);
7581 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7582 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
7583 bool changed
= editor
->EndEdit(row
, col
, this);
7590 if ( SendEvent( wxEVT_GRID_CELL_CHANGE
,
7591 m_currentCellCoords
.GetRow(),
7592 m_currentCellCoords
.GetCol() ) < 0 ) {
7594 // Event has been vetoed, set the data back.
7595 SetCellValue(row
,col
,oldval
);
7603 // ------ Grid location functions
7604 // Note that all of these functions work with the logical coordinates of
7605 // grid cells and labels so you will need to convert from device
7606 // coordinates for mouse events etc.
7609 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
7611 int row
= YToRow(y
);
7612 int col
= XToCol(x
);
7614 if ( row
== -1 || col
== -1 )
7616 coords
= wxGridNoCellCoords
;
7620 coords
.Set( row
, col
);
7625 // Internal Helper function for computing row or column from some
7626 // (unscrolled) coordinate value, using either
7627 // m_defaultRowHeight/m_defaultColWidth or binary search on array
7628 // of m_rowBottoms/m_ColRights to speed up the search!
7630 static int CoordToRowOrCol(int coord
, int defaultDist
, int minDist
,
7631 const wxArrayInt
& BorderArray
, int nMax
,
7636 return clipToMinMax
&& (nMax
> 0) ? 0 : -1;
7642 size_t i_max
= coord
/ defaultDist
,
7645 if (BorderArray
.IsEmpty())
7647 if((int) i_max
< nMax
)
7649 return clipToMinMax
? nMax
- 1 : -1;
7652 if ( i_max
>= BorderArray
.GetCount())
7653 i_max
= BorderArray
.GetCount() - 1;
7656 if ( coord
>= BorderArray
[i_max
])
7659 i_max
= coord
/ minDist
;
7661 if ( i_max
>= BorderArray
.GetCount())
7662 i_max
= BorderArray
.GetCount() - 1;
7664 if ( coord
>= BorderArray
[i_max
])
7665 return clipToMinMax
? (int)i_max
: -1;
7666 if ( coord
< BorderArray
[0] )
7669 while ( i_max
- i_min
> 0 )
7671 wxCHECK_MSG(BorderArray
[i_min
] <= coord
&& coord
< BorderArray
[i_max
],
7672 0, _T("wxGrid: internal error in CoordToRowOrCol"));
7673 if (coord
>= BorderArray
[ i_max
- 1])
7677 int median
= i_min
+ (i_max
- i_min
+ 1) / 2;
7678 if (coord
< BorderArray
[median
])
7686 int wxGrid::YToRow( int y
)
7688 return CoordToRowOrCol(y
, m_defaultRowHeight
,
7689 m_minAcceptableRowHeight
, m_rowBottoms
, m_numRows
, FALSE
);
7693 int wxGrid::XToCol( int x
)
7695 return CoordToRowOrCol(x
, m_defaultColWidth
,
7696 m_minAcceptableColWidth
, m_colRights
, m_numCols
, FALSE
);
7700 // return the row number that that the y coord is near the edge of, or
7701 // -1 if not near an edge
7703 int wxGrid::YToEdgeOfRow( int y
)
7706 i
= internalYToRow(y
);
7708 if ( GetRowHeight(i
) > WXGRID_LABEL_EDGE_ZONE
)
7710 // We know that we are in row i, test whether we are
7711 // close enough to lower or upper border, respectively.
7712 if ( abs(GetRowBottom(i
) - y
) < WXGRID_LABEL_EDGE_ZONE
)
7714 else if( i
> 0 && y
- GetRowTop(i
) < WXGRID_LABEL_EDGE_ZONE
)
7722 // return the col number that that the x coord is near the edge of, or
7723 // -1 if not near an edge
7725 int wxGrid::XToEdgeOfCol( int x
)
7728 i
= internalXToCol(x
);
7730 if ( GetColWidth(i
) > WXGRID_LABEL_EDGE_ZONE
)
7732 // We know that we are in column i, test whether we are
7733 // close enough to right or left border, respectively.
7734 if ( abs(GetColRight(i
) - x
) < WXGRID_LABEL_EDGE_ZONE
)
7736 else if( i
> 0 && x
- GetColLeft(i
) < WXGRID_LABEL_EDGE_ZONE
)
7744 wxRect
wxGrid::CellToRect( int row
, int col
)
7746 wxRect
rect( -1, -1, -1, -1 );
7748 if ( row
>= 0 && row
< m_numRows
&&
7749 col
>= 0 && col
< m_numCols
)
7751 int i
, cell_rows
, cell_cols
;
7752 rect
.width
= rect
.height
= 0;
7753 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7754 // if negative then find multicell owner
7755 if (cell_rows
< 0) row
+= cell_rows
;
7756 if (cell_cols
< 0) col
+= cell_cols
;
7757 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7759 rect
.x
= GetColLeft(col
);
7760 rect
.y
= GetRowTop(row
);
7761 for (i
=col
; i
<col
+cell_cols
; i
++)
7762 rect
.width
+= GetColWidth(i
);
7763 for (i
=row
; i
<row
+cell_rows
; i
++)
7764 rect
.height
+= GetRowHeight(i
);
7767 // if grid lines are enabled, then the area of the cell is a bit smaller
7768 if (m_gridLinesEnabled
) {
7776 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
7778 // get the cell rectangle in logical coords
7780 wxRect
r( CellToRect( row
, col
) );
7782 // convert to device coords
7784 int left
, top
, right
, bottom
;
7785 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
7786 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
7788 // check against the client area of the grid window
7791 m_gridWin
->GetClientSize( &cw
, &ch
);
7793 if ( wholeCellVisible
)
7795 // is the cell wholly visible ?
7797 return ( left
>= 0 && right
<= cw
&&
7798 top
>= 0 && bottom
<= ch
);
7802 // is the cell partly visible ?
7804 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
7805 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
7810 // make the specified cell location visible by doing a minimal amount
7813 void wxGrid::MakeCellVisible( int row
, int col
)
7817 int xpos
= -1, ypos
= -1;
7819 if ( row
>= 0 && row
< m_numRows
&&
7820 col
>= 0 && col
< m_numCols
)
7822 // get the cell rectangle in logical coords
7824 wxRect
r( CellToRect( row
, col
) );
7826 // convert to device coords
7828 int left
, top
, right
, bottom
;
7829 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
7830 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
7833 m_gridWin
->GetClientSize( &cw
, &ch
);
7839 else if ( bottom
> ch
)
7841 int h
= r
.GetHeight();
7843 for ( i
= row
-1; i
>= 0; i
-- )
7845 int rowHeight
= GetRowHeight(i
);
7846 if ( h
+ rowHeight
> ch
)
7853 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
7854 // have rounding errors (this is important, because if we do, we
7855 // might not scroll at all and some cells won't be redrawn)
7857 // Sometimes GRID_SCROLL_LINE/2 is not enough, so just add a full
7859 ypos
+= GRID_SCROLL_LINE_Y
;
7866 else if ( right
> cw
)
7868 // position the view so that the cell is on the right
7870 CalcUnscrolledPosition(0, 0, &x0
, &y0
);
7871 xpos
= x0
+ (right
- cw
);
7873 // see comment for ypos above
7874 xpos
+= GRID_SCROLL_LINE_X
;
7877 if ( xpos
!= -1 || ypos
!= -1 )
7880 xpos
/= GRID_SCROLL_LINE_X
;
7882 ypos
/= GRID_SCROLL_LINE_Y
;
7883 Scroll( xpos
, ypos
);
7891 // ------ Grid cursor movement functions
7894 bool wxGrid::MoveCursorUp( bool expandSelection
)
7896 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7897 m_currentCellCoords
.GetRow() >= 0 )
7899 if ( expandSelection
)
7901 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7902 m_selectingKeyboard
= m_currentCellCoords
;
7903 if ( m_selectingKeyboard
.GetRow() > 0 )
7905 m_selectingKeyboard
.SetRow( m_selectingKeyboard
.GetRow() - 1 );
7906 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7907 m_selectingKeyboard
.GetCol() );
7908 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7911 else if ( m_currentCellCoords
.GetRow() > 0 )
7914 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
7915 m_currentCellCoords
.GetCol() );
7916 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
7917 m_currentCellCoords
.GetCol() );
7928 bool wxGrid::MoveCursorDown( bool expandSelection
)
7930 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7931 m_currentCellCoords
.GetRow() < m_numRows
)
7933 if ( expandSelection
)
7935 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7936 m_selectingKeyboard
= m_currentCellCoords
;
7937 if ( m_selectingKeyboard
.GetRow() < m_numRows
-1 )
7939 m_selectingKeyboard
.SetRow( m_selectingKeyboard
.GetRow() + 1 );
7940 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7941 m_selectingKeyboard
.GetCol() );
7942 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7945 else if ( m_currentCellCoords
.GetRow() < m_numRows
- 1 )
7948 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
7949 m_currentCellCoords
.GetCol() );
7950 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
7951 m_currentCellCoords
.GetCol() );
7962 bool wxGrid::MoveCursorLeft( bool expandSelection
)
7964 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7965 m_currentCellCoords
.GetCol() >= 0 )
7967 if ( expandSelection
)
7969 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7970 m_selectingKeyboard
= m_currentCellCoords
;
7971 if ( m_selectingKeyboard
.GetCol() > 0 )
7973 m_selectingKeyboard
.SetCol( m_selectingKeyboard
.GetCol() - 1 );
7974 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7975 m_selectingKeyboard
.GetCol() );
7976 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7979 else if ( m_currentCellCoords
.GetCol() > 0 )
7982 MakeCellVisible( m_currentCellCoords
.GetRow(),
7983 m_currentCellCoords
.GetCol() - 1 );
7984 SetCurrentCell( m_currentCellCoords
.GetRow(),
7985 m_currentCellCoords
.GetCol() - 1 );
7996 bool wxGrid::MoveCursorRight( bool expandSelection
)
7998 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7999 m_currentCellCoords
.GetCol() < m_numCols
)
8001 if ( expandSelection
)
8003 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
8004 m_selectingKeyboard
= m_currentCellCoords
;
8005 if ( m_selectingKeyboard
.GetCol() < m_numCols
- 1 )
8007 m_selectingKeyboard
.SetCol( m_selectingKeyboard
.GetCol() + 1 );
8008 MakeCellVisible( m_selectingKeyboard
.GetRow(),
8009 m_selectingKeyboard
.GetCol() );
8010 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8013 else if ( m_currentCellCoords
.GetCol() < m_numCols
- 1 )
8016 MakeCellVisible( m_currentCellCoords
.GetRow(),
8017 m_currentCellCoords
.GetCol() + 1 );
8018 SetCurrentCell( m_currentCellCoords
.GetRow(),
8019 m_currentCellCoords
.GetCol() + 1 );
8030 bool wxGrid::MovePageUp()
8032 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
8034 int row
= m_currentCellCoords
.GetRow();
8038 m_gridWin
->GetClientSize( &cw
, &ch
);
8040 int y
= GetRowTop(row
);
8041 int newRow
= internalYToRow( y
- ch
+ 1 );
8043 if ( newRow
== row
)
8045 //row > 0 , so newrow can never be less than 0 here.
8049 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
8050 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
8058 bool wxGrid::MovePageDown()
8060 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
8062 int row
= m_currentCellCoords
.GetRow();
8063 if ( (row
+1) < m_numRows
)
8066 m_gridWin
->GetClientSize( &cw
, &ch
);
8068 int y
= GetRowTop(row
);
8069 int newRow
= internalYToRow( y
+ ch
);
8070 if ( newRow
== row
)
8072 // row < m_numRows , so newrow can't overflow here.
8076 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
8077 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
8085 bool wxGrid::MoveCursorUpBlock( bool expandSelection
)
8088 m_currentCellCoords
!= wxGridNoCellCoords
&&
8089 m_currentCellCoords
.GetRow() > 0 )
8091 int row
= m_currentCellCoords
.GetRow();
8092 int col
= m_currentCellCoords
.GetCol();
8094 if ( m_table
->IsEmptyCell(row
, col
) )
8096 // starting in an empty cell: find the next block of
8102 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8105 else if ( m_table
->IsEmptyCell(row
-1, col
) )
8107 // starting at the top of a block: find the next block
8113 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8118 // starting within a block: find the top of the block
8123 if ( m_table
->IsEmptyCell(row
, col
) )
8131 MakeCellVisible( row
, col
);
8132 if ( expandSelection
)
8134 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8135 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8140 SetCurrentCell( row
, col
);
8148 bool wxGrid::MoveCursorDownBlock( bool expandSelection
)
8151 m_currentCellCoords
!= wxGridNoCellCoords
&&
8152 m_currentCellCoords
.GetRow() < m_numRows
-1 )
8154 int row
= m_currentCellCoords
.GetRow();
8155 int col
= m_currentCellCoords
.GetCol();
8157 if ( m_table
->IsEmptyCell(row
, col
) )
8159 // starting in an empty cell: find the next block of
8162 while ( row
< m_numRows
-1 )
8165 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8168 else if ( m_table
->IsEmptyCell(row
+1, col
) )
8170 // starting at the bottom of a block: find the next block
8173 while ( row
< m_numRows
-1 )
8176 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8181 // starting within a block: find the bottom of the block
8183 while ( row
< m_numRows
-1 )
8186 if ( m_table
->IsEmptyCell(row
, col
) )
8194 MakeCellVisible( row
, col
);
8195 if ( expandSelection
)
8197 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8198 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8203 SetCurrentCell( row
, col
);
8212 bool wxGrid::MoveCursorLeftBlock( bool expandSelection
)
8215 m_currentCellCoords
!= wxGridNoCellCoords
&&
8216 m_currentCellCoords
.GetCol() > 0 )
8218 int row
= m_currentCellCoords
.GetRow();
8219 int col
= m_currentCellCoords
.GetCol();
8221 if ( m_table
->IsEmptyCell(row
, col
) )
8223 // starting in an empty cell: find the next block of
8229 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8232 else if ( m_table
->IsEmptyCell(row
, col
-1) )
8234 // starting at the left of a block: find the next block
8240 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8245 // starting within a block: find the left of the block
8250 if ( m_table
->IsEmptyCell(row
, col
) )
8258 MakeCellVisible( row
, col
);
8259 if ( expandSelection
)
8261 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8262 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8267 SetCurrentCell( row
, col
);
8276 bool wxGrid::MoveCursorRightBlock( bool expandSelection
)
8279 m_currentCellCoords
!= wxGridNoCellCoords
&&
8280 m_currentCellCoords
.GetCol() < m_numCols
-1 )
8282 int row
= m_currentCellCoords
.GetRow();
8283 int col
= m_currentCellCoords
.GetCol();
8285 if ( m_table
->IsEmptyCell(row
, col
) )
8287 // starting in an empty cell: find the next block of
8290 while ( col
< m_numCols
-1 )
8293 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8296 else if ( m_table
->IsEmptyCell(row
, col
+1) )
8298 // starting at the right of a block: find the next block
8301 while ( col
< m_numCols
-1 )
8304 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8309 // starting within a block: find the right of the block
8311 while ( col
< m_numCols
-1 )
8314 if ( m_table
->IsEmptyCell(row
, col
) )
8322 MakeCellVisible( row
, col
);
8323 if ( expandSelection
)
8325 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8326 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8331 SetCurrentCell( row
, col
);
8343 // ------ Label values and formatting
8346 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
8348 *horiz
= m_rowLabelHorizAlign
;
8349 *vert
= m_rowLabelVertAlign
;
8352 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
8354 *horiz
= m_colLabelHorizAlign
;
8355 *vert
= m_colLabelVertAlign
;
8358 int wxGrid::GetColLabelTextOrientation()
8360 return m_colLabelTextOrientation
;
8363 wxString
wxGrid::GetRowLabelValue( int row
)
8367 return m_table
->GetRowLabelValue( row
);
8377 wxString
wxGrid::GetColLabelValue( int col
)
8381 return m_table
->GetColLabelValue( col
);
8392 void wxGrid::SetRowLabelSize( int width
)
8394 width
= wxMax( width
, 0 );
8395 if ( width
!= m_rowLabelWidth
)
8399 m_rowLabelWin
->Show( FALSE
);
8400 m_cornerLabelWin
->Show( FALSE
);
8402 else if ( m_rowLabelWidth
== 0 )
8404 m_rowLabelWin
->Show( TRUE
);
8405 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
8408 m_rowLabelWidth
= width
;
8410 wxScrolledWindow::Refresh( TRUE
);
8415 void wxGrid::SetColLabelSize( int height
)
8417 height
= wxMax( height
, 0 );
8418 if ( height
!= m_colLabelHeight
)
8422 m_colLabelWin
->Show( FALSE
);
8423 m_cornerLabelWin
->Show( FALSE
);
8425 else if ( m_colLabelHeight
== 0 )
8427 m_colLabelWin
->Show( TRUE
);
8428 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
8431 m_colLabelHeight
= height
;
8433 wxScrolledWindow::Refresh( TRUE
);
8438 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
8440 if ( m_labelBackgroundColour
!= colour
)
8442 m_labelBackgroundColour
= colour
;
8443 m_rowLabelWin
->SetBackgroundColour( colour
);
8444 m_colLabelWin
->SetBackgroundColour( colour
);
8445 m_cornerLabelWin
->SetBackgroundColour( colour
);
8447 if ( !GetBatchCount() )
8449 m_rowLabelWin
->Refresh();
8450 m_colLabelWin
->Refresh();
8451 m_cornerLabelWin
->Refresh();
8456 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
8458 if ( m_labelTextColour
!= colour
)
8460 m_labelTextColour
= colour
;
8461 if ( !GetBatchCount() )
8463 m_rowLabelWin
->Refresh();
8464 m_colLabelWin
->Refresh();
8469 void wxGrid::SetLabelFont( const wxFont
& font
)
8472 if ( !GetBatchCount() )
8474 m_rowLabelWin
->Refresh();
8475 m_colLabelWin
->Refresh();
8479 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
8481 // allow old (incorrect) defs to be used
8484 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
8485 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
8486 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
8491 case wxTOP
: vert
= wxALIGN_TOP
; break;
8492 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
8493 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
8496 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
8498 m_rowLabelHorizAlign
= horiz
;
8501 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
8503 m_rowLabelVertAlign
= vert
;
8506 if ( !GetBatchCount() )
8508 m_rowLabelWin
->Refresh();
8512 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
8514 // allow old (incorrect) defs to be used
8517 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
8518 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
8519 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
8524 case wxTOP
: vert
= wxALIGN_TOP
; break;
8525 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
8526 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
8529 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
8531 m_colLabelHorizAlign
= horiz
;
8534 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
8536 m_colLabelVertAlign
= vert
;
8539 if ( !GetBatchCount() )
8541 m_colLabelWin
->Refresh();
8545 // Note: under MSW, the default column label font must be changed because it
8546 // does not support vertical printing
8548 // Example: wxFont font(9, wxSWISS, wxNORMAL, wxBOLD);
8549 // pGrid->SetLabelFont(font);
8550 // pGrid->SetColLabelTextOrientation(wxVERTICAL);
8552 void wxGrid::SetColLabelTextOrientation( int textOrientation
)
8554 if( textOrientation
== wxHORIZONTAL
|| textOrientation
== wxVERTICAL
)
8556 m_colLabelTextOrientation
= textOrientation
;
8559 if ( !GetBatchCount() )
8561 m_colLabelWin
->Refresh();
8565 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
8569 m_table
->SetRowLabelValue( row
, s
);
8570 if ( !GetBatchCount() )
8572 wxRect rect
= CellToRect( row
, 0);
8573 if ( rect
.height
> 0 )
8575 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
8577 rect
.width
= m_rowLabelWidth
;
8578 m_rowLabelWin
->Refresh( TRUE
, &rect
);
8584 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
8588 m_table
->SetColLabelValue( col
, s
);
8589 if ( !GetBatchCount() )
8591 wxRect rect
= CellToRect( 0, col
);
8592 if ( rect
.width
> 0 )
8594 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
8596 rect
.height
= m_colLabelHeight
;
8597 m_colLabelWin
->Refresh( TRUE
, &rect
);
8603 void wxGrid::SetGridLineColour( const wxColour
& colour
)
8605 if ( m_gridLineColour
!= colour
)
8607 m_gridLineColour
= colour
;
8609 wxClientDC
dc( m_gridWin
);
8611 DrawAllGridLines( dc
, wxRegion() );
8616 void wxGrid::SetCellHighlightColour( const wxColour
& colour
)
8618 if ( m_cellHighlightColour
!= colour
)
8620 m_cellHighlightColour
= colour
;
8622 wxClientDC
dc( m_gridWin
);
8624 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
8625 DrawCellHighlight(dc
, attr
);
8630 void wxGrid::SetCellHighlightPenWidth(int width
)
8632 if (m_cellHighlightPenWidth
!= width
) {
8633 m_cellHighlightPenWidth
= width
;
8635 // Just redrawing the cell highlight is not enough since that won't
8636 // make any visible change if the the thickness is getting smaller.
8637 int row
= m_currentCellCoords
.GetRow();
8638 int col
= m_currentCellCoords
.GetCol();
8639 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
8641 wxRect rect
= CellToRect(row
, col
);
8642 m_gridWin
->Refresh(TRUE
, &rect
);
8646 void wxGrid::SetCellHighlightROPenWidth(int width
)
8648 if (m_cellHighlightROPenWidth
!= width
) {
8649 m_cellHighlightROPenWidth
= width
;
8651 // Just redrawing the cell highlight is not enough since that won't
8652 // make any visible change if the the thickness is getting smaller.
8653 int row
= m_currentCellCoords
.GetRow();
8654 int col
= m_currentCellCoords
.GetCol();
8655 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
8657 wxRect rect
= CellToRect(row
, col
);
8658 m_gridWin
->Refresh(TRUE
, &rect
);
8662 void wxGrid::EnableGridLines( bool enable
)
8664 if ( enable
!= m_gridLinesEnabled
)
8666 m_gridLinesEnabled
= enable
;
8668 if ( !GetBatchCount() )
8672 wxClientDC
dc( m_gridWin
);
8674 DrawAllGridLines( dc
, wxRegion() );
8678 m_gridWin
->Refresh();
8685 int wxGrid::GetDefaultRowSize()
8687 return m_defaultRowHeight
;
8690 int wxGrid::GetRowSize( int row
)
8692 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
8694 return GetRowHeight(row
);
8697 int wxGrid::GetDefaultColSize()
8699 return m_defaultColWidth
;
8702 int wxGrid::GetColSize( int col
)
8704 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
8706 return GetColWidth(col
);
8709 // ============================================================================
8710 // access to the grid attributes: each of them has a default value in the grid
8711 // itself and may be overidden on a per-cell basis
8712 // ============================================================================
8714 // ----------------------------------------------------------------------------
8715 // setting default attributes
8716 // ----------------------------------------------------------------------------
8718 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
8720 m_defaultCellAttr
->SetBackgroundColour(col
);
8722 m_gridWin
->SetBackgroundColour(col
);
8726 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
8728 m_defaultCellAttr
->SetTextColour(col
);
8731 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
8733 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
8736 void wxGrid::SetDefaultCellOverflow( bool allow
)
8738 m_defaultCellAttr
->SetOverflow(allow
);
8741 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
8743 m_defaultCellAttr
->SetFont(font
);
8746 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
8748 m_defaultCellAttr
->SetRenderer(renderer
);
8751 void wxGrid::SetDefaultEditor(wxGridCellEditor
*editor
)
8753 m_defaultCellAttr
->SetEditor(editor
);
8756 // ----------------------------------------------------------------------------
8757 // access to the default attrbiutes
8758 // ----------------------------------------------------------------------------
8760 wxColour
wxGrid::GetDefaultCellBackgroundColour()
8762 return m_defaultCellAttr
->GetBackgroundColour();
8765 wxColour
wxGrid::GetDefaultCellTextColour()
8767 return m_defaultCellAttr
->GetTextColour();
8770 wxFont
wxGrid::GetDefaultCellFont()
8772 return m_defaultCellAttr
->GetFont();
8775 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
8777 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
8780 bool wxGrid::GetDefaultCellOverflow()
8782 return m_defaultCellAttr
->GetOverflow();
8785 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
8787 return m_defaultCellAttr
->GetRenderer(NULL
, 0, 0);
8790 wxGridCellEditor
*wxGrid::GetDefaultEditor() const
8792 return m_defaultCellAttr
->GetEditor(NULL
,0,0);
8795 // ----------------------------------------------------------------------------
8796 // access to cell attributes
8797 // ----------------------------------------------------------------------------
8799 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
8801 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8802 wxColour colour
= attr
->GetBackgroundColour();
8807 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
8809 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8810 wxColour colour
= attr
->GetTextColour();
8815 wxFont
wxGrid::GetCellFont( int row
, int col
)
8817 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8818 wxFont font
= attr
->GetFont();
8823 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
8825 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8826 attr
->GetAlignment(horiz
, vert
);
8830 bool wxGrid::GetCellOverflow( int row
, int col
)
8832 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8833 bool allow
= attr
->GetOverflow();
8838 void wxGrid::GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
)
8840 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8841 attr
->GetSize( num_rows
, num_cols
);
8845 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
)
8847 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8848 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
8854 wxGridCellEditor
* wxGrid::GetCellEditor(int row
, int col
)
8856 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8857 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
8863 bool wxGrid::IsReadOnly(int row
, int col
) const
8865 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8866 bool isReadOnly
= attr
->IsReadOnly();
8871 // ----------------------------------------------------------------------------
8872 // attribute support: cache, automatic provider creation, ...
8873 // ----------------------------------------------------------------------------
8875 bool wxGrid::CanHaveAttributes()
8882 return m_table
->CanHaveAttributes();
8885 void wxGrid::ClearAttrCache()
8887 if ( m_attrCache
.row
!= -1 )
8889 wxSafeDecRef(m_attrCache
.attr
);
8890 m_attrCache
.attr
= NULL
;
8891 m_attrCache
.row
= -1;
8895 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
8899 wxGrid
*self
= (wxGrid
*)this; // const_cast
8901 self
->ClearAttrCache();
8902 self
->m_attrCache
.row
= row
;
8903 self
->m_attrCache
.col
= col
;
8904 self
->m_attrCache
.attr
= attr
;
8909 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
8911 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
8913 *attr
= m_attrCache
.attr
;
8914 wxSafeIncRef(m_attrCache
.attr
);
8916 #ifdef DEBUG_ATTR_CACHE
8917 gs_nAttrCacheHits
++;
8924 #ifdef DEBUG_ATTR_CACHE
8925 gs_nAttrCacheMisses
++;
8931 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
8933 wxGridCellAttr
*attr
= NULL
;
8934 // Additional test to avoid looking at the cache e.g. for
8935 // wxNoCellCoords, as this will confuse memory management.
8938 if ( !LookupAttr(row
, col
, &attr
) )
8940 attr
= m_table
? m_table
->GetAttr(row
, col
, wxGridCellAttr::Any
)
8941 : (wxGridCellAttr
*)NULL
;
8942 CacheAttr(row
, col
, attr
);
8947 attr
->SetDefAttr(m_defaultCellAttr
);
8951 attr
= m_defaultCellAttr
;
8958 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
8960 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
8962 wxCHECK_MSG( m_table
, attr
,
8963 _T("we may only be called if CanHaveAttributes() returned TRUE and then m_table should be !NULL") );
8965 attr
= m_table
->GetAttr(row
, col
, wxGridCellAttr::Cell
);
8968 attr
= new wxGridCellAttr(m_defaultCellAttr
);
8970 // artificially inc the ref count to match DecRef() in caller
8972 m_table
->SetAttr(attr
, row
, col
);
8978 // ----------------------------------------------------------------------------
8979 // setting column attributes (wrappers around SetColAttr)
8980 // ----------------------------------------------------------------------------
8982 void wxGrid::SetColFormatBool(int col
)
8984 SetColFormatCustom(col
, wxGRID_VALUE_BOOL
);
8987 void wxGrid::SetColFormatNumber(int col
)
8989 SetColFormatCustom(col
, wxGRID_VALUE_NUMBER
);
8992 void wxGrid::SetColFormatFloat(int col
, int width
, int precision
)
8994 wxString typeName
= wxGRID_VALUE_FLOAT
;
8995 if ( (width
!= -1) || (precision
!= -1) )
8997 typeName
<< _T(':') << width
<< _T(',') << precision
;
9000 SetColFormatCustom(col
, typeName
);
9003 void wxGrid::SetColFormatCustom(int col
, const wxString
& typeName
)
9005 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
9007 attr
= m_table
->GetAttr(-1, col
, wxGridCellAttr::Col
);
9009 attr
= new wxGridCellAttr
;
9010 wxGridCellRenderer
*renderer
= GetDefaultRendererForType(typeName
);
9011 attr
->SetRenderer(renderer
);
9013 SetColAttr(col
, attr
);
9017 // ----------------------------------------------------------------------------
9018 // setting cell attributes: this is forwarded to the table
9019 // ----------------------------------------------------------------------------
9021 void wxGrid::SetAttr(int row
, int col
, wxGridCellAttr
*attr
)
9023 if ( CanHaveAttributes() )
9025 m_table
->SetAttr(attr
, row
, col
);
9034 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
9036 if ( CanHaveAttributes() )
9038 m_table
->SetRowAttr(attr
, row
);
9047 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
9049 if ( CanHaveAttributes() )
9051 m_table
->SetColAttr(attr
, col
);
9060 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
9062 if ( CanHaveAttributes() )
9064 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9065 attr
->SetBackgroundColour(colour
);
9070 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
9072 if ( CanHaveAttributes() )
9074 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9075 attr
->SetTextColour(colour
);
9080 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
9082 if ( CanHaveAttributes() )
9084 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9085 attr
->SetFont(font
);
9090 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
9092 if ( CanHaveAttributes() )
9094 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9095 attr
->SetAlignment(horiz
, vert
);
9100 void wxGrid::SetCellOverflow( int row
, int col
, bool allow
)
9102 if ( CanHaveAttributes() )
9104 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9105 attr
->SetOverflow(allow
);
9110 void wxGrid::SetCellSize( int row
, int col
, int num_rows
, int num_cols
)
9112 if ( CanHaveAttributes() )
9114 int cell_rows
, cell_cols
;
9116 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9117 attr
->GetSize(&cell_rows
, &cell_cols
);
9118 attr
->SetSize(num_rows
, num_cols
);
9121 // Cannot set the size of a cell to 0 or negative values
9122 // While it is perfectly legal to do that, this function cannot
9123 // handle all the possibilies, do it by hand by getting the CellAttr.
9124 // You can only set the size of a cell to 1,1 or greater with this fn
9125 wxASSERT_MSG( !((cell_rows
< 1) || (cell_cols
< 1)),
9126 wxT("wxGrid::SetCellSize setting cell size that is already part of another cell"));
9127 wxASSERT_MSG( !((num_rows
< 1) || (num_cols
< 1)),
9128 wxT("wxGrid::SetCellSize setting cell size to < 1"));
9130 // if this was already a multicell then "turn off" the other cells first
9131 if ((cell_rows
> 1) || (cell_rows
> 1))
9134 for (j
=row
; j
<row
+cell_rows
; j
++)
9136 for (i
=col
; i
<col
+cell_cols
; i
++)
9138 if ((i
!= col
) || (j
!= row
))
9140 wxGridCellAttr
*attr_stub
= GetOrCreateCellAttr(j
, i
);
9141 attr_stub
->SetSize( 1, 1 );
9142 attr_stub
->DecRef();
9148 // mark the cells that will be covered by this cell to
9149 // negative or zero values to point back at this cell
9150 if (((num_rows
> 1) || (num_cols
> 1)) && (num_rows
>= 1) && (num_cols
>= 1))
9153 for (j
=row
; j
<row
+num_rows
; j
++)
9155 for (i
=col
; i
<col
+num_cols
; i
++)
9157 if ((i
!= col
) || (j
!= row
))
9159 wxGridCellAttr
*attr_stub
= GetOrCreateCellAttr(j
, i
);
9160 attr_stub
->SetSize( row
-j
, col
-i
);
9161 attr_stub
->DecRef();
9169 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
9171 if ( CanHaveAttributes() )
9173 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9174 attr
->SetRenderer(renderer
);
9179 void wxGrid::SetCellEditor(int row
, int col
, wxGridCellEditor
* editor
)
9181 if ( CanHaveAttributes() )
9183 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9184 attr
->SetEditor(editor
);
9189 void wxGrid::SetReadOnly(int row
, int col
, bool isReadOnly
)
9191 if ( CanHaveAttributes() )
9193 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9194 attr
->SetReadOnly(isReadOnly
);
9199 // ----------------------------------------------------------------------------
9200 // Data type registration
9201 // ----------------------------------------------------------------------------
9203 void wxGrid::RegisterDataType(const wxString
& typeName
,
9204 wxGridCellRenderer
* renderer
,
9205 wxGridCellEditor
* editor
)
9207 m_typeRegistry
->RegisterDataType(typeName
, renderer
, editor
);
9211 wxGridCellEditor
* wxGrid::GetDefaultEditorForCell(int row
, int col
) const
9213 wxString typeName
= m_table
->GetTypeName(row
, col
);
9214 return GetDefaultEditorForType(typeName
);
9217 wxGridCellRenderer
* wxGrid::GetDefaultRendererForCell(int row
, int col
) const
9219 wxString typeName
= m_table
->GetTypeName(row
, col
);
9220 return GetDefaultRendererForType(typeName
);
9224 wxGrid::GetDefaultEditorForType(const wxString
& typeName
) const
9226 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
9227 if ( index
== wxNOT_FOUND
)
9229 wxFAIL_MSG(wxT("Unknown data type name"));
9234 return m_typeRegistry
->GetEditor(index
);
9238 wxGrid::GetDefaultRendererForType(const wxString
& typeName
) const
9240 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
9241 if ( index
== wxNOT_FOUND
)
9243 wxFAIL_MSG(wxT("Unknown data type name"));
9248 return m_typeRegistry
->GetRenderer(index
);
9252 // ----------------------------------------------------------------------------
9254 // ----------------------------------------------------------------------------
9256 void wxGrid::EnableDragRowSize( bool enable
)
9258 m_canDragRowSize
= enable
;
9262 void wxGrid::EnableDragColSize( bool enable
)
9264 m_canDragColSize
= enable
;
9267 void wxGrid::EnableDragGridSize( bool enable
)
9269 m_canDragGridSize
= enable
;
9273 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
9275 m_defaultRowHeight
= wxMax( height
, m_minAcceptableRowHeight
);
9277 if ( resizeExistingRows
)
9279 // since we are resizing all rows to the default row size,
9280 // we can simply clear the row heights and row bottoms
9281 // arrays (which also allows us to take advantage of
9282 // some speed optimisations)
9283 m_rowHeights
.Empty();
9284 m_rowBottoms
.Empty();
9285 if ( !GetBatchCount() )
9290 void wxGrid::SetRowSize( int row
, int height
)
9292 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
9294 // See comment in SetColSize
9295 if ( height
< GetRowMinimalAcceptableHeight()) { return; }
9297 if ( m_rowHeights
.IsEmpty() )
9299 // need to really create the array
9303 int h
= wxMax( 0, height
);
9304 int diff
= h
- m_rowHeights
[row
];
9306 m_rowHeights
[row
] = h
;
9308 for ( i
= row
; i
< m_numRows
; i
++ )
9310 m_rowBottoms
[i
] += diff
;
9312 if ( !GetBatchCount() )
9316 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
9318 m_defaultColWidth
= wxMax( width
, m_minAcceptableColWidth
);
9320 if ( resizeExistingCols
)
9322 // since we are resizing all columns to the default column size,
9323 // we can simply clear the col widths and col rights
9324 // arrays (which also allows us to take advantage of
9325 // some speed optimisations)
9326 m_colWidths
.Empty();
9327 m_colRights
.Empty();
9328 if ( !GetBatchCount() )
9333 void wxGrid::SetColSize( int col
, int width
)
9335 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
9337 // should we check that it's bigger than GetColMinimalWidth(col) here?
9339 // No, because it is reasonable to assume the library user know's
9340 // what he is doing. However whe should test against the weaker
9341 // constariant of minimalAcceptableWidth, as this breaks rendering
9343 // This test then fixes sf.net bug #645734
9345 if ( width
< GetColMinimalAcceptableWidth()) { return; }
9347 if ( m_colWidths
.IsEmpty() )
9349 // need to really create the array
9353 // if < 0 calc new width from label
9357 wxArrayString lines
;
9358 wxClientDC
dc(m_colLabelWin
);
9359 dc
.SetFont(GetLabelFont());
9360 StringToLines(GetColLabelValue(col
), lines
);
9361 GetTextBoxSize(dc
, lines
, &w
, &h
);
9364 int w
= wxMax( 0, width
);
9365 int diff
= w
- m_colWidths
[col
];
9366 m_colWidths
[col
] = w
;
9369 for ( i
= col
; i
< m_numCols
; i
++ )
9371 m_colRights
[i
] += diff
;
9373 if ( !GetBatchCount() )
9378 void wxGrid::SetColMinimalWidth( int col
, int width
)
9380 if (width
> GetColMinimalAcceptableWidth()) {
9381 m_colMinWidths
.Put(col
, width
);
9385 void wxGrid::SetRowMinimalHeight( int row
, int width
)
9387 if (width
> GetRowMinimalAcceptableHeight()) {
9388 m_rowMinHeights
.Put(row
, width
);
9392 int wxGrid::GetColMinimalWidth(int col
) const
9394 long value
= m_colMinWidths
.Get(col
);
9395 return value
!= wxNOT_FOUND
? (int)value
: m_minAcceptableColWidth
;
9398 int wxGrid::GetRowMinimalHeight(int row
) const
9400 long value
= m_rowMinHeights
.Get(row
);
9401 return value
!= wxNOT_FOUND
? (int)value
: m_minAcceptableRowHeight
;
9404 void wxGrid::SetColMinimalAcceptableWidth( int width
)
9408 m_minAcceptableColWidth
= width
;
9411 void wxGrid::SetRowMinimalAcceptableHeight( int height
)
9415 m_minAcceptableRowHeight
= height
;
9418 int wxGrid::GetColMinimalAcceptableWidth() const
9420 return m_minAcceptableColWidth
;
9423 int wxGrid::GetRowMinimalAcceptableHeight() const
9425 return m_minAcceptableRowHeight
;
9428 // ----------------------------------------------------------------------------
9430 // ----------------------------------------------------------------------------
9432 void wxGrid::AutoSizeColOrRow( int colOrRow
, bool setAsMin
, bool column
)
9434 wxClientDC
dc(m_gridWin
);
9436 // init both of them to avoid compiler warnings, even if weo nly need one
9444 wxCoord extent
, extentMax
= 0;
9445 int max
= column
? m_numRows
: m_numCols
;
9446 for ( int rowOrCol
= 0; rowOrCol
< max
; rowOrCol
++ )
9453 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
9454 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
9457 wxSize size
= renderer
->GetBestSize(*this, *attr
, dc
, row
, col
);
9458 extent
= column
? size
.x
: size
.y
;
9459 if ( extent
> extentMax
)
9470 // now also compare with the column label extent
9472 dc
.SetFont( GetLabelFont() );
9476 dc
.GetTextExtent( GetColLabelValue(col
), &w
, &h
);
9477 if( GetColLabelTextOrientation() == wxVERTICAL
)
9481 dc
.GetTextExtent( GetRowLabelValue(row
), &w
, &h
);
9483 extent
= column
? w
: h
;
9484 if ( extent
> extentMax
)
9491 // empty column - give default extent (notice that if extentMax is less
9492 // than default extent but != 0, it's ok)
9493 extentMax
= column
? m_defaultColWidth
: m_defaultRowHeight
;
9499 // leave some space around text
9510 SetColSize(col
, extentMax
);
9511 if ( !GetBatchCount() )
9514 m_gridWin
->GetClientSize( &cw
, &ch
);
9515 wxRect
rect ( CellToRect( 0, col
) );
9517 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
9518 rect
.width
= cw
- rect
.x
;
9519 rect
.height
= m_colLabelHeight
;
9520 m_colLabelWin
->Refresh( TRUE
, &rect
);
9525 SetRowSize(row
, extentMax
);
9526 if ( !GetBatchCount() )
9529 m_gridWin
->GetClientSize( &cw
, &ch
);
9530 wxRect
rect ( CellToRect( row
, 0 ) );
9532 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
9533 rect
.width
= m_rowLabelWidth
;
9534 rect
.height
= ch
- rect
.y
;
9535 m_rowLabelWin
->Refresh( TRUE
, &rect
);
9541 SetColMinimalWidth(col
, extentMax
);
9543 SetRowMinimalHeight(row
, extentMax
);
9547 int wxGrid::SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
)
9549 int width
= m_rowLabelWidth
;
9554 for ( int col
= 0; col
< m_numCols
; col
++ )
9558 AutoSizeColumn(col
, setAsMin
);
9561 width
+= GetColWidth(col
);
9570 int wxGrid::SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
)
9572 int height
= m_colLabelHeight
;
9577 for ( int row
= 0; row
< m_numRows
; row
++ )
9581 AutoSizeRow(row
, setAsMin
);
9584 height
+= GetRowHeight(row
);
9593 void wxGrid::AutoSize()
9597 wxSize
size(SetOrCalcColumnSizes(FALSE
), SetOrCalcRowSizes(FALSE
));
9599 // round up the size to a multiple of scroll step - this ensures that we
9600 // won't get the scrollbars if we're sized exactly to this width
9601 // CalcDimension adds m_extraWidth + 1 etc. to calculate the necessary
9603 wxSize
sizeFit(GetScrollX(size
.x
+ m_extraWidth
+ 1) * GRID_SCROLL_LINE_X
,
9604 GetScrollY(size
.y
+ m_extraHeight
+ 1) * GRID_SCROLL_LINE_Y
);
9606 // distribute the extra space between the columns/rows to avoid having
9607 // extra white space
9609 // Remove the extra m_extraWidth + 1 added above
9610 wxCoord diff
= sizeFit
.x
- size
.x
+ (m_extraWidth
+ 1);
9611 if ( diff
&& m_numCols
)
9613 // try to resize the columns uniformly
9614 wxCoord diffPerCol
= diff
/ m_numCols
;
9617 for ( int col
= 0; col
< m_numCols
; col
++ )
9619 SetColSize(col
, GetColWidth(col
) + diffPerCol
);
9623 // add remaining amount to the last columns
9624 diff
-= diffPerCol
* m_numCols
;
9627 for ( int col
= m_numCols
- 1; col
>= m_numCols
- diff
; col
-- )
9629 SetColSize(col
, GetColWidth(col
) + 1);
9635 diff
= sizeFit
.y
- size
.y
- (m_extraHeight
+ 1);
9636 if ( diff
&& m_numRows
)
9638 // try to resize the columns uniformly
9639 wxCoord diffPerRow
= diff
/ m_numRows
;
9642 for ( int row
= 0; row
< m_numRows
; row
++ )
9644 SetRowSize(row
, GetRowHeight(row
) + diffPerRow
);
9648 // add remaining amount to the last rows
9649 diff
-= diffPerRow
* m_numRows
;
9652 for ( int row
= m_numRows
- 1; row
>= m_numRows
- diff
; row
-- )
9654 SetRowSize(row
, GetRowHeight(row
) + 1);
9661 SetClientSize(sizeFit
);
9664 void wxGrid::AutoSizeRowLabelSize( int row
)
9666 wxArrayString lines
;
9669 // Hide the edit control, so it
9670 // won't interfer with drag-shrinking.
9671 if( IsCellEditControlShown() )
9673 HideCellEditControl();
9674 SaveEditControlValue();
9677 // autosize row height depending on label text
9678 StringToLines( GetRowLabelValue( row
), lines
);
9679 wxClientDC
dc( m_rowLabelWin
);
9680 GetTextBoxSize( dc
, lines
, &w
, &h
);
9681 if( h
< m_defaultRowHeight
)
9682 h
= m_defaultRowHeight
;
9687 void wxGrid::AutoSizeColLabelSize( int col
)
9689 wxArrayString lines
;
9692 // Hide the edit control, so it
9693 // won't interfer with drag-shrinking.
9694 if( IsCellEditControlShown() )
9696 HideCellEditControl();
9697 SaveEditControlValue();
9700 // autosize column width depending on label text
9701 StringToLines( GetColLabelValue( col
), lines
);
9702 wxClientDC
dc( m_colLabelWin
);
9703 if( GetColLabelTextOrientation() == wxHORIZONTAL
)
9704 GetTextBoxSize( dc
, lines
, &w
, &h
);
9706 GetTextBoxSize( dc
, lines
, &h
, &w
);
9707 if( w
< m_defaultColWidth
)
9708 w
= m_defaultColWidth
;
9713 wxSize
wxGrid::DoGetBestSize() const
9715 // don't set sizes, only calculate them
9716 wxGrid
*self
= (wxGrid
*)this; // const_cast
9719 width
= self
->SetOrCalcColumnSizes(TRUE
);
9720 height
= self
->SetOrCalcRowSizes(TRUE
);
9722 int maxwidth
, maxheight
;
9723 wxDisplaySize( & maxwidth
, & maxheight
);
9725 if ( width
> maxwidth
) width
= maxwidth
;
9726 if ( height
> maxheight
) height
= maxheight
;
9728 return wxSize( width
, height
);
9737 wxPen
& wxGrid::GetDividerPen() const
9742 // ----------------------------------------------------------------------------
9743 // cell value accessor functions
9744 // ----------------------------------------------------------------------------
9746 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
9750 m_table
->SetValue( row
, col
, s
);
9751 if ( !GetBatchCount() )
9754 wxRect
rect( CellToRect( row
, col
) );
9756 rect
.width
= m_gridWin
->GetClientSize().GetWidth();
9757 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
9758 m_gridWin
->Refresh( FALSE
, &rect
);
9761 if ( m_currentCellCoords
.GetRow() == row
&&
9762 m_currentCellCoords
.GetCol() == col
&&
9763 IsCellEditControlShown())
9764 // Note: If we are using IsCellEditControlEnabled,
9765 // this interacts badly with calling SetCellValue from
9766 // an EVT_GRID_CELL_CHANGE handler.
9768 HideCellEditControl();
9769 ShowCellEditControl(); // will reread data from table
9776 // ------ Block, row and col selection
9779 void wxGrid::SelectRow( int row
, bool addToSelected
)
9781 if ( IsSelection() && !addToSelected
)
9785 m_selection
->SelectRow( row
, FALSE
, addToSelected
);
9789 void wxGrid::SelectCol( int col
, bool addToSelected
)
9791 if ( IsSelection() && !addToSelected
)
9795 m_selection
->SelectCol( col
, FALSE
, addToSelected
);
9799 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
9800 bool addToSelected
)
9802 if ( IsSelection() && !addToSelected
)
9806 m_selection
->SelectBlock( topRow
, leftCol
, bottomRow
, rightCol
,
9807 FALSE
, addToSelected
);
9811 void wxGrid::SelectAll()
9813 if ( m_numRows
> 0 && m_numCols
> 0 )
9816 m_selection
->SelectBlock( 0, 0, m_numRows
-1, m_numCols
-1 );
9821 // ------ Cell, row and col deselection
9824 void wxGrid::DeselectRow( int row
)
9829 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectRows
)
9831 if ( m_selection
->IsInSelection(row
, 0 ) )
9832 m_selection
->ToggleCellSelection( row
, 0);
9836 int nCols
= GetNumberCols();
9837 for ( int i
= 0; i
< nCols
; i
++ )
9839 if ( m_selection
->IsInSelection(row
, i
) )
9840 m_selection
->ToggleCellSelection( row
, i
);
9845 void wxGrid::DeselectCol( int col
)
9850 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectColumns
)
9852 if ( m_selection
->IsInSelection(0, col
) )
9853 m_selection
->ToggleCellSelection( 0, col
);
9857 int nRows
= GetNumberRows();
9858 for ( int i
= 0; i
< nRows
; i
++ )
9860 if ( m_selection
->IsInSelection(i
, col
) )
9861 m_selection
->ToggleCellSelection(i
, col
);
9866 void wxGrid::DeselectCell( int row
, int col
)
9868 if ( m_selection
&& m_selection
->IsInSelection(row
, col
) )
9869 m_selection
->ToggleCellSelection(row
, col
);
9872 bool wxGrid::IsSelection()
9874 return ( m_selection
&& (m_selection
->IsSelection() ||
9875 ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
9876 m_selectingBottomRight
!= wxGridNoCellCoords
) ) );
9879 bool wxGrid::IsInSelection( int row
, int col
) const
9881 return ( m_selection
&& (m_selection
->IsInSelection( row
, col
) ||
9882 ( row
>= m_selectingTopLeft
.GetRow() &&
9883 col
>= m_selectingTopLeft
.GetCol() &&
9884 row
<= m_selectingBottomRight
.GetRow() &&
9885 col
<= m_selectingBottomRight
.GetCol() )) );
9888 wxGridCellCoordsArray
wxGrid::GetSelectedCells() const
9890 if (!m_selection
) { wxGridCellCoordsArray a
; return a
; }
9891 return m_selection
->m_cellSelection
;
9893 wxGridCellCoordsArray
wxGrid::GetSelectionBlockTopLeft() const
9895 if (!m_selection
) { wxGridCellCoordsArray a
; return a
; }
9896 return m_selection
->m_blockSelectionTopLeft
;
9898 wxGridCellCoordsArray
wxGrid::GetSelectionBlockBottomRight() const
9900 if (!m_selection
) { wxGridCellCoordsArray a
; return a
; }
9901 return m_selection
->m_blockSelectionBottomRight
;
9903 wxArrayInt
wxGrid::GetSelectedRows() const
9905 if (!m_selection
) { wxArrayInt a
; return a
; }
9906 return m_selection
->m_rowSelection
;
9908 wxArrayInt
wxGrid::GetSelectedCols() const
9910 if (!m_selection
) { wxArrayInt a
; return a
; }
9911 return m_selection
->m_colSelection
;
9915 void wxGrid::ClearSelection()
9917 m_selectingTopLeft
= wxGridNoCellCoords
;
9918 m_selectingBottomRight
= wxGridNoCellCoords
;
9920 m_selection
->ClearSelection();
9924 // This function returns the rectangle that encloses the given block
9925 // in device coords clipped to the client size of the grid window.
9927 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
9928 const wxGridCellCoords
&bottomRight
)
9930 wxRect
rect( wxGridNoCellRect
);
9933 cellRect
= CellToRect( topLeft
);
9934 if ( cellRect
!= wxGridNoCellRect
)
9940 rect
= wxRect( 0, 0, 0, 0 );
9943 cellRect
= CellToRect( bottomRight
);
9944 if ( cellRect
!= wxGridNoCellRect
)
9950 return wxGridNoCellRect
;
9954 int left
= rect
.GetLeft();
9955 int top
= rect
.GetTop();
9956 int right
= rect
.GetRight();
9957 int bottom
= rect
.GetBottom();
9959 int leftCol
= topLeft
.GetCol();
9960 int topRow
= topLeft
.GetRow();
9961 int rightCol
= bottomRight
.GetCol();
9962 int bottomRow
= bottomRight
.GetRow();
9985 for ( j
= topRow
; j
<= bottomRow
; j
++ )
9987 for ( i
= leftCol
; i
<= rightCol
; i
++ )
9989 if ((j
==topRow
) || (j
==bottomRow
) || (i
==leftCol
) || (i
==rightCol
))
9991 cellRect
= CellToRect( j
, i
);
9993 if (cellRect
.x
< left
)
9995 if (cellRect
.y
< top
)
9997 if (cellRect
.x
+ cellRect
.width
> right
)
9998 right
= cellRect
.x
+ cellRect
.width
;
9999 if (cellRect
.y
+ cellRect
.height
> bottom
)
10000 bottom
= cellRect
.y
+ cellRect
.height
;
10002 else i
= rightCol
; // jump over inner cells.
10006 // convert to scrolled coords
10008 CalcScrolledPosition( left
, top
, &left
, &top
);
10009 CalcScrolledPosition( right
, bottom
, &right
, &bottom
);
10012 m_gridWin
->GetClientSize( &cw
, &ch
);
10014 if (right
< 0 || bottom
< 0 || left
> cw
|| top
> ch
)
10015 return wxRect( 0, 0, 0, 0);
10017 rect
.SetLeft( wxMax(0, left
) );
10018 rect
.SetTop( wxMax(0, top
) );
10019 rect
.SetRight( wxMin(cw
, right
) );
10020 rect
.SetBottom( wxMin(ch
, bottom
) );
10026 // ------ Grid event classes
10029 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxNotifyEvent
)
10031 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
10032 int row
, int col
, int x
, int y
, bool sel
,
10033 bool control
, bool shift
, bool alt
, bool meta
)
10034 : wxNotifyEvent( type
, id
)
10041 m_control
= control
;
10046 SetEventObject(obj
);
10050 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxNotifyEvent
)
10052 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
10053 int rowOrCol
, int x
, int y
,
10054 bool control
, bool shift
, bool alt
, bool meta
)
10055 : wxNotifyEvent( type
, id
)
10057 m_rowOrCol
= rowOrCol
;
10060 m_control
= control
;
10065 SetEventObject(obj
);
10069 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxNotifyEvent
)
10071 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
10072 const wxGridCellCoords
& topLeft
,
10073 const wxGridCellCoords
& bottomRight
,
10074 bool sel
, bool control
,
10075 bool shift
, bool alt
, bool meta
)
10076 : wxNotifyEvent( type
, id
)
10078 m_topLeft
= topLeft
;
10079 m_bottomRight
= bottomRight
;
10081 m_control
= control
;
10086 SetEventObject(obj
);
10090 IMPLEMENT_DYNAMIC_CLASS(wxGridEditorCreatedEvent
, wxCommandEvent
)
10092 wxGridEditorCreatedEvent::wxGridEditorCreatedEvent(int id
, wxEventType type
,
10093 wxObject
* obj
, int row
,
10094 int col
, wxControl
* ctrl
)
10095 : wxCommandEvent(type
, id
)
10097 SetEventObject(obj
);
10103 #endif // wxUSE_GRID