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 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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_ARRAY_WITH_DECL_NO_PTR(wxGridCellAttr
*, wxArrayAttrs
,
73 class WXDLLIMPEXP_ADV
);
75 struct wxGridCellWithAttr
77 wxGridCellWithAttr(int row
, int col
, wxGridCellAttr
*attr_
)
78 : coords(row
, col
), attr(attr_
)
87 wxGridCellCoords coords
;
91 // DECLARE_NO_COPY_CLASS(wxGridCellWithAttr)
92 // without rewriting the macros, which require a public copy constructor.
95 WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellWithAttr
, wxGridCellWithAttrArray
,
96 class WXDLLIMPEXP_ADV
);
98 #include "wx/arrimpl.cpp"
100 WX_DEFINE_OBJARRAY(wxGridCellCoordsArray
)
101 WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray
)
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_CLICK
)
108 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_CLICK
)
109 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_DCLICK
)
110 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_DCLICK
)
111 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_CLICK
)
112 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_CLICK
)
113 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_DCLICK
)
114 DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_DCLICK
)
115 DEFINE_EVENT_TYPE(wxEVT_GRID_ROW_SIZE
)
116 DEFINE_EVENT_TYPE(wxEVT_GRID_COL_SIZE
)
117 DEFINE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT
)
118 DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGE
)
119 DEFINE_EVENT_TYPE(wxEVT_GRID_SELECT_CELL
)
120 DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN
)
121 DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN
)
122 DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_CREATED
)
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
128 class WXDLLIMPEXP_ADV wxGridRowLabelWindow
: public wxWindow
131 wxGridRowLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
132 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
133 const wxPoint
&pos
, const wxSize
&size
);
138 void OnPaint( wxPaintEvent
& event
);
139 void OnMouseEvent( wxMouseEvent
& event
);
140 void OnMouseWheel( wxMouseEvent
& event
);
141 void OnKeyDown( wxKeyEvent
& event
);
142 void OnKeyUp( wxKeyEvent
& );
144 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
145 DECLARE_EVENT_TABLE()
146 DECLARE_NO_COPY_CLASS(wxGridRowLabelWindow
)
150 class WXDLLIMPEXP_ADV wxGridColLabelWindow
: public wxWindow
153 wxGridColLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
154 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
155 const wxPoint
&pos
, const wxSize
&size
);
160 void OnPaint( wxPaintEvent
&event
);
161 void OnMouseEvent( wxMouseEvent
& event
);
162 void OnMouseWheel( wxMouseEvent
& event
);
163 void OnKeyDown( wxKeyEvent
& event
);
164 void OnKeyUp( wxKeyEvent
& );
166 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
167 DECLARE_EVENT_TABLE()
168 DECLARE_NO_COPY_CLASS(wxGridColLabelWindow
)
172 class WXDLLIMPEXP_ADV wxGridCornerLabelWindow
: public wxWindow
175 wxGridCornerLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
176 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
177 const wxPoint
&pos
, const wxSize
&size
);
182 void OnMouseEvent( wxMouseEvent
& event
);
183 void OnMouseWheel( wxMouseEvent
& event
);
184 void OnKeyDown( wxKeyEvent
& event
);
185 void OnKeyUp( wxKeyEvent
& );
186 void OnPaint( wxPaintEvent
& event
);
188 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
189 DECLARE_EVENT_TABLE()
190 DECLARE_NO_COPY_CLASS(wxGridCornerLabelWindow
)
193 class WXDLLIMPEXP_ADV wxGridWindow
: public wxWindow
198 m_owner
= (wxGrid
*)NULL
;
199 m_rowLabelWin
= (wxGridRowLabelWindow
*)NULL
;
200 m_colLabelWin
= (wxGridColLabelWindow
*)NULL
;
203 wxGridWindow( wxGrid
*parent
,
204 wxGridRowLabelWindow
*rowLblWin
,
205 wxGridColLabelWindow
*colLblWin
,
206 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
209 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
211 wxGrid
* GetOwner() { return m_owner
; }
215 wxGridRowLabelWindow
*m_rowLabelWin
;
216 wxGridColLabelWindow
*m_colLabelWin
;
218 void OnPaint( wxPaintEvent
&event
);
219 void OnMouseWheel( wxMouseEvent
& event
);
220 void OnMouseEvent( wxMouseEvent
& event
);
221 void OnKeyDown( wxKeyEvent
& );
222 void OnKeyUp( wxKeyEvent
& );
223 void OnEraseBackground( wxEraseEvent
& );
226 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
227 DECLARE_EVENT_TABLE()
228 DECLARE_NO_COPY_CLASS(wxGridWindow
)
233 class wxGridCellEditorEvtHandler
: public wxEvtHandler
236 wxGridCellEditorEvtHandler()
237 : m_grid(0), m_editor(0)
239 wxGridCellEditorEvtHandler(wxGrid
* grid
, wxGridCellEditor
* editor
)
240 : m_grid(grid
), m_editor(editor
)
243 void OnKeyDown(wxKeyEvent
& event
);
244 void OnChar(wxKeyEvent
& event
);
248 wxGridCellEditor
* m_editor
;
249 DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler
)
250 DECLARE_EVENT_TABLE()
251 DECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler
)
255 IMPLEMENT_DYNAMIC_CLASS( wxGridCellEditorEvtHandler
, wxEvtHandler
)
256 BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler
, wxEvtHandler
)
257 EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown
)
258 EVT_CHAR( wxGridCellEditorEvtHandler::OnChar
)
263 // ----------------------------------------------------------------------------
264 // the internal data representation used by wxGridCellAttrProvider
265 // ----------------------------------------------------------------------------
267 // this class stores attributes set for cells
268 class WXDLLIMPEXP_ADV wxGridCellAttrData
271 void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
272 wxGridCellAttr
*GetAttr(int row
, int col
) const;
273 void UpdateAttrRows( size_t pos
, int numRows
);
274 void UpdateAttrCols( size_t pos
, int numCols
);
277 // searches for the attr for given cell, returns wxNOT_FOUND if not found
278 int FindIndex(int row
, int col
) const;
280 wxGridCellWithAttrArray m_attrs
;
283 // this class stores attributes set for rows or columns
284 class WXDLLIMPEXP_ADV wxGridRowOrColAttrData
287 // empty ctor to suppress warnings
288 wxGridRowOrColAttrData() { }
289 ~wxGridRowOrColAttrData();
291 void SetAttr(wxGridCellAttr
*attr
, int rowOrCol
);
292 wxGridCellAttr
*GetAttr(int rowOrCol
) const;
293 void UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
);
296 wxArrayInt m_rowsOrCols
;
297 wxArrayAttrs m_attrs
;
300 // NB: this is just a wrapper around 3 objects: one which stores cell
301 // attributes, and 2 others for row/col ones
302 class WXDLLIMPEXP_ADV wxGridCellAttrProviderData
305 wxGridCellAttrData m_cellAttrs
;
306 wxGridRowOrColAttrData m_rowAttrs
,
311 // ----------------------------------------------------------------------------
312 // data structures used for the data type registry
313 // ----------------------------------------------------------------------------
315 struct wxGridDataTypeInfo
317 wxGridDataTypeInfo(const wxString
& typeName
,
318 wxGridCellRenderer
* renderer
,
319 wxGridCellEditor
* editor
)
320 : m_typeName(typeName
), m_renderer(renderer
), m_editor(editor
)
323 ~wxGridDataTypeInfo()
325 wxSafeDecRef(m_renderer
);
326 wxSafeDecRef(m_editor
);
330 wxGridCellRenderer
* m_renderer
;
331 wxGridCellEditor
* m_editor
;
333 DECLARE_NO_COPY_CLASS(wxGridDataTypeInfo
)
337 WX_DEFINE_ARRAY_WITH_DECL_NO_PTR(wxGridDataTypeInfo
*, wxGridDataTypeInfoArray
,
338 class WXDLLIMPEXP_ADV
);
341 class WXDLLIMPEXP_ADV wxGridTypeRegistry
344 wxGridTypeRegistry() {}
345 ~wxGridTypeRegistry();
347 void RegisterDataType(const wxString
& typeName
,
348 wxGridCellRenderer
* renderer
,
349 wxGridCellEditor
* editor
);
351 // find one of already registered data types
352 int FindRegisteredDataType(const wxString
& typeName
);
354 // try to FindRegisteredDataType(), if this fails and typeName is one of
355 // standard typenames, register it and return its index
356 int FindDataType(const wxString
& typeName
);
358 // try to FindDataType(), if it fails see if it is not one of already
359 // registered data types with some params in which case clone the
360 // registered data type and set params for it
361 int FindOrCloneDataType(const wxString
& typeName
);
363 wxGridCellRenderer
* GetRenderer(int index
);
364 wxGridCellEditor
* GetEditor(int index
);
367 wxGridDataTypeInfoArray m_typeinfo
;
370 // ----------------------------------------------------------------------------
371 // conditional compilation
372 // ----------------------------------------------------------------------------
374 #ifndef WXGRID_DRAW_LINES
375 #define WXGRID_DRAW_LINES 1
378 // ----------------------------------------------------------------------------
380 // ----------------------------------------------------------------------------
382 //#define DEBUG_ATTR_CACHE
383 #ifdef DEBUG_ATTR_CACHE
384 static size_t gs_nAttrCacheHits
= 0;
385 static size_t gs_nAttrCacheMisses
= 0;
386 #endif // DEBUG_ATTR_CACHE
388 // ----------------------------------------------------------------------------
390 // ----------------------------------------------------------------------------
392 wxGridCellCoords
wxGridNoCellCoords( -1, -1 );
393 wxRect
wxGridNoCellRect( -1, -1, -1, -1 );
396 // TODO: this doesn't work at all, grid cells have different sizes and approx
397 // calculations don't work as because of the size mismatch scrollbars
398 // sometimes fail to be shown when they should be or vice versa
400 // The scroll bars may be a little flakey once in a while, but that is
401 // surely much less horrible than having scroll lines of only 1!!!
404 // Well, it's still seriously broken so it might be better but needs
407 static const size_t GRID_SCROLL_LINE_X
= 15; // 1;
408 static const size_t GRID_SCROLL_LINE_Y
= GRID_SCROLL_LINE_X
;
410 // the size of hash tables used a bit everywhere (the max number of elements
411 // in these hash tables is the number of rows/columns)
412 static const int GRID_HASH_SIZE
= 100;
414 // ----------------------------------------------------------------------------
416 // ----------------------------------------------------------------------------
418 static inline int GetScrollX(int x
)
420 return (x
+ GRID_SCROLL_LINE_X
- 1) / GRID_SCROLL_LINE_X
;
423 static inline int GetScrollY(int y
)
425 return (y
+ GRID_SCROLL_LINE_Y
- 1) / GRID_SCROLL_LINE_Y
;
428 // ============================================================================
430 // ============================================================================
432 // ----------------------------------------------------------------------------
434 // ----------------------------------------------------------------------------
436 wxGridCellEditor::wxGridCellEditor()
443 wxGridCellEditor::~wxGridCellEditor()
448 void wxGridCellEditor::Create(wxWindow
* WXUNUSED(parent
),
449 wxWindowID
WXUNUSED(id
),
450 wxEvtHandler
* evtHandler
)
453 m_control
->PushEventHandler(evtHandler
);
456 void wxGridCellEditor::PaintBackground(const wxRect
& rectCell
,
457 wxGridCellAttr
*attr
)
459 // erase the background because we might not fill the cell
460 wxClientDC
dc(m_control
->GetParent());
461 wxGridWindow
* gridWindow
= wxDynamicCast(m_control
->GetParent(), wxGridWindow
);
463 gridWindow
->GetOwner()->PrepareDC(dc
);
465 dc
.SetPen(*wxTRANSPARENT_PEN
);
466 dc
.SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
467 dc
.DrawRectangle(rectCell
);
469 // redraw the control we just painted over
470 m_control
->Refresh();
473 void wxGridCellEditor::Destroy()
477 m_control
->PopEventHandler(TRUE
/* delete it*/);
479 m_control
->Destroy();
484 void wxGridCellEditor::Show(bool show
, wxGridCellAttr
*attr
)
486 wxASSERT_MSG(m_control
,
487 wxT("The wxGridCellEditor must be Created first!"));
488 m_control
->Show(show
);
492 // set the colours/fonts if we have any
495 m_colFgOld
= m_control
->GetForegroundColour();
496 m_control
->SetForegroundColour(attr
->GetTextColour());
498 m_colBgOld
= m_control
->GetBackgroundColour();
499 m_control
->SetBackgroundColour(attr
->GetBackgroundColour());
501 m_fontOld
= m_control
->GetFont();
502 m_control
->SetFont(attr
->GetFont());
504 // can't do anything more in the base class version, the other
505 // attributes may only be used by the derived classes
510 // restore the standard colours fonts
511 if ( m_colFgOld
.Ok() )
513 m_control
->SetForegroundColour(m_colFgOld
);
514 m_colFgOld
= wxNullColour
;
517 if ( m_colBgOld
.Ok() )
519 m_control
->SetBackgroundColour(m_colBgOld
);
520 m_colBgOld
= wxNullColour
;
523 if ( m_fontOld
.Ok() )
525 m_control
->SetFont(m_fontOld
);
526 m_fontOld
= wxNullFont
;
531 void wxGridCellEditor::SetSize(const wxRect
& rect
)
533 wxASSERT_MSG(m_control
,
534 wxT("The wxGridCellEditor must be Created first!"));
535 m_control
->SetSize(rect
, wxSIZE_ALLOW_MINUS_ONE
);
538 void wxGridCellEditor::HandleReturn(wxKeyEvent
& event
)
543 bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent
& event
)
545 // accept the simple key presses, not anything with Ctrl/Alt/Meta
546 return !(event
.ControlDown() || event
.AltDown());
549 void wxGridCellEditor::StartingKey(wxKeyEvent
& event
)
554 void wxGridCellEditor::StartingClick()
560 // ----------------------------------------------------------------------------
561 // wxGridCellTextEditor
562 // ----------------------------------------------------------------------------
564 wxGridCellTextEditor::wxGridCellTextEditor()
569 void wxGridCellTextEditor::Create(wxWindow
* parent
,
571 wxEvtHandler
* evtHandler
)
573 m_control
= new wxTextCtrl(parent
, id
, wxEmptyString
,
574 wxDefaultPosition
, wxDefaultSize
575 #if defined(__WXMSW__)
576 , wxTE_PROCESS_TAB
| wxTE_MULTILINE
|
577 wxTE_NO_VSCROLL
| wxTE_AUTO_SCROLL
581 // set max length allowed in the textctrl, if the parameter was set
584 ((wxTextCtrl
*)m_control
)->SetMaxLength(m_maxChars
);
587 wxGridCellEditor::Create(parent
, id
, evtHandler
);
590 void wxGridCellTextEditor::PaintBackground(const wxRect
& WXUNUSED(rectCell
),
591 wxGridCellAttr
* WXUNUSED(attr
))
593 // as we fill the entire client area, don't do anything here to minimize
597 void wxGridCellTextEditor::SetSize(const wxRect
& rectOrig
)
599 wxRect
rect(rectOrig
);
601 // Make the edit control large enough to allow for internal
604 // TODO: remove this if the text ctrl sizing is improved esp. for
607 #if defined(__WXGTK__)
616 int extra_x
= ( rect
.x
> 2 )? 2 : 1;
618 // MB: treat MSW separately here otherwise the caret doesn't show
619 // when the editor is in the first row.
620 #if defined(__WXMSW__)
623 int extra_y
= ( rect
.y
> 2 )? 2 : 1;
626 #if defined(__WXMOTIF__)
630 rect
.SetLeft( wxMax(0, rect
.x
- extra_x
) );
631 rect
.SetTop( wxMax(0, rect
.y
- extra_y
) );
632 rect
.SetRight( rect
.GetRight() + 2*extra_x
);
633 rect
.SetBottom( rect
.GetBottom() + 2*extra_y
);
636 wxGridCellEditor::SetSize(rect
);
639 void wxGridCellTextEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
641 wxASSERT_MSG(m_control
,
642 wxT("The wxGridCellEditor must be Created first!"));
644 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
646 DoBeginEdit(m_startValue
);
649 void wxGridCellTextEditor::DoBeginEdit(const wxString
& startValue
)
651 Text()->SetValue(startValue
);
652 Text()->SetInsertionPointEnd();
653 Text()->SetSelection(-1,-1);
657 bool wxGridCellTextEditor::EndEdit(int row
, int col
,
660 wxASSERT_MSG(m_control
,
661 wxT("The wxGridCellEditor must be Created first!"));
663 bool changed
= FALSE
;
664 wxString value
= Text()->GetValue();
665 if (value
!= m_startValue
)
669 grid
->GetTable()->SetValue(row
, col
, value
);
671 m_startValue
= wxEmptyString
;
672 Text()->SetValue(m_startValue
);
678 void wxGridCellTextEditor::Reset()
680 wxASSERT_MSG(m_control
,
681 wxT("The wxGridCellEditor must be Created first!"));
683 DoReset(m_startValue
);
686 void wxGridCellTextEditor::DoReset(const wxString
& startValue
)
688 Text()->SetValue(startValue
);
689 Text()->SetInsertionPointEnd();
692 bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent
& event
)
694 if ( wxGridCellEditor::IsAcceptedKey(event
) )
696 int keycode
= event
.GetKeyCode();
710 case WXK_NUMPAD_MULTIPLY
:
714 case WXK_NUMPAD_SUBTRACT
:
716 case WXK_NUMPAD_DECIMAL
:
718 case WXK_NUMPAD_DIVIDE
:
722 // accept 8 bit chars too if isprint() agrees
723 if ( (keycode
< 255) && (wxIsprint(keycode
)) )
731 void wxGridCellTextEditor::StartingKey(wxKeyEvent
& event
)
733 if ( !Text()->EmulateKeyPress(event
) )
739 void wxGridCellTextEditor::HandleReturn( wxKeyEvent
&
740 WXUNUSED_GTK(WXUNUSED_MOTIF(event
)) )
742 #if defined(__WXMOTIF__) || defined(__WXGTK__)
743 // wxMotif needs a little extra help...
744 size_t pos
= (size_t)( Text()->GetInsertionPoint() );
745 wxString
s( Text()->GetValue() );
746 s
= s
.Left(pos
) + wxT("\n") + s
.Mid(pos
);
748 Text()->SetInsertionPoint( pos
);
750 // the other ports can handle a Return key press
756 void wxGridCellTextEditor::SetParameters(const wxString
& params
)
766 if ( !params
.ToLong(&tmp
) )
768 wxLogDebug(_T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params
.c_str());
772 m_maxChars
= (size_t)tmp
;
777 // return the value in the text control
778 wxString
wxGridCellTextEditor::GetValue() const
780 return Text()->GetValue();
783 // ----------------------------------------------------------------------------
784 // wxGridCellNumberEditor
785 // ----------------------------------------------------------------------------
787 wxGridCellNumberEditor::wxGridCellNumberEditor(int min
, int max
)
793 void wxGridCellNumberEditor::Create(wxWindow
* parent
,
795 wxEvtHandler
* evtHandler
)
799 // create a spin ctrl
800 m_control
= new wxSpinCtrl(parent
, -1, wxEmptyString
,
801 wxDefaultPosition
, wxDefaultSize
,
805 wxGridCellEditor::Create(parent
, id
, evtHandler
);
809 // just a text control
810 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
813 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
814 #endif // wxUSE_VALIDATORS
818 void wxGridCellNumberEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
820 // first get the value
821 wxGridTableBase
*table
= grid
->GetTable();
822 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
824 m_valueOld
= table
->GetValueAsLong(row
, col
);
829 wxString sValue
= table
->GetValue(row
, col
);
830 if (! sValue
.ToLong(&m_valueOld
) && ! sValue
.IsEmpty())
832 wxFAIL_MSG( _T("this cell doesn't have numeric value") );
839 Spin()->SetValue((int)m_valueOld
);
844 DoBeginEdit(GetString());
848 bool wxGridCellNumberEditor::EndEdit(int row
, int col
,
857 value
= Spin()->GetValue();
858 changed
= value
!= m_valueOld
;
860 text
= wxString::Format(wxT("%ld"), value
);
864 text
= Text()->GetValue();
865 changed
= (text
.IsEmpty() || text
.ToLong(&value
)) && (value
!= m_valueOld
);
870 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_NUMBER
))
871 grid
->GetTable()->SetValueAsLong(row
, col
, value
);
873 grid
->GetTable()->SetValue(row
, col
, text
);
879 void wxGridCellNumberEditor::Reset()
883 Spin()->SetValue((int)m_valueOld
);
887 DoReset(GetString());
891 bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent
& event
)
893 if ( wxGridCellEditor::IsAcceptedKey(event
) )
895 int keycode
= event
.GetKeyCode();
911 case WXK_NUMPAD_SUBTRACT
:
917 if ( (keycode
< 128) && wxIsdigit(keycode
) )
925 void wxGridCellNumberEditor::StartingKey(wxKeyEvent
& event
)
929 int keycode
= event
.GetKeyCode();
930 if ( wxIsdigit(keycode
) || keycode
== '+' || keycode
== '-'
931 || keycode
== WXK_NUMPAD0
932 || keycode
== WXK_NUMPAD1
933 || keycode
== WXK_NUMPAD2
934 || keycode
== WXK_NUMPAD3
935 || keycode
== WXK_NUMPAD4
936 || keycode
== WXK_NUMPAD5
937 || keycode
== WXK_NUMPAD6
938 || keycode
== WXK_NUMPAD7
939 || keycode
== WXK_NUMPAD8
940 || keycode
== WXK_NUMPAD9
941 || keycode
== WXK_ADD
942 || keycode
== WXK_NUMPAD_ADD
943 || keycode
== WXK_SUBTRACT
944 || keycode
== WXK_NUMPAD_SUBTRACT
)
946 wxGridCellTextEditor::StartingKey(event
);
956 void wxGridCellNumberEditor::SetParameters(const wxString
& params
)
967 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
971 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
975 // skip the error message below
980 wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string '%s' ignored"), params
.c_str());
984 // return the value in the spin control if it is there (the text control otherwise)
985 wxString
wxGridCellNumberEditor::GetValue() const
991 long value
= Spin()->GetValue();
992 s
.Printf(wxT("%ld"), value
);
996 s
= Text()->GetValue();
1001 // ----------------------------------------------------------------------------
1002 // wxGridCellFloatEditor
1003 // ----------------------------------------------------------------------------
1005 wxGridCellFloatEditor::wxGridCellFloatEditor(int width
, int precision
)
1008 m_precision
= precision
;
1011 void wxGridCellFloatEditor::Create(wxWindow
* parent
,
1013 wxEvtHandler
* evtHandler
)
1015 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
1017 #if wxUSE_VALIDATORS
1018 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
1019 #endif // wxUSE_VALIDATORS
1022 void wxGridCellFloatEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1024 // first get the value
1025 wxGridTableBase
*table
= grid
->GetTable();
1026 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
1028 m_valueOld
= table
->GetValueAsDouble(row
, col
);
1033 wxString sValue
= table
->GetValue(row
, col
);
1034 if (! sValue
.ToDouble(&m_valueOld
) && ! sValue
.IsEmpty())
1036 wxFAIL_MSG( _T("this cell doesn't have float value") );
1041 DoBeginEdit(GetString());
1044 bool wxGridCellFloatEditor::EndEdit(int row
, int col
,
1048 wxString
text(Text()->GetValue());
1050 if ( (text
.IsEmpty() || text
.ToDouble(&value
)) && (value
!= m_valueOld
) )
1052 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_FLOAT
))
1053 grid
->GetTable()->SetValueAsDouble(row
, col
, value
);
1055 grid
->GetTable()->SetValue(row
, col
, text
);
1062 void wxGridCellFloatEditor::Reset()
1064 DoReset(GetString());
1067 void wxGridCellFloatEditor::StartingKey(wxKeyEvent
& event
)
1069 int keycode
= event
.GetKeyCode();
1070 if ( wxIsdigit(keycode
) || keycode
== '+' || keycode
== '-' || keycode
== '.'
1071 || keycode
== WXK_NUMPAD0
1072 || keycode
== WXK_NUMPAD1
1073 || keycode
== WXK_NUMPAD2
1074 || keycode
== WXK_NUMPAD3
1075 || keycode
== WXK_NUMPAD4
1076 || keycode
== WXK_NUMPAD5
1077 || keycode
== WXK_NUMPAD6
1078 || keycode
== WXK_NUMPAD7
1079 || keycode
== WXK_NUMPAD8
1080 || keycode
== WXK_NUMPAD9
1081 || keycode
== WXK_ADD
1082 || keycode
== WXK_NUMPAD_ADD
1083 || keycode
== WXK_SUBTRACT
1084 || keycode
== WXK_NUMPAD_SUBTRACT
)
1086 wxGridCellTextEditor::StartingKey(event
);
1088 // skip Skip() below
1095 void wxGridCellFloatEditor::SetParameters(const wxString
& params
)
1106 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
1110 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
1112 m_precision
= (int)tmp
;
1114 // skip the error message below
1119 wxLogDebug(_T("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params
.c_str());
1123 wxString
wxGridCellFloatEditor::GetString() const
1126 if ( m_width
== -1 )
1128 // default width/precision
1131 else if ( m_precision
== -1 )
1133 // default precision
1134 fmt
.Printf(_T("%%%d.f"), m_width
);
1138 fmt
.Printf(_T("%%%d.%df"), m_width
, m_precision
);
1141 return wxString::Format(fmt
, m_valueOld
);
1144 bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent
& event
)
1146 if ( wxGridCellEditor::IsAcceptedKey(event
) )
1148 int keycode
= event
.GetKeyCode();
1162 case WXK_NUMPAD_ADD
:
1164 case WXK_NUMPAD_SUBTRACT
:
1166 case WXK_NUMPAD_DECIMAL
:
1170 // additionally accept 'e' as in '1e+6'
1171 if ( (keycode
< 128) &&
1172 (wxIsdigit(keycode
) || tolower(keycode
) == 'e') )
1180 #endif // wxUSE_TEXTCTRL
1184 // ----------------------------------------------------------------------------
1185 // wxGridCellBoolEditor
1186 // ----------------------------------------------------------------------------
1188 void wxGridCellBoolEditor::Create(wxWindow
* parent
,
1190 wxEvtHandler
* evtHandler
)
1192 m_control
= new wxCheckBox(parent
, id
, wxEmptyString
,
1193 wxDefaultPosition
, wxDefaultSize
,
1196 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1199 void wxGridCellBoolEditor::SetSize(const wxRect
& r
)
1201 bool resize
= FALSE
;
1202 wxSize size
= m_control
->GetSize();
1203 wxCoord minSize
= wxMin(r
.width
, r
.height
);
1205 // check if the checkbox is not too big/small for this cell
1206 wxSize sizeBest
= m_control
->GetBestSize();
1207 if ( !(size
== sizeBest
) )
1209 // reset to default size if it had been made smaller
1215 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
1217 // leave 1 pixel margin
1218 size
.x
= size
.y
= minSize
- 2;
1225 m_control
->SetSize(size
);
1228 // position it in the centre of the rectangle (TODO: support alignment?)
1230 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1231 // the checkbox without label still has some space to the right in wxGTK,
1232 // so shift it to the right
1234 #elif defined(__WXMSW__)
1235 // here too, but in other way
1240 int hAlign
= wxALIGN_CENTRE
;
1241 int vAlign
= wxALIGN_CENTRE
;
1243 GetCellAttr()->GetAlignment(& hAlign
, & vAlign
);
1246 if (hAlign
== wxALIGN_LEFT
)
1252 y
= r
.y
+ r
.height
/2 - size
.y
/2;
1254 else if (hAlign
== wxALIGN_RIGHT
)
1256 x
= r
.x
+ r
.width
- size
.x
- 2;
1257 y
= r
.y
+ r
.height
/2 - size
.y
/2;
1259 else if (hAlign
== wxALIGN_CENTRE
)
1261 x
= r
.x
+ r
.width
/2 - size
.x
/2;
1262 y
= r
.y
+ r
.height
/2 - size
.y
/2;
1265 m_control
->Move(x
, y
);
1268 void wxGridCellBoolEditor::Show(bool show
, wxGridCellAttr
*attr
)
1270 m_control
->Show(show
);
1274 wxColour colBg
= attr
? attr
->GetBackgroundColour() : *wxLIGHT_GREY
;
1275 CBox()->SetBackgroundColour(colBg
);
1279 void wxGridCellBoolEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1281 wxASSERT_MSG(m_control
,
1282 wxT("The wxGridCellEditor must be Created first!"));
1284 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
1285 m_startValue
= grid
->GetTable()->GetValueAsBool(row
, col
);
1288 wxString
cellval( grid
->GetTable()->GetValue(row
, col
) );
1289 m_startValue
= !( !cellval
|| (cellval
== wxT("0")) );
1291 CBox()->SetValue(m_startValue
);
1295 bool wxGridCellBoolEditor::EndEdit(int row
, int col
,
1298 wxASSERT_MSG(m_control
,
1299 wxT("The wxGridCellEditor must be Created first!"));
1301 bool changed
= FALSE
;
1302 bool value
= CBox()->GetValue();
1303 if ( value
!= m_startValue
)
1308 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
1309 grid
->GetTable()->SetValueAsBool(row
, col
, value
);
1311 grid
->GetTable()->SetValue(row
, col
, value
? _T("1") : wxEmptyString
);
1317 void wxGridCellBoolEditor::Reset()
1319 wxASSERT_MSG(m_control
,
1320 wxT("The wxGridCellEditor must be Created first!"));
1322 CBox()->SetValue(m_startValue
);
1325 void wxGridCellBoolEditor::StartingClick()
1327 CBox()->SetValue(!CBox()->GetValue());
1330 bool wxGridCellBoolEditor::IsAcceptedKey(wxKeyEvent
& event
)
1332 if ( wxGridCellEditor::IsAcceptedKey(event
) )
1334 int keycode
= event
.GetKeyCode();
1338 case WXK_NUMPAD_MULTIPLY
:
1340 case WXK_NUMPAD_ADD
:
1342 case WXK_NUMPAD_SUBTRACT
:
1353 // return the value as "1" for true and the empty string for false
1354 wxString
wxGridCellBoolEditor::GetValue() const
1356 bool bSet
= CBox()->GetValue();
1357 return bSet
? _T("1") : wxEmptyString
;
1360 #endif // wxUSE_CHECKBOX
1364 // ----------------------------------------------------------------------------
1365 // wxGridCellChoiceEditor
1366 // ----------------------------------------------------------------------------
1368 wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count
,
1369 const wxString choices
[],
1371 : m_allowOthers(allowOthers
)
1375 m_choices
.Alloc(count
);
1376 for ( size_t n
= 0; n
< count
; n
++ )
1378 m_choices
.Add(choices
[n
]);
1383 wxGridCellEditor
*wxGridCellChoiceEditor::Clone() const
1385 wxGridCellChoiceEditor
*editor
= new wxGridCellChoiceEditor
;
1386 editor
->m_allowOthers
= m_allowOthers
;
1387 editor
->m_choices
= m_choices
;
1392 void wxGridCellChoiceEditor::Create(wxWindow
* parent
,
1394 wxEvtHandler
* evtHandler
)
1396 size_t count
= m_choices
.GetCount();
1397 wxString
*choices
= new wxString
[count
];
1398 for ( size_t n
= 0; n
< count
; n
++ )
1400 choices
[n
] = m_choices
[n
];
1403 m_control
= new wxComboBox(parent
, id
, wxEmptyString
,
1404 wxDefaultPosition
, wxDefaultSize
,
1406 m_allowOthers
? 0 : wxCB_READONLY
);
1410 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1413 void wxGridCellChoiceEditor::PaintBackground(const wxRect
& rectCell
,
1414 wxGridCellAttr
* attr
)
1416 // as we fill the entire client area, don't do anything here to minimize
1419 // TODO: It doesn't actually fill the client area since the height of a
1420 // combo always defaults to the standard... Until someone has time to
1421 // figure out the right rectangle to paint, just do it the normal way...
1422 wxGridCellEditor::PaintBackground(rectCell
, attr
);
1425 void wxGridCellChoiceEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1427 wxASSERT_MSG(m_control
,
1428 wxT("The wxGridCellEditor must be Created first!"));
1430 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
1433 Combo()->SetValue(m_startValue
);
1436 // find the right position, or default to the first if not found
1437 int pos
= Combo()->FindString(m_startValue
);
1440 Combo()->SetSelection(pos
);
1442 Combo()->SetInsertionPointEnd();
1443 Combo()->SetFocus();
1446 bool wxGridCellChoiceEditor::EndEdit(int row
, int col
,
1449 wxString value
= Combo()->GetValue();
1450 bool changed
= value
!= m_startValue
;
1453 grid
->GetTable()->SetValue(row
, col
, value
);
1455 m_startValue
= wxEmptyString
;
1457 Combo()->SetValue(m_startValue
);
1459 Combo()->SetSelection(0);
1464 void wxGridCellChoiceEditor::Reset()
1466 Combo()->SetValue(m_startValue
);
1467 Combo()->SetInsertionPointEnd();
1470 void wxGridCellChoiceEditor::SetParameters(const wxString
& params
)
1480 wxStringTokenizer
tk(params
, _T(','));
1481 while ( tk
.HasMoreTokens() )
1483 m_choices
.Add(tk
.GetNextToken());
1487 // return the value in the text control
1488 wxString
wxGridCellChoiceEditor::GetValue() const
1490 return Combo()->GetValue();
1493 #endif // wxUSE_COMBOBOX
1495 // ----------------------------------------------------------------------------
1496 // wxGridCellEditorEvtHandler
1497 // ----------------------------------------------------------------------------
1499 void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent
& event
)
1501 switch ( event
.GetKeyCode() )
1505 m_grid
->DisableCellEditControl();
1509 m_grid
->GetEventHandler()->ProcessEvent( event
);
1513 case WXK_NUMPAD_ENTER
:
1514 if (!m_grid
->GetEventHandler()->ProcessEvent(event
))
1515 m_editor
->HandleReturn(event
);
1524 void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent
& event
)
1526 switch ( event
.GetKeyCode() )
1531 case WXK_NUMPAD_ENTER
:
1539 // ----------------------------------------------------------------------------
1540 // wxGridCellWorker is an (almost) empty common base class for
1541 // wxGridCellRenderer and wxGridCellEditor managing ref counting
1542 // ----------------------------------------------------------------------------
1544 void wxGridCellWorker::SetParameters(const wxString
& WXUNUSED(params
))
1549 wxGridCellWorker::~wxGridCellWorker()
1553 // ============================================================================
1555 // ============================================================================
1557 // ----------------------------------------------------------------------------
1558 // wxGridCellRenderer
1559 // ----------------------------------------------------------------------------
1561 void wxGridCellRenderer::Draw(wxGrid
& grid
,
1562 wxGridCellAttr
& attr
,
1565 int WXUNUSED(row
), int WXUNUSED(col
),
1568 dc
.SetBackgroundMode( wxSOLID
);
1570 // grey out fields if the grid is disabled
1571 if( grid
.IsEnabled() )
1575 dc
.SetBrush( wxBrush(grid
.GetSelectionBackground(), wxSOLID
) );
1579 dc
.SetBrush( wxBrush(attr
.GetBackgroundColour(), wxSOLID
) );
1584 dc
.SetBrush(wxBrush(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE
), wxSOLID
));
1587 dc
.SetPen( *wxTRANSPARENT_PEN
);
1588 dc
.DrawRectangle(rect
);
1591 // ----------------------------------------------------------------------------
1592 // wxGridCellStringRenderer
1593 // ----------------------------------------------------------------------------
1595 void wxGridCellStringRenderer::SetTextColoursAndFont(wxGrid
& grid
,
1596 wxGridCellAttr
& attr
,
1600 dc
.SetBackgroundMode( wxTRANSPARENT
);
1602 // TODO some special colours for attr.IsReadOnly() case?
1604 // different coloured text when the grid is disabled
1605 if( grid
.IsEnabled() )
1609 dc
.SetTextBackground( grid
.GetSelectionBackground() );
1610 dc
.SetTextForeground( grid
.GetSelectionForeground() );
1614 dc
.SetTextBackground( attr
.GetBackgroundColour() );
1615 dc
.SetTextForeground( attr
.GetTextColour() );
1620 dc
.SetTextBackground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE
));
1621 dc
.SetTextForeground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_GRAYTEXT
));
1624 dc
.SetFont( attr
.GetFont() );
1627 wxSize
wxGridCellStringRenderer::DoGetBestSize(wxGridCellAttr
& attr
,
1629 const wxString
& text
)
1631 wxCoord x
= 0, y
= 0, max_x
= 0;
1632 dc
.SetFont(attr
.GetFont());
1633 wxStringTokenizer
tk(text
, _T('\n'));
1634 while ( tk
.HasMoreTokens() )
1636 dc
.GetTextExtent(tk
.GetNextToken(), &x
, &y
);
1637 max_x
= wxMax(max_x
, x
);
1640 y
*= 1 + text
.Freq(wxT('\n')); // multiply by the number of lines.
1642 return wxSize(max_x
, y
);
1645 wxSize
wxGridCellStringRenderer::GetBestSize(wxGrid
& grid
,
1646 wxGridCellAttr
& attr
,
1650 return DoGetBestSize(attr
, dc
, grid
.GetCellValue(row
, col
));
1653 void wxGridCellStringRenderer::Draw(wxGrid
& grid
,
1654 wxGridCellAttr
& attr
,
1656 const wxRect
& rectCell
,
1660 wxRect rect
= rectCell
;
1663 // erase only this cells background, overflow cells should have been erased
1664 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1667 attr
.GetAlignment(&hAlign
, &vAlign
);
1669 int overflowCols
= 0;
1671 if (attr
.GetOverflow())
1673 int cols
= grid
.GetNumberCols();
1674 int best_width
= GetBestSize(grid
,attr
,dc
,row
,col
).GetWidth();
1675 int cell_rows
, cell_cols
;
1676 attr
.GetSize( &cell_rows
, &cell_cols
); // shouldn't get here if <=0
1677 if ((best_width
> rectCell
.width
) && (col
< cols
) && grid
.GetTable())
1679 int i
, c_cols
, c_rows
;
1680 for (i
= col
+cell_cols
; i
< cols
; i
++)
1682 bool is_empty
= TRUE
;
1683 for (int j
=row
; j
<row
+cell_rows
; j
++)
1685 // check w/ anchor cell for multicell block
1686 grid
.GetCellSize(j
, i
, &c_rows
, &c_cols
);
1687 if (c_rows
> 0) c_rows
= 0;
1688 if (!grid
.GetTable()->IsEmptyCell(j
+c_rows
, i
))
1695 rect
.width
+= grid
.GetColSize(i
);
1701 if (rect
.width
>= best_width
) break;
1703 overflowCols
= i
- col
- cell_cols
+ 1;
1704 if (overflowCols
>= cols
) overflowCols
= cols
- 1;
1707 if (overflowCols
> 0) // redraw overflow cells w/ proper hilight
1709 hAlign
= wxALIGN_LEFT
; // if oveflowed then it's left aligned
1711 clip
.x
+= rectCell
.width
;
1712 // draw each overflow cell individually
1713 int col_end
= col
+cell_cols
+overflowCols
;
1714 if (col_end
>= grid
.GetNumberCols())
1715 col_end
= grid
.GetNumberCols() - 1;
1716 for (int i
= col
+cell_cols
; i
<= col_end
; i
++)
1718 clip
.width
= grid
.GetColSize(i
) - 1;
1719 dc
.DestroyClippingRegion();
1720 dc
.SetClippingRegion(clip
);
1722 SetTextColoursAndFont(grid
, attr
, dc
,
1723 grid
.IsInSelection(row
,i
));
1725 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
1726 rect
, hAlign
, vAlign
);
1727 clip
.x
+= grid
.GetColSize(i
) - 1;
1733 dc
.DestroyClippingRegion();
1737 // now we only have to draw the text
1738 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1740 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
1741 rect
, hAlign
, vAlign
);
1744 // ----------------------------------------------------------------------------
1745 // wxGridCellNumberRenderer
1746 // ----------------------------------------------------------------------------
1748 wxString
wxGridCellNumberRenderer::GetString(wxGrid
& grid
, int row
, int col
)
1750 wxGridTableBase
*table
= grid
.GetTable();
1752 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
1754 text
.Printf(_T("%ld"), table
->GetValueAsLong(row
, col
));
1758 text
= table
->GetValue(row
, col
);
1764 void wxGridCellNumberRenderer::Draw(wxGrid
& grid
,
1765 wxGridCellAttr
& attr
,
1767 const wxRect
& rectCell
,
1771 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1773 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1775 // draw the text right aligned by default
1777 attr
.GetAlignment(&hAlign
, &vAlign
);
1778 hAlign
= wxALIGN_RIGHT
;
1780 wxRect rect
= rectCell
;
1783 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1786 wxSize
wxGridCellNumberRenderer::GetBestSize(wxGrid
& grid
,
1787 wxGridCellAttr
& attr
,
1791 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1794 // ----------------------------------------------------------------------------
1795 // wxGridCellFloatRenderer
1796 // ----------------------------------------------------------------------------
1798 wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width
, int precision
)
1801 SetPrecision(precision
);
1804 wxGridCellRenderer
*wxGridCellFloatRenderer::Clone() const
1806 wxGridCellFloatRenderer
*renderer
= new wxGridCellFloatRenderer
;
1807 renderer
->m_width
= m_width
;
1808 renderer
->m_precision
= m_precision
;
1809 renderer
->m_format
= m_format
;
1814 wxString
wxGridCellFloatRenderer::GetString(wxGrid
& grid
, int row
, int col
)
1816 wxGridTableBase
*table
= grid
.GetTable();
1821 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
1823 val
= table
->GetValueAsDouble(row
, col
);
1828 text
= table
->GetValue(row
, col
);
1829 hasDouble
= text
.ToDouble(&val
);
1836 if ( m_width
== -1 )
1838 if ( m_precision
== -1 )
1840 // default width/precision
1841 m_format
= _T("%f");
1845 m_format
.Printf(_T("%%.%df"), m_precision
);
1848 else if ( m_precision
== -1 )
1850 // default precision
1851 m_format
.Printf(_T("%%%d.f"), m_width
);
1855 m_format
.Printf(_T("%%%d.%df"), m_width
, m_precision
);
1859 text
.Printf(m_format
, val
);
1862 //else: text already contains the string
1867 void wxGridCellFloatRenderer::Draw(wxGrid
& grid
,
1868 wxGridCellAttr
& attr
,
1870 const wxRect
& rectCell
,
1874 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1876 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1878 // draw the text right aligned by default
1880 attr
.GetAlignment(&hAlign
, &vAlign
);
1881 hAlign
= wxALIGN_RIGHT
;
1883 wxRect rect
= rectCell
;
1886 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1889 wxSize
wxGridCellFloatRenderer::GetBestSize(wxGrid
& grid
,
1890 wxGridCellAttr
& attr
,
1894 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1897 void wxGridCellFloatRenderer::SetParameters(const wxString
& params
)
1901 // reset to defaults
1907 wxString tmp
= params
.BeforeFirst(_T(','));
1911 if ( tmp
.ToLong(&width
) )
1913 SetWidth((int)width
);
1917 wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params
.c_str());
1921 tmp
= params
.AfterFirst(_T(','));
1925 if ( tmp
.ToLong(&precision
) )
1927 SetPrecision((int)precision
);
1931 wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params
.c_str());
1939 // ----------------------------------------------------------------------------
1940 // wxGridCellBoolRenderer
1941 // ----------------------------------------------------------------------------
1943 wxSize
wxGridCellBoolRenderer::ms_sizeCheckMark
;
1945 // FIXME these checkbox size calculations are really ugly...
1947 // between checkmark and box
1948 static const wxCoord wxGRID_CHECKMARK_MARGIN
= 2;
1950 wxSize
wxGridCellBoolRenderer::GetBestSize(wxGrid
& grid
,
1951 wxGridCellAttr
& WXUNUSED(attr
),
1956 // compute it only once (no locks for MT safeness in GUI thread...)
1957 if ( !ms_sizeCheckMark
.x
)
1959 // get checkbox size
1960 wxCoord checkSize
= 0;
1961 wxCheckBox
*checkbox
= new wxCheckBox(&grid
, -1, wxEmptyString
);
1962 wxSize size
= checkbox
->GetBestSize();
1963 checkSize
= size
.y
+ 2*wxGRID_CHECKMARK_MARGIN
;
1965 // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result
1966 #if defined(__WXGTK__) || defined(__WXMOTIF__)
1967 checkSize
-= size
.y
/ 2;
1972 ms_sizeCheckMark
.x
= ms_sizeCheckMark
.y
= checkSize
;
1975 return ms_sizeCheckMark
;
1978 void wxGridCellBoolRenderer::Draw(wxGrid
& grid
,
1979 wxGridCellAttr
& attr
,
1985 wxGridCellRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
1987 // draw a check mark in the centre (ignoring alignment - TODO)
1988 wxSize size
= GetBestSize(grid
, attr
, dc
, row
, col
);
1990 // don't draw outside the cell
1991 wxCoord minSize
= wxMin(rect
.width
, rect
.height
);
1992 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
1994 // and even leave (at least) 1 pixel margin
1995 size
.x
= size
.y
= minSize
- 2;
1998 // draw a border around checkmark
2000 attr
.GetAlignment(& hAlign
, &vAlign
);
2003 if (hAlign
== wxALIGN_CENTRE
)
2005 rectBorder
.x
= rect
.x
+ rect
.width
/2 - size
.x
/2;
2006 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
2007 rectBorder
.width
= size
.x
;
2008 rectBorder
.height
= size
.y
;
2010 else if (hAlign
== wxALIGN_LEFT
)
2012 rectBorder
.x
= rect
.x
+ 2;
2013 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
2014 rectBorder
.width
= size
.x
;
2015 rectBorder
.height
= size
.y
;
2017 else if (hAlign
== wxALIGN_RIGHT
)
2019 rectBorder
.x
= rect
.x
+ rect
.width
- size
.x
- 2;
2020 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
2021 rectBorder
.width
= size
.x
;
2022 rectBorder
.height
= size
.y
;
2026 if ( grid
.GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
) )
2027 value
= grid
.GetTable()->GetValueAsBool(row
, col
);
2030 wxString
cellval( grid
.GetTable()->GetValue(row
, col
) );
2031 value
= !( !cellval
|| (cellval
== wxT("0")) );
2036 wxRect rectMark
= rectBorder
;
2038 // MSW DrawCheckMark() is weird (and should probably be changed...)
2039 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
/2);
2043 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
);
2046 dc
.SetTextForeground(attr
.GetTextColour());
2047 dc
.DrawCheckMark(rectMark
);
2050 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2051 dc
.SetPen(wxPen(attr
.GetTextColour(), 1, wxSOLID
));
2052 dc
.DrawRectangle(rectBorder
);
2055 // ----------------------------------------------------------------------------
2057 // ----------------------------------------------------------------------------
2059 void wxGridCellAttr::Init(wxGridCellAttr
*attrDefault
)
2063 m_isReadOnly
= Unset
;
2068 m_attrkind
= wxGridCellAttr::Cell
;
2070 m_sizeRows
= m_sizeCols
= 1;
2071 m_overflow
= UnsetOverflow
;
2073 SetDefAttr(attrDefault
);
2076 wxGridCellAttr
*wxGridCellAttr::Clone() const
2078 wxGridCellAttr
*attr
= new wxGridCellAttr(m_defGridAttr
);
2080 if ( HasTextColour() )
2081 attr
->SetTextColour(GetTextColour());
2082 if ( HasBackgroundColour() )
2083 attr
->SetBackgroundColour(GetBackgroundColour());
2085 attr
->SetFont(GetFont());
2086 if ( HasAlignment() )
2087 attr
->SetAlignment(m_hAlign
, m_vAlign
);
2089 attr
->SetSize( m_sizeRows
, m_sizeCols
);
2093 attr
->SetRenderer(m_renderer
);
2094 m_renderer
->IncRef();
2098 attr
->SetEditor(m_editor
);
2103 attr
->SetReadOnly();
2105 attr
->SetKind( m_attrkind
);
2110 void wxGridCellAttr::MergeWith(wxGridCellAttr
*mergefrom
)
2112 if ( !HasTextColour() && mergefrom
->HasTextColour() )
2113 SetTextColour(mergefrom
->GetTextColour());
2114 if ( !HasBackgroundColour() && mergefrom
->HasBackgroundColour() )
2115 SetBackgroundColour(mergefrom
->GetBackgroundColour());
2116 if ( !HasFont() && mergefrom
->HasFont() )
2117 SetFont(mergefrom
->GetFont());
2118 if ( !HasAlignment() && mergefrom
->HasAlignment() ){
2120 mergefrom
->GetAlignment( &hAlign
, &vAlign
);
2121 SetAlignment(hAlign
, vAlign
);
2124 mergefrom
->GetSize( &m_sizeRows
, &m_sizeCols
);
2126 // Directly access member functions as GetRender/Editor don't just return
2127 // m_renderer/m_editor
2129 // Maybe add support for merge of Render and Editor?
2130 if (!HasRenderer() && mergefrom
->HasRenderer() )
2132 m_renderer
= mergefrom
->m_renderer
;
2133 m_renderer
->IncRef();
2135 if ( !HasEditor() && mergefrom
->HasEditor() )
2137 m_editor
= mergefrom
->m_editor
;
2140 if ( !HasReadWriteMode() && mergefrom
->HasReadWriteMode() )
2141 SetReadOnly(mergefrom
->IsReadOnly());
2143 if (!HasOverflowMode() && mergefrom
->HasOverflowMode() )
2144 SetOverflow(mergefrom
->GetOverflow());
2146 SetDefAttr(mergefrom
->m_defGridAttr
);
2149 void wxGridCellAttr::SetSize(int num_rows
, int num_cols
)
2151 // The size of a cell is normally 1,1
2153 // If this cell is larger (2,2) then this is the top left cell
2154 // the other cells that will be covered (lower right cells) must be
2155 // set to negative or zero values such that
2156 // row + num_rows of the covered cell points to the larger cell (this cell)
2157 // same goes for the col + num_cols.
2159 // Size of 0,0 is NOT valid, neither is <=0 and any positive value
2161 wxASSERT_MSG( (!((num_rows
>0)&&(num_cols
<=0)) ||
2162 !((num_rows
<=0)&&(num_cols
>0)) ||
2163 !((num_rows
==0)&&(num_cols
==0))),
2164 wxT("wxGridCellAttr::SetSize only takes two postive values or negative/zero values"));
2166 m_sizeRows
= num_rows
;
2167 m_sizeCols
= num_cols
;
2170 const wxColour
& wxGridCellAttr::GetTextColour() const
2172 if (HasTextColour())
2176 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2178 return m_defGridAttr
->GetTextColour();
2182 wxFAIL_MSG(wxT("Missing default cell attribute"));
2183 return wxNullColour
;
2188 const wxColour
& wxGridCellAttr::GetBackgroundColour() const
2190 if (HasBackgroundColour())
2192 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2193 return m_defGridAttr
->GetBackgroundColour();
2196 wxFAIL_MSG(wxT("Missing default cell attribute"));
2197 return wxNullColour
;
2202 const wxFont
& wxGridCellAttr::GetFont() const
2206 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2207 return m_defGridAttr
->GetFont();
2210 wxFAIL_MSG(wxT("Missing default cell attribute"));
2216 void wxGridCellAttr::GetAlignment(int *hAlign
, int *vAlign
) const
2220 if ( hAlign
) *hAlign
= m_hAlign
;
2221 if ( vAlign
) *vAlign
= m_vAlign
;
2223 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2224 m_defGridAttr
->GetAlignment(hAlign
, vAlign
);
2227 wxFAIL_MSG(wxT("Missing default cell attribute"));
2231 void wxGridCellAttr::GetSize( int *num_rows
, int *num_cols
) const
2233 if ( num_rows
) *num_rows
= m_sizeRows
;
2234 if ( num_cols
) *num_cols
= m_sizeCols
;
2237 // GetRenderer and GetEditor use a slightly different decision path about
2238 // which attribute to use. If a non-default attr object has one then it is
2239 // used, otherwise the default editor or renderer is fetched from the grid and
2240 // used. It should be the default for the data type of the cell. If it is
2241 // NULL (because the table has a type that the grid does not have in its
2242 // registry,) then the grid's default editor or renderer is used.
2244 wxGridCellRenderer
* wxGridCellAttr::GetRenderer(wxGrid
* grid
, int row
, int col
) const
2246 wxGridCellRenderer
*renderer
;
2248 if ( m_renderer
&& this != m_defGridAttr
)
2250 // use the cells renderer if it has one
2251 renderer
= m_renderer
;
2254 else // no non default cell renderer
2256 // get default renderer for the data type
2259 // GetDefaultRendererForCell() will do IncRef() for us
2260 renderer
= grid
->GetDefaultRendererForCell(row
, col
);
2269 if (m_defGridAttr
&& this != m_defGridAttr
)
2271 // if we still don't have one then use the grid default
2272 // (no need for IncRef() here neither)
2273 renderer
= m_defGridAttr
->GetRenderer(NULL
, 0, 0);
2275 else // default grid attr
2277 // use m_renderer which we had decided not to use initially
2278 renderer
= m_renderer
;
2285 // we're supposed to always find something
2286 wxASSERT_MSG(renderer
, wxT("Missing default cell renderer"));
2291 // same as above, except for s/renderer/editor/g
2292 wxGridCellEditor
* wxGridCellAttr::GetEditor(wxGrid
* grid
, int row
, int col
) const
2294 wxGridCellEditor
*editor
;
2296 if ( m_editor
&& this != m_defGridAttr
)
2298 // use the cells editor if it has one
2302 else // no non default cell editor
2304 // get default editor for the data type
2307 // GetDefaultEditorForCell() will do IncRef() for us
2308 editor
= grid
->GetDefaultEditorForCell(row
, col
);
2317 if ( m_defGridAttr
&& this != m_defGridAttr
)
2319 // if we still don't have one then use the grid default
2320 // (no need for IncRef() here neither)
2321 editor
= m_defGridAttr
->GetEditor(NULL
, 0, 0);
2323 else // default grid attr
2325 // use m_editor which we had decided not to use initially
2333 // we're supposed to always find something
2334 wxASSERT_MSG(editor
, wxT("Missing default cell editor"));
2339 // ----------------------------------------------------------------------------
2340 // wxGridCellAttrData
2341 // ----------------------------------------------------------------------------
2343 void wxGridCellAttrData::SetAttr(wxGridCellAttr
*attr
, int row
, int col
)
2345 int n
= FindIndex(row
, col
);
2346 if ( n
== wxNOT_FOUND
)
2348 // add the attribute
2349 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
2353 // free the old attribute
2354 m_attrs
[(size_t)n
].attr
->DecRef();
2358 // change the attribute
2359 m_attrs
[(size_t)n
].attr
= attr
;
2363 // remove this attribute
2364 m_attrs
.RemoveAt((size_t)n
);
2369 wxGridCellAttr
*wxGridCellAttrData::GetAttr(int row
, int col
) const
2371 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2373 int n
= FindIndex(row
, col
);
2374 if ( n
!= wxNOT_FOUND
)
2376 attr
= m_attrs
[(size_t)n
].attr
;
2383 void wxGridCellAttrData::UpdateAttrRows( size_t pos
, int numRows
)
2385 size_t count
= m_attrs
.GetCount();
2386 for ( size_t n
= 0; n
< count
; n
++ )
2388 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2389 wxCoord row
= coords
.GetRow();
2390 if ((size_t)row
>= pos
)
2394 // If rows inserted, include row counter where necessary
2395 coords
.SetRow(row
+ numRows
);
2397 else if (numRows
< 0)
2399 // If rows deleted ...
2400 if ((size_t)row
>= pos
- numRows
)
2402 // ...either decrement row counter (if row still exists)...
2403 coords
.SetRow(row
+ numRows
);
2407 // ...or remove the attribute
2408 m_attrs
.RemoveAt((size_t)n
);
2416 void wxGridCellAttrData::UpdateAttrCols( size_t pos
, int numCols
)
2418 size_t count
= m_attrs
.GetCount();
2419 for ( size_t n
= 0; n
< count
; n
++ )
2421 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2422 wxCoord col
= coords
.GetCol();
2423 if ( (size_t)col
>= pos
)
2427 // If rows inserted, include row counter where necessary
2428 coords
.SetCol(col
+ numCols
);
2430 else if (numCols
< 0)
2432 // If rows deleted ...
2433 if ((size_t)col
>= pos
- numCols
)
2435 // ...either decrement row counter (if row still exists)...
2436 coords
.SetCol(col
+ numCols
);
2440 // ...or remove the attribute
2441 m_attrs
.RemoveAt((size_t)n
);
2449 int wxGridCellAttrData::FindIndex(int row
, int col
) const
2451 size_t count
= m_attrs
.GetCount();
2452 for ( size_t n
= 0; n
< count
; n
++ )
2454 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2455 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
2464 // ----------------------------------------------------------------------------
2465 // wxGridRowOrColAttrData
2466 // ----------------------------------------------------------------------------
2468 wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
2470 size_t count
= m_attrs
.Count();
2471 for ( size_t n
= 0; n
< count
; n
++ )
2473 m_attrs
[n
]->DecRef();
2477 wxGridCellAttr
*wxGridRowOrColAttrData::GetAttr(int rowOrCol
) const
2479 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2481 int n
= m_rowsOrCols
.Index(rowOrCol
);
2482 if ( n
!= wxNOT_FOUND
)
2484 attr
= m_attrs
[(size_t)n
];
2491 void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr
*attr
, int rowOrCol
)
2493 int i
= m_rowsOrCols
.Index(rowOrCol
);
2494 if ( i
== wxNOT_FOUND
)
2496 // add the attribute
2497 m_rowsOrCols
.Add(rowOrCol
);
2502 size_t n
= (size_t)i
;
2505 // change the attribute
2506 m_attrs
[n
]->DecRef();
2511 // remove this attribute
2512 m_attrs
[n
]->DecRef();
2513 m_rowsOrCols
.RemoveAt(n
);
2514 m_attrs
.RemoveAt(n
);
2519 void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
)
2521 size_t count
= m_attrs
.GetCount();
2522 for ( size_t n
= 0; n
< count
; n
++ )
2524 int & rowOrCol
= m_rowsOrCols
[n
];
2525 if ( (size_t)rowOrCol
>= pos
)
2527 if ( numRowsOrCols
> 0 )
2529 // If rows inserted, include row counter where necessary
2530 rowOrCol
+= numRowsOrCols
;
2532 else if ( numRowsOrCols
< 0)
2534 // If rows deleted, either decrement row counter (if row still exists)
2535 if ((size_t)rowOrCol
>= pos
- numRowsOrCols
)
2536 rowOrCol
+= numRowsOrCols
;
2539 m_rowsOrCols
.RemoveAt((size_t)n
);
2540 m_attrs
.RemoveAt((size_t)n
);
2548 // ----------------------------------------------------------------------------
2549 // wxGridCellAttrProvider
2550 // ----------------------------------------------------------------------------
2552 wxGridCellAttrProvider::wxGridCellAttrProvider()
2554 m_data
= (wxGridCellAttrProviderData
*)NULL
;
2557 wxGridCellAttrProvider::~wxGridCellAttrProvider()
2562 void wxGridCellAttrProvider::InitData()
2564 m_data
= new wxGridCellAttrProviderData
;
2567 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
,
2568 wxGridCellAttr::wxAttrKind kind
) const
2570 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2575 case (wxGridCellAttr::Any
):
2576 //Get cached merge attributes.
2577 // Currenlty not used as no cache implemented as not mutiable
2578 // attr = m_data->m_mergeAttr.GetAttr(row, col);
2581 //Basicaly implement old version.
2582 //Also check merge cache, so we don't have to re-merge every time..
2583 wxGridCellAttr
*attrcell
= (wxGridCellAttr
*)NULL
,
2584 *attrrow
= (wxGridCellAttr
*)NULL
,
2585 *attrcol
= (wxGridCellAttr
*)NULL
;
2587 attrcell
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
2588 attrcol
= m_data
->m_colAttrs
.GetAttr(col
);
2589 attrrow
= m_data
->m_rowAttrs
.GetAttr(row
);
2591 if((attrcell
!= attrrow
) && (attrrow
!=attrcol
) && (attrcell
!= attrcol
)){
2592 // Two or move are non NULL
2593 attr
= new wxGridCellAttr
;
2594 attr
->SetKind(wxGridCellAttr::Merged
);
2598 attr
->MergeWith(attrcell
);
2602 attr
->MergeWith(attrcol
);
2606 attr
->MergeWith(attrrow
);
2609 //store merge attr if cache implemented
2611 //m_data->m_mergeAttr.SetAttr(attr, row, col);
2615 // one or none is non null return it or null.
2616 if(attrrow
) attr
= attrrow
;
2617 if(attrcol
) attr
= attrcol
;
2618 if(attrcell
) attr
= attrcell
;
2622 case (wxGridCellAttr::Cell
):
2623 attr
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
2625 case (wxGridCellAttr::Col
):
2626 attr
= m_data
->m_colAttrs
.GetAttr(col
);
2628 case (wxGridCellAttr::Row
):
2629 attr
= m_data
->m_rowAttrs
.GetAttr(row
);
2633 // (wxGridCellAttr::Default):
2634 // (wxGridCellAttr::Merged):
2641 void wxGridCellAttrProvider::SetAttr(wxGridCellAttr
*attr
,
2647 m_data
->m_cellAttrs
.SetAttr(attr
, row
, col
);
2650 void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr
*attr
, int row
)
2655 m_data
->m_rowAttrs
.SetAttr(attr
, row
);
2658 void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr
*attr
, int col
)
2663 m_data
->m_colAttrs
.SetAttr(attr
, col
);
2666 void wxGridCellAttrProvider::UpdateAttrRows( size_t pos
, int numRows
)
2670 m_data
->m_cellAttrs
.UpdateAttrRows( pos
, numRows
);
2672 m_data
->m_rowAttrs
.UpdateAttrRowsOrCols( pos
, numRows
);
2676 void wxGridCellAttrProvider::UpdateAttrCols( size_t pos
, int numCols
)
2680 m_data
->m_cellAttrs
.UpdateAttrCols( pos
, numCols
);
2682 m_data
->m_colAttrs
.UpdateAttrRowsOrCols( pos
, numCols
);
2686 // ----------------------------------------------------------------------------
2687 // wxGridTypeRegistry
2688 // ----------------------------------------------------------------------------
2690 wxGridTypeRegistry::~wxGridTypeRegistry()
2692 size_t count
= m_typeinfo
.Count();
2693 for ( size_t i
= 0; i
< count
; i
++ )
2694 delete m_typeinfo
[i
];
2698 void wxGridTypeRegistry::RegisterDataType(const wxString
& typeName
,
2699 wxGridCellRenderer
* renderer
,
2700 wxGridCellEditor
* editor
)
2702 wxGridDataTypeInfo
* info
= new wxGridDataTypeInfo(typeName
, renderer
, editor
);
2704 // is it already registered?
2705 int loc
= FindRegisteredDataType(typeName
);
2706 if ( loc
!= wxNOT_FOUND
)
2708 delete m_typeinfo
[loc
];
2709 m_typeinfo
[loc
] = info
;
2713 m_typeinfo
.Add(info
);
2717 int wxGridTypeRegistry::FindRegisteredDataType(const wxString
& typeName
)
2719 size_t count
= m_typeinfo
.GetCount();
2720 for ( size_t i
= 0; i
< count
; i
++ )
2722 if ( typeName
== m_typeinfo
[i
]->m_typeName
)
2731 int wxGridTypeRegistry::FindDataType(const wxString
& typeName
)
2733 int index
= FindRegisteredDataType(typeName
);
2734 if ( index
== wxNOT_FOUND
)
2736 // check whether this is one of the standard ones, in which case
2737 // register it "on the fly"
2739 if ( typeName
== wxGRID_VALUE_STRING
)
2741 RegisterDataType(wxGRID_VALUE_STRING
,
2742 new wxGridCellStringRenderer
,
2743 new wxGridCellTextEditor
);
2745 #endif // wxUSE_TEXTCTRL
2747 if ( typeName
== wxGRID_VALUE_BOOL
)
2749 RegisterDataType(wxGRID_VALUE_BOOL
,
2750 new wxGridCellBoolRenderer
,
2751 new wxGridCellBoolEditor
);
2753 #endif // wxUSE_CHECKBOX
2755 if ( typeName
== wxGRID_VALUE_NUMBER
)
2757 RegisterDataType(wxGRID_VALUE_NUMBER
,
2758 new wxGridCellNumberRenderer
,
2759 new wxGridCellNumberEditor
);
2761 else if ( typeName
== wxGRID_VALUE_FLOAT
)
2763 RegisterDataType(wxGRID_VALUE_FLOAT
,
2764 new wxGridCellFloatRenderer
,
2765 new wxGridCellFloatEditor
);
2767 #endif // wxUSE_TEXTCTRL
2769 if ( typeName
== wxGRID_VALUE_CHOICE
)
2771 RegisterDataType(wxGRID_VALUE_CHOICE
,
2772 new wxGridCellStringRenderer
,
2773 new wxGridCellChoiceEditor
);
2775 #endif // wxUSE_COMBOBOX
2780 // we get here only if just added the entry for this type, so return
2782 index
= m_typeinfo
.GetCount() - 1;
2788 int wxGridTypeRegistry::FindOrCloneDataType(const wxString
& typeName
)
2790 int index
= FindDataType(typeName
);
2791 if ( index
== wxNOT_FOUND
)
2793 // the first part of the typename is the "real" type, anything after ':'
2794 // are the parameters for the renderer
2795 index
= FindDataType(typeName
.BeforeFirst(_T(':')));
2796 if ( index
== wxNOT_FOUND
)
2801 wxGridCellRenderer
*renderer
= GetRenderer(index
);
2802 wxGridCellRenderer
*rendererOld
= renderer
;
2803 renderer
= renderer
->Clone();
2804 rendererOld
->DecRef();
2806 wxGridCellEditor
*editor
= GetEditor(index
);
2807 wxGridCellEditor
*editorOld
= editor
;
2808 editor
= editor
->Clone();
2809 editorOld
->DecRef();
2811 // do it even if there are no parameters to reset them to defaults
2812 wxString params
= typeName
.AfterFirst(_T(':'));
2813 renderer
->SetParameters(params
);
2814 editor
->SetParameters(params
);
2816 // register the new typename
2817 RegisterDataType(typeName
, renderer
, editor
);
2819 // we just registered it, it's the last one
2820 index
= m_typeinfo
.GetCount() - 1;
2826 wxGridCellRenderer
* wxGridTypeRegistry::GetRenderer(int index
)
2828 wxGridCellRenderer
* renderer
= m_typeinfo
[index
]->m_renderer
;
2834 wxGridCellEditor
* wxGridTypeRegistry::GetEditor(int index
)
2836 wxGridCellEditor
* editor
= m_typeinfo
[index
]->m_editor
;
2842 // ----------------------------------------------------------------------------
2844 // ----------------------------------------------------------------------------
2846 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
2849 wxGridTableBase::wxGridTableBase()
2851 m_view
= (wxGrid
*) NULL
;
2852 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
2855 wxGridTableBase::~wxGridTableBase()
2857 delete m_attrProvider
;
2860 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
2862 delete m_attrProvider
;
2863 m_attrProvider
= attrProvider
;
2866 bool wxGridTableBase::CanHaveAttributes()
2868 if ( ! GetAttrProvider() )
2870 // use the default attr provider by default
2871 SetAttrProvider(new wxGridCellAttrProvider
);
2876 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
, wxGridCellAttr::wxAttrKind kind
)
2878 if ( m_attrProvider
)
2879 return m_attrProvider
->GetAttr(row
, col
, kind
);
2881 return (wxGridCellAttr
*)NULL
;
2884 void wxGridTableBase::SetAttr(wxGridCellAttr
* attr
, int row
, int col
)
2886 if ( m_attrProvider
)
2888 attr
->SetKind(wxGridCellAttr::Cell
);
2889 m_attrProvider
->SetAttr(attr
, row
, col
);
2893 // as we take ownership of the pointer and don't store it, we must
2899 void wxGridTableBase::SetRowAttr(wxGridCellAttr
*attr
, int row
)
2901 if ( m_attrProvider
)
2903 attr
->SetKind(wxGridCellAttr::Row
);
2904 m_attrProvider
->SetRowAttr(attr
, row
);
2908 // as we take ownership of the pointer and don't store it, we must
2914 void wxGridTableBase::SetColAttr(wxGridCellAttr
*attr
, int col
)
2916 if ( m_attrProvider
)
2918 attr
->SetKind(wxGridCellAttr::Col
);
2919 m_attrProvider
->SetColAttr(attr
, col
);
2923 // as we take ownership of the pointer and don't store it, we must
2929 bool wxGridTableBase::InsertRows( size_t WXUNUSED(pos
),
2930 size_t WXUNUSED(numRows
) )
2932 wxFAIL_MSG( wxT("Called grid table class function InsertRows\nbut your derived table class does not override this function") );
2937 bool wxGridTableBase::AppendRows( size_t WXUNUSED(numRows
) )
2939 wxFAIL_MSG( wxT("Called grid table class function AppendRows\nbut your derived table class does not override this function"));
2944 bool wxGridTableBase::DeleteRows( size_t WXUNUSED(pos
),
2945 size_t WXUNUSED(numRows
) )
2947 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\nbut your derived table class does not override this function"));
2952 bool wxGridTableBase::InsertCols( size_t WXUNUSED(pos
),
2953 size_t WXUNUSED(numCols
) )
2955 wxFAIL_MSG( wxT("Called grid table class function InsertCols\nbut your derived table class does not override this function"));
2960 bool wxGridTableBase::AppendCols( size_t WXUNUSED(numCols
) )
2962 wxFAIL_MSG(wxT("Called grid table class function AppendCols\nbut your derived table class does not override this function"));
2967 bool wxGridTableBase::DeleteCols( size_t WXUNUSED(pos
),
2968 size_t WXUNUSED(numCols
) )
2970 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\nbut your derived table class does not override this function"));
2976 wxString
wxGridTableBase::GetRowLabelValue( int row
)
2979 s
<< row
+ 1; // RD: Starting the rows at zero confuses users, no matter
2980 // how much it makes sense to us geeks.
2984 wxString
wxGridTableBase::GetColLabelValue( int col
)
2986 // default col labels are:
2987 // cols 0 to 25 : A-Z
2988 // cols 26 to 675 : AA-ZZ
2993 for ( n
= 1; ; n
++ )
2995 s
+= (_T('A') + (wxChar
)( col%26
));
2997 if ( col
< 0 ) break;
3000 // reverse the string...
3002 for ( i
= 0; i
< n
; i
++ )
3011 wxString
wxGridTableBase::GetTypeName( int WXUNUSED(row
), int WXUNUSED(col
) )
3013 return wxGRID_VALUE_STRING
;
3016 bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row
), int WXUNUSED(col
),
3017 const wxString
& typeName
)
3019 return typeName
== wxGRID_VALUE_STRING
;
3022 bool wxGridTableBase::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
3024 return CanGetValueAs(row
, col
, typeName
);
3027 long wxGridTableBase::GetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
) )
3032 double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
) )
3037 bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
) )
3042 void wxGridTableBase::SetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
),
3043 long WXUNUSED(value
) )
3047 void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
),
3048 double WXUNUSED(value
) )
3052 void wxGridTableBase::SetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
),
3053 bool WXUNUSED(value
) )
3058 void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
3059 const wxString
& WXUNUSED(typeName
) )
3064 void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
3065 const wxString
& WXUNUSED(typeName
),
3066 void* WXUNUSED(value
) )
3070 //////////////////////////////////////////////////////////////////////
3072 // Message class for the grid table to send requests and notifications
3076 wxGridTableMessage::wxGridTableMessage()
3078 m_table
= (wxGridTableBase
*) NULL
;
3084 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
3085 int commandInt1
, int commandInt2
)
3089 m_comInt1
= commandInt1
;
3090 m_comInt2
= commandInt2
;
3095 //////////////////////////////////////////////////////////////////////
3097 // A basic grid table for string data. An object of this class will
3098 // created by wxGrid if you don't specify an alternative table class.
3101 WX_DEFINE_OBJARRAY(wxGridStringArray
)
3103 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
3105 wxGridStringTable::wxGridStringTable()
3110 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
3113 m_data
.Alloc( numRows
);
3116 sa
.Alloc( numCols
);
3117 sa
.Add( wxEmptyString
, numCols
);
3119 m_data
.Add( sa
, numRows
);
3122 wxGridStringTable::~wxGridStringTable()
3126 int wxGridStringTable::GetNumberRows()
3128 return m_data
.GetCount();
3131 int wxGridStringTable::GetNumberCols()
3133 if ( m_data
.GetCount() > 0 )
3134 return m_data
[0].GetCount();
3139 wxString
wxGridStringTable::GetValue( int row
, int col
)
3141 wxCHECK_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3143 _T("invalid row or column index in wxGridStringTable") );
3145 return m_data
[row
][col
];
3148 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& value
)
3150 wxCHECK_RET( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3151 _T("invalid row or column index in wxGridStringTable") );
3153 m_data
[row
][col
] = value
;
3156 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
3158 wxCHECK_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3160 _T("invalid row or column index in wxGridStringTable") );
3162 return (m_data
[row
][col
] == wxEmptyString
);
3165 void wxGridStringTable::Clear()
3168 int numRows
, numCols
;
3170 numRows
= m_data
.GetCount();
3173 numCols
= m_data
[0].GetCount();
3175 for ( row
= 0; row
< numRows
; row
++ )
3177 for ( col
= 0; col
< numCols
; col
++ )
3179 m_data
[row
][col
] = wxEmptyString
;
3186 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
3188 size_t curNumRows
= m_data
.GetCount();
3189 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3190 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3192 if ( pos
>= curNumRows
)
3194 return AppendRows( numRows
);
3198 sa
.Alloc( curNumCols
);
3199 sa
.Add( wxEmptyString
, curNumCols
);
3200 m_data
.Insert( sa
, pos
, numRows
);
3203 wxGridTableMessage
msg( this,
3204 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
3208 GetView()->ProcessTableMessage( msg
);
3214 bool wxGridStringTable::AppendRows( size_t numRows
)
3216 size_t curNumRows
= m_data
.GetCount();
3217 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3218 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3221 if ( curNumCols
> 0 )
3223 sa
.Alloc( curNumCols
);
3224 sa
.Add( wxEmptyString
, curNumCols
);
3227 m_data
.Add( sa
, numRows
);
3231 wxGridTableMessage
msg( this,
3232 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
3235 GetView()->ProcessTableMessage( msg
);
3241 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
3243 size_t curNumRows
= m_data
.GetCount();
3245 if ( pos
>= curNumRows
)
3247 wxFAIL_MSG( wxString::Format
3249 wxT("Called wxGridStringTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows"),
3251 (unsigned long)numRows
,
3252 (unsigned long)curNumRows
3258 if ( numRows
> curNumRows
- pos
)
3260 numRows
= curNumRows
- pos
;
3263 if ( numRows
>= curNumRows
)
3269 m_data
.RemoveAt( pos
, numRows
);
3273 wxGridTableMessage
msg( this,
3274 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
3278 GetView()->ProcessTableMessage( msg
);
3284 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
3288 size_t curNumRows
= m_data
.GetCount();
3289 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3290 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3292 if ( pos
>= curNumCols
)
3294 return AppendCols( numCols
);
3297 for ( row
= 0; row
< curNumRows
; row
++ )
3299 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
3301 m_data
[row
].Insert( wxEmptyString
, col
);
3306 wxGridTableMessage
msg( this,
3307 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
3311 GetView()->ProcessTableMessage( msg
);
3317 bool wxGridStringTable::AppendCols( size_t numCols
)
3321 size_t curNumRows
= m_data
.GetCount();
3325 // TODO: something better than this ?
3327 wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\nCall AppendRows() first") );
3332 for ( row
= 0; row
< curNumRows
; row
++ )
3334 m_data
[row
].Add( wxEmptyString
, numCols
);
3339 wxGridTableMessage
msg( this,
3340 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
3343 GetView()->ProcessTableMessage( msg
);
3349 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
3353 size_t curNumRows
= m_data
.GetCount();
3354 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3355 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3357 if ( pos
>= curNumCols
)
3359 wxFAIL_MSG( wxString::Format
3361 wxT("Called wxGridStringTable::DeleteCols(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu cols"),
3363 (unsigned long)numCols
,
3364 (unsigned long)curNumCols
3369 if ( numCols
> curNumCols
- pos
)
3371 numCols
= curNumCols
- pos
;
3374 for ( row
= 0; row
< curNumRows
; row
++ )
3376 if ( numCols
>= curNumCols
)
3378 m_data
[row
].Clear();
3382 m_data
[row
].RemoveAt( pos
, numCols
);
3387 wxGridTableMessage
msg( this,
3388 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
3392 GetView()->ProcessTableMessage( msg
);
3398 wxString
wxGridStringTable::GetRowLabelValue( int row
)
3400 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
3402 // using default label
3404 return wxGridTableBase::GetRowLabelValue( row
);
3408 return m_rowLabels
[ row
];
3412 wxString
wxGridStringTable::GetColLabelValue( int col
)
3414 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
3416 // using default label
3418 return wxGridTableBase::GetColLabelValue( col
);
3422 return m_colLabels
[ col
];
3426 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
3428 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
3430 int n
= m_rowLabels
.GetCount();
3432 for ( i
= n
; i
<= row
; i
++ )
3434 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
3438 m_rowLabels
[row
] = value
;
3441 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
3443 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
3445 int n
= m_colLabels
.GetCount();
3447 for ( i
= n
; i
<= col
; i
++ )
3449 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
3453 m_colLabels
[col
] = value
;
3458 //////////////////////////////////////////////////////////////////////
3459 //////////////////////////////////////////////////////////////////////
3461 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
3463 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
3464 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
3465 EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel
)
3466 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
3467 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
3468 EVT_KEY_UP( wxGridRowLabelWindow::OnKeyUp
)
3471 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
3473 const wxPoint
&pos
, const wxSize
&size
)
3474 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
)
3479 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3483 // NO - don't do this because it will set both the x and y origin
3484 // coords to match the parent scrolled window and we just want to
3485 // set the y coord - MB
3487 // m_owner->PrepareDC( dc );
3490 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
3491 dc
.SetDeviceOrigin( 0, -y
);
3493 wxArrayInt rows
= m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
3494 m_owner
->DrawRowLabels( dc
, rows
);
3498 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3500 m_owner
->ProcessRowLabelMouseEvent( event
);
3504 void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3506 m_owner
->GetEventHandler()->ProcessEvent(event
);
3510 // This seems to be required for wxMotif otherwise the mouse
3511 // cursor must be in the cell edit control to get key events
3513 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3515 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3518 void wxGridRowLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3520 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3525 //////////////////////////////////////////////////////////////////////
3527 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
3529 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
3530 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
3531 EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel
)
3532 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
3533 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
3534 EVT_KEY_UP( wxGridColLabelWindow::OnKeyUp
)
3537 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
3539 const wxPoint
&pos
, const wxSize
&size
)
3540 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
)
3545 void wxGridColLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3549 // NO - don't do this because it will set both the x and y origin
3550 // coords to match the parent scrolled window and we just want to
3551 // set the x coord - MB
3553 // m_owner->PrepareDC( dc );
3556 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
3557 dc
.SetDeviceOrigin( -x
, 0 );
3559 wxArrayInt cols
= m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
3560 m_owner
->DrawColLabels( dc
, cols
);
3564 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3566 m_owner
->ProcessColLabelMouseEvent( event
);
3569 void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3571 m_owner
->GetEventHandler()->ProcessEvent(event
);
3575 // This seems to be required for wxMotif otherwise the mouse
3576 // cursor must be in the cell edit control to get key events
3578 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3580 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3583 void wxGridColLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3585 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3590 //////////////////////////////////////////////////////////////////////
3592 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
3594 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
3595 EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel
)
3596 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
3597 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
3598 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
3599 EVT_KEY_UP( wxGridCornerLabelWindow::OnKeyUp
)
3602 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
3604 const wxPoint
&pos
, const wxSize
&size
)
3605 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
)
3610 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3614 int client_height
= 0;
3615 int client_width
= 0;
3616 GetClientSize( &client_width
, &client_height
);
3618 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
),1, wxSOLID
) );
3619 dc
.DrawLine( client_width
-1, client_height
-1, client_width
-1, 0 );
3620 dc
.DrawLine( client_width
-1, client_height
-1, 0, client_height
-1 );
3621 dc
.DrawLine( 0, 0, client_width
, 0 );
3622 dc
.DrawLine( 0, 0, 0, client_height
);
3624 dc
.SetPen( *wxWHITE_PEN
);
3625 dc
.DrawLine( 1, 1, client_width
-1, 1 );
3626 dc
.DrawLine( 1, 1, 1, client_height
-1 );
3630 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3632 m_owner
->ProcessCornerLabelMouseEvent( event
);
3636 void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3638 m_owner
->GetEventHandler()->ProcessEvent(event
);
3641 // This seems to be required for wxMotif otherwise the mouse
3642 // cursor must be in the cell edit control to get key events
3644 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3646 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3649 void wxGridCornerLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3651 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3656 //////////////////////////////////////////////////////////////////////
3658 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxWindow
)
3660 BEGIN_EVENT_TABLE( wxGridWindow
, wxWindow
)
3661 EVT_PAINT( wxGridWindow::OnPaint
)
3662 EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel
)
3663 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
3664 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
3665 EVT_KEY_UP( wxGridWindow::OnKeyUp
)
3666 EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground
)
3669 wxGridWindow::wxGridWindow( wxGrid
*parent
,
3670 wxGridRowLabelWindow
*rowLblWin
,
3671 wxGridColLabelWindow
*colLblWin
,
3674 const wxSize
&size
)
3675 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
| wxBORDER_NONE
| wxCLIP_CHILDREN
,
3676 wxT("grid window") )
3680 m_rowLabelWin
= rowLblWin
;
3681 m_colLabelWin
= colLblWin
;
3682 SetBackgroundColour(_T("WHITE"));
3686 wxGridWindow::~wxGridWindow()
3691 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
3693 wxPaintDC
dc( this );
3694 m_owner
->PrepareDC( dc
);
3695 wxRegion reg
= GetUpdateRegion();
3696 wxGridCellCoordsArray DirtyCells
= m_owner
->CalcCellsExposed( reg
);
3697 m_owner
->DrawGridCellArea( dc
, DirtyCells
);
3698 #if WXGRID_DRAW_LINES
3699 m_owner
->DrawAllGridLines( dc
, reg
);
3701 m_owner
->DrawGridSpace( dc
);
3702 m_owner
->DrawHighlight( dc
, DirtyCells
);
3706 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
3708 wxWindow::ScrollWindow( dx
, dy
, rect
);
3709 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
3710 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
3714 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
3716 m_owner
->ProcessGridCellMouseEvent( event
);
3719 void wxGridWindow::OnMouseWheel( wxMouseEvent
& event
)
3721 m_owner
->GetEventHandler()->ProcessEvent(event
);
3724 // This seems to be required for wxMotif/wxGTK otherwise the mouse
3725 // cursor must be in the cell edit control to get key events
3727 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
3729 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3732 void wxGridWindow::OnKeyUp( wxKeyEvent
& event
)
3734 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3737 void wxGridWindow::OnEraseBackground( wxEraseEvent
& WXUNUSED(event
) )
3742 //////////////////////////////////////////////////////////////////////
3744 // Internal Helper function for computing row or column from some
3745 // (unscrolled) coordinate value, using either
3746 // m_defaultRowHeight/m_defaultColWidth or binary search on array
3747 // of m_rowBottoms/m_ColRights to speed up the search!
3749 // Internal helper macros for simpler use of that function
3751 static int CoordToRowOrCol(int coord
, int defaultDist
, int minDist
,
3752 const wxArrayInt
& BorderArray
, int nMax
,
3755 #define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \
3756 m_minAcceptableColWidth, \
3757 m_colRights, m_numCols, TRUE)
3758 #define internalYToRow(y) CoordToRowOrCol(y, m_defaultRowHeight, \
3759 m_minAcceptableRowHeight, \
3760 m_rowBottoms, m_numRows, TRUE)
3761 /////////////////////////////////////////////////////////////////////
3763 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
3765 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
3766 EVT_PAINT( wxGrid::OnPaint
)
3767 EVT_SIZE( wxGrid::OnSize
)
3768 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
3769 EVT_KEY_UP( wxGrid::OnKeyUp
)
3770 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
3773 wxGrid::wxGrid( wxWindow
*parent
,
3778 const wxString
& name
)
3779 : wxScrolledWindow( parent
, id
, pos
, size
, (style
| wxWANTS_CHARS
), name
),
3780 m_colMinWidths(GRID_HASH_SIZE
),
3781 m_rowMinHeights(GRID_HASH_SIZE
)
3789 // Must do this or ~wxScrollHelper will pop the wrong event handler
3790 SetTargetWindow(this);
3792 wxSafeDecRef(m_defaultCellAttr
);
3794 #ifdef DEBUG_ATTR_CACHE
3795 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
3796 wxPrintf(_T("wxGrid attribute cache statistics: "
3797 "total: %u, hits: %u (%u%%)\n"),
3798 total
, gs_nAttrCacheHits
,
3799 total
? (gs_nAttrCacheHits
*100) / total
: 0);
3805 delete m_typeRegistry
;
3811 // ----- internal init and update functions
3814 void wxGrid::Create()
3816 m_created
= FALSE
; // set to TRUE by CreateGrid
3818 m_table
= (wxGridTableBase
*) NULL
;
3821 m_cellEditCtrlEnabled
= FALSE
;
3823 m_defaultCellAttr
= new wxGridCellAttr();
3825 // Set default cell attributes
3826 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
3827 m_defaultCellAttr
->SetKind(wxGridCellAttr::Default
);
3828 m_defaultCellAttr
->SetFont(GetFont());
3829 m_defaultCellAttr
->SetAlignment(wxALIGN_LEFT
, wxALIGN_TOP
);
3830 m_defaultCellAttr
->SetTextColour(
3831 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
3832 m_defaultCellAttr
->SetBackgroundColour(
3833 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
3834 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
3835 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
3840 m_currentCellCoords
= wxGridNoCellCoords
;
3842 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
3843 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
3845 // create the type registry
3846 m_typeRegistry
= new wxGridTypeRegistry
;
3849 // subwindow components that make up the wxGrid
3850 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
3855 m_rowLabelWin
= new wxGridRowLabelWindow( this,
3860 m_colLabelWin
= new wxGridColLabelWindow( this,
3865 m_gridWin
= new wxGridWindow( this,
3872 SetTargetWindow( m_gridWin
);
3878 bool wxGrid::CreateGrid( int numRows
, int numCols
,
3879 wxGrid::wxGridSelectionModes selmode
)
3881 wxCHECK_MSG( !m_created
,
3883 wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
3885 m_numRows
= numRows
;
3886 m_numCols
= numCols
;
3888 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
3889 m_table
->SetView( this );
3891 m_selection
= new wxGridSelection( this, selmode
);
3900 void wxGrid::SetSelectionMode(wxGrid::wxGridSelectionModes selmode
)
3902 wxCHECK_RET( m_created
,
3903 wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") );
3905 m_selection
->SetSelectionMode( selmode
);
3908 wxGrid::wxGridSelectionModes
wxGrid::GetSelectionMode() const
3910 wxCHECK_MSG( m_created
, wxGrid::wxGridSelectCells
,
3911 wxT("Called wxGrid::GetSelectionMode() before calling CreateGrid()") );
3913 return m_selection
->GetSelectionMode();
3916 bool wxGrid::SetTable( wxGridTableBase
*table
, bool takeOwnership
,
3917 wxGrid::wxGridSelectionModes selmode
)
3921 // stop all processing
3926 wxGridTableBase
*t
=m_table
;
3939 m_numRows
= table
->GetNumberRows();
3940 m_numCols
= table
->GetNumberCols();
3943 m_table
->SetView( this );
3946 m_selection
= new wxGridSelection( this, selmode
);
3959 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
3960 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
3962 if ( m_rowLabelWin
)
3964 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
3968 m_labelBackgroundColour
= wxColour( _T("WHITE") );
3971 m_labelTextColour
= wxColour( _T("BLACK") );
3974 m_attrCache
.row
= -1;
3975 m_attrCache
.col
= -1;
3976 m_attrCache
.attr
= NULL
;
3978 // TODO: something better than this ?
3980 m_labelFont
= this->GetFont();
3981 m_labelFont
.SetWeight( wxBOLD
);
3983 m_rowLabelHorizAlign
= wxALIGN_CENTRE
;
3984 m_rowLabelVertAlign
= wxALIGN_CENTRE
;
3986 m_colLabelHorizAlign
= wxALIGN_CENTRE
;
3987 m_colLabelVertAlign
= wxALIGN_CENTRE
;
3988 m_colLabelTextOrientation
= wxHORIZONTAL
;
3990 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
3991 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
3993 m_minAcceptableColWidth
= WXGRID_MIN_COL_WIDTH
;
3994 m_minAcceptableRowHeight
= WXGRID_MIN_ROW_HEIGHT
;
3996 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
3997 m_defaultRowHeight
+= 8;
3999 m_defaultRowHeight
+= 4;
4002 m_gridLineColour
= wxColour( 192,192,192 );
4003 m_gridLinesEnabled
= TRUE
;
4004 m_cellHighlightColour
= *wxBLACK
;
4005 m_cellHighlightPenWidth
= 2;
4006 m_cellHighlightROPenWidth
= 1;
4008 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
4009 m_winCapture
= (wxWindow
*)NULL
;
4010 m_canDragRowSize
= TRUE
;
4011 m_canDragColSize
= TRUE
;
4012 m_canDragGridSize
= TRUE
;
4014 m_dragRowOrCol
= -1;
4015 m_isDragging
= FALSE
;
4016 m_startDragPos
= wxDefaultPosition
;
4018 m_waitForSlowClick
= FALSE
;
4020 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
4021 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
4023 m_currentCellCoords
= wxGridNoCellCoords
;
4025 m_selectingTopLeft
= wxGridNoCellCoords
;
4026 m_selectingBottomRight
= wxGridNoCellCoords
;
4027 m_selectionBackground
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
4028 m_selectionForeground
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
4030 m_editable
= TRUE
; // default for whole grid
4032 m_inOnKeyDown
= FALSE
;
4039 // ----------------------------------------------------------------------------
4040 // the idea is to call these functions only when necessary because they create
4041 // quite big arrays which eat memory mostly unnecessary - in particular, if
4042 // default widths/heights are used for all rows/columns, we may not use these
4045 // with some extra code, it should be possible to only store the
4046 // widths/heights different from default ones but this will be done later...
4047 // ----------------------------------------------------------------------------
4049 void wxGrid::InitRowHeights()
4051 m_rowHeights
.Empty();
4052 m_rowBottoms
.Empty();
4054 m_rowHeights
.Alloc( m_numRows
);
4055 m_rowBottoms
.Alloc( m_numRows
);
4059 m_rowHeights
.Add( m_defaultRowHeight
, m_numRows
);
4061 for ( int i
= 0; i
< m_numRows
; i
++ )
4063 rowBottom
+= m_defaultRowHeight
;
4064 m_rowBottoms
.Add( rowBottom
);
4068 void wxGrid::InitColWidths()
4070 m_colWidths
.Empty();
4071 m_colRights
.Empty();
4073 m_colWidths
.Alloc( m_numCols
);
4074 m_colRights
.Alloc( m_numCols
);
4077 m_colWidths
.Add( m_defaultColWidth
, m_numCols
);
4079 for ( int i
= 0; i
< m_numCols
; i
++ )
4081 colRight
+= m_defaultColWidth
;
4082 m_colRights
.Add( colRight
);
4086 int wxGrid::GetColWidth(int col
) const
4088 return m_colWidths
.IsEmpty() ? m_defaultColWidth
: m_colWidths
[col
];
4091 int wxGrid::GetColLeft(int col
) const
4093 return m_colRights
.IsEmpty() ? col
* m_defaultColWidth
4094 : m_colRights
[col
] - m_colWidths
[col
];
4097 int wxGrid::GetColRight(int col
) const
4099 return m_colRights
.IsEmpty() ? (col
+ 1) * m_defaultColWidth
4103 int wxGrid::GetRowHeight(int row
) const
4105 return m_rowHeights
.IsEmpty() ? m_defaultRowHeight
: m_rowHeights
[row
];
4108 int wxGrid::GetRowTop(int row
) const
4110 return m_rowBottoms
.IsEmpty() ? row
* m_defaultRowHeight
4111 : m_rowBottoms
[row
] - m_rowHeights
[row
];
4114 int wxGrid::GetRowBottom(int row
) const
4116 return m_rowBottoms
.IsEmpty() ? (row
+ 1) * m_defaultRowHeight
4117 : m_rowBottoms
[row
];
4120 void wxGrid::CalcDimensions()
4123 GetClientSize( &cw
, &ch
);
4125 if ( m_rowLabelWin
->IsShown() )
4126 cw
-= m_rowLabelWidth
;
4127 if ( m_colLabelWin
->IsShown() )
4128 ch
-= m_colLabelHeight
;
4131 int w
= m_numCols
> 0 ? GetColRight(m_numCols
- 1) + m_extraWidth
+ 1 : 0;
4132 int h
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) + m_extraHeight
+ 1 : 0;
4134 // take into account editor if shown
4135 if( IsCellEditControlShown() )
4138 int r
= m_currentCellCoords
.GetRow();
4139 int c
= m_currentCellCoords
.GetCol();
4140 int x
= GetColLeft(c
);
4141 int y
= GetRowTop(r
);
4143 // how big is the editor
4144 wxGridCellAttr
* attr
= GetCellAttr(r
, c
);
4145 wxGridCellEditor
* editor
= attr
->GetEditor(this, r
, c
);
4146 editor
->GetControl()->GetSize(&w2
, &h2
);
4149 if( w2
> w
) w
= w2
;
4150 if( h2
> h
) h
= h2
;
4155 // preserve (more or less) the previous position
4157 GetViewStart( &x
, &y
);
4159 // maybe we don't need scrollbars at all?
4161 // also adjust the position to be valid for the new scroll rangs
4182 // do set scrollbar parameters
4183 SetScrollbars( GRID_SCROLL_LINE_X
, GRID_SCROLL_LINE_Y
,
4184 GetScrollX(w
), GetScrollY(h
), x
, y
,
4185 GetBatchCount() != 0);
4187 // if our OnSize() hadn't been called (it would if we have scrollbars), we
4188 // still must reposition the children
4193 void wxGrid::CalcWindowSizes()
4196 GetClientSize( &cw
, &ch
);
4198 if ( m_cornerLabelWin
->IsShown() )
4199 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
4201 if ( m_colLabelWin
->IsShown() )
4202 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
4204 if ( m_rowLabelWin
->IsShown() )
4205 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
4207 if ( m_gridWin
->IsShown() )
4208 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
4212 // this is called when the grid table sends a message to say that it
4213 // has been redimensioned
4215 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
4218 bool result
= FALSE
;
4220 // Clear the attribute cache as the attribute might refer to a different
4221 // cell than stored in the cache after adding/removing rows/columns.
4223 // By the same reasoning, the editor should be dismissed if columns are
4224 // added or removed. And for consistency, it should IMHO always be
4225 // removed, not only if the cell "underneath" it actually changes.
4226 // For now, I intentionally do not save the editor's content as the
4227 // cell it might want to save that stuff to might no longer exist.
4228 HideCellEditControl();
4230 // if we were using the default widths/heights so far, we must change them
4232 if ( m_colWidths
.IsEmpty() )
4237 if ( m_rowHeights
.IsEmpty() )
4243 switch ( msg
.GetId() )
4245 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
4247 size_t pos
= msg
.GetCommandInt();
4248 int numRows
= msg
.GetCommandInt2();
4250 m_numRows
+= numRows
;
4252 if ( !m_rowHeights
.IsEmpty() )
4254 m_rowHeights
.Insert( m_defaultRowHeight
, pos
, numRows
);
4255 m_rowBottoms
.Insert( 0, pos
, numRows
);
4258 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
4260 for ( i
= pos
; i
< m_numRows
; i
++ )
4262 bottom
+= m_rowHeights
[i
];
4263 m_rowBottoms
[i
] = bottom
;
4266 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4268 // if we have just inserted cols into an empty grid the current
4269 // cell will be undefined...
4271 SetCurrentCell( 0, 0 );
4275 m_selection
->UpdateRows( pos
, numRows
);
4276 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4278 attrProvider
->UpdateAttrRows( pos
, numRows
);
4280 if ( !GetBatchCount() )
4283 m_rowLabelWin
->Refresh();
4289 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
4291 int numRows
= msg
.GetCommandInt();
4292 int oldNumRows
= m_numRows
;
4293 m_numRows
+= numRows
;
4295 if ( !m_rowHeights
.IsEmpty() )
4297 m_rowHeights
.Add( m_defaultRowHeight
, numRows
);
4298 m_rowBottoms
.Add( 0, numRows
);
4301 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
4303 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
4305 bottom
+= m_rowHeights
[i
];
4306 m_rowBottoms
[i
] = bottom
;
4309 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4311 // if we have just inserted cols into an empty grid the current
4312 // cell will be undefined...
4314 SetCurrentCell( 0, 0 );
4316 if ( !GetBatchCount() )
4319 m_rowLabelWin
->Refresh();
4325 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
4327 size_t pos
= msg
.GetCommandInt();
4328 int numRows
= msg
.GetCommandInt2();
4329 m_numRows
-= numRows
;
4331 if ( !m_rowHeights
.IsEmpty() )
4333 m_rowHeights
.RemoveAt( pos
, numRows
);
4334 m_rowBottoms
.RemoveAt( pos
, numRows
);
4337 for ( i
= 0; i
< m_numRows
; i
++ )
4339 h
+= m_rowHeights
[i
];
4340 m_rowBottoms
[i
] = h
;
4345 m_currentCellCoords
= wxGridNoCellCoords
;
4349 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
4350 m_currentCellCoords
.Set( 0, 0 );
4354 m_selection
->UpdateRows( pos
, -((int)numRows
) );
4355 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4357 attrProvider
->UpdateAttrRows( pos
, -((int)numRows
) );
4358 // ifdef'd out following patch from Paul Gammans
4360 // No need to touch column attributes, unless we
4361 // removed _all_ rows, in this case, we remove
4362 // all column attributes.
4363 // I hate to do this here, but the
4364 // needed data is not available inside UpdateAttrRows.
4365 if ( !GetNumberRows() )
4366 attrProvider
->UpdateAttrCols( 0, -GetNumberCols() );
4369 if ( !GetBatchCount() )
4372 m_rowLabelWin
->Refresh();
4378 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
4380 size_t pos
= msg
.GetCommandInt();
4381 int numCols
= msg
.GetCommandInt2();
4382 m_numCols
+= numCols
;
4384 if ( !m_colWidths
.IsEmpty() )
4386 m_colWidths
.Insert( m_defaultColWidth
, pos
, numCols
);
4387 m_colRights
.Insert( 0, pos
, numCols
);
4390 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
4392 for ( i
= pos
; i
< m_numCols
; i
++ )
4394 right
+= m_colWidths
[i
];
4395 m_colRights
[i
] = right
;
4398 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4400 // if we have just inserted cols into an empty grid the current
4401 // cell will be undefined...
4403 SetCurrentCell( 0, 0 );
4407 m_selection
->UpdateCols( pos
, numCols
);
4408 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4410 attrProvider
->UpdateAttrCols( pos
, numCols
);
4411 if ( !GetBatchCount() )
4414 m_colLabelWin
->Refresh();
4421 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
4423 int numCols
= msg
.GetCommandInt();
4424 int oldNumCols
= m_numCols
;
4425 m_numCols
+= numCols
;
4426 if ( !m_colWidths
.IsEmpty() )
4428 m_colWidths
.Add( m_defaultColWidth
, numCols
);
4429 m_colRights
.Add( 0, numCols
);
4432 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
4434 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
4436 right
+= m_colWidths
[i
];
4437 m_colRights
[i
] = right
;
4440 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4442 // if we have just inserted cols into an empty grid the current
4443 // cell will be undefined...
4445 SetCurrentCell( 0, 0 );
4447 if ( !GetBatchCount() )
4450 m_colLabelWin
->Refresh();
4456 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
4458 size_t pos
= msg
.GetCommandInt();
4459 int numCols
= msg
.GetCommandInt2();
4460 m_numCols
-= numCols
;
4462 if ( !m_colWidths
.IsEmpty() )
4464 m_colWidths
.RemoveAt( pos
, numCols
);
4465 m_colRights
.RemoveAt( pos
, numCols
);
4468 for ( i
= 0; i
< m_numCols
; i
++ )
4470 w
+= m_colWidths
[i
];
4476 m_currentCellCoords
= wxGridNoCellCoords
;
4480 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
4481 m_currentCellCoords
.Set( 0, 0 );
4485 m_selection
->UpdateCols( pos
, -((int)numCols
) );
4486 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4488 attrProvider
->UpdateAttrCols( pos
, -((int)numCols
) );
4489 // ifdef'd out following patch from Paul Gammans
4491 // No need to touch row attributes, unless we
4492 // removed _all_ columns, in this case, we remove
4493 // all row attributes.
4494 // I hate to do this here, but the
4495 // needed data is not available inside UpdateAttrCols.
4496 if ( !GetNumberCols() )
4497 attrProvider
->UpdateAttrRows( 0, -GetNumberRows() );
4500 if ( !GetBatchCount() )
4503 m_colLabelWin
->Refresh();
4510 if (result
&& !GetBatchCount() )
4511 m_gridWin
->Refresh();
4516 wxArrayInt
wxGrid::CalcRowLabelsExposed( const wxRegion
& reg
)
4518 wxRegionIterator
iter( reg
);
4521 wxArrayInt rowlabels
;
4528 // TODO: remove this when we can...
4529 // There is a bug in wxMotif that gives garbage update
4530 // rectangles if you jump-scroll a long way by clicking the
4531 // scrollbar with middle button. This is a work-around
4533 #if defined(__WXMOTIF__)
4535 m_gridWin
->GetClientSize( &cw
, &ch
);
4536 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
4537 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
4540 // logical bounds of update region
4543 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
4544 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
4546 // find the row labels within these bounds
4549 for ( row
= internalYToRow(top
); row
< m_numRows
; row
++ )
4551 if ( GetRowBottom(row
) < top
)
4554 if ( GetRowTop(row
) > bottom
)
4557 rowlabels
.Add( row
);
4567 wxArrayInt
wxGrid::CalcColLabelsExposed( const wxRegion
& reg
)
4569 wxRegionIterator
iter( reg
);
4572 wxArrayInt colLabels
;
4579 // TODO: remove this when we can...
4580 // There is a bug in wxMotif that gives garbage update
4581 // rectangles if you jump-scroll a long way by clicking the
4582 // scrollbar with middle button. This is a work-around
4584 #if defined(__WXMOTIF__)
4586 m_gridWin
->GetClientSize( &cw
, &ch
);
4587 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
4588 r
.SetRight( wxMin( r
.GetRight(), cw
) );
4591 // logical bounds of update region
4594 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
4595 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
4597 // find the cells within these bounds
4600 for ( col
= internalXToCol(left
); col
< m_numCols
; col
++ )
4602 if ( GetColRight(col
) < left
)
4605 if ( GetColLeft(col
) > right
)
4608 colLabels
.Add( col
);
4617 wxGridCellCoordsArray
wxGrid::CalcCellsExposed( const wxRegion
& reg
)
4619 wxRegionIterator
iter( reg
);
4622 wxGridCellCoordsArray cellsExposed
;
4624 int left
, top
, right
, bottom
;
4629 // TODO: remove this when we can...
4630 // There is a bug in wxMotif that gives garbage update
4631 // rectangles if you jump-scroll a long way by clicking the
4632 // scrollbar with middle button. This is a work-around
4634 #if defined(__WXMOTIF__)
4636 m_gridWin
->GetClientSize( &cw
, &ch
);
4637 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
4638 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
4639 r
.SetRight( wxMin( r
.GetRight(), cw
) );
4640 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
4643 // logical bounds of update region
4645 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
4646 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
4648 // find the cells within these bounds
4651 for ( row
= internalYToRow(top
); row
< m_numRows
; row
++ )
4653 if ( GetRowBottom(row
) <= top
)
4656 if ( GetRowTop(row
) > bottom
)
4659 for ( col
= internalXToCol(left
); col
< m_numCols
; col
++ )
4661 if ( GetColRight(col
) <= left
)
4664 if ( GetColLeft(col
) > right
)
4667 cellsExposed
.Add( wxGridCellCoords( row
, col
) );
4674 return cellsExposed
;
4678 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
4681 wxPoint
pos( event
.GetPosition() );
4682 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
4684 if ( event
.Dragging() )
4688 m_isDragging
= TRUE
;
4689 m_rowLabelWin
->CaptureMouse();
4692 if ( event
.LeftIsDown() )
4694 switch( m_cursorMode
)
4696 case WXGRID_CURSOR_RESIZE_ROW
:
4698 int cw
, ch
, left
, dummy
;
4699 m_gridWin
->GetClientSize( &cw
, &ch
);
4700 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
4702 wxClientDC
dc( m_gridWin
);
4705 GetRowTop(m_dragRowOrCol
) +
4706 GetRowMinimalHeight(m_dragRowOrCol
) );
4707 dc
.SetLogicalFunction(wxINVERT
);
4708 if ( m_dragLastPos
>= 0 )
4710 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
4712 dc
.DrawLine( left
, y
, left
+cw
, y
);
4717 case WXGRID_CURSOR_SELECT_ROW
:
4718 if ( (row
= YToRow( y
)) >= 0 )
4722 m_selection
->SelectRow( row
,
4723 event
.ControlDown(),
4730 // default label to suppress warnings about "enumeration value
4731 // 'xxx' not handled in switch
4739 if ( m_isDragging
&& (event
.Entering() || event
.Leaving()) )
4744 if (m_rowLabelWin
->HasCapture()) m_rowLabelWin
->ReleaseMouse();
4745 m_isDragging
= FALSE
;
4748 // ------------ Entering or leaving the window
4750 if ( event
.Entering() || event
.Leaving() )
4752 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
4756 // ------------ Left button pressed
4758 else if ( event
.LeftDown() )
4760 // don't send a label click event for a hit on the
4761 // edge of the row label - this is probably the user
4762 // wanting to resize the row
4764 if ( YToEdgeOfRow(y
) < 0 )
4768 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
4770 if ( !event
.ShiftDown() && !event
.ControlDown() )
4774 if ( event
.ShiftDown() )
4776 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
4779 GetNumberCols() - 1,
4780 event
.ControlDown(),
4787 m_selection
->SelectRow( row
,
4788 event
.ControlDown(),
4795 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
4800 // starting to drag-resize a row
4802 if ( CanDragRowSize() )
4803 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
4808 // ------------ Left double click
4810 else if (event
.LeftDClick() )
4812 int row
= YToEdgeOfRow(y
);
4817 !SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
) )
4819 // no default action at the moment
4824 // adjust row height depending on label text
4825 AutoSizeRowLabelSize( row
);
4827 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
4833 // ------------ Left button released
4835 else if ( event
.LeftUp() )
4837 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
4839 DoEndDragResizeRow();
4841 // Note: we are ending the event *after* doing
4842 // default processing in this case
4844 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
4847 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
4852 // ------------ Right button down
4854 else if ( event
.RightDown() )
4858 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
4860 // no default action at the moment
4865 // ------------ Right double click
4867 else if ( event
.RightDClick() )
4871 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
4873 // no default action at the moment
4878 // ------------ No buttons down and mouse moving
4880 else if ( event
.Moving() )
4882 m_dragRowOrCol
= YToEdgeOfRow( y
);
4883 if ( m_dragRowOrCol
>= 0 )
4885 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4887 // don't capture the mouse yet
4888 if ( CanDragRowSize() )
4889 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, FALSE
);
4892 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
4894 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, FALSE
);
4900 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
4903 wxPoint
pos( event
.GetPosition() );
4904 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
4906 if ( event
.Dragging() )
4910 m_isDragging
= TRUE
;
4911 m_colLabelWin
->CaptureMouse();
4914 if ( event
.LeftIsDown() )
4916 switch( m_cursorMode
)
4918 case WXGRID_CURSOR_RESIZE_COL
:
4920 int cw
, ch
, dummy
, top
;
4921 m_gridWin
->GetClientSize( &cw
, &ch
);
4922 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
4924 wxClientDC
dc( m_gridWin
);
4927 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
4928 GetColMinimalWidth(m_dragRowOrCol
));
4929 dc
.SetLogicalFunction(wxINVERT
);
4930 if ( m_dragLastPos
>= 0 )
4932 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
4934 dc
.DrawLine( x
, top
, x
, top
+ch
);
4939 case WXGRID_CURSOR_SELECT_COL
:
4940 if ( (col
= XToCol( x
)) >= 0 )
4944 m_selection
->SelectCol( col
,
4945 event
.ControlDown(),
4952 // default label to suppress warnings about "enumeration value
4953 // 'xxx' not handled in switch
4961 if ( m_isDragging
&& (event
.Entering() || event
.Leaving()) )
4966 if (m_colLabelWin
->HasCapture()) m_colLabelWin
->ReleaseMouse();
4967 m_isDragging
= FALSE
;
4970 // ------------ Entering or leaving the window
4972 if ( event
.Entering() || event
.Leaving() )
4974 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
4978 // ------------ Left button pressed
4980 else if ( event
.LeftDown() )
4982 // don't send a label click event for a hit on the
4983 // edge of the col label - this is probably the user
4984 // wanting to resize the col
4986 if ( XToEdgeOfCol(x
) < 0 )
4990 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
4992 if ( !event
.ShiftDown() && !event
.ControlDown() )
4996 if ( event
.ShiftDown() )
4998 m_selection
->SelectBlock( 0,
4999 m_currentCellCoords
.GetCol(),
5000 GetNumberRows() - 1, col
,
5001 event
.ControlDown(),
5008 m_selection
->SelectCol( col
,
5009 event
.ControlDown(),
5016 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, m_colLabelWin
);
5021 // starting to drag-resize a col
5023 if ( CanDragColSize() )
5024 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
);
5029 // ------------ Left double click
5031 if ( event
.LeftDClick() )
5033 int col
= XToEdgeOfCol(x
);
5038 ! SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
) )
5040 // no default action at the moment
5045 // adjust column width depending on label text
5046 AutoSizeColLabelSize( col
);
5048 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
5054 // ------------ Left button released
5056 else if ( event
.LeftUp() )
5058 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5060 DoEndDragResizeCol();
5062 // Note: we are ending the event *after* doing
5063 // default processing in this case
5065 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
5068 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
5073 // ------------ Right button down
5075 else if ( event
.RightDown() )
5079 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
5081 // no default action at the moment
5086 // ------------ Right double click
5088 else if ( event
.RightDClick() )
5092 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
5094 // no default action at the moment
5099 // ------------ No buttons down and mouse moving
5101 else if ( event
.Moving() )
5103 m_dragRowOrCol
= XToEdgeOfCol( x
);
5104 if ( m_dragRowOrCol
>= 0 )
5106 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5108 // don't capture the cursor yet
5109 if ( CanDragColSize() )
5110 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
, FALSE
);
5113 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
5115 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
, FALSE
);
5121 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
5123 if ( event
.LeftDown() )
5125 // indicate corner label by having both row and
5128 if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
5134 else if ( event
.LeftDClick() )
5136 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
5139 else if ( event
.RightDown() )
5141 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
5143 // no default action at the moment
5147 else if ( event
.RightDClick() )
5149 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
5151 // no default action at the moment
5156 void wxGrid::ChangeCursorMode(CursorMode mode
,
5161 static const wxChar
*cursorModes
[] =
5170 wxLogTrace(_T("grid"),
5171 _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
5172 win
== m_colLabelWin
? _T("colLabelWin")
5173 : win
? _T("rowLabelWin")
5175 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
5176 #endif // __WXDEBUG__
5178 if ( mode
== m_cursorMode
&&
5179 win
== m_winCapture
&&
5180 captureMouse
== (m_winCapture
!= NULL
))
5185 // by default use the grid itself
5191 if (m_winCapture
->HasCapture()) m_winCapture
->ReleaseMouse();
5192 m_winCapture
= (wxWindow
*)NULL
;
5195 m_cursorMode
= mode
;
5197 switch ( m_cursorMode
)
5199 case WXGRID_CURSOR_RESIZE_ROW
:
5200 win
->SetCursor( m_rowResizeCursor
);
5203 case WXGRID_CURSOR_RESIZE_COL
:
5204 win
->SetCursor( m_colResizeCursor
);
5208 win
->SetCursor( *wxSTANDARD_CURSOR
);
5211 // we need to capture mouse when resizing
5212 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
5213 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
5215 if ( captureMouse
&& resize
)
5217 win
->CaptureMouse();
5222 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
5225 wxPoint
pos( event
.GetPosition() );
5226 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
5228 wxGridCellCoords coords
;
5229 XYToCell( x
, y
, coords
);
5231 int cell_rows
, cell_cols
;
5232 GetCellSize( coords
.GetRow(), coords
.GetCol(), &cell_rows
, &cell_cols
);
5233 if ((cell_rows
< 0) || (cell_cols
< 0))
5235 coords
.SetRow(coords
.GetRow() + cell_rows
);
5236 coords
.SetCol(coords
.GetCol() + cell_cols
);
5239 if ( event
.Dragging() )
5241 //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
5243 // Don't start doing anything until the mouse has been drug at
5244 // least 3 pixels in any direction...
5247 if (m_startDragPos
== wxDefaultPosition
)
5249 m_startDragPos
= pos
;
5252 if (abs(m_startDragPos
.x
- pos
.x
) < 4 && abs(m_startDragPos
.y
- pos
.y
) < 4)
5256 m_isDragging
= TRUE
;
5257 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5259 // Hide the edit control, so it
5260 // won't interfer with drag-shrinking.
5261 if ( IsCellEditControlShown() )
5263 HideCellEditControl();
5264 SaveEditControlValue();
5267 // Have we captured the mouse yet?
5270 m_winCapture
= m_gridWin
;
5271 m_winCapture
->CaptureMouse();
5274 if ( coords
!= wxGridNoCellCoords
)
5276 if ( event
.ControlDown() )
5278 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
5279 m_selectingKeyboard
= coords
;
5280 HighlightBlock ( m_selectingKeyboard
, coords
);
5284 if ( !IsSelection() )
5286 HighlightBlock( coords
, coords
);
5290 HighlightBlock( m_currentCellCoords
, coords
);
5294 if (! IsVisible(coords
))
5296 MakeCellVisible(coords
);
5297 // TODO: need to introduce a delay or something here. The
5298 // scrolling is way to fast, at least on MSW - also on GTK.
5302 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
5304 int cw
, ch
, left
, dummy
;
5305 m_gridWin
->GetClientSize( &cw
, &ch
);
5306 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
5308 wxClientDC
dc( m_gridWin
);
5310 y
= wxMax( y
, GetRowTop(m_dragRowOrCol
) +
5311 GetRowMinimalHeight(m_dragRowOrCol
) );
5312 dc
.SetLogicalFunction(wxINVERT
);
5313 if ( m_dragLastPos
>= 0 )
5315 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
5317 dc
.DrawLine( left
, y
, left
+cw
, y
);
5320 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5322 int cw
, ch
, dummy
, top
;
5323 m_gridWin
->GetClientSize( &cw
, &ch
);
5324 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
5326 wxClientDC
dc( m_gridWin
);
5328 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
5329 GetColMinimalWidth(m_dragRowOrCol
) );
5330 dc
.SetLogicalFunction(wxINVERT
);
5331 if ( m_dragLastPos
>= 0 )
5333 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
5335 dc
.DrawLine( x
, top
, x
, top
+ch
);
5342 m_isDragging
= FALSE
;
5343 m_startDragPos
= wxDefaultPosition
;
5345 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
5346 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
5349 if ( event
.Entering() || event
.Leaving() )
5351 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5352 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
5357 // ------------ Left button pressed
5359 if ( event
.LeftDown() && coords
!= wxGridNoCellCoords
)
5361 if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK
,
5366 if ( !event
.ControlDown() )
5368 if ( event
.ShiftDown() )
5372 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
5373 m_currentCellCoords
.GetCol(),
5376 event
.ControlDown(),
5382 else if ( XToEdgeOfCol(x
) < 0 &&
5383 YToEdgeOfRow(y
) < 0 )
5385 DisableCellEditControl();
5386 MakeCellVisible( coords
);
5388 if ( event
.ControlDown() )
5392 m_selection
->ToggleCellSelection( coords
.GetRow(),
5394 event
.ControlDown(),
5399 m_selectingTopLeft
= wxGridNoCellCoords
;
5400 m_selectingBottomRight
= wxGridNoCellCoords
;
5401 m_selectingKeyboard
= coords
;
5405 m_waitForSlowClick
= m_currentCellCoords
== coords
&& coords
!= wxGridNoCellCoords
;
5406 SetCurrentCell( coords
);
5409 if ( m_selection
->GetSelectionMode() !=
5410 wxGrid::wxGridSelectCells
)
5412 HighlightBlock( coords
, coords
);
5421 // ------------ Left double click
5423 else if ( event
.LeftDClick() && coords
!= wxGridNoCellCoords
)
5425 DisableCellEditControl();
5427 if ( XToEdgeOfCol(x
) < 0 && YToEdgeOfRow(y
) < 0 )
5429 SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK
,
5437 // ------------ Left button released
5439 else if ( event
.LeftUp() )
5441 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5445 if (m_winCapture
->HasCapture()) m_winCapture
->ReleaseMouse();
5446 m_winCapture
= NULL
;
5449 if ( coords
== m_currentCellCoords
&& m_waitForSlowClick
&& CanEnableCellControl())
5452 EnableCellEditControl();
5454 wxGridCellAttr
* attr
= GetCellAttr(coords
);
5455 wxGridCellEditor
*editor
= attr
->GetEditor(this, coords
.GetRow(), coords
.GetCol());
5456 editor
->StartingClick();
5460 m_waitForSlowClick
= FALSE
;
5462 else if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
5463 m_selectingBottomRight
!= wxGridNoCellCoords
)
5467 m_selection
->SelectBlock( m_selectingTopLeft
.GetRow(),
5468 m_selectingTopLeft
.GetCol(),
5469 m_selectingBottomRight
.GetRow(),
5470 m_selectingBottomRight
.GetCol(),
5471 event
.ControlDown(),
5477 m_selectingTopLeft
= wxGridNoCellCoords
;
5478 m_selectingBottomRight
= wxGridNoCellCoords
;
5480 // Show the edit control, if it has been hidden for
5482 ShowCellEditControl();
5485 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
5487 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5488 DoEndDragResizeRow();
5490 // Note: we are ending the event *after* doing
5491 // default processing in this case
5493 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
5495 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5497 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5498 DoEndDragResizeCol();
5500 // Note: we are ending the event *after* doing
5501 // default processing in this case
5503 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
5510 // ------------ Right button down
5512 else if ( event
.RightDown() && coords
!= wxGridNoCellCoords
)
5514 DisableCellEditControl();
5515 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK
,
5520 // no default action at the moment
5525 // ------------ Right double click
5527 else if ( event
.RightDClick() && coords
!= wxGridNoCellCoords
)
5529 DisableCellEditControl();
5530 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK
,
5535 // no default action at the moment
5539 // ------------ Moving and no button action
5541 else if ( event
.Moving() && !event
.IsButton() )
5543 if( coords
.GetRow() < 0 || coords
.GetCol() < 0 )
5545 // out of grid cell area
5546 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5550 int dragRow
= YToEdgeOfRow( y
);
5551 int dragCol
= XToEdgeOfCol( x
);
5553 // Dragging on the corner of a cell to resize in both
5554 // directions is not implemented yet...
5556 if ( dragRow
>= 0 && dragCol
>= 0 )
5558 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5564 m_dragRowOrCol
= dragRow
;
5566 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5568 if ( CanDragRowSize() && CanDragGridSize() )
5569 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
);
5574 m_dragRowOrCol
= dragCol
;
5582 m_dragRowOrCol
= dragCol
;
5584 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5586 if ( CanDragColSize() && CanDragGridSize() )
5587 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
);
5593 // Neither on a row or col edge
5595 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
5597 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5603 void wxGrid::DoEndDragResizeRow()
5605 if ( m_dragLastPos
>= 0 )
5607 // erase the last line and resize the row
5609 int cw
, ch
, left
, dummy
;
5610 m_gridWin
->GetClientSize( &cw
, &ch
);
5611 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
5613 wxClientDC
dc( m_gridWin
);
5615 dc
.SetLogicalFunction( wxINVERT
);
5616 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
5617 HideCellEditControl();
5618 SaveEditControlValue();
5620 int rowTop
= GetRowTop(m_dragRowOrCol
);
5621 SetRowSize( m_dragRowOrCol
,
5622 wxMax( m_dragLastPos
- rowTop
, m_minAcceptableRowHeight
) );
5624 if ( !GetBatchCount() )
5626 // Only needed to get the correct rect.y:
5627 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
5629 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
5630 rect
.width
= m_rowLabelWidth
;
5631 rect
.height
= ch
- rect
.y
;
5632 m_rowLabelWin
->Refresh( TRUE
, &rect
);
5634 // if there is a multicell block, paint all of it
5637 int i
, cell_rows
, cell_cols
, subtract_rows
= 0;
5638 int leftCol
= XToCol(left
);
5639 int rightCol
= internalXToCol(left
+cw
);
5642 for (i
=leftCol
; i
<rightCol
; i
++)
5644 GetCellSize(m_dragRowOrCol
, i
, &cell_rows
, &cell_cols
);
5645 if (cell_rows
< subtract_rows
)
5646 subtract_rows
= cell_rows
;
5648 rect
.y
= GetRowTop(m_dragRowOrCol
+ subtract_rows
);
5649 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
5650 rect
.height
= ch
- rect
.y
;
5653 m_gridWin
->Refresh( FALSE
, &rect
);
5656 ShowCellEditControl();
5661 void wxGrid::DoEndDragResizeCol()
5663 if ( m_dragLastPos
>= 0 )
5665 // erase the last line and resize the col
5667 int cw
, ch
, dummy
, top
;
5668 m_gridWin
->GetClientSize( &cw
, &ch
);
5669 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
5671 wxClientDC
dc( m_gridWin
);
5673 dc
.SetLogicalFunction( wxINVERT
);
5674 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
5675 HideCellEditControl();
5676 SaveEditControlValue();
5678 int colLeft
= GetColLeft(m_dragRowOrCol
);
5679 SetColSize( m_dragRowOrCol
,
5680 wxMax( m_dragLastPos
- colLeft
,
5681 GetColMinimalWidth(m_dragRowOrCol
) ) );
5683 if ( !GetBatchCount() )
5685 // Only needed to get the correct rect.x:
5686 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
5688 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
5689 rect
.width
= cw
- rect
.x
;
5690 rect
.height
= m_colLabelHeight
;
5691 m_colLabelWin
->Refresh( TRUE
, &rect
);
5693 // if there is a multicell block, paint all of it
5696 int i
, cell_rows
, cell_cols
, subtract_cols
= 0;
5697 int topRow
= YToRow(top
);
5698 int bottomRow
= internalYToRow(top
+cw
);
5701 for (i
=topRow
; i
<bottomRow
; i
++)
5703 GetCellSize(i
, m_dragRowOrCol
, &cell_rows
, &cell_cols
);
5704 if (cell_cols
< subtract_cols
)
5705 subtract_cols
= cell_cols
;
5707 rect
.x
= GetColLeft(m_dragRowOrCol
+ subtract_cols
);
5708 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
5709 rect
.width
= cw
- rect
.x
;
5712 m_gridWin
->Refresh( FALSE
, &rect
);
5715 ShowCellEditControl();
5722 // ------ interaction with data model
5724 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
5726 switch ( msg
.GetId() )
5728 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
5729 return GetModelValues();
5731 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
5732 return SetModelValues();
5734 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
5735 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
5736 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
5737 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
5738 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
5739 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
5740 return Redimension( msg
);
5749 // The behaviour of this function depends on the grid table class
5750 // Clear() function. For the default wxGridStringTable class the
5751 // behavious is to replace all cell contents with wxEmptyString but
5752 // not to change the number of rows or cols.
5754 void wxGrid::ClearGrid()
5758 if (IsCellEditControlEnabled())
5759 DisableCellEditControl();
5762 if ( !GetBatchCount() ) m_gridWin
->Refresh();
5767 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
5769 // TODO: something with updateLabels flag
5773 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
5779 if (IsCellEditControlEnabled())
5780 DisableCellEditControl();
5782 bool done
= m_table
->InsertRows( pos
, numRows
);
5785 // the table will have sent the results of the insert row
5786 // operation to this view object as a grid table message
5792 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
5794 // TODO: something with updateLabels flag
5798 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
5804 bool done
= m_table
&& m_table
->AppendRows( numRows
);
5806 // the table will have sent the results of the append row
5807 // operation to this view object as a grid table message
5813 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
5815 // TODO: something with updateLabels flag
5819 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
5825 if (IsCellEditControlEnabled())
5826 DisableCellEditControl();
5828 bool done
= m_table
->DeleteRows( pos
, numRows
);
5830 // the table will have sent the results of the delete row
5831 // operation to this view object as a grid table message
5837 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
5839 // TODO: something with updateLabels flag
5843 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
5849 if (IsCellEditControlEnabled())
5850 DisableCellEditControl();
5852 bool done
= m_table
->InsertCols( pos
, numCols
);
5854 // the table will have sent the results of the insert col
5855 // operation to this view object as a grid table message
5861 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
5863 // TODO: something with updateLabels flag
5867 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
5873 bool done
= m_table
->AppendCols( numCols
);
5875 // the table will have sent the results of the append col
5876 // operation to this view object as a grid table message
5882 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
5884 // TODO: something with updateLabels flag
5888 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
5894 if (IsCellEditControlEnabled())
5895 DisableCellEditControl();
5897 bool done
= m_table
->DeleteCols( pos
, numCols
);
5899 // the table will have sent the results of the delete col
5900 // operation to this view object as a grid table message
5908 // ----- event handlers
5911 // Generate a grid event based on a mouse event and
5912 // return the result of ProcessEvent()
5914 int wxGrid::SendEvent( const wxEventType type
,
5916 wxMouseEvent
& mouseEv
)
5921 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
5923 int rowOrCol
= (row
== -1 ? col
: row
);
5925 wxGridSizeEvent
gridEvt( GetId(),
5929 mouseEv
.GetX() + GetRowLabelSize(),
5930 mouseEv
.GetY() + GetColLabelSize(),
5931 mouseEv
.ControlDown(),
5932 mouseEv
.ShiftDown(),
5934 mouseEv
.MetaDown() );
5936 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5937 vetoed
= !gridEvt
.IsAllowed();
5939 else if ( type
== wxEVT_GRID_RANGE_SELECT
)
5941 // Right now, it should _never_ end up here!
5942 wxGridRangeSelectEvent
gridEvt( GetId(),
5946 m_selectingBottomRight
,
5948 mouseEv
.ControlDown(),
5949 mouseEv
.ShiftDown(),
5951 mouseEv
.MetaDown() );
5953 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5954 vetoed
= !gridEvt
.IsAllowed();
5958 wxGridEvent
gridEvt( GetId(),
5962 mouseEv
.GetX() + GetRowLabelSize(),
5963 mouseEv
.GetY() + GetColLabelSize(),
5965 mouseEv
.ControlDown(),
5966 mouseEv
.ShiftDown(),
5968 mouseEv
.MetaDown() );
5969 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5970 vetoed
= !gridEvt
.IsAllowed();
5973 // A Veto'd event may not be `claimed' so test this first
5974 if (vetoed
) return -1;
5975 return claimed
? 1 : 0;
5979 // Generate a grid event of specified type and return the result
5980 // of ProcessEvent().
5982 int wxGrid::SendEvent( const wxEventType type
,
5988 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
5990 int rowOrCol
= (row
== -1 ? col
: row
);
5992 wxGridSizeEvent
gridEvt( GetId(),
5997 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5998 vetoed
= !gridEvt
.IsAllowed();
6002 wxGridEvent
gridEvt( GetId(),
6007 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
6008 vetoed
= !gridEvt
.IsAllowed();
6011 // A Veto'd event may not be `claimed' so test this first
6012 if (vetoed
) return -1;
6013 return claimed
? 1 : 0;
6017 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
6019 wxPaintDC
dc(this); // needed to prevent zillions of paint events on MSW
6022 void wxGrid::Refresh(bool eraseb
, const wxRect
* rect
)
6024 // Don't do anything if between Begin/EndBatch...
6025 // EndBatch() will do all this on the last nested one anyway.
6026 if (! GetBatchCount())
6028 // Refresh to get correct scrolled position:
6029 wxScrolledWindow::Refresh(eraseb
,rect
);
6033 int rect_x
, rect_y
, rectWidth
, rectHeight
;
6034 int width_label
, width_cell
, height_label
, height_cell
;
6037 //Copy rectangle can get scroll offsets..
6038 rect_x
= rect
->GetX();
6039 rect_y
= rect
->GetY();
6040 rectWidth
= rect
->GetWidth();
6041 rectHeight
= rect
->GetHeight();
6043 width_label
= m_rowLabelWidth
- rect_x
;
6044 if (width_label
> rectWidth
) width_label
= rectWidth
;
6046 height_label
= m_colLabelHeight
- rect_y
;
6047 if (height_label
> rectHeight
) height_label
= rectHeight
;
6049 if (rect_x
> m_rowLabelWidth
)
6051 x
= rect_x
- m_rowLabelWidth
;
6052 width_cell
= rectWidth
;
6057 width_cell
= rectWidth
- (m_rowLabelWidth
- rect_x
);
6060 if (rect_y
> m_colLabelHeight
)
6062 y
= rect_y
- m_colLabelHeight
;
6063 height_cell
= rectHeight
;
6068 height_cell
= rectHeight
- (m_colLabelHeight
- rect_y
);
6071 // Paint corner label part intersecting rect.
6072 if ( width_label
> 0 && height_label
> 0 )
6074 wxRect
anotherrect(rect_x
, rect_y
, width_label
, height_label
);
6075 m_cornerLabelWin
->Refresh(eraseb
, &anotherrect
);
6078 // Paint col labels part intersecting rect.
6079 if ( width_cell
> 0 && height_label
> 0 )
6081 wxRect
anotherrect(x
, rect_y
, width_cell
, height_label
);
6082 m_colLabelWin
->Refresh(eraseb
, &anotherrect
);
6085 // Paint row labels part intersecting rect.
6086 if ( width_label
> 0 && height_cell
> 0 )
6088 wxRect
anotherrect(rect_x
, y
, width_label
, height_cell
);
6089 m_rowLabelWin
->Refresh(eraseb
, &anotherrect
);
6092 // Paint cell area part intersecting rect.
6093 if ( width_cell
> 0 && height_cell
> 0 )
6095 wxRect
anotherrect(x
, y
, width_cell
, height_cell
);
6096 m_gridWin
->Refresh(eraseb
, &anotherrect
);
6101 m_cornerLabelWin
->Refresh(eraseb
, NULL
);
6102 m_colLabelWin
->Refresh(eraseb
, NULL
);
6103 m_rowLabelWin
->Refresh(eraseb
, NULL
);
6104 m_gridWin
->Refresh(eraseb
, NULL
);
6109 void wxGrid::OnSize( wxSizeEvent
& event
)
6111 // position the child windows
6114 // don't call CalcDimensions() from here, the base class handles the size
6120 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
6122 if ( m_inOnKeyDown
)
6124 // shouldn't be here - we are going round in circles...
6126 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
6129 m_inOnKeyDown
= TRUE
;
6131 // propagate the event up and see if it gets processed
6133 wxWindow
*parent
= GetParent();
6134 wxKeyEvent
keyEvt( event
);
6135 keyEvt
.SetEventObject( parent
);
6137 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
6140 // try local handlers
6142 switch ( event
.GetKeyCode() )
6145 if ( event
.ControlDown() )
6147 MoveCursorUpBlock( event
.ShiftDown() );
6151 MoveCursorUp( event
.ShiftDown() );
6156 if ( event
.ControlDown() )
6158 MoveCursorDownBlock( event
.ShiftDown() );
6162 MoveCursorDown( event
.ShiftDown() );
6167 if ( event
.ControlDown() )
6169 MoveCursorLeftBlock( event
.ShiftDown() );
6173 MoveCursorLeft( event
.ShiftDown() );
6178 if ( event
.ControlDown() )
6180 MoveCursorRightBlock( event
.ShiftDown() );
6184 MoveCursorRight( event
.ShiftDown() );
6189 case WXK_NUMPAD_ENTER
:
6190 if ( event
.ControlDown() )
6192 event
.Skip(); // to let the edit control have the return
6196 if ( GetGridCursorRow() < GetNumberRows()-1 )
6198 MoveCursorDown( event
.ShiftDown() );
6202 // at the bottom of a column
6203 HideCellEditControl();
6204 SaveEditControlValue();
6214 if (event
.ShiftDown())
6216 if ( GetGridCursorCol() > 0 )
6218 MoveCursorLeft( FALSE
);
6223 HideCellEditControl();
6224 SaveEditControlValue();
6229 if ( GetGridCursorCol() < GetNumberCols()-1 )
6231 MoveCursorRight( FALSE
);
6236 HideCellEditControl();
6237 SaveEditControlValue();
6243 if ( event
.ControlDown() )
6245 MakeCellVisible( 0, 0 );
6246 SetCurrentCell( 0, 0 );
6255 if ( event
.ControlDown() )
6257 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
6258 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
6275 if ( event
.ControlDown() )
6279 m_selection
->ToggleCellSelection( m_currentCellCoords
.GetRow(),
6280 m_currentCellCoords
.GetCol(),
6281 event
.ControlDown(),
6288 if ( !IsEditable() )
6290 MoveCursorRight( FALSE
);
6293 // Otherwise fall through to default
6296 // is it possible to edit the current cell at all?
6297 if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
6299 // yes, now check whether the cells editor accepts the key
6300 int row
= m_currentCellCoords
.GetRow();
6301 int col
= m_currentCellCoords
.GetCol();
6302 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6303 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
6305 // <F2> is special and will always start editing, for
6306 // other keys - ask the editor itself
6307 if ( (event
.GetKeyCode() == WXK_F2
&& !event
.HasModifiers())
6308 || editor
->IsAcceptedKey(event
) )
6310 // ensure cell is visble
6311 MakeCellVisible(row
, col
);
6312 EnableCellEditControl();
6314 // a problem can arise if the cell is not completely
6315 // visible (even after calling MakeCellVisible the
6316 // control is not created and calling StartingKey will
6318 if( editor
->IsCreated() && m_cellEditCtrlEnabled
) editor
->StartingKey(event
);
6330 // let others process char events with modifiers or all
6331 // char events for readonly cells
6338 m_inOnKeyDown
= FALSE
;
6341 void wxGrid::OnKeyUp( wxKeyEvent
& event
)
6343 // try local handlers
6345 if ( event
.GetKeyCode() == WXK_SHIFT
)
6347 if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
6348 m_selectingBottomRight
!= wxGridNoCellCoords
)
6352 m_selection
->SelectBlock( m_selectingTopLeft
.GetRow(),
6353 m_selectingTopLeft
.GetCol(),
6354 m_selectingBottomRight
.GetRow(),
6355 m_selectingBottomRight
.GetCol(),
6356 event
.ControlDown(),
6363 m_selectingTopLeft
= wxGridNoCellCoords
;
6364 m_selectingBottomRight
= wxGridNoCellCoords
;
6365 m_selectingKeyboard
= wxGridNoCellCoords
;
6369 void wxGrid::OnEraseBackground(wxEraseEvent
&)
6373 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
6375 if ( SendEvent( wxEVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
6377 // the event has been intercepted - do nothing
6381 wxClientDC
dc(m_gridWin
);
6384 if ( m_currentCellCoords
!= wxGridNoCellCoords
)
6386 HideCellEditControl();
6387 DisableCellEditControl();
6389 if ( IsVisible( m_currentCellCoords
, FALSE
) )
6392 r
= BlockToDeviceRect(m_currentCellCoords
, m_currentCellCoords
);
6393 if ( !m_gridLinesEnabled
)
6401 wxGridCellCoordsArray cells
= CalcCellsExposed( r
);
6403 // Otherwise refresh redraws the highlight!
6404 m_currentCellCoords
= coords
;
6406 DrawGridCellArea(dc
,cells
);
6407 DrawAllGridLines( dc
, r
);
6411 m_currentCellCoords
= coords
;
6413 wxGridCellAttr
* attr
= GetCellAttr(coords
);
6414 DrawCellHighlight(dc
, attr
);
6419 void wxGrid::HighlightBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
6422 wxGridCellCoords updateTopLeft
, updateBottomRight
;
6426 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectRows
)
6429 rightCol
= GetNumberCols() - 1;
6431 else if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectColumns
)
6434 bottomRow
= GetNumberRows() - 1;
6438 if ( topRow
> bottomRow
)
6445 if ( leftCol
> rightCol
)
6452 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
6453 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
6455 // First the case that we selected a completely new area
6456 if ( m_selectingTopLeft
== wxGridNoCellCoords
||
6457 m_selectingBottomRight
== wxGridNoCellCoords
)
6460 rect
= BlockToDeviceRect( wxGridCellCoords ( topRow
, leftCol
),
6461 wxGridCellCoords ( bottomRow
, rightCol
) );
6462 m_gridWin
->Refresh( FALSE
, &rect
);
6464 // Now handle changing an existing selection area.
6465 else if ( m_selectingTopLeft
!= updateTopLeft
||
6466 m_selectingBottomRight
!= updateBottomRight
)
6468 // Compute two optimal update rectangles:
6469 // Either one rectangle is a real subset of the
6470 // other, or they are (almost) disjoint!
6472 bool need_refresh
[4];
6476 need_refresh
[3] = FALSE
;
6479 // Store intermediate values
6480 wxCoord oldLeft
= m_selectingTopLeft
.GetCol();
6481 wxCoord oldTop
= m_selectingTopLeft
.GetRow();
6482 wxCoord oldRight
= m_selectingBottomRight
.GetCol();
6483 wxCoord oldBottom
= m_selectingBottomRight
.GetRow();
6485 // Determine the outer/inner coordinates.
6486 if (oldLeft
> leftCol
)
6492 if (oldTop
> topRow
)
6498 if (oldRight
< rightCol
)
6501 oldRight
= rightCol
;
6504 if (oldBottom
< bottomRow
)
6507 oldBottom
= bottomRow
;
6511 // Now, either the stuff marked old is the outer
6512 // rectangle or we don't have a situation where one
6513 // is contained in the other.
6515 if ( oldLeft
< leftCol
)
6517 // Refresh the newly selected or deselected
6518 // area to the left of the old or new selection.
6519 need_refresh
[0] = TRUE
;
6520 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6522 wxGridCellCoords ( oldBottom
,
6526 if ( oldTop
< topRow
)
6528 // Refresh the newly selected or deselected
6529 // area above the old or new selection.
6530 need_refresh
[1] = TRUE
;
6531 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6533 wxGridCellCoords ( topRow
- 1,
6537 if ( oldRight
> rightCol
)
6539 // Refresh the newly selected or deselected
6540 // area to the right of the old or new selection.
6541 need_refresh
[2] = TRUE
;
6542 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6544 wxGridCellCoords ( oldBottom
,
6548 if ( oldBottom
> bottomRow
)
6550 // Refresh the newly selected or deselected
6551 // area below the old or new selection.
6552 need_refresh
[3] = TRUE
;
6553 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
6555 wxGridCellCoords ( oldBottom
,
6559 // various Refresh() calls
6560 for (i
= 0; i
< 4; i
++ )
6561 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
6562 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
6565 m_selectingTopLeft
= updateTopLeft
;
6566 m_selectingBottomRight
= updateBottomRight
;
6570 // ------ functions to get/send data (see also public functions)
6573 bool wxGrid::GetModelValues()
6575 // Hide the editor, so it won't hide a changed value.
6576 HideCellEditControl();
6580 // all we need to do is repaint the grid
6582 m_gridWin
->Refresh();
6590 bool wxGrid::SetModelValues()
6594 // Disable the editor, so it won't hide a changed value.
6595 // Do we also want to save the current value of the editor first?
6597 DisableCellEditControl();
6601 for ( row
= 0; row
< m_numRows
; row
++ )
6603 for ( col
= 0; col
< m_numCols
; col
++ )
6605 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
6617 // Note - this function only draws cells that are in the list of
6618 // exposed cells (usually set from the update region by
6619 // CalcExposedCells)
6621 void wxGrid::DrawGridCellArea( wxDC
& dc
, const wxGridCellCoordsArray
& cells
)
6623 if ( !m_numRows
|| !m_numCols
) return;
6625 int i
, numCells
= cells
.GetCount();
6626 int row
, col
, cell_rows
, cell_cols
;
6627 wxGridCellCoordsArray redrawCells
;
6629 for ( i
= numCells
-1; i
>= 0; i
-- )
6631 row
= cells
[i
].GetRow();
6632 col
= cells
[i
].GetCol();
6633 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
6635 // If this cell is part of a multicell block, find owner for repaint
6636 if ( cell_rows
<= 0 || cell_cols
<= 0 )
6638 wxGridCellCoords
cell(row
+cell_rows
, col
+cell_cols
);
6639 bool marked
= FALSE
;
6640 for ( int j
= 0; j
< numCells
; j
++ )
6642 if ( cell
== cells
[j
] )
6650 int count
= redrawCells
.GetCount();
6651 for (int j
= 0; j
< count
; j
++)
6653 if ( cell
== redrawCells
[j
] )
6659 if (!marked
) redrawCells
.Add( cell
);
6661 continue; // don't bother drawing this cell
6664 // If this cell is empty, find cell to left that might want to overflow
6665 if (m_table
&& m_table
->IsEmptyCell(row
, col
))
6667 for ( int l
= 0; l
< cell_rows
; l
++ )
6669 // find a cell in this row to left alreay marked for repaint
6671 for (int k
= 0; k
< int(redrawCells
.GetCount()); k
++)
6672 if ((redrawCells
[k
].GetCol() < left
) &&
6673 (redrawCells
[k
].GetRow() == row
))
6674 left
=redrawCells
[k
].GetCol();
6676 if (left
== col
) left
= 0; // oh well
6678 for (int j
= col
-1; j
>= left
; j
--)
6680 if (!m_table
->IsEmptyCell(row
+l
, j
))
6682 if (GetCellOverflow(row
+l
, j
))
6684 wxGridCellCoords
cell(row
+l
, j
);
6685 bool marked
= FALSE
;
6687 for (int k
= 0; k
< numCells
; k
++)
6689 if ( cell
== cells
[k
] )
6697 int count
= redrawCells
.GetCount();
6698 for (int k
= 0; k
< count
; k
++)
6700 if ( cell
== redrawCells
[k
] )
6706 if (!marked
) redrawCells
.Add( cell
);
6714 DrawCell( dc
, cells
[i
] );
6717 numCells
= redrawCells
.GetCount();
6719 for ( i
= numCells
- 1; i
>= 0; i
-- )
6721 DrawCell( dc
, redrawCells
[i
] );
6726 void wxGrid::DrawGridSpace( wxDC
& dc
)
6729 m_gridWin
->GetClientSize( &cw
, &ch
);
6732 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6734 int rightCol
= m_numCols
> 0 ? GetColRight(m_numCols
- 1) : 0;
6735 int bottomRow
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) : 0 ;
6737 if ( right
> rightCol
|| bottom
> bottomRow
)
6740 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6742 dc
.SetBrush( wxBrush(GetDefaultCellBackgroundColour(), wxSOLID
) );
6743 dc
.SetPen( *wxTRANSPARENT_PEN
);
6745 if ( right
> rightCol
)
6747 dc
.DrawRectangle( rightCol
, top
, right
- rightCol
, ch
);
6750 if ( bottom
> bottomRow
)
6752 dc
.DrawRectangle( left
, bottomRow
, cw
, bottom
- bottomRow
);
6758 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
6760 int row
= coords
.GetRow();
6761 int col
= coords
.GetCol();
6763 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6766 // we draw the cell border ourselves
6767 #if !WXGRID_DRAW_LINES
6768 if ( m_gridLinesEnabled
)
6769 DrawCellBorder( dc
, coords
);
6772 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6774 bool isCurrent
= coords
== m_currentCellCoords
;
6776 wxRect rect
= CellToRect( row
, col
);
6778 // if the editor is shown, we should use it and not the renderer
6779 // Note: However, only if it is really _shown_, i.e. not hidden!
6780 if ( isCurrent
&& IsCellEditControlShown() )
6782 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
6783 editor
->PaintBackground(rect
, attr
);
6788 // but all the rest is drawn by the cell renderer and hence may be
6790 wxGridCellRenderer
*renderer
= attr
->GetRenderer(this, row
, col
);
6791 renderer
->Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
6798 void wxGrid::DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
)
6800 int row
= m_currentCellCoords
.GetRow();
6801 int col
= m_currentCellCoords
.GetCol();
6803 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6806 wxRect rect
= CellToRect(row
, col
);
6808 // hmmm... what could we do here to show that the cell is disabled?
6809 // for now, I just draw a thinner border than for the other ones, but
6810 // it doesn't look really good
6812 int penWidth
= attr
->IsReadOnly() ? m_cellHighlightROPenWidth
: m_cellHighlightPenWidth
;
6816 // The center of th drawn line is where the position/width/height of
6817 // the rectangle is actually at, (on wxMSW atr least,) so we will
6818 // reduce the size of the rectangle to compensate for the thickness of
6819 // the line. If this is too strange on non wxMSW platforms then
6820 // please #ifdef this appropriately.
6821 rect
.x
+= penWidth
/2;
6822 rect
.y
+= penWidth
/2;
6823 rect
.width
-= penWidth
-1;
6824 rect
.height
-= penWidth
-1;
6827 // Now draw the rectangle
6828 // use the cellHighlightColour if the cell is inside a selection, this
6829 // will ensure the cell is always visible.
6830 dc
.SetPen(wxPen(IsInSelection(row
,col
)?m_selectionForeground
:m_cellHighlightColour
, penWidth
, wxSOLID
));
6831 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
6832 dc
.DrawRectangle(rect
);
6836 // VZ: my experiments with 3d borders...
6838 // how to properly set colours for arbitrary bg?
6839 wxCoord x1
= rect
.x
,
6841 x2
= rect
.x
+ rect
.width
-1,
6842 y2
= rect
.y
+ rect
.height
-1;
6844 dc
.SetPen(*wxWHITE_PEN
);
6845 dc
.DrawLine(x1
, y1
, x2
, y1
);
6846 dc
.DrawLine(x1
, y1
, x1
, y2
);
6848 dc
.DrawLine(x1
+ 1, y2
- 1, x2
- 1, y2
- 1);
6849 dc
.DrawLine(x2
- 1, y1
+ 1, x2
- 1, y2
);
6851 dc
.SetPen(*wxBLACK_PEN
);
6852 dc
.DrawLine(x1
, y2
, x2
, y2
);
6853 dc
.DrawLine(x2
, y1
, x2
, y2
+1);
6858 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
6860 int row
= coords
.GetRow();
6861 int col
= coords
.GetCol();
6862 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6865 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
6867 wxRect rect
= CellToRect( row
, col
);
6869 // right hand border
6871 dc
.DrawLine( rect
.x
+ rect
.width
, rect
.y
,
6872 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
+ 1 );
6876 dc
.DrawLine( rect
.x
, rect
.y
+ rect
.height
,
6877 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
6880 void wxGrid::DrawHighlight(wxDC
& dc
,const wxGridCellCoordsArray
& cells
)
6882 // This if block was previously in wxGrid::OnPaint but that doesn't
6883 // seem to get called under wxGTK - MB
6885 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
6886 m_numRows
&& m_numCols
)
6888 m_currentCellCoords
.Set(0, 0);
6891 if ( IsCellEditControlShown() )
6893 // don't show highlight when the edit control is shown
6897 // if the active cell was repainted, repaint its highlight too because it
6898 // might have been damaged by the grid lines
6899 size_t count
= cells
.GetCount();
6900 for ( size_t n
= 0; n
< count
; n
++ )
6902 if ( cells
[n
] == m_currentCellCoords
)
6904 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
6905 DrawCellHighlight(dc
, attr
);
6913 // TODO: remove this ???
6914 // This is used to redraw all grid lines e.g. when the grid line colour
6917 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& WXUNUSED(reg
) )
6919 #if !WXGRID_DRAW_LINES
6923 if ( !m_gridLinesEnabled
||
6925 !m_numCols
) return;
6927 int top
, bottom
, left
, right
;
6929 #if 0 //#ifndef __WXGTK__
6933 m_gridWin
->GetClientSize(&cw
, &ch
);
6935 // virtual coords of visible area
6937 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6938 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6943 reg
.GetBox(x
, y
, w
, h
);
6944 CalcUnscrolledPosition( x
, y
, &left
, &top
);
6945 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
6949 m_gridWin
->GetClientSize(&cw
, &ch
);
6950 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6951 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6954 // avoid drawing grid lines past the last row and col
6956 right
= wxMin( right
, GetColRight(m_numCols
- 1) );
6957 bottom
= wxMin( bottom
, GetRowBottom(m_numRows
- 1) );
6959 // no gridlines inside multicells, clip them out
6960 int leftCol
= internalXToCol(left
);
6961 int topRow
= internalYToRow(top
);
6962 int rightCol
= internalXToCol(right
);
6963 int bottomRow
= internalYToRow(bottom
);
6964 wxRegion
clippedcells(0, 0, cw
, ch
);
6967 int i
, j
, cell_rows
, cell_cols
;
6970 for (j
=topRow
; j
<bottomRow
; j
++)
6972 for (i
=leftCol
; i
<rightCol
; i
++)
6974 GetCellSize( j
, i
, &cell_rows
, &cell_cols
);
6975 if ((cell_rows
> 1) || (cell_cols
> 1))
6977 rect
= CellToRect(j
,i
);
6978 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
6979 clippedcells
.Subtract(rect
);
6981 else if ((cell_rows
< 0) || (cell_cols
< 0))
6983 rect
= CellToRect(j
+cell_rows
, i
+cell_cols
);
6984 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
6985 clippedcells
.Subtract(rect
);
6989 dc
.SetClippingRegion( clippedcells
);
6991 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
6993 // horizontal grid lines
6995 // already declared above - int i;
6996 for ( i
= internalYToRow(top
); i
< m_numRows
; i
++ )
6998 int bot
= GetRowBottom(i
) - 1;
7007 dc
.DrawLine( left
, bot
, right
, bot
);
7012 // vertical grid lines
7014 for ( i
= internalXToCol(left
); i
< m_numCols
; i
++ )
7016 int colRight
= GetColRight(i
) - 1;
7017 if ( colRight
> right
)
7022 if ( colRight
>= left
)
7024 dc
.DrawLine( colRight
, top
, colRight
, bottom
);
7027 dc
.DestroyClippingRegion();
7031 void wxGrid::DrawRowLabels( wxDC
& dc
,const wxArrayInt
& rows
)
7033 if ( !m_numRows
) return;
7036 size_t numLabels
= rows
.GetCount();
7038 for ( i
= 0; i
< numLabels
; i
++ )
7040 DrawRowLabel( dc
, rows
[i
] );
7045 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
7047 if ( GetRowHeight(row
) <= 0 )
7050 int rowTop
= GetRowTop(row
),
7051 rowBottom
= GetRowBottom(row
) - 1;
7053 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
),1, wxSOLID
) );
7054 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
7055 m_rowLabelWidth
-1, rowBottom
);
7057 dc
.DrawLine( 0, rowTop
, 0, rowBottom
);
7059 dc
.DrawLine( 0, rowBottom
, m_rowLabelWidth
, rowBottom
);
7061 dc
.SetPen( *wxWHITE_PEN
);
7062 dc
.DrawLine( 1, rowTop
, 1, rowBottom
);
7063 dc
.DrawLine( 1, rowTop
, m_rowLabelWidth
-1, rowTop
);
7065 dc
.SetBackgroundMode( wxTRANSPARENT
);
7066 dc
.SetTextForeground( GetLabelTextColour() );
7067 dc
.SetFont( GetLabelFont() );
7070 GetRowLabelAlignment( &hAlign
, &vAlign
);
7074 rect
.SetY( GetRowTop(row
) + 2 );
7075 rect
.SetWidth( m_rowLabelWidth
- 4 );
7076 rect
.SetHeight( GetRowHeight(row
) - 4 );
7077 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
7081 void wxGrid::DrawColLabels( wxDC
& dc
,const wxArrayInt
& cols
)
7083 if ( !m_numCols
) return;
7086 size_t numLabels
= cols
.GetCount();
7088 for ( i
= 0; i
< numLabels
; i
++ )
7090 DrawColLabel( dc
, cols
[i
] );
7095 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
7097 if ( GetColWidth(col
) <= 0 )
7100 int colLeft
= GetColLeft(col
),
7101 colRight
= GetColRight(col
) - 1;
7103 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
),1, wxSOLID
) );
7104 dc
.DrawLine( colRight
, 0,
7105 colRight
, m_colLabelHeight
-1 );
7107 dc
.DrawLine( colLeft
, 0, colRight
, 0 );
7109 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
7110 colRight
+1, m_colLabelHeight
-1 );
7112 dc
.SetPen( *wxWHITE_PEN
);
7113 dc
.DrawLine( colLeft
, 1, colLeft
, m_colLabelHeight
-1 );
7114 dc
.DrawLine( colLeft
, 1, colRight
, 1 );
7116 dc
.SetBackgroundMode( wxTRANSPARENT
);
7117 dc
.SetTextForeground( GetLabelTextColour() );
7118 dc
.SetFont( GetLabelFont() );
7120 int hAlign
, vAlign
, orient
;
7121 GetColLabelAlignment( &hAlign
, &vAlign
);
7122 orient
= GetColLabelTextOrientation();
7125 rect
.SetX( colLeft
+ 2 );
7127 rect
.SetWidth( GetColWidth(col
) - 4 );
7128 rect
.SetHeight( m_colLabelHeight
- 4 );
7129 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
, orient
);
7132 void wxGrid::DrawTextRectangle( wxDC
& dc
,
7133 const wxString
& value
,
7137 int textOrientation
)
7139 wxArrayString lines
;
7141 StringToLines( value
, lines
);
7144 //Forward to new API.
7145 DrawTextRectangle( dc
,
7154 void wxGrid::DrawTextRectangle( wxDC
& dc
,
7155 const wxArrayString
& lines
,
7159 int textOrientation
)
7161 long textWidth
, textHeight
;
7162 long lineWidth
, lineHeight
;
7165 dc
.SetClippingRegion( rect
);
7167 nLines
= lines
.GetCount();
7171 float x
= 0.0, y
= 0.0;
7173 if( textOrientation
== wxHORIZONTAL
)
7174 GetTextBoxSize(dc
, lines
, &textWidth
, &textHeight
);
7176 GetTextBoxSize( dc
, lines
, &textHeight
, &textWidth
);
7180 case wxALIGN_BOTTOM
:
7181 if( textOrientation
== wxHORIZONTAL
)
7182 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
7184 x
= rect
.x
+ rect
.width
- textWidth
;
7187 case wxALIGN_CENTRE
:
7188 if( textOrientation
== wxHORIZONTAL
)
7189 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
7191 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
7196 if( textOrientation
== wxHORIZONTAL
)
7203 // Align each line of a multi-line label
7204 for( l
= 0; l
< nLines
; l
++ )
7206 dc
.GetTextExtent(lines
[l
], &lineWidth
, &lineHeight
);
7208 switch( horizAlign
)
7211 if( textOrientation
== wxHORIZONTAL
)
7212 x
= rect
.x
+ (rect
.width
- lineWidth
- 1);
7214 y
= rect
.y
+ lineWidth
+ 1;
7217 case wxALIGN_CENTRE
:
7218 if( textOrientation
== wxHORIZONTAL
)
7219 x
= rect
.x
+ ((rect
.width
- lineWidth
)/2);
7221 y
= rect
.y
+ rect
.height
- ((rect
.height
- lineWidth
)/2);
7226 if( textOrientation
== wxHORIZONTAL
)
7229 y
= rect
.y
+ rect
.height
- 1;
7233 if( textOrientation
== wxHORIZONTAL
)
7235 dc
.DrawText( lines
[l
], (int)x
, (int)y
);
7240 dc
.DrawRotatedText( lines
[l
], (int)x
, (int)y
, 90.0 );
7245 dc
.DestroyClippingRegion();
7249 // Split multi line text up into an array of strings. Any existing
7250 // contents of the string array are preserved.
7252 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
7256 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
7257 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
7259 while ( startPos
< (int)tVal
.Length() )
7261 pos
= tVal
.Mid(startPos
).Find( eol
);
7266 else if ( pos
== 0 )
7268 lines
.Add( wxEmptyString
);
7272 lines
.Add( value
.Mid(startPos
, pos
) );
7276 if ( startPos
< (int)value
.Length() )
7278 lines
.Add( value
.Mid( startPos
) );
7283 void wxGrid::GetTextBoxSize( wxDC
& dc
,
7284 const wxArrayString
& lines
,
7285 long *width
, long *height
)
7292 for ( i
= 0; i
< lines
.GetCount(); i
++ )
7294 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
7295 w
= wxMax( w
, lineW
);
7304 // ------ Batch processing.
7306 void wxGrid::EndBatch()
7308 if ( m_batchCount
> 0 )
7311 if ( !m_batchCount
)
7314 m_rowLabelWin
->Refresh();
7315 m_colLabelWin
->Refresh();
7316 m_cornerLabelWin
->Refresh();
7317 m_gridWin
->Refresh();
7322 // Use this, rather than wxWindow::Refresh(), to force an immediate
7323 // repainting of the grid. Has no effect if you are already inside a
7324 // BeginBatch / EndBatch block.
7326 void wxGrid::ForceRefresh()
7334 // ------ Edit control functions
7338 void wxGrid::EnableEditing( bool edit
)
7340 // TODO: improve this ?
7342 if ( edit
!= m_editable
)
7344 if(!edit
) EnableCellEditControl(edit
);
7350 void wxGrid::EnableCellEditControl( bool enable
)
7355 if ( m_currentCellCoords
== wxGridNoCellCoords
)
7356 SetCurrentCell( 0, 0 );
7358 if ( enable
!= m_cellEditCtrlEnabled
)
7362 if (SendEvent( wxEVT_GRID_EDITOR_SHOWN
) <0)
7365 // this should be checked by the caller!
7366 wxASSERT_MSG( CanEnableCellControl(),
7367 _T("can't enable editing for this cell!") );
7369 // do it before ShowCellEditControl()
7370 m_cellEditCtrlEnabled
= enable
;
7372 ShowCellEditControl();
7376 //FIXME:add veto support
7377 SendEvent( wxEVT_GRID_EDITOR_HIDDEN
);
7379 HideCellEditControl();
7380 SaveEditControlValue();
7382 // do it after HideCellEditControl()
7383 m_cellEditCtrlEnabled
= enable
;
7388 bool wxGrid::IsCurrentCellReadOnly() const
7391 wxGridCellAttr
* attr
= ((wxGrid
*)this)->GetCellAttr(m_currentCellCoords
);
7392 bool readonly
= attr
->IsReadOnly();
7398 bool wxGrid::CanEnableCellControl() const
7400 return m_editable
&& !IsCurrentCellReadOnly();
7403 bool wxGrid::IsCellEditControlEnabled() const
7405 // the cell edit control might be disable for all cells or just for the
7406 // current one if it's read only
7407 return m_cellEditCtrlEnabled
? !IsCurrentCellReadOnly() : FALSE
;
7410 bool wxGrid::IsCellEditControlShown() const
7412 bool isShown
= FALSE
;
7414 if ( m_cellEditCtrlEnabled
)
7416 int row
= m_currentCellCoords
.GetRow();
7417 int col
= m_currentCellCoords
.GetCol();
7418 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7419 wxGridCellEditor
* editor
= attr
->GetEditor((wxGrid
*) this, row
, col
);
7424 if ( editor
->IsCreated() )
7426 isShown
= editor
->GetControl()->IsShown();
7436 void wxGrid::ShowCellEditControl()
7438 if ( IsCellEditControlEnabled() )
7440 if ( !IsVisible( m_currentCellCoords
) )
7442 m_cellEditCtrlEnabled
= FALSE
;
7447 wxRect rect
= CellToRect( m_currentCellCoords
);
7448 int row
= m_currentCellCoords
.GetRow();
7449 int col
= m_currentCellCoords
.GetCol();
7451 // if this is part of a multicell, find owner (topleft)
7452 int cell_rows
, cell_cols
;
7453 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7454 if ( cell_rows
<= 0 || cell_cols
<= 0 )
7458 m_currentCellCoords
.SetRow( row
);
7459 m_currentCellCoords
.SetCol( col
);
7462 // convert to scrolled coords
7464 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
7466 // done in PaintBackground()
7468 // erase the highlight and the cell contents because the editor
7469 // might not cover the entire cell
7470 wxClientDC
dc( m_gridWin
);
7472 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
); //wxBrush(attr->GetBackgroundColour(), wxSOLID));
7473 dc
.SetPen(*wxTRANSPARENT_PEN
);
7474 dc
.DrawRectangle(rect
);
7477 // cell is shifted by one pixel
7478 // However, don't allow x or y to become negative
7479 // since the SetSize() method interprets that as
7486 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7487 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
7488 if ( !editor
->IsCreated() )
7490 editor
->Create(m_gridWin
, -1,
7491 new wxGridCellEditorEvtHandler(this, editor
));
7493 wxGridEditorCreatedEvent
evt(GetId(),
7494 wxEVT_GRID_EDITOR_CREATED
,
7498 editor
->GetControl());
7499 GetEventHandler()->ProcessEvent(evt
);
7503 // resize editor to overflow into righthand cells if allowed
7504 int maxWidth
= rect
.width
;
7505 wxString value
= GetCellValue(row
, col
);
7506 if ( (value
!= wxEmptyString
) && (attr
->GetOverflow()) )
7509 GetTextExtent(value
, &maxWidth
, &y
,
7510 NULL
, NULL
, &attr
->GetFont());
7511 if (maxWidth
< rect
.width
) maxWidth
= rect
.width
;
7513 int client_right
= m_gridWin
->GetClientSize().GetWidth();
7514 if (rect
.x
+maxWidth
> client_right
)
7515 maxWidth
= client_right
- rect
.x
;
7517 if ((maxWidth
> rect
.width
) && (col
< m_numCols
) && m_table
)
7519 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7520 // may have changed earlier
7521 for (int i
= col
+cell_cols
; i
< m_numCols
; i
++)
7524 GetCellSize( row
, i
, &c_rows
, &c_cols
);
7525 // looks weird going over a multicell
7526 if (m_table
->IsEmptyCell(row
,i
) &&
7527 (rect
.width
< maxWidth
) && (c_rows
== 1))
7528 rect
.width
+= GetColWidth(i
);
7532 if (rect
.GetRight() > client_right
)
7533 rect
.SetRight(client_right
-1);
7536 editor
->SetCellAttr(attr
);
7537 editor
->SetSize( rect
);
7538 editor
->Show( TRUE
, attr
);
7540 // recalc dimensions in case we need to
7541 // expand the scrolled window to account for editor
7544 editor
->BeginEdit(row
, col
, this);
7545 editor
->SetCellAttr(NULL
);
7554 void wxGrid::HideCellEditControl()
7556 if ( IsCellEditControlEnabled() )
7558 int row
= m_currentCellCoords
.GetRow();
7559 int col
= m_currentCellCoords
.GetCol();
7561 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7562 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
7563 editor
->Show( FALSE
);
7566 m_gridWin
->SetFocus();
7567 // refresh whole row to the right
7568 wxRect
rect( CellToRect(row
, col
) );
7569 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
7570 rect
.width
= m_gridWin
->GetClientSize().GetWidth() - rect
.x
;
7571 m_gridWin
->Refresh( FALSE
, &rect
);
7576 void wxGrid::SaveEditControlValue()
7578 if ( IsCellEditControlEnabled() )
7580 int row
= m_currentCellCoords
.GetRow();
7581 int col
= m_currentCellCoords
.GetCol();
7583 wxString oldval
= GetCellValue(row
,col
);
7585 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7586 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
7587 bool changed
= editor
->EndEdit(row
, col
, this);
7594 if ( SendEvent( wxEVT_GRID_CELL_CHANGE
,
7595 m_currentCellCoords
.GetRow(),
7596 m_currentCellCoords
.GetCol() ) < 0 ) {
7598 // Event has been vetoed, set the data back.
7599 SetCellValue(row
,col
,oldval
);
7607 // ------ Grid location functions
7608 // Note that all of these functions work with the logical coordinates of
7609 // grid cells and labels so you will need to convert from device
7610 // coordinates for mouse events etc.
7613 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
7615 int row
= YToRow(y
);
7616 int col
= XToCol(x
);
7618 if ( row
== -1 || col
== -1 )
7620 coords
= wxGridNoCellCoords
;
7624 coords
.Set( row
, col
);
7629 // Internal Helper function for computing row or column from some
7630 // (unscrolled) coordinate value, using either
7631 // m_defaultRowHeight/m_defaultColWidth or binary search on array
7632 // of m_rowBottoms/m_ColRights to speed up the search!
7634 static int CoordToRowOrCol(int coord
, int defaultDist
, int minDist
,
7635 const wxArrayInt
& BorderArray
, int nMax
,
7640 return clipToMinMax
&& (nMax
> 0) ? 0 : -1;
7646 size_t i_max
= coord
/ defaultDist
,
7649 if (BorderArray
.IsEmpty())
7651 if((int) i_max
< nMax
)
7653 return clipToMinMax
? nMax
- 1 : -1;
7656 if ( i_max
>= BorderArray
.GetCount())
7657 i_max
= BorderArray
.GetCount() - 1;
7660 if ( coord
>= BorderArray
[i_max
])
7663 i_max
= coord
/ minDist
;
7665 if ( i_max
>= BorderArray
.GetCount())
7666 i_max
= BorderArray
.GetCount() - 1;
7668 if ( coord
>= BorderArray
[i_max
])
7669 return clipToMinMax
? (int)i_max
: -1;
7670 if ( coord
< BorderArray
[0] )
7673 while ( i_max
- i_min
> 0 )
7675 wxCHECK_MSG(BorderArray
[i_min
] <= coord
&& coord
< BorderArray
[i_max
],
7676 0, _T("wxGrid: internal error in CoordToRowOrCol"));
7677 if (coord
>= BorderArray
[ i_max
- 1])
7681 int median
= i_min
+ (i_max
- i_min
+ 1) / 2;
7682 if (coord
< BorderArray
[median
])
7690 int wxGrid::YToRow( int y
)
7692 return CoordToRowOrCol(y
, m_defaultRowHeight
,
7693 m_minAcceptableRowHeight
, m_rowBottoms
, m_numRows
, FALSE
);
7697 int wxGrid::XToCol( int x
)
7699 return CoordToRowOrCol(x
, m_defaultColWidth
,
7700 m_minAcceptableColWidth
, m_colRights
, m_numCols
, FALSE
);
7704 // return the row number that that the y coord is near the edge of, or
7705 // -1 if not near an edge
7707 int wxGrid::YToEdgeOfRow( int y
)
7710 i
= internalYToRow(y
);
7712 if ( GetRowHeight(i
) > WXGRID_LABEL_EDGE_ZONE
)
7714 // We know that we are in row i, test whether we are
7715 // close enough to lower or upper border, respectively.
7716 if ( abs(GetRowBottom(i
) - y
) < WXGRID_LABEL_EDGE_ZONE
)
7718 else if( i
> 0 && y
- GetRowTop(i
) < WXGRID_LABEL_EDGE_ZONE
)
7726 // return the col number that that the x coord is near the edge of, or
7727 // -1 if not near an edge
7729 int wxGrid::XToEdgeOfCol( int x
)
7732 i
= internalXToCol(x
);
7734 if ( GetColWidth(i
) > WXGRID_LABEL_EDGE_ZONE
)
7736 // We know that we are in column i, test whether we are
7737 // close enough to right or left border, respectively.
7738 if ( abs(GetColRight(i
) - x
) < WXGRID_LABEL_EDGE_ZONE
)
7740 else if( i
> 0 && x
- GetColLeft(i
) < WXGRID_LABEL_EDGE_ZONE
)
7748 wxRect
wxGrid::CellToRect( int row
, int col
)
7750 wxRect
rect( -1, -1, -1, -1 );
7752 if ( row
>= 0 && row
< m_numRows
&&
7753 col
>= 0 && col
< m_numCols
)
7755 int i
, cell_rows
, cell_cols
;
7756 rect
.width
= rect
.height
= 0;
7757 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7758 // if negative then find multicell owner
7759 if (cell_rows
< 0) row
+= cell_rows
;
7760 if (cell_cols
< 0) col
+= cell_cols
;
7761 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7763 rect
.x
= GetColLeft(col
);
7764 rect
.y
= GetRowTop(row
);
7765 for (i
=col
; i
<col
+cell_cols
; i
++)
7766 rect
.width
+= GetColWidth(i
);
7767 for (i
=row
; i
<row
+cell_rows
; i
++)
7768 rect
.height
+= GetRowHeight(i
);
7771 // if grid lines are enabled, then the area of the cell is a bit smaller
7772 if (m_gridLinesEnabled
) {
7780 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
7782 // get the cell rectangle in logical coords
7784 wxRect
r( CellToRect( row
, col
) );
7786 // convert to device coords
7788 int left
, top
, right
, bottom
;
7789 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
7790 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
7792 // check against the client area of the grid window
7795 m_gridWin
->GetClientSize( &cw
, &ch
);
7797 if ( wholeCellVisible
)
7799 // is the cell wholly visible ?
7801 return ( left
>= 0 && right
<= cw
&&
7802 top
>= 0 && bottom
<= ch
);
7806 // is the cell partly visible ?
7808 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
7809 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
7814 // make the specified cell location visible by doing a minimal amount
7817 void wxGrid::MakeCellVisible( int row
, int col
)
7821 int xpos
= -1, ypos
= -1;
7823 if ( row
>= 0 && row
< m_numRows
&&
7824 col
>= 0 && col
< m_numCols
)
7826 // get the cell rectangle in logical coords
7828 wxRect
r( CellToRect( row
, col
) );
7830 // convert to device coords
7832 int left
, top
, right
, bottom
;
7833 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
7834 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
7837 m_gridWin
->GetClientSize( &cw
, &ch
);
7843 else if ( bottom
> ch
)
7845 int h
= r
.GetHeight();
7847 for ( i
= row
-1; i
>= 0; i
-- )
7849 int rowHeight
= GetRowHeight(i
);
7850 if ( h
+ rowHeight
> ch
)
7857 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
7858 // have rounding errors (this is important, because if we do, we
7859 // might not scroll at all and some cells won't be redrawn)
7861 // Sometimes GRID_SCROLL_LINE/2 is not enough, so just add a full
7863 ypos
+= GRID_SCROLL_LINE_Y
;
7870 else if ( right
> cw
)
7872 // position the view so that the cell is on the right
7874 CalcUnscrolledPosition(0, 0, &x0
, &y0
);
7875 xpos
= x0
+ (right
- cw
);
7877 // see comment for ypos above
7878 xpos
+= GRID_SCROLL_LINE_X
;
7881 if ( xpos
!= -1 || ypos
!= -1 )
7884 xpos
/= GRID_SCROLL_LINE_X
;
7886 ypos
/= GRID_SCROLL_LINE_Y
;
7887 Scroll( xpos
, ypos
);
7895 // ------ Grid cursor movement functions
7898 bool wxGrid::MoveCursorUp( bool expandSelection
)
7900 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7901 m_currentCellCoords
.GetRow() >= 0 )
7903 if ( expandSelection
)
7905 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7906 m_selectingKeyboard
= m_currentCellCoords
;
7907 if ( m_selectingKeyboard
.GetRow() > 0 )
7909 m_selectingKeyboard
.SetRow( m_selectingKeyboard
.GetRow() - 1 );
7910 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7911 m_selectingKeyboard
.GetCol() );
7912 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7915 else if ( m_currentCellCoords
.GetRow() > 0 )
7918 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
7919 m_currentCellCoords
.GetCol() );
7920 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
7921 m_currentCellCoords
.GetCol() );
7932 bool wxGrid::MoveCursorDown( bool expandSelection
)
7934 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7935 m_currentCellCoords
.GetRow() < m_numRows
)
7937 if ( expandSelection
)
7939 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7940 m_selectingKeyboard
= m_currentCellCoords
;
7941 if ( m_selectingKeyboard
.GetRow() < m_numRows
-1 )
7943 m_selectingKeyboard
.SetRow( m_selectingKeyboard
.GetRow() + 1 );
7944 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7945 m_selectingKeyboard
.GetCol() );
7946 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7949 else if ( m_currentCellCoords
.GetRow() < m_numRows
- 1 )
7952 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
7953 m_currentCellCoords
.GetCol() );
7954 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
7955 m_currentCellCoords
.GetCol() );
7966 bool wxGrid::MoveCursorLeft( bool expandSelection
)
7968 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7969 m_currentCellCoords
.GetCol() >= 0 )
7971 if ( expandSelection
)
7973 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7974 m_selectingKeyboard
= m_currentCellCoords
;
7975 if ( m_selectingKeyboard
.GetCol() > 0 )
7977 m_selectingKeyboard
.SetCol( m_selectingKeyboard
.GetCol() - 1 );
7978 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7979 m_selectingKeyboard
.GetCol() );
7980 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7983 else if ( m_currentCellCoords
.GetCol() > 0 )
7986 MakeCellVisible( m_currentCellCoords
.GetRow(),
7987 m_currentCellCoords
.GetCol() - 1 );
7988 SetCurrentCell( m_currentCellCoords
.GetRow(),
7989 m_currentCellCoords
.GetCol() - 1 );
8000 bool wxGrid::MoveCursorRight( bool expandSelection
)
8002 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
8003 m_currentCellCoords
.GetCol() < m_numCols
)
8005 if ( expandSelection
)
8007 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
8008 m_selectingKeyboard
= m_currentCellCoords
;
8009 if ( m_selectingKeyboard
.GetCol() < m_numCols
- 1 )
8011 m_selectingKeyboard
.SetCol( m_selectingKeyboard
.GetCol() + 1 );
8012 MakeCellVisible( m_selectingKeyboard
.GetRow(),
8013 m_selectingKeyboard
.GetCol() );
8014 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8017 else if ( m_currentCellCoords
.GetCol() < m_numCols
- 1 )
8020 MakeCellVisible( m_currentCellCoords
.GetRow(),
8021 m_currentCellCoords
.GetCol() + 1 );
8022 SetCurrentCell( m_currentCellCoords
.GetRow(),
8023 m_currentCellCoords
.GetCol() + 1 );
8034 bool wxGrid::MovePageUp()
8036 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
8038 int row
= m_currentCellCoords
.GetRow();
8042 m_gridWin
->GetClientSize( &cw
, &ch
);
8044 int y
= GetRowTop(row
);
8045 int newRow
= internalYToRow( y
- ch
+ 1 );
8047 if ( newRow
== row
)
8049 //row > 0 , so newrow can never be less than 0 here.
8053 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
8054 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
8062 bool wxGrid::MovePageDown()
8064 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
8066 int row
= m_currentCellCoords
.GetRow();
8067 if ( (row
+1) < m_numRows
)
8070 m_gridWin
->GetClientSize( &cw
, &ch
);
8072 int y
= GetRowTop(row
);
8073 int newRow
= internalYToRow( y
+ ch
);
8074 if ( newRow
== row
)
8076 // row < m_numRows , so newrow can't overflow here.
8080 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
8081 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
8089 bool wxGrid::MoveCursorUpBlock( bool expandSelection
)
8092 m_currentCellCoords
!= wxGridNoCellCoords
&&
8093 m_currentCellCoords
.GetRow() > 0 )
8095 int row
= m_currentCellCoords
.GetRow();
8096 int col
= m_currentCellCoords
.GetCol();
8098 if ( m_table
->IsEmptyCell(row
, col
) )
8100 // starting in an empty cell: find the next block of
8106 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8109 else if ( m_table
->IsEmptyCell(row
-1, col
) )
8111 // starting at the top of a block: find the next block
8117 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8122 // starting within a block: find the top of the block
8127 if ( m_table
->IsEmptyCell(row
, col
) )
8135 MakeCellVisible( row
, col
);
8136 if ( expandSelection
)
8138 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8139 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8144 SetCurrentCell( row
, col
);
8152 bool wxGrid::MoveCursorDownBlock( bool expandSelection
)
8155 m_currentCellCoords
!= wxGridNoCellCoords
&&
8156 m_currentCellCoords
.GetRow() < m_numRows
-1 )
8158 int row
= m_currentCellCoords
.GetRow();
8159 int col
= m_currentCellCoords
.GetCol();
8161 if ( m_table
->IsEmptyCell(row
, col
) )
8163 // starting in an empty cell: find the next block of
8166 while ( row
< m_numRows
-1 )
8169 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8172 else if ( m_table
->IsEmptyCell(row
+1, col
) )
8174 // starting at the bottom of a block: find the next block
8177 while ( row
< m_numRows
-1 )
8180 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8185 // starting within a block: find the bottom of the block
8187 while ( row
< m_numRows
-1 )
8190 if ( m_table
->IsEmptyCell(row
, col
) )
8198 MakeCellVisible( row
, col
);
8199 if ( expandSelection
)
8201 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8202 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8207 SetCurrentCell( row
, col
);
8216 bool wxGrid::MoveCursorLeftBlock( bool expandSelection
)
8219 m_currentCellCoords
!= wxGridNoCellCoords
&&
8220 m_currentCellCoords
.GetCol() > 0 )
8222 int row
= m_currentCellCoords
.GetRow();
8223 int col
= m_currentCellCoords
.GetCol();
8225 if ( m_table
->IsEmptyCell(row
, col
) )
8227 // starting in an empty cell: find the next block of
8233 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8236 else if ( m_table
->IsEmptyCell(row
, col
-1) )
8238 // starting at the left of a block: find the next block
8244 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8249 // starting within a block: find the left of the block
8254 if ( m_table
->IsEmptyCell(row
, col
) )
8262 MakeCellVisible( row
, col
);
8263 if ( expandSelection
)
8265 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8266 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8271 SetCurrentCell( row
, col
);
8280 bool wxGrid::MoveCursorRightBlock( bool expandSelection
)
8283 m_currentCellCoords
!= wxGridNoCellCoords
&&
8284 m_currentCellCoords
.GetCol() < m_numCols
-1 )
8286 int row
= m_currentCellCoords
.GetRow();
8287 int col
= m_currentCellCoords
.GetCol();
8289 if ( m_table
->IsEmptyCell(row
, col
) )
8291 // starting in an empty cell: find the next block of
8294 while ( col
< m_numCols
-1 )
8297 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8300 else if ( m_table
->IsEmptyCell(row
, col
+1) )
8302 // starting at the right of a block: find the next block
8305 while ( col
< m_numCols
-1 )
8308 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8313 // starting within a block: find the right of the block
8315 while ( col
< m_numCols
-1 )
8318 if ( m_table
->IsEmptyCell(row
, col
) )
8326 MakeCellVisible( row
, col
);
8327 if ( expandSelection
)
8329 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8330 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8335 SetCurrentCell( row
, col
);
8347 // ------ Label values and formatting
8350 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
8352 *horiz
= m_rowLabelHorizAlign
;
8353 *vert
= m_rowLabelVertAlign
;
8356 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
8358 *horiz
= m_colLabelHorizAlign
;
8359 *vert
= m_colLabelVertAlign
;
8362 int wxGrid::GetColLabelTextOrientation()
8364 return m_colLabelTextOrientation
;
8367 wxString
wxGrid::GetRowLabelValue( int row
)
8371 return m_table
->GetRowLabelValue( row
);
8381 wxString
wxGrid::GetColLabelValue( int col
)
8385 return m_table
->GetColLabelValue( col
);
8396 void wxGrid::SetRowLabelSize( int width
)
8398 width
= wxMax( width
, 0 );
8399 if ( width
!= m_rowLabelWidth
)
8403 m_rowLabelWin
->Show( FALSE
);
8404 m_cornerLabelWin
->Show( FALSE
);
8406 else if ( m_rowLabelWidth
== 0 )
8408 m_rowLabelWin
->Show( TRUE
);
8409 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
8412 m_rowLabelWidth
= width
;
8414 wxScrolledWindow::Refresh( TRUE
);
8419 void wxGrid::SetColLabelSize( int height
)
8421 height
= wxMax( height
, 0 );
8422 if ( height
!= m_colLabelHeight
)
8426 m_colLabelWin
->Show( FALSE
);
8427 m_cornerLabelWin
->Show( FALSE
);
8429 else if ( m_colLabelHeight
== 0 )
8431 m_colLabelWin
->Show( TRUE
);
8432 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
8435 m_colLabelHeight
= height
;
8437 wxScrolledWindow::Refresh( TRUE
);
8442 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
8444 if ( m_labelBackgroundColour
!= colour
)
8446 m_labelBackgroundColour
= colour
;
8447 m_rowLabelWin
->SetBackgroundColour( colour
);
8448 m_colLabelWin
->SetBackgroundColour( colour
);
8449 m_cornerLabelWin
->SetBackgroundColour( colour
);
8451 if ( !GetBatchCount() )
8453 m_rowLabelWin
->Refresh();
8454 m_colLabelWin
->Refresh();
8455 m_cornerLabelWin
->Refresh();
8460 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
8462 if ( m_labelTextColour
!= colour
)
8464 m_labelTextColour
= colour
;
8465 if ( !GetBatchCount() )
8467 m_rowLabelWin
->Refresh();
8468 m_colLabelWin
->Refresh();
8473 void wxGrid::SetLabelFont( const wxFont
& font
)
8476 if ( !GetBatchCount() )
8478 m_rowLabelWin
->Refresh();
8479 m_colLabelWin
->Refresh();
8483 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
8485 // allow old (incorrect) defs to be used
8488 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
8489 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
8490 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
8495 case wxTOP
: vert
= wxALIGN_TOP
; break;
8496 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
8497 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
8500 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
8502 m_rowLabelHorizAlign
= horiz
;
8505 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
8507 m_rowLabelVertAlign
= vert
;
8510 if ( !GetBatchCount() )
8512 m_rowLabelWin
->Refresh();
8516 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
8518 // allow old (incorrect) defs to be used
8521 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
8522 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
8523 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
8528 case wxTOP
: vert
= wxALIGN_TOP
; break;
8529 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
8530 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
8533 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
8535 m_colLabelHorizAlign
= horiz
;
8538 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
8540 m_colLabelVertAlign
= vert
;
8543 if ( !GetBatchCount() )
8545 m_colLabelWin
->Refresh();
8549 // Note: under MSW, the default column label font must be changed because it
8550 // does not support vertical printing
8552 // Example: wxFont font(9, wxSWISS, wxNORMAL, wxBOLD);
8553 // pGrid->SetLabelFont(font);
8554 // pGrid->SetColLabelTextOrientation(wxVERTICAL);
8556 void wxGrid::SetColLabelTextOrientation( int textOrientation
)
8558 if( textOrientation
== wxHORIZONTAL
|| textOrientation
== wxVERTICAL
)
8560 m_colLabelTextOrientation
= textOrientation
;
8563 if ( !GetBatchCount() )
8565 m_colLabelWin
->Refresh();
8569 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
8573 m_table
->SetRowLabelValue( row
, s
);
8574 if ( !GetBatchCount() )
8576 wxRect rect
= CellToRect( row
, 0);
8577 if ( rect
.height
> 0 )
8579 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
8581 rect
.width
= m_rowLabelWidth
;
8582 m_rowLabelWin
->Refresh( TRUE
, &rect
);
8588 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
8592 m_table
->SetColLabelValue( col
, s
);
8593 if ( !GetBatchCount() )
8595 wxRect rect
= CellToRect( 0, col
);
8596 if ( rect
.width
> 0 )
8598 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
8600 rect
.height
= m_colLabelHeight
;
8601 m_colLabelWin
->Refresh( TRUE
, &rect
);
8607 void wxGrid::SetGridLineColour( const wxColour
& colour
)
8609 if ( m_gridLineColour
!= colour
)
8611 m_gridLineColour
= colour
;
8613 wxClientDC
dc( m_gridWin
);
8615 DrawAllGridLines( dc
, wxRegion() );
8620 void wxGrid::SetCellHighlightColour( const wxColour
& colour
)
8622 if ( m_cellHighlightColour
!= colour
)
8624 m_cellHighlightColour
= colour
;
8626 wxClientDC
dc( m_gridWin
);
8628 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
8629 DrawCellHighlight(dc
, attr
);
8634 void wxGrid::SetCellHighlightPenWidth(int width
)
8636 if (m_cellHighlightPenWidth
!= width
) {
8637 m_cellHighlightPenWidth
= width
;
8639 // Just redrawing the cell highlight is not enough since that won't
8640 // make any visible change if the the thickness is getting smaller.
8641 int row
= m_currentCellCoords
.GetRow();
8642 int col
= m_currentCellCoords
.GetCol();
8643 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
8645 wxRect rect
= CellToRect(row
, col
);
8646 m_gridWin
->Refresh(TRUE
, &rect
);
8650 void wxGrid::SetCellHighlightROPenWidth(int width
)
8652 if (m_cellHighlightROPenWidth
!= width
) {
8653 m_cellHighlightROPenWidth
= width
;
8655 // Just redrawing the cell highlight is not enough since that won't
8656 // make any visible change if the the thickness is getting smaller.
8657 int row
= m_currentCellCoords
.GetRow();
8658 int col
= m_currentCellCoords
.GetCol();
8659 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
8661 wxRect rect
= CellToRect(row
, col
);
8662 m_gridWin
->Refresh(TRUE
, &rect
);
8666 void wxGrid::EnableGridLines( bool enable
)
8668 if ( enable
!= m_gridLinesEnabled
)
8670 m_gridLinesEnabled
= enable
;
8672 if ( !GetBatchCount() )
8676 wxClientDC
dc( m_gridWin
);
8678 DrawAllGridLines( dc
, wxRegion() );
8682 m_gridWin
->Refresh();
8689 int wxGrid::GetDefaultRowSize()
8691 return m_defaultRowHeight
;
8694 int wxGrid::GetRowSize( int row
)
8696 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
8698 return GetRowHeight(row
);
8701 int wxGrid::GetDefaultColSize()
8703 return m_defaultColWidth
;
8706 int wxGrid::GetColSize( int col
)
8708 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
8710 return GetColWidth(col
);
8713 // ============================================================================
8714 // access to the grid attributes: each of them has a default value in the grid
8715 // itself and may be overidden on a per-cell basis
8716 // ============================================================================
8718 // ----------------------------------------------------------------------------
8719 // setting default attributes
8720 // ----------------------------------------------------------------------------
8722 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
8724 m_defaultCellAttr
->SetBackgroundColour(col
);
8726 m_gridWin
->SetBackgroundColour(col
);
8730 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
8732 m_defaultCellAttr
->SetTextColour(col
);
8735 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
8737 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
8740 void wxGrid::SetDefaultCellOverflow( bool allow
)
8742 m_defaultCellAttr
->SetOverflow(allow
);
8745 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
8747 m_defaultCellAttr
->SetFont(font
);
8750 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
8752 m_defaultCellAttr
->SetRenderer(renderer
);
8755 void wxGrid::SetDefaultEditor(wxGridCellEditor
*editor
)
8757 m_defaultCellAttr
->SetEditor(editor
);
8760 // ----------------------------------------------------------------------------
8761 // access to the default attrbiutes
8762 // ----------------------------------------------------------------------------
8764 wxColour
wxGrid::GetDefaultCellBackgroundColour()
8766 return m_defaultCellAttr
->GetBackgroundColour();
8769 wxColour
wxGrid::GetDefaultCellTextColour()
8771 return m_defaultCellAttr
->GetTextColour();
8774 wxFont
wxGrid::GetDefaultCellFont()
8776 return m_defaultCellAttr
->GetFont();
8779 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
8781 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
8784 bool wxGrid::GetDefaultCellOverflow()
8786 return m_defaultCellAttr
->GetOverflow();
8789 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
8791 return m_defaultCellAttr
->GetRenderer(NULL
, 0, 0);
8794 wxGridCellEditor
*wxGrid::GetDefaultEditor() const
8796 return m_defaultCellAttr
->GetEditor(NULL
,0,0);
8799 // ----------------------------------------------------------------------------
8800 // access to cell attributes
8801 // ----------------------------------------------------------------------------
8803 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
8805 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8806 wxColour colour
= attr
->GetBackgroundColour();
8811 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
8813 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8814 wxColour colour
= attr
->GetTextColour();
8819 wxFont
wxGrid::GetCellFont( int row
, int col
)
8821 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8822 wxFont font
= attr
->GetFont();
8827 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
8829 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8830 attr
->GetAlignment(horiz
, vert
);
8834 bool wxGrid::GetCellOverflow( int row
, int col
)
8836 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8837 bool allow
= attr
->GetOverflow();
8842 void wxGrid::GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
)
8844 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8845 attr
->GetSize( num_rows
, num_cols
);
8849 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
)
8851 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8852 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
8858 wxGridCellEditor
* wxGrid::GetCellEditor(int row
, int col
)
8860 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8861 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
8867 bool wxGrid::IsReadOnly(int row
, int col
) const
8869 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8870 bool isReadOnly
= attr
->IsReadOnly();
8875 // ----------------------------------------------------------------------------
8876 // attribute support: cache, automatic provider creation, ...
8877 // ----------------------------------------------------------------------------
8879 bool wxGrid::CanHaveAttributes()
8886 return m_table
->CanHaveAttributes();
8889 void wxGrid::ClearAttrCache()
8891 if ( m_attrCache
.row
!= -1 )
8893 wxSafeDecRef(m_attrCache
.attr
);
8894 m_attrCache
.attr
= NULL
;
8895 m_attrCache
.row
= -1;
8899 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
8903 wxGrid
*self
= (wxGrid
*)this; // const_cast
8905 self
->ClearAttrCache();
8906 self
->m_attrCache
.row
= row
;
8907 self
->m_attrCache
.col
= col
;
8908 self
->m_attrCache
.attr
= attr
;
8913 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
8915 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
8917 *attr
= m_attrCache
.attr
;
8918 wxSafeIncRef(m_attrCache
.attr
);
8920 #ifdef DEBUG_ATTR_CACHE
8921 gs_nAttrCacheHits
++;
8928 #ifdef DEBUG_ATTR_CACHE
8929 gs_nAttrCacheMisses
++;
8935 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
8937 wxGridCellAttr
*attr
= NULL
;
8938 // Additional test to avoid looking at the cache e.g. for
8939 // wxNoCellCoords, as this will confuse memory management.
8942 if ( !LookupAttr(row
, col
, &attr
) )
8944 attr
= m_table
? m_table
->GetAttr(row
, col
, wxGridCellAttr::Any
)
8945 : (wxGridCellAttr
*)NULL
;
8946 CacheAttr(row
, col
, attr
);
8951 attr
->SetDefAttr(m_defaultCellAttr
);
8955 attr
= m_defaultCellAttr
;
8962 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
8964 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
8966 wxCHECK_MSG( m_table
, attr
,
8967 _T("we may only be called if CanHaveAttributes() returned TRUE and then m_table should be !NULL") );
8969 attr
= m_table
->GetAttr(row
, col
, wxGridCellAttr::Cell
);
8972 attr
= new wxGridCellAttr(m_defaultCellAttr
);
8974 // artificially inc the ref count to match DecRef() in caller
8976 m_table
->SetAttr(attr
, row
, col
);
8982 // ----------------------------------------------------------------------------
8983 // setting column attributes (wrappers around SetColAttr)
8984 // ----------------------------------------------------------------------------
8986 void wxGrid::SetColFormatBool(int col
)
8988 SetColFormatCustom(col
, wxGRID_VALUE_BOOL
);
8991 void wxGrid::SetColFormatNumber(int col
)
8993 SetColFormatCustom(col
, wxGRID_VALUE_NUMBER
);
8996 void wxGrid::SetColFormatFloat(int col
, int width
, int precision
)
8998 wxString typeName
= wxGRID_VALUE_FLOAT
;
8999 if ( (width
!= -1) || (precision
!= -1) )
9001 typeName
<< _T(':') << width
<< _T(',') << precision
;
9004 SetColFormatCustom(col
, typeName
);
9007 void wxGrid::SetColFormatCustom(int col
, const wxString
& typeName
)
9009 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
9011 attr
= m_table
->GetAttr(-1, col
, wxGridCellAttr::Col
);
9013 attr
= new wxGridCellAttr
;
9014 wxGridCellRenderer
*renderer
= GetDefaultRendererForType(typeName
);
9015 attr
->SetRenderer(renderer
);
9017 SetColAttr(col
, attr
);
9021 // ----------------------------------------------------------------------------
9022 // setting cell attributes: this is forwarded to the table
9023 // ----------------------------------------------------------------------------
9025 void wxGrid::SetAttr(int row
, int col
, wxGridCellAttr
*attr
)
9027 if ( CanHaveAttributes() )
9029 m_table
->SetAttr(attr
, row
, col
);
9038 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
9040 if ( CanHaveAttributes() )
9042 m_table
->SetRowAttr(attr
, row
);
9051 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
9053 if ( CanHaveAttributes() )
9055 m_table
->SetColAttr(attr
, col
);
9064 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
9066 if ( CanHaveAttributes() )
9068 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9069 attr
->SetBackgroundColour(colour
);
9074 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
9076 if ( CanHaveAttributes() )
9078 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9079 attr
->SetTextColour(colour
);
9084 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
9086 if ( CanHaveAttributes() )
9088 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9089 attr
->SetFont(font
);
9094 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
9096 if ( CanHaveAttributes() )
9098 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9099 attr
->SetAlignment(horiz
, vert
);
9104 void wxGrid::SetCellOverflow( int row
, int col
, bool allow
)
9106 if ( CanHaveAttributes() )
9108 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9109 attr
->SetOverflow(allow
);
9114 void wxGrid::SetCellSize( int row
, int col
, int num_rows
, int num_cols
)
9116 if ( CanHaveAttributes() )
9118 int cell_rows
, cell_cols
;
9120 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9121 attr
->GetSize(&cell_rows
, &cell_cols
);
9122 attr
->SetSize(num_rows
, num_cols
);
9125 // Cannot set the size of a cell to 0 or negative values
9126 // While it is perfectly legal to do that, this function cannot
9127 // handle all the possibilies, do it by hand by getting the CellAttr.
9128 // You can only set the size of a cell to 1,1 or greater with this fn
9129 wxASSERT_MSG( !((cell_rows
< 1) || (cell_cols
< 1)),
9130 wxT("wxGrid::SetCellSize setting cell size that is already part of another cell"));
9131 wxASSERT_MSG( !((num_rows
< 1) || (num_cols
< 1)),
9132 wxT("wxGrid::SetCellSize setting cell size to < 1"));
9134 // if this was already a multicell then "turn off" the other cells first
9135 if ((cell_rows
> 1) || (cell_rows
> 1))
9138 for (j
=row
; j
<row
+cell_rows
; j
++)
9140 for (i
=col
; i
<col
+cell_cols
; i
++)
9142 if ((i
!= col
) || (j
!= row
))
9144 wxGridCellAttr
*attr_stub
= GetOrCreateCellAttr(j
, i
);
9145 attr_stub
->SetSize( 1, 1 );
9146 attr_stub
->DecRef();
9152 // mark the cells that will be covered by this cell to
9153 // negative or zero values to point back at this cell
9154 if (((num_rows
> 1) || (num_cols
> 1)) && (num_rows
>= 1) && (num_cols
>= 1))
9157 for (j
=row
; j
<row
+num_rows
; j
++)
9159 for (i
=col
; i
<col
+num_cols
; i
++)
9161 if ((i
!= col
) || (j
!= row
))
9163 wxGridCellAttr
*attr_stub
= GetOrCreateCellAttr(j
, i
);
9164 attr_stub
->SetSize( row
-j
, col
-i
);
9165 attr_stub
->DecRef();
9173 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
9175 if ( CanHaveAttributes() )
9177 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9178 attr
->SetRenderer(renderer
);
9183 void wxGrid::SetCellEditor(int row
, int col
, wxGridCellEditor
* editor
)
9185 if ( CanHaveAttributes() )
9187 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9188 attr
->SetEditor(editor
);
9193 void wxGrid::SetReadOnly(int row
, int col
, bool isReadOnly
)
9195 if ( CanHaveAttributes() )
9197 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9198 attr
->SetReadOnly(isReadOnly
);
9203 // ----------------------------------------------------------------------------
9204 // Data type registration
9205 // ----------------------------------------------------------------------------
9207 void wxGrid::RegisterDataType(const wxString
& typeName
,
9208 wxGridCellRenderer
* renderer
,
9209 wxGridCellEditor
* editor
)
9211 m_typeRegistry
->RegisterDataType(typeName
, renderer
, editor
);
9215 wxGridCellEditor
* wxGrid::GetDefaultEditorForCell(int row
, int col
) const
9217 wxString typeName
= m_table
->GetTypeName(row
, col
);
9218 return GetDefaultEditorForType(typeName
);
9221 wxGridCellRenderer
* wxGrid::GetDefaultRendererForCell(int row
, int col
) const
9223 wxString typeName
= m_table
->GetTypeName(row
, col
);
9224 return GetDefaultRendererForType(typeName
);
9228 wxGrid::GetDefaultEditorForType(const wxString
& typeName
) const
9230 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
9231 if ( index
== wxNOT_FOUND
)
9233 wxFAIL_MSG(wxT("Unknown data type name"));
9238 return m_typeRegistry
->GetEditor(index
);
9242 wxGrid::GetDefaultRendererForType(const wxString
& typeName
) const
9244 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
9245 if ( index
== wxNOT_FOUND
)
9247 wxFAIL_MSG(wxT("Unknown data type name"));
9252 return m_typeRegistry
->GetRenderer(index
);
9256 // ----------------------------------------------------------------------------
9258 // ----------------------------------------------------------------------------
9260 void wxGrid::EnableDragRowSize( bool enable
)
9262 m_canDragRowSize
= enable
;
9266 void wxGrid::EnableDragColSize( bool enable
)
9268 m_canDragColSize
= enable
;
9271 void wxGrid::EnableDragGridSize( bool enable
)
9273 m_canDragGridSize
= enable
;
9277 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
9279 m_defaultRowHeight
= wxMax( height
, m_minAcceptableRowHeight
);
9281 if ( resizeExistingRows
)
9283 // since we are resizing all rows to the default row size,
9284 // we can simply clear the row heights and row bottoms
9285 // arrays (which also allows us to take advantage of
9286 // some speed optimisations)
9287 m_rowHeights
.Empty();
9288 m_rowBottoms
.Empty();
9289 if ( !GetBatchCount() )
9294 void wxGrid::SetRowSize( int row
, int height
)
9296 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
9298 // See comment in SetColSize
9299 if ( height
< GetRowMinimalAcceptableHeight()) { return; }
9301 if ( m_rowHeights
.IsEmpty() )
9303 // need to really create the array
9307 int h
= wxMax( 0, height
);
9308 int diff
= h
- m_rowHeights
[row
];
9310 m_rowHeights
[row
] = h
;
9312 for ( i
= row
; i
< m_numRows
; i
++ )
9314 m_rowBottoms
[i
] += diff
;
9316 if ( !GetBatchCount() )
9320 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
9322 m_defaultColWidth
= wxMax( width
, m_minAcceptableColWidth
);
9324 if ( resizeExistingCols
)
9326 // since we are resizing all columns to the default column size,
9327 // we can simply clear the col widths and col rights
9328 // arrays (which also allows us to take advantage of
9329 // some speed optimisations)
9330 m_colWidths
.Empty();
9331 m_colRights
.Empty();
9332 if ( !GetBatchCount() )
9337 void wxGrid::SetColSize( int col
, int width
)
9339 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
9341 // should we check that it's bigger than GetColMinimalWidth(col) here?
9343 // No, because it is reasonable to assume the library user know's
9344 // what he is doing. However whe should test against the weaker
9345 // constariant of minimalAcceptableWidth, as this breaks rendering
9347 // This test then fixes sf.net bug #645734
9349 if ( width
< GetColMinimalAcceptableWidth()) { return; }
9351 if ( m_colWidths
.IsEmpty() )
9353 // need to really create the array
9357 // if < 0 calc new width from label
9361 wxArrayString lines
;
9362 wxClientDC
dc(m_colLabelWin
);
9363 dc
.SetFont(GetLabelFont());
9364 StringToLines(GetColLabelValue(col
), lines
);
9365 GetTextBoxSize(dc
, lines
, &w
, &h
);
9368 int w
= wxMax( 0, width
);
9369 int diff
= w
- m_colWidths
[col
];
9370 m_colWidths
[col
] = w
;
9373 for ( i
= col
; i
< m_numCols
; i
++ )
9375 m_colRights
[i
] += diff
;
9377 if ( !GetBatchCount() )
9382 void wxGrid::SetColMinimalWidth( int col
, int width
)
9384 if (width
> GetColMinimalAcceptableWidth()) {
9385 m_colMinWidths
[col
] = width
;
9389 void wxGrid::SetRowMinimalHeight( int row
, int width
)
9391 if (width
> GetRowMinimalAcceptableHeight()) {
9392 m_rowMinHeights
[row
] = width
;
9396 int wxGrid::GetColMinimalWidth(int col
) const
9398 wxLongToLongHashMap::const_iterator it
= m_colMinWidths
.find(col
);
9399 return it
!= m_colMinWidths
.end() ? (int)it
->second
: m_minAcceptableColWidth
;
9402 int wxGrid::GetRowMinimalHeight(int row
) const
9404 wxLongToLongHashMap::const_iterator it
= m_rowMinHeights
.find(row
);
9405 return it
!= m_rowMinHeights
.end() ? (int)it
->second
: m_minAcceptableRowHeight
;
9408 void wxGrid::SetColMinimalAcceptableWidth( int width
)
9412 m_minAcceptableColWidth
= width
;
9415 void wxGrid::SetRowMinimalAcceptableHeight( int height
)
9419 m_minAcceptableRowHeight
= height
;
9422 int wxGrid::GetColMinimalAcceptableWidth() const
9424 return m_minAcceptableColWidth
;
9427 int wxGrid::GetRowMinimalAcceptableHeight() const
9429 return m_minAcceptableRowHeight
;
9432 // ----------------------------------------------------------------------------
9434 // ----------------------------------------------------------------------------
9436 void wxGrid::AutoSizeColOrRow( int colOrRow
, bool setAsMin
, bool column
)
9438 wxClientDC
dc(m_gridWin
);
9440 // init both of them to avoid compiler warnings, even if weo nly need one
9448 wxCoord extent
, extentMax
= 0;
9449 int max
= column
? m_numRows
: m_numCols
;
9450 for ( int rowOrCol
= 0; rowOrCol
< max
; rowOrCol
++ )
9457 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
9458 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
9461 wxSize size
= renderer
->GetBestSize(*this, *attr
, dc
, row
, col
);
9462 extent
= column
? size
.x
: size
.y
;
9463 if ( extent
> extentMax
)
9474 // now also compare with the column label extent
9476 dc
.SetFont( GetLabelFont() );
9480 dc
.GetTextExtent( GetColLabelValue(col
), &w
, &h
);
9481 if( GetColLabelTextOrientation() == wxVERTICAL
)
9485 dc
.GetTextExtent( GetRowLabelValue(row
), &w
, &h
);
9487 extent
= column
? w
: h
;
9488 if ( extent
> extentMax
)
9495 // empty column - give default extent (notice that if extentMax is less
9496 // than default extent but != 0, it's ok)
9497 extentMax
= column
? m_defaultColWidth
: m_defaultRowHeight
;
9503 // leave some space around text
9514 SetColSize(col
, extentMax
);
9515 if ( !GetBatchCount() )
9518 m_gridWin
->GetClientSize( &cw
, &ch
);
9519 wxRect
rect ( CellToRect( 0, col
) );
9521 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
9522 rect
.width
= cw
- rect
.x
;
9523 rect
.height
= m_colLabelHeight
;
9524 m_colLabelWin
->Refresh( TRUE
, &rect
);
9529 SetRowSize(row
, extentMax
);
9530 if ( !GetBatchCount() )
9533 m_gridWin
->GetClientSize( &cw
, &ch
);
9534 wxRect
rect ( CellToRect( row
, 0 ) );
9536 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
9537 rect
.width
= m_rowLabelWidth
;
9538 rect
.height
= ch
- rect
.y
;
9539 m_rowLabelWin
->Refresh( TRUE
, &rect
);
9545 SetColMinimalWidth(col
, extentMax
);
9547 SetRowMinimalHeight(row
, extentMax
);
9551 int wxGrid::SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
)
9553 int width
= m_rowLabelWidth
;
9558 for ( int col
= 0; col
< m_numCols
; col
++ )
9562 AutoSizeColumn(col
, setAsMin
);
9565 width
+= GetColWidth(col
);
9574 int wxGrid::SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
)
9576 int height
= m_colLabelHeight
;
9581 for ( int row
= 0; row
< m_numRows
; row
++ )
9585 AutoSizeRow(row
, setAsMin
);
9588 height
+= GetRowHeight(row
);
9597 void wxGrid::AutoSize()
9601 wxSize
size(SetOrCalcColumnSizes(FALSE
), SetOrCalcRowSizes(FALSE
));
9603 // round up the size to a multiple of scroll step - this ensures that we
9604 // won't get the scrollbars if we're sized exactly to this width
9605 // CalcDimension adds m_extraWidth + 1 etc. to calculate the necessary
9607 wxSize
sizeFit(GetScrollX(size
.x
+ m_extraWidth
+ 1) * GRID_SCROLL_LINE_X
,
9608 GetScrollY(size
.y
+ m_extraHeight
+ 1) * GRID_SCROLL_LINE_Y
);
9610 // distribute the extra space between the columns/rows to avoid having
9611 // extra white space
9613 // Remove the extra m_extraWidth + 1 added above
9614 wxCoord diff
= sizeFit
.x
- size
.x
+ (m_extraWidth
+ 1);
9615 if ( diff
&& m_numCols
)
9617 // try to resize the columns uniformly
9618 wxCoord diffPerCol
= diff
/ m_numCols
;
9621 for ( int col
= 0; col
< m_numCols
; col
++ )
9623 SetColSize(col
, GetColWidth(col
) + diffPerCol
);
9627 // add remaining amount to the last columns
9628 diff
-= diffPerCol
* m_numCols
;
9631 for ( int col
= m_numCols
- 1; col
>= m_numCols
- diff
; col
-- )
9633 SetColSize(col
, GetColWidth(col
) + 1);
9639 diff
= sizeFit
.y
- size
.y
- (m_extraHeight
+ 1);
9640 if ( diff
&& m_numRows
)
9642 // try to resize the columns uniformly
9643 wxCoord diffPerRow
= diff
/ m_numRows
;
9646 for ( int row
= 0; row
< m_numRows
; row
++ )
9648 SetRowSize(row
, GetRowHeight(row
) + diffPerRow
);
9652 // add remaining amount to the last rows
9653 diff
-= diffPerRow
* m_numRows
;
9656 for ( int row
= m_numRows
- 1; row
>= m_numRows
- diff
; row
-- )
9658 SetRowSize(row
, GetRowHeight(row
) + 1);
9665 SetClientSize(sizeFit
);
9668 void wxGrid::AutoSizeRowLabelSize( int row
)
9670 wxArrayString lines
;
9673 // Hide the edit control, so it
9674 // won't interfer with drag-shrinking.
9675 if( IsCellEditControlShown() )
9677 HideCellEditControl();
9678 SaveEditControlValue();
9681 // autosize row height depending on label text
9682 StringToLines( GetRowLabelValue( row
), lines
);
9683 wxClientDC
dc( m_rowLabelWin
);
9684 GetTextBoxSize( dc
, lines
, &w
, &h
);
9685 if( h
< m_defaultRowHeight
)
9686 h
= m_defaultRowHeight
;
9691 void wxGrid::AutoSizeColLabelSize( int col
)
9693 wxArrayString lines
;
9696 // Hide the edit control, so it
9697 // won't interfer with drag-shrinking.
9698 if( IsCellEditControlShown() )
9700 HideCellEditControl();
9701 SaveEditControlValue();
9704 // autosize column width depending on label text
9705 StringToLines( GetColLabelValue( col
), lines
);
9706 wxClientDC
dc( m_colLabelWin
);
9707 if( GetColLabelTextOrientation() == wxHORIZONTAL
)
9708 GetTextBoxSize( dc
, lines
, &w
, &h
);
9710 GetTextBoxSize( dc
, lines
, &h
, &w
);
9711 if( w
< m_defaultColWidth
)
9712 w
= m_defaultColWidth
;
9717 wxSize
wxGrid::DoGetBestSize() const
9719 // don't set sizes, only calculate them
9720 wxGrid
*self
= (wxGrid
*)this; // const_cast
9723 width
= self
->SetOrCalcColumnSizes(TRUE
);
9724 height
= self
->SetOrCalcRowSizes(TRUE
);
9726 int maxwidth
, maxheight
;
9727 wxDisplaySize( & maxwidth
, & maxheight
);
9729 if ( width
> maxwidth
) width
= maxwidth
;
9730 if ( height
> maxheight
) height
= maxheight
;
9732 return wxSize( width
, height
);
9741 wxPen
& wxGrid::GetDividerPen() const
9746 // ----------------------------------------------------------------------------
9747 // cell value accessor functions
9748 // ----------------------------------------------------------------------------
9750 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
9754 m_table
->SetValue( row
, col
, s
);
9755 if ( !GetBatchCount() )
9758 wxRect
rect( CellToRect( row
, col
) );
9760 rect
.width
= m_gridWin
->GetClientSize().GetWidth();
9761 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
9762 m_gridWin
->Refresh( FALSE
, &rect
);
9765 if ( m_currentCellCoords
.GetRow() == row
&&
9766 m_currentCellCoords
.GetCol() == col
&&
9767 IsCellEditControlShown())
9768 // Note: If we are using IsCellEditControlEnabled,
9769 // this interacts badly with calling SetCellValue from
9770 // an EVT_GRID_CELL_CHANGE handler.
9772 HideCellEditControl();
9773 ShowCellEditControl(); // will reread data from table
9780 // ------ Block, row and col selection
9783 void wxGrid::SelectRow( int row
, bool addToSelected
)
9785 if ( IsSelection() && !addToSelected
)
9789 m_selection
->SelectRow( row
, FALSE
, addToSelected
);
9793 void wxGrid::SelectCol( int col
, bool addToSelected
)
9795 if ( IsSelection() && !addToSelected
)
9799 m_selection
->SelectCol( col
, FALSE
, addToSelected
);
9803 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
9804 bool addToSelected
)
9806 if ( IsSelection() && !addToSelected
)
9810 m_selection
->SelectBlock( topRow
, leftCol
, bottomRow
, rightCol
,
9811 FALSE
, addToSelected
);
9815 void wxGrid::SelectAll()
9817 if ( m_numRows
> 0 && m_numCols
> 0 )
9820 m_selection
->SelectBlock( 0, 0, m_numRows
-1, m_numCols
-1 );
9825 // ------ Cell, row and col deselection
9828 void wxGrid::DeselectRow( int row
)
9833 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectRows
)
9835 if ( m_selection
->IsInSelection(row
, 0 ) )
9836 m_selection
->ToggleCellSelection( row
, 0);
9840 int nCols
= GetNumberCols();
9841 for ( int i
= 0; i
< nCols
; i
++ )
9843 if ( m_selection
->IsInSelection(row
, i
) )
9844 m_selection
->ToggleCellSelection( row
, i
);
9849 void wxGrid::DeselectCol( int col
)
9854 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectColumns
)
9856 if ( m_selection
->IsInSelection(0, col
) )
9857 m_selection
->ToggleCellSelection( 0, col
);
9861 int nRows
= GetNumberRows();
9862 for ( int i
= 0; i
< nRows
; i
++ )
9864 if ( m_selection
->IsInSelection(i
, col
) )
9865 m_selection
->ToggleCellSelection(i
, col
);
9870 void wxGrid::DeselectCell( int row
, int col
)
9872 if ( m_selection
&& m_selection
->IsInSelection(row
, col
) )
9873 m_selection
->ToggleCellSelection(row
, col
);
9876 bool wxGrid::IsSelection()
9878 return ( m_selection
&& (m_selection
->IsSelection() ||
9879 ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
9880 m_selectingBottomRight
!= wxGridNoCellCoords
) ) );
9883 bool wxGrid::IsInSelection( int row
, int col
) const
9885 return ( m_selection
&& (m_selection
->IsInSelection( row
, col
) ||
9886 ( row
>= m_selectingTopLeft
.GetRow() &&
9887 col
>= m_selectingTopLeft
.GetCol() &&
9888 row
<= m_selectingBottomRight
.GetRow() &&
9889 col
<= m_selectingBottomRight
.GetCol() )) );
9892 wxGridCellCoordsArray
wxGrid::GetSelectedCells() const
9894 if (!m_selection
) { wxGridCellCoordsArray a
; return a
; }
9895 return m_selection
->m_cellSelection
;
9897 wxGridCellCoordsArray
wxGrid::GetSelectionBlockTopLeft() const
9899 if (!m_selection
) { wxGridCellCoordsArray a
; return a
; }
9900 return m_selection
->m_blockSelectionTopLeft
;
9902 wxGridCellCoordsArray
wxGrid::GetSelectionBlockBottomRight() const
9904 if (!m_selection
) { wxGridCellCoordsArray a
; return a
; }
9905 return m_selection
->m_blockSelectionBottomRight
;
9907 wxArrayInt
wxGrid::GetSelectedRows() const
9909 if (!m_selection
) { wxArrayInt a
; return a
; }
9910 return m_selection
->m_rowSelection
;
9912 wxArrayInt
wxGrid::GetSelectedCols() const
9914 if (!m_selection
) { wxArrayInt a
; return a
; }
9915 return m_selection
->m_colSelection
;
9919 void wxGrid::ClearSelection()
9921 m_selectingTopLeft
= wxGridNoCellCoords
;
9922 m_selectingBottomRight
= wxGridNoCellCoords
;
9924 m_selection
->ClearSelection();
9928 // This function returns the rectangle that encloses the given block
9929 // in device coords clipped to the client size of the grid window.
9931 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
9932 const wxGridCellCoords
&bottomRight
)
9934 wxRect
rect( wxGridNoCellRect
);
9937 cellRect
= CellToRect( topLeft
);
9938 if ( cellRect
!= wxGridNoCellRect
)
9944 rect
= wxRect( 0, 0, 0, 0 );
9947 cellRect
= CellToRect( bottomRight
);
9948 if ( cellRect
!= wxGridNoCellRect
)
9954 return wxGridNoCellRect
;
9958 int left
= rect
.GetLeft();
9959 int top
= rect
.GetTop();
9960 int right
= rect
.GetRight();
9961 int bottom
= rect
.GetBottom();
9963 int leftCol
= topLeft
.GetCol();
9964 int topRow
= topLeft
.GetRow();
9965 int rightCol
= bottomRight
.GetCol();
9966 int bottomRow
= bottomRight
.GetRow();
9989 for ( j
= topRow
; j
<= bottomRow
; j
++ )
9991 for ( i
= leftCol
; i
<= rightCol
; i
++ )
9993 if ((j
==topRow
) || (j
==bottomRow
) || (i
==leftCol
) || (i
==rightCol
))
9995 cellRect
= CellToRect( j
, i
);
9997 if (cellRect
.x
< left
)
9999 if (cellRect
.y
< top
)
10001 if (cellRect
.x
+ cellRect
.width
> right
)
10002 right
= cellRect
.x
+ cellRect
.width
;
10003 if (cellRect
.y
+ cellRect
.height
> bottom
)
10004 bottom
= cellRect
.y
+ cellRect
.height
;
10006 else i
= rightCol
; // jump over inner cells.
10010 // convert to scrolled coords
10012 CalcScrolledPosition( left
, top
, &left
, &top
);
10013 CalcScrolledPosition( right
, bottom
, &right
, &bottom
);
10016 m_gridWin
->GetClientSize( &cw
, &ch
);
10018 if (right
< 0 || bottom
< 0 || left
> cw
|| top
> ch
)
10019 return wxRect( 0, 0, 0, 0);
10021 rect
.SetLeft( wxMax(0, left
) );
10022 rect
.SetTop( wxMax(0, top
) );
10023 rect
.SetRight( wxMin(cw
, right
) );
10024 rect
.SetBottom( wxMin(ch
, bottom
) );
10030 // ------ Grid event classes
10033 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxNotifyEvent
)
10035 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
10036 int row
, int col
, int x
, int y
, bool sel
,
10037 bool control
, bool shift
, bool alt
, bool meta
)
10038 : wxNotifyEvent( type
, id
)
10045 m_control
= control
;
10050 SetEventObject(obj
);
10054 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxNotifyEvent
)
10056 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
10057 int rowOrCol
, int x
, int y
,
10058 bool control
, bool shift
, bool alt
, bool meta
)
10059 : wxNotifyEvent( type
, id
)
10061 m_rowOrCol
= rowOrCol
;
10064 m_control
= control
;
10069 SetEventObject(obj
);
10073 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxNotifyEvent
)
10075 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
10076 const wxGridCellCoords
& topLeft
,
10077 const wxGridCellCoords
& bottomRight
,
10078 bool sel
, bool control
,
10079 bool shift
, bool alt
, bool meta
)
10080 : wxNotifyEvent( type
, id
)
10082 m_topLeft
= topLeft
;
10083 m_bottomRight
= bottomRight
;
10085 m_control
= control
;
10090 SetEventObject(obj
);
10094 IMPLEMENT_DYNAMIC_CLASS(wxGridEditorCreatedEvent
, wxCommandEvent
)
10096 wxGridEditorCreatedEvent::wxGridEditorCreatedEvent(int id
, wxEventType type
,
10097 wxObject
* obj
, int row
,
10098 int col
, wxControl
* ctrl
)
10099 : wxCommandEvent(type
, id
)
10101 SetEventObject(obj
);
10107 #endif // wxUSE_GRID