1 ///////////////////////////////////////////////////////////////////////////
2 // Name: generic/grid.cpp
3 // Purpose: wxGrid and related classes
4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
8 // Copyright: (c) Michael Bedward (mbedward@ozemail.com.au)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "grid.h"
24 // For compilers that support precompilation, includes "wx/wx.h".
25 #include "wx/wxprec.h"
33 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
39 #include "wx/dcclient.h"
40 #include "wx/settings.h"
42 #include "wx/textctrl.h"
43 #include "wx/checkbox.h"
44 #include "wx/combobox.h"
45 #include "wx/valtext.h"
48 #include "wx/textfile.h"
49 #include "wx/spinctrl.h"
50 #include "wx/tokenzr.h"
53 #include "wx/generic/gridsel.h"
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 WX_DEFINE_ARRAY(wxGridCellAttr
*, wxArrayAttrs
);
61 struct wxGridCellWithAttr
63 wxGridCellWithAttr(int row
, int col
, wxGridCellAttr
*attr_
)
64 : coords(row
, col
), attr(attr_
)
73 wxGridCellCoords coords
;
77 WX_DECLARE_OBJARRAY(wxGridCellWithAttr
, wxGridCellWithAttrArray
);
79 #include "wx/arrimpl.cpp"
81 WX_DEFINE_OBJARRAY(wxGridCellCoordsArray
)
82 WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray
)
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 class WXDLLEXPORT wxGridRowLabelWindow
: public wxWindow
91 wxGridRowLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
92 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
93 const wxPoint
&pos
, const wxSize
&size
);
98 void OnPaint( wxPaintEvent
& event
);
99 void OnMouseEvent( wxMouseEvent
& event
);
100 void OnKeyDown( wxKeyEvent
& event
);
102 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
103 DECLARE_EVENT_TABLE()
107 class WXDLLEXPORT wxGridColLabelWindow
: public wxWindow
110 wxGridColLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
111 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
112 const wxPoint
&pos
, const wxSize
&size
);
117 void OnPaint( wxPaintEvent
&event
);
118 void OnMouseEvent( wxMouseEvent
& event
);
119 void OnKeyDown( wxKeyEvent
& event
);
121 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
122 DECLARE_EVENT_TABLE()
126 class WXDLLEXPORT wxGridCornerLabelWindow
: public wxWindow
129 wxGridCornerLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
130 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
131 const wxPoint
&pos
, const wxSize
&size
);
136 void OnMouseEvent( wxMouseEvent
& event
);
137 void OnKeyDown( wxKeyEvent
& event
);
138 void OnPaint( wxPaintEvent
& event
);
140 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
141 DECLARE_EVENT_TABLE()
144 class WXDLLEXPORT wxGridWindow
: public wxPanel
149 m_owner
= (wxGrid
*)NULL
;
150 m_rowLabelWin
= (wxGridRowLabelWindow
*)NULL
;
151 m_colLabelWin
= (wxGridColLabelWindow
*)NULL
;
154 wxGridWindow( wxGrid
*parent
,
155 wxGridRowLabelWindow
*rowLblWin
,
156 wxGridColLabelWindow
*colLblWin
,
157 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
160 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
164 wxGridRowLabelWindow
*m_rowLabelWin
;
165 wxGridColLabelWindow
*m_colLabelWin
;
167 void OnPaint( wxPaintEvent
&event
);
168 void OnMouseEvent( wxMouseEvent
& event
);
169 void OnKeyDown( wxKeyEvent
& );
170 void OnEraseBackground( wxEraseEvent
& );
173 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
174 DECLARE_EVENT_TABLE()
179 class wxGridCellEditorEvtHandler
: public wxEvtHandler
182 wxGridCellEditorEvtHandler()
183 : m_grid(0), m_editor(0)
185 wxGridCellEditorEvtHandler(wxGrid
* grid
, wxGridCellEditor
* editor
)
186 : m_grid(grid
), m_editor(editor
)
189 void OnKeyDown(wxKeyEvent
& event
);
190 void OnChar(wxKeyEvent
& event
);
194 wxGridCellEditor
* m_editor
;
195 DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler
)
196 DECLARE_EVENT_TABLE()
200 IMPLEMENT_DYNAMIC_CLASS( wxGridCellEditorEvtHandler
, wxEvtHandler
)
201 BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler
, wxEvtHandler
)
202 EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown
)
203 EVT_CHAR( wxGridCellEditorEvtHandler::OnChar
)
208 // ----------------------------------------------------------------------------
209 // the internal data representation used by wxGridCellAttrProvider
210 // ----------------------------------------------------------------------------
212 // this class stores attributes set for cells
213 class WXDLLEXPORT wxGridCellAttrData
216 void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
217 wxGridCellAttr
*GetAttr(int row
, int col
) const;
218 void UpdateAttrRows( size_t pos
, int numRows
);
219 void UpdateAttrCols( size_t pos
, int numCols
);
222 // searches for the attr for given cell, returns wxNOT_FOUND if not found
223 int FindIndex(int row
, int col
) const;
225 wxGridCellWithAttrArray m_attrs
;
228 // this class stores attributes set for rows or columns
229 class WXDLLEXPORT wxGridRowOrColAttrData
232 // empty ctor to suppress warnings
233 wxGridRowOrColAttrData() { }
234 ~wxGridRowOrColAttrData();
236 void SetAttr(wxGridCellAttr
*attr
, int rowOrCol
);
237 wxGridCellAttr
*GetAttr(int rowOrCol
) const;
238 void UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
);
241 wxArrayInt m_rowsOrCols
;
242 wxArrayAttrs m_attrs
;
245 // NB: this is just a wrapper around 3 objects: one which stores cell
246 // attributes, and 2 others for row/col ones
247 class WXDLLEXPORT wxGridCellAttrProviderData
250 wxGridCellAttrData m_cellAttrs
;
251 wxGridRowOrColAttrData m_rowAttrs
,
256 // ----------------------------------------------------------------------------
257 // data structures used for the data type registry
258 // ----------------------------------------------------------------------------
260 struct wxGridDataTypeInfo
262 wxGridDataTypeInfo(const wxString
& typeName
,
263 wxGridCellRenderer
* renderer
,
264 wxGridCellEditor
* editor
)
265 : m_typeName(typeName
), m_renderer(renderer
), m_editor(editor
)
268 ~wxGridDataTypeInfo()
270 wxSafeDecRef(m_renderer
);
271 wxSafeDecRef(m_editor
);
275 wxGridCellRenderer
* m_renderer
;
276 wxGridCellEditor
* m_editor
;
280 WX_DEFINE_ARRAY(wxGridDataTypeInfo
*, wxGridDataTypeInfoArray
);
283 class WXDLLEXPORT wxGridTypeRegistry
286 ~wxGridTypeRegistry();
288 void RegisterDataType(const wxString
& typeName
,
289 wxGridCellRenderer
* renderer
,
290 wxGridCellEditor
* editor
);
292 // find one of already registered data types
293 int FindRegisteredDataType(const wxString
& typeName
);
295 // try to FindRegisteredDataType(), if this fails and typeName is one of
296 // standard typenames, register it and return its index
297 int FindDataType(const wxString
& typeName
);
299 // try to FindDataType(), if it fails see if it is not one of already
300 // registered data types with some params in which case clone the
301 // registered data type and set params for it
302 int FindOrCloneDataType(const wxString
& typeName
);
304 wxGridCellRenderer
* GetRenderer(int index
);
305 wxGridCellEditor
* GetEditor(int index
);
308 wxGridDataTypeInfoArray m_typeinfo
;
311 // ----------------------------------------------------------------------------
312 // conditional compilation
313 // ----------------------------------------------------------------------------
315 #ifndef WXGRID_DRAW_LINES
316 #define WXGRID_DRAW_LINES 1
319 // ----------------------------------------------------------------------------
321 // ----------------------------------------------------------------------------
323 //#define DEBUG_ATTR_CACHE
324 #ifdef DEBUG_ATTR_CACHE
325 static size_t gs_nAttrCacheHits
= 0;
326 static size_t gs_nAttrCacheMisses
= 0;
327 #endif // DEBUG_ATTR_CACHE
329 // ----------------------------------------------------------------------------
331 // ----------------------------------------------------------------------------
333 wxGridCellCoords
wxGridNoCellCoords( -1, -1 );
334 wxRect
wxGridNoCellRect( -1, -1, -1, -1 );
337 // TODO: fixed so far - make configurable later (and also different for x/y)
338 static const size_t GRID_SCROLL_LINE
= 10;
340 // the size of hash tables used a bit everywhere (the max number of elements
341 // in these hash tables is the number of rows/columns)
342 static const int GRID_HASH_SIZE
= 100;
344 // ============================================================================
346 // ============================================================================
348 // ----------------------------------------------------------------------------
350 // ----------------------------------------------------------------------------
352 wxGridCellEditor::wxGridCellEditor()
358 wxGridCellEditor::~wxGridCellEditor()
363 void wxGridCellEditor::Create(wxWindow
* WXUNUSED(parent
),
364 wxWindowID
WXUNUSED(id
),
365 wxEvtHandler
* evtHandler
)
368 m_control
->PushEventHandler(evtHandler
);
371 void wxGridCellEditor::PaintBackground(const wxRect
& rectCell
,
372 wxGridCellAttr
*attr
)
374 // erase the background because we might not fill the cell
375 wxClientDC
dc(m_control
->GetParent());
376 dc
.SetPen(*wxTRANSPARENT_PEN
);
377 dc
.SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
378 dc
.DrawRectangle(rectCell
);
380 // redraw the control we just painted over
381 m_control
->Refresh();
384 void wxGridCellEditor::Destroy()
388 m_control
->PopEventHandler(TRUE
/* delete it*/);
390 m_control
->Destroy();
395 void wxGridCellEditor::Show(bool show
, wxGridCellAttr
*attr
)
397 wxASSERT_MSG(m_control
,
398 wxT("The wxGridCellEditor must be Created first!"));
399 m_control
->Show(show
);
403 // set the colours/fonts if we have any
406 m_colFgOld
= m_control
->GetForegroundColour();
407 m_control
->SetForegroundColour(attr
->GetTextColour());
409 m_colBgOld
= m_control
->GetBackgroundColour();
410 m_control
->SetBackgroundColour(attr
->GetBackgroundColour());
412 m_fontOld
= m_control
->GetFont();
413 m_control
->SetFont(attr
->GetFont());
415 // can't do anything more in the base class version, the other
416 // attributes may only be used by the derived classes
421 // restore the standard colours fonts
422 if ( m_colFgOld
.Ok() )
424 m_control
->SetForegroundColour(m_colFgOld
);
425 m_colFgOld
= wxNullColour
;
428 if ( m_colBgOld
.Ok() )
430 m_control
->SetBackgroundColour(m_colBgOld
);
431 m_colBgOld
= wxNullColour
;
434 if ( m_fontOld
.Ok() )
436 m_control
->SetFont(m_fontOld
);
437 m_fontOld
= wxNullFont
;
442 void wxGridCellEditor::SetSize(const wxRect
& rect
)
444 wxASSERT_MSG(m_control
,
445 wxT("The wxGridCellEditor must be Created first!"));
446 m_control
->SetSize(rect
, wxSIZE_ALLOW_MINUS_ONE
);
449 void wxGridCellEditor::HandleReturn(wxKeyEvent
& event
)
455 void wxGridCellEditor::StartingKey(wxKeyEvent
& event
)
460 void wxGridCellEditor::StartingClick()
464 // ----------------------------------------------------------------------------
465 // wxGridCellTextEditor
466 // ----------------------------------------------------------------------------
468 wxGridCellTextEditor::wxGridCellTextEditor()
473 void wxGridCellTextEditor::Create(wxWindow
* parent
,
475 wxEvtHandler
* evtHandler
)
477 m_control
= new wxTextCtrl(parent
, id
, wxEmptyString
,
478 wxDefaultPosition
, wxDefaultSize
479 #if defined(__WXMSW__)
480 , wxTE_MULTILINE
| wxTE_NO_VSCROLL
// necessary ???
484 // TODO: use m_maxChars
486 wxGridCellEditor::Create(parent
, id
, evtHandler
);
489 void wxGridCellTextEditor::PaintBackground(const wxRect
& WXUNUSED(rectCell
),
490 wxGridCellAttr
* WXUNUSED(attr
))
492 // as we fill the entire client area, don't do anything here to minimize
496 void wxGridCellTextEditor::SetSize(const wxRect
& rectOrig
)
498 wxRect
rect(rectOrig
);
500 // Make the edit control large enough to allow for internal
503 // TODO: remove this if the text ctrl sizing is improved esp. for
506 #if defined(__WXGTK__)
515 int extra_x
= ( rect
.x
> 2 )? 2 : 1;
516 int extra_y
= ( rect
.y
> 2 )? 2 : 1;
517 #if defined(__WXMOTIF__)
521 rect
.SetLeft( wxMax(0, rect
.x
- extra_x
) );
522 rect
.SetTop( wxMax(0, rect
.y
- extra_y
) );
523 rect
.SetRight( rect
.GetRight() + 2*extra_x
);
524 rect
.SetBottom( rect
.GetBottom() + 2*extra_y
);
527 wxGridCellEditor::SetSize(rect
);
530 void wxGridCellTextEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
532 wxASSERT_MSG(m_control
,
533 wxT("The wxGridCellEditor must be Created first!"));
535 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
537 DoBeginEdit(m_startValue
);
540 void wxGridCellTextEditor::DoBeginEdit(const wxString
& startValue
)
542 Text()->SetValue(startValue
);
543 Text()->SetInsertionPointEnd();
547 bool wxGridCellTextEditor::EndEdit(int row
, int col
,
550 wxASSERT_MSG(m_control
,
551 wxT("The wxGridCellEditor must be Created first!"));
553 bool changed
= FALSE
;
554 wxString value
= Text()->GetValue();
555 if (value
!= m_startValue
)
559 grid
->GetTable()->SetValue(row
, col
, value
);
561 m_startValue
= wxEmptyString
;
562 Text()->SetValue(m_startValue
);
568 void wxGridCellTextEditor::Reset()
570 wxASSERT_MSG(m_control
,
571 wxT("The wxGridCellEditor must be Created first!"));
573 DoReset(m_startValue
);
576 void wxGridCellTextEditor::DoReset(const wxString
& startValue
)
578 Text()->SetValue(startValue
);
579 Text()->SetInsertionPointEnd();
582 void wxGridCellTextEditor::StartingKey(wxKeyEvent
& event
)
584 if ( !event
.AltDown() && !event
.MetaDown() && !event
.ControlDown() )
586 // insert the key in the control
587 long keycode
= event
.KeyCode();
588 if ( isprint(keycode
) )
590 // FIXME this is not going to work for non letters...
591 if ( !event
.ShiftDown() )
593 keycode
= tolower(keycode
);
596 Text()->AppendText((wxChar
)keycode
);
606 void wxGridCellTextEditor::HandleReturn(wxKeyEvent
& event
)
608 #if defined(__WXMOTIF__) || defined(__WXGTK__)
609 // wxMotif needs a little extra help...
610 int pos
= Text()->GetInsertionPoint();
611 wxString
s( Text()->GetValue() );
612 s
= s
.Left(pos
) + "\n" + s
.Mid(pos
);
614 Text()->SetInsertionPoint( pos
);
616 // the other ports can handle a Return key press
622 void wxGridCellTextEditor::SetParameters(const wxString
& params
)
632 if ( !params
.ToLong(&tmp
) )
634 wxLogDebug(_T("Invalid wxGridCellTextEditor parameter string "
635 "'%s' ignored"), params
.c_str());
639 m_maxChars
= (size_t)tmp
;
644 // ----------------------------------------------------------------------------
645 // wxGridCellNumberEditor
646 // ----------------------------------------------------------------------------
648 wxGridCellNumberEditor::wxGridCellNumberEditor(int min
, int max
)
654 void wxGridCellNumberEditor::Create(wxWindow
* parent
,
656 wxEvtHandler
* evtHandler
)
660 // create a spin ctrl
661 m_control
= new wxSpinCtrl(parent
, -1, wxEmptyString
,
662 wxDefaultPosition
, wxDefaultSize
,
666 wxGridCellEditor::Create(parent
, id
, evtHandler
);
670 // just a text control
671 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
674 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
675 #endif // wxUSE_VALIDATORS
679 void wxGridCellNumberEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
681 // first get the value
682 wxGridTableBase
*table
= grid
->GetTable();
683 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
685 m_valueOld
= table
->GetValueAsLong(row
, col
);
689 wxString sValue
= table
->GetValue(row
, col
);
690 if (! sValue
.ToLong(&m_valueOld
))
692 wxFAIL_MSG( _T("this cell doesn't have numeric value") );
699 Spin()->SetValue(m_valueOld
);
703 DoBeginEdit(GetString());
707 bool wxGridCellNumberEditor::EndEdit(int row
, int col
,
715 value
= Spin()->GetValue();
716 changed
= value
!= m_valueOld
;
720 changed
= Text()->GetValue().ToLong(&value
) && (value
!= m_valueOld
);
725 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_NUMBER
))
726 grid
->GetTable()->SetValueAsLong(row
, col
, value
);
728 grid
->GetTable()->SetValue(row
, col
, wxString::Format("%ld", value
));
734 void wxGridCellNumberEditor::Reset()
738 Spin()->SetValue(m_valueOld
);
742 DoReset(GetString());
746 void wxGridCellNumberEditor::StartingKey(wxKeyEvent
& event
)
750 long keycode
= event
.KeyCode();
751 if ( isdigit(keycode
) || keycode
== '+' || keycode
== '-' )
753 wxGridCellTextEditor::StartingKey(event
);
763 void wxGridCellNumberEditor::SetParameters(const wxString
& params
)
774 if ( params
.BeforeFirst(_T(',')).ToLong(&tmp
) )
778 if ( params
.AfterFirst(_T(',')).ToLong(&tmp
) )
782 // skip the error message below
787 wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string "
788 "'%s' ignored"), params
.c_str());
792 // ----------------------------------------------------------------------------
793 // wxGridCellFloatEditor
794 // ----------------------------------------------------------------------------
796 void wxGridCellFloatEditor::Create(wxWindow
* parent
,
798 wxEvtHandler
* evtHandler
)
800 wxGridCellTextEditor::Create(parent
, id
, evtHandler
);
803 Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
804 #endif // wxUSE_VALIDATORS
807 void wxGridCellFloatEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
809 // first get the value
810 wxGridTableBase
*table
= grid
->GetTable();
811 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
813 m_valueOld
= table
->GetValueAsDouble(row
, col
);
817 wxString sValue
= table
->GetValue(row
, col
);
818 if (! sValue
.ToDouble(&m_valueOld
))
820 wxFAIL_MSG( _T("this cell doesn't have float value") );
825 DoBeginEdit(GetString());
828 bool wxGridCellFloatEditor::EndEdit(int row
, int col
,
832 if ( Text()->GetValue().ToDouble(&value
) && (value
!= m_valueOld
) )
834 if (grid
->GetTable()->CanSetValueAs(row
, col
, wxGRID_VALUE_FLOAT
))
835 grid
->GetTable()->SetValueAsDouble(row
, col
, value
);
837 grid
->GetTable()->SetValue(row
, col
, wxString::Format("%f", value
));
847 void wxGridCellFloatEditor::Reset()
849 DoReset(GetString());
852 void wxGridCellFloatEditor::StartingKey(wxKeyEvent
& event
)
854 long keycode
= event
.KeyCode();
855 if ( isdigit(keycode
) ||
856 keycode
== '+' || keycode
== '-' || keycode
== '.' )
858 wxGridCellTextEditor::StartingKey(event
);
867 // ----------------------------------------------------------------------------
868 // wxGridCellBoolEditor
869 // ----------------------------------------------------------------------------
871 void wxGridCellBoolEditor::Create(wxWindow
* parent
,
873 wxEvtHandler
* evtHandler
)
875 m_control
= new wxCheckBox(parent
, id
, wxEmptyString
,
876 wxDefaultPosition
, wxDefaultSize
,
879 wxGridCellEditor::Create(parent
, id
, evtHandler
);
882 void wxGridCellBoolEditor::SetSize(const wxRect
& r
)
885 wxSize size
= m_control
->GetSize();
886 wxCoord minSize
= wxMin(r
.width
, r
.height
);
888 // check if the checkbox is not too big/small for this cell
889 wxSize sizeBest
= m_control
->GetBestSize();
890 if ( !(size
== sizeBest
) )
892 // reset to default size if it had been made smaller
898 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
900 // leave 1 pixel margin
901 size
.x
= size
.y
= minSize
- 2;
908 m_control
->SetSize(size
);
911 // position it in the centre of the rectangle (TODO: support alignment?)
913 #if defined(__WXGTK__) || defined (__WXMOTIF__)
914 // the checkbox without label still has some space to the right in wxGTK,
915 // so shift it to the right
917 #elif defined(__WXMSW__)
918 // here too, but in other way
923 m_control
->Move(r
.x
+ r
.width
/2 - size
.x
/2, r
.y
+ r
.height
/2 - size
.y
/2);
926 void wxGridCellBoolEditor::Show(bool show
, wxGridCellAttr
*attr
)
928 m_control
->Show(show
);
932 wxColour colBg
= attr
? attr
->GetBackgroundColour() : *wxLIGHT_GREY
;
933 CBox()->SetBackgroundColour(colBg
);
937 void wxGridCellBoolEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
939 wxASSERT_MSG(m_control
,
940 wxT("The wxGridCellEditor must be Created first!"));
942 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
943 m_startValue
= grid
->GetTable()->GetValueAsBool(row
, col
);
945 m_startValue
= !!grid
->GetTable()->GetValue(row
, col
);
946 CBox()->SetValue(m_startValue
);
950 bool wxGridCellBoolEditor::EndEdit(int row
, int col
,
953 wxASSERT_MSG(m_control
,
954 wxT("The wxGridCellEditor must be Created first!"));
956 bool changed
= FALSE
;
957 bool value
= CBox()->GetValue();
958 if ( value
!= m_startValue
)
963 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
))
964 grid
->GetTable()->SetValueAsBool(row
, col
, value
);
966 grid
->GetTable()->SetValue(row
, col
, value
? _T("1") : wxEmptyString
);
972 void wxGridCellBoolEditor::Reset()
974 wxASSERT_MSG(m_control
,
975 wxT("The wxGridCellEditor must be Created first!"));
977 CBox()->SetValue(m_startValue
);
980 void wxGridCellBoolEditor::StartingClick()
982 CBox()->SetValue(!CBox()->GetValue());
985 // ----------------------------------------------------------------------------
986 // wxGridCellChoiceEditor
987 // ----------------------------------------------------------------------------
989 wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count
,
990 const wxChar
* choices
[],
992 : m_allowOthers(allowOthers
)
996 m_choices
.Alloc(count
);
997 for ( size_t n
= 0; n
< count
; n
++ )
999 m_choices
.Add(choices
[n
]);
1004 wxGridCellEditor
*wxGridCellChoiceEditor::Clone() const
1006 wxGridCellChoiceEditor
*editor
= new wxGridCellChoiceEditor
;
1007 editor
->m_allowOthers
= m_allowOthers
;
1008 editor
->m_choices
= m_choices
;
1013 void wxGridCellChoiceEditor::Create(wxWindow
* parent
,
1015 wxEvtHandler
* evtHandler
)
1017 size_t count
= m_choices
.GetCount();
1018 wxString
*choices
= new wxString
[count
];
1019 for ( size_t n
= 0; n
< count
; n
++ )
1021 choices
[n
] = m_choices
[n
];
1024 m_control
= new wxComboBox(parent
, id
, wxEmptyString
,
1025 wxDefaultPosition
, wxDefaultSize
,
1027 m_allowOthers
? 0 : wxCB_READONLY
);
1031 wxGridCellEditor::Create(parent
, id
, evtHandler
);
1034 void wxGridCellChoiceEditor::PaintBackground(const wxRect
& rectCell
,
1035 wxGridCellAttr
* attr
)
1037 // as we fill the entire client area, don't do anything here to minimize
1040 // TODO: It doesn't actually fill the client area since the height of a
1041 // combo always defaults to the standard... Until someone has time to
1042 // figure out the right rectangle to paint, just do it the normal way...
1043 wxGridCellEditor::PaintBackground(rectCell
, attr
);
1046 void wxGridCellChoiceEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
1048 wxASSERT_MSG(m_control
,
1049 wxT("The wxGridCellEditor must be Created first!"));
1051 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
1053 Combo()->SetValue(m_startValue
);
1054 size_t count
= m_choices
.GetCount();
1055 for (size_t i
=0; i
<count
; i
++)
1057 if (m_startValue
== m_choices
[i
])
1059 Combo()->SetSelection(i
);
1063 Combo()->SetInsertionPointEnd();
1064 Combo()->SetFocus();
1067 bool wxGridCellChoiceEditor::EndEdit(int row
, int col
,
1070 wxString value
= Combo()->GetValue();
1071 bool changed
= value
!= m_startValue
;
1074 grid
->GetTable()->SetValue(row
, col
, value
);
1076 m_startValue
= wxEmptyString
;
1077 Combo()->SetValue(m_startValue
);
1082 void wxGridCellChoiceEditor::Reset()
1084 Combo()->SetValue(m_startValue
);
1085 Combo()->SetInsertionPointEnd();
1088 void wxGridCellChoiceEditor::SetParameters(const wxString
& params
)
1098 wxStringTokenizer
tk(params
, _T(','));
1099 while ( tk
.HasMoreTokens() )
1101 m_choices
.Add(tk
.GetNextToken());
1105 // ----------------------------------------------------------------------------
1106 // wxGridCellEditorEvtHandler
1107 // ----------------------------------------------------------------------------
1109 void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent
& event
)
1111 switch ( event
.KeyCode() )
1115 m_grid
->DisableCellEditControl();
1119 event
.Skip( m_grid
->ProcessEvent( event
) );
1123 if (!m_grid
->ProcessEvent(event
))
1124 m_editor
->HandleReturn(event
);
1133 void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent
& event
)
1135 switch ( event
.KeyCode() )
1147 // ----------------------------------------------------------------------------
1148 // wxGridCellWorker is an (almost) empty common base class for
1149 // wxGridCellRenderer and wxGridCellEditor managing ref counting
1150 // ----------------------------------------------------------------------------
1152 void wxGridCellWorker::SetParameters(const wxString
& WXUNUSED(params
))
1157 wxGridCellWorker::~wxGridCellWorker()
1161 // ============================================================================
1163 // ============================================================================
1165 // ----------------------------------------------------------------------------
1166 // wxGridCellRenderer
1167 // ----------------------------------------------------------------------------
1169 void wxGridCellRenderer::Draw(wxGrid
& grid
,
1170 wxGridCellAttr
& attr
,
1176 dc
.SetBackgroundMode( wxSOLID
);
1180 dc
.SetBrush( wxBrush(grid
.GetSelectionBackground(), wxSOLID
) );
1184 dc
.SetBrush( wxBrush(attr
.GetBackgroundColour(), wxSOLID
) );
1187 dc
.SetPen( *wxTRANSPARENT_PEN
);
1188 dc
.DrawRectangle(rect
);
1191 // ----------------------------------------------------------------------------
1192 // wxGridCellStringRenderer
1193 // ----------------------------------------------------------------------------
1195 void wxGridCellStringRenderer::SetTextColoursAndFont(wxGrid
& grid
,
1196 wxGridCellAttr
& attr
,
1200 dc
.SetBackgroundMode( wxTRANSPARENT
);
1202 // TODO some special colours for attr.IsReadOnly() case?
1206 dc
.SetTextBackground( grid
.GetSelectionBackground() );
1207 dc
.SetTextForeground( grid
.GetSelectionForeground() );
1211 dc
.SetTextBackground( attr
.GetBackgroundColour() );
1212 dc
.SetTextForeground( attr
.GetTextColour() );
1215 dc
.SetFont( attr
.GetFont() );
1218 wxSize
wxGridCellStringRenderer::DoGetBestSize(wxGridCellAttr
& attr
,
1220 const wxString
& text
)
1223 dc
.SetFont(attr
.GetFont());
1224 dc
.GetTextExtent(text
, &x
, &y
);
1226 return wxSize(x
, y
);
1229 wxSize
wxGridCellStringRenderer::GetBestSize(wxGrid
& grid
,
1230 wxGridCellAttr
& attr
,
1234 return DoGetBestSize(attr
, dc
, grid
.GetCellValue(row
, col
));
1237 void wxGridCellStringRenderer::Draw(wxGrid
& grid
,
1238 wxGridCellAttr
& attr
,
1240 const wxRect
& rectCell
,
1244 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1246 // now we only have to draw the text
1247 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1250 attr
.GetAlignment(&hAlign
, &vAlign
);
1252 wxRect rect
= rectCell
;
1255 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
1256 rect
, hAlign
, vAlign
);
1259 // ----------------------------------------------------------------------------
1260 // wxGridCellNumberRenderer
1261 // ----------------------------------------------------------------------------
1263 wxString
wxGridCellNumberRenderer::GetString(wxGrid
& grid
, int row
, int col
)
1265 wxGridTableBase
*table
= grid
.GetTable();
1267 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_NUMBER
) )
1269 text
.Printf(_T("%ld"), table
->GetValueAsLong(row
, col
));
1273 text
= table
->GetValue(row
, col
);
1279 void wxGridCellNumberRenderer::Draw(wxGrid
& grid
,
1280 wxGridCellAttr
& attr
,
1282 const wxRect
& rectCell
,
1286 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1288 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1290 // draw the text right aligned by default
1292 attr
.GetAlignment(&hAlign
, &vAlign
);
1295 wxRect rect
= rectCell
;
1298 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1301 wxSize
wxGridCellNumberRenderer::GetBestSize(wxGrid
& grid
,
1302 wxGridCellAttr
& attr
,
1306 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1309 // ----------------------------------------------------------------------------
1310 // wxGridCellFloatRenderer
1311 // ----------------------------------------------------------------------------
1313 wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width
, int precision
)
1316 SetPrecision(precision
);
1319 wxGridCellRenderer
*wxGridCellFloatRenderer::Clone() const
1321 wxGridCellFloatRenderer
*renderer
= new wxGridCellFloatRenderer
;
1322 renderer
->m_width
= m_width
;
1323 renderer
->m_precision
= m_precision
;
1324 renderer
->m_format
= m_format
;
1329 wxString
wxGridCellFloatRenderer::GetString(wxGrid
& grid
, int row
, int col
)
1331 wxGridTableBase
*table
= grid
.GetTable();
1336 if ( table
->CanGetValueAs(row
, col
, wxGRID_VALUE_FLOAT
) )
1338 val
= table
->GetValueAsDouble(row
, col
);
1343 text
= table
->GetValue(row
, col
);
1344 hasDouble
= text
.ToDouble(&val
);
1351 if ( m_width
== -1 )
1353 // default width/precision
1354 m_format
= _T("%f");
1356 else if ( m_precision
== -1 )
1358 // default precision
1359 m_format
.Printf(_T("%%%d.f"), m_width
);
1363 m_format
.Printf(_T("%%%d.%df"), m_width
, m_precision
);
1367 text
.Printf(m_format
, val
);
1369 //else: text already contains the string
1374 void wxGridCellFloatRenderer::Draw(wxGrid
& grid
,
1375 wxGridCellAttr
& attr
,
1377 const wxRect
& rectCell
,
1381 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
1383 SetTextColoursAndFont(grid
, attr
, dc
, isSelected
);
1385 // draw the text right aligned by default
1387 attr
.GetAlignment(&hAlign
, &vAlign
);
1390 wxRect rect
= rectCell
;
1393 grid
.DrawTextRectangle(dc
, GetString(grid
, row
, col
), rect
, hAlign
, vAlign
);
1396 wxSize
wxGridCellFloatRenderer::GetBestSize(wxGrid
& grid
,
1397 wxGridCellAttr
& attr
,
1401 return DoGetBestSize(attr
, dc
, GetString(grid
, row
, col
));
1404 void wxGridCellFloatRenderer::SetParameters(const wxString
& params
)
1410 // reset to defaults
1416 wxString tmp
= params
.BeforeFirst(_T(','));
1420 if ( !tmp
.ToLong(&width
) )
1426 SetWidth((int)width
);
1428 tmp
= params
.AfterFirst(_T(','));
1432 if ( !tmp
.ToLong(&precision
) )
1438 SetPrecision((int)precision
);
1446 wxLogDebug(_T("Invalid wxGridCellFloatRenderer parameter string "
1447 "'%s ignored"), params
.c_str());
1452 // ----------------------------------------------------------------------------
1453 // wxGridCellBoolRenderer
1454 // ----------------------------------------------------------------------------
1456 wxSize
wxGridCellBoolRenderer::ms_sizeCheckMark
;
1458 // FIXME these checkbox size calculations are really ugly...
1460 // between checkmark and box
1461 static const wxCoord wxGRID_CHECKMARK_MARGIN
= 2;
1463 wxSize
wxGridCellBoolRenderer::GetBestSize(wxGrid
& grid
,
1464 wxGridCellAttr
& WXUNUSED(attr
),
1469 // compute it only once (no locks for MT safeness in GUI thread...)
1470 if ( !ms_sizeCheckMark
.x
)
1472 // get checkbox size
1473 wxCoord checkSize
= 0;
1474 wxCheckBox
*checkbox
= new wxCheckBox(&grid
, -1, wxEmptyString
);
1475 wxSize size
= checkbox
->GetBestSize();
1476 checkSize
= size
.y
+ 2*wxGRID_CHECKMARK_MARGIN
;
1478 // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result
1479 #if defined(__WXGTK__) || defined(__WXMOTIF__)
1480 checkSize
-= size
.y
/ 2;
1485 ms_sizeCheckMark
.x
= ms_sizeCheckMark
.y
= checkSize
;
1488 return ms_sizeCheckMark
;
1491 void wxGridCellBoolRenderer::Draw(wxGrid
& grid
,
1492 wxGridCellAttr
& attr
,
1498 wxGridCellRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
1500 // draw a check mark in the centre (ignoring alignment - TODO)
1501 wxSize size
= GetBestSize(grid
, attr
, dc
, row
, col
);
1503 // don't draw outside the cell
1504 wxCoord minSize
= wxMin(rect
.width
, rect
.height
);
1505 if ( size
.x
>= minSize
|| size
.y
>= minSize
)
1507 // and even leave (at least) 1 pixel margin
1508 size
.x
= size
.y
= minSize
- 2;
1511 // draw a border around checkmark
1513 rectBorder
.x
= rect
.x
+ rect
.width
/2 - size
.x
/2;
1514 rectBorder
.y
= rect
.y
+ rect
.height
/2 - size
.y
/2;
1515 rectBorder
.width
= size
.x
;
1516 rectBorder
.height
= size
.y
;
1519 if ( grid
.GetTable()->CanGetValueAs(row
, col
, wxGRID_VALUE_BOOL
) )
1520 value
= grid
.GetTable()->GetValueAsBool(row
, col
);
1522 value
= !!grid
.GetTable()->GetValue(row
, col
);
1526 wxRect rectMark
= rectBorder
;
1528 // MSW DrawCheckMark() is weird (and should probably be changed...)
1529 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
/2);
1533 rectMark
.Inflate(-wxGRID_CHECKMARK_MARGIN
);
1536 dc
.SetTextForeground(attr
.GetTextColour());
1537 dc
.DrawCheckMark(rectMark
);
1540 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1541 dc
.SetPen(wxPen(attr
.GetTextColour(), 1, wxSOLID
));
1542 dc
.DrawRectangle(rectBorder
);
1545 // ----------------------------------------------------------------------------
1547 // ----------------------------------------------------------------------------
1549 wxGridCellAttr
*wxGridCellAttr::Clone() const
1551 wxGridCellAttr
*attr
= new wxGridCellAttr
;
1552 if ( HasTextColour() )
1553 attr
->SetTextColour(GetTextColour());
1554 if ( HasBackgroundColour() )
1555 attr
->SetBackgroundColour(GetBackgroundColour());
1557 attr
->SetFont(GetFont());
1558 if ( HasAlignment() )
1559 attr
->SetAlignment(m_hAlign
, m_vAlign
);
1563 attr
->SetRenderer(m_renderer
);
1564 m_renderer
->IncRef();
1568 attr
->SetEditor(m_editor
);
1573 attr
->SetReadOnly();
1575 attr
->SetDefAttr(m_defGridAttr
);
1580 const wxColour
& wxGridCellAttr::GetTextColour() const
1582 if (HasTextColour())
1586 else if (m_defGridAttr
!= this)
1588 return m_defGridAttr
->GetTextColour();
1592 wxFAIL_MSG(wxT("Missing default cell attribute"));
1593 return wxNullColour
;
1598 const wxColour
& wxGridCellAttr::GetBackgroundColour() const
1600 if (HasBackgroundColour())
1602 else if (m_defGridAttr
!= this)
1603 return m_defGridAttr
->GetBackgroundColour();
1606 wxFAIL_MSG(wxT("Missing default cell attribute"));
1607 return wxNullColour
;
1612 const wxFont
& wxGridCellAttr::GetFont() const
1616 else if (m_defGridAttr
!= this)
1617 return m_defGridAttr
->GetFont();
1620 wxFAIL_MSG(wxT("Missing default cell attribute"));
1626 void wxGridCellAttr::GetAlignment(int *hAlign
, int *vAlign
) const
1630 if ( hAlign
) *hAlign
= m_hAlign
;
1631 if ( vAlign
) *vAlign
= m_vAlign
;
1633 else if (m_defGridAttr
!= this)
1634 m_defGridAttr
->GetAlignment(hAlign
, vAlign
);
1637 wxFAIL_MSG(wxT("Missing default cell attribute"));
1642 // GetRenderer and GetEditor use a slightly different decision path about
1643 // which attribute to use. If a non-default attr object has one then it is
1644 // used, otherwise the default editor or renderer is fetched from the grid and
1645 // used. It should be the default for the data type of the cell. If it is
1646 // NULL (because the table has a type that the grid does not have in its
1647 // registry,) then the grid's default editor or renderer is used.
1649 wxGridCellRenderer
* wxGridCellAttr::GetRenderer(wxGrid
* grid
, int row
, int col
) const
1651 wxGridCellRenderer
* renderer
= NULL
;
1653 if ( m_defGridAttr
!= this || grid
== NULL
)
1655 renderer
= m_renderer
; // use local attribute
1660 if ( !renderer
&& grid
) // get renderer for the data type
1662 // GetDefaultRendererForCell() will do IncRef() for us
1663 renderer
= grid
->GetDefaultRendererForCell(row
, col
);
1668 // if we still don't have one then use the grid default
1669 // (no need for IncRef() here neither)
1670 renderer
= m_defGridAttr
->GetRenderer(NULL
,0,0);
1675 wxFAIL_MSG(wxT("Missing default cell attribute"));
1681 wxGridCellEditor
* wxGridCellAttr::GetEditor(wxGrid
* grid
, int row
, int col
) const
1683 wxGridCellEditor
* editor
= NULL
;
1685 if ( m_defGridAttr
!= this || grid
== NULL
)
1687 editor
= m_editor
; // use local attribute
1692 if ( !editor
&& grid
) // get renderer for the data type
1693 editor
= grid
->GetDefaultEditorForCell(row
, col
);
1696 // if we still don't have one then use the grid default
1697 editor
= m_defGridAttr
->GetEditor(NULL
,0,0);
1701 wxFAIL_MSG(wxT("Missing default cell attribute"));
1707 // ----------------------------------------------------------------------------
1708 // wxGridCellAttrData
1709 // ----------------------------------------------------------------------------
1711 void wxGridCellAttrData::SetAttr(wxGridCellAttr
*attr
, int row
, int col
)
1713 int n
= FindIndex(row
, col
);
1714 if ( n
== wxNOT_FOUND
)
1716 // add the attribute
1717 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
1723 // change the attribute
1724 m_attrs
[(size_t)n
].attr
= attr
;
1728 // remove this attribute
1729 m_attrs
.RemoveAt((size_t)n
);
1734 wxGridCellAttr
*wxGridCellAttrData::GetAttr(int row
, int col
) const
1736 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
1738 int n
= FindIndex(row
, col
);
1739 if ( n
!= wxNOT_FOUND
)
1741 attr
= m_attrs
[(size_t)n
].attr
;
1748 void wxGridCellAttrData::UpdateAttrRows( size_t pos
, int numRows
)
1750 size_t count
= m_attrs
.GetCount();
1751 for ( size_t n
= 0; n
< count
; n
++ )
1753 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
1754 wxCoord row
= coords
.GetRow();
1755 if ((size_t)row
>= pos
)
1759 // If rows inserted, include row counter where necessary
1760 coords
.SetRow(row
+ numRows
);
1762 else if (numRows
< 0)
1764 // If rows deleted ...
1765 if ((size_t)row
>= pos
- numRows
)
1767 // ...either decrement row counter (if row still exists)...
1768 coords
.SetRow(row
+ numRows
);
1772 // ...or remove the attribute
1773 m_attrs
.RemoveAt((size_t)n
);
1781 void wxGridCellAttrData::UpdateAttrCols( size_t pos
, int numCols
)
1783 size_t count
= m_attrs
.GetCount();
1784 for ( size_t n
= 0; n
< count
; n
++ )
1786 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
1787 wxCoord col
= coords
.GetCol();
1788 if ( (size_t)col
>= pos
)
1792 // If rows inserted, include row counter where necessary
1793 coords
.SetCol(col
+ numCols
);
1795 else if (numCols
< 0)
1797 // If rows deleted ...
1798 if ((size_t)col
>= pos
- numCols
)
1800 // ...either decrement row counter (if row still exists)...
1801 coords
.SetCol(col
+ numCols
);
1805 // ...or remove the attribute
1806 m_attrs
.RemoveAt((size_t)n
);
1814 int wxGridCellAttrData::FindIndex(int row
, int col
) const
1816 size_t count
= m_attrs
.GetCount();
1817 for ( size_t n
= 0; n
< count
; n
++ )
1819 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
1820 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
1829 // ----------------------------------------------------------------------------
1830 // wxGridRowOrColAttrData
1831 // ----------------------------------------------------------------------------
1833 wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
1835 size_t count
= m_attrs
.Count();
1836 for ( size_t n
= 0; n
< count
; n
++ )
1838 m_attrs
[n
]->DecRef();
1842 wxGridCellAttr
*wxGridRowOrColAttrData::GetAttr(int rowOrCol
) const
1844 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
1846 int n
= m_rowsOrCols
.Index(rowOrCol
);
1847 if ( n
!= wxNOT_FOUND
)
1849 attr
= m_attrs
[(size_t)n
];
1856 void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr
*attr
, int rowOrCol
)
1858 int i
= m_rowsOrCols
.Index(rowOrCol
);
1859 if ( i
== wxNOT_FOUND
)
1861 // add the attribute
1862 m_rowsOrCols
.Add(rowOrCol
);
1867 size_t n
= (size_t)i
;
1870 // change the attribute
1871 m_attrs
[n
]->DecRef();
1876 // remove this attribute
1877 m_attrs
[n
]->DecRef();
1878 m_rowsOrCols
.RemoveAt(n
);
1879 m_attrs
.RemoveAt(n
);
1884 void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
)
1886 size_t count
= m_attrs
.GetCount();
1887 for ( size_t n
= 0; n
< count
; n
++ )
1889 int & rowOrCol
= m_rowsOrCols
[n
];
1890 if ( (size_t)rowOrCol
>= pos
)
1892 if ( numRowsOrCols
> 0 )
1894 // If rows inserted, include row counter where necessary
1895 rowOrCol
+= numRowsOrCols
;
1897 else if ( numRowsOrCols
< 0)
1899 // If rows deleted, either decrement row counter (if row still exists)
1900 if ((size_t)rowOrCol
>= pos
- numRowsOrCols
)
1901 rowOrCol
+= numRowsOrCols
;
1904 m_rowsOrCols
.RemoveAt((size_t)n
);
1905 m_attrs
.RemoveAt((size_t)n
);
1913 // ----------------------------------------------------------------------------
1914 // wxGridCellAttrProvider
1915 // ----------------------------------------------------------------------------
1917 wxGridCellAttrProvider::wxGridCellAttrProvider()
1919 m_data
= (wxGridCellAttrProviderData
*)NULL
;
1922 wxGridCellAttrProvider::~wxGridCellAttrProvider()
1927 void wxGridCellAttrProvider::InitData()
1929 m_data
= new wxGridCellAttrProviderData
;
1932 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
) const
1934 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
1937 // first look for the attribute of this specific cell
1938 attr
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
1942 // then look for the col attr (col attributes are more common than
1943 // the row ones, hence they have priority)
1944 attr
= m_data
->m_colAttrs
.GetAttr(col
);
1949 // finally try the row attributes
1950 attr
= m_data
->m_rowAttrs
.GetAttr(row
);
1957 void wxGridCellAttrProvider::SetAttr(wxGridCellAttr
*attr
,
1963 m_data
->m_cellAttrs
.SetAttr(attr
, row
, col
);
1966 void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr
*attr
, int row
)
1971 m_data
->m_rowAttrs
.SetAttr(attr
, row
);
1974 void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr
*attr
, int col
)
1979 m_data
->m_colAttrs
.SetAttr(attr
, col
);
1982 void wxGridCellAttrProvider::UpdateAttrRows( size_t pos
, int numRows
)
1986 m_data
->m_cellAttrs
.UpdateAttrRows( pos
, numRows
);
1988 m_data
->m_rowAttrs
.UpdateAttrRowsOrCols( pos
, numRows
);
1992 void wxGridCellAttrProvider::UpdateAttrCols( size_t pos
, int numCols
)
1996 m_data
->m_cellAttrs
.UpdateAttrCols( pos
, numCols
);
1998 m_data
->m_colAttrs
.UpdateAttrRowsOrCols( pos
, numCols
);
2002 // ----------------------------------------------------------------------------
2003 // wxGridTypeRegistry
2004 // ----------------------------------------------------------------------------
2006 wxGridTypeRegistry::~wxGridTypeRegistry()
2008 size_t count
= m_typeinfo
.Count();
2009 for ( size_t i
= 0; i
< count
; i
++ )
2010 delete m_typeinfo
[i
];
2014 void wxGridTypeRegistry::RegisterDataType(const wxString
& typeName
,
2015 wxGridCellRenderer
* renderer
,
2016 wxGridCellEditor
* editor
)
2018 wxGridDataTypeInfo
* info
= new wxGridDataTypeInfo(typeName
, renderer
, editor
);
2020 // is it already registered?
2021 int loc
= FindRegisteredDataType(typeName
);
2022 if ( loc
!= wxNOT_FOUND
)
2024 delete m_typeinfo
[loc
];
2025 m_typeinfo
[loc
] = info
;
2029 m_typeinfo
.Add(info
);
2033 int wxGridTypeRegistry::FindRegisteredDataType(const wxString
& typeName
)
2035 size_t count
= m_typeinfo
.GetCount();
2036 for ( size_t i
= 0; i
< count
; i
++ )
2038 if ( typeName
== m_typeinfo
[i
]->m_typeName
)
2047 int wxGridTypeRegistry::FindDataType(const wxString
& typeName
)
2049 int index
= FindRegisteredDataType(typeName
);
2050 if ( index
== wxNOT_FOUND
)
2052 // check whether this is one of the standard ones, in which case
2053 // register it "on the fly"
2054 if ( typeName
== wxGRID_VALUE_STRING
)
2056 RegisterDataType(wxGRID_VALUE_STRING
,
2057 new wxGridCellStringRenderer
,
2058 new wxGridCellTextEditor
);
2060 else if ( typeName
== wxGRID_VALUE_BOOL
)
2062 RegisterDataType(wxGRID_VALUE_BOOL
,
2063 new wxGridCellBoolRenderer
,
2064 new wxGridCellBoolEditor
);
2066 else if ( typeName
== wxGRID_VALUE_NUMBER
)
2068 RegisterDataType(wxGRID_VALUE_NUMBER
,
2069 new wxGridCellNumberRenderer
,
2070 new wxGridCellNumberEditor
);
2072 else if ( typeName
== wxGRID_VALUE_FLOAT
)
2074 RegisterDataType(wxGRID_VALUE_FLOAT
,
2075 new wxGridCellFloatRenderer
,
2076 new wxGridCellFloatEditor
);
2078 else if ( typeName
== wxGRID_VALUE_CHOICE
)
2080 RegisterDataType(wxGRID_VALUE_CHOICE
,
2081 new wxGridCellStringRenderer
,
2082 new wxGridCellChoiceEditor
);
2089 // we get here only if just added the entry for this type, so return
2091 index
= m_typeinfo
.GetCount() - 1;
2097 int wxGridTypeRegistry::FindOrCloneDataType(const wxString
& typeName
)
2099 int index
= FindDataType(typeName
);
2100 if ( index
== wxNOT_FOUND
)
2102 // the first part of the typename is the "real" type, anything after ':'
2103 // are the parameters for the renderer
2104 index
= FindDataType(typeName
.BeforeFirst(_T(':')));
2105 if ( index
== wxNOT_FOUND
)
2110 wxGridCellRenderer
*renderer
= GetRenderer(index
);
2111 wxGridCellRenderer
*rendererOld
= renderer
;
2112 renderer
= renderer
->Clone();
2113 rendererOld
->DecRef();
2115 wxGridCellEditor
*editor
= GetEditor(index
);
2116 wxGridCellEditor
*editorOld
= editor
;
2117 editor
= editor
->Clone();
2118 editorOld
->DecRef();
2120 // do it even if there are no parameters to reset them to defaults
2121 wxString params
= typeName
.AfterFirst(_T(':'));
2122 renderer
->SetParameters(params
);
2123 editor
->SetParameters(params
);
2125 // register the new typename
2126 RegisterDataType(typeName
, renderer
, editor
);
2128 // we just registered it, it's the last one
2129 index
= m_typeinfo
.GetCount() - 1;
2135 wxGridCellRenderer
* wxGridTypeRegistry::GetRenderer(int index
)
2137 wxGridCellRenderer
* renderer
= m_typeinfo
[index
]->m_renderer
;
2142 wxGridCellEditor
* wxGridTypeRegistry::GetEditor(int index
)
2144 wxGridCellEditor
* editor
= m_typeinfo
[index
]->m_editor
;
2149 // ----------------------------------------------------------------------------
2151 // ----------------------------------------------------------------------------
2153 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
2156 wxGridTableBase::wxGridTableBase()
2158 m_view
= (wxGrid
*) NULL
;
2159 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
2162 wxGridTableBase::~wxGridTableBase()
2164 delete m_attrProvider
;
2167 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
2169 delete m_attrProvider
;
2170 m_attrProvider
= attrProvider
;
2173 bool wxGridTableBase::CanHaveAttributes()
2175 if ( ! GetAttrProvider() )
2177 // use the default attr provider by default
2178 SetAttrProvider(new wxGridCellAttrProvider
);
2183 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
)
2185 if ( m_attrProvider
)
2186 return m_attrProvider
->GetAttr(row
, col
);
2188 return (wxGridCellAttr
*)NULL
;
2191 void wxGridTableBase::SetAttr(wxGridCellAttr
* attr
, int row
, int col
)
2193 if ( m_attrProvider
)
2195 m_attrProvider
->SetAttr(attr
, row
, col
);
2199 // as we take ownership of the pointer and don't store it, we must
2205 void wxGridTableBase::SetRowAttr(wxGridCellAttr
*attr
, int row
)
2207 if ( m_attrProvider
)
2209 m_attrProvider
->SetRowAttr(attr
, row
);
2213 // as we take ownership of the pointer and don't store it, we must
2219 void wxGridTableBase::SetColAttr(wxGridCellAttr
*attr
, int col
)
2221 if ( m_attrProvider
)
2223 m_attrProvider
->SetColAttr(attr
, col
);
2227 // as we take ownership of the pointer and don't store it, we must
2233 void wxGridTableBase::UpdateAttrRows( size_t pos
, int numRows
)
2235 if ( m_attrProvider
)
2237 m_attrProvider
->UpdateAttrRows( pos
, numRows
);
2241 void wxGridTableBase::UpdateAttrCols( size_t pos
, int numCols
)
2243 if ( m_attrProvider
)
2245 m_attrProvider
->UpdateAttrCols( pos
, numCols
);
2249 bool wxGridTableBase::InsertRows( size_t pos
, size_t numRows
)
2251 wxFAIL_MSG( wxT("Called grid table class function InsertRows\n"
2252 "but your derived table class does not override this function") );
2257 bool wxGridTableBase::AppendRows( size_t numRows
)
2259 wxFAIL_MSG( wxT("Called grid table class function AppendRows\n"
2260 "but your derived table class does not override this function"));
2265 bool wxGridTableBase::DeleteRows( size_t pos
, size_t numRows
)
2267 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\n"
2268 "but your derived table class does not override this function"));
2273 bool wxGridTableBase::InsertCols( size_t pos
, size_t numCols
)
2275 wxFAIL_MSG( wxT("Called grid table class function InsertCols\n"
2276 "but your derived table class does not override this function"));
2281 bool wxGridTableBase::AppendCols( size_t numCols
)
2283 wxFAIL_MSG(wxT("Called grid table class function AppendCols\n"
2284 "but your derived table class does not override this function"));
2289 bool wxGridTableBase::DeleteCols( size_t pos
, size_t numCols
)
2291 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\n"
2292 "but your derived table class does not override this function"));
2298 wxString
wxGridTableBase::GetRowLabelValue( int row
)
2301 s
<< row
+ 1; // RD: Starting the rows at zero confuses users, no matter
2302 // how much it makes sense to us geeks.
2306 wxString
wxGridTableBase::GetColLabelValue( int col
)
2308 // default col labels are:
2309 // cols 0 to 25 : A-Z
2310 // cols 26 to 675 : AA-ZZ
2315 for ( n
= 1; ; n
++ )
2317 s
+= (_T('A') + (wxChar
)( col%26
));
2319 if ( col
< 0 ) break;
2322 // reverse the string...
2324 for ( i
= 0; i
< n
; i
++ )
2333 wxString
wxGridTableBase::GetTypeName( int WXUNUSED(row
), int WXUNUSED(col
) )
2335 return wxGRID_VALUE_STRING
;
2338 bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row
), int WXUNUSED(col
),
2339 const wxString
& typeName
)
2341 return typeName
== wxGRID_VALUE_STRING
;
2344 bool wxGridTableBase::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
2346 return CanGetValueAs(row
, col
, typeName
);
2349 long wxGridTableBase::GetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
) )
2354 double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
) )
2359 bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
) )
2364 void wxGridTableBase::SetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
),
2365 long WXUNUSED(value
) )
2369 void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
),
2370 double WXUNUSED(value
) )
2374 void wxGridTableBase::SetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
),
2375 bool WXUNUSED(value
) )
2380 void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
2381 const wxString
& WXUNUSED(typeName
) )
2386 void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
2387 const wxString
& WXUNUSED(typeName
),
2388 void* WXUNUSED(value
) )
2392 //////////////////////////////////////////////////////////////////////
2394 // Message class for the grid table to send requests and notifications
2398 wxGridTableMessage::wxGridTableMessage()
2400 m_table
= (wxGridTableBase
*) NULL
;
2406 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
2407 int commandInt1
, int commandInt2
)
2411 m_comInt1
= commandInt1
;
2412 m_comInt2
= commandInt2
;
2417 //////////////////////////////////////////////////////////////////////
2419 // A basic grid table for string data. An object of this class will
2420 // created by wxGrid if you don't specify an alternative table class.
2423 WX_DEFINE_OBJARRAY(wxGridStringArray
)
2425 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
2427 wxGridStringTable::wxGridStringTable()
2432 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
2437 m_data
.Alloc( numRows
);
2440 sa
.Alloc( numCols
);
2441 for ( col
= 0; col
< numCols
; col
++ )
2443 sa
.Add( wxEmptyString
);
2446 for ( row
= 0; row
< numRows
; row
++ )
2452 wxGridStringTable::~wxGridStringTable()
2456 long wxGridStringTable::GetNumberRows()
2458 return m_data
.GetCount();
2461 long wxGridStringTable::GetNumberCols()
2463 if ( m_data
.GetCount() > 0 )
2464 return m_data
[0].GetCount();
2469 wxString
wxGridStringTable::GetValue( int row
, int col
)
2471 wxASSERT_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
2472 _T("invalid row or column index in wxGridStringTable") );
2474 return m_data
[row
][col
];
2477 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& value
)
2479 wxASSERT_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
2480 _T("invalid row or column index in wxGridStringTable") );
2482 m_data
[row
][col
] = value
;
2485 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
2487 wxASSERT_MSG( (row
< GetNumberRows()) && (col
< GetNumberCols()),
2488 _T("invalid row or column index in wxGridStringTable") );
2490 return (m_data
[row
][col
] == wxEmptyString
);
2493 void wxGridStringTable::Clear()
2496 int numRows
, numCols
;
2498 numRows
= m_data
.GetCount();
2501 numCols
= m_data
[0].GetCount();
2503 for ( row
= 0; row
< numRows
; row
++ )
2505 for ( col
= 0; col
< numCols
; col
++ )
2507 m_data
[row
][col
] = wxEmptyString
;
2514 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
2518 size_t curNumRows
= m_data
.GetCount();
2519 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
2521 if ( pos
>= curNumRows
)
2523 return AppendRows( numRows
);
2527 sa
.Alloc( curNumCols
);
2528 for ( col
= 0; col
< curNumCols
; col
++ )
2530 sa
.Add( wxEmptyString
);
2533 for ( row
= pos
; row
< pos
+ numRows
; row
++ )
2535 m_data
.Insert( sa
, row
);
2537 UpdateAttrRows( pos
, numRows
);
2540 wxGridTableMessage
msg( this,
2541 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
2545 GetView()->ProcessTableMessage( msg
);
2551 bool wxGridStringTable::AppendRows( size_t numRows
)
2555 size_t curNumRows
= m_data
.GetCount();
2556 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
2559 if ( curNumCols
> 0 )
2561 sa
.Alloc( curNumCols
);
2562 for ( col
= 0; col
< curNumCols
; col
++ )
2564 sa
.Add( wxEmptyString
);
2568 for ( row
= 0; row
< numRows
; row
++ )
2575 wxGridTableMessage
msg( this,
2576 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
2579 GetView()->ProcessTableMessage( msg
);
2585 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
2589 size_t curNumRows
= m_data
.GetCount();
2591 if ( pos
>= curNumRows
)
2594 errmsg
.Printf("Called wxGridStringTable::DeleteRows(pos=%d, N=%d)\n"
2595 "Pos value is invalid for present table with %d rows",
2596 pos
, numRows
, curNumRows
);
2597 wxFAIL_MSG( wxT(errmsg
) );
2601 if ( numRows
> curNumRows
- pos
)
2603 numRows
= curNumRows
- pos
;
2606 if ( numRows
>= curNumRows
)
2608 m_data
.Empty(); // don't release memory just yet
2612 for ( n
= 0; n
< numRows
; n
++ )
2614 m_data
.Remove( pos
);
2617 UpdateAttrRows( pos
, -((int)numRows
) );
2620 wxGridTableMessage
msg( this,
2621 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
2625 GetView()->ProcessTableMessage( msg
);
2631 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
2635 size_t curNumRows
= m_data
.GetCount();
2636 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
2638 if ( pos
>= curNumCols
)
2640 return AppendCols( numCols
);
2643 for ( row
= 0; row
< curNumRows
; row
++ )
2645 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
2647 m_data
[row
].Insert( wxEmptyString
, col
);
2650 UpdateAttrCols( pos
, numCols
);
2653 wxGridTableMessage
msg( this,
2654 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
2658 GetView()->ProcessTableMessage( msg
);
2664 bool wxGridStringTable::AppendCols( size_t numCols
)
2668 size_t curNumRows
= m_data
.GetCount();
2671 // TODO: something better than this ?
2673 wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\n"
2674 "Call AppendRows() first") );
2678 for ( row
= 0; row
< curNumRows
; row
++ )
2680 for ( n
= 0; n
< numCols
; n
++ )
2682 m_data
[row
].Add( wxEmptyString
);
2688 wxGridTableMessage
msg( this,
2689 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
2692 GetView()->ProcessTableMessage( msg
);
2698 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
2702 size_t curNumRows
= m_data
.GetCount();
2703 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
2705 if ( pos
>= curNumCols
)
2708 errmsg
.Printf( "Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\n"
2709 "Pos value is invalid for present table with %d cols",
2710 pos
, numCols
, curNumCols
);
2711 wxFAIL_MSG( wxT( errmsg
) );
2715 if ( numCols
> curNumCols
- pos
)
2717 numCols
= curNumCols
- pos
;
2720 for ( row
= 0; row
< curNumRows
; row
++ )
2722 if ( numCols
>= curNumCols
)
2724 m_data
[row
].Clear();
2728 for ( n
= 0; n
< numCols
; n
++ )
2730 m_data
[row
].Remove( pos
);
2734 UpdateAttrCols( pos
, -((int)numCols
) );
2737 wxGridTableMessage
msg( this,
2738 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
2742 GetView()->ProcessTableMessage( msg
);
2748 wxString
wxGridStringTable::GetRowLabelValue( int row
)
2750 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
2752 // using default label
2754 return wxGridTableBase::GetRowLabelValue( row
);
2758 return m_rowLabels
[ row
];
2762 wxString
wxGridStringTable::GetColLabelValue( int col
)
2764 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
2766 // using default label
2768 return wxGridTableBase::GetColLabelValue( col
);
2772 return m_colLabels
[ col
];
2776 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
2778 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
2780 int n
= m_rowLabels
.GetCount();
2782 for ( i
= n
; i
<= row
; i
++ )
2784 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
2788 m_rowLabels
[row
] = value
;
2791 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
2793 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
2795 int n
= m_colLabels
.GetCount();
2797 for ( i
= n
; i
<= col
; i
++ )
2799 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
2803 m_colLabels
[col
] = value
;
2808 //////////////////////////////////////////////////////////////////////
2809 //////////////////////////////////////////////////////////////////////
2811 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
2813 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
2814 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
2815 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
2816 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
2819 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
2821 const wxPoint
&pos
, const wxSize
&size
)
2822 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
)
2827 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
&event
)
2831 // NO - don't do this because it will set both the x and y origin
2832 // coords to match the parent scrolled window and we just want to
2833 // set the y coord - MB
2835 // m_owner->PrepareDC( dc );
2838 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
2839 dc
.SetDeviceOrigin( 0, -y
);
2841 m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
2842 m_owner
->DrawRowLabels( dc
);
2846 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
2848 m_owner
->ProcessRowLabelMouseEvent( event
);
2852 // This seems to be required for wxMotif otherwise the mouse
2853 // cursor must be in the cell edit control to get key events
2855 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
2857 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
2862 //////////////////////////////////////////////////////////////////////
2864 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
2866 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
2867 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
2868 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
2869 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
2872 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
2874 const wxPoint
&pos
, const wxSize
&size
)
2875 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
)
2880 void wxGridColLabelWindow::OnPaint( wxPaintEvent
&event
)
2884 // NO - don't do this because it will set both the x and y origin
2885 // coords to match the parent scrolled window and we just want to
2886 // set the x coord - MB
2888 // m_owner->PrepareDC( dc );
2891 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
2892 dc
.SetDeviceOrigin( -x
, 0 );
2894 m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
2895 m_owner
->DrawColLabels( dc
);
2899 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
2901 m_owner
->ProcessColLabelMouseEvent( event
);
2905 // This seems to be required for wxMotif otherwise the mouse
2906 // cursor must be in the cell edit control to get key events
2908 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
2910 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
2915 //////////////////////////////////////////////////////////////////////
2917 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
2919 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
2920 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
2921 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
2922 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
2925 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
2927 const wxPoint
&pos
, const wxSize
&size
)
2928 : wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
)
2933 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2937 int client_height
= 0;
2938 int client_width
= 0;
2939 GetClientSize( &client_width
, &client_height
);
2941 dc
.SetPen( *wxBLACK_PEN
);
2942 dc
.DrawLine( client_width
-1, client_height
-1, client_width
-1, 0 );
2943 dc
.DrawLine( client_width
-1, client_height
-1, 0, client_height
-1 );
2945 dc
.SetPen( *wxWHITE_PEN
);
2946 dc
.DrawLine( 0, 0, client_width
, 0 );
2947 dc
.DrawLine( 0, 0, 0, client_height
);
2951 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
2953 m_owner
->ProcessCornerLabelMouseEvent( event
);
2957 // This seems to be required for wxMotif otherwise the mouse
2958 // cursor must be in the cell edit control to get key events
2960 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
2962 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
2967 //////////////////////////////////////////////////////////////////////
2969 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxPanel
)
2971 BEGIN_EVENT_TABLE( wxGridWindow
, wxPanel
)
2972 EVT_PAINT( wxGridWindow::OnPaint
)
2973 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
2974 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
2975 EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground
)
2978 wxGridWindow::wxGridWindow( wxGrid
*parent
,
2979 wxGridRowLabelWindow
*rowLblWin
,
2980 wxGridColLabelWindow
*colLblWin
,
2981 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
)
2982 : wxPanel( parent
, id
, pos
, size
, wxWANTS_CHARS
, "grid window" )
2985 m_rowLabelWin
= rowLblWin
;
2986 m_colLabelWin
= colLblWin
;
2987 SetBackgroundColour( "WHITE" );
2991 wxGridWindow::~wxGridWindow()
2996 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2998 wxPaintDC
dc( this );
2999 m_owner
->PrepareDC( dc
);
3000 wxRegion reg
= GetUpdateRegion();
3001 m_owner
->CalcCellsExposed( reg
);
3002 m_owner
->DrawGridCellArea( dc
);
3003 #if WXGRID_DRAW_LINES
3004 m_owner
->DrawAllGridLines( dc
, reg
);
3006 m_owner
->DrawGridSpace( dc
);
3007 m_owner
->DrawHighlight( dc
);
3011 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
3013 wxPanel::ScrollWindow( dx
, dy
, rect
);
3014 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
3015 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
3019 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
3021 m_owner
->ProcessGridCellMouseEvent( event
);
3025 // This seems to be required for wxMotif otherwise the mouse
3026 // cursor must be in the cell edit control to get key events
3028 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
3030 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
3034 void wxGridWindow::OnEraseBackground(wxEraseEvent
& event
)
3039 //////////////////////////////////////////////////////////////////////
3042 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
3044 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
3045 EVT_PAINT( wxGrid::OnPaint
)
3046 EVT_SIZE( wxGrid::OnSize
)
3047 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
3048 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
3051 wxGrid::wxGrid( wxWindow
*parent
,
3056 const wxString
& name
)
3057 : wxScrolledWindow( parent
, id
, pos
, size
, (style
| wxWANTS_CHARS
), name
),
3058 m_colMinWidths(GRID_HASH_SIZE
),
3059 m_rowMinHeights(GRID_HASH_SIZE
)
3068 wxSafeDecRef(m_defaultCellAttr
);
3070 #ifdef DEBUG_ATTR_CACHE
3071 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
3072 wxPrintf(_T("wxGrid attribute cache statistics: "
3073 "total: %u, hits: %u (%u%%)\n"),
3074 total
, gs_nAttrCacheHits
,
3075 total
? (gs_nAttrCacheHits
*100) / total
: 0);
3081 delete m_typeRegistry
;
3087 // ----- internal init and update functions
3090 void wxGrid::Create()
3092 m_created
= FALSE
; // set to TRUE by CreateGrid
3093 m_displayed
= TRUE
; // FALSE; // set to TRUE by OnPaint
3095 m_table
= (wxGridTableBase
*) NULL
;
3098 m_cellEditCtrlEnabled
= FALSE
;
3100 m_defaultCellAttr
= new wxGridCellAttr
;
3101 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
3103 // Set default cell attributes
3104 m_defaultCellAttr
->SetFont(GetFont());
3105 m_defaultCellAttr
->SetAlignment(wxLEFT
, wxTOP
);
3106 m_defaultCellAttr
->SetTextColour(
3107 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT
));
3108 m_defaultCellAttr
->SetBackgroundColour(
3109 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
3110 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
3111 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
3116 m_currentCellCoords
= wxGridNoCellCoords
;
3118 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
3119 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
3121 // create the type registry
3122 m_typeRegistry
= new wxGridTypeRegistry
;
3124 // subwindow components that make up the wxGrid
3125 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
3130 m_rowLabelWin
= new wxGridRowLabelWindow( this,
3135 m_colLabelWin
= new wxGridColLabelWindow( this,
3140 m_gridWin
= new wxGridWindow( this,
3147 SetTargetWindow( m_gridWin
);
3151 bool wxGrid::CreateGrid( int numRows
, int numCols
,
3152 wxGrid::wxGridSelectionModes selmode
)
3156 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
3161 m_numRows
= numRows
;
3162 m_numCols
= numCols
;
3164 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
3165 m_table
->SetView( this );
3168 m_selection
= new wxGridSelection( this, selmode
);
3174 void wxGrid::SetSelectionMode(wxGrid::wxGridSelectionModes selmode
)
3178 wxFAIL_MSG( wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") );
3181 m_selection
->SetSelectionMode( selmode
);
3184 bool wxGrid::SetTable( wxGridTableBase
*table
, bool takeOwnership
,
3185 wxGrid::wxGridSelectionModes selmode
)
3189 // RD: Actually, this should probably be allowed. I think it would be
3190 // nice to be able to switch multiple Tables in and out of a single
3191 // View at runtime. Is there anything in the implmentation that would
3194 // At least, you now have to copy with m_selection
3195 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
3200 m_numRows
= table
->GetNumberRows();
3201 m_numCols
= table
->GetNumberCols();
3204 m_table
->SetView( this );
3208 m_selection
= new wxGridSelection( this, selmode
);
3218 if ( m_numRows
<= 0 )
3219 m_numRows
= WXGRID_DEFAULT_NUMBER_ROWS
;
3221 if ( m_numCols
<= 0 )
3222 m_numCols
= WXGRID_DEFAULT_NUMBER_COLS
;
3224 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
3225 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
3227 if ( m_rowLabelWin
)
3229 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
3233 m_labelBackgroundColour
= wxColour( _T("WHITE") );
3236 m_labelTextColour
= wxColour( _T("BLACK") );
3239 m_attrCache
.row
= -1;
3241 // TODO: something better than this ?
3243 m_labelFont
= this->GetFont();
3244 m_labelFont
.SetWeight( m_labelFont
.GetWeight() + 2 );
3246 m_rowLabelHorizAlign
= wxLEFT
;
3247 m_rowLabelVertAlign
= wxCENTRE
;
3249 m_colLabelHorizAlign
= wxCENTRE
;
3250 m_colLabelVertAlign
= wxTOP
;
3252 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
3253 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
3255 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
3256 m_defaultRowHeight
+= 8;
3258 m_defaultRowHeight
+= 4;
3261 m_gridLineColour
= wxColour( 128, 128, 255 );
3262 m_gridLinesEnabled
= TRUE
;
3264 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
3265 m_winCapture
= (wxWindow
*)NULL
;
3266 m_canDragRowSize
= TRUE
;
3267 m_canDragColSize
= TRUE
;
3268 m_canDragGridSize
= TRUE
;
3270 m_dragRowOrCol
= -1;
3271 m_isDragging
= FALSE
;
3272 m_startDragPos
= wxDefaultPosition
;
3274 m_waitForSlowClick
= FALSE
;
3276 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
3277 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
3279 m_currentCellCoords
= wxGridNoCellCoords
;
3281 m_selectingTopLeft
= wxGridNoCellCoords
;
3282 m_selectingBottomRight
= wxGridNoCellCoords
;
3283 m_selectionBackground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
);
3284 m_selectionForeground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
3286 m_editable
= TRUE
; // default for whole grid
3288 m_inOnKeyDown
= FALSE
;
3297 // ----------------------------------------------------------------------------
3298 // the idea is to call these functions only when necessary because they create
3299 // quite big arrays which eat memory mostly unnecessary - in particular, if
3300 // default widths/heights are used for all rows/columns, we may not use these
3303 // with some extra code, it should be possible to only store the
3304 // widths/heights different from default ones but this will be done later...
3305 // ----------------------------------------------------------------------------
3307 void wxGrid::InitRowHeights()
3309 m_rowHeights
.Empty();
3310 m_rowBottoms
.Empty();
3312 m_rowHeights
.Alloc( m_numRows
);
3313 m_rowBottoms
.Alloc( m_numRows
);
3316 for ( int i
= 0; i
< m_numRows
; i
++ )
3318 m_rowHeights
.Add( m_defaultRowHeight
);
3319 rowBottom
+= m_defaultRowHeight
;
3320 m_rowBottoms
.Add( rowBottom
);
3324 void wxGrid::InitColWidths()
3326 m_colWidths
.Empty();
3327 m_colRights
.Empty();
3329 m_colWidths
.Alloc( m_numCols
);
3330 m_colRights
.Alloc( m_numCols
);
3332 for ( int i
= 0; i
< m_numCols
; i
++ )
3334 m_colWidths
.Add( m_defaultColWidth
);
3335 colRight
+= m_defaultColWidth
;
3336 m_colRights
.Add( colRight
);
3340 int wxGrid::GetColWidth(int col
) const
3342 return m_colWidths
.IsEmpty() ? m_defaultColWidth
: m_colWidths
[col
];
3345 int wxGrid::GetColLeft(int col
) const
3347 return m_colRights
.IsEmpty() ? col
* m_defaultColWidth
3348 : m_colRights
[col
] - m_colWidths
[col
];
3351 int wxGrid::GetColRight(int col
) const
3353 return m_colRights
.IsEmpty() ? (col
+ 1) * m_defaultColWidth
3357 int wxGrid::GetRowHeight(int row
) const
3359 return m_rowHeights
.IsEmpty() ? m_defaultRowHeight
: m_rowHeights
[row
];
3362 int wxGrid::GetRowTop(int row
) const
3364 return m_rowBottoms
.IsEmpty() ? row
* m_defaultRowHeight
3365 : m_rowBottoms
[row
] - m_rowHeights
[row
];
3368 int wxGrid::GetRowBottom(int row
) const
3370 return m_rowBottoms
.IsEmpty() ? (row
+ 1) * m_defaultRowHeight
3371 : m_rowBottoms
[row
];
3374 void wxGrid::CalcDimensions()
3377 GetClientSize( &cw
, &ch
);
3379 if ( m_numRows
> 0 && m_numCols
> 0 )
3381 int right
= GetColRight( m_numCols
-1 ) + m_extraWidth
;
3382 int bottom
= GetRowBottom( m_numRows
-1 ) + m_extraHeight
;
3384 // TODO: restore the scroll position that we had before sizing
3387 GetViewStart( &x
, &y
);
3388 SetScrollbars( GRID_SCROLL_LINE
, GRID_SCROLL_LINE
,
3389 right
/GRID_SCROLL_LINE
, bottom
/GRID_SCROLL_LINE
,
3395 void wxGrid::CalcWindowSizes()
3398 GetClientSize( &cw
, &ch
);
3400 if ( m_cornerLabelWin
->IsShown() )
3401 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
3403 if ( m_colLabelWin
->IsShown() )
3404 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
3406 if ( m_rowLabelWin
->IsShown() )
3407 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
3409 if ( m_gridWin
->IsShown() )
3410 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
3414 // this is called when the grid table sends a message to say that it
3415 // has been redimensioned
3417 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
3421 // if we were using the default widths/heights so far, we must change them
3423 if ( m_colWidths
.IsEmpty() )
3428 if ( m_rowHeights
.IsEmpty() )
3433 switch ( msg
.GetId() )
3435 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
3437 size_t pos
= msg
.GetCommandInt();
3438 int numRows
= msg
.GetCommandInt2();
3439 for ( i
= 0; i
< numRows
; i
++ )
3441 m_rowHeights
.Insert( m_defaultRowHeight
, pos
);
3442 m_rowBottoms
.Insert( 0, pos
);
3444 m_numRows
+= numRows
;
3447 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
3449 for ( i
= pos
; i
< m_numRows
; i
++ )
3451 bottom
+= m_rowHeights
[i
];
3452 m_rowBottoms
[i
] = bottom
;
3458 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
3460 int numRows
= msg
.GetCommandInt();
3461 for ( i
= 0; i
< numRows
; i
++ )
3463 m_rowHeights
.Add( m_defaultRowHeight
);
3464 m_rowBottoms
.Add( 0 );
3467 int oldNumRows
= m_numRows
;
3468 m_numRows
+= numRows
;
3471 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
3473 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
3475 bottom
+= m_rowHeights
[i
];
3476 m_rowBottoms
[i
] = bottom
;
3482 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
3484 size_t pos
= msg
.GetCommandInt();
3485 int numRows
= msg
.GetCommandInt2();
3486 for ( i
= 0; i
< numRows
; i
++ )
3488 m_rowHeights
.Remove( pos
);
3489 m_rowBottoms
.Remove( pos
);
3491 m_numRows
-= numRows
;
3496 m_colWidths
.Clear();
3497 m_colRights
.Clear();
3498 m_currentCellCoords
= wxGridNoCellCoords
;
3502 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
3503 m_currentCellCoords
.Set( 0, 0 );
3506 for ( i
= 0; i
< m_numRows
; i
++ )
3508 h
+= m_rowHeights
[i
];
3509 m_rowBottoms
[i
] = h
;
3517 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
3519 size_t pos
= msg
.GetCommandInt();
3520 int numCols
= msg
.GetCommandInt2();
3521 for ( i
= 0; i
< numCols
; i
++ )
3523 m_colWidths
.Insert( m_defaultColWidth
, pos
);
3524 m_colRights
.Insert( 0, pos
);
3526 m_numCols
+= numCols
;
3529 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
3531 for ( i
= pos
; i
< m_numCols
; i
++ )
3533 right
+= m_colWidths
[i
];
3534 m_colRights
[i
] = right
;
3540 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
3542 int numCols
= msg
.GetCommandInt();
3543 for ( i
= 0; i
< numCols
; i
++ )
3545 m_colWidths
.Add( m_defaultColWidth
);
3546 m_colRights
.Add( 0 );
3549 int oldNumCols
= m_numCols
;
3550 m_numCols
+= numCols
;
3553 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
3555 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
3557 right
+= m_colWidths
[i
];
3558 m_colRights
[i
] = right
;
3564 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
3566 size_t pos
= msg
.GetCommandInt();
3567 int numCols
= msg
.GetCommandInt2();
3568 for ( i
= 0; i
< numCols
; i
++ )
3570 m_colWidths
.Remove( pos
);
3571 m_colRights
.Remove( pos
);
3573 m_numCols
-= numCols
;
3577 #if 0 // leave the row alone here so that AppendCols will work subsequently
3579 m_rowHeights
.Clear();
3580 m_rowBottoms
.Clear();
3582 m_currentCellCoords
= wxGridNoCellCoords
;
3586 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
3587 m_currentCellCoords
.Set( 0, 0 );
3590 for ( i
= 0; i
< m_numCols
; i
++ )
3592 w
+= m_colWidths
[i
];
3605 void wxGrid::CalcRowLabelsExposed( wxRegion
& reg
)
3607 wxRegionIterator
iter( reg
);
3610 m_rowLabelsExposed
.Empty();
3617 // TODO: remove this when we can...
3618 // There is a bug in wxMotif that gives garbage update
3619 // rectangles if you jump-scroll a long way by clicking the
3620 // scrollbar with middle button. This is a work-around
3622 #if defined(__WXMOTIF__)
3624 m_gridWin
->GetClientSize( &cw
, &ch
);
3625 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
3626 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
3629 // logical bounds of update region
3632 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
3633 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
3635 // find the row labels within these bounds
3638 for ( row
= 0; row
< m_numRows
; row
++ )
3640 if ( GetRowBottom(row
) < top
)
3643 if ( GetRowTop(row
) > bottom
)
3646 m_rowLabelsExposed
.Add( row
);
3654 void wxGrid::CalcColLabelsExposed( wxRegion
& reg
)
3656 wxRegionIterator
iter( reg
);
3659 m_colLabelsExposed
.Empty();
3666 // TODO: remove this when we can...
3667 // There is a bug in wxMotif that gives garbage update
3668 // rectangles if you jump-scroll a long way by clicking the
3669 // scrollbar with middle button. This is a work-around
3671 #if defined(__WXMOTIF__)
3673 m_gridWin
->GetClientSize( &cw
, &ch
);
3674 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
3675 r
.SetRight( wxMin( r
.GetRight(), cw
) );
3678 // logical bounds of update region
3681 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
3682 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
3684 // find the cells within these bounds
3687 for ( col
= 0; col
< m_numCols
; col
++ )
3689 if ( GetColRight(col
) < left
)
3692 if ( GetColLeft(col
) > right
)
3695 m_colLabelsExposed
.Add( col
);
3703 void wxGrid::CalcCellsExposed( wxRegion
& reg
)
3705 wxRegionIterator
iter( reg
);
3708 m_cellsExposed
.Empty();
3709 m_rowsExposed
.Empty();
3710 m_colsExposed
.Empty();
3712 int left
, top
, right
, bottom
;
3717 // TODO: remove this when we can...
3718 // There is a bug in wxMotif that gives garbage update
3719 // rectangles if you jump-scroll a long way by clicking the
3720 // scrollbar with middle button. This is a work-around
3722 #if defined(__WXMOTIF__)
3724 m_gridWin
->GetClientSize( &cw
, &ch
);
3725 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
3726 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
3727 r
.SetRight( wxMin( r
.GetRight(), cw
) );
3728 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
3731 // logical bounds of update region
3733 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
3734 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
3736 // find the cells within these bounds
3739 for ( row
= 0; row
< m_numRows
; row
++ )
3741 if ( GetRowBottom(row
) <= top
)
3744 if ( GetRowTop(row
) > bottom
)
3747 m_rowsExposed
.Add( row
);
3749 for ( col
= 0; col
< m_numCols
; col
++ )
3751 if ( GetColRight(col
) <= left
)
3754 if ( GetColLeft(col
) > right
)
3757 if ( m_colsExposed
.Index( col
) == wxNOT_FOUND
)
3758 m_colsExposed
.Add( col
);
3759 m_cellsExposed
.Add( wxGridCellCoords( row
, col
) );
3768 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
3771 wxPoint
pos( event
.GetPosition() );
3772 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
3774 if ( event
.Dragging() )
3776 m_isDragging
= TRUE
;
3778 if ( event
.LeftIsDown() )
3780 switch( m_cursorMode
)
3782 case WXGRID_CURSOR_RESIZE_ROW
:
3784 int cw
, ch
, left
, dummy
;
3785 m_gridWin
->GetClientSize( &cw
, &ch
);
3786 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
3788 wxClientDC
dc( m_gridWin
);
3791 GetRowTop(m_dragRowOrCol
) +
3792 GetRowMinimalHeight(m_dragRowOrCol
) );
3793 dc
.SetLogicalFunction(wxINVERT
);
3794 if ( m_dragLastPos
>= 0 )
3796 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
3798 dc
.DrawLine( left
, y
, left
+cw
, y
);
3803 case WXGRID_CURSOR_SELECT_ROW
:
3804 if ( (row
= YToRow( y
)) >= 0 &&
3805 !IsInSelection( row
, 0 ) )
3807 SelectRow( row
, TRUE
);
3810 // default label to suppress warnings about "enumeration value
3811 // 'xxx' not handled in switch
3819 m_isDragging
= FALSE
;
3822 // ------------ Entering or leaving the window
3824 if ( event
.Entering() || event
.Leaving() )
3826 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
3830 // ------------ Left button pressed
3832 else if ( event
.LeftDown() )
3834 // don't send a label click event for a hit on the
3835 // edge of the row label - this is probably the user
3836 // wanting to resize the row
3838 if ( YToEdgeOfRow(y
) < 0 )
3842 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
3844 SelectRow( row
, event
.ShiftDown() );
3845 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
3850 // starting to drag-resize a row
3852 if ( CanDragRowSize() )
3853 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
3858 // ------------ Left double click
3860 else if (event
.LeftDClick() )
3862 if ( YToEdgeOfRow(y
) < 0 )
3865 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
);
3870 // ------------ Left button released
3872 else if ( event
.LeftUp() )
3874 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
3876 DoEndDragResizeRow();
3878 // Note: we are ending the event *after* doing
3879 // default processing in this case
3881 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
3884 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
3889 // ------------ Right button down
3891 else if ( event
.RightDown() )
3894 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
3896 // no default action at the moment
3901 // ------------ Right double click
3903 else if ( event
.RightDClick() )
3906 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
3908 // no default action at the moment
3913 // ------------ No buttons down and mouse moving
3915 else if ( event
.Moving() )
3917 m_dragRowOrCol
= YToEdgeOfRow( y
);
3918 if ( m_dragRowOrCol
>= 0 )
3920 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3922 // don't capture the mouse yet
3923 if ( CanDragRowSize() )
3924 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, FALSE
);
3927 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3929 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, FALSE
);
3935 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
3938 wxPoint
pos( event
.GetPosition() );
3939 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
3941 if ( event
.Dragging() )
3943 m_isDragging
= TRUE
;
3945 if ( event
.LeftIsDown() )
3947 switch( m_cursorMode
)
3949 case WXGRID_CURSOR_RESIZE_COL
:
3951 int cw
, ch
, dummy
, top
;
3952 m_gridWin
->GetClientSize( &cw
, &ch
);
3953 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
3955 wxClientDC
dc( m_gridWin
);
3958 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
3959 GetColMinimalWidth(m_dragRowOrCol
));
3960 dc
.SetLogicalFunction(wxINVERT
);
3961 if ( m_dragLastPos
>= 0 )
3963 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
3965 dc
.DrawLine( x
, top
, x
, top
+ch
);
3970 case WXGRID_CURSOR_SELECT_COL
:
3971 if ( (col
= XToCol( x
)) >= 0 &&
3972 !IsInSelection( 0, col
) )
3974 SelectCol( col
, TRUE
);
3977 // default label to suppress warnings about "enumeration value
3978 // 'xxx' not handled in switch
3986 m_isDragging
= FALSE
;
3989 // ------------ Entering or leaving the window
3991 if ( event
.Entering() || event
.Leaving() )
3993 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
3997 // ------------ Left button pressed
3999 else if ( event
.LeftDown() )
4001 // don't send a label click event for a hit on the
4002 // edge of the col label - this is probably the user
4003 // wanting to resize the col
4005 if ( XToEdgeOfCol(x
) < 0 )
4009 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
4011 SelectCol( col
, event
.ShiftDown() );
4012 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, m_colLabelWin
);
4017 // starting to drag-resize a col
4019 if ( CanDragColSize() )
4020 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
);
4025 // ------------ Left double click
4027 if ( event
.LeftDClick() )
4029 if ( XToEdgeOfCol(x
) < 0 )
4032 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
);
4037 // ------------ Left button released
4039 else if ( event
.LeftUp() )
4041 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
4043 DoEndDragResizeCol();
4045 // Note: we are ending the event *after* doing
4046 // default processing in this case
4048 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
4051 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
4056 // ------------ Right button down
4058 else if ( event
.RightDown() )
4061 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
4063 // no default action at the moment
4068 // ------------ Right double click
4070 else if ( event
.RightDClick() )
4073 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
4075 // no default action at the moment
4080 // ------------ No buttons down and mouse moving
4082 else if ( event
.Moving() )
4084 m_dragRowOrCol
= XToEdgeOfCol( x
);
4085 if ( m_dragRowOrCol
>= 0 )
4087 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4089 // don't capture the cursor yet
4090 if ( CanDragColSize() )
4091 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
, FALSE
);
4094 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
4096 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
, FALSE
);
4102 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
4104 if ( event
.LeftDown() )
4106 // indicate corner label by having both row and
4109 if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
4115 else if ( event
.LeftDClick() )
4117 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
4120 else if ( event
.RightDown() )
4122 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
4124 // no default action at the moment
4128 else if ( event
.RightDClick() )
4130 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
4132 // no default action at the moment
4137 void wxGrid::ChangeCursorMode(CursorMode mode
,
4142 static const wxChar
*cursorModes
[] =
4151 wxLogTrace(_T("grid"),
4152 _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
4153 win
== m_colLabelWin
? _T("colLabelWin")
4154 : win
? _T("rowLabelWin")
4156 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
4157 #endif // __WXDEBUG__
4159 if ( mode
== m_cursorMode
)
4164 // by default use the grid itself
4170 m_winCapture
->ReleaseMouse();
4171 m_winCapture
= (wxWindow
*)NULL
;
4174 m_cursorMode
= mode
;
4176 switch ( m_cursorMode
)
4178 case WXGRID_CURSOR_RESIZE_ROW
:
4179 win
->SetCursor( m_rowResizeCursor
);
4182 case WXGRID_CURSOR_RESIZE_COL
:
4183 win
->SetCursor( m_colResizeCursor
);
4187 win
->SetCursor( *wxSTANDARD_CURSOR
);
4190 // we need to capture mouse when resizing
4191 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
4192 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
4194 if ( captureMouse
&& resize
)
4196 win
->CaptureMouse();
4201 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
4204 wxPoint
pos( event
.GetPosition() );
4205 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
4207 wxGridCellCoords coords
;
4208 XYToCell( x
, y
, coords
);
4210 if ( event
.Dragging() )
4212 //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
4214 // Don't start doing anything until the mouse has been drug at
4215 // least 3 pixels in any direction...
4218 if (m_startDragPos
== wxDefaultPosition
)
4220 m_startDragPos
= pos
;
4223 if (abs(m_startDragPos
.x
- pos
.x
) < 4 && abs(m_startDragPos
.y
- pos
.y
) < 4)
4227 m_isDragging
= TRUE
;
4228 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4230 // Hide the edit control, so it
4231 // won't interfer with drag-shrinking.
4232 if ( IsCellEditControlEnabled() )
4234 HideCellEditControl();
4235 SaveEditControlValue();
4238 // Have we captured the mouse yet?
4241 m_winCapture
= m_gridWin
;
4242 m_winCapture
->CaptureMouse();
4245 if ( coords
!= wxGridNoCellCoords
)
4247 if ( !IsSelection() )
4249 SelectBlock( coords
, coords
);
4253 SelectBlock( m_currentCellCoords
, coords
);
4256 if (! IsVisible(coords
))
4258 MakeCellVisible(coords
);
4259 // TODO: need to introduce a delay or something here. The
4260 // scrolling is way to fast, at least on MSW.
4264 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
4266 int cw
, ch
, left
, dummy
;
4267 m_gridWin
->GetClientSize( &cw
, &ch
);
4268 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
4270 wxClientDC
dc( m_gridWin
);
4272 y
= wxMax( y
, GetRowTop(m_dragRowOrCol
) +
4273 GetRowMinimalHeight(m_dragRowOrCol
) );
4274 dc
.SetLogicalFunction(wxINVERT
);
4275 if ( m_dragLastPos
>= 0 )
4277 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
4279 dc
.DrawLine( left
, y
, left
+cw
, y
);
4282 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
4284 int cw
, ch
, dummy
, top
;
4285 m_gridWin
->GetClientSize( &cw
, &ch
);
4286 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
4288 wxClientDC
dc( m_gridWin
);
4290 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
4291 GetColMinimalWidth(m_dragRowOrCol
) );
4292 dc
.SetLogicalFunction(wxINVERT
);
4293 if ( m_dragLastPos
>= 0 )
4295 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
4297 dc
.DrawLine( x
, top
, x
, top
+ch
);
4304 m_isDragging
= FALSE
;
4305 m_startDragPos
= wxDefaultPosition
;
4307 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
4308 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
4311 if ( event
.Entering() || event
.Leaving() )
4313 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
4314 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
4319 // ------------ Left button pressed
4321 if ( event
.LeftDown() && coords
!= wxGridNoCellCoords
)
4323 if ( !event
.ShiftDown() && !event
.ControlDown() )
4325 if ( event
.ShiftDown() )
4327 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
4328 m_currentCellCoords
.GetCol(),
4332 else if ( XToEdgeOfCol(x
) < 0 &&
4333 YToEdgeOfRow(y
) < 0 )
4335 if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK
,
4340 DisableCellEditControl();
4341 MakeCellVisible( coords
);
4343 // if this is the second click on this cell then start
4345 if ( m_waitForSlowClick
&&
4346 (coords
== m_currentCellCoords
) &&
4347 CanEnableCellControl())
4349 EnableCellEditControl();
4351 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
4352 wxGridCellEditor
*editor
= attr
->GetEditor(this,
4355 editor
->StartingClick();
4359 m_waitForSlowClick
= FALSE
;
4363 m_selection
->ToggleCellSelection( coords
.GetRow(),
4365 m_selectingTopLeft
= wxGridNoCellCoords
;
4366 m_selectingBottomRight
= wxGridNoCellCoords
;
4367 SetCurrentCell( coords
);
4368 m_waitForSlowClick
= TRUE
;
4375 // ------------ Left double click
4377 else if ( event
.LeftDClick() && coords
!= wxGridNoCellCoords
)
4379 DisableCellEditControl();
4381 if ( XToEdgeOfCol(x
) < 0 && YToEdgeOfRow(y
) < 0 )
4383 SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK
,
4391 // ------------ Left button released
4393 else if ( event
.LeftUp() )
4395 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4397 if ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
4398 m_selectingBottomRight
!= wxGridNoCellCoords
)
4402 m_winCapture
->ReleaseMouse();
4403 m_winCapture
= NULL
;
4405 m_selection
->SelectBlock( m_selectingTopLeft
.GetRow(),
4406 m_selectingTopLeft
.GetCol(),
4407 m_selectingBottomRight
.GetRow(),
4408 m_selectingBottomRight
.GetCol(),
4410 m_selectingTopLeft
= wxGridNoCellCoords
;
4411 m_selectingBottomRight
= wxGridNoCellCoords
;
4414 // Show the edit control, if it has been hidden for
4416 ShowCellEditControl();
4418 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
4420 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
4421 DoEndDragResizeRow();
4423 // Note: we are ending the event *after* doing
4424 // default processing in this case
4426 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
4428 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
4430 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
4431 DoEndDragResizeCol();
4433 // Note: we are ending the event *after* doing
4434 // default processing in this case
4436 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
4443 // ------------ Right button down
4445 else if ( event
.RightDown() && coords
!= wxGridNoCellCoords
)
4447 DisableCellEditControl();
4448 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK
,
4453 // no default action at the moment
4458 // ------------ Right double click
4460 else if ( event
.RightDClick() && coords
!= wxGridNoCellCoords
)
4462 DisableCellEditControl();
4463 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK
,
4468 // no default action at the moment
4472 // ------------ Moving and no button action
4474 else if ( event
.Moving() && !event
.IsButton() )
4476 int dragRow
= YToEdgeOfRow( y
);
4477 int dragCol
= XToEdgeOfCol( x
);
4479 // Dragging on the corner of a cell to resize in both
4480 // directions is not implemented yet...
4482 if ( dragRow
>= 0 && dragCol
>= 0 )
4484 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
4490 m_dragRowOrCol
= dragRow
;
4492 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4494 if ( CanDragRowSize() && CanDragGridSize() )
4495 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
);
4500 m_dragRowOrCol
= dragCol
;
4508 m_dragRowOrCol
= dragCol
;
4510 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
4512 if ( CanDragColSize() && CanDragGridSize() )
4513 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
);
4519 // Neither on a row or col edge
4521 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
4523 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
4529 void wxGrid::DoEndDragResizeRow()
4531 if ( m_dragLastPos
>= 0 )
4533 // erase the last line and resize the row
4535 int cw
, ch
, left
, dummy
;
4536 m_gridWin
->GetClientSize( &cw
, &ch
);
4537 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
4539 wxClientDC
dc( m_gridWin
);
4541 dc
.SetLogicalFunction( wxINVERT
);
4542 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
4543 HideCellEditControl();
4544 SaveEditControlValue();
4546 int rowTop
= GetRowTop(m_dragRowOrCol
);
4547 SetRowSize( m_dragRowOrCol
,
4548 wxMax( m_dragLastPos
- rowTop
, WXGRID_MIN_ROW_HEIGHT
) );
4550 if ( !GetBatchCount() )
4552 // Only needed to get the correct rect.y:
4553 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
4555 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
4556 rect
.width
= m_rowLabelWidth
;
4557 rect
.height
= ch
- rect
.y
;
4558 m_rowLabelWin
->Refresh( TRUE
, &rect
);
4560 m_gridWin
->Refresh( FALSE
, &rect
);
4563 ShowCellEditControl();
4568 void wxGrid::DoEndDragResizeCol()
4570 if ( m_dragLastPos
>= 0 )
4572 // erase the last line and resize the col
4574 int cw
, ch
, dummy
, top
;
4575 m_gridWin
->GetClientSize( &cw
, &ch
);
4576 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
4578 wxClientDC
dc( m_gridWin
);
4580 dc
.SetLogicalFunction( wxINVERT
);
4581 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
4582 HideCellEditControl();
4583 SaveEditControlValue();
4585 int colLeft
= GetColLeft(m_dragRowOrCol
);
4586 SetColSize( m_dragRowOrCol
,
4587 wxMax( m_dragLastPos
- colLeft
,
4588 GetColMinimalWidth(m_dragRowOrCol
) ) );
4590 if ( !GetBatchCount() )
4592 // Only needed to get the correct rect.x:
4593 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
4595 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
4596 rect
.width
= cw
- rect
.x
;
4597 rect
.height
= m_colLabelHeight
;
4598 m_colLabelWin
->Refresh( TRUE
, &rect
);
4600 m_gridWin
->Refresh( FALSE
, &rect
);
4603 ShowCellEditControl();
4610 // ------ interaction with data model
4612 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
4614 switch ( msg
.GetId() )
4616 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
4617 return GetModelValues();
4619 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
4620 return SetModelValues();
4622 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
4623 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
4624 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
4625 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
4626 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
4627 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
4628 return Redimension( msg
);
4637 // The behaviour of this function depends on the grid table class
4638 // Clear() function. For the default wxGridStringTable class the
4639 // behavious is to replace all cell contents with wxEmptyString but
4640 // not to change the number of rows or cols.
4642 void wxGrid::ClearGrid()
4646 if (IsCellEditControlEnabled())
4647 DisableCellEditControl();
4650 if ( !GetBatchCount() ) m_gridWin
->Refresh();
4655 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
4657 // TODO: something with updateLabels flag
4661 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
4667 if (IsCellEditControlEnabled())
4668 DisableCellEditControl();
4670 bool ok
= m_table
->InsertRows( pos
, numRows
);
4672 // the table will have sent the results of the insert row
4673 // operation to this view object as a grid table message
4677 if ( m_numCols
== 0 )
4679 m_table
->AppendCols( WXGRID_DEFAULT_NUMBER_COLS
);
4681 // TODO: perhaps instead of appending the default number of cols
4682 // we should remember what the last non-zero number of cols was ?
4686 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4688 // if we have just inserted cols into an empty grid the current
4689 // cell will be undefined...
4691 SetCurrentCell( 0, 0 );
4694 m_selection
->UpdateRows( pos
, numRows
);
4695 if ( !GetBatchCount() ) Refresh();
4707 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
4709 // TODO: something with updateLabels flag
4713 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
4717 if ( m_table
&& m_table
->AppendRows( numRows
) )
4719 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4721 // if we have just inserted cols into an empty grid the current
4722 // cell will be undefined...
4724 SetCurrentCell( 0, 0 );
4727 // the table will have sent the results of the append row
4728 // operation to this view object as a grid table message
4730 if ( !GetBatchCount() ) Refresh();
4740 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
4742 // TODO: something with updateLabels flag
4746 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
4752 if (IsCellEditControlEnabled())
4753 DisableCellEditControl();
4755 if (m_table
->DeleteRows( pos
, numRows
))
4758 // the table will have sent the results of the delete row
4759 // operation to this view object as a grid table message
4761 m_selection
->UpdateRows( pos
, -((int)numRows
) );
4762 if ( !GetBatchCount() ) Refresh();
4770 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
4772 // TODO: something with updateLabels flag
4776 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
4782 if (IsCellEditControlEnabled())
4783 DisableCellEditControl();
4785 bool ok
= m_table
->InsertCols( pos
, numCols
);
4787 // the table will have sent the results of the insert col
4788 // operation to this view object as a grid table message
4792 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4794 // if we have just inserted cols into an empty grid the current
4795 // cell will be undefined...
4797 SetCurrentCell( 0, 0 );
4800 m_selection
->UpdateCols( pos
, numCols
);
4801 if ( !GetBatchCount() ) Refresh();
4813 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
4815 // TODO: something with updateLabels flag
4819 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
4823 if ( m_table
&& m_table
->AppendCols( numCols
) )
4825 // the table will have sent the results of the append col
4826 // operation to this view object as a grid table message
4828 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4830 // if we have just inserted cols into an empty grid the current
4831 // cell will be undefined...
4833 SetCurrentCell( 0, 0 );
4836 if ( !GetBatchCount() ) Refresh();
4846 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
4848 // TODO: something with updateLabels flag
4852 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
4858 if (IsCellEditControlEnabled())
4859 DisableCellEditControl();
4861 if ( m_table
->DeleteCols( pos
, numCols
) )
4863 // the table will have sent the results of the delete col
4864 // operation to this view object as a grid table message
4866 m_selection
->UpdateCols( pos
, -((int)numCols
) );
4867 if ( !GetBatchCount() ) Refresh();
4877 // ----- event handlers
4880 // Generate a grid event based on a mouse event and
4881 // return the result of ProcessEvent()
4883 bool wxGrid::SendEvent( const wxEventType type
,
4885 wxMouseEvent
& mouseEv
)
4887 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
4889 int rowOrCol
= (row
== -1 ? col
: row
);
4891 wxGridSizeEvent
gridEvt( GetId(),
4895 mouseEv
.GetX(), mouseEv
.GetY(),
4896 mouseEv
.ControlDown(),
4897 mouseEv
.ShiftDown(),
4899 mouseEv
.MetaDown() );
4901 return GetEventHandler()->ProcessEvent(gridEvt
);
4903 else if ( type
== wxEVT_GRID_RANGE_SELECT
)
4905 // Right now, it should _never_ end up here!
4906 wxGridRangeSelectEvent
gridEvt( GetId(),
4910 m_selectingBottomRight
,
4912 mouseEv
.ControlDown(),
4913 mouseEv
.ShiftDown(),
4915 mouseEv
.MetaDown() );
4917 return GetEventHandler()->ProcessEvent(gridEvt
);
4921 wxGridEvent
gridEvt( GetId(),
4926 mouseEv
.GetX(), mouseEv
.GetY(),
4927 mouseEv
.ControlDown(),
4928 mouseEv
.ShiftDown(),
4930 mouseEv
.MetaDown() );
4932 return GetEventHandler()->ProcessEvent(gridEvt
);
4937 // Generate a grid event of specified type and return the result
4938 // of ProcessEvent().
4940 bool wxGrid::SendEvent( const wxEventType type
,
4943 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
4945 int rowOrCol
= (row
== -1 ? col
: row
);
4947 wxGridSizeEvent
gridEvt( GetId(),
4952 return GetEventHandler()->ProcessEvent(gridEvt
);
4956 wxGridEvent
gridEvt( GetId(),
4961 return GetEventHandler()->ProcessEvent(gridEvt
);
4966 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
4968 wxPaintDC
dc( this );
4970 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
4971 m_numRows
&& m_numCols
)
4973 m_currentCellCoords
.Set(0, 0);
4974 ShowCellEditControl();
4981 // This is just here to make sure that CalcDimensions gets called when
4982 // the grid view is resized... then the size event is skipped to allow
4983 // the box sizers to handle everything
4985 void wxGrid::OnSize( wxSizeEvent
& event
)
4992 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
4994 if ( m_inOnKeyDown
)
4996 // shouldn't be here - we are going round in circles...
4998 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
5001 m_inOnKeyDown
= TRUE
;
5003 // propagate the event up and see if it gets processed
5005 wxWindow
*parent
= GetParent();
5006 wxKeyEvent
keyEvt( event
);
5007 keyEvt
.SetEventObject( parent
);
5009 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
5012 // try local handlers
5014 switch ( event
.KeyCode() )
5017 if ( event
.ControlDown() )
5019 MoveCursorUpBlock( event
.ShiftDown() );
5023 MoveCursorUp( event
.ShiftDown() );
5028 if ( event
.ControlDown() )
5030 MoveCursorDownBlock( event
.ShiftDown() );
5034 MoveCursorDown( event
.ShiftDown() );
5039 if ( event
.ControlDown() )
5041 MoveCursorLeftBlock( event
.ShiftDown() );
5045 MoveCursorLeft( event
.ShiftDown() );
5050 if ( event
.ControlDown() )
5052 MoveCursorRightBlock( event
.ShiftDown() );
5056 MoveCursorRight( event
.ShiftDown() );
5061 if ( event
.ControlDown() )
5063 event
.Skip(); // to let the edit control have the return
5067 MoveCursorDown( event
.ShiftDown() );
5072 m_selection
->ClearSelection();
5076 if (event
.ShiftDown())
5077 MoveCursorLeft( FALSE
);
5079 MoveCursorRight( FALSE
);
5083 if ( event
.ControlDown() )
5085 MakeCellVisible( 0, 0 );
5086 SetCurrentCell( 0, 0 );
5095 if ( event
.ControlDown() )
5097 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
5098 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
5116 if ( !IsEditable() )
5118 MoveCursorRight( FALSE
);
5121 // Otherwise fall through to default
5124 m_selection
->ToggleCellSelection( m_currentCellCoords
.GetRow(),
5125 m_currentCellCoords
.GetCol() );
5130 // alphanumeric keys or F2 (special key just for this) enable
5131 // the cell edit control
5132 // On just Shift/Control I get values for event.KeyCode()
5133 // that are outside the range where isalnum's behaviour is
5134 // well defined, so do an additional sanity check.
5135 if ( !(event
.AltDown() ||
5137 event
.ControlDown()) &&
5138 ((isalnum(event
.KeyCode()) &&
5139 (event
.KeyCode() < 256 && event
.KeyCode() >= 0)) ||
5140 event
.KeyCode() == WXK_F2
) &&
5141 !IsCellEditControlEnabled() &&
5142 CanEnableCellControl() )
5144 EnableCellEditControl();
5145 int row
= m_currentCellCoords
.GetRow();
5146 int col
= m_currentCellCoords
.GetCol();
5147 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5148 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
5149 editor
->StartingKey(event
);
5155 // let others process char events with modifiers or all
5156 // char events for readonly cells
5163 m_inOnKeyDown
= FALSE
;
5167 void wxGrid::OnEraseBackground(wxEraseEvent
&)
5171 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
5174 m_currentCellCoords
!= wxGridNoCellCoords
)
5176 HideCellEditControl();
5177 DisableCellEditControl();
5179 // Clear the old current cell highlight
5180 wxRect r
= BlockToDeviceRect(m_currentCellCoords
, m_currentCellCoords
);
5182 // Otherwise refresh redraws the highlight!
5183 m_currentCellCoords
= coords
;
5185 m_gridWin
->Refresh( FALSE
, &r
);
5188 m_currentCellCoords
= coords
;
5192 wxClientDC
dc(m_gridWin
);
5195 wxGridCellAttr
* attr
= GetCellAttr(coords
);
5196 DrawCellHighlight(dc
, attr
);
5199 // SN: For my extended selection code, automatic
5200 // deselection is definitely not a good idea.
5201 if ( IsSelection() )
5203 wxRect
r( SelectionToDeviceRect() );
5205 if ( !GetBatchCount() ) m_gridWin
->Refresh( FALSE
, &r
);
5213 // ------ functions to get/send data (see also public functions)
5216 bool wxGrid::GetModelValues()
5220 // all we need to do is repaint the grid
5222 m_gridWin
->Refresh();
5230 bool wxGrid::SetModelValues()
5236 for ( row
= 0; row
< m_numRows
; row
++ )
5238 for ( col
= 0; col
< m_numCols
; col
++ )
5240 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
5252 // Note - this function only draws cells that are in the list of
5253 // exposed cells (usually set from the update region by
5254 // CalcExposedCells)
5256 void wxGrid::DrawGridCellArea( wxDC
& dc
)
5258 if ( !m_numRows
|| !m_numCols
) return;
5261 size_t numCells
= m_cellsExposed
.GetCount();
5263 for ( i
= 0; i
< numCells
; i
++ )
5265 DrawCell( dc
, m_cellsExposed
[i
] );
5270 void wxGrid::DrawGridSpace( wxDC
& dc
)
5272 if ( m_numRows
&& m_numCols
)
5275 m_gridWin
->GetClientSize( &cw
, &ch
);
5278 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
5280 if ( right
> GetColRight(m_numCols
-1) ||
5281 bottom
> GetRowBottom(m_numRows
-1) )
5284 CalcUnscrolledPosition( 0, 0, &left
, &top
);
5286 dc
.SetBrush( wxBrush(GetDefaultCellBackgroundColour(), wxSOLID
) );
5287 dc
.SetPen( *wxTRANSPARENT_PEN
);
5289 if ( right
> GetColRight(m_numCols
-1) )
5290 dc
.DrawRectangle( GetColRight(m_numCols
-1), top
,
5291 right
- GetColRight(m_numCols
-1), ch
);
5293 if ( bottom
> GetRowBottom(m_numRows
-1) )
5294 dc
.DrawRectangle( left
, GetRowBottom(m_numRows
-1),
5295 cw
, bottom
- GetRowBottom(m_numRows
-1) );
5301 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
5303 int row
= coords
.GetRow();
5304 int col
= coords
.GetCol();
5306 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
5309 // we draw the cell border ourselves
5310 #if !WXGRID_DRAW_LINES
5311 if ( m_gridLinesEnabled
)
5312 DrawCellBorder( dc
, coords
);
5315 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5317 bool isCurrent
= coords
== m_currentCellCoords
;
5320 rect
.x
= GetColLeft(col
);
5321 rect
.y
= GetRowTop(row
);
5322 rect
.width
= GetColWidth(col
) - 1;
5323 rect
.height
= GetRowHeight(row
) - 1;
5325 // if the editor is shown, we should use it and not the renderer
5326 if ( isCurrent
&& IsCellEditControlEnabled() )
5328 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
5329 editor
->PaintBackground(rect
, attr
);
5334 // but all the rest is drawn by the cell renderer and hence may be
5336 wxGridCellRenderer
*renderer
= attr
->GetRenderer(this, row
, col
);
5337 renderer
->Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
5344 void wxGrid::DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
)
5346 int row
= m_currentCellCoords
.GetRow();
5347 int col
= m_currentCellCoords
.GetCol();
5349 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
5353 rect
.x
= GetColLeft(col
);
5354 rect
.y
= GetRowTop(row
);
5355 rect
.width
= GetColWidth(col
) - 1;
5356 rect
.height
= GetRowHeight(row
) - 1;
5358 // hmmm... what could we do here to show that the cell is disabled?
5359 // for now, I just draw a thinner border than for the other ones, but
5360 // it doesn't look really good
5361 dc
.SetPen(wxPen(m_gridLineColour
, attr
->IsReadOnly() ? 1 : 3, wxSOLID
));
5362 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
5364 dc
.DrawRectangle(rect
);
5367 // VZ: my experiments with 3d borders...
5369 // how to properly set colours for arbitrary bg?
5370 wxCoord x1
= rect
.x
,
5372 x2
= rect
.x
+ rect
.width
-1,
5373 y2
= rect
.y
+ rect
.height
-1;
5375 dc
.SetPen(*wxWHITE_PEN
);
5376 dc
.DrawLine(x1
, y1
, x2
, y1
);
5377 dc
.DrawLine(x1
, y1
, x1
, y2
);
5379 dc
.DrawLine(x1
+ 1, y2
- 1, x2
- 1, y2
- 1);
5380 dc
.DrawLine(x2
- 1, y1
+ 1, x2
- 1, y2
);
5382 dc
.SetPen(*wxBLACK_PEN
);
5383 dc
.DrawLine(x1
, y2
, x2
, y2
);
5384 dc
.DrawLine(x2
, y1
, x2
, y2
+1);
5389 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
5391 int row
= coords
.GetRow();
5392 int col
= coords
.GetCol();
5393 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
5396 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
5398 // right hand border
5400 dc
.DrawLine( GetColRight(col
), GetRowTop(row
),
5401 GetColRight(col
), GetRowBottom(row
) );
5405 dc
.DrawLine( GetColLeft(col
), GetRowBottom(row
),
5406 GetColRight(col
), GetRowBottom(row
) );
5409 void wxGrid::DrawHighlight(wxDC
& dc
)
5411 if ( IsCellEditControlEnabled() )
5413 // don't show highlight when the edit control is shown
5417 // if the active cell was repainted, repaint its highlight too because it
5418 // might have been damaged by the grid lines
5419 size_t count
= m_cellsExposed
.GetCount();
5420 for ( size_t n
= 0; n
< count
; n
++ )
5422 if ( m_cellsExposed
[n
] == m_currentCellCoords
)
5424 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
5425 DrawCellHighlight(dc
, attr
);
5433 // TODO: remove this ???
5434 // This is used to redraw all grid lines e.g. when the grid line colour
5437 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
)
5439 if ( !m_gridLinesEnabled
||
5441 !m_numCols
) return;
5443 int top
, bottom
, left
, right
;
5449 m_gridWin
->GetClientSize(&cw
, &ch
);
5451 // virtual coords of visible area
5453 CalcUnscrolledPosition( 0, 0, &left
, &top
);
5454 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
5459 reg
.GetBox(x
, y
, w
, h
);
5460 CalcUnscrolledPosition( x
, y
, &left
, &top
);
5461 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
5465 m_gridWin
->GetClientSize(&cw
, &ch
);
5466 CalcUnscrolledPosition( 0, 0, &left
, &top
);
5467 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
5470 // avoid drawing grid lines past the last row and col
5472 right
= wxMin( right
, GetColRight(m_numCols
- 1) );
5473 bottom
= wxMin( bottom
, GetRowBottom(m_numRows
- 1) );
5475 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
5477 // horizontal grid lines
5480 for ( i
= 0; i
< m_numRows
; i
++ )
5482 int bot
= GetRowBottom(i
) - 1;
5491 dc
.DrawLine( left
, bot
, right
, bot
);
5496 // vertical grid lines
5498 for ( i
= 0; i
< m_numCols
; i
++ )
5500 int colRight
= GetColRight(i
) - 1;
5501 if ( colRight
> right
)
5506 if ( colRight
>= left
)
5508 dc
.DrawLine( colRight
, top
, colRight
, bottom
);
5514 void wxGrid::DrawRowLabels( wxDC
& dc
)
5516 if ( !m_numRows
|| !m_numCols
) return;
5519 size_t numLabels
= m_rowLabelsExposed
.GetCount();
5521 for ( i
= 0; i
< numLabels
; i
++ )
5523 DrawRowLabel( dc
, m_rowLabelsExposed
[i
] );
5528 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
5530 if ( GetRowHeight(row
) <= 0 )
5533 int rowTop
= GetRowTop(row
),
5534 rowBottom
= GetRowBottom(row
) - 1;
5536 dc
.SetPen( *wxBLACK_PEN
);
5537 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
5538 m_rowLabelWidth
-1, rowBottom
);
5540 dc
.DrawLine( 0, rowBottom
, m_rowLabelWidth
-1, rowBottom
);
5542 dc
.SetPen( *wxWHITE_PEN
);
5543 dc
.DrawLine( 0, rowTop
, 0, rowBottom
);
5544 dc
.DrawLine( 0, rowTop
, m_rowLabelWidth
-1, rowTop
);
5546 dc
.SetBackgroundMode( wxTRANSPARENT
);
5547 dc
.SetTextForeground( GetLabelTextColour() );
5548 dc
.SetFont( GetLabelFont() );
5551 GetRowLabelAlignment( &hAlign
, &vAlign
);
5555 rect
.SetY( GetRowTop(row
) + 2 );
5556 rect
.SetWidth( m_rowLabelWidth
- 4 );
5557 rect
.SetHeight( GetRowHeight(row
) - 4 );
5558 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
5562 void wxGrid::DrawColLabels( wxDC
& dc
)
5564 if ( !m_numRows
|| !m_numCols
) return;
5567 size_t numLabels
= m_colLabelsExposed
.GetCount();
5569 for ( i
= 0; i
< numLabels
; i
++ )
5571 DrawColLabel( dc
, m_colLabelsExposed
[i
] );
5576 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
5578 if ( GetColWidth(col
) <= 0 )
5581 int colLeft
= GetColLeft(col
),
5582 colRight
= GetColRight(col
) - 1;
5584 dc
.SetPen( *wxBLACK_PEN
);
5585 dc
.DrawLine( colRight
, 0,
5586 colRight
, m_colLabelHeight
-1 );
5588 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
5589 colRight
, m_colLabelHeight
-1 );
5591 dc
.SetPen( *wxWHITE_PEN
);
5592 dc
.DrawLine( colLeft
, 0, colLeft
, m_colLabelHeight
-1 );
5593 dc
.DrawLine( colLeft
, 0, colRight
, 0 );
5595 dc
.SetBackgroundMode( wxTRANSPARENT
);
5596 dc
.SetTextForeground( GetLabelTextColour() );
5597 dc
.SetFont( GetLabelFont() );
5599 dc
.SetBackgroundMode( wxTRANSPARENT
);
5600 dc
.SetTextForeground( GetLabelTextColour() );
5601 dc
.SetFont( GetLabelFont() );
5604 GetColLabelAlignment( &hAlign
, &vAlign
);
5607 rect
.SetX( colLeft
+ 2 );
5609 rect
.SetWidth( GetColWidth(col
) - 4 );
5610 rect
.SetHeight( m_colLabelHeight
- 4 );
5611 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
);
5615 void wxGrid::DrawTextRectangle( wxDC
& dc
,
5616 const wxString
& value
,
5621 long textWidth
, textHeight
;
5622 long lineWidth
, lineHeight
;
5623 wxArrayString lines
;
5625 dc
.SetClippingRegion( rect
);
5626 StringToLines( value
, lines
);
5627 if ( lines
.GetCount() )
5629 GetTextBoxSize( dc
, lines
, &textWidth
, &textHeight
);
5630 dc
.GetTextExtent( lines
[0], &lineWidth
, &lineHeight
);
5633 switch ( horizAlign
)
5636 x
= rect
.x
+ (rect
.width
- textWidth
- 1);
5640 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
5649 switch ( vertAlign
)
5652 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
5656 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
5665 for ( size_t i
= 0; i
< lines
.GetCount(); i
++ )
5667 dc
.DrawText( lines
[i
], (long)x
, (long)y
);
5672 dc
.DestroyClippingRegion();
5676 // Split multi line text up into an array of strings. Any existing
5677 // contents of the string array are preserved.
5679 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
5683 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
5684 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
5686 while ( startPos
< (int)tVal
.Length() )
5688 pos
= tVal
.Mid(startPos
).Find( eol
);
5693 else if ( pos
== 0 )
5695 lines
.Add( wxEmptyString
);
5699 lines
.Add( value
.Mid(startPos
, pos
) );
5703 if ( startPos
< (int)value
.Length() )
5705 lines
.Add( value
.Mid( startPos
) );
5710 void wxGrid::GetTextBoxSize( wxDC
& dc
,
5711 wxArrayString
& lines
,
5712 long *width
, long *height
)
5719 for ( i
= 0; i
< lines
.GetCount(); i
++ )
5721 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
5722 w
= wxMax( w
, lineW
);
5732 // ------ Edit control functions
5736 void wxGrid::EnableEditing( bool edit
)
5738 // TODO: improve this ?
5740 if ( edit
!= m_editable
)
5744 // FIXME IMHO this won't disable the edit control if edit == FALSE
5745 // because of the check in the beginning of
5746 // EnableCellEditControl() just below (VZ)
5747 EnableCellEditControl(m_editable
);
5752 void wxGrid::EnableCellEditControl( bool enable
)
5757 if ( m_currentCellCoords
== wxGridNoCellCoords
)
5758 SetCurrentCell( 0, 0 );
5760 if ( enable
!= m_cellEditCtrlEnabled
)
5762 // TODO allow the app to Veto() this event?
5763 SendEvent(enable
? wxEVT_GRID_EDITOR_SHOWN
: wxEVT_GRID_EDITOR_HIDDEN
);
5767 // this should be checked by the caller!
5768 wxASSERT_MSG( CanEnableCellControl(),
5769 _T("can't enable editing for this cell!") );
5771 // do it before ShowCellEditControl()
5772 m_cellEditCtrlEnabled
= enable
;
5774 ShowCellEditControl();
5778 HideCellEditControl();
5779 SaveEditControlValue();
5781 // do it after HideCellEditControl()
5782 m_cellEditCtrlEnabled
= enable
;
5787 bool wxGrid::IsCurrentCellReadOnly() const
5790 wxGridCellAttr
* attr
= ((wxGrid
*)this)->GetCellAttr(m_currentCellCoords
);
5791 bool readonly
= attr
->IsReadOnly();
5797 bool wxGrid::CanEnableCellControl() const
5799 return m_editable
&& !IsCurrentCellReadOnly();
5802 bool wxGrid::IsCellEditControlEnabled() const
5804 // the cell edit control might be disable for all cells or just for the
5805 // current one if it's read only
5806 return m_cellEditCtrlEnabled
? !IsCurrentCellReadOnly() : FALSE
;
5809 void wxGrid::ShowCellEditControl()
5811 if ( IsCellEditControlEnabled() )
5813 if ( !IsVisible( m_currentCellCoords
) )
5819 wxRect rect
= CellToRect( m_currentCellCoords
);
5820 int row
= m_currentCellCoords
.GetRow();
5821 int col
= m_currentCellCoords
.GetCol();
5823 // convert to scrolled coords
5825 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
5827 // done in PaintBackground()
5829 // erase the highlight and the cell contents because the editor
5830 // might not cover the entire cell
5831 wxClientDC
dc( m_gridWin
);
5833 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
); //wxBrush(attr->GetBackgroundColour(), wxSOLID));
5834 dc
.SetPen(*wxTRANSPARENT_PEN
);
5835 dc
.DrawRectangle(rect
);
5838 // cell is shifted by one pixel
5842 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5843 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
5844 if ( !editor
->IsCreated() )
5846 editor
->Create(m_gridWin
, -1,
5847 new wxGridCellEditorEvtHandler(this, editor
));
5850 editor
->Show( TRUE
, attr
);
5852 editor
->SetSize( rect
);
5854 editor
->BeginEdit(row
, col
, this);
5863 void wxGrid::HideCellEditControl()
5865 if ( IsCellEditControlEnabled() )
5867 int row
= m_currentCellCoords
.GetRow();
5868 int col
= m_currentCellCoords
.GetCol();
5870 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5871 wxGridCellEditor
*editor
= attr
->GetEditor(this, row
, col
);
5872 editor
->Show( FALSE
);
5875 m_gridWin
->SetFocus();
5880 void wxGrid::SaveEditControlValue()
5882 if ( IsCellEditControlEnabled() )
5884 int row
= m_currentCellCoords
.GetRow();
5885 int col
= m_currentCellCoords
.GetCol();
5887 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5888 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
5889 bool changed
= editor
->EndEdit(row
, col
, this);
5896 SendEvent( wxEVT_GRID_CELL_CHANGE
,
5897 m_currentCellCoords
.GetRow(),
5898 m_currentCellCoords
.GetCol() );
5905 // ------ Grid location functions
5906 // Note that all of these functions work with the logical coordinates of
5907 // grid cells and labels so you will need to convert from device
5908 // coordinates for mouse events etc.
5911 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
5913 int row
= YToRow(y
);
5914 int col
= XToCol(x
);
5916 if ( row
== -1 || col
== -1 )
5918 coords
= wxGridNoCellCoords
;
5922 coords
.Set( row
, col
);
5927 int wxGrid::YToRow( int y
)
5931 for ( i
= 0; i
< m_numRows
; i
++ )
5933 if ( y
< GetRowBottom(i
) )
5941 int wxGrid::XToCol( int x
)
5945 for ( i
= 0; i
< m_numCols
; i
++ )
5947 if ( x
< GetColRight(i
) )
5955 // return the row number that that the y coord is near the edge of, or
5956 // -1 if not near an edge
5958 int wxGrid::YToEdgeOfRow( int y
)
5962 for ( i
= 0; i
< m_numRows
; i
++ )
5964 if ( GetRowHeight(i
) > WXGRID_LABEL_EDGE_ZONE
)
5966 d
= abs( y
- GetRowBottom(i
) );
5967 if ( d
< WXGRID_LABEL_EDGE_ZONE
)
5976 // return the col number that that the x coord is near the edge of, or
5977 // -1 if not near an edge
5979 int wxGrid::XToEdgeOfCol( int x
)
5983 for ( i
= 0; i
< m_numCols
; i
++ )
5985 if ( GetColWidth(i
) > WXGRID_LABEL_EDGE_ZONE
)
5987 d
= abs( x
- GetColRight(i
) );
5988 if ( d
< WXGRID_LABEL_EDGE_ZONE
)
5997 wxRect
wxGrid::CellToRect( int row
, int col
)
5999 wxRect
rect( -1, -1, -1, -1 );
6001 if ( row
>= 0 && row
< m_numRows
&&
6002 col
>= 0 && col
< m_numCols
)
6004 rect
.x
= GetColLeft(col
);
6005 rect
.y
= GetRowTop(row
);
6006 rect
.width
= GetColWidth(col
);
6007 rect
.height
= GetRowHeight(row
);
6014 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
6016 // get the cell rectangle in logical coords
6018 wxRect
r( CellToRect( row
, col
) );
6020 // convert to device coords
6022 int left
, top
, right
, bottom
;
6023 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
6024 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
6026 // check against the client area of the grid window
6029 m_gridWin
->GetClientSize( &cw
, &ch
);
6031 if ( wholeCellVisible
)
6033 // is the cell wholly visible ?
6035 return ( left
>= 0 && right
<= cw
&&
6036 top
>= 0 && bottom
<= ch
);
6040 // is the cell partly visible ?
6042 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
6043 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
6048 // make the specified cell location visible by doing a minimal amount
6051 void wxGrid::MakeCellVisible( int row
, int col
)
6054 int xpos
= -1, ypos
= -1;
6056 if ( row
>= 0 && row
< m_numRows
&&
6057 col
>= 0 && col
< m_numCols
)
6059 // get the cell rectangle in logical coords
6061 wxRect
r( CellToRect( row
, col
) );
6063 // convert to device coords
6065 int left
, top
, right
, bottom
;
6066 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
6067 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
6070 m_gridWin
->GetClientSize( &cw
, &ch
);
6076 else if ( bottom
> ch
)
6078 int h
= r
.GetHeight();
6080 for ( i
= row
-1; i
>= 0; i
-- )
6082 int rowHeight
= GetRowHeight(i
);
6083 if ( h
+ rowHeight
> ch
)
6090 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
6091 // have rounding errors (this is important, because if we do, we
6092 // might not scroll at all and some cells won't be redrawn)
6093 ypos
+= GRID_SCROLL_LINE
/ 2;
6100 else if ( right
> cw
)
6102 int w
= r
.GetWidth();
6104 for ( i
= col
-1; i
>= 0; i
-- )
6106 int colWidth
= GetColWidth(i
);
6107 if ( w
+ colWidth
> cw
)
6114 // see comment for ypos above
6115 xpos
+= GRID_SCROLL_LINE
/ 2;
6118 if ( xpos
!= -1 || ypos
!= -1 )
6120 if ( xpos
!= -1 ) xpos
/= GRID_SCROLL_LINE
;
6121 if ( ypos
!= -1 ) ypos
/= GRID_SCROLL_LINE
;
6122 Scroll( xpos
, ypos
);
6130 // ------ Grid cursor movement functions
6133 bool wxGrid::MoveCursorUp( bool expandSelection
)
6135 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
6136 m_currentCellCoords
.GetRow() > 0 )
6138 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
6139 m_currentCellCoords
.GetCol() );
6141 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
6142 m_currentCellCoords
.GetCol() );
6144 if ( expandSelection
)
6145 m_selection
->SelectCell( m_currentCellCoords
.GetRow(),
6146 m_currentCellCoords
.GetCol() );
6154 bool wxGrid::MoveCursorDown( bool expandSelection
)
6156 // TODO: allow for scrolling
6158 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
6159 m_currentCellCoords
.GetRow() < m_numRows
-1 )
6161 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
6162 m_currentCellCoords
.GetCol() );
6164 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
6165 m_currentCellCoords
.GetCol() );
6167 if ( expandSelection
)
6168 m_selection
->SelectCell( m_currentCellCoords
.GetRow(),
6169 m_currentCellCoords
.GetCol() );
6177 bool wxGrid::MoveCursorLeft( bool expandSelection
)
6179 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
6180 m_currentCellCoords
.GetCol() > 0 )
6182 MakeCellVisible( m_currentCellCoords
.GetRow(),
6183 m_currentCellCoords
.GetCol() - 1 );
6185 SetCurrentCell( m_currentCellCoords
.GetRow(),
6186 m_currentCellCoords
.GetCol() - 1 );
6188 if ( expandSelection
)
6189 m_selection
->SelectCell( m_currentCellCoords
.GetRow(),
6190 m_currentCellCoords
.GetCol() );
6198 bool wxGrid::MoveCursorRight( bool expandSelection
)
6200 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
6201 m_currentCellCoords
.GetCol() < m_numCols
- 1 )
6203 MakeCellVisible( m_currentCellCoords
.GetRow(),
6204 m_currentCellCoords
.GetCol() + 1 );
6206 SetCurrentCell( m_currentCellCoords
.GetRow(),
6207 m_currentCellCoords
.GetCol() + 1 );
6209 if ( expandSelection
)
6210 m_selection
->SelectCell( m_currentCellCoords
.GetRow(),
6211 m_currentCellCoords
.GetCol() );
6219 bool wxGrid::MovePageUp()
6221 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
6223 int row
= m_currentCellCoords
.GetRow();
6227 m_gridWin
->GetClientSize( &cw
, &ch
);
6229 int y
= GetRowTop(row
);
6230 int newRow
= YToRow( y
- ch
+ 1 );
6235 else if ( newRow
== row
)
6240 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
6241 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
6249 bool wxGrid::MovePageDown()
6251 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
6253 int row
= m_currentCellCoords
.GetRow();
6254 if ( row
< m_numRows
)
6257 m_gridWin
->GetClientSize( &cw
, &ch
);
6259 int y
= GetRowTop(row
);
6260 int newRow
= YToRow( y
+ ch
);
6263 newRow
= m_numRows
- 1;
6265 else if ( newRow
== row
)
6270 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
6271 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
6279 bool wxGrid::MoveCursorUpBlock( bool expandSelection
)
6282 m_currentCellCoords
!= wxGridNoCellCoords
&&
6283 m_currentCellCoords
.GetRow() > 0 )
6285 int row
= m_currentCellCoords
.GetRow();
6286 int col
= m_currentCellCoords
.GetCol();
6288 if ( m_table
->IsEmptyCell(row
, col
) )
6290 // starting in an empty cell: find the next block of
6296 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
6299 else if ( m_table
->IsEmptyCell(row
-1, col
) )
6301 // starting at the top of a block: find the next block
6307 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
6312 // starting within a block: find the top of the block
6317 if ( m_table
->IsEmptyCell(row
, col
) )
6325 MakeCellVisible( row
, col
);
6326 if ( expandSelection
)
6327 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
6328 m_currentCellCoords
.GetCol(),
6330 SetCurrentCell( row
, col
);
6338 bool wxGrid::MoveCursorDownBlock( bool expandSelection
)
6341 m_currentCellCoords
!= wxGridNoCellCoords
&&
6342 m_currentCellCoords
.GetRow() < m_numRows
-1 )
6344 int row
= m_currentCellCoords
.GetRow();
6345 int col
= m_currentCellCoords
.GetCol();
6347 if ( m_table
->IsEmptyCell(row
, col
) )
6349 // starting in an empty cell: find the next block of
6352 while ( row
< m_numRows
-1 )
6355 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
6358 else if ( m_table
->IsEmptyCell(row
+1, col
) )
6360 // starting at the bottom of a block: find the next block
6363 while ( row
< m_numRows
-1 )
6366 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
6371 // starting within a block: find the bottom of the block
6373 while ( row
< m_numRows
-1 )
6376 if ( m_table
->IsEmptyCell(row
, col
) )
6384 MakeCellVisible( row
, col
);
6385 if ( expandSelection
)
6386 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
6387 m_currentCellCoords
.GetCol(),
6389 SetCurrentCell( row
, col
);
6397 bool wxGrid::MoveCursorLeftBlock( bool expandSelection
)
6400 m_currentCellCoords
!= wxGridNoCellCoords
&&
6401 m_currentCellCoords
.GetCol() > 0 )
6403 int row
= m_currentCellCoords
.GetRow();
6404 int col
= m_currentCellCoords
.GetCol();
6406 if ( m_table
->IsEmptyCell(row
, col
) )
6408 // starting in an empty cell: find the next block of
6414 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
6417 else if ( m_table
->IsEmptyCell(row
, col
-1) )
6419 // starting at the left of a block: find the next block
6425 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
6430 // starting within a block: find the left of the block
6435 if ( m_table
->IsEmptyCell(row
, col
) )
6443 MakeCellVisible( row
, col
);
6444 if ( expandSelection
)
6445 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
6446 m_currentCellCoords
.GetCol(),
6448 SetCurrentCell( row
, col
);
6456 bool wxGrid::MoveCursorRightBlock( bool expandSelection
)
6459 m_currentCellCoords
!= wxGridNoCellCoords
&&
6460 m_currentCellCoords
.GetCol() < m_numCols
-1 )
6462 int row
= m_currentCellCoords
.GetRow();
6463 int col
= m_currentCellCoords
.GetCol();
6465 if ( m_table
->IsEmptyCell(row
, col
) )
6467 // starting in an empty cell: find the next block of
6470 while ( col
< m_numCols
-1 )
6473 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
6476 else if ( m_table
->IsEmptyCell(row
, col
+1) )
6478 // starting at the right of a block: find the next block
6481 while ( col
< m_numCols
-1 )
6484 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
6489 // starting within a block: find the right of the block
6491 while ( col
< m_numCols
-1 )
6494 if ( m_table
->IsEmptyCell(row
, col
) )
6502 MakeCellVisible( row
, col
);
6503 if ( expandSelection
)
6504 m_selection
->SelectBlock( m_currentCellCoords
.GetRow(),
6505 m_currentCellCoords
.GetCol(),
6507 SetCurrentCell( row
, col
);
6518 // ------ Label values and formatting
6521 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
6523 *horiz
= m_rowLabelHorizAlign
;
6524 *vert
= m_rowLabelVertAlign
;
6527 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
6529 *horiz
= m_colLabelHorizAlign
;
6530 *vert
= m_colLabelVertAlign
;
6533 wxString
wxGrid::GetRowLabelValue( int row
)
6537 return m_table
->GetRowLabelValue( row
);
6547 wxString
wxGrid::GetColLabelValue( int col
)
6551 return m_table
->GetColLabelValue( col
);
6562 void wxGrid::SetRowLabelSize( int width
)
6564 width
= wxMax( width
, 0 );
6565 if ( width
!= m_rowLabelWidth
)
6569 m_rowLabelWin
->Show( FALSE
);
6570 m_cornerLabelWin
->Show( FALSE
);
6572 else if ( m_rowLabelWidth
== 0 )
6574 m_rowLabelWin
->Show( TRUE
);
6575 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
6578 m_rowLabelWidth
= width
;
6585 void wxGrid::SetColLabelSize( int height
)
6587 height
= wxMax( height
, 0 );
6588 if ( height
!= m_colLabelHeight
)
6592 m_colLabelWin
->Show( FALSE
);
6593 m_cornerLabelWin
->Show( FALSE
);
6595 else if ( m_colLabelHeight
== 0 )
6597 m_colLabelWin
->Show( TRUE
);
6598 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
6601 m_colLabelHeight
= height
;
6608 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
6610 if ( m_labelBackgroundColour
!= colour
)
6612 m_labelBackgroundColour
= colour
;
6613 m_rowLabelWin
->SetBackgroundColour( colour
);
6614 m_colLabelWin
->SetBackgroundColour( colour
);
6615 m_cornerLabelWin
->SetBackgroundColour( colour
);
6617 if ( !GetBatchCount() )
6619 m_rowLabelWin
->Refresh();
6620 m_colLabelWin
->Refresh();
6621 m_cornerLabelWin
->Refresh();
6626 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
6628 if ( m_labelTextColour
!= colour
)
6630 m_labelTextColour
= colour
;
6631 if ( !GetBatchCount() )
6633 m_rowLabelWin
->Refresh();
6634 m_colLabelWin
->Refresh();
6639 void wxGrid::SetLabelFont( const wxFont
& font
)
6642 if ( !GetBatchCount() )
6644 m_rowLabelWin
->Refresh();
6645 m_colLabelWin
->Refresh();
6649 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
6651 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
6653 m_rowLabelHorizAlign
= horiz
;
6656 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
6658 m_rowLabelVertAlign
= vert
;
6661 if ( !GetBatchCount() )
6663 m_rowLabelWin
->Refresh();
6667 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
6669 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
6671 m_colLabelHorizAlign
= horiz
;
6674 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
6676 m_colLabelVertAlign
= vert
;
6679 if ( !GetBatchCount() )
6681 m_colLabelWin
->Refresh();
6685 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
6689 m_table
->SetRowLabelValue( row
, s
);
6690 if ( !GetBatchCount() )
6692 wxRect rect
= CellToRect( row
, 0);
6693 if ( rect
.height
> 0 )
6695 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
6697 rect
.width
= m_rowLabelWidth
;
6698 m_rowLabelWin
->Refresh( TRUE
, &rect
);
6704 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
6708 m_table
->SetColLabelValue( col
, s
);
6709 if ( !GetBatchCount() )
6711 wxRect rect
= CellToRect( 0, col
);
6712 if ( rect
.width
> 0 )
6714 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
6716 rect
.height
= m_colLabelHeight
;
6717 m_colLabelWin
->Refresh( TRUE
, &rect
);
6723 void wxGrid::SetGridLineColour( const wxColour
& colour
)
6725 if ( m_gridLineColour
!= colour
)
6727 m_gridLineColour
= colour
;
6729 wxClientDC
dc( m_gridWin
);
6731 DrawAllGridLines( dc
, wxRegion() );
6735 void wxGrid::EnableGridLines( bool enable
)
6737 if ( enable
!= m_gridLinesEnabled
)
6739 m_gridLinesEnabled
= enable
;
6741 if ( !GetBatchCount() )
6745 wxClientDC
dc( m_gridWin
);
6747 DrawAllGridLines( dc
, wxRegion() );
6751 m_gridWin
->Refresh();
6758 int wxGrid::GetDefaultRowSize()
6760 return m_defaultRowHeight
;
6763 int wxGrid::GetRowSize( int row
)
6765 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
6767 return GetRowHeight(row
);
6770 int wxGrid::GetDefaultColSize()
6772 return m_defaultColWidth
;
6775 int wxGrid::GetColSize( int col
)
6777 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
6779 return GetColWidth(col
);
6782 // ============================================================================
6783 // access to the grid attributes: each of them has a default value in the grid
6784 // itself and may be overidden on a per-cell basis
6785 // ============================================================================
6787 // ----------------------------------------------------------------------------
6788 // setting default attributes
6789 // ----------------------------------------------------------------------------
6791 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
6793 m_defaultCellAttr
->SetBackgroundColour(col
);
6795 m_gridWin
->SetBackgroundColour(col
);
6799 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
6801 m_defaultCellAttr
->SetTextColour(col
);
6804 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
6806 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
6809 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
6811 m_defaultCellAttr
->SetFont(font
);
6814 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
6816 m_defaultCellAttr
->SetRenderer(renderer
);
6819 void wxGrid::SetDefaultEditor(wxGridCellEditor
*editor
)
6821 m_defaultCellAttr
->SetEditor(editor
);
6824 // ----------------------------------------------------------------------------
6825 // access to the default attrbiutes
6826 // ----------------------------------------------------------------------------
6828 wxColour
wxGrid::GetDefaultCellBackgroundColour()
6830 return m_defaultCellAttr
->GetBackgroundColour();
6833 wxColour
wxGrid::GetDefaultCellTextColour()
6835 return m_defaultCellAttr
->GetTextColour();
6838 wxFont
wxGrid::GetDefaultCellFont()
6840 return m_defaultCellAttr
->GetFont();
6843 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
6845 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
6848 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
6850 return m_defaultCellAttr
->GetRenderer(NULL
, 0, 0);
6853 wxGridCellEditor
*wxGrid::GetDefaultEditor() const
6855 return m_defaultCellAttr
->GetEditor(NULL
,0,0);
6858 // ----------------------------------------------------------------------------
6859 // access to cell attributes
6860 // ----------------------------------------------------------------------------
6862 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
6864 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
6865 wxColour colour
= attr
->GetBackgroundColour();
6870 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
6872 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
6873 wxColour colour
= attr
->GetTextColour();
6878 wxFont
wxGrid::GetCellFont( int row
, int col
)
6880 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
6881 wxFont font
= attr
->GetFont();
6886 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
6888 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
6889 attr
->GetAlignment(horiz
, vert
);
6893 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
)
6895 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6896 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
6902 wxGridCellEditor
* wxGrid::GetCellEditor(int row
, int col
)
6904 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6905 wxGridCellEditor
* editor
= attr
->GetEditor(this, row
, col
);
6911 bool wxGrid::IsReadOnly(int row
, int col
) const
6913 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
6914 bool isReadOnly
= attr
->IsReadOnly();
6919 // ----------------------------------------------------------------------------
6920 // attribute support: cache, automatic provider creation, ...
6921 // ----------------------------------------------------------------------------
6923 bool wxGrid::CanHaveAttributes()
6930 return m_table
->CanHaveAttributes();
6933 void wxGrid::ClearAttrCache()
6935 if ( m_attrCache
.row
!= -1 )
6937 wxSafeDecRef(m_attrCache
.attr
);
6938 m_attrCache
.row
= -1;
6942 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
6944 wxGrid
*self
= (wxGrid
*)this; // const_cast
6946 self
->ClearAttrCache();
6947 self
->m_attrCache
.row
= row
;
6948 self
->m_attrCache
.col
= col
;
6949 self
->m_attrCache
.attr
= attr
;
6953 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
6955 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
6957 *attr
= m_attrCache
.attr
;
6958 wxSafeIncRef(m_attrCache
.attr
);
6960 #ifdef DEBUG_ATTR_CACHE
6961 gs_nAttrCacheHits
++;
6968 #ifdef DEBUG_ATTR_CACHE
6969 gs_nAttrCacheMisses
++;
6975 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
6977 wxGridCellAttr
*attr
;
6978 if ( !LookupAttr(row
, col
, &attr
) )
6980 attr
= m_table
? m_table
->GetAttr(row
, col
) : (wxGridCellAttr
*)NULL
;
6981 CacheAttr(row
, col
, attr
);
6985 attr
->SetDefAttr(m_defaultCellAttr
);
6989 attr
= m_defaultCellAttr
;
6996 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
6998 wxGridCellAttr
*attr
;
6999 if ( !LookupAttr(row
, col
, &attr
) || !attr
)
7001 wxASSERT_MSG( m_table
,
7002 _T("we may only be called if CanHaveAttributes() "
7003 "returned TRUE and then m_table should be !NULL") );
7005 attr
= m_table
->GetAttr(row
, col
);
7008 attr
= new wxGridCellAttr
;
7010 // artificially inc the ref count to match DecRef() in caller
7013 m_table
->SetAttr(attr
, row
, col
);
7016 CacheAttr(row
, col
, attr
);
7018 attr
->SetDefAttr(m_defaultCellAttr
);
7022 // ----------------------------------------------------------------------------
7023 // setting column attributes (wrappers around SetColAttr)
7024 // ----------------------------------------------------------------------------
7026 void wxGrid::SetColFormatBool(int col
)
7028 SetColFormatCustom(col
, wxGRID_VALUE_BOOL
);
7031 void wxGrid::SetColFormatNumber(int col
)
7033 SetColFormatCustom(col
, wxGRID_VALUE_NUMBER
);
7036 void wxGrid::SetColFormatFloat(int col
, int width
, int precision
)
7038 wxString typeName
= wxGRID_VALUE_FLOAT
;
7039 if ( (width
!= -1) || (precision
!= -1) )
7041 typeName
<< _T(':') << width
<< _T(',') << precision
;
7044 SetColFormatCustom(col
, typeName
);
7047 void wxGrid::SetColFormatCustom(int col
, const wxString
& typeName
)
7049 wxGridCellAttr
*attr
= new wxGridCellAttr
;
7050 wxGridCellRenderer
*renderer
= GetDefaultRendererForType(typeName
);
7051 attr
->SetRenderer(renderer
);
7053 SetColAttr(col
, attr
);
7056 // ----------------------------------------------------------------------------
7057 // setting cell attributes: this is forwarded to the table
7058 // ----------------------------------------------------------------------------
7060 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
7062 if ( CanHaveAttributes() )
7064 m_table
->SetRowAttr(attr
, row
);
7072 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
7074 if ( CanHaveAttributes() )
7076 m_table
->SetColAttr(attr
, col
);
7084 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
7086 if ( CanHaveAttributes() )
7088 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7089 attr
->SetBackgroundColour(colour
);
7094 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
7096 if ( CanHaveAttributes() )
7098 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7099 attr
->SetTextColour(colour
);
7104 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
7106 if ( CanHaveAttributes() )
7108 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7109 attr
->SetFont(font
);
7114 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
7116 if ( CanHaveAttributes() )
7118 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7119 attr
->SetAlignment(horiz
, vert
);
7124 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
7126 if ( CanHaveAttributes() )
7128 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7129 attr
->SetRenderer(renderer
);
7134 void wxGrid::SetCellEditor(int row
, int col
, wxGridCellEditor
* editor
)
7136 if ( CanHaveAttributes() )
7138 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7139 attr
->SetEditor(editor
);
7144 void wxGrid::SetReadOnly(int row
, int col
, bool isReadOnly
)
7146 if ( CanHaveAttributes() )
7148 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
7149 attr
->SetReadOnly(isReadOnly
);
7154 // ----------------------------------------------------------------------------
7155 // Data type registration
7156 // ----------------------------------------------------------------------------
7158 void wxGrid::RegisterDataType(const wxString
& typeName
,
7159 wxGridCellRenderer
* renderer
,
7160 wxGridCellEditor
* editor
)
7162 m_typeRegistry
->RegisterDataType(typeName
, renderer
, editor
);
7166 wxGridCellEditor
* wxGrid::GetDefaultEditorForCell(int row
, int col
) const
7168 wxString typeName
= m_table
->GetTypeName(row
, col
);
7169 return GetDefaultEditorForType(typeName
);
7172 wxGridCellRenderer
* wxGrid::GetDefaultRendererForCell(int row
, int col
) const
7174 wxString typeName
= m_table
->GetTypeName(row
, col
);
7175 return GetDefaultRendererForType(typeName
);
7179 wxGrid::GetDefaultEditorForType(const wxString
& typeName
) const
7181 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
7182 if ( index
== wxNOT_FOUND
)
7184 wxFAIL_MSG(wxT("Unknown data type name"));
7189 return m_typeRegistry
->GetEditor(index
);
7193 wxGrid::GetDefaultRendererForType(const wxString
& typeName
) const
7195 int index
= m_typeRegistry
->FindOrCloneDataType(typeName
);
7196 if ( index
== wxNOT_FOUND
)
7198 wxFAIL_MSG(wxT("Unknown data type name"));
7203 return m_typeRegistry
->GetRenderer(index
);
7207 // ----------------------------------------------------------------------------
7209 // ----------------------------------------------------------------------------
7211 void wxGrid::EnableDragRowSize( bool enable
)
7213 m_canDragRowSize
= enable
;
7217 void wxGrid::EnableDragColSize( bool enable
)
7219 m_canDragColSize
= enable
;
7222 void wxGrid::EnableDragGridSize( bool enable
)
7224 m_canDragGridSize
= enable
;
7228 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
7230 m_defaultRowHeight
= wxMax( height
, WXGRID_MIN_ROW_HEIGHT
);
7232 if ( resizeExistingRows
)
7240 void wxGrid::SetRowSize( int row
, int height
)
7242 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
7244 if ( m_rowHeights
.IsEmpty() )
7246 // need to really create the array
7250 int h
= wxMax( 0, height
);
7251 int diff
= h
- m_rowHeights
[row
];
7253 m_rowHeights
[row
] = h
;
7255 for ( i
= row
; i
< m_numRows
; i
++ )
7257 m_rowBottoms
[i
] += diff
;
7262 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
7264 m_defaultColWidth
= wxMax( width
, WXGRID_MIN_COL_WIDTH
);
7266 if ( resizeExistingCols
)
7274 void wxGrid::SetColSize( int col
, int width
)
7276 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
7278 // should we check that it's bigger than GetColMinimalWidth(col) here?
7280 if ( m_colWidths
.IsEmpty() )
7282 // need to really create the array
7286 int w
= wxMax( 0, width
);
7287 int diff
= w
- m_colWidths
[col
];
7288 m_colWidths
[col
] = w
;
7291 for ( i
= col
; i
< m_numCols
; i
++ )
7293 m_colRights
[i
] += diff
;
7299 void wxGrid::SetColMinimalWidth( int col
, int width
)
7301 m_colMinWidths
.Put(col
, width
);
7304 void wxGrid::SetRowMinimalHeight( int row
, int width
)
7306 m_rowMinHeights
.Put(row
, width
);
7309 int wxGrid::GetColMinimalWidth(int col
) const
7311 long value
= m_colMinWidths
.Get(col
);
7312 return value
!= wxNOT_FOUND
? (int)value
: WXGRID_MIN_COL_WIDTH
;
7315 int wxGrid::GetRowMinimalHeight(int row
) const
7317 long value
= m_rowMinHeights
.Get(row
);
7318 return value
!= wxNOT_FOUND
? (int)value
: WXGRID_MIN_ROW_HEIGHT
;
7321 // ----------------------------------------------------------------------------
7323 // ----------------------------------------------------------------------------
7325 void wxGrid::AutoSizeColOrRow( int colOrRow
, bool setAsMin
, bool column
)
7327 wxClientDC
dc(m_gridWin
);
7329 // init both of them to avoid compiler warnings, even if weo nly need one
7337 wxCoord extent
, extentMax
= 0;
7338 int max
= column
? m_numRows
: m_numCols
;
7339 for ( int rowOrCol
= 0; rowOrCol
< max
; rowOrCol
++ )
7346 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
7347 wxGridCellRenderer
* renderer
= attr
->GetRenderer(this, row
, col
);
7350 wxSize size
= renderer
->GetBestSize(*this, *attr
, dc
, row
, col
);
7351 extent
= column
? size
.x
: size
.y
;
7352 if ( extent
> extentMax
)
7363 // now also compare with the column label extent
7365 dc
.SetFont( GetLabelFont() );
7368 dc
.GetTextExtent( GetColLabelValue(col
), &w
, &h
);
7370 dc
.GetTextExtent( GetRowLabelValue(col
), &w
, &h
);
7372 extent
= column
? w
: h
;
7373 if ( extent
> extentMax
)
7380 // empty column - give default extent (notice that if extentMax is less
7381 // than default extent but != 0, it's ok)
7382 extentMax
= column
? m_defaultColWidth
: m_defaultRowHeight
;
7388 // leave some space around text
7394 SetColSize(col
, extentMax
);
7396 SetRowSize(row
, extentMax
);
7401 SetColMinimalWidth(col
, extentMax
);
7403 SetRowMinimalHeight(row
, extentMax
);
7407 int wxGrid::SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
)
7409 int width
= m_rowLabelWidth
;
7411 for ( int col
= 0; col
< m_numCols
; col
++ )
7415 AutoSizeColumn(col
, setAsMin
);
7418 width
+= GetColWidth(col
);
7424 int wxGrid::SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
)
7426 int height
= m_colLabelHeight
;
7428 for ( int row
= 0; row
< m_numRows
; row
++ )
7432 AutoSizeRow(row
, setAsMin
);
7435 height
+= GetRowHeight(row
);
7441 void wxGrid::AutoSize()
7444 SetSize(SetOrCalcColumnSizes(FALSE
), SetOrCalcRowSizes(FALSE
));
7447 wxSize
wxGrid::DoGetBestSize() const
7449 // don't set sizes, only calculate them
7450 wxGrid
*self
= (wxGrid
*)this; // const_cast
7452 return wxSize(self
->SetOrCalcColumnSizes(TRUE
),
7453 self
->SetOrCalcRowSizes(TRUE
));
7461 // ----------------------------------------------------------------------------
7462 // cell value accessor functions
7463 // ----------------------------------------------------------------------------
7465 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
7469 m_table
->SetValue( row
, col
, s
.c_str() );
7470 if ( !GetBatchCount() )
7472 wxClientDC
dc( m_gridWin
);
7474 DrawCell( dc
, wxGridCellCoords(row
, col
) );
7477 if ( m_currentCellCoords
.GetRow() == row
&&
7478 m_currentCellCoords
.GetCol() == col
&&
7479 IsCellEditControlEnabled())
7481 HideCellEditControl();
7482 ShowCellEditControl(); // will reread data from table
7489 // ------ Block, row and col selection
7492 void wxGrid::SelectRow( int row
, bool addToSelected
)
7494 if ( IsSelection() && !addToSelected
)
7495 m_selection
->ClearSelection();
7497 m_selection
->SelectRow( row
);
7501 void wxGrid::SelectCol( int col
, bool addToSelected
)
7503 if ( IsSelection() && !addToSelected
)
7504 m_selection
->ClearSelection();
7506 m_selection
->SelectCol( col
);
7510 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
7513 wxGridCellCoords updateTopLeft
, updateBottomRight
;
7515 if ( topRow
> bottomRow
)
7522 if ( leftCol
> rightCol
)
7529 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
7530 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
7532 if ( m_selectingTopLeft
!= updateTopLeft
||
7533 m_selectingBottomRight
!= updateBottomRight
)
7535 // Compute two optimal update rectangles:
7536 // Either one rectangle is a real subset of the
7537 // other, or they are (almost) disjoint!
7539 bool need_refresh
[4];
7543 need_refresh
[3] = FALSE
;
7546 // Store intermediate values
7547 wxCoord oldLeft
= m_selectingTopLeft
.GetCol();
7548 wxCoord oldTop
= m_selectingTopLeft
.GetRow();
7549 wxCoord oldRight
= m_selectingBottomRight
.GetCol();
7550 wxCoord oldBottom
= m_selectingBottomRight
.GetRow();
7552 // Determine the outer/inner coordinates.
7553 if (oldLeft
> leftCol
)
7559 if (oldTop
> topRow
)
7565 if (oldRight
< rightCol
)
7568 oldRight
= rightCol
;
7571 if (oldBottom
< bottomRow
)
7574 oldBottom
= bottomRow
;
7578 // Now, either the stuff marked old is the outer
7579 // rectangle or we don't have a situation where one
7580 // is contained in the other.
7582 if ( oldLeft
< leftCol
)
7584 need_refresh
[0] = TRUE
;
7585 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
7587 wxGridCellCoords ( oldBottom
,
7591 if ( oldTop
< topRow
)
7593 need_refresh
[1] = TRUE
;
7594 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
7596 wxGridCellCoords ( topRow
- 1,
7600 if ( oldRight
> rightCol
)
7602 need_refresh
[2] = TRUE
;
7603 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
7605 wxGridCellCoords ( oldBottom
,
7609 if ( oldBottom
> bottomRow
)
7611 need_refresh
[3] = TRUE
;
7612 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
7614 wxGridCellCoords ( oldBottom
,
7620 m_selectingTopLeft
= updateTopLeft
;
7621 m_selectingBottomRight
= updateBottomRight
;
7623 // various Refresh() calls
7624 for (i
= 0; i
< 4; i
++ )
7625 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
7626 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
7629 // never generate an event as it will be generated from
7630 // wxGridSelection::SelectBlock!
7633 void wxGrid::SelectAll()
7635 m_selection
->SelectBlock( 0, 0, m_numRows
-1, m_numCols
-1 );
7638 bool wxGrid::IsSelection()
7640 return ( m_selection
->IsSelection() ||
7641 ( m_selectingTopLeft
!= wxGridNoCellCoords
&&
7642 m_selectingBottomRight
!= wxGridNoCellCoords
) );
7645 bool wxGrid::IsInSelection( int row
, int col
)
7647 return ( m_selection
->IsInSelection( row
, col
) ||
7648 ( row
>= m_selectingTopLeft
.GetRow() &&
7649 col
>= m_selectingTopLeft
.GetCol() &&
7650 row
<= m_selectingBottomRight
.GetRow() &&
7651 col
<= m_selectingBottomRight
.GetCol() ) );
7654 void wxGrid::ClearSelection()
7656 m_selectingTopLeft
= wxGridNoCellCoords
;
7657 m_selectingBottomRight
= wxGridNoCellCoords
;
7658 m_selection
->ClearSelection();
7662 // This function returns the rectangle that encloses the given block
7663 // in device coords clipped to the client size of the grid window.
7665 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
7666 const wxGridCellCoords
&bottomRight
)
7668 wxRect
rect( wxGridNoCellRect
);
7671 cellRect
= CellToRect( topLeft
);
7672 if ( cellRect
!= wxGridNoCellRect
)
7678 rect
= wxRect( 0, 0, 0, 0 );
7681 cellRect
= CellToRect( bottomRight
);
7682 if ( cellRect
!= wxGridNoCellRect
)
7688 return wxGridNoCellRect
;
7691 // convert to scrolled coords
7693 int left
, top
, right
, bottom
;
7694 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
7695 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
7698 m_gridWin
->GetClientSize( &cw
, &ch
);
7700 rect
.SetLeft( wxMax(0, left
) );
7701 rect
.SetTop( wxMax(0, top
) );
7702 rect
.SetRight( wxMin(cw
, right
) );
7703 rect
.SetBottom( wxMin(ch
, bottom
) );
7711 // ------ Grid event classes
7714 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxEvent
)
7716 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
7717 int row
, int col
, int x
, int y
, bool sel
,
7718 bool control
, bool shift
, bool alt
, bool meta
)
7719 : wxNotifyEvent( type
, id
)
7726 m_control
= control
;
7731 SetEventObject(obj
);
7735 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxEvent
)
7737 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
7738 int rowOrCol
, int x
, int y
,
7739 bool control
, bool shift
, bool alt
, bool meta
)
7740 : wxNotifyEvent( type
, id
)
7742 m_rowOrCol
= rowOrCol
;
7745 m_control
= control
;
7750 SetEventObject(obj
);
7754 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxEvent
)
7756 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
7757 const wxGridCellCoords
& topLeft
,
7758 const wxGridCellCoords
& bottomRight
,
7759 bool sel
, bool control
,
7760 bool shift
, bool alt
, bool meta
)
7761 : wxNotifyEvent( type
, id
)
7763 m_topLeft
= topLeft
;
7764 m_bottomRight
= bottomRight
;
7766 m_control
= control
;
7771 SetEventObject(obj
);
7775 #endif // ifndef wxUSE_NEW_GRID