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_AUTO_SCROLL
580 // set max length allowed in the textctrl, if the parameter was set
583 ((wxTextCtrl
*)m_control
)->SetMaxLength(m_maxChars
);
586 wxGridCellEditor::Create(parent
, id
, evtHandler
);
589 void wxGridCellTextEditor::PaintBackground(const wxRect
& WXUNUSED(rectCell
),
590 wxGridCellAttr
* WXUNUSED(attr
))
592 // as we fill the entire client area, don't do anything here to minimize
596 void wxGridCellTextEditor::SetSize(const wxRect
& rectOrig
)
598 wxRect
rect(rectOrig
);
600 // Make the edit control large enough to allow for internal
603 // TODO: remove this if the text ctrl sizing is improved esp. for
606 #if defined(__WXGTK__)
615 int extra_x
= ( rect
.x
> 2 )? 2 : 1;
617 // MB: treat MSW separately here otherwise the caret doesn't show
618 // when the editor is in the first row.
619 #if defined(__WXMSW__)
622 int extra_y
= ( rect
.y
> 2 )? 2 : 1;
625 #if defined(__WXMOTIF__)
629 rect
.SetLeft( wxMax(0, rect
.x
- extra_x
) );
630 rect
.SetTop( wxMax(0, rect
.y
- extra_y
) );
631 rect
.SetRight( rect
.GetRight() + 2*extra_x
);
632 rect
.SetBottom( rect
.GetBottom() + 2*extra_y
);
635 wxGridCellEditor::SetSize(rect
);
638 void wxGridCellTextEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
640 wxASSERT_MSG(m_control
,
641 wxT("The wxGridCellEditor must be Created first!"));
643 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
645 DoBeginEdit(m_startValue
);
648 void wxGridCellTextEditor::DoBeginEdit(const wxString
& startValue
)
650 Text()->SetValue(startValue
);
651 Text()->SetInsertionPointEnd();
652 Text()->SetSelection(-1,-1);
656 bool wxGridCellTextEditor::EndEdit(int row
, int col
,
659 wxASSERT_MSG(m_control
,
660 wxT("The wxGridCellEditor must be Created first!"));
662 bool changed
= FALSE
;
663 wxString value
= Text()->GetValue();
664 if (value
!= m_startValue
)
668 grid
->GetTable()->SetValue(row
, col
, value
);
670 m_startValue
= wxEmptyString
;
671 Text()->SetValue(m_startValue
);
677 void wxGridCellTextEditor::Reset()
679 wxASSERT_MSG(m_control
,
680 wxT("The wxGridCellEditor must be Created first!"));
682 DoReset(m_startValue
);
685 void wxGridCellTextEditor::DoReset(const wxString
& startValue
)
687 Text()->SetValue(startValue
);
688 Text()->SetInsertionPointEnd();
691 bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent
& event
)
693 if ( wxGridCellEditor::IsAcceptedKey(event
) )
695 int keycode
= event
.GetKeyCode();
709 case WXK_NUMPAD_MULTIPLY
:
713 case WXK_NUMPAD_SUBTRACT
:
715 case WXK_NUMPAD_DECIMAL
:
717 case WXK_NUMPAD_DIVIDE
:
721 // accept 8 bit chars too if isprint() agrees
722 if ( (keycode
< 255) && (wxIsprint(keycode
)) )
730 void wxGridCellTextEditor::StartingKey(wxKeyEvent
& event
)
732 if ( !Text()->EmulateKeyPress(event
) )
738 void wxGridCellTextEditor::HandleReturn( wxKeyEvent
&
739 WXUNUSED_GTK(WXUNUSED_MOTIF(event
)) )
741 #if defined(__WXMOTIF__) || defined(__WXGTK__)
742 // wxMotif needs a little extra help...
743 size_t pos
= (size_t)( Text()->GetInsertionPoint() );
744 wxString
s( Text()->GetValue() );
745 s
= s
.Left(pos
) + wxT("\n") + s
.Mid(pos
);
747 Text()->SetInsertionPoint( pos
);
749 // the other ports can handle a Return key press
755 void wxGridCellTextEditor::SetParameters(const wxString
& params
)
765 if ( !params
.ToLong(&tmp
) )
767 wxLogDebug(_T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params
.c_str());
771 m_maxChars
= (size_t)tmp
;
776 // return the value in the text control
777 wxString
wxGridCellTextEditor::GetValue() const
779 return Text()->GetValue();
782 // ----------------------------------------------------------------------------
783 // wxGridCellNumberEditor
784 // ----------------------------------------------------------------------------
786 wxGridCellNumberEditor::wxGridCellNumberEditor(int min
, int max
)
792 void wxGridCellNumberEditor::Create(wxWindow
* parent
,
794 wxEvtHandler
* evtHandler
)
798 // create a spin ctrl
799 m_control
= new wxSpinCtrl(parent
, -1, wxEmptyString
,
800 wxDefaultPosition
, wxDefaultSize
,
804 wxGridCellEditor::Create(parent
, id
, evtHandler
);
808 // just a text control
809 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
812 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
813 #endif // wxUSE_VALIDATORS
817 void wxGridCellNumberEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
819 // first get the value
820 wxGridTableBase
*table
= grid
->GetTable();
821 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
823 m_valueOld
= table
->GetValueAsLong(row
, col
);
828 wxString sValue
= table
->GetValue(row
, col
);
829 if (! sValue
.ToLong(&m_valueOld
) && ! sValue
.IsEmpty())
831 wxFAIL_MSG( _T("this cell doesn't have numeric value") );
838 Spin()->SetValue((int)m_valueOld
);
843 DoBeginEdit(GetString());
847 bool wxGridCellNumberEditor::EndEdit(int row
, int col
,
856 value
= Spin()->GetValue();
857 changed
= value
!= m_valueOld
;
859 text
= wxString::Format(wxT("%ld"), value
);
863 text
= Text()->GetValue();
864 changed
= (text
.IsEmpty() || text
.ToLong(&value
)) && (value
!= m_valueOld
);
869 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_NUMBER
))
870 grid
->GetTable()->SetValueAsLong(row
, col
, value
);
872 grid
->GetTable()->SetValue(row
, col
, text
);
878 void wxGridCellNumberEditor::Reset()
882 Spin()->SetValue((int)m_valueOld
);
886 DoReset(GetString());
890 bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent
& event
)
892 if ( wxGridCellEditor::IsAcceptedKey(event
) )
894 int keycode
= event
.GetKeyCode();
910 case WXK_NUMPAD_SUBTRACT
:
916 if ( (keycode
< 128) && wxIsdigit(keycode
) )
924 void wxGridCellNumberEditor::StartingKey(wxKeyEvent
& event
)
928 int keycode
= event
.GetKeyCode();
929 if ( wxIsdigit(keycode
) || keycode
== '+' || keycode
== '-'
930 || keycode
== WXK_NUMPAD0
931 || keycode
== WXK_NUMPAD1
932 || keycode
== WXK_NUMPAD2
933 || keycode
== WXK_NUMPAD3
934 || keycode
== WXK_NUMPAD4
935 || keycode
== WXK_NUMPAD5
936 || keycode
== WXK_NUMPAD6
937 || keycode
== WXK_NUMPAD7
938 || keycode
== WXK_NUMPAD8
939 || keycode
== WXK_NUMPAD9
940 || keycode
== WXK_ADD
941 || keycode
== WXK_NUMPAD_ADD
942 || keycode
== WXK_SUBTRACT
943 || keycode
== WXK_NUMPAD_SUBTRACT
)
945 wxGridCellTextEditor::StartingKey(event
);
955 void wxGridCellNumberEditor::SetParameters(const wxString
& params
)
966 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
970 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
974 // skip the error message below
979 wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string '%s' ignored"), params
.c_str());
983 // return the value in the spin control if it is there (the text control otherwise)
984 wxString
wxGridCellNumberEditor::GetValue() const
990 long value
= Spin()->GetValue();
991 s
.Printf(wxT("%ld"), value
);
995 s
= Text()->GetValue();
1000 // ----------------------------------------------------------------------------
1001 // wxGridCellFloatEditor
1002 // ----------------------------------------------------------------------------
1004 wxGridCellFloatEditor::wxGridCellFloatEditor(int width
, int precision
)
1007 m_precision
= precision
;
1010 void wxGridCellFloatEditor::Create(wxWindow
* parent
,
1012 wxEvtHandler
* evtHandler
)
1014 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
1016 #if wxUSE_VALIDATORS
1017 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
1018 #endif // wxUSE_VALIDATORS
1021 void wxGridCellFloatEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1023 // first get the value
1024 wxGridTableBase
*table
= grid
->GetTable();
1025 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
1027 m_valueOld
= table
->GetValueAsDouble(row
, col
);
1032 wxString sValue
= table
->GetValue(row
, col
);
1033 if (! sValue
.ToDouble(&m_valueOld
) && ! sValue
.IsEmpty())
1035 wxFAIL_MSG( _T("this cell doesn't have float value") );
1040 DoBeginEdit(GetString());
1043 bool wxGridCellFloatEditor::EndEdit(int row
, int col
,
1047 wxString
text(Text()->GetValue());
1049 if ( (text
.IsEmpty() || text
.ToDouble(&value
)) && (value
!= m_valueOld
) )
1051 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_FLOAT
))
1052 grid
->GetTable()->SetValueAsDouble(row
, col
, value
);
1054 grid
->GetTable()->SetValue(row
, col
, text
);
1061 void wxGridCellFloatEditor::Reset()
1063 DoReset(GetString());
1066 void wxGridCellFloatEditor::StartingKey(wxKeyEvent
& event
)
1068 int keycode
= event
.GetKeyCode();
1069 if ( wxIsdigit(keycode
) || keycode
== '+' || keycode
== '-' || keycode
== '.'
1070 || keycode
== WXK_NUMPAD0
1071 || keycode
== WXK_NUMPAD1
1072 || keycode
== WXK_NUMPAD2
1073 || keycode
== WXK_NUMPAD3
1074 || keycode
== WXK_NUMPAD4
1075 || keycode
== WXK_NUMPAD5
1076 || keycode
== WXK_NUMPAD6
1077 || keycode
== WXK_NUMPAD7
1078 || keycode
== WXK_NUMPAD8
1079 || keycode
== WXK_NUMPAD9
1080 || keycode
== WXK_ADD
1081 || keycode
== WXK_NUMPAD_ADD
1082 || keycode
== WXK_SUBTRACT
1083 || keycode
== WXK_NUMPAD_SUBTRACT
)
1085 wxGridCellTextEditor::StartingKey(event
);
1087 // skip Skip() below
1094 void wxGridCellFloatEditor::SetParameters(const wxString
& params
)
1105 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
1109 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
1111 m_precision
= (int)tmp
;
1113 // skip the error message below
1118 wxLogDebug(_T("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params
.c_str());
1122 wxString
wxGridCellFloatEditor::GetString() const
1125 if ( m_width
== -1 )
1127 // default width/precision
1130 else if ( m_precision
== -1 )
1132 // default precision
1133 fmt
.Printf(_T("%%%d.f"), m_width
);
1137 fmt
.Printf(_T("%%%d.%df"), m_width
, m_precision
);
1140 return wxString::Format(fmt
, m_valueOld
);
1143 bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent
& event
)
1145 if ( wxGridCellEditor::IsAcceptedKey(event
) )
1147 int keycode
= event
.GetKeyCode();
1161 case WXK_NUMPAD_ADD
:
1163 case WXK_NUMPAD_SUBTRACT
:
1165 case WXK_NUMPAD_DECIMAL
:
1169 // additionally accept 'e' as in '1e+6'
1170 if ( (keycode
< 128) &&
1171 (wxIsdigit(keycode
) || tolower(keycode
) == 'e') )
1179 #endif // wxUSE_TEXTCTRL
1183 // ----------------------------------------------------------------------------
1184 // wxGridCellBoolEditor
1185 // ----------------------------------------------------------------------------
1187 void wxGridCellBoolEditor::Create(wxWindow
* parent
,
1189 wxEvtHandler
* evtHandler
)
1191 m_control
= new wxCheckBox(parent
, id
, wxEmptyString
,
1192 wxDefaultPosition
, wxDefaultSize
,
1195 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1198 void wxGridCellBoolEditor::SetSize(const wxRect
& r
)
1200 bool resize
= FALSE
;
1201 wxSize size
= m_control
->GetSize();
1202 wxCoord minSize
= wxMin(r
.width
, r
.height
);
1204 // check if the checkbox is not too big/small for this cell
1205 wxSize sizeBest
= m_control
->GetBestSize();
1206 if ( !(size
== sizeBest
) )
1208 // reset to default size if it had been made smaller
1214 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
1216 // leave 1 pixel margin
1217 size
.x
= size
.y
= minSize
- 2;
1224 m_control
->SetSize(size
);
1227 // position it in the centre of the rectangle (TODO: support alignment?)
1229 #if defined(__WXGTK__) || defined (__WXMOTIF__)
1230 // the checkbox without label still has some space to the right in wxGTK,
1231 // so shift it to the right
1233 #elif defined(__WXMSW__)
1234 // here too, but in other way
1239 int hAlign
= wxALIGN_CENTRE
;
1240 int vAlign
= wxALIGN_CENTRE
;
1242 GetCellAttr()->GetAlignment(& hAlign
, & vAlign
);
1245 if (hAlign
== wxALIGN_LEFT
)
1251 y
= r
.y
+ r
.height
/2 - size
.y
/2;
1253 else if (hAlign
== wxALIGN_RIGHT
)
1255 x
= r
.x
+ r
.width
- size
.x
- 2;
1256 y
= r
.y
+ r
.height
/2 - size
.y
/2;
1258 else if (hAlign
== wxALIGN_CENTRE
)
1260 x
= r
.x
+ r
.width
/2 - size
.x
/2;
1261 y
= r
.y
+ r
.height
/2 - size
.y
/2;
1264 m_control
->Move(x
, y
);
1267 void wxGridCellBoolEditor::Show(bool show
, wxGridCellAttr
*attr
)
1269 m_control
->Show(show
);
1273 wxColour colBg
= attr
? attr
->GetBackgroundColour() : *wxLIGHT_GREY
;
1274 CBox()->SetBackgroundColour(colBg
);
1278 void wxGridCellBoolEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1280 wxASSERT_MSG(m_control
,
1281 wxT("The wxGridCellEditor must be Created first!"));
1283 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
1284 m_startValue
= grid
->GetTable()->GetValueAsBool(row
, col
);
1287 wxString
cellval( grid
->GetTable()->GetValue(row
, col
) );
1288 m_startValue
= !( !cellval
|| (cellval
== wxT("0")) );
1290 CBox()->SetValue(m_startValue
);
1294 bool wxGridCellBoolEditor::EndEdit(int row
, int col
,
1297 wxASSERT_MSG(m_control
,
1298 wxT("The wxGridCellEditor must be Created first!"));
1300 bool changed
= FALSE
;
1301 bool value
= CBox()->GetValue();
1302 if ( value
!= m_startValue
)
1307 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
1308 grid
->GetTable()->SetValueAsBool(row
, col
, value
);
1310 grid
->GetTable()->SetValue(row
, col
, value
? _T("1") : wxEmptyString
);
1316 void wxGridCellBoolEditor::Reset()
1318 wxASSERT_MSG(m_control
,
1319 wxT("The wxGridCellEditor must be Created first!"));
1321 CBox()->SetValue(m_startValue
);
1324 void wxGridCellBoolEditor::StartingClick()
1326 CBox()->SetValue(!CBox()->GetValue());
1329 bool wxGridCellBoolEditor::IsAcceptedKey(wxKeyEvent
& event
)
1331 if ( wxGridCellEditor::IsAcceptedKey(event
) )
1333 int keycode
= event
.GetKeyCode();
1337 case WXK_NUMPAD_MULTIPLY
:
1339 case WXK_NUMPAD_ADD
:
1341 case WXK_NUMPAD_SUBTRACT
:
1352 // return the value as "1" for true and the empty string for false
1353 wxString
wxGridCellBoolEditor::GetValue() const
1355 bool bSet
= CBox()->GetValue();
1356 return bSet
? _T("1") : wxEmptyString
;
1359 #endif // wxUSE_CHECKBOX
1363 // ----------------------------------------------------------------------------
1364 // wxGridCellChoiceEditor
1365 // ----------------------------------------------------------------------------
1367 wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count
,
1368 const wxString choices
[],
1370 : m_allowOthers(allowOthers
)
1374 m_choices
.Alloc(count
);
1375 for ( size_t n
= 0; n
< count
; n
++ )
1377 m_choices
.Add(choices
[n
]);
1382 wxGridCellEditor
*wxGridCellChoiceEditor::Clone() const
1384 wxGridCellChoiceEditor
*editor
= new wxGridCellChoiceEditor
;
1385 editor
->m_allowOthers
= m_allowOthers
;
1386 editor
->m_choices
= m_choices
;
1391 void wxGridCellChoiceEditor::Create(wxWindow
* parent
,
1393 wxEvtHandler
* evtHandler
)
1395 size_t count
= m_choices
.GetCount();
1396 wxString
*choices
= new wxString
[count
];
1397 for ( size_t n
= 0; n
< count
; n
++ )
1399 choices
[n
] = m_choices
[n
];
1402 m_control
= new wxComboBox(parent
, id
, wxEmptyString
,
1403 wxDefaultPosition
, wxDefaultSize
,
1405 m_allowOthers
? 0 : wxCB_READONLY
);
1409 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1412 void wxGridCellChoiceEditor::PaintBackground(const wxRect
& rectCell
,
1413 wxGridCellAttr
* attr
)
1415 // as we fill the entire client area, don't do anything here to minimize
1418 // TODO: It doesn't actually fill the client area since the height of a
1419 // combo always defaults to the standard... Until someone has time to
1420 // figure out the right rectangle to paint, just do it the normal way...
1421 wxGridCellEditor::PaintBackground(rectCell
, attr
);
1424 void wxGridCellChoiceEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1426 wxASSERT_MSG(m_control
,
1427 wxT("The wxGridCellEditor must be Created first!"));
1429 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
1432 Combo()->SetValue(m_startValue
);
1435 // find the right position, or default to the first if not found
1436 int pos
= Combo()->FindString(m_startValue
);
1439 Combo()->SetSelection(pos
);
1441 Combo()->SetInsertionPointEnd();
1442 Combo()->SetFocus();
1445 bool wxGridCellChoiceEditor::EndEdit(int row
, int col
,
1448 wxString value
= Combo()->GetValue();
1449 bool changed
= value
!= m_startValue
;
1452 grid
->GetTable()->SetValue(row
, col
, value
);
1454 m_startValue
= wxEmptyString
;
1456 Combo()->SetValue(m_startValue
);
1458 Combo()->SetSelection(0);
1463 void wxGridCellChoiceEditor::Reset()
1465 Combo()->SetValue(m_startValue
);
1466 Combo()->SetInsertionPointEnd();
1469 void wxGridCellChoiceEditor::SetParameters(const wxString
& params
)
1479 wxStringTokenizer
tk(params
, _T(','));
1480 while ( tk
.HasMoreTokens() )
1482 m_choices
.Add(tk
.GetNextToken());
1486 // return the value in the text control
1487 wxString
wxGridCellChoiceEditor::GetValue() const
1489 return Combo()->GetValue();
1492 #endif // wxUSE_COMBOBOX
1494 // ----------------------------------------------------------------------------
1495 // wxGridCellEditorEvtHandler
1496 // ----------------------------------------------------------------------------
1498 void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent
& event
)
1500 switch ( event
.GetKeyCode() )
1504 m_grid
->DisableCellEditControl();
1508 m_grid
->GetEventHandler()->ProcessEvent( event
);
1512 case WXK_NUMPAD_ENTER
:
1513 if (!m_grid
->GetEventHandler()->ProcessEvent(event
))
1514 m_editor
->HandleReturn(event
);
1523 void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent
& event
)
1525 switch ( event
.GetKeyCode() )
1530 case WXK_NUMPAD_ENTER
:
1538 // ----------------------------------------------------------------------------
1539 // wxGridCellWorker is an (almost) empty common base class for
1540 // wxGridCellRenderer and wxGridCellEditor managing ref counting
1541 // ----------------------------------------------------------------------------
1543 void wxGridCellWorker::SetParameters(const wxString
& WXUNUSED(params
))
1548 wxGridCellWorker::~wxGridCellWorker()
1552 // ============================================================================
1554 // ============================================================================
1556 // ----------------------------------------------------------------------------
1557 // wxGridCellRenderer
1558 // ----------------------------------------------------------------------------
1560 void wxGridCellRenderer::Draw(wxGrid
& grid
,
1561 wxGridCellAttr
& attr
,
1564 int WXUNUSED(row
), int WXUNUSED(col
),
1567 dc
.SetBackgroundMode( wxSOLID
);
1569 // grey out fields if the grid is disabled
1570 if( grid
.IsEnabled() )
1574 dc
.SetBrush( wxBrush(grid
.GetSelectionBackground(), wxSOLID
) );
1578 dc
.SetBrush( wxBrush(attr
.GetBackgroundColour(), wxSOLID
) );
1583 dc
.SetBrush(wxBrush(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE
), wxSOLID
));
1586 dc
.SetPen( *wxTRANSPARENT_PEN
);
1587 dc
.DrawRectangle(rect
);
1590 // ----------------------------------------------------------------------------
1591 // wxGridCellStringRenderer
1592 // ----------------------------------------------------------------------------
1594 void wxGridCellStringRenderer::SetTextColoursAndFont(wxGrid
& grid
,
1595 wxGridCellAttr
& attr
,
1599 dc
.SetBackgroundMode( wxTRANSPARENT
);
1601 // TODO some special colours for attr.IsReadOnly() case?
1603 // different coloured text when the grid is disabled
1604 if( grid
.IsEnabled() )
1608 dc
.SetTextBackground( grid
.GetSelectionBackground() );
1609 dc
.SetTextForeground( grid
.GetSelectionForeground() );
1613 dc
.SetTextBackground( attr
.GetBackgroundColour() );
1614 dc
.SetTextForeground( attr
.GetTextColour() );
1619 dc
.SetTextBackground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE
));
1620 dc
.SetTextForeground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_GRAYTEXT
));
1623 dc
.SetFont( attr
.GetFont() );
1626 wxSize
wxGridCellStringRenderer::DoGetBestSize(wxGridCellAttr
& attr
,
1628 const wxString
& text
)
1630 wxCoord x
= 0, y
= 0, max_x
= 0;
1631 dc
.SetFont(attr
.GetFont());
1632 wxStringTokenizer
tk(text
, _T('\n'));
1633 while ( tk
.HasMoreTokens() )
1635 dc
.GetTextExtent(tk
.GetNextToken(), &x
, &y
);
1636 max_x
= wxMax(max_x
, x
);
1639 y
*= 1 + text
.Freq(wxT('\n')); // multiply by the number of lines.
1641 return wxSize(max_x
, y
);
1644 wxSize
wxGridCellStringRenderer::GetBestSize(wxGrid
& grid
,
1645 wxGridCellAttr
& attr
,
1649 return DoGetBestSize(attr
, dc
, grid
.GetCellValue(row
, col
));
1652 void wxGridCellStringRenderer::Draw(wxGrid
& grid
,
1653 wxGridCellAttr
& attr
,
1655 const wxRect
& rectCell
,
1659 wxRect rect
= rectCell
;
1662 // erase only this cells background, overflow cells should have been erased
1663 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1666 attr
.GetAlignment(&hAlign
, &vAlign
);
1668 int overflowCols
= 0;
1670 if (attr
.GetOverflow())
1672 int cols
= grid
.GetNumberCols();
1673 int best_width
= GetBestSize(grid
,attr
,dc
,row
,col
).GetWidth();
1674 int cell_rows
, cell_cols
;
1675 attr
.GetSize( &cell_rows
, &cell_cols
); // shouldn't get here if <=0
1676 if ((best_width
> rectCell
.width
) && (col
< cols
) && grid
.GetTable())
1678 int i
, c_cols
, c_rows
;
1679 for (i
= col
+cell_cols
; i
< cols
; i
++)
1681 bool is_empty
= TRUE
;
1682 for (int j
=row
; j
<row
+cell_rows
; j
++)
1684 // check w/ anchor cell for multicell block
1685 grid
.GetCellSize(j
, i
, &c_rows
, &c_cols
);
1686 if (c_rows
> 0) c_rows
= 0;
1687 if (!grid
.GetTable()->IsEmptyCell(j
+c_rows
, i
))
1694 rect
.width
+= grid
.GetColSize(i
);
1700 if (rect
.width
>= best_width
) break;
1702 overflowCols
= i
- col
- cell_cols
+ 1;
1703 if (overflowCols
>= cols
) overflowCols
= cols
- 1;
1706 if (overflowCols
> 0) // redraw overflow cells w/ proper hilight
1708 hAlign
= wxALIGN_LEFT
; // if oveflowed then it's left aligned
1710 clip
.x
+= rectCell
.width
;
1711 // draw each overflow cell individually
1712 int col_end
= col
+cell_cols
+overflowCols
;
1713 if (col_end
>= grid
.GetNumberCols())
1714 col_end
= grid
.GetNumberCols() - 1;
1715 for (int i
= col
+cell_cols
; i
<= col_end
; i
++)
1717 clip
.width
= grid
.GetColSize(i
) - 1;
1718 dc
.DestroyClippingRegion();
1719 dc
.SetClippingRegion(clip
);
1721 SetTextColoursAndFont(grid
, attr
, dc
,
1722 grid
.IsInSelection(row
,i
));
1724 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
1725 rect
, hAlign
, vAlign
);
1726 clip
.x
+= grid
.GetColSize(i
) - 1;
1732 dc
.DestroyClippingRegion();
1736 // now we only have to draw the text
1737 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1739 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
1740 rect
, hAlign
, vAlign
);
1743 // ----------------------------------------------------------------------------
1744 // wxGridCellNumberRenderer
1745 // ----------------------------------------------------------------------------
1747 wxString
wxGridCellNumberRenderer::GetString(wxGrid
& grid
, int row
, int col
)
1749 wxGridTableBase
*table
= grid
.GetTable();
1751 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
1753 text
.Printf(_T("%ld"), table
->GetValueAsLong(row
, col
));
1757 text
= table
->GetValue(row
, col
);
1763 void wxGridCellNumberRenderer::Draw(wxGrid
& grid
,
1764 wxGridCellAttr
& attr
,
1766 const wxRect
& rectCell
,
1770 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1772 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1774 // draw the text right aligned by default
1776 attr
.GetAlignment(&hAlign
, &vAlign
);
1777 hAlign
= wxALIGN_RIGHT
;
1779 wxRect rect
= rectCell
;
1782 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1785 wxSize
wxGridCellNumberRenderer::GetBestSize(wxGrid
& grid
,
1786 wxGridCellAttr
& attr
,
1790 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1793 // ----------------------------------------------------------------------------
1794 // wxGridCellFloatRenderer
1795 // ----------------------------------------------------------------------------
1797 wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width
, int precision
)
1800 SetPrecision(precision
);
1803 wxGridCellRenderer
*wxGridCellFloatRenderer::Clone() const
1805 wxGridCellFloatRenderer
*renderer
= new wxGridCellFloatRenderer
;
1806 renderer
->m_width
= m_width
;
1807 renderer
->m_precision
= m_precision
;
1808 renderer
->m_format
= m_format
;
1813 wxString
wxGridCellFloatRenderer::GetString(wxGrid
& grid
, int row
, int col
)
1815 wxGridTableBase
*table
= grid
.GetTable();
1820 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
1822 val
= table
->GetValueAsDouble(row
, col
);
1827 text
= table
->GetValue(row
, col
);
1828 hasDouble
= text
.ToDouble(&val
);
1835 if ( m_width
== -1 )
1837 if ( m_precision
== -1 )
1839 // default width/precision
1840 m_format
= _T("%f");
1844 m_format
.Printf(_T("%%.%df"), m_precision
);
1847 else if ( m_precision
== -1 )
1849 // default precision
1850 m_format
.Printf(_T("%%%d.f"), m_width
);
1854 m_format
.Printf(_T("%%%d.%df"), m_width
, m_precision
);
1858 text
.Printf(m_format
, val
);
1861 //else: text already contains the string
1866 void wxGridCellFloatRenderer::Draw(wxGrid
& grid
,
1867 wxGridCellAttr
& attr
,
1869 const wxRect
& rectCell
,
1873 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1875 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1877 // draw the text right aligned by default
1879 attr
.GetAlignment(&hAlign
, &vAlign
);
1880 hAlign
= wxALIGN_RIGHT
;
1882 wxRect rect
= rectCell
;
1885 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1888 wxSize
wxGridCellFloatRenderer::GetBestSize(wxGrid
& grid
,
1889 wxGridCellAttr
& attr
,
1893 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1896 void wxGridCellFloatRenderer::SetParameters(const wxString
& params
)
1900 // reset to defaults
1906 wxString tmp
= params
.BeforeFirst(_T(','));
1910 if ( tmp
.ToLong(&width
) )
1912 SetWidth((int)width
);
1916 wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params
.c_str());
1920 tmp
= params
.AfterFirst(_T(','));
1924 if ( tmp
.ToLong(&precision
) )
1926 SetPrecision((int)precision
);
1930 wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params
.c_str());
1938 // ----------------------------------------------------------------------------
1939 // wxGridCellBoolRenderer
1940 // ----------------------------------------------------------------------------
1942 wxSize
wxGridCellBoolRenderer::ms_sizeCheckMark
;
1944 // FIXME these checkbox size calculations are really ugly...
1946 // between checkmark and box
1947 static const wxCoord wxGRID_CHECKMARK_MARGIN
= 2;
1949 wxSize
wxGridCellBoolRenderer::GetBestSize(wxGrid
& grid
,
1950 wxGridCellAttr
& WXUNUSED(attr
),
1955 // compute it only once (no locks for MT safeness in GUI thread...)
1956 if ( !ms_sizeCheckMark
.x
)
1958 // get checkbox size
1959 wxCoord checkSize
= 0;
1960 wxCheckBox
*checkbox
= new wxCheckBox(&grid
, -1, wxEmptyString
);
1961 wxSize size
= checkbox
->GetBestSize();
1962 checkSize
= size
.y
+ 2*wxGRID_CHECKMARK_MARGIN
;
1964 // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result
1965 #if defined(__WXGTK__) || defined(__WXMOTIF__)
1966 checkSize
-= size
.y
/ 2;
1971 ms_sizeCheckMark
.x
= ms_sizeCheckMark
.y
= checkSize
;
1974 return ms_sizeCheckMark
;
1977 void wxGridCellBoolRenderer::Draw(wxGrid
& grid
,
1978 wxGridCellAttr
& attr
,
1984 wxGridCellRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
1986 // draw a check mark in the centre (ignoring alignment - TODO)
1987 wxSize size
= GetBestSize(grid
, attr
, dc
, row
, col
);
1989 // don't draw outside the cell
1990 wxCoord minSize
= wxMin(rect
.width
, rect
.height
);
1991 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
1993 // and even leave (at least) 1 pixel margin
1994 size
.x
= size
.y
= minSize
- 2;
1997 // draw a border around checkmark
1999 attr
.GetAlignment(& hAlign
, &vAlign
);
2002 if (hAlign
== wxALIGN_CENTRE
)
2004 rectBorder
.x
= rect
.x
+ rect
.width
/2 - size
.x
/2;
2005 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
2006 rectBorder
.width
= size
.x
;
2007 rectBorder
.height
= size
.y
;
2009 else if (hAlign
== wxALIGN_LEFT
)
2011 rectBorder
.x
= rect
.x
+ 2;
2012 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
2013 rectBorder
.width
= size
.x
;
2014 rectBorder
.height
= size
.y
;
2016 else if (hAlign
== wxALIGN_RIGHT
)
2018 rectBorder
.x
= rect
.x
+ rect
.width
- size
.x
- 2;
2019 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
2020 rectBorder
.width
= size
.x
;
2021 rectBorder
.height
= size
.y
;
2025 if ( grid
.GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
) )
2026 value
= grid
.GetTable()->GetValueAsBool(row
, col
);
2029 wxString
cellval( grid
.GetTable()->GetValue(row
, col
) );
2030 value
= !( !cellval
|| (cellval
== wxT("0")) );
2035 wxRect rectMark
= rectBorder
;
2037 // MSW DrawCheckMark() is weird (and should probably be changed...)
2038 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
/2);
2042 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
);
2045 dc
.SetTextForeground(attr
.GetTextColour());
2046 dc
.DrawCheckMark(rectMark
);
2049 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2050 dc
.SetPen(wxPen(attr
.GetTextColour(), 1, wxSOLID
));
2051 dc
.DrawRectangle(rectBorder
);
2054 // ----------------------------------------------------------------------------
2056 // ----------------------------------------------------------------------------
2058 void wxGridCellAttr::Init(wxGridCellAttr
*attrDefault
)
2062 m_isReadOnly
= Unset
;
2067 m_attrkind
= wxGridCellAttr::Cell
;
2069 m_sizeRows
= m_sizeCols
= 1;
2070 m_overflow
= UnsetOverflow
;
2072 SetDefAttr(attrDefault
);
2075 wxGridCellAttr
*wxGridCellAttr::Clone() const
2077 wxGridCellAttr
*attr
= new wxGridCellAttr(m_defGridAttr
);
2079 if ( HasTextColour() )
2080 attr
->SetTextColour(GetTextColour());
2081 if ( HasBackgroundColour() )
2082 attr
->SetBackgroundColour(GetBackgroundColour());
2084 attr
->SetFont(GetFont());
2085 if ( HasAlignment() )
2086 attr
->SetAlignment(m_hAlign
, m_vAlign
);
2088 attr
->SetSize( m_sizeRows
, m_sizeCols
);
2092 attr
->SetRenderer(m_renderer
);
2093 m_renderer
->IncRef();
2097 attr
->SetEditor(m_editor
);
2102 attr
->SetReadOnly();
2104 attr
->SetKind( m_attrkind
);
2109 void wxGridCellAttr::MergeWith(wxGridCellAttr
*mergefrom
)
2111 if ( !HasTextColour() && mergefrom
->HasTextColour() )
2112 SetTextColour(mergefrom
->GetTextColour());
2113 if ( !HasBackgroundColour() && mergefrom
->HasBackgroundColour() )
2114 SetBackgroundColour(mergefrom
->GetBackgroundColour());
2115 if ( !HasFont() && mergefrom
->HasFont() )
2116 SetFont(mergefrom
->GetFont());
2117 if ( !HasAlignment() && mergefrom
->HasAlignment() ){
2119 mergefrom
->GetAlignment( &hAlign
, &vAlign
);
2120 SetAlignment(hAlign
, vAlign
);
2123 mergefrom
->GetSize( &m_sizeRows
, &m_sizeCols
);
2125 // Directly access member functions as GetRender/Editor don't just return
2126 // m_renderer/m_editor
2128 // Maybe add support for merge of Render and Editor?
2129 if (!HasRenderer() && mergefrom
->HasRenderer() )
2131 m_renderer
= mergefrom
->m_renderer
;
2132 m_renderer
->IncRef();
2134 if ( !HasEditor() && mergefrom
->HasEditor() )
2136 m_editor
= mergefrom
->m_editor
;
2139 if ( !HasReadWriteMode() && mergefrom
->HasReadWriteMode() )
2140 SetReadOnly(mergefrom
->IsReadOnly());
2142 if (!HasOverflowMode() && mergefrom
->HasOverflowMode() )
2143 SetOverflow(mergefrom
->GetOverflow());
2145 SetDefAttr(mergefrom
->m_defGridAttr
);
2148 void wxGridCellAttr::SetSize(int num_rows
, int num_cols
)
2150 // The size of a cell is normally 1,1
2152 // If this cell is larger (2,2) then this is the top left cell
2153 // the other cells that will be covered (lower right cells) must be
2154 // set to negative or zero values such that
2155 // row + num_rows of the covered cell points to the larger cell (this cell)
2156 // same goes for the col + num_cols.
2158 // Size of 0,0 is NOT valid, neither is <=0 and any positive value
2160 wxASSERT_MSG( (!((num_rows
>0)&&(num_cols
<=0)) ||
2161 !((num_rows
<=0)&&(num_cols
>0)) ||
2162 !((num_rows
==0)&&(num_cols
==0))),
2163 wxT("wxGridCellAttr::SetSize only takes two postive values or negative/zero values"));
2165 m_sizeRows
= num_rows
;
2166 m_sizeCols
= num_cols
;
2169 const wxColour
& wxGridCellAttr::GetTextColour() const
2171 if (HasTextColour())
2175 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2177 return m_defGridAttr
->GetTextColour();
2181 wxFAIL_MSG(wxT("Missing default cell attribute"));
2182 return wxNullColour
;
2187 const wxColour
& wxGridCellAttr::GetBackgroundColour() const
2189 if (HasBackgroundColour())
2191 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2192 return m_defGridAttr
->GetBackgroundColour();
2195 wxFAIL_MSG(wxT("Missing default cell attribute"));
2196 return wxNullColour
;
2201 const wxFont
& wxGridCellAttr::GetFont() const
2205 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2206 return m_defGridAttr
->GetFont();
2209 wxFAIL_MSG(wxT("Missing default cell attribute"));
2215 void wxGridCellAttr::GetAlignment(int *hAlign
, int *vAlign
) const
2219 if ( hAlign
) *hAlign
= m_hAlign
;
2220 if ( vAlign
) *vAlign
= m_vAlign
;
2222 else if (m_defGridAttr
&& m_defGridAttr
!= this)
2223 m_defGridAttr
->GetAlignment(hAlign
, vAlign
);
2226 wxFAIL_MSG(wxT("Missing default cell attribute"));
2230 void wxGridCellAttr::GetSize( int *num_rows
, int *num_cols
) const
2232 if ( num_rows
) *num_rows
= m_sizeRows
;
2233 if ( num_cols
) *num_cols
= m_sizeCols
;
2236 // GetRenderer and GetEditor use a slightly different decision path about
2237 // which attribute to use. If a non-default attr object has one then it is
2238 // used, otherwise the default editor or renderer is fetched from the grid and
2239 // used. It should be the default for the data type of the cell. If it is
2240 // NULL (because the table has a type that the grid does not have in its
2241 // registry,) then the grid's default editor or renderer is used.
2243 wxGridCellRenderer
* wxGridCellAttr::GetRenderer(wxGrid
* grid
, int row
, int col
) const
2245 wxGridCellRenderer
*renderer
;
2247 if ( m_renderer
&& this != m_defGridAttr
)
2249 // use the cells renderer if it has one
2250 renderer
= m_renderer
;
2253 else // no non default cell renderer
2255 // get default renderer for the data type
2258 // GetDefaultRendererForCell() will do IncRef() for us
2259 renderer
= grid
->GetDefaultRendererForCell(row
, col
);
2268 if (m_defGridAttr
&& this != m_defGridAttr
)
2270 // if we still don't have one then use the grid default
2271 // (no need for IncRef() here neither)
2272 renderer
= m_defGridAttr
->GetRenderer(NULL
, 0, 0);
2274 else // default grid attr
2276 // use m_renderer which we had decided not to use initially
2277 renderer
= m_renderer
;
2284 // we're supposed to always find something
2285 wxASSERT_MSG(renderer
, wxT("Missing default cell renderer"));
2290 // same as above, except for s/renderer/editor/g
2291 wxGridCellEditor
* wxGridCellAttr::GetEditor(wxGrid
* grid
, int row
, int col
) const
2293 wxGridCellEditor
*editor
;
2295 if ( m_editor
&& this != m_defGridAttr
)
2297 // use the cells editor if it has one
2301 else // no non default cell editor
2303 // get default editor for the data type
2306 // GetDefaultEditorForCell() will do IncRef() for us
2307 editor
= grid
->GetDefaultEditorForCell(row
, col
);
2316 if ( m_defGridAttr
&& this != m_defGridAttr
)
2318 // if we still don't have one then use the grid default
2319 // (no need for IncRef() here neither)
2320 editor
= m_defGridAttr
->GetEditor(NULL
, 0, 0);
2322 else // default grid attr
2324 // use m_editor which we had decided not to use initially
2332 // we're supposed to always find something
2333 wxASSERT_MSG(editor
, wxT("Missing default cell editor"));
2338 // ----------------------------------------------------------------------------
2339 // wxGridCellAttrData
2340 // ----------------------------------------------------------------------------
2342 void wxGridCellAttrData::SetAttr(wxGridCellAttr
*attr
, int row
, int col
)
2344 int n
= FindIndex(row
, col
);
2345 if ( n
== wxNOT_FOUND
)
2347 // add the attribute
2348 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
2352 // free the old attribute
2353 m_attrs
[(size_t)n
].attr
->DecRef();
2357 // change the attribute
2358 m_attrs
[(size_t)n
].attr
= attr
;
2362 // remove this attribute
2363 m_attrs
.RemoveAt((size_t)n
);
2368 wxGridCellAttr
*wxGridCellAttrData::GetAttr(int row
, int col
) const
2370 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2372 int n
= FindIndex(row
, col
);
2373 if ( n
!= wxNOT_FOUND
)
2375 attr
= m_attrs
[(size_t)n
].attr
;
2382 void wxGridCellAttrData::UpdateAttrRows( size_t pos
, int numRows
)
2384 size_t count
= m_attrs
.GetCount();
2385 for ( size_t n
= 0; n
< count
; n
++ )
2387 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2388 wxCoord row
= coords
.GetRow();
2389 if ((size_t)row
>= pos
)
2393 // If rows inserted, include row counter where necessary
2394 coords
.SetRow(row
+ numRows
);
2396 else if (numRows
< 0)
2398 // If rows deleted ...
2399 if ((size_t)row
>= pos
- numRows
)
2401 // ...either decrement row counter (if row still exists)...
2402 coords
.SetRow(row
+ numRows
);
2406 // ...or remove the attribute
2407 m_attrs
.RemoveAt((size_t)n
);
2415 void wxGridCellAttrData::UpdateAttrCols( size_t pos
, int numCols
)
2417 size_t count
= m_attrs
.GetCount();
2418 for ( size_t n
= 0; n
< count
; n
++ )
2420 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2421 wxCoord col
= coords
.GetCol();
2422 if ( (size_t)col
>= pos
)
2426 // If rows inserted, include row counter where necessary
2427 coords
.SetCol(col
+ numCols
);
2429 else if (numCols
< 0)
2431 // If rows deleted ...
2432 if ((size_t)col
>= pos
- numCols
)
2434 // ...either decrement row counter (if row still exists)...
2435 coords
.SetCol(col
+ numCols
);
2439 // ...or remove the attribute
2440 m_attrs
.RemoveAt((size_t)n
);
2448 int wxGridCellAttrData::FindIndex(int row
, int col
) const
2450 size_t count
= m_attrs
.GetCount();
2451 for ( size_t n
= 0; n
< count
; n
++ )
2453 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
2454 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
2463 // ----------------------------------------------------------------------------
2464 // wxGridRowOrColAttrData
2465 // ----------------------------------------------------------------------------
2467 wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
2469 size_t count
= m_attrs
.Count();
2470 for ( size_t n
= 0; n
< count
; n
++ )
2472 m_attrs
[n
]->DecRef();
2476 wxGridCellAttr
*wxGridRowOrColAttrData::GetAttr(int rowOrCol
) const
2478 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2480 int n
= m_rowsOrCols
.Index(rowOrCol
);
2481 if ( n
!= wxNOT_FOUND
)
2483 attr
= m_attrs
[(size_t)n
];
2490 void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr
*attr
, int rowOrCol
)
2492 int i
= m_rowsOrCols
.Index(rowOrCol
);
2493 if ( i
== wxNOT_FOUND
)
2495 // add the attribute
2496 m_rowsOrCols
.Add(rowOrCol
);
2501 size_t n
= (size_t)i
;
2504 // change the attribute
2505 m_attrs
[n
]->DecRef();
2510 // remove this attribute
2511 m_attrs
[n
]->DecRef();
2512 m_rowsOrCols
.RemoveAt(n
);
2513 m_attrs
.RemoveAt(n
);
2518 void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
)
2520 size_t count
= m_attrs
.GetCount();
2521 for ( size_t n
= 0; n
< count
; n
++ )
2523 int & rowOrCol
= m_rowsOrCols
[n
];
2524 if ( (size_t)rowOrCol
>= pos
)
2526 if ( numRowsOrCols
> 0 )
2528 // If rows inserted, include row counter where necessary
2529 rowOrCol
+= numRowsOrCols
;
2531 else if ( numRowsOrCols
< 0)
2533 // If rows deleted, either decrement row counter (if row still exists)
2534 if ((size_t)rowOrCol
>= pos
- numRowsOrCols
)
2535 rowOrCol
+= numRowsOrCols
;
2538 m_rowsOrCols
.RemoveAt((size_t)n
);
2539 m_attrs
.RemoveAt((size_t)n
);
2547 // ----------------------------------------------------------------------------
2548 // wxGridCellAttrProvider
2549 // ----------------------------------------------------------------------------
2551 wxGridCellAttrProvider::wxGridCellAttrProvider()
2553 m_data
= (wxGridCellAttrProviderData
*)NULL
;
2556 wxGridCellAttrProvider::~wxGridCellAttrProvider()
2561 void wxGridCellAttrProvider::InitData()
2563 m_data
= new wxGridCellAttrProviderData
;
2566 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
,
2567 wxGridCellAttr::wxAttrKind kind
) const
2569 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
2574 case (wxGridCellAttr::Any
):
2575 //Get cached merge attributes.
2576 // Currenlty not used as no cache implemented as not mutiable
2577 // attr = m_data->m_mergeAttr.GetAttr(row, col);
2580 //Basicaly implement old version.
2581 //Also check merge cache, so we don't have to re-merge every time..
2582 wxGridCellAttr
*attrcell
= (wxGridCellAttr
*)NULL
,
2583 *attrrow
= (wxGridCellAttr
*)NULL
,
2584 *attrcol
= (wxGridCellAttr
*)NULL
;
2586 attrcell
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
2587 attrcol
= m_data
->m_colAttrs
.GetAttr(col
);
2588 attrrow
= m_data
->m_rowAttrs
.GetAttr(row
);
2590 if((attrcell
!= attrrow
) && (attrrow
!=attrcol
) && (attrcell
!= attrcol
)){
2591 // Two or move are non NULL
2592 attr
= new wxGridCellAttr
;
2593 attr
->SetKind(wxGridCellAttr::Merged
);
2597 attr
->MergeWith(attrcell
);
2601 attr
->MergeWith(attrcol
);
2605 attr
->MergeWith(attrrow
);
2608 //store merge attr if cache implemented
2610 //m_data->m_mergeAttr.SetAttr(attr, row, col);
2614 // one or none is non null return it or null.
2615 if(attrrow
) attr
= attrrow
;
2616 if(attrcol
) attr
= attrcol
;
2617 if(attrcell
) attr
= attrcell
;
2621 case (wxGridCellAttr::Cell
):
2622 attr
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
2624 case (wxGridCellAttr::Col
):
2625 attr
= m_data
->m_colAttrs
.GetAttr(col
);
2627 case (wxGridCellAttr::Row
):
2628 attr
= m_data
->m_rowAttrs
.GetAttr(row
);
2632 // (wxGridCellAttr::Default):
2633 // (wxGridCellAttr::Merged):
2640 void wxGridCellAttrProvider::SetAttr(wxGridCellAttr
*attr
,
2646 m_data
->m_cellAttrs
.SetAttr(attr
, row
, col
);
2649 void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr
*attr
, int row
)
2654 m_data
->m_rowAttrs
.SetAttr(attr
, row
);
2657 void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr
*attr
, int col
)
2662 m_data
->m_colAttrs
.SetAttr(attr
, col
);
2665 void wxGridCellAttrProvider::UpdateAttrRows( size_t pos
, int numRows
)
2669 m_data
->m_cellAttrs
.UpdateAttrRows( pos
, numRows
);
2671 m_data
->m_rowAttrs
.UpdateAttrRowsOrCols( pos
, numRows
);
2675 void wxGridCellAttrProvider::UpdateAttrCols( size_t pos
, int numCols
)
2679 m_data
->m_cellAttrs
.UpdateAttrCols( pos
, numCols
);
2681 m_data
->m_colAttrs
.UpdateAttrRowsOrCols( pos
, numCols
);
2685 // ----------------------------------------------------------------------------
2686 // wxGridTypeRegistry
2687 // ----------------------------------------------------------------------------
2689 wxGridTypeRegistry::~wxGridTypeRegistry()
2691 size_t count
= m_typeinfo
.Count();
2692 for ( size_t i
= 0; i
< count
; i
++ )
2693 delete m_typeinfo
[i
];
2697 void wxGridTypeRegistry::RegisterDataType(const wxString
& typeName
,
2698 wxGridCellRenderer
* renderer
,
2699 wxGridCellEditor
* editor
)
2701 wxGridDataTypeInfo
* info
= new wxGridDataTypeInfo(typeName
, renderer
, editor
);
2703 // is it already registered?
2704 int loc
= FindRegisteredDataType(typeName
);
2705 if ( loc
!= wxNOT_FOUND
)
2707 delete m_typeinfo
[loc
];
2708 m_typeinfo
[loc
] = info
;
2712 m_typeinfo
.Add(info
);
2716 int wxGridTypeRegistry::FindRegisteredDataType(const wxString
& typeName
)
2718 size_t count
= m_typeinfo
.GetCount();
2719 for ( size_t i
= 0; i
< count
; i
++ )
2721 if ( typeName
== m_typeinfo
[i
]->m_typeName
)
2730 int wxGridTypeRegistry::FindDataType(const wxString
& typeName
)
2732 int index
= FindRegisteredDataType(typeName
);
2733 if ( index
== wxNOT_FOUND
)
2735 // check whether this is one of the standard ones, in which case
2736 // register it "on the fly"
2738 if ( typeName
== wxGRID_VALUE_STRING
)
2740 RegisterDataType(wxGRID_VALUE_STRING
,
2741 new wxGridCellStringRenderer
,
2742 new wxGridCellTextEditor
);
2744 #endif // wxUSE_TEXTCTRL
2746 if ( typeName
== wxGRID_VALUE_BOOL
)
2748 RegisterDataType(wxGRID_VALUE_BOOL
,
2749 new wxGridCellBoolRenderer
,
2750 new wxGridCellBoolEditor
);
2752 #endif // wxUSE_CHECKBOX
2754 if ( typeName
== wxGRID_VALUE_NUMBER
)
2756 RegisterDataType(wxGRID_VALUE_NUMBER
,
2757 new wxGridCellNumberRenderer
,
2758 new wxGridCellNumberEditor
);
2760 else if ( typeName
== wxGRID_VALUE_FLOAT
)
2762 RegisterDataType(wxGRID_VALUE_FLOAT
,
2763 new wxGridCellFloatRenderer
,
2764 new wxGridCellFloatEditor
);
2766 #endif // wxUSE_TEXTCTRL
2768 if ( typeName
== wxGRID_VALUE_CHOICE
)
2770 RegisterDataType(wxGRID_VALUE_CHOICE
,
2771 new wxGridCellStringRenderer
,
2772 new wxGridCellChoiceEditor
);
2774 #endif // wxUSE_COMBOBOX
2779 // we get here only if just added the entry for this type, so return
2781 index
= m_typeinfo
.GetCount() - 1;
2787 int wxGridTypeRegistry::FindOrCloneDataType(const wxString
& typeName
)
2789 int index
= FindDataType(typeName
);
2790 if ( index
== wxNOT_FOUND
)
2792 // the first part of the typename is the "real" type, anything after ':'
2793 // are the parameters for the renderer
2794 index
= FindDataType(typeName
.BeforeFirst(_T(':')));
2795 if ( index
== wxNOT_FOUND
)
2800 wxGridCellRenderer
*renderer
= GetRenderer(index
);
2801 wxGridCellRenderer
*rendererOld
= renderer
;
2802 renderer
= renderer
->Clone();
2803 rendererOld
->DecRef();
2805 wxGridCellEditor
*editor
= GetEditor(index
);
2806 wxGridCellEditor
*editorOld
= editor
;
2807 editor
= editor
->Clone();
2808 editorOld
->DecRef();
2810 // do it even if there are no parameters to reset them to defaults
2811 wxString params
= typeName
.AfterFirst(_T(':'));
2812 renderer
->SetParameters(params
);
2813 editor
->SetParameters(params
);
2815 // register the new typename
2816 RegisterDataType(typeName
, renderer
, editor
);
2818 // we just registered it, it's the last one
2819 index
= m_typeinfo
.GetCount() - 1;
2825 wxGridCellRenderer
* wxGridTypeRegistry::GetRenderer(int index
)
2827 wxGridCellRenderer
* renderer
= m_typeinfo
[index
]->m_renderer
;
2833 wxGridCellEditor
* wxGridTypeRegistry::GetEditor(int index
)
2835 wxGridCellEditor
* editor
= m_typeinfo
[index
]->m_editor
;
2841 // ----------------------------------------------------------------------------
2843 // ----------------------------------------------------------------------------
2845 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
2848 wxGridTableBase::wxGridTableBase()
2850 m_view
= (wxGrid
*) NULL
;
2851 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
2854 wxGridTableBase::~wxGridTableBase()
2856 delete m_attrProvider
;
2859 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
2861 delete m_attrProvider
;
2862 m_attrProvider
= attrProvider
;
2865 bool wxGridTableBase::CanHaveAttributes()
2867 if ( ! GetAttrProvider() )
2869 // use the default attr provider by default
2870 SetAttrProvider(new wxGridCellAttrProvider
);
2875 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
, wxGridCellAttr::wxAttrKind kind
)
2877 if ( m_attrProvider
)
2878 return m_attrProvider
->GetAttr(row
, col
, kind
);
2880 return (wxGridCellAttr
*)NULL
;
2883 void wxGridTableBase::SetAttr(wxGridCellAttr
* attr
, int row
, int col
)
2885 if ( m_attrProvider
)
2887 attr
->SetKind(wxGridCellAttr::Cell
);
2888 m_attrProvider
->SetAttr(attr
, row
, col
);
2892 // as we take ownership of the pointer and don't store it, we must
2898 void wxGridTableBase::SetRowAttr(wxGridCellAttr
*attr
, int row
)
2900 if ( m_attrProvider
)
2902 attr
->SetKind(wxGridCellAttr::Row
);
2903 m_attrProvider
->SetRowAttr(attr
, row
);
2907 // as we take ownership of the pointer and don't store it, we must
2913 void wxGridTableBase::SetColAttr(wxGridCellAttr
*attr
, int col
)
2915 if ( m_attrProvider
)
2917 attr
->SetKind(wxGridCellAttr::Col
);
2918 m_attrProvider
->SetColAttr(attr
, col
);
2922 // as we take ownership of the pointer and don't store it, we must
2928 bool wxGridTableBase::InsertRows( size_t WXUNUSED(pos
),
2929 size_t WXUNUSED(numRows
) )
2931 wxFAIL_MSG( wxT("Called grid table class function InsertRows\nbut your derived table class does not override this function") );
2936 bool wxGridTableBase::AppendRows( size_t WXUNUSED(numRows
) )
2938 wxFAIL_MSG( wxT("Called grid table class function AppendRows\nbut your derived table class does not override this function"));
2943 bool wxGridTableBase::DeleteRows( size_t WXUNUSED(pos
),
2944 size_t WXUNUSED(numRows
) )
2946 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\nbut your derived table class does not override this function"));
2951 bool wxGridTableBase::InsertCols( size_t WXUNUSED(pos
),
2952 size_t WXUNUSED(numCols
) )
2954 wxFAIL_MSG( wxT("Called grid table class function InsertCols\nbut your derived table class does not override this function"));
2959 bool wxGridTableBase::AppendCols( size_t WXUNUSED(numCols
) )
2961 wxFAIL_MSG(wxT("Called grid table class function AppendCols\nbut your derived table class does not override this function"));
2966 bool wxGridTableBase::DeleteCols( size_t WXUNUSED(pos
),
2967 size_t WXUNUSED(numCols
) )
2969 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\nbut your derived table class does not override this function"));
2975 wxString
wxGridTableBase::GetRowLabelValue( int row
)
2978 s
<< row
+ 1; // RD: Starting the rows at zero confuses users, no matter
2979 // how much it makes sense to us geeks.
2983 wxString
wxGridTableBase::GetColLabelValue( int col
)
2985 // default col labels are:
2986 // cols 0 to 25 : A-Z
2987 // cols 26 to 675 : AA-ZZ
2992 for ( n
= 1; ; n
++ )
2994 s
+= (_T('A') + (wxChar
)( col%26
));
2996 if ( col
< 0 ) break;
2999 // reverse the string...
3001 for ( i
= 0; i
< n
; i
++ )
3010 wxString
wxGridTableBase::GetTypeName( int WXUNUSED(row
), int WXUNUSED(col
) )
3012 return wxGRID_VALUE_STRING
;
3015 bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row
), int WXUNUSED(col
),
3016 const wxString
& typeName
)
3018 return typeName
== wxGRID_VALUE_STRING
;
3021 bool wxGridTableBase::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
3023 return CanGetValueAs(row
, col
, typeName
);
3026 long wxGridTableBase::GetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
) )
3031 double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
) )
3036 bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
) )
3041 void wxGridTableBase::SetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
),
3042 long WXUNUSED(value
) )
3046 void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
),
3047 double WXUNUSED(value
) )
3051 void wxGridTableBase::SetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
),
3052 bool WXUNUSED(value
) )
3057 void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
3058 const wxString
& WXUNUSED(typeName
) )
3063 void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
3064 const wxString
& WXUNUSED(typeName
),
3065 void* WXUNUSED(value
) )
3069 //////////////////////////////////////////////////////////////////////
3071 // Message class for the grid table to send requests and notifications
3075 wxGridTableMessage::wxGridTableMessage()
3077 m_table
= (wxGridTableBase
*) NULL
;
3083 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
3084 int commandInt1
, int commandInt2
)
3088 m_comInt1
= commandInt1
;
3089 m_comInt2
= commandInt2
;
3094 //////////////////////////////////////////////////////////////////////
3096 // A basic grid table for string data. An object of this class will
3097 // created by wxGrid if you don't specify an alternative table class.
3100 WX_DEFINE_OBJARRAY(wxGridStringArray
)
3102 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
3104 wxGridStringTable::wxGridStringTable()
3109 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
3112 m_data
.Alloc( numRows
);
3115 sa
.Alloc( numCols
);
3116 sa
.Add( wxEmptyString
, numCols
);
3118 m_data
.Add( sa
, numRows
);
3121 wxGridStringTable::~wxGridStringTable()
3125 int wxGridStringTable::GetNumberRows()
3127 return m_data
.GetCount();
3130 int wxGridStringTable::GetNumberCols()
3132 if ( m_data
.GetCount() > 0 )
3133 return m_data
[0].GetCount();
3138 wxString
wxGridStringTable::GetValue( int row
, int col
)
3140 wxCHECK_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3142 _T("invalid row or column index in wxGridStringTable") );
3144 return m_data
[row
][col
];
3147 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& value
)
3149 wxCHECK_RET( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3150 _T("invalid row or column index in wxGridStringTable") );
3152 m_data
[row
][col
] = value
;
3155 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
3157 wxCHECK_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
3159 _T("invalid row or column index in wxGridStringTable") );
3161 return (m_data
[row
][col
] == wxEmptyString
);
3164 void wxGridStringTable::Clear()
3167 int numRows
, numCols
;
3169 numRows
= m_data
.GetCount();
3172 numCols
= m_data
[0].GetCount();
3174 for ( row
= 0; row
< numRows
; row
++ )
3176 for ( col
= 0; col
< numCols
; col
++ )
3178 m_data
[row
][col
] = wxEmptyString
;
3185 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
3187 size_t curNumRows
= m_data
.GetCount();
3188 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3189 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3191 if ( pos
>= curNumRows
)
3193 return AppendRows( numRows
);
3197 sa
.Alloc( curNumCols
);
3198 sa
.Add( wxEmptyString
, curNumCols
);
3199 m_data
.Insert( sa
, pos
, numRows
);
3202 wxGridTableMessage
msg( this,
3203 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
3207 GetView()->ProcessTableMessage( msg
);
3213 bool wxGridStringTable::AppendRows( size_t numRows
)
3215 size_t curNumRows
= m_data
.GetCount();
3216 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3217 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3220 if ( curNumCols
> 0 )
3222 sa
.Alloc( curNumCols
);
3223 sa
.Add( wxEmptyString
, curNumCols
);
3226 m_data
.Add( sa
, numRows
);
3230 wxGridTableMessage
msg( this,
3231 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
3234 GetView()->ProcessTableMessage( msg
);
3240 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
3242 size_t curNumRows
= m_data
.GetCount();
3244 if ( pos
>= curNumRows
)
3246 wxFAIL_MSG( wxString::Format
3248 wxT("Called wxGridStringTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows"),
3250 (unsigned long)numRows
,
3251 (unsigned long)curNumRows
3257 if ( numRows
> curNumRows
- pos
)
3259 numRows
= curNumRows
- pos
;
3262 if ( numRows
>= curNumRows
)
3268 m_data
.RemoveAt( pos
, numRows
);
3272 wxGridTableMessage
msg( this,
3273 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
3277 GetView()->ProcessTableMessage( msg
);
3283 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
3287 size_t curNumRows
= m_data
.GetCount();
3288 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3289 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3291 if ( pos
>= curNumCols
)
3293 return AppendCols( numCols
);
3296 for ( row
= 0; row
< curNumRows
; row
++ )
3298 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
3300 m_data
[row
].Insert( wxEmptyString
, col
);
3305 wxGridTableMessage
msg( this,
3306 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
3310 GetView()->ProcessTableMessage( msg
);
3316 bool wxGridStringTable::AppendCols( size_t numCols
)
3320 size_t curNumRows
= m_data
.GetCount();
3324 // TODO: something better than this ?
3326 wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\nCall AppendRows() first") );
3331 for ( row
= 0; row
< curNumRows
; row
++ )
3333 m_data
[row
].Add( wxEmptyString
, numCols
);
3338 wxGridTableMessage
msg( this,
3339 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
3342 GetView()->ProcessTableMessage( msg
);
3348 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
3352 size_t curNumRows
= m_data
.GetCount();
3353 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() :
3354 ( GetView() ? GetView()->GetNumberCols() : 0 ) );
3356 if ( pos
>= curNumCols
)
3358 wxFAIL_MSG( wxString::Format
3360 wxT("Called wxGridStringTable::DeleteCols(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu cols"),
3362 (unsigned long)numCols
,
3363 (unsigned long)curNumCols
3368 if ( numCols
> curNumCols
- pos
)
3370 numCols
= curNumCols
- pos
;
3373 for ( row
= 0; row
< curNumRows
; row
++ )
3375 if ( numCols
>= curNumCols
)
3377 m_data
[row
].Clear();
3381 m_data
[row
].RemoveAt( pos
, numCols
);
3386 wxGridTableMessage
msg( this,
3387 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
3391 GetView()->ProcessTableMessage( msg
);
3397 wxString
wxGridStringTable::GetRowLabelValue( int row
)
3399 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
3401 // using default label
3403 return wxGridTableBase::GetRowLabelValue( row
);
3407 return m_rowLabels
[ row
];
3411 wxString
wxGridStringTable::GetColLabelValue( int col
)
3413 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
3415 // using default label
3417 return wxGridTableBase::GetColLabelValue( col
);
3421 return m_colLabels
[ col
];
3425 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
3427 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
3429 int n
= m_rowLabels
.GetCount();
3431 for ( i
= n
; i
<= row
; i
++ )
3433 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
3437 m_rowLabels
[row
] = value
;
3440 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
3442 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
3444 int n
= m_colLabels
.GetCount();
3446 for ( i
= n
; i
<= col
; i
++ )
3448 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
3452 m_colLabels
[col
] = value
;
3457 //////////////////////////////////////////////////////////////////////
3458 //////////////////////////////////////////////////////////////////////
3460 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
3462 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
3463 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
3464 EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel
)
3465 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
3466 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
3467 EVT_KEY_UP( wxGridRowLabelWindow::OnKeyUp
)
3470 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
3472 const wxPoint
&pos
, const wxSize
&size
)
3473 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
)
3478 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3482 // NO - don't do this because it will set both the x and y origin
3483 // coords to match the parent scrolled window and we just want to
3484 // set the y coord - MB
3486 // m_owner->PrepareDC( dc );
3489 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
3490 dc
.SetDeviceOrigin( 0, -y
);
3492 wxArrayInt rows
= m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
3493 m_owner
->DrawRowLabels( dc
, rows
);
3497 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3499 m_owner
->ProcessRowLabelMouseEvent( event
);
3503 void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3505 m_owner
->GetEventHandler()->ProcessEvent(event
);
3509 // This seems to be required for wxMotif otherwise the mouse
3510 // cursor must be in the cell edit control to get key events
3512 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3514 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3517 void wxGridRowLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3519 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3524 //////////////////////////////////////////////////////////////////////
3526 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
3528 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
3529 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
3530 EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel
)
3531 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
3532 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
3533 EVT_KEY_UP( wxGridColLabelWindow::OnKeyUp
)
3536 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
3538 const wxPoint
&pos
, const wxSize
&size
)
3539 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
)
3544 void wxGridColLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3548 // NO - don't do this because it will set both the x and y origin
3549 // coords to match the parent scrolled window and we just want to
3550 // set the x coord - MB
3552 // m_owner->PrepareDC( dc );
3555 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
3556 dc
.SetDeviceOrigin( -x
, 0 );
3558 wxArrayInt cols
= m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
3559 m_owner
->DrawColLabels( dc
, cols
);
3563 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3565 m_owner
->ProcessColLabelMouseEvent( event
);
3568 void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3570 m_owner
->GetEventHandler()->ProcessEvent(event
);
3574 // This seems to be required for wxMotif otherwise the mouse
3575 // cursor must be in the cell edit control to get key events
3577 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3579 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3582 void wxGridColLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3584 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3589 //////////////////////////////////////////////////////////////////////
3591 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
3593 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
3594 EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel
)
3595 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
3596 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
3597 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
3598 EVT_KEY_UP( wxGridCornerLabelWindow::OnKeyUp
)
3601 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
3603 const wxPoint
&pos
, const wxSize
&size
)
3604 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
)
3609 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3613 int client_height
= 0;
3614 int client_width
= 0;
3615 GetClientSize( &client_width
, &client_height
);
3617 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
),1, wxSOLID
) );
3618 dc
.DrawLine( client_width
-1, client_height
-1, client_width
-1, 0 );
3619 dc
.DrawLine( client_width
-1, client_height
-1, 0, client_height
-1 );
3620 dc
.DrawLine( 0, 0, client_width
, 0 );
3621 dc
.DrawLine( 0, 0, 0, client_height
);
3623 dc
.SetPen( *wxWHITE_PEN
);
3624 dc
.DrawLine( 1, 1, client_width
-1, 1 );
3625 dc
.DrawLine( 1, 1, 1, client_height
-1 );
3629 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
3631 m_owner
->ProcessCornerLabelMouseEvent( event
);
3635 void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent
& event
)
3637 m_owner
->GetEventHandler()->ProcessEvent(event
);
3640 // This seems to be required for wxMotif otherwise the mouse
3641 // cursor must be in the cell edit control to get key events
3643 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
3645 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3648 void wxGridCornerLabelWindow::OnKeyUp( wxKeyEvent
& event
)
3650 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3655 //////////////////////////////////////////////////////////////////////
3657 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxWindow
)
3659 BEGIN_EVENT_TABLE( wxGridWindow
, wxWindow
)
3660 EVT_PAINT( wxGridWindow::OnPaint
)
3661 EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel
)
3662 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
3663 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
3664 EVT_KEY_UP( wxGridWindow::OnKeyUp
)
3665 EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground
)
3668 wxGridWindow::wxGridWindow( wxGrid
*parent
,
3669 wxGridRowLabelWindow
*rowLblWin
,
3670 wxGridColLabelWindow
*colLblWin
,
3673 const wxSize
&size
)
3674 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
| wxBORDER_NONE
| wxCLIP_CHILDREN
,
3675 wxT("grid window") )
3679 m_rowLabelWin
= rowLblWin
;
3680 m_colLabelWin
= colLblWin
;
3681 SetBackgroundColour(_T("WHITE"));
3685 wxGridWindow::~wxGridWindow()
3690 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
3692 wxPaintDC
dc( this );
3693 m_owner
->PrepareDC( dc
);
3694 wxRegion reg
= GetUpdateRegion();
3695 wxGridCellCoordsArray DirtyCells
= m_owner
->CalcCellsExposed( reg
);
3696 m_owner
->DrawGridCellArea( dc
, DirtyCells
);
3697 #if WXGRID_DRAW_LINES
3698 m_owner
->DrawAllGridLines( dc
, reg
);
3700 m_owner
->DrawGridSpace( dc
);
3701 m_owner
->DrawHighlight( dc
, DirtyCells
);
3705 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
3707 wxWindow::ScrollWindow( dx
, dy
, rect
);
3708 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
3709 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
3713 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
3715 m_owner
->ProcessGridCellMouseEvent( event
);
3718 void wxGridWindow::OnMouseWheel( wxMouseEvent
& event
)
3720 m_owner
->GetEventHandler()->ProcessEvent(event
);
3723 // This seems to be required for wxMotif/wxGTK otherwise the mouse
3724 // cursor must be in the cell edit control to get key events
3726 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
3728 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3731 void wxGridWindow::OnKeyUp( wxKeyEvent
& event
)
3733 if ( !m_owner
->GetEventHandler()->ProcessEvent( event
) ) event
.Skip();
3736 void wxGridWindow::OnEraseBackground( wxEraseEvent
& WXUNUSED(event
) )
3741 //////////////////////////////////////////////////////////////////////
3743 // Internal Helper function for computing row or column from some
3744 // (unscrolled) coordinate value, using either
3745 // m_defaultRowHeight/m_defaultColWidth or binary search on array
3746 // of m_rowBottoms/m_ColRights to speed up the search!
3748 // Internal helper macros for simpler use of that function
3750 static int CoordToRowOrCol(int coord
, int defaultDist
, int minDist
,
3751 const wxArrayInt
& BorderArray
, int nMax
,
3754 #define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \
3755 m_minAcceptableColWidth, \
3756 m_colRights, m_numCols, TRUE)
3757 #define internalYToRow(y) CoordToRowOrCol(y, m_defaultRowHeight, \
3758 m_minAcceptableRowHeight, \
3759 m_rowBottoms, m_numRows, TRUE)
3760 /////////////////////////////////////////////////////////////////////
3762 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
3764 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
3765 EVT_PAINT( wxGrid::OnPaint
)
3766 EVT_SIZE( wxGrid::OnSize
)
3767 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
3768 EVT_KEY_UP( wxGrid::OnKeyUp
)
3769 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
3772 wxGrid::wxGrid( wxWindow
*parent
,
3777 const wxString
& name
)
3778 : wxScrolledWindow( parent
, id
, pos
, size
, (style
| wxWANTS_CHARS
), name
),
3779 m_colMinWidths(GRID_HASH_SIZE
),
3780 m_rowMinHeights(GRID_HASH_SIZE
)
3788 // Must do this or ~wxScrollHelper will pop the wrong event handler
3789 SetTargetWindow(this);
3791 wxSafeDecRef(m_defaultCellAttr
);
3793 #ifdef DEBUG_ATTR_CACHE
3794 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
3795 wxPrintf(_T("wxGrid attribute cache statistics: "
3796 "total: %u, hits: %u (%u%%)\n"),
3797 total
, gs_nAttrCacheHits
,
3798 total
? (gs_nAttrCacheHits
*100) / total
: 0);
3804 delete m_typeRegistry
;
3810 // ----- internal init and update functions
3813 void wxGrid::Create()
3815 m_created
= FALSE
; // set to TRUE by CreateGrid
3817 m_table
= (wxGridTableBase
*) NULL
;
3820 m_cellEditCtrlEnabled
= FALSE
;
3822 m_defaultCellAttr
= new wxGridCellAttr();
3824 // Set default cell attributes
3825 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
3826 m_defaultCellAttr
->SetKind(wxGridCellAttr::Default
);
3827 m_defaultCellAttr
->SetFont(GetFont());
3828 m_defaultCellAttr
->SetAlignment(wxALIGN_LEFT
, wxALIGN_TOP
);
3829 m_defaultCellAttr
->SetTextColour(
3830 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
3831 m_defaultCellAttr
->SetBackgroundColour(
3832 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
3833 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
3834 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
3839 m_currentCellCoords
= wxGridNoCellCoords
;
3841 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
3842 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
3844 // create the type registry
3845 m_typeRegistry
= new wxGridTypeRegistry
;
3848 // subwindow components that make up the wxGrid
3849 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
3854 m_rowLabelWin
= new wxGridRowLabelWindow( this,
3859 m_colLabelWin
= new wxGridColLabelWindow( this,
3864 m_gridWin
= new wxGridWindow( this,
3871 SetTargetWindow( m_gridWin
);
3877 bool wxGrid::CreateGrid( int numRows
, int numCols
,
3878 wxGrid::wxGridSelectionModes selmode
)
3880 wxCHECK_MSG( !m_created
,
3882 wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
3884 m_numRows
= numRows
;
3885 m_numCols
= numCols
;
3887 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
3888 m_table
->SetView( this );
3890 m_selection
= new wxGridSelection( this, selmode
);
3899 void wxGrid::SetSelectionMode(wxGrid::wxGridSelectionModes selmode
)
3901 wxCHECK_RET( m_created
,
3902 wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") );
3904 m_selection
->SetSelectionMode( selmode
);
3907 wxGrid::wxGridSelectionModes
wxGrid::GetSelectionMode() const
3909 wxCHECK_MSG( m_created
, wxGrid::wxGridSelectCells
,
3910 wxT("Called wxGrid::GetSelectionMode() before calling CreateGrid()") );
3912 return m_selection
->GetSelectionMode();
3915 bool wxGrid::SetTable( wxGridTableBase
*table
, bool takeOwnership
,
3916 wxGrid::wxGridSelectionModes selmode
)
3920 // stop all processing
3925 wxGridTableBase
*t
=m_table
;
3938 m_numRows
= table
->GetNumberRows();
3939 m_numCols
= table
->GetNumberCols();
3942 m_table
->SetView( this );
3945 m_selection
= new wxGridSelection( this, selmode
);
3958 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
3959 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
3961 if ( m_rowLabelWin
)
3963 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
3967 m_labelBackgroundColour
= wxColour( _T("WHITE") );
3970 m_labelTextColour
= wxColour( _T("BLACK") );
3973 m_attrCache
.row
= -1;
3974 m_attrCache
.col
= -1;
3975 m_attrCache
.attr
= NULL
;
3977 // TODO: something better than this ?
3979 m_labelFont
= this->GetFont();
3980 m_labelFont
.SetWeight( wxBOLD
);
3982 m_rowLabelHorizAlign
= wxALIGN_CENTRE
;
3983 m_rowLabelVertAlign
= wxALIGN_CENTRE
;
3985 m_colLabelHorizAlign
= wxALIGN_CENTRE
;
3986 m_colLabelVertAlign
= wxALIGN_CENTRE
;
3987 m_colLabelTextOrientation
= wxHORIZONTAL
;
3989 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
3990 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
3992 m_minAcceptableColWidth
= WXGRID_MIN_COL_WIDTH
;
3993 m_minAcceptableRowHeight
= WXGRID_MIN_ROW_HEIGHT
;
3995 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
3996 m_defaultRowHeight
+= 8;
3998 m_defaultRowHeight
+= 4;
4001 m_gridLineColour
= wxColour( 192,192,192 );
4002 m_gridLinesEnabled
= TRUE
;
4003 m_cellHighlightColour
= *wxBLACK
;
4004 m_cellHighlightPenWidth
= 2;
4005 m_cellHighlightROPenWidth
= 1;
4007 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
4008 m_winCapture
= (wxWindow
*)NULL
;
4009 m_canDragRowSize
= TRUE
;
4010 m_canDragColSize
= TRUE
;
4011 m_canDragGridSize
= TRUE
;
4013 m_dragRowOrCol
= -1;
4014 m_isDragging
= FALSE
;
4015 m_startDragPos
= wxDefaultPosition
;
4017 m_waitForSlowClick
= FALSE
;
4019 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
4020 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
4022 m_currentCellCoords
= wxGridNoCellCoords
;
4024 m_selectingTopLeft
= wxGridNoCellCoords
;
4025 m_selectingBottomRight
= wxGridNoCellCoords
;
4026 m_selectionBackground
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
4027 m_selectionForeground
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
4029 m_editable
= TRUE
; // default for whole grid
4031 m_inOnKeyDown
= FALSE
;
4038 // ----------------------------------------------------------------------------
4039 // the idea is to call these functions only when necessary because they create
4040 // quite big arrays which eat memory mostly unnecessary - in particular, if
4041 // default widths/heights are used for all rows/columns, we may not use these
4044 // with some extra code, it should be possible to only store the
4045 // widths/heights different from default ones but this will be done later...
4046 // ----------------------------------------------------------------------------
4048 void wxGrid::InitRowHeights()
4050 m_rowHeights
.Empty();
4051 m_rowBottoms
.Empty();
4053 m_rowHeights
.Alloc( m_numRows
);
4054 m_rowBottoms
.Alloc( m_numRows
);
4058 m_rowHeights
.Add( m_defaultRowHeight
, m_numRows
);
4060 for ( int i
= 0; i
< m_numRows
; i
++ )
4062 rowBottom
+= m_defaultRowHeight
;
4063 m_rowBottoms
.Add( rowBottom
);
4067 void wxGrid::InitColWidths()
4069 m_colWidths
.Empty();
4070 m_colRights
.Empty();
4072 m_colWidths
.Alloc( m_numCols
);
4073 m_colRights
.Alloc( m_numCols
);
4076 m_colWidths
.Add( m_defaultColWidth
, m_numCols
);
4078 for ( int i
= 0; i
< m_numCols
; i
++ )
4080 colRight
+= m_defaultColWidth
;
4081 m_colRights
.Add( colRight
);
4085 int wxGrid::GetColWidth(int col
) const
4087 return m_colWidths
.IsEmpty() ? m_defaultColWidth
: m_colWidths
[col
];
4090 int wxGrid::GetColLeft(int col
) const
4092 return m_colRights
.IsEmpty() ? col
* m_defaultColWidth
4093 : m_colRights
[col
] - m_colWidths
[col
];
4096 int wxGrid::GetColRight(int col
) const
4098 return m_colRights
.IsEmpty() ? (col
+ 1) * m_defaultColWidth
4102 int wxGrid::GetRowHeight(int row
) const
4104 return m_rowHeights
.IsEmpty() ? m_defaultRowHeight
: m_rowHeights
[row
];
4107 int wxGrid::GetRowTop(int row
) const
4109 return m_rowBottoms
.IsEmpty() ? row
* m_defaultRowHeight
4110 : m_rowBottoms
[row
] - m_rowHeights
[row
];
4113 int wxGrid::GetRowBottom(int row
) const
4115 return m_rowBottoms
.IsEmpty() ? (row
+ 1) * m_defaultRowHeight
4116 : m_rowBottoms
[row
];
4119 void wxGrid::CalcDimensions()
4122 GetClientSize( &cw
, &ch
);
4124 if ( m_rowLabelWin
->IsShown() )
4125 cw
-= m_rowLabelWidth
;
4126 if ( m_colLabelWin
->IsShown() )
4127 ch
-= m_colLabelHeight
;
4130 int w
= m_numCols
> 0 ? GetColRight(m_numCols
- 1) + m_extraWidth
+ 1 : 0;
4131 int h
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) + m_extraHeight
+ 1 : 0;
4133 // take into account editor if shown
4134 if( IsCellEditControlShown() )
4137 int r
= m_currentCellCoords
.GetRow();
4138 int c
= m_currentCellCoords
.GetCol();
4139 int x
= GetColLeft(c
);
4140 int y
= GetRowTop(r
);
4142 // how big is the editor
4143 wxGridCellAttr
* attr
= GetCellAttr(r
, c
);
4144 wxGridCellEditor
* editor
= attr
->GetEditor(this, r
, c
);
4145 editor
->GetControl()->GetSize(&w2
, &h2
);
4148 if( w2
> w
) w
= w2
;
4149 if( h2
> h
) h
= h2
;
4154 // preserve (more or less) the previous position
4156 GetViewStart( &x
, &y
);
4158 // maybe we don't need scrollbars at all?
4160 // also adjust the position to be valid for the new scroll rangs
4181 // do set scrollbar parameters
4182 SetScrollbars( GRID_SCROLL_LINE_X
, GRID_SCROLL_LINE_Y
,
4183 GetScrollX(w
), GetScrollY(h
), x
, y
,
4184 GetBatchCount() != 0);
4186 // if our OnSize() hadn't been called (it would if we have scrollbars), we
4187 // still must reposition the children
4192 void wxGrid::CalcWindowSizes()
4195 GetClientSize( &cw
, &ch
);
4197 if ( m_cornerLabelWin
->IsShown() )
4198 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
4200 if ( m_colLabelWin
->IsShown() )
4201 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
4203 if ( m_rowLabelWin
->IsShown() )
4204 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
4206 if ( m_gridWin
->IsShown() )
4207 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
4211 // this is called when the grid table sends a message to say that it
4212 // has been redimensioned
4214 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
4217 bool result
= FALSE
;
4219 // Clear the attribute cache as the attribute might refer to a different
4220 // cell than stored in the cache after adding/removing rows/columns.
4222 // By the same reasoning, the editor should be dismissed if columns are
4223 // added or removed. And for consistency, it should IMHO always be
4224 // removed, not only if the cell "underneath" it actually changes.
4225 // For now, I intentionally do not save the editor's content as the
4226 // cell it might want to save that stuff to might no longer exist.
4227 HideCellEditControl();
4229 // if we were using the default widths/heights so far, we must change them
4231 if ( m_colWidths
.IsEmpty() )
4236 if ( m_rowHeights
.IsEmpty() )
4242 switch ( msg
.GetId() )
4244 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
4246 size_t pos
= msg
.GetCommandInt();
4247 int numRows
= msg
.GetCommandInt2();
4249 m_numRows
+= numRows
;
4251 if ( !m_rowHeights
.IsEmpty() )
4253 m_rowHeights
.Insert( m_defaultRowHeight
, pos
, numRows
);
4254 m_rowBottoms
.Insert( 0, pos
, numRows
);
4257 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
4259 for ( i
= pos
; i
< m_numRows
; i
++ )
4261 bottom
+= m_rowHeights
[i
];
4262 m_rowBottoms
[i
] = bottom
;
4265 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4267 // if we have just inserted cols into an empty grid the current
4268 // cell will be undefined...
4270 SetCurrentCell( 0, 0 );
4274 m_selection
->UpdateRows( pos
, numRows
);
4275 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4277 attrProvider
->UpdateAttrRows( pos
, numRows
);
4279 if ( !GetBatchCount() )
4282 m_rowLabelWin
->Refresh();
4288 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
4290 int numRows
= msg
.GetCommandInt();
4291 int oldNumRows
= m_numRows
;
4292 m_numRows
+= numRows
;
4294 if ( !m_rowHeights
.IsEmpty() )
4296 m_rowHeights
.Add( m_defaultRowHeight
, numRows
);
4297 m_rowBottoms
.Add( 0, numRows
);
4300 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
4302 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
4304 bottom
+= m_rowHeights
[i
];
4305 m_rowBottoms
[i
] = bottom
;
4308 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4310 // if we have just inserted cols into an empty grid the current
4311 // cell will be undefined...
4313 SetCurrentCell( 0, 0 );
4315 if ( !GetBatchCount() )
4318 m_rowLabelWin
->Refresh();
4324 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
4326 size_t pos
= msg
.GetCommandInt();
4327 int numRows
= msg
.GetCommandInt2();
4328 m_numRows
-= numRows
;
4330 if ( !m_rowHeights
.IsEmpty() )
4332 m_rowHeights
.RemoveAt( pos
, numRows
);
4333 m_rowBottoms
.RemoveAt( pos
, numRows
);
4336 for ( i
= 0; i
< m_numRows
; i
++ )
4338 h
+= m_rowHeights
[i
];
4339 m_rowBottoms
[i
] = h
;
4344 m_currentCellCoords
= wxGridNoCellCoords
;
4348 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
4349 m_currentCellCoords
.Set( 0, 0 );
4353 m_selection
->UpdateRows( pos
, -((int)numRows
) );
4354 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4356 attrProvider
->UpdateAttrRows( pos
, -((int)numRows
) );
4357 // ifdef'd out following patch from Paul Gammans
4359 // No need to touch column attributes, unless we
4360 // removed _all_ rows, in this case, we remove
4361 // all column attributes.
4362 // I hate to do this here, but the
4363 // needed data is not available inside UpdateAttrRows.
4364 if ( !GetNumberRows() )
4365 attrProvider
->UpdateAttrCols( 0, -GetNumberCols() );
4368 if ( !GetBatchCount() )
4371 m_rowLabelWin
->Refresh();
4377 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
4379 size_t pos
= msg
.GetCommandInt();
4380 int numCols
= msg
.GetCommandInt2();
4381 m_numCols
+= numCols
;
4383 if ( !m_colWidths
.IsEmpty() )
4385 m_colWidths
.Insert( m_defaultColWidth
, pos
, numCols
);
4386 m_colRights
.Insert( 0, pos
, numCols
);
4389 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
4391 for ( i
= pos
; i
< m_numCols
; i
++ )
4393 right
+= m_colWidths
[i
];
4394 m_colRights
[i
] = right
;
4397 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4399 // if we have just inserted cols into an empty grid the current
4400 // cell will be undefined...
4402 SetCurrentCell( 0, 0 );
4406 m_selection
->UpdateCols( pos
, numCols
);
4407 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4409 attrProvider
->UpdateAttrCols( pos
, numCols
);
4410 if ( !GetBatchCount() )
4413 m_colLabelWin
->Refresh();
4420 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
4422 int numCols
= msg
.GetCommandInt();
4423 int oldNumCols
= m_numCols
;
4424 m_numCols
+= numCols
;
4425 if ( !m_colWidths
.IsEmpty() )
4427 m_colWidths
.Add( m_defaultColWidth
, numCols
);
4428 m_colRights
.Add( 0, numCols
);
4431 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
4433 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
4435 right
+= m_colWidths
[i
];
4436 m_colRights
[i
] = right
;
4439 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4441 // if we have just inserted cols into an empty grid the current
4442 // cell will be undefined...
4444 SetCurrentCell( 0, 0 );
4446 if ( !GetBatchCount() )
4449 m_colLabelWin
->Refresh();
4455 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
4457 size_t pos
= msg
.GetCommandInt();
4458 int numCols
= msg
.GetCommandInt2();
4459 m_numCols
-= numCols
;
4461 if ( !m_colWidths
.IsEmpty() )
4463 m_colWidths
.RemoveAt( pos
, numCols
);
4464 m_colRights
.RemoveAt( pos
, numCols
);
4467 for ( i
= 0; i
< m_numCols
; i
++ )
4469 w
+= m_colWidths
[i
];
4475 m_currentCellCoords
= wxGridNoCellCoords
;
4479 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
4480 m_currentCellCoords
.Set( 0, 0 );
4484 m_selection
->UpdateCols( pos
, -((int)numCols
) );
4485 wxGridCellAttrProvider
* attrProvider
= m_table
->GetAttrProvider();
4487 attrProvider
->UpdateAttrCols( pos
, -((int)numCols
) );
4488 // ifdef'd out following patch from Paul Gammans
4490 // No need to touch row attributes, unless we
4491 // removed _all_ columns, in this case, we remove
4492 // all row attributes.
4493 // I hate to do this here, but the
4494 // needed data is not available inside UpdateAttrCols.
4495 if ( !GetNumberCols() )
4496 attrProvider
->UpdateAttrRows( 0, -GetNumberRows() );
4499 if ( !GetBatchCount() )
4502 m_colLabelWin
->Refresh();
4509 if (result
&& !GetBatchCount() )
4510 m_gridWin
->Refresh();
4515 wxArrayInt
wxGrid::CalcRowLabelsExposed( const wxRegion
& reg
)
4517 wxRegionIterator
iter( reg
);
4520 wxArrayInt rowlabels
;
4527 // TODO: remove this when we can...
4528 // There is a bug in wxMotif that gives garbage update
4529 // rectangles if you jump-scroll a long way by clicking the
4530 // scrollbar with middle button. This is a work-around
4532 #if defined(__WXMOTIF__)
4534 m_gridWin
->GetClientSize( &cw
, &ch
);
4535 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
4536 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
4539 // logical bounds of update region
4542 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
4543 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
4545 // find the row labels within these bounds
4548 for ( row
= internalYToRow(top
); row
< m_numRows
; row
++ )
4550 if ( GetRowBottom(row
) < top
)
4553 if ( GetRowTop(row
) > bottom
)
4556 rowlabels
.Add( row
);
4566 wxArrayInt
wxGrid::CalcColLabelsExposed( const wxRegion
& reg
)
4568 wxRegionIterator
iter( reg
);
4571 wxArrayInt colLabels
;
4578 // TODO: remove this when we can...
4579 // There is a bug in wxMotif that gives garbage update
4580 // rectangles if you jump-scroll a long way by clicking the
4581 // scrollbar with middle button. This is a work-around
4583 #if defined(__WXMOTIF__)
4585 m_gridWin
->GetClientSize( &cw
, &ch
);
4586 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
4587 r
.SetRight( wxMin( r
.GetRight(), cw
) );
4590 // logical bounds of update region
4593 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
4594 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
4596 // find the cells within these bounds
4599 for ( col
= internalXToCol(left
); col
< m_numCols
; col
++ )
4601 if ( GetColRight(col
) < left
)
4604 if ( GetColLeft(col
) > right
)
4607 colLabels
.Add( col
);
4616 wxGridCellCoordsArray
wxGrid::CalcCellsExposed( const wxRegion
& reg
)
4618 wxRegionIterator
iter( reg
);
4621 wxGridCellCoordsArray cellsExposed
;
4623 int left
, top
, right
, bottom
;
4628 // TODO: remove this when we can...
4629 // There is a bug in wxMotif that gives garbage update
4630 // rectangles if you jump-scroll a long way by clicking the
4631 // scrollbar with middle button. This is a work-around
4633 #if defined(__WXMOTIF__)
4635 m_gridWin
->GetClientSize( &cw
, &ch
);
4636 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
4637 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
4638 r
.SetRight( wxMin( r
.GetRight(), cw
) );
4639 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
4642 // logical bounds of update region
4644 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
4645 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
4647 // find the cells within these bounds
4650 for ( row
= internalYToRow(top
); row
< m_numRows
; row
++ )
4652 if ( GetRowBottom(row
) <= top
)
4655 if ( GetRowTop(row
) > bottom
)
4658 for ( col
= internalXToCol(left
); col
< m_numCols
; col
++ )
4660 if ( GetColRight(col
) <= left
)
4663 if ( GetColLeft(col
) > right
)
4666 cellsExposed
.Add( wxGridCellCoords( row
, col
) );
4673 return cellsExposed
;
4677 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
4680 wxPoint
pos( event
.GetPosition() );
4681 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
4683 if ( event
.Dragging() )
4687 m_isDragging
= TRUE
;
4688 m_rowLabelWin
->CaptureMouse();
4691 if ( event
.LeftIsDown() )
4693 switch( m_cursorMode
)
4695 case WXGRID_CURSOR_RESIZE_ROW
:
4697 int cw
, ch
, left
, dummy
;
4698 m_gridWin
->GetClientSize( &cw
, &ch
);
4699 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
4701 wxClientDC
dc( m_gridWin
);
4704 GetRowTop(m_dragRowOrCol
) +
4705 GetRowMinimalHeight(m_dragRowOrCol
) );
4706 dc
.SetLogicalFunction(wxINVERT
);
4707 if ( m_dragLastPos
>= 0 )
4709 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
4711 dc
.DrawLine( left
, y
, left
+cw
, y
);
4716 case WXGRID_CURSOR_SELECT_ROW
:
4717 if ( (row
= YToRow( y
)) >= 0 )
4721 m_selection
->SelectRow( row
,
4722 event
.ControlDown(),
4729 // default label to suppress warnings about "enumeration value
4730 // 'xxx' not handled in switch
4738 if ( m_isDragging
&& (event
.Entering() || event
.Leaving()) )
4743 if (m_rowLabelWin
->HasCapture()) m_rowLabelWin
->ReleaseMouse();
4744 m_isDragging
= FALSE
;
4747 // ------------ Entering or leaving the window
4749 if ( event
.Entering() || event
.Leaving() )
4751 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
4755 // ------------ Left button pressed
4757 else if ( event
.LeftDown() )
4759 // don't send a label click event for a hit on the
4760 // edge of the row label - this is probably the user
4761 // wanting to resize the row
4763 if ( YToEdgeOfRow(y
) < 0 )
4767 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
4769 if ( !event
.ShiftDown() && !event
.ControlDown() )
4773 if ( event
.ShiftDown() )
4775 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
4778 GetNumberCols() - 1,
4779 event
.ControlDown(),
4786 m_selection
->SelectRow( row
,
4787 event
.ControlDown(),
4794 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
4799 // starting to drag-resize a row
4801 if ( CanDragRowSize() )
4802 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
4807 // ------------ Left double click
4809 else if (event
.LeftDClick() )
4811 int row
= YToEdgeOfRow(y
);
4816 !SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
) )
4818 // no default action at the moment
4823 // adjust row height depending on label text
4824 AutoSizeRowLabelSize( row
);
4826 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
4832 // ------------ Left button released
4834 else if ( event
.LeftUp() )
4836 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
4838 DoEndDragResizeRow();
4840 // Note: we are ending the event *after* doing
4841 // default processing in this case
4843 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
4846 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
4851 // ------------ Right button down
4853 else if ( event
.RightDown() )
4857 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
4859 // no default action at the moment
4864 // ------------ Right double click
4866 else if ( event
.RightDClick() )
4870 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
4872 // no default action at the moment
4877 // ------------ No buttons down and mouse moving
4879 else if ( event
.Moving() )
4881 m_dragRowOrCol
= YToEdgeOfRow( y
);
4882 if ( m_dragRowOrCol
>= 0 )
4884 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4886 // don't capture the mouse yet
4887 if ( CanDragRowSize() )
4888 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, FALSE
);
4891 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
4893 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, FALSE
);
4899 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
4902 wxPoint
pos( event
.GetPosition() );
4903 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
4905 if ( event
.Dragging() )
4909 m_isDragging
= TRUE
;
4910 m_colLabelWin
->CaptureMouse();
4913 if ( event
.LeftIsDown() )
4915 switch( m_cursorMode
)
4917 case WXGRID_CURSOR_RESIZE_COL
:
4919 int cw
, ch
, dummy
, top
;
4920 m_gridWin
->GetClientSize( &cw
, &ch
);
4921 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
4923 wxClientDC
dc( m_gridWin
);
4926 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
4927 GetColMinimalWidth(m_dragRowOrCol
));
4928 dc
.SetLogicalFunction(wxINVERT
);
4929 if ( m_dragLastPos
>= 0 )
4931 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
4933 dc
.DrawLine( x
, top
, x
, top
+ch
);
4938 case WXGRID_CURSOR_SELECT_COL
:
4939 if ( (col
= XToCol( x
)) >= 0 )
4943 m_selection
->SelectCol( col
,
4944 event
.ControlDown(),
4951 // default label to suppress warnings about "enumeration value
4952 // 'xxx' not handled in switch
4960 if ( m_isDragging
&& (event
.Entering() || event
.Leaving()) )
4965 if (m_colLabelWin
->HasCapture()) m_colLabelWin
->ReleaseMouse();
4966 m_isDragging
= FALSE
;
4969 // ------------ Entering or leaving the window
4971 if ( event
.Entering() || event
.Leaving() )
4973 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
4977 // ------------ Left button pressed
4979 else if ( event
.LeftDown() )
4981 // don't send a label click event for a hit on the
4982 // edge of the col label - this is probably the user
4983 // wanting to resize the col
4985 if ( XToEdgeOfCol(x
) < 0 )
4989 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
4991 if ( !event
.ShiftDown() && !event
.ControlDown() )
4995 if ( event
.ShiftDown() )
4997 m_selection
->SelectBlock( 0,
4998 m_currentCellCoords
.GetCol(),
4999 GetNumberRows() - 1, col
,
5000 event
.ControlDown(),
5007 m_selection
->SelectCol( col
,
5008 event
.ControlDown(),
5015 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, m_colLabelWin
);
5020 // starting to drag-resize a col
5022 if ( CanDragColSize() )
5023 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
);
5028 // ------------ Left double click
5030 if ( event
.LeftDClick() )
5032 int col
= XToEdgeOfCol(x
);
5037 ! SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
) )
5039 // no default action at the moment
5044 // adjust column width depending on label text
5045 AutoSizeColLabelSize( col
);
5047 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
5053 // ------------ Left button released
5055 else if ( event
.LeftUp() )
5057 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5059 DoEndDragResizeCol();
5061 // Note: we are ending the event *after* doing
5062 // default processing in this case
5064 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
5067 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
5072 // ------------ Right button down
5074 else if ( event
.RightDown() )
5078 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
5080 // no default action at the moment
5085 // ------------ Right double click
5087 else if ( event
.RightDClick() )
5091 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
5093 // no default action at the moment
5098 // ------------ No buttons down and mouse moving
5100 else if ( event
.Moving() )
5102 m_dragRowOrCol
= XToEdgeOfCol( x
);
5103 if ( m_dragRowOrCol
>= 0 )
5105 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5107 // don't capture the cursor yet
5108 if ( CanDragColSize() )
5109 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
, FALSE
);
5112 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
5114 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
, FALSE
);
5120 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
5122 if ( event
.LeftDown() )
5124 // indicate corner label by having both row and
5127 if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
5133 else if ( event
.LeftDClick() )
5135 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
5138 else if ( event
.RightDown() )
5140 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
5142 // no default action at the moment
5146 else if ( event
.RightDClick() )
5148 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
5150 // no default action at the moment
5155 void wxGrid::ChangeCursorMode(CursorMode mode
,
5160 static const wxChar
*cursorModes
[] =
5169 wxLogTrace(_T("grid"),
5170 _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
5171 win
== m_colLabelWin
? _T("colLabelWin")
5172 : win
? _T("rowLabelWin")
5174 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
5175 #endif // __WXDEBUG__
5177 if ( mode
== m_cursorMode
&&
5178 win
== m_winCapture
&&
5179 captureMouse
== (m_winCapture
!= NULL
))
5184 // by default use the grid itself
5190 if (m_winCapture
->HasCapture()) m_winCapture
->ReleaseMouse();
5191 m_winCapture
= (wxWindow
*)NULL
;
5194 m_cursorMode
= mode
;
5196 switch ( m_cursorMode
)
5198 case WXGRID_CURSOR_RESIZE_ROW
:
5199 win
->SetCursor( m_rowResizeCursor
);
5202 case WXGRID_CURSOR_RESIZE_COL
:
5203 win
->SetCursor( m_colResizeCursor
);
5207 win
->SetCursor( *wxSTANDARD_CURSOR
);
5210 // we need to capture mouse when resizing
5211 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
5212 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
5214 if ( captureMouse
&& resize
)
5216 win
->CaptureMouse();
5221 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
5224 wxPoint
pos( event
.GetPosition() );
5225 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
5227 wxGridCellCoords coords
;
5228 XYToCell( x
, y
, coords
);
5230 int cell_rows
, cell_cols
;
5231 GetCellSize( coords
.GetRow(), coords
.GetCol(), &cell_rows
, &cell_cols
);
5232 if ((cell_rows
< 0) || (cell_cols
< 0))
5234 coords
.SetRow(coords
.GetRow() + cell_rows
);
5235 coords
.SetCol(coords
.GetCol() + cell_cols
);
5238 if ( event
.Dragging() )
5240 //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
5242 // Don't start doing anything until the mouse has been drug at
5243 // least 3 pixels in any direction...
5246 if (m_startDragPos
== wxDefaultPosition
)
5248 m_startDragPos
= pos
;
5251 if (abs(m_startDragPos
.x
- pos
.x
) < 4 && abs(m_startDragPos
.y
- pos
.y
) < 4)
5255 m_isDragging
= TRUE
;
5256 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5258 // Hide the edit control, so it
5259 // won't interfer with drag-shrinking.
5260 if ( IsCellEditControlShown() )
5262 HideCellEditControl();
5263 SaveEditControlValue();
5266 // Have we captured the mouse yet?
5269 m_winCapture
= m_gridWin
;
5270 m_winCapture
->CaptureMouse();
5273 if ( coords
!= wxGridNoCellCoords
)
5275 if ( event
.ControlDown() )
5277 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
5278 m_selectingKeyboard
= coords
;
5279 HighlightBlock ( m_selectingKeyboard
, coords
);
5283 if ( !IsSelection() )
5285 HighlightBlock( coords
, coords
);
5289 HighlightBlock( m_currentCellCoords
, coords
);
5293 if (! IsVisible(coords
))
5295 MakeCellVisible(coords
);
5296 // TODO: need to introduce a delay or something here. The
5297 // scrolling is way to fast, at least on MSW - also on GTK.
5301 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
5303 int cw
, ch
, left
, dummy
;
5304 m_gridWin
->GetClientSize( &cw
, &ch
);
5305 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
5307 wxClientDC
dc( m_gridWin
);
5309 y
= wxMax( y
, GetRowTop(m_dragRowOrCol
) +
5310 GetRowMinimalHeight(m_dragRowOrCol
) );
5311 dc
.SetLogicalFunction(wxINVERT
);
5312 if ( m_dragLastPos
>= 0 )
5314 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
5316 dc
.DrawLine( left
, y
, left
+cw
, y
);
5319 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5321 int cw
, ch
, dummy
, top
;
5322 m_gridWin
->GetClientSize( &cw
, &ch
);
5323 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
5325 wxClientDC
dc( m_gridWin
);
5327 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
5328 GetColMinimalWidth(m_dragRowOrCol
) );
5329 dc
.SetLogicalFunction(wxINVERT
);
5330 if ( m_dragLastPos
>= 0 )
5332 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
5334 dc
.DrawLine( x
, top
, x
, top
+ch
);
5341 m_isDragging
= FALSE
;
5342 m_startDragPos
= wxDefaultPosition
;
5344 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
5345 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
5348 if ( event
.Entering() || event
.Leaving() )
5350 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5351 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
5356 // ------------ Left button pressed
5358 if ( event
.LeftDown() && coords
!= wxGridNoCellCoords
)
5360 if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK
,
5365 if ( !event
.ControlDown() )
5367 if ( event
.ShiftDown() )
5371 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
5372 m_currentCellCoords
.GetCol(),
5375 event
.ControlDown(),
5381 else if ( XToEdgeOfCol(x
) < 0 &&
5382 YToEdgeOfRow(y
) < 0 )
5384 DisableCellEditControl();
5385 MakeCellVisible( coords
);
5387 if ( event
.ControlDown() )
5391 m_selection
->ToggleCellSelection( coords
.GetRow(),
5393 event
.ControlDown(),
5398 m_selectingTopLeft
= wxGridNoCellCoords
;
5399 m_selectingBottomRight
= wxGridNoCellCoords
;
5400 m_selectingKeyboard
= coords
;
5404 m_waitForSlowClick
= m_currentCellCoords
== coords
&& coords
!= wxGridNoCellCoords
;
5405 SetCurrentCell( coords
);
5408 if ( m_selection
->GetSelectionMode() !=
5409 wxGrid::wxGridSelectCells
)
5411 HighlightBlock( coords
, coords
);
5420 // ------------ Left double click
5422 else if ( event
.LeftDClick() && coords
!= wxGridNoCellCoords
)
5424 DisableCellEditControl();
5426 if ( XToEdgeOfCol(x
) < 0 && YToEdgeOfRow(y
) < 0 )
5428 SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK
,
5436 // ------------ Left button released
5438 else if ( event
.LeftUp() )
5440 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5444 if (m_winCapture
->HasCapture()) m_winCapture
->ReleaseMouse();
5445 m_winCapture
= NULL
;
5448 if ( coords
== m_currentCellCoords
&& m_waitForSlowClick
&& CanEnableCellControl())
5451 EnableCellEditControl();
5453 wxGridCellAttr
* attr
= GetCellAttr(coords
);
5454 wxGridCellEditor
*editor
= attr
->GetEditor(this, coords
.GetRow(), coords
.GetCol());
5455 editor
->StartingClick();
5459 m_waitForSlowClick
= FALSE
;
5461 else if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
5462 m_selectingBottomRight
!= wxGridNoCellCoords
)
5466 m_selection
->SelectBlock( m_selectingTopLeft
.GetRow(),
5467 m_selectingTopLeft
.GetCol(),
5468 m_selectingBottomRight
.GetRow(),
5469 m_selectingBottomRight
.GetCol(),
5470 event
.ControlDown(),
5476 m_selectingTopLeft
= wxGridNoCellCoords
;
5477 m_selectingBottomRight
= wxGridNoCellCoords
;
5479 // Show the edit control, if it has been hidden for
5481 ShowCellEditControl();
5484 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
5486 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5487 DoEndDragResizeRow();
5489 // Note: we are ending the event *after* doing
5490 // default processing in this case
5492 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
5494 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
5496 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5497 DoEndDragResizeCol();
5499 // Note: we are ending the event *after* doing
5500 // default processing in this case
5502 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
5509 // ------------ Right button down
5511 else if ( event
.RightDown() && coords
!= wxGridNoCellCoords
)
5513 DisableCellEditControl();
5514 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK
,
5519 // no default action at the moment
5524 // ------------ Right double click
5526 else if ( event
.RightDClick() && coords
!= wxGridNoCellCoords
)
5528 DisableCellEditControl();
5529 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK
,
5534 // no default action at the moment
5538 // ------------ Moving and no button action
5540 else if ( event
.Moving() && !event
.IsButton() )
5542 if( coords
.GetRow() < 0 || coords
.GetCol() < 0 )
5544 // out of grid cell area
5545 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5549 int dragRow
= YToEdgeOfRow( y
);
5550 int dragCol
= XToEdgeOfCol( x
);
5552 // Dragging on the corner of a cell to resize in both
5553 // directions is not implemented yet...
5555 if ( dragRow
>= 0 && dragCol
>= 0 )
5557 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5563 m_dragRowOrCol
= dragRow
;
5565 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5567 if ( CanDragRowSize() && CanDragGridSize() )
5568 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
);
5573 m_dragRowOrCol
= dragCol
;
5581 m_dragRowOrCol
= dragCol
;
5583 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
5585 if ( CanDragColSize() && CanDragGridSize() )
5586 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
);
5592 // Neither on a row or col edge
5594 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
5596 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
5602 void wxGrid::DoEndDragResizeRow()
5604 if ( m_dragLastPos
>= 0 )
5606 // erase the last line and resize the row
5608 int cw
, ch
, left
, dummy
;
5609 m_gridWin
->GetClientSize( &cw
, &ch
);
5610 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
5612 wxClientDC
dc( m_gridWin
);
5614 dc
.SetLogicalFunction( wxINVERT
);
5615 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
5616 HideCellEditControl();
5617 SaveEditControlValue();
5619 int rowTop
= GetRowTop(m_dragRowOrCol
);
5620 SetRowSize( m_dragRowOrCol
,
5621 wxMax( m_dragLastPos
- rowTop
, m_minAcceptableRowHeight
) );
5623 if ( !GetBatchCount() )
5625 // Only needed to get the correct rect.y:
5626 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
5628 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
5629 rect
.width
= m_rowLabelWidth
;
5630 rect
.height
= ch
- rect
.y
;
5631 m_rowLabelWin
->Refresh( TRUE
, &rect
);
5633 // if there is a multicell block, paint all of it
5636 int i
, cell_rows
, cell_cols
, subtract_rows
= 0;
5637 int leftCol
= XToCol(left
);
5638 int rightCol
= internalXToCol(left
+cw
);
5641 for (i
=leftCol
; i
<rightCol
; i
++)
5643 GetCellSize(m_dragRowOrCol
, i
, &cell_rows
, &cell_cols
);
5644 if (cell_rows
< subtract_rows
)
5645 subtract_rows
= cell_rows
;
5647 rect
.y
= GetRowTop(m_dragRowOrCol
+ subtract_rows
);
5648 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
5649 rect
.height
= ch
- rect
.y
;
5652 m_gridWin
->Refresh( FALSE
, &rect
);
5655 ShowCellEditControl();
5660 void wxGrid::DoEndDragResizeCol()
5662 if ( m_dragLastPos
>= 0 )
5664 // erase the last line and resize the col
5666 int cw
, ch
, dummy
, top
;
5667 m_gridWin
->GetClientSize( &cw
, &ch
);
5668 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
5670 wxClientDC
dc( m_gridWin
);
5672 dc
.SetLogicalFunction( wxINVERT
);
5673 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
5674 HideCellEditControl();
5675 SaveEditControlValue();
5677 int colLeft
= GetColLeft(m_dragRowOrCol
);
5678 SetColSize( m_dragRowOrCol
,
5679 wxMax( m_dragLastPos
- colLeft
,
5680 GetColMinimalWidth(m_dragRowOrCol
) ) );
5682 if ( !GetBatchCount() )
5684 // Only needed to get the correct rect.x:
5685 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
5687 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
5688 rect
.width
= cw
- rect
.x
;
5689 rect
.height
= m_colLabelHeight
;
5690 m_colLabelWin
->Refresh( TRUE
, &rect
);
5692 // if there is a multicell block, paint all of it
5695 int i
, cell_rows
, cell_cols
, subtract_cols
= 0;
5696 int topRow
= YToRow(top
);
5697 int bottomRow
= internalYToRow(top
+cw
);
5700 for (i
=topRow
; i
<bottomRow
; i
++)
5702 GetCellSize(i
, m_dragRowOrCol
, &cell_rows
, &cell_cols
);
5703 if (cell_cols
< subtract_cols
)
5704 subtract_cols
= cell_cols
;
5706 rect
.x
= GetColLeft(m_dragRowOrCol
+ subtract_cols
);
5707 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
5708 rect
.width
= cw
- rect
.x
;
5711 m_gridWin
->Refresh( FALSE
, &rect
);
5714 ShowCellEditControl();
5721 // ------ interaction with data model
5723 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
5725 switch ( msg
.GetId() )
5727 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
5728 return GetModelValues();
5730 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
5731 return SetModelValues();
5733 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
5734 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
5735 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
5736 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
5737 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
5738 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
5739 return Redimension( msg
);
5748 // The behaviour of this function depends on the grid table class
5749 // Clear() function. For the default wxGridStringTable class the
5750 // behavious is to replace all cell contents with wxEmptyString but
5751 // not to change the number of rows or cols.
5753 void wxGrid::ClearGrid()
5757 if (IsCellEditControlEnabled())
5758 DisableCellEditControl();
5761 if ( !GetBatchCount() ) m_gridWin
->Refresh();
5766 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
5768 // TODO: something with updateLabels flag
5772 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
5778 if (IsCellEditControlEnabled())
5779 DisableCellEditControl();
5781 bool done
= m_table
->InsertRows( pos
, numRows
);
5784 // the table will have sent the results of the insert row
5785 // operation to this view object as a grid table message
5791 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
5793 // TODO: something with updateLabels flag
5797 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
5803 bool done
= m_table
&& m_table
->AppendRows( numRows
);
5805 // the table will have sent the results of the append row
5806 // operation to this view object as a grid table message
5812 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
5814 // TODO: something with updateLabels flag
5818 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
5824 if (IsCellEditControlEnabled())
5825 DisableCellEditControl();
5827 bool done
= m_table
->DeleteRows( pos
, numRows
);
5829 // the table will have sent the results of the delete row
5830 // operation to this view object as a grid table message
5836 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
5838 // TODO: something with updateLabels flag
5842 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
5848 if (IsCellEditControlEnabled())
5849 DisableCellEditControl();
5851 bool done
= m_table
->InsertCols( pos
, numCols
);
5853 // the table will have sent the results of the insert col
5854 // operation to this view object as a grid table message
5860 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
5862 // TODO: something with updateLabels flag
5866 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
5872 bool done
= m_table
->AppendCols( numCols
);
5874 // the table will have sent the results of the append col
5875 // operation to this view object as a grid table message
5881 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
5883 // TODO: something with updateLabels flag
5887 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
5893 if (IsCellEditControlEnabled())
5894 DisableCellEditControl();
5896 bool done
= m_table
->DeleteCols( pos
, numCols
);
5898 // the table will have sent the results of the delete col
5899 // operation to this view object as a grid table message
5907 // ----- event handlers
5910 // Generate a grid event based on a mouse event and
5911 // return the result of ProcessEvent()
5913 int wxGrid::SendEvent( const wxEventType type
,
5915 wxMouseEvent
& mouseEv
)
5920 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
5922 int rowOrCol
= (row
== -1 ? col
: row
);
5924 wxGridSizeEvent
gridEvt( GetId(),
5928 mouseEv
.GetX() + GetRowLabelSize(),
5929 mouseEv
.GetY() + GetColLabelSize(),
5930 mouseEv
.ControlDown(),
5931 mouseEv
.ShiftDown(),
5933 mouseEv
.MetaDown() );
5935 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5936 vetoed
= !gridEvt
.IsAllowed();
5938 else if ( type
== wxEVT_GRID_RANGE_SELECT
)
5940 // Right now, it should _never_ end up here!
5941 wxGridRangeSelectEvent
gridEvt( GetId(),
5945 m_selectingBottomRight
,
5947 mouseEv
.ControlDown(),
5948 mouseEv
.ShiftDown(),
5950 mouseEv
.MetaDown() );
5952 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5953 vetoed
= !gridEvt
.IsAllowed();
5957 wxGridEvent
gridEvt( GetId(),
5961 mouseEv
.GetX() + GetRowLabelSize(),
5962 mouseEv
.GetY() + GetColLabelSize(),
5964 mouseEv
.ControlDown(),
5965 mouseEv
.ShiftDown(),
5967 mouseEv
.MetaDown() );
5968 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5969 vetoed
= !gridEvt
.IsAllowed();
5972 // A Veto'd event may not be `claimed' so test this first
5973 if (vetoed
) return -1;
5974 return claimed
? 1 : 0;
5978 // Generate a grid event of specified type and return the result
5979 // of ProcessEvent().
5981 int wxGrid::SendEvent( const wxEventType type
,
5987 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
5989 int rowOrCol
= (row
== -1 ? col
: row
);
5991 wxGridSizeEvent
gridEvt( GetId(),
5996 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
5997 vetoed
= !gridEvt
.IsAllowed();
6001 wxGridEvent
gridEvt( GetId(),
6006 claimed
= GetEventHandler()->ProcessEvent(gridEvt
);
6007 vetoed
= !gridEvt
.IsAllowed();
6010 // A Veto'd event may not be `claimed' so test this first
6011 if (vetoed
) return -1;
6012 return claimed
? 1 : 0;
6016 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
6018 wxPaintDC
dc(this); // needed to prevent zillions of paint events on MSW
6021 void wxGrid::Refresh(bool eraseb
, const wxRect
* rect
)
6023 // Don't do anything if between Begin/EndBatch...
6024 // EndBatch() will do all this on the last nested one anyway.
6025 if (! GetBatchCount())
6027 // Refresh to get correct scrolled position:
6028 wxScrolledWindow::Refresh(eraseb
,rect
);
6032 int rect_x
, rect_y
, rectWidth
, rectHeight
;
6033 int width_label
, width_cell
, height_label
, height_cell
;
6036 //Copy rectangle can get scroll offsets..
6037 rect_x
= rect
->GetX();
6038 rect_y
= rect
->GetY();
6039 rectWidth
= rect
->GetWidth();
6040 rectHeight
= rect
->GetHeight();
6042 width_label
= m_rowLabelWidth
- rect_x
;
6043 if (width_label
> rectWidth
) width_label
= rectWidth
;
6045 height_label
= m_colLabelHeight
- rect_y
;
6046 if (height_label
> rectHeight
) height_label
= rectHeight
;
6048 if (rect_x
> m_rowLabelWidth
)
6050 x
= rect_x
- m_rowLabelWidth
;
6051 width_cell
= rectWidth
;
6056 width_cell
= rectWidth
- (m_rowLabelWidth
- rect_x
);
6059 if (rect_y
> m_colLabelHeight
)
6061 y
= rect_y
- m_colLabelHeight
;
6062 height_cell
= rectHeight
;
6067 height_cell
= rectHeight
- (m_colLabelHeight
- rect_y
);
6070 // Paint corner label part intersecting rect.
6071 if ( width_label
> 0 && height_label
> 0 )
6073 wxRect
anotherrect(rect_x
, rect_y
, width_label
, height_label
);
6074 m_cornerLabelWin
->Refresh(eraseb
, &anotherrect
);
6077 // Paint col labels part intersecting rect.
6078 if ( width_cell
> 0 && height_label
> 0 )
6080 wxRect
anotherrect(x
, rect_y
, width_cell
, height_label
);
6081 m_colLabelWin
->Refresh(eraseb
, &anotherrect
);
6084 // Paint row labels part intersecting rect.
6085 if ( width_label
> 0 && height_cell
> 0 )
6087 wxRect
anotherrect(rect_x
, y
, width_label
, height_cell
);
6088 m_rowLabelWin
->Refresh(eraseb
, &anotherrect
);
6091 // Paint cell area part intersecting rect.
6092 if ( width_cell
> 0 && height_cell
> 0 )
6094 wxRect
anotherrect(x
, y
, width_cell
, height_cell
);
6095 m_gridWin
->Refresh(eraseb
, &anotherrect
);
6100 m_cornerLabelWin
->Refresh(eraseb
, NULL
);
6101 m_colLabelWin
->Refresh(eraseb
, NULL
);
6102 m_rowLabelWin
->Refresh(eraseb
, NULL
);
6103 m_gridWin
->Refresh(eraseb
, NULL
);
6108 void wxGrid::OnSize( wxSizeEvent
& event
)
6110 // position the child windows
6113 // don't call CalcDimensions() from here, the base class handles the size
6119 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
6121 if ( m_inOnKeyDown
)
6123 // shouldn't be here - we are going round in circles...
6125 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
6128 m_inOnKeyDown
= TRUE
;
6130 // propagate the event up and see if it gets processed
6132 wxWindow
*parent
= GetParent();
6133 wxKeyEvent
keyEvt( event
);
6134 keyEvt
.SetEventObject( parent
);
6136 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
6139 // try local handlers
6141 switch ( event
.GetKeyCode() )
6144 if ( event
.ControlDown() )
6146 MoveCursorUpBlock( event
.ShiftDown() );
6150 MoveCursorUp( event
.ShiftDown() );
6155 if ( event
.ControlDown() )
6157 MoveCursorDownBlock( event
.ShiftDown() );
6161 MoveCursorDown( event
.ShiftDown() );
6166 if ( event
.ControlDown() )
6168 MoveCursorLeftBlock( event
.ShiftDown() );
6172 MoveCursorLeft( event
.ShiftDown() );
6177 if ( event
.ControlDown() )
6179 MoveCursorRightBlock( event
.ShiftDown() );
6183 MoveCursorRight( event
.ShiftDown() );
6188 case WXK_NUMPAD_ENTER
:
6189 if ( event
.ControlDown() )
6191 event
.Skip(); // to let the edit control have the return
6195 if ( GetGridCursorRow() < GetNumberRows()-1 )
6197 MoveCursorDown( event
.ShiftDown() );
6201 // at the bottom of a column
6202 HideCellEditControl();
6203 SaveEditControlValue();
6213 if (event
.ShiftDown())
6215 if ( GetGridCursorCol() > 0 )
6217 MoveCursorLeft( FALSE
);
6222 HideCellEditControl();
6223 SaveEditControlValue();
6228 if ( GetGridCursorCol() < GetNumberCols()-1 )
6230 MoveCursorRight( FALSE
);
6235 HideCellEditControl();
6236 SaveEditControlValue();
6242 if ( event
.ControlDown() )
6244 MakeCellVisible( 0, 0 );
6245 SetCurrentCell( 0, 0 );
6254 if ( event
.ControlDown() )
6256 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
6257 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
6274 if ( event
.ControlDown() )
6278 m_selection
->ToggleCellSelection( m_currentCellCoords
.GetRow(),
6279 m_currentCellCoords
.GetCol(),
6280 event
.ControlDown(),
6287 if ( !IsEditable() )
6289 MoveCursorRight( FALSE
);
6292 // Otherwise fall through to default
6295 // is it possible to edit the current cell at all?
6296 if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
6298 // yes, now check whether the cells editor accepts the key
6299 int row
= m_currentCellCoords
.GetRow();
6300 int col
= m_currentCellCoords
.GetCol();
6301 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6302 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
6304 // <F2> is special and will always start editing, for
6305 // other keys - ask the editor itself
6306 if ( (event
.GetKeyCode() == WXK_F2
&& !event
.HasModifiers())
6307 || editor
->IsAcceptedKey(event
) )
6309 // ensure cell is visble
6310 MakeCellVisible(row
, col
);
6311 EnableCellEditControl();
6313 // a problem can arise if the cell is not completely
6314 // visible (even after calling MakeCellVisible the
6315 // control is not created and calling StartingKey will
6317 if( editor
->IsCreated() && m_cellEditCtrlEnabled
) editor
->StartingKey(event
);
6329 // let others process char events with modifiers or all
6330 // char events for readonly cells
6337 m_inOnKeyDown
= FALSE
;
6340 void wxGrid::OnKeyUp( wxKeyEvent
& event
)
6342 // try local handlers
6344 if ( event
.GetKeyCode() == WXK_SHIFT
)
6346 if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
6347 m_selectingBottomRight
!= wxGridNoCellCoords
)
6351 m_selection
->SelectBlock( m_selectingTopLeft
.GetRow(),
6352 m_selectingTopLeft
.GetCol(),
6353 m_selectingBottomRight
.GetRow(),
6354 m_selectingBottomRight
.GetCol(),
6355 event
.ControlDown(),
6362 m_selectingTopLeft
= wxGridNoCellCoords
;
6363 m_selectingBottomRight
= wxGridNoCellCoords
;
6364 m_selectingKeyboard
= wxGridNoCellCoords
;
6368 void wxGrid::OnEraseBackground(wxEraseEvent
&)
6372 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
6374 if ( SendEvent( wxEVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
6376 // the event has been intercepted - do nothing
6380 wxClientDC
dc(m_gridWin
);
6383 if ( m_currentCellCoords
!= wxGridNoCellCoords
)
6385 HideCellEditControl();
6386 DisableCellEditControl();
6388 if ( IsVisible( m_currentCellCoords
, FALSE
) )
6391 r
= BlockToDeviceRect(m_currentCellCoords
, m_currentCellCoords
);
6392 if ( !m_gridLinesEnabled
)
6400 wxGridCellCoordsArray cells
= CalcCellsExposed( r
);
6402 // Otherwise refresh redraws the highlight!
6403 m_currentCellCoords
= coords
;
6405 DrawGridCellArea(dc
,cells
);
6406 DrawAllGridLines( dc
, r
);
6410 m_currentCellCoords
= coords
;
6412 wxGridCellAttr
* attr
= GetCellAttr(coords
);
6413 DrawCellHighlight(dc
, attr
);
6418 void wxGrid::HighlightBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
6421 wxGridCellCoords updateTopLeft
, updateBottomRight
;
6425 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectRows
)
6428 rightCol
= GetNumberCols() - 1;
6430 else if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectColumns
)
6433 bottomRow
= GetNumberRows() - 1;
6437 if ( topRow
> bottomRow
)
6444 if ( leftCol
> rightCol
)
6451 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
6452 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
6454 // First the case that we selected a completely new area
6455 if ( m_selectingTopLeft
== wxGridNoCellCoords
||
6456 m_selectingBottomRight
== wxGridNoCellCoords
)
6459 rect
= BlockToDeviceRect( wxGridCellCoords ( topRow
, leftCol
),
6460 wxGridCellCoords ( bottomRow
, rightCol
) );
6461 m_gridWin
->Refresh( FALSE
, &rect
);
6463 // Now handle changing an existing selection area.
6464 else if ( m_selectingTopLeft
!= updateTopLeft
||
6465 m_selectingBottomRight
!= updateBottomRight
)
6467 // Compute two optimal update rectangles:
6468 // Either one rectangle is a real subset of the
6469 // other, or they are (almost) disjoint!
6471 bool need_refresh
[4];
6475 need_refresh
[3] = FALSE
;
6478 // Store intermediate values
6479 wxCoord oldLeft
= m_selectingTopLeft
.GetCol();
6480 wxCoord oldTop
= m_selectingTopLeft
.GetRow();
6481 wxCoord oldRight
= m_selectingBottomRight
.GetCol();
6482 wxCoord oldBottom
= m_selectingBottomRight
.GetRow();
6484 // Determine the outer/inner coordinates.
6485 if (oldLeft
> leftCol
)
6491 if (oldTop
> topRow
)
6497 if (oldRight
< rightCol
)
6500 oldRight
= rightCol
;
6503 if (oldBottom
< bottomRow
)
6506 oldBottom
= bottomRow
;
6510 // Now, either the stuff marked old is the outer
6511 // rectangle or we don't have a situation where one
6512 // is contained in the other.
6514 if ( oldLeft
< leftCol
)
6516 // Refresh the newly selected or deselected
6517 // area to the left of the old or new selection.
6518 need_refresh
[0] = TRUE
;
6519 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6521 wxGridCellCoords ( oldBottom
,
6525 if ( oldTop
< topRow
)
6527 // Refresh the newly selected or deselected
6528 // area above the old or new selection.
6529 need_refresh
[1] = TRUE
;
6530 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6532 wxGridCellCoords ( topRow
- 1,
6536 if ( oldRight
> rightCol
)
6538 // Refresh the newly selected or deselected
6539 // area to the right of the old or new selection.
6540 need_refresh
[2] = TRUE
;
6541 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6543 wxGridCellCoords ( oldBottom
,
6547 if ( oldBottom
> bottomRow
)
6549 // Refresh the newly selected or deselected
6550 // area below the old or new selection.
6551 need_refresh
[3] = TRUE
;
6552 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
6554 wxGridCellCoords ( oldBottom
,
6558 // various Refresh() calls
6559 for (i
= 0; i
< 4; i
++ )
6560 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
6561 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
6564 m_selectingTopLeft
= updateTopLeft
;
6565 m_selectingBottomRight
= updateBottomRight
;
6569 // ------ functions to get/send data (see also public functions)
6572 bool wxGrid::GetModelValues()
6574 // Hide the editor, so it won't hide a changed value.
6575 HideCellEditControl();
6579 // all we need to do is repaint the grid
6581 m_gridWin
->Refresh();
6589 bool wxGrid::SetModelValues()
6593 // Disable the editor, so it won't hide a changed value.
6594 // Do we also want to save the current value of the editor first?
6596 DisableCellEditControl();
6600 for ( row
= 0; row
< m_numRows
; row
++ )
6602 for ( col
= 0; col
< m_numCols
; col
++ )
6604 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
6616 // Note - this function only draws cells that are in the list of
6617 // exposed cells (usually set from the update region by
6618 // CalcExposedCells)
6620 void wxGrid::DrawGridCellArea( wxDC
& dc
, const wxGridCellCoordsArray
& cells
)
6622 if ( !m_numRows
|| !m_numCols
) return;
6624 int i
, numCells
= cells
.GetCount();
6625 int row
, col
, cell_rows
, cell_cols
;
6626 wxGridCellCoordsArray redrawCells
;
6628 for ( i
= numCells
-1; i
>= 0; i
-- )
6630 row
= cells
[i
].GetRow();
6631 col
= cells
[i
].GetCol();
6632 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
6634 // If this cell is part of a multicell block, find owner for repaint
6635 if ( cell_rows
<= 0 || cell_cols
<= 0 )
6637 wxGridCellCoords
cell(row
+cell_rows
, col
+cell_cols
);
6638 bool marked
= FALSE
;
6639 for ( int j
= 0; j
< numCells
; j
++ )
6641 if ( cell
== cells
[j
] )
6649 int count
= redrawCells
.GetCount();
6650 for (int j
= 0; j
< count
; j
++)
6652 if ( cell
== redrawCells
[j
] )
6658 if (!marked
) redrawCells
.Add( cell
);
6660 continue; // don't bother drawing this cell
6663 // If this cell is empty, find cell to left that might want to overflow
6664 if (m_table
&& m_table
->IsEmptyCell(row
, col
))
6666 for ( int l
= 0; l
< cell_rows
; l
++ )
6668 // find a cell in this row to left alreay marked for repaint
6670 for (int k
= 0; k
< int(redrawCells
.GetCount()); k
++)
6671 if ((redrawCells
[k
].GetCol() < left
) &&
6672 (redrawCells
[k
].GetRow() == row
))
6673 left
=redrawCells
[k
].GetCol();
6675 if (left
== col
) left
= 0; // oh well
6677 for (int j
= col
-1; j
>= left
; j
--)
6679 if (!m_table
->IsEmptyCell(row
+l
, j
))
6681 if (GetCellOverflow(row
+l
, j
))
6683 wxGridCellCoords
cell(row
+l
, j
);
6684 bool marked
= FALSE
;
6686 for (int k
= 0; k
< numCells
; k
++)
6688 if ( cell
== cells
[k
] )
6696 int count
= redrawCells
.GetCount();
6697 for (int k
= 0; k
< count
; k
++)
6699 if ( cell
== redrawCells
[k
] )
6705 if (!marked
) redrawCells
.Add( cell
);
6713 DrawCell( dc
, cells
[i
] );
6716 numCells
= redrawCells
.GetCount();
6718 for ( i
= numCells
- 1; i
>= 0; i
-- )
6720 DrawCell( dc
, redrawCells
[i
] );
6725 void wxGrid::DrawGridSpace( wxDC
& dc
)
6728 m_gridWin
->GetClientSize( &cw
, &ch
);
6731 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6733 int rightCol
= m_numCols
> 0 ? GetColRight(m_numCols
- 1) : 0;
6734 int bottomRow
= m_numRows
> 0 ? GetRowBottom(m_numRows
- 1) : 0 ;
6736 if ( right
> rightCol
|| bottom
> bottomRow
)
6739 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6741 dc
.SetBrush( wxBrush(GetDefaultCellBackgroundColour(), wxSOLID
) );
6742 dc
.SetPen( *wxTRANSPARENT_PEN
);
6744 if ( right
> rightCol
)
6746 dc
.DrawRectangle( rightCol
, top
, right
- rightCol
, ch
);
6749 if ( bottom
> bottomRow
)
6751 dc
.DrawRectangle( left
, bottomRow
, cw
, bottom
- bottomRow
);
6757 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
6759 int row
= coords
.GetRow();
6760 int col
= coords
.GetCol();
6762 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6765 // we draw the cell border ourselves
6766 #if !WXGRID_DRAW_LINES
6767 if ( m_gridLinesEnabled
)
6768 DrawCellBorder( dc
, coords
);
6771 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6773 bool isCurrent
= coords
== m_currentCellCoords
;
6775 wxRect rect
= CellToRect( row
, col
);
6777 // if the editor is shown, we should use it and not the renderer
6778 // Note: However, only if it is really _shown_, i.e. not hidden!
6779 if ( isCurrent
&& IsCellEditControlShown() )
6781 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
6782 editor
->PaintBackground(rect
, attr
);
6787 // but all the rest is drawn by the cell renderer and hence may be
6789 wxGridCellRenderer
*renderer
= attr
->GetRenderer(this, row
, col
);
6790 renderer
->Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
6797 void wxGrid::DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
)
6799 int row
= m_currentCellCoords
.GetRow();
6800 int col
= m_currentCellCoords
.GetCol();
6802 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6805 wxRect rect
= CellToRect(row
, col
);
6807 // hmmm... what could we do here to show that the cell is disabled?
6808 // for now, I just draw a thinner border than for the other ones, but
6809 // it doesn't look really good
6811 int penWidth
= attr
->IsReadOnly() ? m_cellHighlightROPenWidth
: m_cellHighlightPenWidth
;
6815 // The center of th drawn line is where the position/width/height of
6816 // the rectangle is actually at, (on wxMSW atr least,) so we will
6817 // reduce the size of the rectangle to compensate for the thickness of
6818 // the line. If this is too strange on non wxMSW platforms then
6819 // please #ifdef this appropriately.
6820 rect
.x
+= penWidth
/2;
6821 rect
.y
+= penWidth
/2;
6822 rect
.width
-= penWidth
-1;
6823 rect
.height
-= penWidth
-1;
6826 // Now draw the rectangle
6827 // use the cellHighlightColour if the cell is inside a selection, this
6828 // will ensure the cell is always visible.
6829 dc
.SetPen(wxPen(IsInSelection(row
,col
)?m_selectionForeground
:m_cellHighlightColour
, penWidth
, wxSOLID
));
6830 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
6831 dc
.DrawRectangle(rect
);
6835 // VZ: my experiments with 3d borders...
6837 // how to properly set colours for arbitrary bg?
6838 wxCoord x1
= rect
.x
,
6840 x2
= rect
.x
+ rect
.width
-1,
6841 y2
= rect
.y
+ rect
.height
-1;
6843 dc
.SetPen(*wxWHITE_PEN
);
6844 dc
.DrawLine(x1
, y1
, x2
, y1
);
6845 dc
.DrawLine(x1
, y1
, x1
, y2
);
6847 dc
.DrawLine(x1
+ 1, y2
- 1, x2
- 1, y2
- 1);
6848 dc
.DrawLine(x2
- 1, y1
+ 1, x2
- 1, y2
);
6850 dc
.SetPen(*wxBLACK_PEN
);
6851 dc
.DrawLine(x1
, y2
, x2
, y2
);
6852 dc
.DrawLine(x2
, y1
, x2
, y2
+1);
6857 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
6859 int row
= coords
.GetRow();
6860 int col
= coords
.GetCol();
6861 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
6864 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
6866 wxRect rect
= CellToRect( row
, col
);
6868 // right hand border
6870 dc
.DrawLine( rect
.x
+ rect
.width
, rect
.y
,
6871 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
+ 1 );
6875 dc
.DrawLine( rect
.x
, rect
.y
+ rect
.height
,
6876 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
6879 void wxGrid::DrawHighlight(wxDC
& dc
,const wxGridCellCoordsArray
& cells
)
6881 // This if block was previously in wxGrid::OnPaint but that doesn't
6882 // seem to get called under wxGTK - MB
6884 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
6885 m_numRows
&& m_numCols
)
6887 m_currentCellCoords
.Set(0, 0);
6890 if ( IsCellEditControlShown() )
6892 // don't show highlight when the edit control is shown
6896 // if the active cell was repainted, repaint its highlight too because it
6897 // might have been damaged by the grid lines
6898 size_t count
= cells
.GetCount();
6899 for ( size_t n
= 0; n
< count
; n
++ )
6901 if ( cells
[n
] == m_currentCellCoords
)
6903 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
6904 DrawCellHighlight(dc
, attr
);
6912 // TODO: remove this ???
6913 // This is used to redraw all grid lines e.g. when the grid line colour
6916 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& WXUNUSED(reg
) )
6918 #if !WXGRID_DRAW_LINES
6922 if ( !m_gridLinesEnabled
||
6924 !m_numCols
) return;
6926 int top
, bottom
, left
, right
;
6928 #if 0 //#ifndef __WXGTK__
6932 m_gridWin
->GetClientSize(&cw
, &ch
);
6934 // virtual coords of visible area
6936 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6937 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6942 reg
.GetBox(x
, y
, w
, h
);
6943 CalcUnscrolledPosition( x
, y
, &left
, &top
);
6944 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
6948 m_gridWin
->GetClientSize(&cw
, &ch
);
6949 CalcUnscrolledPosition( 0, 0, &left
, &top
);
6950 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
6953 // avoid drawing grid lines past the last row and col
6955 right
= wxMin( right
, GetColRight(m_numCols
- 1) );
6956 bottom
= wxMin( bottom
, GetRowBottom(m_numRows
- 1) );
6958 // no gridlines inside multicells, clip them out
6959 int leftCol
= internalXToCol(left
);
6960 int topRow
= internalYToRow(top
);
6961 int rightCol
= internalXToCol(right
);
6962 int bottomRow
= internalYToRow(bottom
);
6963 wxRegion
clippedcells(0, 0, cw
, ch
);
6966 int i
, j
, cell_rows
, cell_cols
;
6969 for (j
=topRow
; j
<bottomRow
; j
++)
6971 for (i
=leftCol
; i
<rightCol
; i
++)
6973 GetCellSize( j
, i
, &cell_rows
, &cell_cols
);
6974 if ((cell_rows
> 1) || (cell_cols
> 1))
6976 rect
= CellToRect(j
,i
);
6977 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
6978 clippedcells
.Subtract(rect
);
6980 else if ((cell_rows
< 0) || (cell_cols
< 0))
6982 rect
= CellToRect(j
+cell_rows
, i
+cell_cols
);
6983 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
6984 clippedcells
.Subtract(rect
);
6988 dc
.SetClippingRegion( clippedcells
);
6990 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
6992 // horizontal grid lines
6994 // already declared above - int i;
6995 for ( i
= internalYToRow(top
); i
< m_numRows
; i
++ )
6997 int bot
= GetRowBottom(i
) - 1;
7006 dc
.DrawLine( left
, bot
, right
, bot
);
7011 // vertical grid lines
7013 for ( i
= internalXToCol(left
); i
< m_numCols
; i
++ )
7015 int colRight
= GetColRight(i
) - 1;
7016 if ( colRight
> right
)
7021 if ( colRight
>= left
)
7023 dc
.DrawLine( colRight
, top
, colRight
, bottom
);
7026 dc
.DestroyClippingRegion();
7030 void wxGrid::DrawRowLabels( wxDC
& dc
,const wxArrayInt
& rows
)
7032 if ( !m_numRows
) return;
7035 size_t numLabels
= rows
.GetCount();
7037 for ( i
= 0; i
< numLabels
; i
++ )
7039 DrawRowLabel( dc
, rows
[i
] );
7044 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
7046 if ( GetRowHeight(row
) <= 0 )
7049 int rowTop
= GetRowTop(row
),
7050 rowBottom
= GetRowBottom(row
) - 1;
7052 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
),1, wxSOLID
) );
7053 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
7054 m_rowLabelWidth
-1, rowBottom
);
7056 dc
.DrawLine( 0, rowTop
, 0, rowBottom
);
7058 dc
.DrawLine( 0, rowBottom
, m_rowLabelWidth
, rowBottom
);
7060 dc
.SetPen( *wxWHITE_PEN
);
7061 dc
.DrawLine( 1, rowTop
, 1, rowBottom
);
7062 dc
.DrawLine( 1, rowTop
, m_rowLabelWidth
-1, rowTop
);
7064 dc
.SetBackgroundMode( wxTRANSPARENT
);
7065 dc
.SetTextForeground( GetLabelTextColour() );
7066 dc
.SetFont( GetLabelFont() );
7069 GetRowLabelAlignment( &hAlign
, &vAlign
);
7073 rect
.SetY( GetRowTop(row
) + 2 );
7074 rect
.SetWidth( m_rowLabelWidth
- 4 );
7075 rect
.SetHeight( GetRowHeight(row
) - 4 );
7076 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
7080 void wxGrid::DrawColLabels( wxDC
& dc
,const wxArrayInt
& cols
)
7082 if ( !m_numCols
) return;
7085 size_t numLabels
= cols
.GetCount();
7087 for ( i
= 0; i
< numLabels
; i
++ )
7089 DrawColLabel( dc
, cols
[i
] );
7094 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
7096 if ( GetColWidth(col
) <= 0 )
7099 int colLeft
= GetColLeft(col
),
7100 colRight
= GetColRight(col
) - 1;
7102 dc
.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
),1, wxSOLID
) );
7103 dc
.DrawLine( colRight
, 0,
7104 colRight
, m_colLabelHeight
-1 );
7106 dc
.DrawLine( colLeft
, 0, colRight
, 0 );
7108 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
7109 colRight
+1, m_colLabelHeight
-1 );
7111 dc
.SetPen( *wxWHITE_PEN
);
7112 dc
.DrawLine( colLeft
, 1, colLeft
, m_colLabelHeight
-1 );
7113 dc
.DrawLine( colLeft
, 1, colRight
, 1 );
7115 dc
.SetBackgroundMode( wxTRANSPARENT
);
7116 dc
.SetTextForeground( GetLabelTextColour() );
7117 dc
.SetFont( GetLabelFont() );
7119 int hAlign
, vAlign
, orient
;
7120 GetColLabelAlignment( &hAlign
, &vAlign
);
7121 orient
= GetColLabelTextOrientation();
7124 rect
.SetX( colLeft
+ 2 );
7126 rect
.SetWidth( GetColWidth(col
) - 4 );
7127 rect
.SetHeight( m_colLabelHeight
- 4 );
7128 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
, orient
);
7131 void wxGrid::DrawTextRectangle( wxDC
& dc
,
7132 const wxString
& value
,
7136 int textOrientation
)
7138 wxArrayString lines
;
7140 StringToLines( value
, lines
);
7143 //Forward to new API.
7144 DrawTextRectangle( dc
,
7153 void wxGrid::DrawTextRectangle( wxDC
& dc
,
7154 const wxArrayString
& lines
,
7158 int textOrientation
)
7160 long textWidth
, textHeight
;
7161 long lineWidth
, lineHeight
;
7164 dc
.SetClippingRegion( rect
);
7166 nLines
= lines
.GetCount();
7170 float x
= 0.0, y
= 0.0;
7172 if( textOrientation
== wxHORIZONTAL
)
7173 GetTextBoxSize(dc
, lines
, &textWidth
, &textHeight
);
7175 GetTextBoxSize( dc
, lines
, &textHeight
, &textWidth
);
7179 case wxALIGN_BOTTOM
:
7180 if( textOrientation
== wxHORIZONTAL
)
7181 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
7183 x
= rect
.x
+ rect
.width
- textWidth
;
7186 case wxALIGN_CENTRE
:
7187 if( textOrientation
== wxHORIZONTAL
)
7188 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
7190 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
7195 if( textOrientation
== wxHORIZONTAL
)
7202 // Align each line of a multi-line label
7203 for( l
= 0; l
< nLines
; l
++ )
7205 dc
.GetTextExtent(lines
[l
], &lineWidth
, &lineHeight
);
7207 switch( horizAlign
)
7210 if( textOrientation
== wxHORIZONTAL
)
7211 x
= rect
.x
+ (rect
.width
- lineWidth
- 1);
7213 y
= rect
.y
+ lineWidth
+ 1;
7216 case wxALIGN_CENTRE
:
7217 if( textOrientation
== wxHORIZONTAL
)
7218 x
= rect
.x
+ ((rect
.width
- lineWidth
)/2);
7220 y
= rect
.y
+ rect
.height
- ((rect
.height
- lineWidth
)/2);
7225 if( textOrientation
== wxHORIZONTAL
)
7228 y
= rect
.y
+ rect
.height
- 1;
7232 if( textOrientation
== wxHORIZONTAL
)
7234 dc
.DrawText( lines
[l
], (int)x
, (int)y
);
7239 dc
.DrawRotatedText( lines
[l
], (int)x
, (int)y
, 90.0 );
7244 dc
.DestroyClippingRegion();
7248 // Split multi line text up into an array of strings. Any existing
7249 // contents of the string array are preserved.
7251 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
7255 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
7256 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
7258 while ( startPos
< (int)tVal
.Length() )
7260 pos
= tVal
.Mid(startPos
).Find( eol
);
7265 else if ( pos
== 0 )
7267 lines
.Add( wxEmptyString
);
7271 lines
.Add( value
.Mid(startPos
, pos
) );
7275 if ( startPos
< (int)value
.Length() )
7277 lines
.Add( value
.Mid( startPos
) );
7282 void wxGrid::GetTextBoxSize( wxDC
& dc
,
7283 const wxArrayString
& lines
,
7284 long *width
, long *height
)
7291 for ( i
= 0; i
< lines
.GetCount(); i
++ )
7293 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
7294 w
= wxMax( w
, lineW
);
7303 // ------ Batch processing.
7305 void wxGrid::EndBatch()
7307 if ( m_batchCount
> 0 )
7310 if ( !m_batchCount
)
7313 m_rowLabelWin
->Refresh();
7314 m_colLabelWin
->Refresh();
7315 m_cornerLabelWin
->Refresh();
7316 m_gridWin
->Refresh();
7321 // Use this, rather than wxWindow::Refresh(), to force an immediate
7322 // repainting of the grid. Has no effect if you are already inside a
7323 // BeginBatch / EndBatch block.
7325 void wxGrid::ForceRefresh()
7333 // ------ Edit control functions
7337 void wxGrid::EnableEditing( bool edit
)
7339 // TODO: improve this ?
7341 if ( edit
!= m_editable
)
7343 if(!edit
) EnableCellEditControl(edit
);
7349 void wxGrid::EnableCellEditControl( bool enable
)
7354 if ( m_currentCellCoords
== wxGridNoCellCoords
)
7355 SetCurrentCell( 0, 0 );
7357 if ( enable
!= m_cellEditCtrlEnabled
)
7361 if (SendEvent( wxEVT_GRID_EDITOR_SHOWN
) <0)
7364 // this should be checked by the caller!
7365 wxASSERT_MSG( CanEnableCellControl(),
7366 _T("can't enable editing for this cell!") );
7368 // do it before ShowCellEditControl()
7369 m_cellEditCtrlEnabled
= enable
;
7371 ShowCellEditControl();
7375 //FIXME:add veto support
7376 SendEvent( wxEVT_GRID_EDITOR_HIDDEN
);
7378 HideCellEditControl();
7379 SaveEditControlValue();
7381 // do it after HideCellEditControl()
7382 m_cellEditCtrlEnabled
= enable
;
7387 bool wxGrid::IsCurrentCellReadOnly() const
7390 wxGridCellAttr
* attr
= ((wxGrid
*)this)->GetCellAttr(m_currentCellCoords
);
7391 bool readonly
= attr
->IsReadOnly();
7397 bool wxGrid::CanEnableCellControl() const
7399 return m_editable
&& !IsCurrentCellReadOnly();
7402 bool wxGrid::IsCellEditControlEnabled() const
7404 // the cell edit control might be disable for all cells or just for the
7405 // current one if it's read only
7406 return m_cellEditCtrlEnabled
? !IsCurrentCellReadOnly() : FALSE
;
7409 bool wxGrid::IsCellEditControlShown() const
7411 bool isShown
= FALSE
;
7413 if ( m_cellEditCtrlEnabled
)
7415 int row
= m_currentCellCoords
.GetRow();
7416 int col
= m_currentCellCoords
.GetCol();
7417 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7418 wxGridCellEditor
* editor
= attr
->GetEditor((wxGrid
*) this, row
, col
);
7423 if ( editor
->IsCreated() )
7425 isShown
= editor
->GetControl()->IsShown();
7435 void wxGrid::ShowCellEditControl()
7437 if ( IsCellEditControlEnabled() )
7439 if ( !IsVisible( m_currentCellCoords
) )
7441 m_cellEditCtrlEnabled
= FALSE
;
7446 wxRect rect
= CellToRect( m_currentCellCoords
);
7447 int row
= m_currentCellCoords
.GetRow();
7448 int col
= m_currentCellCoords
.GetCol();
7450 // if this is part of a multicell, find owner (topleft)
7451 int cell_rows
, cell_cols
;
7452 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7453 if ( cell_rows
<= 0 || cell_cols
<= 0 )
7457 m_currentCellCoords
.SetRow( row
);
7458 m_currentCellCoords
.SetCol( col
);
7461 // convert to scrolled coords
7463 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
7465 // done in PaintBackground()
7467 // erase the highlight and the cell contents because the editor
7468 // might not cover the entire cell
7469 wxClientDC
dc( m_gridWin
);
7471 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
); //wxBrush(attr->GetBackgroundColour(), wxSOLID));
7472 dc
.SetPen(*wxTRANSPARENT_PEN
);
7473 dc
.DrawRectangle(rect
);
7476 // cell is shifted by one pixel
7477 // However, don't allow x or y to become negative
7478 // since the SetSize() method interprets that as
7485 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7486 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
7487 if ( !editor
->IsCreated() )
7489 editor
->Create(m_gridWin
, -1,
7490 new wxGridCellEditorEvtHandler(this, editor
));
7492 wxGridEditorCreatedEvent
evt(GetId(),
7493 wxEVT_GRID_EDITOR_CREATED
,
7497 editor
->GetControl());
7498 GetEventHandler()->ProcessEvent(evt
);
7502 // resize editor to overflow into righthand cells if allowed
7503 int maxWidth
= rect
.width
;
7504 wxString value
= GetCellValue(row
, col
);
7505 if ( (value
!= wxEmptyString
) && (attr
->GetOverflow()) )
7508 GetTextExtent(value
, &maxWidth
, &y
,
7509 NULL
, NULL
, &attr
->GetFont());
7510 if (maxWidth
< rect
.width
) maxWidth
= rect
.width
;
7512 int client_right
= m_gridWin
->GetClientSize().GetWidth();
7513 if (rect
.x
+maxWidth
> client_right
)
7514 maxWidth
= client_right
- rect
.x
;
7516 if ((maxWidth
> rect
.width
) && (col
< m_numCols
) && m_table
)
7518 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7519 // may have changed earlier
7520 for (int i
= col
+cell_cols
; i
< m_numCols
; i
++)
7523 GetCellSize( row
, i
, &c_rows
, &c_cols
);
7524 // looks weird going over a multicell
7525 if (m_table
->IsEmptyCell(row
,i
) &&
7526 (rect
.width
< maxWidth
) && (c_rows
== 1))
7527 rect
.width
+= GetColWidth(i
);
7531 if (rect
.GetRight() > client_right
)
7532 rect
.SetRight(client_right
-1);
7535 editor
->SetCellAttr(attr
);
7536 editor
->SetSize( rect
);
7537 editor
->Show( TRUE
, attr
);
7539 // recalc dimensions in case we need to
7540 // expand the scrolled window to account for editor
7543 editor
->BeginEdit(row
, col
, this);
7544 editor
->SetCellAttr(NULL
);
7553 void wxGrid::HideCellEditControl()
7555 if ( IsCellEditControlEnabled() )
7557 int row
= m_currentCellCoords
.GetRow();
7558 int col
= m_currentCellCoords
.GetCol();
7560 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7561 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
7562 editor
->Show( FALSE
);
7565 m_gridWin
->SetFocus();
7566 // refresh whole row to the right
7567 wxRect
rect( CellToRect(row
, col
) );
7568 CalcScrolledPosition(rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
7569 rect
.width
= m_gridWin
->GetClientSize().GetWidth() - rect
.x
;
7570 m_gridWin
->Refresh( FALSE
, &rect
);
7575 void wxGrid::SaveEditControlValue()
7577 if ( IsCellEditControlEnabled() )
7579 int row
= m_currentCellCoords
.GetRow();
7580 int col
= m_currentCellCoords
.GetCol();
7582 wxString oldval
= GetCellValue(row
,col
);
7584 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7585 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
7586 bool changed
= editor
->EndEdit(row
, col
, this);
7593 if ( SendEvent( wxEVT_GRID_CELL_CHANGE
,
7594 m_currentCellCoords
.GetRow(),
7595 m_currentCellCoords
.GetCol() ) < 0 ) {
7597 // Event has been vetoed, set the data back.
7598 SetCellValue(row
,col
,oldval
);
7606 // ------ Grid location functions
7607 // Note that all of these functions work with the logical coordinates of
7608 // grid cells and labels so you will need to convert from device
7609 // coordinates for mouse events etc.
7612 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
7614 int row
= YToRow(y
);
7615 int col
= XToCol(x
);
7617 if ( row
== -1 || col
== -1 )
7619 coords
= wxGridNoCellCoords
;
7623 coords
.Set( row
, col
);
7628 // Internal Helper function for computing row or column from some
7629 // (unscrolled) coordinate value, using either
7630 // m_defaultRowHeight/m_defaultColWidth or binary search on array
7631 // of m_rowBottoms/m_ColRights to speed up the search!
7633 static int CoordToRowOrCol(int coord
, int defaultDist
, int minDist
,
7634 const wxArrayInt
& BorderArray
, int nMax
,
7639 return clipToMinMax
&& (nMax
> 0) ? 0 : -1;
7645 size_t i_max
= coord
/ defaultDist
,
7648 if (BorderArray
.IsEmpty())
7650 if((int) i_max
< nMax
)
7652 return clipToMinMax
? nMax
- 1 : -1;
7655 if ( i_max
>= BorderArray
.GetCount())
7656 i_max
= BorderArray
.GetCount() - 1;
7659 if ( coord
>= BorderArray
[i_max
])
7662 i_max
= coord
/ minDist
;
7664 if ( i_max
>= BorderArray
.GetCount())
7665 i_max
= BorderArray
.GetCount() - 1;
7667 if ( coord
>= BorderArray
[i_max
])
7668 return clipToMinMax
? (int)i_max
: -1;
7669 if ( coord
< BorderArray
[0] )
7672 while ( i_max
- i_min
> 0 )
7674 wxCHECK_MSG(BorderArray
[i_min
] <= coord
&& coord
< BorderArray
[i_max
],
7675 0, _T("wxGrid: internal error in CoordToRowOrCol"));
7676 if (coord
>= BorderArray
[ i_max
- 1])
7680 int median
= i_min
+ (i_max
- i_min
+ 1) / 2;
7681 if (coord
< BorderArray
[median
])
7689 int wxGrid::YToRow( int y
)
7691 return CoordToRowOrCol(y
, m_defaultRowHeight
,
7692 m_minAcceptableRowHeight
, m_rowBottoms
, m_numRows
, FALSE
);
7696 int wxGrid::XToCol( int x
)
7698 return CoordToRowOrCol(x
, m_defaultColWidth
,
7699 m_minAcceptableColWidth
, m_colRights
, m_numCols
, FALSE
);
7703 // return the row number that that the y coord is near the edge of, or
7704 // -1 if not near an edge
7706 int wxGrid::YToEdgeOfRow( int y
)
7709 i
= internalYToRow(y
);
7711 if ( GetRowHeight(i
) > WXGRID_LABEL_EDGE_ZONE
)
7713 // We know that we are in row i, test whether we are
7714 // close enough to lower or upper border, respectively.
7715 if ( abs(GetRowBottom(i
) - y
) < WXGRID_LABEL_EDGE_ZONE
)
7717 else if( i
> 0 && y
- GetRowTop(i
) < WXGRID_LABEL_EDGE_ZONE
)
7725 // return the col number that that the x coord is near the edge of, or
7726 // -1 if not near an edge
7728 int wxGrid::XToEdgeOfCol( int x
)
7731 i
= internalXToCol(x
);
7733 if ( GetColWidth(i
) > WXGRID_LABEL_EDGE_ZONE
)
7735 // We know that we are in column i, test whether we are
7736 // close enough to right or left border, respectively.
7737 if ( abs(GetColRight(i
) - x
) < WXGRID_LABEL_EDGE_ZONE
)
7739 else if( i
> 0 && x
- GetColLeft(i
) < WXGRID_LABEL_EDGE_ZONE
)
7747 wxRect
wxGrid::CellToRect( int row
, int col
)
7749 wxRect
rect( -1, -1, -1, -1 );
7751 if ( row
>= 0 && row
< m_numRows
&&
7752 col
>= 0 && col
< m_numCols
)
7754 int i
, cell_rows
, cell_cols
;
7755 rect
.width
= rect
.height
= 0;
7756 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7757 // if negative then find multicell owner
7758 if (cell_rows
< 0) row
+= cell_rows
;
7759 if (cell_cols
< 0) col
+= cell_cols
;
7760 GetCellSize( row
, col
, &cell_rows
, &cell_cols
);
7762 rect
.x
= GetColLeft(col
);
7763 rect
.y
= GetRowTop(row
);
7764 for (i
=col
; i
<col
+cell_cols
; i
++)
7765 rect
.width
+= GetColWidth(i
);
7766 for (i
=row
; i
<row
+cell_rows
; i
++)
7767 rect
.height
+= GetRowHeight(i
);
7770 // if grid lines are enabled, then the area of the cell is a bit smaller
7771 if (m_gridLinesEnabled
) {
7779 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
7781 // get the cell rectangle in logical coords
7783 wxRect
r( CellToRect( row
, col
) );
7785 // convert to device coords
7787 int left
, top
, right
, bottom
;
7788 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
7789 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
7791 // check against the client area of the grid window
7794 m_gridWin
->GetClientSize( &cw
, &ch
);
7796 if ( wholeCellVisible
)
7798 // is the cell wholly visible ?
7800 return ( left
>= 0 && right
<= cw
&&
7801 top
>= 0 && bottom
<= ch
);
7805 // is the cell partly visible ?
7807 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
7808 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
7813 // make the specified cell location visible by doing a minimal amount
7816 void wxGrid::MakeCellVisible( int row
, int col
)
7820 int xpos
= -1, ypos
= -1;
7822 if ( row
>= 0 && row
< m_numRows
&&
7823 col
>= 0 && col
< m_numCols
)
7825 // get the cell rectangle in logical coords
7827 wxRect
r( CellToRect( row
, col
) );
7829 // convert to device coords
7831 int left
, top
, right
, bottom
;
7832 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
7833 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
7836 m_gridWin
->GetClientSize( &cw
, &ch
);
7842 else if ( bottom
> ch
)
7844 int h
= r
.GetHeight();
7846 for ( i
= row
-1; i
>= 0; i
-- )
7848 int rowHeight
= GetRowHeight(i
);
7849 if ( h
+ rowHeight
> ch
)
7856 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
7857 // have rounding errors (this is important, because if we do, we
7858 // might not scroll at all and some cells won't be redrawn)
7860 // Sometimes GRID_SCROLL_LINE/2 is not enough, so just add a full
7862 ypos
+= GRID_SCROLL_LINE_Y
;
7869 else if ( right
> cw
)
7871 // position the view so that the cell is on the right
7873 CalcUnscrolledPosition(0, 0, &x0
, &y0
);
7874 xpos
= x0
+ (right
- cw
);
7876 // see comment for ypos above
7877 xpos
+= GRID_SCROLL_LINE_X
;
7880 if ( xpos
!= -1 || ypos
!= -1 )
7883 xpos
/= GRID_SCROLL_LINE_X
;
7885 ypos
/= GRID_SCROLL_LINE_Y
;
7886 Scroll( xpos
, ypos
);
7894 // ------ Grid cursor movement functions
7897 bool wxGrid::MoveCursorUp( bool expandSelection
)
7899 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7900 m_currentCellCoords
.GetRow() >= 0 )
7902 if ( expandSelection
)
7904 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7905 m_selectingKeyboard
= m_currentCellCoords
;
7906 if ( m_selectingKeyboard
.GetRow() > 0 )
7908 m_selectingKeyboard
.SetRow( m_selectingKeyboard
.GetRow() - 1 );
7909 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7910 m_selectingKeyboard
.GetCol() );
7911 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7914 else if ( m_currentCellCoords
.GetRow() > 0 )
7917 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
7918 m_currentCellCoords
.GetCol() );
7919 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
7920 m_currentCellCoords
.GetCol() );
7931 bool wxGrid::MoveCursorDown( bool expandSelection
)
7933 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7934 m_currentCellCoords
.GetRow() < m_numRows
)
7936 if ( expandSelection
)
7938 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7939 m_selectingKeyboard
= m_currentCellCoords
;
7940 if ( m_selectingKeyboard
.GetRow() < m_numRows
-1 )
7942 m_selectingKeyboard
.SetRow( m_selectingKeyboard
.GetRow() + 1 );
7943 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7944 m_selectingKeyboard
.GetCol() );
7945 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7948 else if ( m_currentCellCoords
.GetRow() < m_numRows
- 1 )
7951 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
7952 m_currentCellCoords
.GetCol() );
7953 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
7954 m_currentCellCoords
.GetCol() );
7965 bool wxGrid::MoveCursorLeft( bool expandSelection
)
7967 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
7968 m_currentCellCoords
.GetCol() >= 0 )
7970 if ( expandSelection
)
7972 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
7973 m_selectingKeyboard
= m_currentCellCoords
;
7974 if ( m_selectingKeyboard
.GetCol() > 0 )
7976 m_selectingKeyboard
.SetCol( m_selectingKeyboard
.GetCol() - 1 );
7977 MakeCellVisible( m_selectingKeyboard
.GetRow(),
7978 m_selectingKeyboard
.GetCol() );
7979 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
7982 else if ( m_currentCellCoords
.GetCol() > 0 )
7985 MakeCellVisible( m_currentCellCoords
.GetRow(),
7986 m_currentCellCoords
.GetCol() - 1 );
7987 SetCurrentCell( m_currentCellCoords
.GetRow(),
7988 m_currentCellCoords
.GetCol() - 1 );
7999 bool wxGrid::MoveCursorRight( bool expandSelection
)
8001 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
8002 m_currentCellCoords
.GetCol() < m_numCols
)
8004 if ( expandSelection
)
8006 if ( m_selectingKeyboard
== wxGridNoCellCoords
)
8007 m_selectingKeyboard
= m_currentCellCoords
;
8008 if ( m_selectingKeyboard
.GetCol() < m_numCols
- 1 )
8010 m_selectingKeyboard
.SetCol( m_selectingKeyboard
.GetCol() + 1 );
8011 MakeCellVisible( m_selectingKeyboard
.GetRow(),
8012 m_selectingKeyboard
.GetCol() );
8013 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8016 else if ( m_currentCellCoords
.GetCol() < m_numCols
- 1 )
8019 MakeCellVisible( m_currentCellCoords
.GetRow(),
8020 m_currentCellCoords
.GetCol() + 1 );
8021 SetCurrentCell( m_currentCellCoords
.GetRow(),
8022 m_currentCellCoords
.GetCol() + 1 );
8033 bool wxGrid::MovePageUp()
8035 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
8037 int row
= m_currentCellCoords
.GetRow();
8041 m_gridWin
->GetClientSize( &cw
, &ch
);
8043 int y
= GetRowTop(row
);
8044 int newRow
= internalYToRow( y
- ch
+ 1 );
8046 if ( newRow
== row
)
8048 //row > 0 , so newrow can never be less than 0 here.
8052 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
8053 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
8061 bool wxGrid::MovePageDown()
8063 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
8065 int row
= m_currentCellCoords
.GetRow();
8066 if ( (row
+1) < m_numRows
)
8069 m_gridWin
->GetClientSize( &cw
, &ch
);
8071 int y
= GetRowTop(row
);
8072 int newRow
= internalYToRow( y
+ ch
);
8073 if ( newRow
== row
)
8075 // row < m_numRows , so newrow can't overflow here.
8079 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
8080 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
8088 bool wxGrid::MoveCursorUpBlock( bool expandSelection
)
8091 m_currentCellCoords
!= wxGridNoCellCoords
&&
8092 m_currentCellCoords
.GetRow() > 0 )
8094 int row
= m_currentCellCoords
.GetRow();
8095 int col
= m_currentCellCoords
.GetCol();
8097 if ( m_table
->IsEmptyCell(row
, col
) )
8099 // starting in an empty cell: find the next block of
8105 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8108 else if ( m_table
->IsEmptyCell(row
-1, col
) )
8110 // starting at the top of a block: find the next block
8116 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8121 // starting within a block: find the top of the block
8126 if ( m_table
->IsEmptyCell(row
, col
) )
8134 MakeCellVisible( row
, col
);
8135 if ( expandSelection
)
8137 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8138 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8143 SetCurrentCell( row
, col
);
8151 bool wxGrid::MoveCursorDownBlock( bool expandSelection
)
8154 m_currentCellCoords
!= wxGridNoCellCoords
&&
8155 m_currentCellCoords
.GetRow() < m_numRows
-1 )
8157 int row
= m_currentCellCoords
.GetRow();
8158 int col
= m_currentCellCoords
.GetCol();
8160 if ( m_table
->IsEmptyCell(row
, col
) )
8162 // starting in an empty cell: find the next block of
8165 while ( row
< m_numRows
-1 )
8168 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8171 else if ( m_table
->IsEmptyCell(row
+1, col
) )
8173 // starting at the bottom of a block: find the next block
8176 while ( row
< m_numRows
-1 )
8179 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8184 // starting within a block: find the bottom of the block
8186 while ( row
< m_numRows
-1 )
8189 if ( m_table
->IsEmptyCell(row
, col
) )
8197 MakeCellVisible( row
, col
);
8198 if ( expandSelection
)
8200 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8201 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8206 SetCurrentCell( row
, col
);
8215 bool wxGrid::MoveCursorLeftBlock( bool expandSelection
)
8218 m_currentCellCoords
!= wxGridNoCellCoords
&&
8219 m_currentCellCoords
.GetCol() > 0 )
8221 int row
= m_currentCellCoords
.GetRow();
8222 int col
= m_currentCellCoords
.GetCol();
8224 if ( m_table
->IsEmptyCell(row
, col
) )
8226 // starting in an empty cell: find the next block of
8232 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8235 else if ( m_table
->IsEmptyCell(row
, col
-1) )
8237 // starting at the left of a block: find the next block
8243 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8248 // starting within a block: find the left of the block
8253 if ( m_table
->IsEmptyCell(row
, col
) )
8261 MakeCellVisible( row
, col
);
8262 if ( expandSelection
)
8264 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8265 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8270 SetCurrentCell( row
, col
);
8279 bool wxGrid::MoveCursorRightBlock( bool expandSelection
)
8282 m_currentCellCoords
!= wxGridNoCellCoords
&&
8283 m_currentCellCoords
.GetCol() < m_numCols
-1 )
8285 int row
= m_currentCellCoords
.GetRow();
8286 int col
= m_currentCellCoords
.GetCol();
8288 if ( m_table
->IsEmptyCell(row
, col
) )
8290 // starting in an empty cell: find the next block of
8293 while ( col
< m_numCols
-1 )
8296 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8299 else if ( m_table
->IsEmptyCell(row
, col
+1) )
8301 // starting at the right of a block: find the next block
8304 while ( col
< m_numCols
-1 )
8307 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
8312 // starting within a block: find the right of the block
8314 while ( col
< m_numCols
-1 )
8317 if ( m_table
->IsEmptyCell(row
, col
) )
8325 MakeCellVisible( row
, col
);
8326 if ( expandSelection
)
8328 m_selectingKeyboard
= wxGridCellCoords( row
, col
);
8329 HighlightBlock( m_currentCellCoords
, m_selectingKeyboard
);
8334 SetCurrentCell( row
, col
);
8346 // ------ Label values and formatting
8349 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
8351 *horiz
= m_rowLabelHorizAlign
;
8352 *vert
= m_rowLabelVertAlign
;
8355 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
8357 *horiz
= m_colLabelHorizAlign
;
8358 *vert
= m_colLabelVertAlign
;
8361 int wxGrid::GetColLabelTextOrientation()
8363 return m_colLabelTextOrientation
;
8366 wxString
wxGrid::GetRowLabelValue( int row
)
8370 return m_table
->GetRowLabelValue( row
);
8380 wxString
wxGrid::GetColLabelValue( int col
)
8384 return m_table
->GetColLabelValue( col
);
8395 void wxGrid::SetRowLabelSize( int width
)
8397 width
= wxMax( width
, 0 );
8398 if ( width
!= m_rowLabelWidth
)
8402 m_rowLabelWin
->Show( FALSE
);
8403 m_cornerLabelWin
->Show( FALSE
);
8405 else if ( m_rowLabelWidth
== 0 )
8407 m_rowLabelWin
->Show( TRUE
);
8408 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
8411 m_rowLabelWidth
= width
;
8413 wxScrolledWindow::Refresh( TRUE
);
8418 void wxGrid::SetColLabelSize( int height
)
8420 height
= wxMax( height
, 0 );
8421 if ( height
!= m_colLabelHeight
)
8425 m_colLabelWin
->Show( FALSE
);
8426 m_cornerLabelWin
->Show( FALSE
);
8428 else if ( m_colLabelHeight
== 0 )
8430 m_colLabelWin
->Show( TRUE
);
8431 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
8434 m_colLabelHeight
= height
;
8436 wxScrolledWindow::Refresh( TRUE
);
8441 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
8443 if ( m_labelBackgroundColour
!= colour
)
8445 m_labelBackgroundColour
= colour
;
8446 m_rowLabelWin
->SetBackgroundColour( colour
);
8447 m_colLabelWin
->SetBackgroundColour( colour
);
8448 m_cornerLabelWin
->SetBackgroundColour( colour
);
8450 if ( !GetBatchCount() )
8452 m_rowLabelWin
->Refresh();
8453 m_colLabelWin
->Refresh();
8454 m_cornerLabelWin
->Refresh();
8459 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
8461 if ( m_labelTextColour
!= colour
)
8463 m_labelTextColour
= colour
;
8464 if ( !GetBatchCount() )
8466 m_rowLabelWin
->Refresh();
8467 m_colLabelWin
->Refresh();
8472 void wxGrid::SetLabelFont( const wxFont
& font
)
8475 if ( !GetBatchCount() )
8477 m_rowLabelWin
->Refresh();
8478 m_colLabelWin
->Refresh();
8482 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
8484 // allow old (incorrect) defs to be used
8487 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
8488 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
8489 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
8494 case wxTOP
: vert
= wxALIGN_TOP
; break;
8495 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
8496 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
8499 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
8501 m_rowLabelHorizAlign
= horiz
;
8504 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
8506 m_rowLabelVertAlign
= vert
;
8509 if ( !GetBatchCount() )
8511 m_rowLabelWin
->Refresh();
8515 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
8517 // allow old (incorrect) defs to be used
8520 case wxLEFT
: horiz
= wxALIGN_LEFT
; break;
8521 case wxRIGHT
: horiz
= wxALIGN_RIGHT
; break;
8522 case wxCENTRE
: horiz
= wxALIGN_CENTRE
; break;
8527 case wxTOP
: vert
= wxALIGN_TOP
; break;
8528 case wxBOTTOM
: vert
= wxALIGN_BOTTOM
; break;
8529 case wxCENTRE
: vert
= wxALIGN_CENTRE
; break;
8532 if ( horiz
== wxALIGN_LEFT
|| horiz
== wxALIGN_CENTRE
|| horiz
== wxALIGN_RIGHT
)
8534 m_colLabelHorizAlign
= horiz
;
8537 if ( vert
== wxALIGN_TOP
|| vert
== wxALIGN_CENTRE
|| vert
== wxALIGN_BOTTOM
)
8539 m_colLabelVertAlign
= vert
;
8542 if ( !GetBatchCount() )
8544 m_colLabelWin
->Refresh();
8548 // Note: under MSW, the default column label font must be changed because it
8549 // does not support vertical printing
8551 // Example: wxFont font(9, wxSWISS, wxNORMAL, wxBOLD);
8552 // pGrid->SetLabelFont(font);
8553 // pGrid->SetColLabelTextOrientation(wxVERTICAL);
8555 void wxGrid::SetColLabelTextOrientation( int textOrientation
)
8557 if( textOrientation
== wxHORIZONTAL
|| textOrientation
== wxVERTICAL
)
8559 m_colLabelTextOrientation
= textOrientation
;
8562 if ( !GetBatchCount() )
8564 m_colLabelWin
->Refresh();
8568 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
8572 m_table
->SetRowLabelValue( row
, s
);
8573 if ( !GetBatchCount() )
8575 wxRect rect
= CellToRect( row
, 0);
8576 if ( rect
.height
> 0 )
8578 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
8580 rect
.width
= m_rowLabelWidth
;
8581 m_rowLabelWin
->Refresh( TRUE
, &rect
);
8587 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
8591 m_table
->SetColLabelValue( col
, s
);
8592 if ( !GetBatchCount() )
8594 wxRect rect
= CellToRect( 0, col
);
8595 if ( rect
.width
> 0 )
8597 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
8599 rect
.height
= m_colLabelHeight
;
8600 m_colLabelWin
->Refresh( TRUE
, &rect
);
8606 void wxGrid::SetGridLineColour( const wxColour
& colour
)
8608 if ( m_gridLineColour
!= colour
)
8610 m_gridLineColour
= colour
;
8612 wxClientDC
dc( m_gridWin
);
8614 DrawAllGridLines( dc
, wxRegion() );
8619 void wxGrid::SetCellHighlightColour( const wxColour
& colour
)
8621 if ( m_cellHighlightColour
!= colour
)
8623 m_cellHighlightColour
= colour
;
8625 wxClientDC
dc( m_gridWin
);
8627 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
8628 DrawCellHighlight(dc
, attr
);
8633 void wxGrid::SetCellHighlightPenWidth(int width
)
8635 if (m_cellHighlightPenWidth
!= width
) {
8636 m_cellHighlightPenWidth
= width
;
8638 // Just redrawing the cell highlight is not enough since that won't
8639 // make any visible change if the the thickness is getting smaller.
8640 int row
= m_currentCellCoords
.GetRow();
8641 int col
= m_currentCellCoords
.GetCol();
8642 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
8644 wxRect rect
= CellToRect(row
, col
);
8645 m_gridWin
->Refresh(TRUE
, &rect
);
8649 void wxGrid::SetCellHighlightROPenWidth(int width
)
8651 if (m_cellHighlightROPenWidth
!= width
) {
8652 m_cellHighlightROPenWidth
= width
;
8654 // Just redrawing the cell highlight is not enough since that won't
8655 // make any visible change if the the thickness is getting smaller.
8656 int row
= m_currentCellCoords
.GetRow();
8657 int col
= m_currentCellCoords
.GetCol();
8658 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
8660 wxRect rect
= CellToRect(row
, col
);
8661 m_gridWin
->Refresh(TRUE
, &rect
);
8665 void wxGrid::EnableGridLines( bool enable
)
8667 if ( enable
!= m_gridLinesEnabled
)
8669 m_gridLinesEnabled
= enable
;
8671 if ( !GetBatchCount() )
8675 wxClientDC
dc( m_gridWin
);
8677 DrawAllGridLines( dc
, wxRegion() );
8681 m_gridWin
->Refresh();
8688 int wxGrid::GetDefaultRowSize()
8690 return m_defaultRowHeight
;
8693 int wxGrid::GetRowSize( int row
)
8695 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
8697 return GetRowHeight(row
);
8700 int wxGrid::GetDefaultColSize()
8702 return m_defaultColWidth
;
8705 int wxGrid::GetColSize( int col
)
8707 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
8709 return GetColWidth(col
);
8712 // ============================================================================
8713 // access to the grid attributes: each of them has a default value in the grid
8714 // itself and may be overidden on a per-cell basis
8715 // ============================================================================
8717 // ----------------------------------------------------------------------------
8718 // setting default attributes
8719 // ----------------------------------------------------------------------------
8721 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
8723 m_defaultCellAttr
->SetBackgroundColour(col
);
8725 m_gridWin
->SetBackgroundColour(col
);
8729 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
8731 m_defaultCellAttr
->SetTextColour(col
);
8734 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
8736 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
8739 void wxGrid::SetDefaultCellOverflow( bool allow
)
8741 m_defaultCellAttr
->SetOverflow(allow
);
8744 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
8746 m_defaultCellAttr
->SetFont(font
);
8749 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
8751 m_defaultCellAttr
->SetRenderer(renderer
);
8754 void wxGrid::SetDefaultEditor(wxGridCellEditor
*editor
)
8756 m_defaultCellAttr
->SetEditor(editor
);
8759 // ----------------------------------------------------------------------------
8760 // access to the default attrbiutes
8761 // ----------------------------------------------------------------------------
8763 wxColour
wxGrid::GetDefaultCellBackgroundColour()
8765 return m_defaultCellAttr
->GetBackgroundColour();
8768 wxColour
wxGrid::GetDefaultCellTextColour()
8770 return m_defaultCellAttr
->GetTextColour();
8773 wxFont
wxGrid::GetDefaultCellFont()
8775 return m_defaultCellAttr
->GetFont();
8778 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
8780 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
8783 bool wxGrid::GetDefaultCellOverflow()
8785 return m_defaultCellAttr
->GetOverflow();
8788 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
8790 return m_defaultCellAttr
->GetRenderer(NULL
, 0, 0);
8793 wxGridCellEditor
*wxGrid::GetDefaultEditor() const
8795 return m_defaultCellAttr
->GetEditor(NULL
,0,0);
8798 // ----------------------------------------------------------------------------
8799 // access to cell attributes
8800 // ----------------------------------------------------------------------------
8802 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
8804 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8805 wxColour colour
= attr
->GetBackgroundColour();
8810 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
8812 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8813 wxColour colour
= attr
->GetTextColour();
8818 wxFont
wxGrid::GetCellFont( int row
, int col
)
8820 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8821 wxFont font
= attr
->GetFont();
8826 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
8828 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8829 attr
->GetAlignment(horiz
, vert
);
8833 bool wxGrid::GetCellOverflow( int row
, int col
)
8835 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8836 bool allow
= attr
->GetOverflow();
8841 void wxGrid::GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
)
8843 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
8844 attr
->GetSize( num_rows
, num_cols
);
8848 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
)
8850 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8851 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
8857 wxGridCellEditor
* wxGrid::GetCellEditor(int row
, int col
)
8859 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8860 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
8866 bool wxGrid::IsReadOnly(int row
, int col
) const
8868 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
8869 bool isReadOnly
= attr
->IsReadOnly();
8874 // ----------------------------------------------------------------------------
8875 // attribute support: cache, automatic provider creation, ...
8876 // ----------------------------------------------------------------------------
8878 bool wxGrid::CanHaveAttributes()
8885 return m_table
->CanHaveAttributes();
8888 void wxGrid::ClearAttrCache()
8890 if ( m_attrCache
.row
!= -1 )
8892 wxSafeDecRef(m_attrCache
.attr
);
8893 m_attrCache
.attr
= NULL
;
8894 m_attrCache
.row
= -1;
8898 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
8902 wxGrid
*self
= (wxGrid
*)this; // const_cast
8904 self
->ClearAttrCache();
8905 self
->m_attrCache
.row
= row
;
8906 self
->m_attrCache
.col
= col
;
8907 self
->m_attrCache
.attr
= attr
;
8912 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
8914 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
8916 *attr
= m_attrCache
.attr
;
8917 wxSafeIncRef(m_attrCache
.attr
);
8919 #ifdef DEBUG_ATTR_CACHE
8920 gs_nAttrCacheHits
++;
8927 #ifdef DEBUG_ATTR_CACHE
8928 gs_nAttrCacheMisses
++;
8934 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
8936 wxGridCellAttr
*attr
= NULL
;
8937 // Additional test to avoid looking at the cache e.g. for
8938 // wxNoCellCoords, as this will confuse memory management.
8941 if ( !LookupAttr(row
, col
, &attr
) )
8943 attr
= m_table
? m_table
->GetAttr(row
, col
, wxGridCellAttr::Any
)
8944 : (wxGridCellAttr
*)NULL
;
8945 CacheAttr(row
, col
, attr
);
8950 attr
->SetDefAttr(m_defaultCellAttr
);
8954 attr
= m_defaultCellAttr
;
8961 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
8963 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
8965 wxCHECK_MSG( m_table
, attr
,
8966 _T("we may only be called if CanHaveAttributes() returned TRUE and then m_table should be !NULL") );
8968 attr
= m_table
->GetAttr(row
, col
, wxGridCellAttr::Cell
);
8971 attr
= new wxGridCellAttr(m_defaultCellAttr
);
8973 // artificially inc the ref count to match DecRef() in caller
8975 m_table
->SetAttr(attr
, row
, col
);
8981 // ----------------------------------------------------------------------------
8982 // setting column attributes (wrappers around SetColAttr)
8983 // ----------------------------------------------------------------------------
8985 void wxGrid::SetColFormatBool(int col
)
8987 SetColFormatCustom(col
, wxGRID_VALUE_BOOL
);
8990 void wxGrid::SetColFormatNumber(int col
)
8992 SetColFormatCustom(col
, wxGRID_VALUE_NUMBER
);
8995 void wxGrid::SetColFormatFloat(int col
, int width
, int precision
)
8997 wxString typeName
= wxGRID_VALUE_FLOAT
;
8998 if ( (width
!= -1) || (precision
!= -1) )
9000 typeName
<< _T(':') << width
<< _T(',') << precision
;
9003 SetColFormatCustom(col
, typeName
);
9006 void wxGrid::SetColFormatCustom(int col
, const wxString
& typeName
)
9008 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
9010 attr
= m_table
->GetAttr(-1, col
, wxGridCellAttr::Col
);
9012 attr
= new wxGridCellAttr
;
9013 wxGridCellRenderer
*renderer
= GetDefaultRendererForType(typeName
);
9014 attr
->SetRenderer(renderer
);
9016 SetColAttr(col
, attr
);
9020 // ----------------------------------------------------------------------------
9021 // setting cell attributes: this is forwarded to the table
9022 // ----------------------------------------------------------------------------
9024 void wxGrid::SetAttr(int row
, int col
, wxGridCellAttr
*attr
)
9026 if ( CanHaveAttributes() )
9028 m_table
->SetAttr(attr
, row
, col
);
9037 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
9039 if ( CanHaveAttributes() )
9041 m_table
->SetRowAttr(attr
, row
);
9050 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
9052 if ( CanHaveAttributes() )
9054 m_table
->SetColAttr(attr
, col
);
9063 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
9065 if ( CanHaveAttributes() )
9067 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9068 attr
->SetBackgroundColour(colour
);
9073 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
9075 if ( CanHaveAttributes() )
9077 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9078 attr
->SetTextColour(colour
);
9083 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
9085 if ( CanHaveAttributes() )
9087 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9088 attr
->SetFont(font
);
9093 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
9095 if ( CanHaveAttributes() )
9097 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9098 attr
->SetAlignment(horiz
, vert
);
9103 void wxGrid::SetCellOverflow( int row
, int col
, bool allow
)
9105 if ( CanHaveAttributes() )
9107 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9108 attr
->SetOverflow(allow
);
9113 void wxGrid::SetCellSize( int row
, int col
, int num_rows
, int num_cols
)
9115 if ( CanHaveAttributes() )
9117 int cell_rows
, cell_cols
;
9119 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9120 attr
->GetSize(&cell_rows
, &cell_cols
);
9121 attr
->SetSize(num_rows
, num_cols
);
9124 // Cannot set the size of a cell to 0 or negative values
9125 // While it is perfectly legal to do that, this function cannot
9126 // handle all the possibilies, do it by hand by getting the CellAttr.
9127 // You can only set the size of a cell to 1,1 or greater with this fn
9128 wxASSERT_MSG( !((cell_rows
< 1) || (cell_cols
< 1)),
9129 wxT("wxGrid::SetCellSize setting cell size that is already part of another cell"));
9130 wxASSERT_MSG( !((num_rows
< 1) || (num_cols
< 1)),
9131 wxT("wxGrid::SetCellSize setting cell size to < 1"));
9133 // if this was already a multicell then "turn off" the other cells first
9134 if ((cell_rows
> 1) || (cell_rows
> 1))
9137 for (j
=row
; j
<row
+cell_rows
; j
++)
9139 for (i
=col
; i
<col
+cell_cols
; i
++)
9141 if ((i
!= col
) || (j
!= row
))
9143 wxGridCellAttr
*attr_stub
= GetOrCreateCellAttr(j
, i
);
9144 attr_stub
->SetSize( 1, 1 );
9145 attr_stub
->DecRef();
9151 // mark the cells that will be covered by this cell to
9152 // negative or zero values to point back at this cell
9153 if (((num_rows
> 1) || (num_cols
> 1)) && (num_rows
>= 1) && (num_cols
>= 1))
9156 for (j
=row
; j
<row
+num_rows
; j
++)
9158 for (i
=col
; i
<col
+num_cols
; i
++)
9160 if ((i
!= col
) || (j
!= row
))
9162 wxGridCellAttr
*attr_stub
= GetOrCreateCellAttr(j
, i
);
9163 attr_stub
->SetSize( row
-j
, col
-i
);
9164 attr_stub
->DecRef();
9172 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
9174 if ( CanHaveAttributes() )
9176 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9177 attr
->SetRenderer(renderer
);
9182 void wxGrid::SetCellEditor(int row
, int col
, wxGridCellEditor
* editor
)
9184 if ( CanHaveAttributes() )
9186 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9187 attr
->SetEditor(editor
);
9192 void wxGrid::SetReadOnly(int row
, int col
, bool isReadOnly
)
9194 if ( CanHaveAttributes() )
9196 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
9197 attr
->SetReadOnly(isReadOnly
);
9202 // ----------------------------------------------------------------------------
9203 // Data type registration
9204 // ----------------------------------------------------------------------------
9206 void wxGrid::RegisterDataType(const wxString
& typeName
,
9207 wxGridCellRenderer
* renderer
,
9208 wxGridCellEditor
* editor
)
9210 m_typeRegistry
->RegisterDataType(typeName
, renderer
, editor
);
9214 wxGridCellEditor
* wxGrid::GetDefaultEditorForCell(int row
, int col
) const
9216 wxString typeName
= m_table
->GetTypeName(row
, col
);
9217 return GetDefaultEditorForType(typeName
);
9220 wxGridCellRenderer
* wxGrid::GetDefaultRendererForCell(int row
, int col
) const
9222 wxString typeName
= m_table
->GetTypeName(row
, col
);
9223 return GetDefaultRendererForType(typeName
);
9227 wxGrid::GetDefaultEditorForType(const wxString
& typeName
) const
9229 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
9230 if ( index
== wxNOT_FOUND
)
9232 wxFAIL_MSG(wxT("Unknown data type name"));
9237 return m_typeRegistry
->GetEditor(index
);
9241 wxGrid::GetDefaultRendererForType(const wxString
& typeName
) const
9243 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
9244 if ( index
== wxNOT_FOUND
)
9246 wxFAIL_MSG(wxT("Unknown data type name"));
9251 return m_typeRegistry
->GetRenderer(index
);
9255 // ----------------------------------------------------------------------------
9257 // ----------------------------------------------------------------------------
9259 void wxGrid::EnableDragRowSize( bool enable
)
9261 m_canDragRowSize
= enable
;
9265 void wxGrid::EnableDragColSize( bool enable
)
9267 m_canDragColSize
= enable
;
9270 void wxGrid::EnableDragGridSize( bool enable
)
9272 m_canDragGridSize
= enable
;
9276 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
9278 m_defaultRowHeight
= wxMax( height
, m_minAcceptableRowHeight
);
9280 if ( resizeExistingRows
)
9282 // since we are resizing all rows to the default row size,
9283 // we can simply clear the row heights and row bottoms
9284 // arrays (which also allows us to take advantage of
9285 // some speed optimisations)
9286 m_rowHeights
.Empty();
9287 m_rowBottoms
.Empty();
9288 if ( !GetBatchCount() )
9293 void wxGrid::SetRowSize( int row
, int height
)
9295 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
9297 // See comment in SetColSize
9298 if ( height
< GetRowMinimalAcceptableHeight()) { return; }
9300 if ( m_rowHeights
.IsEmpty() )
9302 // need to really create the array
9306 int h
= wxMax( 0, height
);
9307 int diff
= h
- m_rowHeights
[row
];
9309 m_rowHeights
[row
] = h
;
9311 for ( i
= row
; i
< m_numRows
; i
++ )
9313 m_rowBottoms
[i
] += diff
;
9315 if ( !GetBatchCount() )
9319 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
9321 m_defaultColWidth
= wxMax( width
, m_minAcceptableColWidth
);
9323 if ( resizeExistingCols
)
9325 // since we are resizing all columns to the default column size,
9326 // we can simply clear the col widths and col rights
9327 // arrays (which also allows us to take advantage of
9328 // some speed optimisations)
9329 m_colWidths
.Empty();
9330 m_colRights
.Empty();
9331 if ( !GetBatchCount() )
9336 void wxGrid::SetColSize( int col
, int width
)
9338 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
9340 // should we check that it's bigger than GetColMinimalWidth(col) here?
9342 // No, because it is reasonable to assume the library user know's
9343 // what he is doing. However whe should test against the weaker
9344 // constariant of minimalAcceptableWidth, as this breaks rendering
9346 // This test then fixes sf.net bug #645734
9348 if ( width
< GetColMinimalAcceptableWidth()) { return; }
9350 if ( m_colWidths
.IsEmpty() )
9352 // need to really create the array
9356 // if < 0 calc new width from label
9360 wxArrayString lines
;
9361 wxClientDC
dc(m_colLabelWin
);
9362 dc
.SetFont(GetLabelFont());
9363 StringToLines(GetColLabelValue(col
), lines
);
9364 GetTextBoxSize(dc
, lines
, &w
, &h
);
9367 int w
= wxMax( 0, width
);
9368 int diff
= w
- m_colWidths
[col
];
9369 m_colWidths
[col
] = w
;
9372 for ( i
= col
; i
< m_numCols
; i
++ )
9374 m_colRights
[i
] += diff
;
9376 if ( !GetBatchCount() )
9381 void wxGrid::SetColMinimalWidth( int col
, int width
)
9383 if (width
> GetColMinimalAcceptableWidth()) {
9384 m_colMinWidths
[col
] = width
;
9388 void wxGrid::SetRowMinimalHeight( int row
, int width
)
9390 if (width
> GetRowMinimalAcceptableHeight()) {
9391 m_rowMinHeights
[row
] = width
;
9395 int wxGrid::GetColMinimalWidth(int col
) const
9397 wxLongToLongHashMap::const_iterator it
= m_colMinWidths
.find(col
);
9398 return it
!= m_colMinWidths
.end() ? (int)it
->second
: m_minAcceptableColWidth
;
9401 int wxGrid::GetRowMinimalHeight(int row
) const
9403 wxLongToLongHashMap::const_iterator it
= m_rowMinHeights
.find(row
);
9404 return it
!= m_rowMinHeights
.end() ? (int)it
->second
: m_minAcceptableRowHeight
;
9407 void wxGrid::SetColMinimalAcceptableWidth( int width
)
9411 m_minAcceptableColWidth
= width
;
9414 void wxGrid::SetRowMinimalAcceptableHeight( int height
)
9418 m_minAcceptableRowHeight
= height
;
9421 int wxGrid::GetColMinimalAcceptableWidth() const
9423 return m_minAcceptableColWidth
;
9426 int wxGrid::GetRowMinimalAcceptableHeight() const
9428 return m_minAcceptableRowHeight
;
9431 // ----------------------------------------------------------------------------
9433 // ----------------------------------------------------------------------------
9435 void wxGrid::AutoSizeColOrRow( int colOrRow
, bool setAsMin
, bool column
)
9437 wxClientDC
dc(m_gridWin
);
9439 // init both of them to avoid compiler warnings, even if weo nly need one
9447 wxCoord extent
, extentMax
= 0;
9448 int max
= column
? m_numRows
: m_numCols
;
9449 for ( int rowOrCol
= 0; rowOrCol
< max
; rowOrCol
++ )
9456 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
9457 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
9460 wxSize size
= renderer
->GetBestSize(*this, *attr
, dc
, row
, col
);
9461 extent
= column
? size
.x
: size
.y
;
9462 if ( extent
> extentMax
)
9473 // now also compare with the column label extent
9475 dc
.SetFont( GetLabelFont() );
9479 dc
.GetTextExtent( GetColLabelValue(col
), &w
, &h
);
9480 if( GetColLabelTextOrientation() == wxVERTICAL
)
9484 dc
.GetTextExtent( GetRowLabelValue(row
), &w
, &h
);
9486 extent
= column
? w
: h
;
9487 if ( extent
> extentMax
)
9494 // empty column - give default extent (notice that if extentMax is less
9495 // than default extent but != 0, it's ok)
9496 extentMax
= column
? m_defaultColWidth
: m_defaultRowHeight
;
9502 // leave some space around text
9513 SetColSize(col
, extentMax
);
9514 if ( !GetBatchCount() )
9517 m_gridWin
->GetClientSize( &cw
, &ch
);
9518 wxRect
rect ( CellToRect( 0, col
) );
9520 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
9521 rect
.width
= cw
- rect
.x
;
9522 rect
.height
= m_colLabelHeight
;
9523 m_colLabelWin
->Refresh( TRUE
, &rect
);
9528 SetRowSize(row
, extentMax
);
9529 if ( !GetBatchCount() )
9532 m_gridWin
->GetClientSize( &cw
, &ch
);
9533 wxRect
rect ( CellToRect( row
, 0 ) );
9535 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
9536 rect
.width
= m_rowLabelWidth
;
9537 rect
.height
= ch
- rect
.y
;
9538 m_rowLabelWin
->Refresh( TRUE
, &rect
);
9544 SetColMinimalWidth(col
, extentMax
);
9546 SetRowMinimalHeight(row
, extentMax
);
9550 int wxGrid::SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
)
9552 int width
= m_rowLabelWidth
;
9557 for ( int col
= 0; col
< m_numCols
; col
++ )
9561 AutoSizeColumn(col
, setAsMin
);
9564 width
+= GetColWidth(col
);
9573 int wxGrid::SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
)
9575 int height
= m_colLabelHeight
;
9580 for ( int row
= 0; row
< m_numRows
; row
++ )
9584 AutoSizeRow(row
, setAsMin
);
9587 height
+= GetRowHeight(row
);
9596 void wxGrid::AutoSize()
9600 wxSize
size(SetOrCalcColumnSizes(FALSE
), SetOrCalcRowSizes(FALSE
));
9602 // round up the size to a multiple of scroll step - this ensures that we
9603 // won't get the scrollbars if we're sized exactly to this width
9604 // CalcDimension adds m_extraWidth + 1 etc. to calculate the necessary
9606 wxSize
sizeFit(GetScrollX(size
.x
+ m_extraWidth
+ 1) * GRID_SCROLL_LINE_X
,
9607 GetScrollY(size
.y
+ m_extraHeight
+ 1) * GRID_SCROLL_LINE_Y
);
9609 // distribute the extra space between the columns/rows to avoid having
9610 // extra white space
9612 // Remove the extra m_extraWidth + 1 added above
9613 wxCoord diff
= sizeFit
.x
- size
.x
+ (m_extraWidth
+ 1);
9614 if ( diff
&& m_numCols
)
9616 // try to resize the columns uniformly
9617 wxCoord diffPerCol
= diff
/ m_numCols
;
9620 for ( int col
= 0; col
< m_numCols
; col
++ )
9622 SetColSize(col
, GetColWidth(col
) + diffPerCol
);
9626 // add remaining amount to the last columns
9627 diff
-= diffPerCol
* m_numCols
;
9630 for ( int col
= m_numCols
- 1; col
>= m_numCols
- diff
; col
-- )
9632 SetColSize(col
, GetColWidth(col
) + 1);
9638 diff
= sizeFit
.y
- size
.y
- (m_extraHeight
+ 1);
9639 if ( diff
&& m_numRows
)
9641 // try to resize the columns uniformly
9642 wxCoord diffPerRow
= diff
/ m_numRows
;
9645 for ( int row
= 0; row
< m_numRows
; row
++ )
9647 SetRowSize(row
, GetRowHeight(row
) + diffPerRow
);
9651 // add remaining amount to the last rows
9652 diff
-= diffPerRow
* m_numRows
;
9655 for ( int row
= m_numRows
- 1; row
>= m_numRows
- diff
; row
-- )
9657 SetRowSize(row
, GetRowHeight(row
) + 1);
9664 SetClientSize(sizeFit
);
9667 void wxGrid::AutoSizeRowLabelSize( int row
)
9669 wxArrayString lines
;
9672 // Hide the edit control, so it
9673 // won't interfer with drag-shrinking.
9674 if( IsCellEditControlShown() )
9676 HideCellEditControl();
9677 SaveEditControlValue();
9680 // autosize row height depending on label text
9681 StringToLines( GetRowLabelValue( row
), lines
);
9682 wxClientDC
dc( m_rowLabelWin
);
9683 GetTextBoxSize( dc
, lines
, &w
, &h
);
9684 if( h
< m_defaultRowHeight
)
9685 h
= m_defaultRowHeight
;
9690 void wxGrid::AutoSizeColLabelSize( int col
)
9692 wxArrayString lines
;
9695 // Hide the edit control, so it
9696 // won't interfer with drag-shrinking.
9697 if( IsCellEditControlShown() )
9699 HideCellEditControl();
9700 SaveEditControlValue();
9703 // autosize column width depending on label text
9704 StringToLines( GetColLabelValue( col
), lines
);
9705 wxClientDC
dc( m_colLabelWin
);
9706 if( GetColLabelTextOrientation() == wxHORIZONTAL
)
9707 GetTextBoxSize( dc
, lines
, &w
, &h
);
9709 GetTextBoxSize( dc
, lines
, &h
, &w
);
9710 if( w
< m_defaultColWidth
)
9711 w
= m_defaultColWidth
;
9716 wxSize
wxGrid::DoGetBestSize() const
9718 // don't set sizes, only calculate them
9719 wxGrid
*self
= (wxGrid
*)this; // const_cast
9722 width
= self
->SetOrCalcColumnSizes(TRUE
);
9723 height
= self
->SetOrCalcRowSizes(TRUE
);
9725 int maxwidth
, maxheight
;
9726 wxDisplaySize( & maxwidth
, & maxheight
);
9728 if ( width
> maxwidth
) width
= maxwidth
;
9729 if ( height
> maxheight
) height
= maxheight
;
9731 return wxSize( width
, height
);
9740 wxPen
& wxGrid::GetDividerPen() const
9745 // ----------------------------------------------------------------------------
9746 // cell value accessor functions
9747 // ----------------------------------------------------------------------------
9749 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
9753 m_table
->SetValue( row
, col
, s
);
9754 if ( !GetBatchCount() )
9757 wxRect
rect( CellToRect( row
, col
) );
9759 rect
.width
= m_gridWin
->GetClientSize().GetWidth();
9760 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
9761 m_gridWin
->Refresh( FALSE
, &rect
);
9764 if ( m_currentCellCoords
.GetRow() == row
&&
9765 m_currentCellCoords
.GetCol() == col
&&
9766 IsCellEditControlShown())
9767 // Note: If we are using IsCellEditControlEnabled,
9768 // this interacts badly with calling SetCellValue from
9769 // an EVT_GRID_CELL_CHANGE handler.
9771 HideCellEditControl();
9772 ShowCellEditControl(); // will reread data from table
9779 // ------ Block, row and col selection
9782 void wxGrid::SelectRow( int row
, bool addToSelected
)
9784 if ( IsSelection() && !addToSelected
)
9788 m_selection
->SelectRow( row
, FALSE
, addToSelected
);
9792 void wxGrid::SelectCol( int col
, bool addToSelected
)
9794 if ( IsSelection() && !addToSelected
)
9798 m_selection
->SelectCol( col
, FALSE
, addToSelected
);
9802 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
9803 bool addToSelected
)
9805 if ( IsSelection() && !addToSelected
)
9809 m_selection
->SelectBlock( topRow
, leftCol
, bottomRow
, rightCol
,
9810 FALSE
, addToSelected
);
9814 void wxGrid::SelectAll()
9816 if ( m_numRows
> 0 && m_numCols
> 0 )
9819 m_selection
->SelectBlock( 0, 0, m_numRows
-1, m_numCols
-1 );
9824 // ------ Cell, row and col deselection
9827 void wxGrid::DeselectRow( int row
)
9832 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectRows
)
9834 if ( m_selection
->IsInSelection(row
, 0 ) )
9835 m_selection
->ToggleCellSelection( row
, 0);
9839 int nCols
= GetNumberCols();
9840 for ( int i
= 0; i
< nCols
; i
++ )
9842 if ( m_selection
->IsInSelection(row
, i
) )
9843 m_selection
->ToggleCellSelection( row
, i
);
9848 void wxGrid::DeselectCol( int col
)
9853 if ( m_selection
->GetSelectionMode() == wxGrid::wxGridSelectColumns
)
9855 if ( m_selection
->IsInSelection(0, col
) )
9856 m_selection
->ToggleCellSelection( 0, col
);
9860 int nRows
= GetNumberRows();
9861 for ( int i
= 0; i
< nRows
; i
++ )
9863 if ( m_selection
->IsInSelection(i
, col
) )
9864 m_selection
->ToggleCellSelection(i
, col
);
9869 void wxGrid::DeselectCell( int row
, int col
)
9871 if ( m_selection
&& m_selection
->IsInSelection(row
, col
) )
9872 m_selection
->ToggleCellSelection(row
, col
);
9875 bool wxGrid::IsSelection()
9877 return ( m_selection
&& (m_selection
->IsSelection() ||
9878 ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
9879 m_selectingBottomRight
!= wxGridNoCellCoords
) ) );
9882 bool wxGrid::IsInSelection( int row
, int col
) const
9884 return ( m_selection
&& (m_selection
->IsInSelection( row
, col
) ||
9885 ( row
>= m_selectingTopLeft
.GetRow() &&
9886 col
>= m_selectingTopLeft
.GetCol() &&
9887 row
<= m_selectingBottomRight
.GetRow() &&
9888 col
<= m_selectingBottomRight
.GetCol() )) );
9891 wxGridCellCoordsArray
wxGrid::GetSelectedCells() const
9893 if (!m_selection
) { wxGridCellCoordsArray a
; return a
; }
9894 return m_selection
->m_cellSelection
;
9896 wxGridCellCoordsArray
wxGrid::GetSelectionBlockTopLeft() const
9898 if (!m_selection
) { wxGridCellCoordsArray a
; return a
; }
9899 return m_selection
->m_blockSelectionTopLeft
;
9901 wxGridCellCoordsArray
wxGrid::GetSelectionBlockBottomRight() const
9903 if (!m_selection
) { wxGridCellCoordsArray a
; return a
; }
9904 return m_selection
->m_blockSelectionBottomRight
;
9906 wxArrayInt
wxGrid::GetSelectedRows() const
9908 if (!m_selection
) { wxArrayInt a
; return a
; }
9909 return m_selection
->m_rowSelection
;
9911 wxArrayInt
wxGrid::GetSelectedCols() const
9913 if (!m_selection
) { wxArrayInt a
; return a
; }
9914 return m_selection
->m_colSelection
;
9918 void wxGrid::ClearSelection()
9920 m_selectingTopLeft
= wxGridNoCellCoords
;
9921 m_selectingBottomRight
= wxGridNoCellCoords
;
9923 m_selection
->ClearSelection();
9927 // This function returns the rectangle that encloses the given block
9928 // in device coords clipped to the client size of the grid window.
9930 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
9931 const wxGridCellCoords
&bottomRight
)
9933 wxRect
rect( wxGridNoCellRect
);
9936 cellRect
= CellToRect( topLeft
);
9937 if ( cellRect
!= wxGridNoCellRect
)
9943 rect
= wxRect( 0, 0, 0, 0 );
9946 cellRect
= CellToRect( bottomRight
);
9947 if ( cellRect
!= wxGridNoCellRect
)
9953 return wxGridNoCellRect
;
9957 int left
= rect
.GetLeft();
9958 int top
= rect
.GetTop();
9959 int right
= rect
.GetRight();
9960 int bottom
= rect
.GetBottom();
9962 int leftCol
= topLeft
.GetCol();
9963 int topRow
= topLeft
.GetRow();
9964 int rightCol
= bottomRight
.GetCol();
9965 int bottomRow
= bottomRight
.GetRow();
9988 for ( j
= topRow
; j
<= bottomRow
; j
++ )
9990 for ( i
= leftCol
; i
<= rightCol
; i
++ )
9992 if ((j
==topRow
) || (j
==bottomRow
) || (i
==leftCol
) || (i
==rightCol
))
9994 cellRect
= CellToRect( j
, i
);
9996 if (cellRect
.x
< left
)
9998 if (cellRect
.y
< top
)
10000 if (cellRect
.x
+ cellRect
.width
> right
)
10001 right
= cellRect
.x
+ cellRect
.width
;
10002 if (cellRect
.y
+ cellRect
.height
> bottom
)
10003 bottom
= cellRect
.y
+ cellRect
.height
;
10005 else i
= rightCol
; // jump over inner cells.
10009 // convert to scrolled coords
10011 CalcScrolledPosition( left
, top
, &left
, &top
);
10012 CalcScrolledPosition( right
, bottom
, &right
, &bottom
);
10015 m_gridWin
->GetClientSize( &cw
, &ch
);
10017 if (right
< 0 || bottom
< 0 || left
> cw
|| top
> ch
)
10018 return wxRect( 0, 0, 0, 0);
10020 rect
.SetLeft( wxMax(0, left
) );
10021 rect
.SetTop( wxMax(0, top
) );
10022 rect
.SetRight( wxMin(cw
, right
) );
10023 rect
.SetBottom( wxMin(ch
, bottom
) );
10029 // ------ Grid event classes
10032 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxNotifyEvent
)
10034 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
10035 int row
, int col
, int x
, int y
, bool sel
,
10036 bool control
, bool shift
, bool alt
, bool meta
)
10037 : wxNotifyEvent( type
, id
)
10044 m_control
= control
;
10049 SetEventObject(obj
);
10053 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxNotifyEvent
)
10055 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
10056 int rowOrCol
, int x
, int y
,
10057 bool control
, bool shift
, bool alt
, bool meta
)
10058 : wxNotifyEvent( type
, id
)
10060 m_rowOrCol
= rowOrCol
;
10063 m_control
= control
;
10068 SetEventObject(obj
);
10072 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxNotifyEvent
)
10074 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
10075 const wxGridCellCoords
& topLeft
,
10076 const wxGridCellCoords
& bottomRight
,
10077 bool sel
, bool control
,
10078 bool shift
, bool alt
, bool meta
)
10079 : wxNotifyEvent( type
, id
)
10081 m_topLeft
= topLeft
;
10082 m_bottomRight
= bottomRight
;
10084 m_control
= control
;
10089 SetEventObject(obj
);
10093 IMPLEMENT_DYNAMIC_CLASS(wxGridEditorCreatedEvent
, wxCommandEvent
)
10095 wxGridEditorCreatedEvent::wxGridEditorCreatedEvent(int id
, wxEventType type
,
10096 wxObject
* obj
, int row
,
10097 int col
, wxControl
* ctrl
)
10098 : wxCommandEvent(type
, id
)
10100 SetEventObject(obj
);
10106 #endif // wxUSE_GRID