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"
46 // this include needs to be outside precomp for BCC
47 #include "wx/textfile.h"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 WX_DEFINE_ARRAY(wxGridCellAttr
*, wxArrayAttrs
);
57 struct wxGridCellWithAttr
59 wxGridCellWithAttr(int row
, int col
, wxGridCellAttr
*attr_
)
60 : coords(row
, col
), attr(attr_
)
69 wxGridCellCoords coords
;
73 WX_DECLARE_OBJARRAY(wxGridCellWithAttr
, wxGridCellWithAttrArray
);
75 #include "wx/arrimpl.cpp"
77 WX_DEFINE_OBJARRAY(wxGridCellCoordsArray
)
78 WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray
)
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 class WXDLLEXPORT wxGridRowLabelWindow
: public wxWindow
87 wxGridRowLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
88 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
89 const wxPoint
&pos
, const wxSize
&size
);
94 void OnPaint( wxPaintEvent
& event
);
95 void OnMouseEvent( wxMouseEvent
& event
);
96 void OnKeyDown( wxKeyEvent
& event
);
98 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
103 class WXDLLEXPORT wxGridColLabelWindow
: public wxWindow
106 wxGridColLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
107 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
108 const wxPoint
&pos
, const wxSize
&size
);
113 void OnPaint( wxPaintEvent
&event
);
114 void OnMouseEvent( wxMouseEvent
& event
);
115 void OnKeyDown( wxKeyEvent
& event
);
117 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
118 DECLARE_EVENT_TABLE()
122 class WXDLLEXPORT wxGridCornerLabelWindow
: public wxWindow
125 wxGridCornerLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
126 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
127 const wxPoint
&pos
, const wxSize
&size
);
132 void OnMouseEvent( wxMouseEvent
& event
);
133 void OnKeyDown( wxKeyEvent
& event
);
134 void OnPaint( wxPaintEvent
& event
);
136 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
137 DECLARE_EVENT_TABLE()
140 class WXDLLEXPORT wxGridWindow
: public wxPanel
145 m_owner
= (wxGrid
*)NULL
;
146 m_rowLabelWin
= (wxGridRowLabelWindow
*)NULL
;
147 m_colLabelWin
= (wxGridColLabelWindow
*)NULL
;
150 wxGridWindow( wxGrid
*parent
,
151 wxGridRowLabelWindow
*rowLblWin
,
152 wxGridColLabelWindow
*colLblWin
,
153 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
156 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
160 wxGridRowLabelWindow
*m_rowLabelWin
;
161 wxGridColLabelWindow
*m_colLabelWin
;
163 void OnPaint( wxPaintEvent
&event
);
164 void OnMouseEvent( wxMouseEvent
& event
);
165 void OnKeyDown( wxKeyEvent
& );
166 void OnEraseBackground( wxEraseEvent
& );
169 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
170 DECLARE_EVENT_TABLE()
175 class wxGridCellEditorEvtHandler
: public wxEvtHandler
178 wxGridCellEditorEvtHandler()
179 : m_grid(0), m_editor(0)
181 wxGridCellEditorEvtHandler(wxGrid
* grid
, wxGridCellEditor
* editor
)
182 : m_grid(grid
), m_editor(editor
)
185 void OnKeyDown(wxKeyEvent
& event
);
186 void OnChar(wxKeyEvent
& event
);
190 wxGridCellEditor
* m_editor
;
191 DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler
)
192 DECLARE_EVENT_TABLE()
196 IMPLEMENT_DYNAMIC_CLASS( wxGridCellEditorEvtHandler
, wxEvtHandler
)
197 BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler
, wxEvtHandler
)
198 EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown
)
199 EVT_CHAR( wxGridCellEditorEvtHandler::OnChar
)
204 // ----------------------------------------------------------------------------
205 // the internal data representation used by wxGridCellAttrProvider
206 // ----------------------------------------------------------------------------
208 // this class stores attributes set for cells
209 class WXDLLEXPORT wxGridCellAttrData
212 void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
213 wxGridCellAttr
*GetAttr(int row
, int col
) const;
214 void UpdateAttrRows( size_t pos
, int numRows
);
215 void UpdateAttrCols( size_t pos
, int numCols
);
218 // searches for the attr for given cell, returns wxNOT_FOUND if not found
219 int FindIndex(int row
, int col
) const;
221 wxGridCellWithAttrArray m_attrs
;
224 // this class stores attributes set for rows or columns
225 class WXDLLEXPORT wxGridRowOrColAttrData
228 // empty ctor to suppress warnings
229 wxGridRowOrColAttrData() { }
230 ~wxGridRowOrColAttrData();
232 void SetAttr(wxGridCellAttr
*attr
, int rowOrCol
);
233 wxGridCellAttr
*GetAttr(int rowOrCol
) const;
234 void UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
);
237 wxArrayInt m_rowsOrCols
;
238 wxArrayAttrs m_attrs
;
241 // NB: this is just a wrapper around 3 objects: one which stores cell
242 // attributes, and 2 others for row/col ones
243 class WXDLLEXPORT wxGridCellAttrProviderData
246 wxGridCellAttrData m_cellAttrs
;
247 wxGridRowOrColAttrData m_rowAttrs
,
252 // ----------------------------------------------------------------------------
253 // data structures used for the data type registry
254 // ----------------------------------------------------------------------------
256 struct wxGridDataTypeInfo
{
257 wxGridDataTypeInfo(const wxString
& typeName
,
258 wxGridCellRenderer
* renderer
,
259 wxGridCellEditor
* editor
)
260 : m_typeName(typeName
), m_renderer(renderer
), m_editor(editor
)
263 ~wxGridDataTypeInfo() { delete m_renderer
; delete m_editor
; }
266 wxGridCellRenderer
* m_renderer
;
267 wxGridCellEditor
* m_editor
;
271 WX_DEFINE_ARRAY(wxGridDataTypeInfo
*, wxGridDataTypeInfoArray
);
274 class WXDLLEXPORT wxGridTypeRegistry
{
276 ~wxGridTypeRegistry();
277 void RegisterDataType(const wxString
& typeName
,
278 wxGridCellRenderer
* renderer
,
279 wxGridCellEditor
* editor
);
280 int FindDataType(const wxString
& typeName
);
281 wxGridCellRenderer
* GetRenderer(int index
);
282 wxGridCellEditor
* GetEditor(int index
);
285 wxGridDataTypeInfoArray m_typeinfo
;
291 // ----------------------------------------------------------------------------
292 // conditional compilation
293 // ----------------------------------------------------------------------------
295 #ifndef WXGRID_DRAW_LINES
296 #define WXGRID_DRAW_LINES 1
299 // ----------------------------------------------------------------------------
301 // ----------------------------------------------------------------------------
303 //#define DEBUG_ATTR_CACHE
304 #ifdef DEBUG_ATTR_CACHE
305 static size_t gs_nAttrCacheHits
= 0;
306 static size_t gs_nAttrCacheMisses
= 0;
307 #endif // DEBUG_ATTR_CACHE
309 // ----------------------------------------------------------------------------
311 // ----------------------------------------------------------------------------
313 wxGridCellCoords
wxGridNoCellCoords( -1, -1 );
314 wxRect
wxGridNoCellRect( -1, -1, -1, -1 );
317 // TODO: fixed so far - make configurable later (and also different for x/y)
318 static const size_t GRID_SCROLL_LINE
= 10;
320 // the size of hash tables used a bit everywhere (the max number of elements
321 // in these hash tables is the number of rows/columns)
322 static const int GRID_HASH_SIZE
= 100;
324 // ============================================================================
326 // ============================================================================
328 // ----------------------------------------------------------------------------
330 // ----------------------------------------------------------------------------
332 wxGridCellEditor::wxGridCellEditor()
338 wxGridCellEditor::~wxGridCellEditor()
343 void wxGridCellEditor::Create(wxWindow
* WXUNUSED(parent
),
344 wxWindowID
WXUNUSED(id
),
345 wxEvtHandler
* evtHandler
)
348 m_control
->PushEventHandler(evtHandler
);
351 void wxGridCellEditor::PaintBackground(const wxRect
& rectCell
,
352 wxGridCellAttr
*attr
)
354 // erase the background because we might not fill the cell
355 wxClientDC
dc(m_control
->GetParent());
356 dc
.SetPen(*wxTRANSPARENT_PEN
);
357 dc
.SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
358 dc
.DrawRectangle(rectCell
);
360 // redraw the control we just painted over
361 m_control
->Refresh();
364 void wxGridCellEditor::Destroy()
368 m_control
->Destroy();
373 void wxGridCellEditor::Show(bool show
, wxGridCellAttr
*attr
)
375 wxASSERT_MSG(m_control
,
376 wxT("The wxGridCellEditor must be Created first!"));
377 m_control
->Show(show
);
381 // set the colours/fonts if we have any
384 m_colFgOld
= m_control
->GetForegroundColour();
385 m_control
->SetForegroundColour(attr
->GetTextColour());
387 m_colBgOld
= m_control
->GetBackgroundColour();
388 m_control
->SetBackgroundColour(attr
->GetBackgroundColour());
390 m_fontOld
= m_control
->GetFont();
391 m_control
->SetFont(attr
->GetFont());
393 // can't do anything more in the base class version, the other
394 // attributes may only be used by the derived classes
399 // restore the standard colours fonts
400 if ( m_colFgOld
.Ok() )
402 m_control
->SetForegroundColour(m_colFgOld
);
403 m_colFgOld
= wxNullColour
;
406 if ( m_colBgOld
.Ok() )
408 m_control
->SetBackgroundColour(m_colBgOld
);
409 m_colBgOld
= wxNullColour
;
412 if ( m_fontOld
.Ok() )
414 m_control
->SetFont(m_fontOld
);
415 m_fontOld
= wxNullFont
;
420 void wxGridCellEditor::SetSize(const wxRect
& rect
)
422 wxASSERT_MSG(m_control
,
423 wxT("The wxGridCellEditor must be Created first!"));
424 m_control
->SetSize(rect
);
427 void wxGridCellEditor::HandleReturn(wxKeyEvent
& event
)
433 void wxGridCellEditor::StartingKey(wxKeyEvent
& event
)
438 void wxGridCellEditor::StartingClick()
442 // ----------------------------------------------------------------------------
443 // wxGridCellTextEditor
444 // ----------------------------------------------------------------------------
446 wxGridCellTextEditor::wxGridCellTextEditor()
450 void wxGridCellTextEditor::Create(wxWindow
* parent
,
452 wxEvtHandler
* evtHandler
)
454 m_control
= new wxTextCtrl(parent
, id
, wxEmptyString
,
455 wxDefaultPosition
, wxDefaultSize
456 #if defined(__WXMSW__)
457 , wxTE_MULTILINE
| wxTE_NO_VSCROLL
// necessary ???
461 wxGridCellEditor::Create(parent
, id
, evtHandler
);
464 void wxGridCellTextEditor::PaintBackground(const wxRect
& WXUNUSED(rectCell
),
465 wxGridCellAttr
* WXUNUSED(attr
))
467 // as we fill the entire client area, don't do anything here to minimize
471 void wxGridCellTextEditor::SetSize(const wxRect
& rectOrig
)
473 wxRect
rect(rectOrig
);
475 // Make the edit control large enough to allow for internal
478 // TODO: remove this if the text ctrl sizing is improved esp. for
481 #if defined(__WXGTK__)
482 rect
.Inflate(rect
.x
? 1 : 0, rect
.y
? 1 : 0);
484 int extra
= row
&& col
? 2 : 1;
485 #if defined(__WXMOTIF__)
488 rect
.SetLeft( wxMax(0, rect
.x
- extra
) );
489 rect
.SetTop( wxMax(0, rect
.y
- extra
) );
490 rect
.SetRight( rect
.GetRight() + 2*extra
);
491 rect
.SetBottom( rect
.GetBottom() + 2*extra
);
494 wxGridCellEditor::SetSize(rect
);
497 void wxGridCellTextEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
499 wxASSERT_MSG(m_control
,
500 wxT("The wxGridCellEditor must be Created first!"));
502 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
503 Text()->SetValue(m_startValue
);
504 Text()->SetInsertionPointEnd();
509 bool wxGridCellTextEditor::EndEdit(int row
, int col
, bool saveValue
,
512 wxASSERT_MSG(m_control
,
513 wxT("The wxGridCellEditor must be Created first!"));
515 bool changed
= FALSE
;
516 wxString value
= Text()->GetValue();
517 if (value
!= m_startValue
)
521 grid
->GetTable()->SetValue(row
, col
, value
);
523 m_startValue
= wxEmptyString
;
524 Text()->SetValue(m_startValue
);
530 void wxGridCellTextEditor::Reset()
532 wxASSERT_MSG(m_control
,
533 wxT("The wxGridCellEditor must be Created first!"));
535 Text()->SetValue(m_startValue
);
536 Text()->SetInsertionPointEnd();
539 void wxGridCellTextEditor::StartingKey(wxKeyEvent
& event
)
541 if ( !event
.AltDown() && !event
.MetaDown() && !event
.ControlDown() )
543 // insert the key in the control
544 long keycode
= event
.KeyCode();
545 if ( isprint(keycode
) )
547 // FIXME this is not going to work for non letters...
548 if ( !event
.ShiftDown() )
550 keycode
= tolower(keycode
);
553 Text()->AppendText((wxChar
)keycode
);
563 void wxGridCellTextEditor::HandleReturn(wxKeyEvent
& event
)
565 #if defined(__WXMOTIF__) || defined(__WXGTK__)
566 // wxMotif needs a little extra help...
567 int pos
= Text()->GetInsertionPoint();
568 wxString
s( Text()->GetValue() );
569 s
= s
.Left(pos
) + "\n" + s
.Mid(pos
);
571 Text()->SetInsertionPoint( pos
);
573 // the other ports can handle a Return key press
579 // ----------------------------------------------------------------------------
580 // wxGridCellBoolEditor
581 // ----------------------------------------------------------------------------
583 void wxGridCellBoolEditor::Create(wxWindow
* parent
,
585 wxEvtHandler
* evtHandler
)
587 m_control
= new wxCheckBox(parent
, id
, wxEmptyString
,
588 wxDefaultPosition
, wxDefaultSize
,
591 wxGridCellEditor::Create(parent
, id
, evtHandler
);
594 void wxGridCellBoolEditor::SetSize(const wxRect
& r
)
596 // position it in the centre of the rectangle (TODO: support alignment?)
598 m_control
->GetSize(&w
, &h
);
600 // the checkbox without label still has some space to the right in wxGTK,
601 // so shift it to the right
606 m_control
->Move(r
.x
+ r
.width
/2 - w
/2, r
.y
+ r
.height
/2 - h
/2);
609 void wxGridCellBoolEditor::Show(bool show
, wxGridCellAttr
*attr
)
611 m_control
->Show(show
);
615 wxColour colBg
= attr
? attr
->GetBackgroundColour() : *wxLIGHT_GREY
;
616 CBox()->SetBackgroundColour(colBg
);
620 void wxGridCellBoolEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
622 wxASSERT_MSG(m_control
,
623 wxT("The wxGridCellEditor must be Created first!"));
625 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxT("bool")))
626 m_startValue
= grid
->GetTable()->GetValueAsBool(row
, col
);
628 m_startValue
= !!grid
->GetTable()->GetValue(row
, col
);
629 CBox()->SetValue(m_startValue
);
633 bool wxGridCellBoolEditor::EndEdit(int row
, int col
,
637 wxASSERT_MSG(m_control
,
638 wxT("The wxGridCellEditor must be Created first!"));
640 bool changed
= FALSE
;
641 bool value
= CBox()->GetValue();
642 if ( value
!= m_startValue
)
647 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxT("bool")))
648 grid
->GetTable()->SetValueAsBool(row
, col
, value
);
650 grid
->GetTable()->SetValue(row
, col
, value
? _T("1") : wxEmptyString
);
656 void wxGridCellBoolEditor::Reset()
658 wxASSERT_MSG(m_control
,
659 wxT("The wxGridCellEditor must be Created first!"));
661 CBox()->SetValue(m_startValue
);
664 void wxGridCellBoolEditor::StartingClick()
666 CBox()->SetValue(!CBox()->GetValue());
669 // ----------------------------------------------------------------------------
670 // wxGridCellEditorEvtHandler
671 // ----------------------------------------------------------------------------
673 void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent
& event
)
675 switch ( event
.KeyCode() )
679 m_grid
->DisableCellEditControl();
683 event
.Skip( m_grid
->ProcessEvent( event
) );
687 if (!m_grid
->ProcessEvent(event
))
688 m_editor
->HandleReturn(event
);
697 void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent
& event
)
699 switch ( event
.KeyCode() )
711 // ============================================================================
713 // ============================================================================
715 // ----------------------------------------------------------------------------
716 // wxGridCellRenderer
717 // ----------------------------------------------------------------------------
719 void wxGridCellRenderer::Draw(wxGrid
& grid
,
720 wxGridCellAttr
& attr
,
726 dc
.SetBackgroundMode( wxSOLID
);
730 dc
.SetBrush( wxBrush(grid
.GetSelectionBackground(), wxSOLID
) );
734 dc
.SetBrush( wxBrush(attr
.GetBackgroundColour(), wxSOLID
) );
737 dc
.SetPen( *wxTRANSPARENT_PEN
);
738 dc
.DrawRectangle(rect
);
741 // ----------------------------------------------------------------------------
742 // wxGridCellStringRenderer
743 // ----------------------------------------------------------------------------
745 void wxGridCellStringRenderer::Draw(wxGrid
& grid
,
746 wxGridCellAttr
& attr
,
748 const wxRect
& rectCell
,
752 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
754 // now we only have to draw the text
755 dc
.SetBackgroundMode( wxTRANSPARENT
);
757 // TODO some special colours for attr.IsReadOnly() case?
761 dc
.SetTextBackground( grid
.GetSelectionBackground() );
762 dc
.SetTextForeground( grid
.GetSelectionForeground() );
766 dc
.SetTextBackground( attr
.GetBackgroundColour() );
767 dc
.SetTextForeground( attr
.GetTextColour() );
769 dc
.SetFont( attr
.GetFont() );
772 attr
.GetAlignment(&hAlign
, &vAlign
);
774 wxRect rect
= rectCell
;
780 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
781 rect
, hAlign
, vAlign
);
784 // ----------------------------------------------------------------------------
785 // wxGridCellBoolRenderer
786 // ----------------------------------------------------------------------------
788 void wxGridCellBoolRenderer::Draw(wxGrid
& grid
,
789 wxGridCellAttr
& attr
,
795 wxGridCellRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
797 // between checkmark and box
798 static const wxCoord margin
= 4;
801 static wxCoord s_checkSize
= 0;
802 if ( s_checkSize
== 0 )
804 // compute it only once (no locks for MT safeness in GUI thread...)
805 wxCheckBox
*checkbox
= new wxCheckBox(&grid
, -1, wxEmptyString
);
806 wxSize size
= checkbox
->GetBestSize();
807 s_checkSize
= size
.y
+ margin
;
809 // FIXME wxGTK::wxCheckBox::GetBestSize() is really weird...
811 s_checkSize
-= size
.y
/ 2;
817 // draw a check mark in the centre (ignoring alignment - TODO)
819 rectMark
.x
= rect
.x
+ rect
.width
/2 - s_checkSize
/2;
820 rectMark
.y
= rect
.y
+ rect
.height
/2 - s_checkSize
/2;
821 rectMark
.width
= rectMark
.height
= s_checkSize
;
823 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
824 dc
.SetPen(wxPen(attr
.GetTextColour(), 1, wxSOLID
));
825 dc
.DrawRectangle(rectMark
);
827 rectMark
.Inflate(-margin
);
830 if (grid
.GetTable()->CanGetValueAs(row
, col
, wxT("bool")))
831 value
= grid
.GetTable()->GetValueAsBool(row
, col
);
833 value
= !!grid
.GetTable()->GetValue(row
, col
);
837 dc
.SetTextForeground(attr
.GetTextColour());
838 dc
.DrawCheckMark(rectMark
);
842 // ----------------------------------------------------------------------------
844 // ----------------------------------------------------------------------------
846 const wxColour
& wxGridCellAttr::GetTextColour() const
852 else if (m_defGridAttr
!= this)
854 return m_defGridAttr
->GetTextColour();
858 wxFAIL_MSG(wxT("Missing default cell attribute"));
864 const wxColour
& wxGridCellAttr::GetBackgroundColour() const
866 if (HasBackgroundColour())
868 else if (m_defGridAttr
!= this)
869 return m_defGridAttr
->GetBackgroundColour();
872 wxFAIL_MSG(wxT("Missing default cell attribute"));
878 const wxFont
& wxGridCellAttr::GetFont() const
882 else if (m_defGridAttr
!= this)
883 return m_defGridAttr
->GetFont();
886 wxFAIL_MSG(wxT("Missing default cell attribute"));
892 void wxGridCellAttr::GetAlignment(int *hAlign
, int *vAlign
) const
896 if ( hAlign
) *hAlign
= m_hAlign
;
897 if ( vAlign
) *vAlign
= m_vAlign
;
899 else if (m_defGridAttr
!= this)
900 m_defGridAttr
->GetAlignment(hAlign
, vAlign
);
903 wxFAIL_MSG(wxT("Missing default cell attribute"));
908 // GetRenderer and GetEditor use a slightly different decision path about
909 // which to use. If a non-default attr object has one then it is used,
910 // otherwise the default editor or renderer passed in is used. It should be
911 // the default for the data type of the cell. If it is NULL (because the
912 // table has a type that the grid does not have in its registry,) then the
913 // grid's default editor or renderer is used.
915 wxGridCellRenderer
* wxGridCellAttr::GetRenderer(wxGridCellRenderer
* def
) const
917 if ((m_defGridAttr
!= this || def
== NULL
) && HasRenderer())
921 else if (m_defGridAttr
!= this)
922 return m_defGridAttr
->GetRenderer(NULL
);
925 wxFAIL_MSG(wxT("Missing default cell attribute"));
930 wxGridCellEditor
* wxGridCellAttr::GetEditor(wxGridCellEditor
* def
) const
932 if ((m_defGridAttr
!= this || def
== NULL
) && HasEditor())
936 else if (m_defGridAttr
!= this)
937 return m_defGridAttr
->GetEditor(NULL
);
940 wxFAIL_MSG(wxT("Missing default cell attribute"));
945 // ----------------------------------------------------------------------------
946 // wxGridCellAttrData
947 // ----------------------------------------------------------------------------
949 void wxGridCellAttrData::SetAttr(wxGridCellAttr
*attr
, int row
, int col
)
951 int n
= FindIndex(row
, col
);
952 if ( n
== wxNOT_FOUND
)
955 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
961 // change the attribute
962 m_attrs
[(size_t)n
].attr
= attr
;
966 // remove this attribute
967 m_attrs
.RemoveAt((size_t)n
);
972 wxGridCellAttr
*wxGridCellAttrData::GetAttr(int row
, int col
) const
974 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
976 int n
= FindIndex(row
, col
);
977 if ( n
!= wxNOT_FOUND
)
979 attr
= m_attrs
[(size_t)n
].attr
;
986 void wxGridCellAttrData::UpdateAttrRows( size_t pos
, int numRows
)
988 size_t count
= m_attrs
.GetCount();
989 for ( size_t n
= 0; n
< count
; n
++ )
991 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
992 wxCoord row
= coords
.GetRow();
993 if ((size_t)row
>= pos
)
997 // If rows inserted, include row counter where necessary
998 coords
.SetRow(row
+ numRows
);
1000 else if (numRows
< 0)
1002 // If rows deleted ...
1003 if ((size_t)row
>= pos
- numRows
)
1005 // ...either decrement row counter (if row still exists)...
1006 coords
.SetRow(row
+ numRows
);
1010 // ...or remove the attribute
1011 m_attrs
.RemoveAt((size_t)n
);
1019 void wxGridCellAttrData::UpdateAttrCols( size_t pos
, int numCols
)
1021 size_t count
= m_attrs
.GetCount();
1022 for ( size_t n
= 0; n
< count
; n
++ )
1024 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
1025 wxCoord col
= coords
.GetCol();
1026 if ( (size_t)col
>= pos
)
1030 // If rows inserted, include row counter where necessary
1031 coords
.SetCol(col
+ numCols
);
1033 else if (numCols
< 0)
1035 // If rows deleted ...
1036 if ((size_t)col
>= pos
- numCols
)
1038 // ...either decrement row counter (if row still exists)...
1039 coords
.SetCol(col
+ numCols
);
1043 // ...or remove the attribute
1044 m_attrs
.RemoveAt((size_t)n
);
1052 int wxGridCellAttrData::FindIndex(int row
, int col
) const
1054 size_t count
= m_attrs
.GetCount();
1055 for ( size_t n
= 0; n
< count
; n
++ )
1057 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
1058 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
1067 // ----------------------------------------------------------------------------
1068 // wxGridRowOrColAttrData
1069 // ----------------------------------------------------------------------------
1071 wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
1073 size_t count
= m_attrs
.Count();
1074 for ( size_t n
= 0; n
< count
; n
++ )
1076 m_attrs
[n
]->DecRef();
1080 wxGridCellAttr
*wxGridRowOrColAttrData::GetAttr(int rowOrCol
) const
1082 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
1084 int n
= m_rowsOrCols
.Index(rowOrCol
);
1085 if ( n
!= wxNOT_FOUND
)
1087 attr
= m_attrs
[(size_t)n
];
1094 void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr
*attr
, int rowOrCol
)
1096 int n
= m_rowsOrCols
.Index(rowOrCol
);
1097 if ( n
== wxNOT_FOUND
)
1099 // add the attribute
1100 m_rowsOrCols
.Add(rowOrCol
);
1107 // change the attribute
1108 m_attrs
[(size_t)n
] = attr
;
1112 // remove this attribute
1113 m_attrs
[(size_t)n
]->DecRef();
1114 m_rowsOrCols
.RemoveAt((size_t)n
);
1115 m_attrs
.RemoveAt((size_t)n
);
1120 void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
)
1122 size_t count
= m_attrs
.GetCount();
1123 for ( size_t n
= 0; n
< count
; n
++ )
1125 int & rowOrCol
= m_rowsOrCols
[n
];
1126 if ( (size_t)rowOrCol
>= pos
)
1128 if ( numRowsOrCols
> 0 )
1130 // If rows inserted, include row counter where necessary
1131 rowOrCol
+= numRowsOrCols
;
1133 else if ( numRowsOrCols
< 0)
1135 // If rows deleted, either decrement row counter (if row still exists)
1136 if ((size_t)rowOrCol
>= pos
- numRowsOrCols
)
1137 rowOrCol
+= numRowsOrCols
;
1140 m_rowsOrCols
.RemoveAt((size_t)n
);
1141 m_attrs
.RemoveAt((size_t)n
);
1149 // ----------------------------------------------------------------------------
1150 // wxGridCellAttrProvider
1151 // ----------------------------------------------------------------------------
1153 wxGridCellAttrProvider::wxGridCellAttrProvider()
1155 m_data
= (wxGridCellAttrProviderData
*)NULL
;
1158 wxGridCellAttrProvider::~wxGridCellAttrProvider()
1163 void wxGridCellAttrProvider::InitData()
1165 m_data
= new wxGridCellAttrProviderData
;
1168 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
) const
1170 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
1173 // first look for the attribute of this specific cell
1174 attr
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
1178 // then look for the col attr (col attributes are more common than
1179 // the row ones, hence they have priority)
1180 attr
= m_data
->m_colAttrs
.GetAttr(col
);
1185 // finally try the row attributes
1186 attr
= m_data
->m_rowAttrs
.GetAttr(row
);
1193 void wxGridCellAttrProvider::SetAttr(wxGridCellAttr
*attr
,
1199 m_data
->m_cellAttrs
.SetAttr(attr
, row
, col
);
1202 void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr
*attr
, int row
)
1207 m_data
->m_rowAttrs
.SetAttr(attr
, row
);
1210 void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr
*attr
, int col
)
1215 m_data
->m_colAttrs
.SetAttr(attr
, col
);
1218 void wxGridCellAttrProvider::UpdateAttrRows( size_t pos
, int numRows
)
1222 m_data
->m_cellAttrs
.UpdateAttrRows( pos
, numRows
);
1224 m_data
->m_rowAttrs
.UpdateAttrRowsOrCols( pos
, numRows
);
1228 void wxGridCellAttrProvider::UpdateAttrCols( size_t pos
, int numCols
)
1232 m_data
->m_cellAttrs
.UpdateAttrCols( pos
, numCols
);
1234 m_data
->m_colAttrs
.UpdateAttrRowsOrCols( pos
, numCols
);
1238 // ----------------------------------------------------------------------------
1239 // wxGridTypeRegistry
1240 // ----------------------------------------------------------------------------
1242 wxGridTypeRegistry::~wxGridTypeRegistry()
1244 for (size_t i
=0; i
<m_typeinfo
.Count(); i
++)
1245 delete m_typeinfo
[i
];
1249 void wxGridTypeRegistry::RegisterDataType(const wxString
& typeName
,
1250 wxGridCellRenderer
* renderer
,
1251 wxGridCellEditor
* editor
)
1254 wxGridDataTypeInfo
* info
= new wxGridDataTypeInfo(typeName
, renderer
, editor
);
1256 // is it already registered?
1257 if ((loc
= FindDataType(typeName
)) != -1) {
1258 delete m_typeinfo
[loc
];
1259 m_typeinfo
[loc
] = info
;
1262 m_typeinfo
.Add(info
);
1266 int wxGridTypeRegistry::FindDataType(const wxString
& typeName
)
1270 for (size_t i
=0; i
<m_typeinfo
.Count(); i
++) {
1271 if (typeName
== m_typeinfo
[i
]->m_typeName
) {
1280 wxGridCellRenderer
* wxGridTypeRegistry::GetRenderer(int index
)
1282 wxGridCellRenderer
* renderer
= m_typeinfo
[index
]->m_renderer
;
1286 wxGridCellEditor
* wxGridTypeRegistry::GetEditor(int index
)
1288 wxGridCellEditor
* editor
= m_typeinfo
[index
]->m_editor
;
1292 // ----------------------------------------------------------------------------
1294 // ----------------------------------------------------------------------------
1296 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
1299 wxGridTableBase::wxGridTableBase()
1301 m_view
= (wxGrid
*) NULL
;
1302 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
1305 wxGridTableBase::~wxGridTableBase()
1307 delete m_attrProvider
;
1310 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
1312 delete m_attrProvider
;
1313 m_attrProvider
= attrProvider
;
1316 bool wxGridTableBase::CanHaveAttributes()
1318 if ( ! GetAttrProvider() )
1320 // use the default attr provider by default
1321 SetAttrProvider(new wxGridCellAttrProvider
);
1326 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
)
1328 if ( m_attrProvider
)
1329 return m_attrProvider
->GetAttr(row
, col
);
1331 return (wxGridCellAttr
*)NULL
;
1334 void wxGridTableBase::SetAttr(wxGridCellAttr
* attr
, int row
, int col
)
1336 if ( m_attrProvider
)
1338 m_attrProvider
->SetAttr(attr
, row
, col
);
1342 // as we take ownership of the pointer and don't store it, we must
1348 void wxGridTableBase::SetRowAttr(wxGridCellAttr
*attr
, int row
)
1350 if ( m_attrProvider
)
1352 m_attrProvider
->SetRowAttr(attr
, row
);
1356 // as we take ownership of the pointer and don't store it, we must
1362 void wxGridTableBase::SetColAttr(wxGridCellAttr
*attr
, int col
)
1364 if ( m_attrProvider
)
1366 m_attrProvider
->SetColAttr(attr
, col
);
1370 // as we take ownership of the pointer and don't store it, we must
1376 void wxGridTableBase::UpdateAttrRows( size_t pos
, int numRows
)
1378 if ( m_attrProvider
)
1380 m_attrProvider
->UpdateAttrRows( pos
, numRows
);
1384 void wxGridTableBase::UpdateAttrCols( size_t pos
, int numCols
)
1386 if ( m_attrProvider
)
1388 m_attrProvider
->UpdateAttrCols( pos
, numCols
);
1392 bool wxGridTableBase::InsertRows( size_t pos
, size_t numRows
)
1394 wxFAIL_MSG( wxT("Called grid table class function InsertRows\n"
1395 "but your derived table class does not override this function") );
1400 bool wxGridTableBase::AppendRows( size_t numRows
)
1402 wxFAIL_MSG( wxT("Called grid table class function AppendRows\n"
1403 "but your derived table class does not override this function"));
1408 bool wxGridTableBase::DeleteRows( size_t pos
, size_t numRows
)
1410 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\n"
1411 "but your derived table class does not override this function"));
1416 bool wxGridTableBase::InsertCols( size_t pos
, size_t numCols
)
1418 wxFAIL_MSG( wxT("Called grid table class function InsertCols\n"
1419 "but your derived table class does not override this function"));
1424 bool wxGridTableBase::AppendCols( size_t numCols
)
1426 wxFAIL_MSG(wxT("Called grid table class function AppendCols\n"
1427 "but your derived table class does not override this function"));
1432 bool wxGridTableBase::DeleteCols( size_t pos
, size_t numCols
)
1434 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\n"
1435 "but your derived table class does not override this function"));
1441 wxString
wxGridTableBase::GetRowLabelValue( int row
)
1444 s
<< row
+ 1; // RD: Starting the rows at zero confuses users, no matter
1445 // how much it makes sense to us geeks.
1449 wxString
wxGridTableBase::GetColLabelValue( int col
)
1451 // default col labels are:
1452 // cols 0 to 25 : A-Z
1453 // cols 26 to 675 : AA-ZZ
1458 for ( n
= 1; ; n
++ )
1460 s
+= (_T('A') + (wxChar
)( col%26
));
1462 if ( col
< 0 ) break;
1465 // reverse the string...
1467 for ( i
= 0; i
< n
; i
++ )
1476 wxString
wxGridTableBase::GetTypeName( int WXUNUSED(row
), int WXUNUSED(col
) )
1478 return wxT("string");
1481 bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row
), int WXUNUSED(col
),
1482 const wxString
& typeName
)
1484 return typeName
== wxT("string");
1487 bool wxGridTableBase::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
1489 return CanGetValueAs(row
, col
, typeName
);
1492 long wxGridTableBase::GetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
) )
1497 double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
) )
1502 bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
) )
1507 void wxGridTableBase::SetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
),
1508 long WXUNUSED(value
) )
1512 void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
),
1513 double WXUNUSED(value
) )
1517 void wxGridTableBase::SetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
),
1518 bool WXUNUSED(value
) )
1523 void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
1524 const wxString
& WXUNUSED(typeName
) )
1529 void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
1530 const wxString
& WXUNUSED(typeName
),
1531 void* WXUNUSED(value
) )
1536 //////////////////////////////////////////////////////////////////////
1538 // Message class for the grid table to send requests and notifications
1542 wxGridTableMessage::wxGridTableMessage()
1544 m_table
= (wxGridTableBase
*) NULL
;
1550 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
1551 int commandInt1
, int commandInt2
)
1555 m_comInt1
= commandInt1
;
1556 m_comInt2
= commandInt2
;
1561 //////////////////////////////////////////////////////////////////////
1563 // A basic grid table for string data. An object of this class will
1564 // created by wxGrid if you don't specify an alternative table class.
1567 WX_DEFINE_OBJARRAY(wxGridStringArray
)
1569 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
1571 wxGridStringTable::wxGridStringTable()
1576 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
1581 m_data
.Alloc( numRows
);
1584 sa
.Alloc( numCols
);
1585 for ( col
= 0; col
< numCols
; col
++ )
1587 sa
.Add( wxEmptyString
);
1590 for ( row
= 0; row
< numRows
; row
++ )
1596 wxGridStringTable::~wxGridStringTable()
1600 long wxGridStringTable::GetNumberRows()
1602 return m_data
.GetCount();
1605 long wxGridStringTable::GetNumberCols()
1607 if ( m_data
.GetCount() > 0 )
1608 return m_data
[0].GetCount();
1613 wxString
wxGridStringTable::GetValue( int row
, int col
)
1615 // TODO: bounds checking
1617 return m_data
[row
][col
];
1620 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& value
)
1622 // TODO: bounds checking
1624 m_data
[row
][col
] = value
;
1627 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
1629 // TODO: bounds checking
1631 return (m_data
[row
][col
] == wxEmptyString
);
1635 void wxGridStringTable::Clear()
1638 int numRows
, numCols
;
1640 numRows
= m_data
.GetCount();
1643 numCols
= m_data
[0].GetCount();
1645 for ( row
= 0; row
< numRows
; row
++ )
1647 for ( col
= 0; col
< numCols
; col
++ )
1649 m_data
[row
][col
] = wxEmptyString
;
1656 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
1660 size_t curNumRows
= m_data
.GetCount();
1661 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1663 if ( pos
>= curNumRows
)
1665 return AppendRows( numRows
);
1669 sa
.Alloc( curNumCols
);
1670 for ( col
= 0; col
< curNumCols
; col
++ )
1672 sa
.Add( wxEmptyString
);
1675 for ( row
= pos
; row
< pos
+ numRows
; row
++ )
1677 m_data
.Insert( sa
, row
);
1679 UpdateAttrRows( pos
, numRows
);
1682 wxGridTableMessage
msg( this,
1683 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
1687 GetView()->ProcessTableMessage( msg
);
1693 bool wxGridStringTable::AppendRows( size_t numRows
)
1697 size_t curNumRows
= m_data
.GetCount();
1698 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1701 if ( curNumCols
> 0 )
1703 sa
.Alloc( curNumCols
);
1704 for ( col
= 0; col
< curNumCols
; col
++ )
1706 sa
.Add( wxEmptyString
);
1710 for ( row
= 0; row
< numRows
; row
++ )
1717 wxGridTableMessage
msg( this,
1718 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
1721 GetView()->ProcessTableMessage( msg
);
1727 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
1731 size_t curNumRows
= m_data
.GetCount();
1733 if ( pos
>= curNumRows
)
1736 errmsg
.Printf("Called wxGridStringTable::DeleteRows(pos=%d, N=%d)\n"
1737 "Pos value is invalid for present table with %d rows",
1738 pos
, numRows
, curNumRows
);
1739 wxFAIL_MSG( wxT(errmsg
) );
1743 if ( numRows
> curNumRows
- pos
)
1745 numRows
= curNumRows
- pos
;
1748 if ( numRows
>= curNumRows
)
1750 m_data
.Empty(); // don't release memory just yet
1754 for ( n
= 0; n
< numRows
; n
++ )
1756 m_data
.Remove( pos
);
1759 UpdateAttrRows( pos
, -((int)numRows
) );
1762 wxGridTableMessage
msg( this,
1763 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
1767 GetView()->ProcessTableMessage( msg
);
1773 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
1777 size_t curNumRows
= m_data
.GetCount();
1778 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1780 if ( pos
>= curNumCols
)
1782 return AppendCols( numCols
);
1785 for ( row
= 0; row
< curNumRows
; row
++ )
1787 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
1789 m_data
[row
].Insert( wxEmptyString
, col
);
1792 UpdateAttrCols( pos
, numCols
);
1795 wxGridTableMessage
msg( this,
1796 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
1800 GetView()->ProcessTableMessage( msg
);
1806 bool wxGridStringTable::AppendCols( size_t numCols
)
1810 size_t curNumRows
= m_data
.GetCount();
1813 // TODO: something better than this ?
1815 wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\n"
1816 "Call AppendRows() first") );
1820 for ( row
= 0; row
< curNumRows
; row
++ )
1822 for ( n
= 0; n
< numCols
; n
++ )
1824 m_data
[row
].Add( wxEmptyString
);
1830 wxGridTableMessage
msg( this,
1831 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
1834 GetView()->ProcessTableMessage( msg
);
1840 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
1844 size_t curNumRows
= m_data
.GetCount();
1845 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1847 if ( pos
>= curNumCols
)
1850 errmsg
.Printf( "Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\n"
1851 "Pos value is invalid for present table with %d cols",
1852 pos
, numCols
, curNumCols
);
1853 wxFAIL_MSG( wxT( errmsg
) );
1857 if ( numCols
> curNumCols
- pos
)
1859 numCols
= curNumCols
- pos
;
1862 for ( row
= 0; row
< curNumRows
; row
++ )
1864 if ( numCols
>= curNumCols
)
1866 m_data
[row
].Clear();
1870 for ( n
= 0; n
< numCols
; n
++ )
1872 m_data
[row
].Remove( pos
);
1876 UpdateAttrCols( pos
, -((int)numCols
) );
1879 wxGridTableMessage
msg( this,
1880 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
1884 GetView()->ProcessTableMessage( msg
);
1890 wxString
wxGridStringTable::GetRowLabelValue( int row
)
1892 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
1894 // using default label
1896 return wxGridTableBase::GetRowLabelValue( row
);
1900 return m_rowLabels
[ row
];
1904 wxString
wxGridStringTable::GetColLabelValue( int col
)
1906 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
1908 // using default label
1910 return wxGridTableBase::GetColLabelValue( col
);
1914 return m_colLabels
[ col
];
1918 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
1920 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
1922 int n
= m_rowLabels
.GetCount();
1924 for ( i
= n
; i
<= row
; i
++ )
1926 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
1930 m_rowLabels
[row
] = value
;
1933 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
1935 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
1937 int n
= m_colLabels
.GetCount();
1939 for ( i
= n
; i
<= col
; i
++ )
1941 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
1945 m_colLabels
[col
] = value
;
1950 //////////////////////////////////////////////////////////////////////
1951 //////////////////////////////////////////////////////////////////////
1953 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
1955 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
1956 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
1957 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
1958 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
1961 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
1963 const wxPoint
&pos
, const wxSize
&size
)
1964 : wxWindow( parent
, id
, pos
, size
)
1969 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
&event
)
1973 // NO - don't do this because it will set both the x and y origin
1974 // coords to match the parent scrolled window and we just want to
1975 // set the y coord - MB
1977 // m_owner->PrepareDC( dc );
1980 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
1981 dc
.SetDeviceOrigin( 0, -y
);
1983 m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
1984 m_owner
->DrawRowLabels( dc
);
1988 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1990 m_owner
->ProcessRowLabelMouseEvent( event
);
1994 // This seems to be required for wxMotif otherwise the mouse
1995 // cursor must be in the cell edit control to get key events
1997 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
1999 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
2004 //////////////////////////////////////////////////////////////////////
2006 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
2008 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
2009 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
2010 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
2011 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
2014 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
2016 const wxPoint
&pos
, const wxSize
&size
)
2017 : wxWindow( parent
, id
, pos
, size
)
2022 void wxGridColLabelWindow::OnPaint( wxPaintEvent
&event
)
2026 // NO - don't do this because it will set both the x and y origin
2027 // coords to match the parent scrolled window and we just want to
2028 // set the x coord - MB
2030 // m_owner->PrepareDC( dc );
2033 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
2034 dc
.SetDeviceOrigin( -x
, 0 );
2036 m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
2037 m_owner
->DrawColLabels( dc
);
2041 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
2043 m_owner
->ProcessColLabelMouseEvent( event
);
2047 // This seems to be required for wxMotif otherwise the mouse
2048 // cursor must be in the cell edit control to get key events
2050 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
2052 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
2057 //////////////////////////////////////////////////////////////////////
2059 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
2061 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
2062 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
2063 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
2064 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
2067 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
2069 const wxPoint
&pos
, const wxSize
&size
)
2070 : wxWindow( parent
, id
, pos
, size
)
2075 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2079 int client_height
= 0;
2080 int client_width
= 0;
2081 GetClientSize( &client_width
, &client_height
);
2083 dc
.SetPen( *wxBLACK_PEN
);
2084 dc
.DrawLine( client_width
-1, client_height
-1, client_width
-1, 0 );
2085 dc
.DrawLine( client_width
-1, client_height
-1, 0, client_height
-1 );
2087 dc
.SetPen( *wxWHITE_PEN
);
2088 dc
.DrawLine( 0, 0, client_width
, 0 );
2089 dc
.DrawLine( 0, 0, 0, client_height
);
2093 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
2095 m_owner
->ProcessCornerLabelMouseEvent( event
);
2099 // This seems to be required for wxMotif otherwise the mouse
2100 // cursor must be in the cell edit control to get key events
2102 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
2104 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
2109 //////////////////////////////////////////////////////////////////////
2111 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxPanel
)
2113 BEGIN_EVENT_TABLE( wxGridWindow
, wxPanel
)
2114 EVT_PAINT( wxGridWindow::OnPaint
)
2115 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
2116 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
2117 EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground
)
2120 wxGridWindow::wxGridWindow( wxGrid
*parent
,
2121 wxGridRowLabelWindow
*rowLblWin
,
2122 wxGridColLabelWindow
*colLblWin
,
2123 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
)
2124 : wxPanel( parent
, id
, pos
, size
, 0, "grid window" )
2127 m_rowLabelWin
= rowLblWin
;
2128 m_colLabelWin
= colLblWin
;
2129 SetBackgroundColour( "WHITE" );
2133 wxGridWindow::~wxGridWindow()
2138 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2140 wxPaintDC
dc( this );
2141 m_owner
->PrepareDC( dc
);
2142 wxRegion reg
= GetUpdateRegion();
2143 m_owner
->CalcCellsExposed( reg
);
2144 m_owner
->DrawGridCellArea( dc
);
2145 #if WXGRID_DRAW_LINES
2146 m_owner
->DrawAllGridLines( dc
, reg
);
2148 m_owner
->DrawHighlight( dc
);
2152 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2154 wxPanel::ScrollWindow( dx
, dy
, rect
);
2155 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
2156 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
2160 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
2162 m_owner
->ProcessGridCellMouseEvent( event
);
2166 // This seems to be required for wxMotif otherwise the mouse
2167 // cursor must be in the cell edit control to get key events
2169 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
2171 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
2174 // We are trapping erase background events to reduce flicker under MSW
2175 // and GTK but this can leave junk in the space beyond the last row and
2176 // col. So here we paint these spaces if they are visible.
2178 void wxGridWindow::OnEraseBackground(wxEraseEvent
& event
)
2181 GetClientSize( &cw
, &ch
);
2184 m_owner
->CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
2187 rightRect
= m_owner
->CellToRect( 0, m_owner
->GetNumberCols()-1 );
2190 bottomRect
= m_owner
->CellToRect( m_owner
->GetNumberRows()-1, 0 );
2192 if ( right
> rightRect
.GetRight() || bottom
> bottomRect
.GetBottom() )
2195 m_owner
->CalcUnscrolledPosition( 0, 0, &left
, &top
);
2197 wxClientDC
dc( this );
2198 m_owner
->PrepareDC( dc
);
2199 dc
.SetBrush( wxBrush(m_owner
->GetDefaultCellBackgroundColour(), wxSOLID
) );
2200 dc
.SetPen( *wxTRANSPARENT_PEN
);
2202 if ( right
> rightRect
.GetRight() )
2203 dc
.DrawRectangle( rightRect
.GetRight()+1, top
, right
- rightRect
.GetRight(), ch
);
2205 if ( bottom
> bottomRect
.GetBottom() )
2206 dc
.DrawRectangle( left
, bottomRect
.GetBottom()+1, cw
, bottom
- bottomRect
.GetBottom() );
2211 //////////////////////////////////////////////////////////////////////
2214 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
2216 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
2217 EVT_PAINT( wxGrid::OnPaint
)
2218 EVT_SIZE( wxGrid::OnSize
)
2219 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
2220 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
2223 wxGrid::wxGrid( wxWindow
*parent
,
2228 const wxString
& name
)
2229 : wxScrolledWindow( parent
, id
, pos
, size
, style
, name
),
2230 m_colMinWidths(wxKEY_INTEGER
, GRID_HASH_SIZE
)
2239 m_defaultCellAttr
->SafeDecRef();
2241 #ifdef DEBUG_ATTR_CACHE
2242 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
2243 wxPrintf(_T("wxGrid attribute cache statistics: "
2244 "total: %u, hits: %u (%u%%)\n"),
2245 total
, gs_nAttrCacheHits
,
2246 total
? (gs_nAttrCacheHits
*100) / total
: 0);
2252 delete m_typeRegistry
;
2257 // ----- internal init and update functions
2260 void wxGrid::Create()
2262 m_created
= FALSE
; // set to TRUE by CreateGrid
2263 m_displayed
= TRUE
; // FALSE; // set to TRUE by OnPaint
2265 m_table
= (wxGridTableBase
*) NULL
;
2268 m_cellEditCtrlEnabled
= FALSE
;
2270 m_defaultCellAttr
= new wxGridCellAttr
;
2271 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
2273 // Set default cell attributes
2274 m_defaultCellAttr
->SetFont(GetFont());
2275 m_defaultCellAttr
->SetAlignment(wxLEFT
, wxTOP
);
2276 m_defaultCellAttr
->SetTextColour(
2277 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT
));
2278 m_defaultCellAttr
->SetBackgroundColour(
2279 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
2280 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
2281 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
2286 m_currentCellCoords
= wxGridNoCellCoords
;
2288 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
2289 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
2291 // data type registration
2292 m_typeRegistry
= new wxGridTypeRegistry
;
2293 RegisterDataType(wxT("string"), new wxGridCellStringRenderer
,
2294 new wxGridCellTextEditor
);
2295 RegisterDataType(wxT("bool"), new wxGridCellBoolRenderer
,
2296 new wxGridCellBoolEditor
);
2299 // subwindow components that make up the wxGrid
2300 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
2305 m_rowLabelWin
= new wxGridRowLabelWindow( this,
2310 m_colLabelWin
= new wxGridColLabelWindow( this,
2315 m_gridWin
= new wxGridWindow( this,
2322 SetTargetWindow( m_gridWin
);
2326 bool wxGrid::CreateGrid( int numRows
, int numCols
)
2330 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
2335 m_numRows
= numRows
;
2336 m_numCols
= numCols
;
2338 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
2339 m_table
->SetView( this );
2348 bool wxGrid::SetTable( wxGridTableBase
*table
, bool takeOwnership
)
2352 // RD: Actually, this should probably be allowed. I think it would be
2353 // nice to be able to switch multiple Tables in and out of a single
2354 // View at runtime. Is there anything in the implmentation that would
2357 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
2362 m_numRows
= table
->GetNumberRows();
2363 m_numCols
= table
->GetNumberCols();
2366 m_table
->SetView( this );
2379 if ( m_numRows
<= 0 )
2380 m_numRows
= WXGRID_DEFAULT_NUMBER_ROWS
;
2382 if ( m_numCols
<= 0 )
2383 m_numCols
= WXGRID_DEFAULT_NUMBER_COLS
;
2385 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
2386 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
2388 if ( m_rowLabelWin
)
2390 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
2394 m_labelBackgroundColour
= wxColour( _T("WHITE") );
2397 m_labelTextColour
= wxColour( _T("BLACK") );
2400 m_attrCache
.row
= -1;
2402 // TODO: something better than this ?
2404 m_labelFont
= this->GetFont();
2405 m_labelFont
.SetWeight( m_labelFont
.GetWeight() + 2 );
2407 m_rowLabelHorizAlign
= wxLEFT
;
2408 m_rowLabelVertAlign
= wxCENTRE
;
2410 m_colLabelHorizAlign
= wxCENTRE
;
2411 m_colLabelVertAlign
= wxTOP
;
2413 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
2414 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
2416 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
2417 m_defaultRowHeight
+= 8;
2419 m_defaultRowHeight
+= 4;
2422 m_gridLineColour
= wxColour( 128, 128, 255 );
2423 m_gridLinesEnabled
= TRUE
;
2425 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
2426 m_winCapture
= (wxWindow
*)NULL
;
2427 m_canDragRowSize
= TRUE
;
2428 m_canDragColSize
= TRUE
;
2430 m_dragRowOrCol
= -1;
2431 m_isDragging
= FALSE
;
2432 m_startDragPos
= wxDefaultPosition
;
2434 m_waitForSlowClick
= FALSE
;
2436 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
2437 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
2439 m_currentCellCoords
= wxGridNoCellCoords
;
2441 m_selectedTopLeft
= wxGridNoCellCoords
;
2442 m_selectedBottomRight
= wxGridNoCellCoords
;
2443 m_selectionBackground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
);
2444 m_selectionForeground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
2446 m_editable
= TRUE
; // default for whole grid
2448 m_inOnKeyDown
= FALSE
;
2452 // ----------------------------------------------------------------------------
2453 // the idea is to call these functions only when necessary because they create
2454 // quite big arrays which eat memory mostly unnecessary - in particular, if
2455 // default widths/heights are used for all rows/columns, we may not use these
2458 // with some extra code, it should be possible to only store the
2459 // widths/heights different from default ones but this will be done later...
2460 // ----------------------------------------------------------------------------
2462 void wxGrid::InitRowHeights()
2464 m_rowHeights
.Empty();
2465 m_rowBottoms
.Empty();
2467 m_rowHeights
.Alloc( m_numRows
);
2468 m_rowBottoms
.Alloc( m_numRows
);
2471 for ( int i
= 0; i
< m_numRows
; i
++ )
2473 m_rowHeights
.Add( m_defaultRowHeight
);
2474 rowBottom
+= m_defaultRowHeight
;
2475 m_rowBottoms
.Add( rowBottom
);
2479 void wxGrid::InitColWidths()
2481 m_colWidths
.Empty();
2482 m_colRights
.Empty();
2484 m_colWidths
.Alloc( m_numCols
);
2485 m_colRights
.Alloc( m_numCols
);
2487 for ( int i
= 0; i
< m_numCols
; i
++ )
2489 m_colWidths
.Add( m_defaultColWidth
);
2490 colRight
+= m_defaultColWidth
;
2491 m_colRights
.Add( colRight
);
2495 int wxGrid::GetColWidth(int col
) const
2497 return m_colWidths
.IsEmpty() ? m_defaultColWidth
: m_colWidths
[col
];
2500 int wxGrid::GetColLeft(int col
) const
2502 return m_colRights
.IsEmpty() ? col
* m_defaultColWidth
2503 : m_colRights
[col
] - m_colWidths
[col
];
2506 int wxGrid::GetColRight(int col
) const
2508 return m_colRights
.IsEmpty() ? (col
+ 1) * m_defaultColWidth
2512 int wxGrid::GetRowHeight(int row
) const
2514 return m_rowHeights
.IsEmpty() ? m_defaultRowHeight
: m_rowHeights
[row
];
2517 int wxGrid::GetRowTop(int row
) const
2519 return m_rowBottoms
.IsEmpty() ? row
* m_defaultRowHeight
2520 : m_rowBottoms
[row
] - m_rowHeights
[row
];
2523 int wxGrid::GetRowBottom(int row
) const
2525 return m_rowBottoms
.IsEmpty() ? (row
+ 1) * m_defaultRowHeight
2526 : m_rowBottoms
[row
];
2529 void wxGrid::CalcDimensions()
2532 GetClientSize( &cw
, &ch
);
2534 if ( m_numRows
> 0 && m_numCols
> 0 )
2536 int right
= GetColRight( m_numCols
-1 ) + 50;
2537 int bottom
= GetRowBottom( m_numRows
-1 ) + 50;
2539 // TODO: restore the scroll position that we had before sizing
2542 GetViewStart( &x
, &y
);
2543 SetScrollbars( GRID_SCROLL_LINE
, GRID_SCROLL_LINE
,
2544 right
/GRID_SCROLL_LINE
, bottom
/GRID_SCROLL_LINE
,
2550 void wxGrid::CalcWindowSizes()
2553 GetClientSize( &cw
, &ch
);
2555 if ( m_cornerLabelWin
->IsShown() )
2556 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
2558 if ( m_colLabelWin
->IsShown() )
2559 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
2561 if ( m_rowLabelWin
->IsShown() )
2562 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
2564 if ( m_gridWin
->IsShown() )
2565 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
2569 // this is called when the grid table sends a message to say that it
2570 // has been redimensioned
2572 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
2576 // if we were using the default widths/heights so far, we must change them
2578 if ( m_colWidths
.IsEmpty() )
2583 if ( m_rowHeights
.IsEmpty() )
2588 switch ( msg
.GetId() )
2590 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
2592 size_t pos
= msg
.GetCommandInt();
2593 int numRows
= msg
.GetCommandInt2();
2594 for ( i
= 0; i
< numRows
; i
++ )
2596 m_rowHeights
.Insert( m_defaultRowHeight
, pos
);
2597 m_rowBottoms
.Insert( 0, pos
);
2599 m_numRows
+= numRows
;
2602 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
2604 for ( i
= pos
; i
< m_numRows
; i
++ )
2606 bottom
+= m_rowHeights
[i
];
2607 m_rowBottoms
[i
] = bottom
;
2613 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
2615 int numRows
= msg
.GetCommandInt();
2616 for ( i
= 0; i
< numRows
; i
++ )
2618 m_rowHeights
.Add( m_defaultRowHeight
);
2619 m_rowBottoms
.Add( 0 );
2622 int oldNumRows
= m_numRows
;
2623 m_numRows
+= numRows
;
2626 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
2628 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
2630 bottom
+= m_rowHeights
[i
];
2631 m_rowBottoms
[i
] = bottom
;
2637 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
2639 size_t pos
= msg
.GetCommandInt();
2640 int numRows
= msg
.GetCommandInt2();
2641 for ( i
= 0; i
< numRows
; i
++ )
2643 m_rowHeights
.Remove( pos
);
2644 m_rowBottoms
.Remove( pos
);
2646 m_numRows
-= numRows
;
2651 m_colWidths
.Clear();
2652 m_colRights
.Clear();
2653 m_currentCellCoords
= wxGridNoCellCoords
;
2657 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
2658 m_currentCellCoords
.Set( 0, 0 );
2661 for ( i
= 0; i
< m_numRows
; i
++ )
2663 h
+= m_rowHeights
[i
];
2664 m_rowBottoms
[i
] = h
;
2672 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
2674 size_t pos
= msg
.GetCommandInt();
2675 int numCols
= msg
.GetCommandInt2();
2676 for ( i
= 0; i
< numCols
; i
++ )
2678 m_colWidths
.Insert( m_defaultColWidth
, pos
);
2679 m_colRights
.Insert( 0, pos
);
2681 m_numCols
+= numCols
;
2684 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
2686 for ( i
= pos
; i
< m_numCols
; i
++ )
2688 right
+= m_colWidths
[i
];
2689 m_colRights
[i
] = right
;
2695 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
2697 int numCols
= msg
.GetCommandInt();
2698 for ( i
= 0; i
< numCols
; i
++ )
2700 m_colWidths
.Add( m_defaultColWidth
);
2701 m_colRights
.Add( 0 );
2704 int oldNumCols
= m_numCols
;
2705 m_numCols
+= numCols
;
2708 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
2710 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
2712 right
+= m_colWidths
[i
];
2713 m_colRights
[i
] = right
;
2719 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
2721 size_t pos
= msg
.GetCommandInt();
2722 int numCols
= msg
.GetCommandInt2();
2723 for ( i
= 0; i
< numCols
; i
++ )
2725 m_colWidths
.Remove( pos
);
2726 m_colRights
.Remove( pos
);
2728 m_numCols
-= numCols
;
2732 #if 0 // leave the row alone here so that AppendCols will work subsequently
2734 m_rowHeights
.Clear();
2735 m_rowBottoms
.Clear();
2737 m_currentCellCoords
= wxGridNoCellCoords
;
2741 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
2742 m_currentCellCoords
.Set( 0, 0 );
2745 for ( i
= 0; i
< m_numCols
; i
++ )
2747 w
+= m_colWidths
[i
];
2760 void wxGrid::CalcRowLabelsExposed( wxRegion
& reg
)
2762 wxRegionIterator
iter( reg
);
2765 m_rowLabelsExposed
.Empty();
2772 // TODO: remove this when we can...
2773 // There is a bug in wxMotif that gives garbage update
2774 // rectangles if you jump-scroll a long way by clicking the
2775 // scrollbar with middle button. This is a work-around
2777 #if defined(__WXMOTIF__)
2779 m_gridWin
->GetClientSize( &cw
, &ch
);
2780 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
2781 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
2784 // logical bounds of update region
2787 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
2788 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
2790 // find the row labels within these bounds
2793 for ( row
= 0; row
< m_numRows
; row
++ )
2795 if ( GetRowBottom(row
) < top
)
2798 if ( GetRowTop(row
) > bottom
)
2801 m_rowLabelsExposed
.Add( row
);
2809 void wxGrid::CalcColLabelsExposed( wxRegion
& reg
)
2811 wxRegionIterator
iter( reg
);
2814 m_colLabelsExposed
.Empty();
2821 // TODO: remove this when we can...
2822 // There is a bug in wxMotif that gives garbage update
2823 // rectangles if you jump-scroll a long way by clicking the
2824 // scrollbar with middle button. This is a work-around
2826 #if defined(__WXMOTIF__)
2828 m_gridWin
->GetClientSize( &cw
, &ch
);
2829 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
2830 r
.SetRight( wxMin( r
.GetRight(), cw
) );
2833 // logical bounds of update region
2836 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
2837 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
2839 // find the cells within these bounds
2842 for ( col
= 0; col
< m_numCols
; col
++ )
2844 if ( GetColRight(col
) < left
)
2847 if ( GetColLeft(col
) > right
)
2850 m_colLabelsExposed
.Add( col
);
2858 void wxGrid::CalcCellsExposed( wxRegion
& reg
)
2860 wxRegionIterator
iter( reg
);
2863 m_cellsExposed
.Empty();
2864 m_rowsExposed
.Empty();
2865 m_colsExposed
.Empty();
2867 int left
, top
, right
, bottom
;
2872 // TODO: remove this when we can...
2873 // There is a bug in wxMotif that gives garbage update
2874 // rectangles if you jump-scroll a long way by clicking the
2875 // scrollbar with middle button. This is a work-around
2877 #if defined(__WXMOTIF__)
2879 m_gridWin
->GetClientSize( &cw
, &ch
);
2880 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
2881 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
2882 r
.SetRight( wxMin( r
.GetRight(), cw
) );
2883 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
2886 // logical bounds of update region
2888 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
2889 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
2891 // find the cells within these bounds
2894 for ( row
= 0; row
< m_numRows
; row
++ )
2896 if ( GetRowBottom(row
) <= top
)
2899 if ( GetRowTop(row
) > bottom
)
2902 m_rowsExposed
.Add( row
);
2904 for ( col
= 0; col
< m_numCols
; col
++ )
2906 if ( GetColRight(col
) <= left
)
2909 if ( GetColLeft(col
) > right
)
2912 if ( m_colsExposed
.Index( col
) == wxNOT_FOUND
)
2913 m_colsExposed
.Add( col
);
2914 m_cellsExposed
.Add( wxGridCellCoords( row
, col
) );
2923 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
2926 wxPoint
pos( event
.GetPosition() );
2927 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2929 if ( event
.Dragging() )
2931 m_isDragging
= TRUE
;
2933 if ( event
.LeftIsDown() )
2935 switch( m_cursorMode
)
2937 case WXGRID_CURSOR_RESIZE_ROW
:
2939 int cw
, ch
, left
, dummy
;
2940 m_gridWin
->GetClientSize( &cw
, &ch
);
2941 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
2943 wxClientDC
dc( m_gridWin
);
2945 y
= wxMax( y
, GetRowTop(m_dragRowOrCol
) + WXGRID_MIN_ROW_HEIGHT
);
2946 dc
.SetLogicalFunction(wxINVERT
);
2947 if ( m_dragLastPos
>= 0 )
2949 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
2951 dc
.DrawLine( left
, y
, left
+cw
, y
);
2956 case WXGRID_CURSOR_SELECT_ROW
:
2957 if ( (row
= YToRow( y
)) >= 0 &&
2958 !IsInSelection( row
, 0 ) )
2960 SelectRow( row
, TRUE
);
2963 // default label to suppress warnings about "enumeration value
2964 // 'xxx' not handled in switch
2972 m_isDragging
= FALSE
;
2975 // ------------ Entering or leaving the window
2977 if ( event
.Entering() || event
.Leaving() )
2979 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
2983 // ------------ Left button pressed
2985 else if ( event
.LeftDown() )
2987 // don't send a label click event for a hit on the
2988 // edge of the row label - this is probably the user
2989 // wanting to resize the row
2991 if ( YToEdgeOfRow(y
) < 0 )
2995 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
2997 SelectRow( row
, event
.ShiftDown() );
2998 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
3003 // starting to drag-resize a row
3005 if ( CanDragRowSize() )
3006 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
3011 // ------------ Left double click
3013 else if (event
.LeftDClick() )
3015 if ( YToEdgeOfRow(y
) < 0 )
3018 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
);
3023 // ------------ Left button released
3025 else if ( event
.LeftUp() )
3027 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
3029 DoEndDragResizeRow();
3031 // Note: we are ending the event *after* doing
3032 // default processing in this case
3034 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
3037 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
3042 // ------------ Right button down
3044 else if ( event
.RightDown() )
3047 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
3049 // no default action at the moment
3054 // ------------ Right double click
3056 else if ( event
.RightDClick() )
3059 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
3061 // no default action at the moment
3066 // ------------ No buttons down and mouse moving
3068 else if ( event
.Moving() )
3070 m_dragRowOrCol
= YToEdgeOfRow( y
);
3071 if ( m_dragRowOrCol
>= 0 )
3073 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3075 // don't capture the mouse yet
3076 if ( CanDragRowSize() )
3077 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, FALSE
);
3080 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3082 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, FALSE
);
3088 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
3091 wxPoint
pos( event
.GetPosition() );
3092 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
3094 if ( event
.Dragging() )
3096 m_isDragging
= TRUE
;
3098 if ( event
.LeftIsDown() )
3100 switch( m_cursorMode
)
3102 case WXGRID_CURSOR_RESIZE_COL
:
3104 int cw
, ch
, dummy
, top
;
3105 m_gridWin
->GetClientSize( &cw
, &ch
);
3106 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
3108 wxClientDC
dc( m_gridWin
);
3111 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
3112 GetColMinimalWidth(m_dragRowOrCol
));
3113 dc
.SetLogicalFunction(wxINVERT
);
3114 if ( m_dragLastPos
>= 0 )
3116 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
3118 dc
.DrawLine( x
, top
, x
, top
+ch
);
3123 case WXGRID_CURSOR_SELECT_COL
:
3124 if ( (col
= XToCol( x
)) >= 0 &&
3125 !IsInSelection( 0, col
) )
3127 SelectCol( col
, TRUE
);
3130 // default label to suppress warnings about "enumeration value
3131 // 'xxx' not handled in switch
3139 m_isDragging
= FALSE
;
3142 // ------------ Entering or leaving the window
3144 if ( event
.Entering() || event
.Leaving() )
3146 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
3150 // ------------ Left button pressed
3152 else if ( event
.LeftDown() )
3154 // don't send a label click event for a hit on the
3155 // edge of the col label - this is probably the user
3156 // wanting to resize the col
3158 if ( XToEdgeOfCol(x
) < 0 )
3162 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
3164 SelectCol( col
, event
.ShiftDown() );
3165 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, m_colLabelWin
);
3170 // starting to drag-resize a col
3172 if ( CanDragColSize() )
3173 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
);
3178 // ------------ Left double click
3180 if ( event
.LeftDClick() )
3182 if ( XToEdgeOfCol(x
) < 0 )
3185 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
);
3190 // ------------ Left button released
3192 else if ( event
.LeftUp() )
3194 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
3196 DoEndDragResizeCol();
3198 // Note: we are ending the event *after* doing
3199 // default processing in this case
3201 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
3204 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
3209 // ------------ Right button down
3211 else if ( event
.RightDown() )
3214 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
3216 // no default action at the moment
3221 // ------------ Right double click
3223 else if ( event
.RightDClick() )
3226 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
3228 // no default action at the moment
3233 // ------------ No buttons down and mouse moving
3235 else if ( event
.Moving() )
3237 m_dragRowOrCol
= XToEdgeOfCol( x
);
3238 if ( m_dragRowOrCol
>= 0 )
3240 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3242 // don't capture the cursor yet
3243 if ( CanDragColSize() )
3244 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
, FALSE
);
3247 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3249 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
, FALSE
);
3255 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
3257 if ( event
.LeftDown() )
3259 // indicate corner label by having both row and
3262 if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
3268 else if ( event
.LeftDClick() )
3270 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
3273 else if ( event
.RightDown() )
3275 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
3277 // no default action at the moment
3281 else if ( event
.RightDClick() )
3283 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
3285 // no default action at the moment
3290 void wxGrid::ChangeCursorMode(CursorMode mode
,
3295 static const wxChar
*cursorModes
[] =
3304 wxLogTrace(_T("grid"),
3305 _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
3306 win
== m_colLabelWin
? _T("colLabelWin")
3307 : win
? _T("rowLabelWin")
3309 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
3310 #endif // __WXDEBUG__
3312 if ( mode
== m_cursorMode
)
3317 // by default use the grid itself
3323 m_winCapture
->ReleaseMouse();
3324 m_winCapture
= (wxWindow
*)NULL
;
3327 m_cursorMode
= mode
;
3329 switch ( m_cursorMode
)
3331 case WXGRID_CURSOR_RESIZE_ROW
:
3332 win
->SetCursor( m_rowResizeCursor
);
3335 case WXGRID_CURSOR_RESIZE_COL
:
3336 win
->SetCursor( m_colResizeCursor
);
3340 win
->SetCursor( *wxSTANDARD_CURSOR
);
3343 // we need to capture mouse when resizing
3344 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
3345 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
3347 if ( captureMouse
&& resize
)
3349 win
->CaptureMouse();
3354 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
3357 wxPoint
pos( event
.GetPosition() );
3358 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
3360 wxGridCellCoords coords
;
3361 XYToCell( x
, y
, coords
);
3363 if ( event
.Dragging() )
3365 //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
3367 // Don't start doing anything until the mouse has been drug at
3368 // least 3 pixels in any direction...
3371 if (m_startDragPos
== wxDefaultPosition
)
3373 m_startDragPos
= pos
;
3376 if (abs(m_startDragPos
.x
- pos
.x
) < 4 && abs(m_startDragPos
.y
- pos
.y
) < 4)
3380 m_isDragging
= TRUE
;
3381 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3383 // Hide the edit control, so it
3384 // won't interfer with drag-shrinking.
3385 if ( IsCellEditControlEnabled() )
3386 HideCellEditControl();
3388 // Have we captured the mouse yet?
3391 m_winCapture
= m_gridWin
;
3392 m_winCapture
->CaptureMouse();
3395 if ( coords
!= wxGridNoCellCoords
)
3397 if ( !IsSelection() )
3399 SelectBlock( coords
, coords
);
3403 SelectBlock( m_currentCellCoords
, coords
);
3406 if (! IsVisible(coords
))
3408 MakeCellVisible(coords
);
3409 // TODO: need to introduce a delay or something here. The
3410 // scrolling is way to fast, at least on MSW.
3414 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
3416 int cw
, ch
, left
, dummy
;
3417 m_gridWin
->GetClientSize( &cw
, &ch
);
3418 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
3420 wxClientDC
dc( m_gridWin
);
3422 y
= wxMax( y
, GetRowTop(m_dragRowOrCol
) + WXGRID_MIN_ROW_HEIGHT
);
3423 dc
.SetLogicalFunction(wxINVERT
);
3424 if ( m_dragLastPos
>= 0 )
3426 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
3428 dc
.DrawLine( left
, y
, left
+cw
, y
);
3431 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
3433 int cw
, ch
, dummy
, top
;
3434 m_gridWin
->GetClientSize( &cw
, &ch
);
3435 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
3437 wxClientDC
dc( m_gridWin
);
3439 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
3440 GetColMinimalWidth(m_dragRowOrCol
) );
3441 dc
.SetLogicalFunction(wxINVERT
);
3442 if ( m_dragLastPos
>= 0 )
3444 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
3446 dc
.DrawLine( x
, top
, x
, top
+ch
);
3453 m_isDragging
= FALSE
;
3454 m_startDragPos
= wxDefaultPosition
;
3457 if ( coords
!= wxGridNoCellCoords
)
3459 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
3460 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
3463 if ( event
.Entering() || event
.Leaving() )
3465 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3466 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
3471 // ------------ Left button pressed
3473 if ( event
.LeftDown() )
3475 DisableCellEditControl();
3476 if ( event
.ShiftDown() )
3478 SelectBlock( m_currentCellCoords
, coords
);
3480 else if ( XToEdgeOfCol(x
) < 0 &&
3481 YToEdgeOfRow(y
) < 0 )
3483 if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK
,
3488 MakeCellVisible( coords
);
3490 // if this is the second click on this cell then start
3492 if ( m_waitForSlowClick
&&
3493 (coords
== m_currentCellCoords
) &&
3494 CanEnableCellControl())
3496 EnableCellEditControl();
3498 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
3499 attr
->GetEditor(GetDefaultEditorForCell(coords
.GetRow(), coords
.GetCol()))->StartingClick();
3502 m_waitForSlowClick
= FALSE
;
3506 SetCurrentCell( coords
);
3507 m_waitForSlowClick
= TRUE
;
3514 // ------------ Left double click
3516 else if ( event
.LeftDClick() )
3518 DisableCellEditControl();
3519 if ( XToEdgeOfCol(x
) < 0 && YToEdgeOfRow(y
) < 0 )
3521 SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK
,
3529 // ------------ Left button released
3531 else if ( event
.LeftUp() )
3533 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3535 if ( IsSelection() )
3539 m_winCapture
->ReleaseMouse();
3540 m_winCapture
= NULL
;
3542 SendEvent( wxEVT_GRID_RANGE_SELECT
, -1, -1, event
);
3545 // Show the edit control, if it has been hidden for
3547 ShowCellEditControl();
3549 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
3551 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3552 DoEndDragResizeRow();
3554 // Note: we are ending the event *after* doing
3555 // default processing in this case
3557 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
3559 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
3561 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3562 DoEndDragResizeCol();
3564 // Note: we are ending the event *after* doing
3565 // default processing in this case
3567 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
3574 // ------------ Right button down
3576 else if ( event
.RightDown() )
3578 DisableCellEditControl();
3579 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK
,
3584 // no default action at the moment
3589 // ------------ Right double click
3591 else if ( event
.RightDClick() )
3593 DisableCellEditControl();
3594 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK
,
3599 // no default action at the moment
3603 // ------------ Moving and no button action
3605 else if ( event
.Moving() && !event
.IsButton() )
3607 int dragRow
= YToEdgeOfRow( y
);
3608 int dragCol
= XToEdgeOfCol( x
);
3610 // Dragging on the corner of a cell to resize in both
3611 // directions is not implemented yet...
3613 if ( dragRow
>= 0 && dragCol
>= 0 )
3615 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3621 m_dragRowOrCol
= dragRow
;
3623 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3625 if ( CanDragRowSize() )
3626 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
);
3634 m_dragRowOrCol
= dragCol
;
3636 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3638 if ( CanDragColSize() )
3639 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
);
3645 // Neither on a row or col edge
3647 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3649 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3656 void wxGrid::DoEndDragResizeRow()
3658 if ( m_dragLastPos
>= 0 )
3660 // erase the last line and resize the row
3662 int cw
, ch
, left
, dummy
;
3663 m_gridWin
->GetClientSize( &cw
, &ch
);
3664 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
3666 wxClientDC
dc( m_gridWin
);
3668 dc
.SetLogicalFunction( wxINVERT
);
3669 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
3670 HideCellEditControl();
3672 int rowTop
= GetRowTop(m_dragRowOrCol
);
3673 SetRowSize( m_dragRowOrCol
,
3674 wxMax( m_dragLastPos
- rowTop
, WXGRID_MIN_ROW_HEIGHT
) );
3676 if ( !GetBatchCount() )
3678 // Only needed to get the correct rect.y:
3679 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
3681 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
3682 rect
.width
= m_rowLabelWidth
;
3683 rect
.height
= ch
- rect
.y
;
3684 m_rowLabelWin
->Refresh( TRUE
, &rect
);
3686 m_gridWin
->Refresh( FALSE
, &rect
);
3689 ShowCellEditControl();
3694 void wxGrid::DoEndDragResizeCol()
3696 if ( m_dragLastPos
>= 0 )
3698 // erase the last line and resize the col
3700 int cw
, ch
, dummy
, top
;
3701 m_gridWin
->GetClientSize( &cw
, &ch
);
3702 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
3704 wxClientDC
dc( m_gridWin
);
3706 dc
.SetLogicalFunction( wxINVERT
);
3707 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
3708 HideCellEditControl();
3710 int colLeft
= GetColLeft(m_dragRowOrCol
);
3711 SetColSize( m_dragRowOrCol
,
3712 wxMax( m_dragLastPos
- colLeft
,
3713 GetColMinimalWidth(m_dragRowOrCol
) ) );
3715 if ( !GetBatchCount() )
3717 // Only needed to get the correct rect.x:
3718 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
3720 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
3721 rect
.width
= cw
- rect
.x
;
3722 rect
.height
= m_colLabelHeight
;
3723 m_colLabelWin
->Refresh( TRUE
, &rect
);
3725 m_gridWin
->Refresh( FALSE
, &rect
);
3728 ShowCellEditControl();
3735 // ------ interaction with data model
3737 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
3739 switch ( msg
.GetId() )
3741 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
3742 return GetModelValues();
3744 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
3745 return SetModelValues();
3747 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
3748 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
3749 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
3750 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
3751 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
3752 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
3753 return Redimension( msg
);
3762 // The behaviour of this function depends on the grid table class
3763 // Clear() function. For the default wxGridStringTable class the
3764 // behavious is to replace all cell contents with wxEmptyString but
3765 // not to change the number of rows or cols.
3767 void wxGrid::ClearGrid()
3772 SetEditControlValue();
3773 if ( !GetBatchCount() ) m_gridWin
->Refresh();
3778 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
3780 // TODO: something with updateLabels flag
3784 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
3790 if (IsCellEditControlEnabled())
3791 DisableCellEditControl();
3793 bool ok
= m_table
->InsertRows( pos
, numRows
);
3795 // the table will have sent the results of the insert row
3796 // operation to this view object as a grid table message
3800 if ( m_numCols
== 0 )
3802 m_table
->AppendCols( WXGRID_DEFAULT_NUMBER_COLS
);
3804 // TODO: perhaps instead of appending the default number of cols
3805 // we should remember what the last non-zero number of cols was ?
3809 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3811 // if we have just inserted cols into an empty grid the current
3812 // cell will be undefined...
3814 SetCurrentCell( 0, 0 );
3818 if ( !GetBatchCount() ) Refresh();
3821 SetEditControlValue();
3831 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
3833 // TODO: something with updateLabels flag
3837 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
3841 if ( m_table
&& m_table
->AppendRows( numRows
) )
3843 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3845 // if we have just inserted cols into an empty grid the current
3846 // cell will be undefined...
3848 SetCurrentCell( 0, 0 );
3851 // the table will have sent the results of the append row
3852 // operation to this view object as a grid table message
3855 if ( !GetBatchCount() ) Refresh();
3865 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
3867 // TODO: something with updateLabels flag
3871 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
3877 if (IsCellEditControlEnabled())
3878 DisableCellEditControl();
3880 if (m_table
->DeleteRows( pos
, numRows
))
3883 // the table will have sent the results of the delete row
3884 // operation to this view object as a grid table message
3887 if ( !GetBatchCount() ) Refresh();
3895 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
3897 // TODO: something with updateLabels flag
3901 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
3907 if (IsCellEditControlEnabled())
3908 DisableCellEditControl();
3910 bool ok
= m_table
->InsertCols( pos
, numCols
);
3912 // the table will have sent the results of the insert col
3913 // operation to this view object as a grid table message
3917 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3919 // if we have just inserted cols into an empty grid the current
3920 // cell will be undefined...
3922 SetCurrentCell( 0, 0 );
3926 if ( !GetBatchCount() ) Refresh();
3929 SetEditControlValue();
3939 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
3941 // TODO: something with updateLabels flag
3945 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
3949 if ( m_table
&& m_table
->AppendCols( numCols
) )
3951 // the table will have sent the results of the append col
3952 // operation to this view object as a grid table message
3954 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3956 // if we have just inserted cols into an empty grid the current
3957 // cell will be undefined...
3959 SetCurrentCell( 0, 0 );
3963 if ( !GetBatchCount() ) Refresh();
3973 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
3975 // TODO: something with updateLabels flag
3979 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
3985 if (IsCellEditControlEnabled())
3986 DisableCellEditControl();
3988 if ( m_table
->DeleteCols( pos
, numCols
) )
3990 // the table will have sent the results of the delete col
3991 // operation to this view object as a grid table message
3994 if ( !GetBatchCount() ) Refresh();
4004 // ----- event handlers
4007 // Generate a grid event based on a mouse event and
4008 // return the result of ProcessEvent()
4010 bool wxGrid::SendEvent( const wxEventType type
,
4012 wxMouseEvent
& mouseEv
)
4014 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
4016 int rowOrCol
= (row
== -1 ? col
: row
);
4018 wxGridSizeEvent
gridEvt( GetId(),
4022 mouseEv
.GetX(), mouseEv
.GetY(),
4023 mouseEv
.ControlDown(),
4024 mouseEv
.ShiftDown(),
4026 mouseEv
.MetaDown() );
4028 return GetEventHandler()->ProcessEvent(gridEvt
);
4030 else if ( type
== wxEVT_GRID_RANGE_SELECT
)
4032 wxGridRangeSelectEvent
gridEvt( GetId(),
4036 m_selectedBottomRight
,
4037 mouseEv
.ControlDown(),
4038 mouseEv
.ShiftDown(),
4040 mouseEv
.MetaDown() );
4042 return GetEventHandler()->ProcessEvent(gridEvt
);
4046 wxGridEvent
gridEvt( GetId(),
4050 mouseEv
.GetX(), mouseEv
.GetY(),
4051 mouseEv
.ControlDown(),
4052 mouseEv
.ShiftDown(),
4054 mouseEv
.MetaDown() );
4056 return GetEventHandler()->ProcessEvent(gridEvt
);
4061 // Generate a grid event of specified type and return the result
4062 // of ProcessEvent().
4064 bool wxGrid::SendEvent( const wxEventType type
,
4067 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
4069 int rowOrCol
= (row
== -1 ? col
: row
);
4071 wxGridSizeEvent
gridEvt( GetId(),
4076 return GetEventHandler()->ProcessEvent(gridEvt
);
4080 wxGridEvent
gridEvt( GetId(),
4085 return GetEventHandler()->ProcessEvent(gridEvt
);
4090 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
4092 wxPaintDC
dc( this );
4094 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
4095 m_numRows
&& m_numCols
)
4097 m_currentCellCoords
.Set(0, 0);
4098 SetEditControlValue();
4099 ShowCellEditControl();
4106 // This is just here to make sure that CalcDimensions gets called when
4107 // the grid view is resized... then the size event is skipped to allow
4108 // the box sizers to handle everything
4110 void wxGrid::OnSize( wxSizeEvent
& event
)
4117 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
4119 if ( m_inOnKeyDown
)
4121 // shouldn't be here - we are going round in circles...
4123 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
4126 m_inOnKeyDown
= TRUE
;
4128 // propagate the event up and see if it gets processed
4130 wxWindow
*parent
= GetParent();
4131 wxKeyEvent
keyEvt( event
);
4132 keyEvt
.SetEventObject( parent
);
4134 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
4137 // TODO: Should also support Shift-cursor keys for
4138 // extending the selection. Maybe add a flag to
4139 // MoveCursorXXX() and MoveCursorXXXBlock() and
4140 // just send event.ShiftDown().
4142 // try local handlers
4144 switch ( event
.KeyCode() )
4147 if ( event
.ControlDown() )
4149 MoveCursorUpBlock();
4158 if ( event
.ControlDown() )
4160 MoveCursorDownBlock();
4169 if ( event
.ControlDown() )
4171 MoveCursorLeftBlock();
4180 if ( event
.ControlDown() )
4182 MoveCursorRightBlock();
4191 if ( event
.ControlDown() )
4193 event
.Skip(); // to let the edit control have the return
4202 if (event
.ShiftDown())
4209 if ( event
.ControlDown() )
4211 MakeCellVisible( 0, 0 );
4212 SetCurrentCell( 0, 0 );
4221 if ( event
.ControlDown() )
4223 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
4224 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
4240 // We don't want these keys to trigger the edit control, any others?
4249 if ( !IsEditable() )
4254 // Otherwise fall through to default
4257 // now try the cell edit control
4259 if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
4261 EnableCellEditControl();
4262 int row
= m_currentCellCoords
.GetRow();
4263 int col
= m_currentCellCoords
.GetCol();
4264 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4265 attr
->GetEditor(GetDefaultEditorForCell(row
, col
))->StartingKey(event
);
4270 // let others process char events for readonly cells
4277 m_inOnKeyDown
= FALSE
;
4281 void wxGrid::OnEraseBackground(wxEraseEvent
&)
4285 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
4287 if ( SendEvent( wxEVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
4289 // the event has been intercepted - do nothing
4294 m_currentCellCoords
!= wxGridNoCellCoords
)
4296 HideCellEditControl();
4297 SaveEditControlValue();
4298 DisableCellEditControl();
4300 // Clear the old current cell highlight
4301 wxRect r
= BlockToDeviceRect(m_currentCellCoords
, m_currentCellCoords
);
4303 // Otherwise refresh redraws the highlight!
4304 m_currentCellCoords
= coords
;
4306 m_gridWin
->Refresh( FALSE
, &r
);
4309 m_currentCellCoords
= coords
;
4311 SetEditControlValue();
4315 wxClientDC
dc(m_gridWin
);
4318 wxGridCellAttr
* attr
= GetCellAttr(coords
);
4319 DrawCellHighlight(dc
, attr
);
4322 if ( IsSelection() )
4324 wxRect
r( SelectionToDeviceRect() );
4326 if ( !GetBatchCount() ) m_gridWin
->Refresh( FALSE
, &r
);
4333 // ------ functions to get/send data (see also public functions)
4336 bool wxGrid::GetModelValues()
4340 // all we need to do is repaint the grid
4342 m_gridWin
->Refresh();
4350 bool wxGrid::SetModelValues()
4356 for ( row
= 0; row
< m_numRows
; row
++ )
4358 for ( col
= 0; col
< m_numCols
; col
++ )
4360 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
4372 // Note - this function only draws cells that are in the list of
4373 // exposed cells (usually set from the update region by
4374 // CalcExposedCells)
4376 void wxGrid::DrawGridCellArea( wxDC
& dc
)
4378 if ( !m_numRows
|| !m_numCols
) return;
4381 size_t numCells
= m_cellsExposed
.GetCount();
4383 for ( i
= 0; i
< numCells
; i
++ )
4385 DrawCell( dc
, m_cellsExposed
[i
] );
4390 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
4392 int row
= coords
.GetRow();
4393 int col
= coords
.GetCol();
4395 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
4398 // we draw the cell border ourselves
4399 #if !WXGRID_DRAW_LINES
4400 if ( m_gridLinesEnabled
)
4401 DrawCellBorder( dc
, coords
);
4404 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4406 bool isCurrent
= coords
== m_currentCellCoords
;
4409 rect
.x
= GetColLeft(col
);
4410 rect
.y
= GetRowTop(row
);
4411 rect
.width
= GetColWidth(col
) - 1;
4412 rect
.height
= GetRowHeight(row
) - 1;
4414 // if the editor is shown, we should use it and not the renderer
4415 if ( isCurrent
&& IsCellEditControlEnabled() )
4417 attr
->GetEditor(GetDefaultEditorForCell(row
, col
))->
4418 PaintBackground(rect
, attr
);
4422 // but all the rest is drawn by the cell renderer and hence may be
4424 attr
->GetRenderer(GetDefaultRendererForCell(row
,col
))->
4425 Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
4432 void wxGrid::DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
)
4434 int row
= m_currentCellCoords
.GetRow();
4435 int col
= m_currentCellCoords
.GetCol();
4437 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
4441 rect
.x
= GetColLeft(col
);
4442 rect
.y
= GetRowTop(row
);
4443 rect
.width
= GetColWidth(col
) - 1;
4444 rect
.height
= GetRowHeight(row
) - 1;
4446 // hmmm... what could we do here to show that the cell is disabled?
4447 // for now, I just draw a thinner border than for the other ones, but
4448 // it doesn't look really good
4449 dc
.SetPen(wxPen(m_gridLineColour
, attr
->IsReadOnly() ? 1 : 3, wxSOLID
));
4450 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
4452 dc
.DrawRectangle(rect
);
4455 // VZ: my experiments with 3d borders...
4457 // how to properly set colours for arbitrary bg?
4458 wxCoord x1
= rect
.x
,
4460 x2
= rect
.x
+ rect
.width
-1,
4461 y2
= rect
.y
+ rect
.height
-1;
4463 dc
.SetPen(*wxWHITE_PEN
);
4464 dc
.DrawLine(x1
, y1
, x2
, y1
);
4465 dc
.DrawLine(x1
, y1
, x1
, y2
);
4467 dc
.DrawLine(x1
+ 1, y2
- 1, x2
- 1, y2
- 1);
4468 dc
.DrawLine(x2
- 1, y1
+ 1, x2
- 1, y2
);
4470 dc
.SetPen(*wxBLACK_PEN
);
4471 dc
.DrawLine(x1
, y2
, x2
, y2
);
4472 dc
.DrawLine(x2
, y1
, x2
, y2
+1);
4477 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
4479 int row
= coords
.GetRow();
4480 int col
= coords
.GetCol();
4481 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
4484 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
4486 // right hand border
4488 dc
.DrawLine( GetColRight(col
), GetRowTop(row
),
4489 GetColRight(col
), GetRowBottom(row
) );
4493 dc
.DrawLine( GetColLeft(col
), GetRowBottom(row
),
4494 GetColRight(col
), GetRowBottom(row
) );
4497 void wxGrid::DrawHighlight(wxDC
& dc
)
4499 if ( IsCellEditControlEnabled() )
4501 // don't show highlight when the edit control is shown
4505 // if the active cell was repainted, repaint its highlight too because it
4506 // might have been damaged by the grid lines
4507 size_t count
= m_cellsExposed
.GetCount();
4508 for ( size_t n
= 0; n
< count
; n
++ )
4510 if ( m_cellsExposed
[n
] == m_currentCellCoords
)
4512 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
4513 DrawCellHighlight(dc
, attr
);
4521 // TODO: remove this ???
4522 // This is used to redraw all grid lines e.g. when the grid line colour
4525 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
)
4527 if ( !m_gridLinesEnabled
||
4529 !m_numCols
) return;
4531 int top
, bottom
, left
, right
;
4536 m_gridWin
->GetClientSize(&cw
, &ch
);
4538 // virtual coords of visible area
4540 CalcUnscrolledPosition( 0, 0, &left
, &top
);
4541 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
4546 reg
.GetBox(x
, y
, w
, h
);
4547 CalcUnscrolledPosition( x
, y
, &left
, &top
);
4548 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
4551 // avoid drawing grid lines past the last row and col
4553 right
= wxMin( right
, GetColRight(m_numCols
- 1) );
4554 bottom
= wxMin( bottom
, GetRowBottom(m_numRows
- 1) );
4556 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
4558 // horizontal grid lines
4561 for ( i
= 0; i
< m_numRows
; i
++ )
4563 int bot
= GetRowBottom(i
) - 1;
4572 dc
.DrawLine( left
, bot
, right
, bot
);
4577 // vertical grid lines
4579 for ( i
= 0; i
< m_numCols
; i
++ )
4581 int colRight
= GetColRight(i
) - 1;
4582 if ( colRight
> right
)
4587 if ( colRight
>= left
)
4589 dc
.DrawLine( colRight
, top
, colRight
, bottom
);
4595 void wxGrid::DrawRowLabels( wxDC
& dc
)
4597 if ( !m_numRows
|| !m_numCols
) return;
4600 size_t numLabels
= m_rowLabelsExposed
.GetCount();
4602 for ( i
= 0; i
< numLabels
; i
++ )
4604 DrawRowLabel( dc
, m_rowLabelsExposed
[i
] );
4609 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
4611 if ( GetRowHeight(row
) <= 0 )
4614 int rowTop
= GetRowTop(row
),
4615 rowBottom
= GetRowBottom(row
) - 1;
4617 dc
.SetPen( *wxBLACK_PEN
);
4618 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
4619 m_rowLabelWidth
-1, rowBottom
);
4621 dc
.DrawLine( 0, rowBottom
, m_rowLabelWidth
-1, rowBottom
);
4623 dc
.SetPen( *wxWHITE_PEN
);
4624 dc
.DrawLine( 0, rowTop
, 0, rowBottom
);
4625 dc
.DrawLine( 0, rowTop
, m_rowLabelWidth
-1, rowTop
);
4627 dc
.SetBackgroundMode( wxTRANSPARENT
);
4628 dc
.SetTextForeground( GetLabelTextColour() );
4629 dc
.SetFont( GetLabelFont() );
4632 GetRowLabelAlignment( &hAlign
, &vAlign
);
4636 rect
.SetY( GetRowTop(row
) + 2 );
4637 rect
.SetWidth( m_rowLabelWidth
- 4 );
4638 rect
.SetHeight( GetRowHeight(row
) - 4 );
4639 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
4643 void wxGrid::DrawColLabels( wxDC
& dc
)
4645 if ( !m_numRows
|| !m_numCols
) return;
4648 size_t numLabels
= m_colLabelsExposed
.GetCount();
4650 for ( i
= 0; i
< numLabels
; i
++ )
4652 DrawColLabel( dc
, m_colLabelsExposed
[i
] );
4657 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
4659 if ( GetColWidth(col
) <= 0 )
4662 int colLeft
= GetColLeft(col
),
4663 colRight
= GetColRight(col
) - 1;
4665 dc
.SetPen( *wxBLACK_PEN
);
4666 dc
.DrawLine( colRight
, 0,
4667 colRight
, m_colLabelHeight
-1 );
4669 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
4670 colRight
, m_colLabelHeight
-1 );
4672 dc
.SetPen( *wxWHITE_PEN
);
4673 dc
.DrawLine( colLeft
, 0, colLeft
, m_colLabelHeight
-1 );
4674 dc
.DrawLine( colLeft
, 0, colRight
, 0 );
4676 dc
.SetBackgroundMode( wxTRANSPARENT
);
4677 dc
.SetTextForeground( GetLabelTextColour() );
4678 dc
.SetFont( GetLabelFont() );
4680 dc
.SetBackgroundMode( wxTRANSPARENT
);
4681 dc
.SetTextForeground( GetLabelTextColour() );
4682 dc
.SetFont( GetLabelFont() );
4685 GetColLabelAlignment( &hAlign
, &vAlign
);
4688 rect
.SetX( colLeft
+ 2 );
4690 rect
.SetWidth( GetColWidth(col
) - 4 );
4691 rect
.SetHeight( m_colLabelHeight
- 4 );
4692 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
);
4696 void wxGrid::DrawTextRectangle( wxDC
& dc
,
4697 const wxString
& value
,
4702 long textWidth
, textHeight
;
4703 long lineWidth
, lineHeight
;
4704 wxArrayString lines
;
4706 dc
.SetClippingRegion( rect
);
4707 StringToLines( value
, lines
);
4708 if ( lines
.GetCount() )
4710 GetTextBoxSize( dc
, lines
, &textWidth
, &textHeight
);
4711 dc
.GetTextExtent( lines
[0], &lineWidth
, &lineHeight
);
4714 switch ( horizAlign
)
4717 x
= rect
.x
+ (rect
.width
- textWidth
- 1);
4721 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
4730 switch ( vertAlign
)
4733 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
4737 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
4746 for ( size_t i
= 0; i
< lines
.GetCount(); i
++ )
4748 dc
.DrawText( lines
[i
], (long)x
, (long)y
);
4753 dc
.DestroyClippingRegion();
4757 // Split multi line text up into an array of strings. Any existing
4758 // contents of the string array are preserved.
4760 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
4764 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
4765 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
4767 while ( startPos
< (int)tVal
.Length() )
4769 pos
= tVal
.Mid(startPos
).Find( eol
);
4774 else if ( pos
== 0 )
4776 lines
.Add( wxEmptyString
);
4780 lines
.Add( value
.Mid(startPos
, pos
) );
4784 if ( startPos
< (int)value
.Length() )
4786 lines
.Add( value
.Mid( startPos
) );
4791 void wxGrid::GetTextBoxSize( wxDC
& dc
,
4792 wxArrayString
& lines
,
4793 long *width
, long *height
)
4800 for ( i
= 0; i
< lines
.GetCount(); i
++ )
4802 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
4803 w
= wxMax( w
, lineW
);
4813 // ------ Edit control functions
4817 void wxGrid::EnableEditing( bool edit
)
4819 // TODO: improve this ?
4821 if ( edit
!= m_editable
)
4825 // FIXME IMHO this won't disable the edit control if edit == FALSE
4826 // because of the check in the beginning of
4827 // EnableCellEditControl() just below (VZ)
4828 EnableCellEditControl(m_editable
);
4833 void wxGrid::EnableCellEditControl( bool enable
)
4838 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4839 SetCurrentCell( 0, 0 );
4841 if ( enable
!= m_cellEditCtrlEnabled
)
4843 // TODO allow the app to Veto() this event?
4844 SendEvent(enable
? wxEVT_GRID_EDITOR_SHOWN
: wxEVT_GRID_EDITOR_HIDDEN
);
4848 // this should be checked by the caller!
4849 wxASSERT_MSG( CanEnableCellControl(),
4850 _T("can't enable editing for this cell!") );
4852 // do it before ShowCellEditControl()
4853 m_cellEditCtrlEnabled
= enable
;
4855 SetEditControlValue();
4856 ShowCellEditControl();
4860 HideCellEditControl();
4861 SaveEditControlValue();
4863 // do it after HideCellEditControl()
4864 m_cellEditCtrlEnabled
= enable
;
4869 bool wxGrid::IsCurrentCellReadOnly() const
4872 wxGridCellAttr
* attr
= ((wxGrid
*)this)->GetCellAttr(m_currentCellCoords
);
4873 bool readonly
= attr
->IsReadOnly();
4879 bool wxGrid::CanEnableCellControl() const
4881 return m_editable
&& !IsCurrentCellReadOnly();
4884 bool wxGrid::IsCellEditControlEnabled() const
4886 // the cell edit control might be disable for all cells or just for the
4887 // current one if it's read only
4888 return m_cellEditCtrlEnabled
? !IsCurrentCellReadOnly() : FALSE
;
4891 void wxGrid::ShowCellEditControl()
4893 if ( IsCellEditControlEnabled() )
4895 if ( !IsVisible( m_currentCellCoords
) )
4901 wxRect rect
= CellToRect( m_currentCellCoords
);
4902 int row
= m_currentCellCoords
.GetRow();
4903 int col
= m_currentCellCoords
.GetCol();
4905 // convert to scrolled coords
4907 CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
4909 // done in PaintBackground()
4911 // erase the highlight and the cell contents because the editor
4912 // might not cover the entire cell
4913 wxClientDC
dc( m_gridWin
);
4915 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
); //wxBrush(attr->GetBackgroundColour(), wxSOLID));
4916 dc
.SetPen(*wxTRANSPARENT_PEN
);
4917 dc
.DrawRectangle(rect
);
4920 // cell is shifted by one pixel
4924 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4925 wxGridCellEditor
* editor
= attr
->GetEditor(GetDefaultEditorForCell(row
, col
));
4926 if ( !editor
->IsCreated() )
4928 editor
->Create(m_gridWin
, -1,
4929 new wxGridCellEditorEvtHandler(this, editor
));
4932 editor
->SetSize( rect
);
4934 editor
->Show( TRUE
, attr
);
4935 editor
->BeginEdit(row
, col
, this);
4942 void wxGrid::HideCellEditControl()
4944 if ( IsCellEditControlEnabled() )
4946 int row
= m_currentCellCoords
.GetRow();
4947 int col
= m_currentCellCoords
.GetCol();
4949 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4950 attr
->GetEditor(GetDefaultEditorForCell(row
, col
))->Show( FALSE
);
4952 m_gridWin
->SetFocus();
4957 void wxGrid::SetEditControlValue( const wxString
& value
)
4959 // RD: The new Editors get the value from the table themselves now. This
4960 // method can probably be removed...
4964 void wxGrid::SaveEditControlValue()
4966 if ( IsCellEditControlEnabled() )
4968 int row
= m_currentCellCoords
.GetRow();
4969 int col
= m_currentCellCoords
.GetCol();
4971 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4972 wxGridCellEditor
* editor
= attr
->GetEditor(GetDefaultEditorForCell(row
, col
));
4973 bool changed
= editor
->EndEdit(row
, col
, TRUE
, this);
4979 SendEvent( wxEVT_GRID_CELL_CHANGE
,
4980 m_currentCellCoords
.GetRow(),
4981 m_currentCellCoords
.GetCol() );
4988 // ------ Grid location functions
4989 // Note that all of these functions work with the logical coordinates of
4990 // grid cells and labels so you will need to convert from device
4991 // coordinates for mouse events etc.
4994 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
4996 int row
= YToRow(y
);
4997 int col
= XToCol(x
);
4999 if ( row
== -1 || col
== -1 )
5001 coords
= wxGridNoCellCoords
;
5005 coords
.Set( row
, col
);
5010 int wxGrid::YToRow( int y
)
5014 for ( i
= 0; i
< m_numRows
; i
++ )
5016 if ( y
< GetRowBottom(i
) )
5020 return m_numRows
; //-1;
5024 int wxGrid::XToCol( int x
)
5028 for ( i
= 0; i
< m_numCols
; i
++ )
5030 if ( x
< GetColRight(i
) )
5034 return m_numCols
; //-1;
5038 // return the row number that that the y coord is near the edge of, or
5039 // -1 if not near an edge
5041 int wxGrid::YToEdgeOfRow( int y
)
5045 for ( i
= 0; i
< m_numRows
; i
++ )
5047 if ( GetRowHeight(i
) > WXGRID_LABEL_EDGE_ZONE
)
5049 d
= abs( y
- GetRowBottom(i
) );
5050 if ( d
< WXGRID_LABEL_EDGE_ZONE
)
5059 // return the col number that that the x coord is near the edge of, or
5060 // -1 if not near an edge
5062 int wxGrid::XToEdgeOfCol( int x
)
5066 for ( i
= 0; i
< m_numCols
; i
++ )
5068 if ( GetColWidth(i
) > WXGRID_LABEL_EDGE_ZONE
)
5070 d
= abs( x
- GetColRight(i
) );
5071 if ( d
< WXGRID_LABEL_EDGE_ZONE
)
5080 wxRect
wxGrid::CellToRect( int row
, int col
)
5082 wxRect
rect( -1, -1, -1, -1 );
5084 if ( row
>= 0 && row
< m_numRows
&&
5085 col
>= 0 && col
< m_numCols
)
5087 rect
.x
= GetColLeft(col
);
5088 rect
.y
= GetRowTop(row
);
5089 rect
.width
= GetColWidth(col
);
5090 rect
.height
= GetRowHeight(row
);
5097 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
5099 // get the cell rectangle in logical coords
5101 wxRect
r( CellToRect( row
, col
) );
5103 // convert to device coords
5105 int left
, top
, right
, bottom
;
5106 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
5107 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
5109 // check against the client area of the grid window
5112 m_gridWin
->GetClientSize( &cw
, &ch
);
5114 if ( wholeCellVisible
)
5116 // is the cell wholly visible ?
5118 return ( left
>= 0 && right
<= cw
&&
5119 top
>= 0 && bottom
<= ch
);
5123 // is the cell partly visible ?
5125 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
5126 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
5131 // make the specified cell location visible by doing a minimal amount
5134 void wxGrid::MakeCellVisible( int row
, int col
)
5137 int xpos
= -1, ypos
= -1;
5139 if ( row
>= 0 && row
< m_numRows
&&
5140 col
>= 0 && col
< m_numCols
)
5142 // get the cell rectangle in logical coords
5144 wxRect
r( CellToRect( row
, col
) );
5146 // convert to device coords
5148 int left
, top
, right
, bottom
;
5149 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
5150 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
5153 m_gridWin
->GetClientSize( &cw
, &ch
);
5159 else if ( bottom
> ch
)
5161 int h
= r
.GetHeight();
5163 for ( i
= row
-1; i
>= 0; i
-- )
5165 int rowHeight
= GetRowHeight(i
);
5166 if ( h
+ rowHeight
> ch
)
5173 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
5174 // have rounding errors (this is important, because if we do, we
5175 // might not scroll at all and some cells won't be redrawn)
5176 ypos
+= GRID_SCROLL_LINE
/ 2;
5183 else if ( right
> cw
)
5185 int w
= r
.GetWidth();
5187 for ( i
= col
-1; i
>= 0; i
-- )
5189 int colWidth
= GetColWidth(i
);
5190 if ( w
+ colWidth
> cw
)
5197 // see comment for ypos above
5198 xpos
+= GRID_SCROLL_LINE
/ 2;
5201 if ( xpos
!= -1 || ypos
!= -1 )
5203 if ( xpos
!= -1 ) xpos
/= GRID_SCROLL_LINE
;
5204 if ( ypos
!= -1 ) ypos
/= GRID_SCROLL_LINE
;
5205 Scroll( xpos
, ypos
);
5213 // ------ Grid cursor movement functions
5216 bool wxGrid::MoveCursorUp()
5218 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
5219 m_currentCellCoords
.GetRow() > 0 )
5221 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
5222 m_currentCellCoords
.GetCol() );
5224 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
5225 m_currentCellCoords
.GetCol() );
5234 bool wxGrid::MoveCursorDown()
5236 // TODO: allow for scrolling
5238 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
5239 m_currentCellCoords
.GetRow() < m_numRows
-1 )
5241 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
5242 m_currentCellCoords
.GetCol() );
5244 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
5245 m_currentCellCoords
.GetCol() );
5254 bool wxGrid::MoveCursorLeft()
5256 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
5257 m_currentCellCoords
.GetCol() > 0 )
5259 MakeCellVisible( m_currentCellCoords
.GetRow(),
5260 m_currentCellCoords
.GetCol() - 1 );
5262 SetCurrentCell( m_currentCellCoords
.GetRow(),
5263 m_currentCellCoords
.GetCol() - 1 );
5272 bool wxGrid::MoveCursorRight()
5274 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
5275 m_currentCellCoords
.GetCol() < m_numCols
- 1 )
5277 MakeCellVisible( m_currentCellCoords
.GetRow(),
5278 m_currentCellCoords
.GetCol() + 1 );
5280 SetCurrentCell( m_currentCellCoords
.GetRow(),
5281 m_currentCellCoords
.GetCol() + 1 );
5290 bool wxGrid::MovePageUp()
5292 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
5294 int row
= m_currentCellCoords
.GetRow();
5298 m_gridWin
->GetClientSize( &cw
, &ch
);
5300 int y
= GetRowTop(row
);
5301 int newRow
= YToRow( y
- ch
+ 1 );
5306 else if ( newRow
== row
)
5311 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
5312 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
5320 bool wxGrid::MovePageDown()
5322 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
5324 int row
= m_currentCellCoords
.GetRow();
5325 if ( row
< m_numRows
)
5328 m_gridWin
->GetClientSize( &cw
, &ch
);
5330 int y
= GetRowTop(row
);
5331 int newRow
= YToRow( y
+ ch
);
5334 newRow
= m_numRows
- 1;
5336 else if ( newRow
== row
)
5341 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
5342 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
5350 bool wxGrid::MoveCursorUpBlock()
5353 m_currentCellCoords
!= wxGridNoCellCoords
&&
5354 m_currentCellCoords
.GetRow() > 0 )
5356 int row
= m_currentCellCoords
.GetRow();
5357 int col
= m_currentCellCoords
.GetCol();
5359 if ( m_table
->IsEmptyCell(row
, col
) )
5361 // starting in an empty cell: find the next block of
5367 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5370 else if ( m_table
->IsEmptyCell(row
-1, col
) )
5372 // starting at the top of a block: find the next block
5378 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5383 // starting within a block: find the top of the block
5388 if ( m_table
->IsEmptyCell(row
, col
) )
5396 MakeCellVisible( row
, col
);
5397 SetCurrentCell( row
, col
);
5405 bool wxGrid::MoveCursorDownBlock()
5408 m_currentCellCoords
!= wxGridNoCellCoords
&&
5409 m_currentCellCoords
.GetRow() < m_numRows
-1 )
5411 int row
= m_currentCellCoords
.GetRow();
5412 int col
= m_currentCellCoords
.GetCol();
5414 if ( m_table
->IsEmptyCell(row
, col
) )
5416 // starting in an empty cell: find the next block of
5419 while ( row
< m_numRows
-1 )
5422 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5425 else if ( m_table
->IsEmptyCell(row
+1, col
) )
5427 // starting at the bottom of a block: find the next block
5430 while ( row
< m_numRows
-1 )
5433 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5438 // starting within a block: find the bottom of the block
5440 while ( row
< m_numRows
-1 )
5443 if ( m_table
->IsEmptyCell(row
, col
) )
5451 MakeCellVisible( row
, col
);
5452 SetCurrentCell( row
, col
);
5460 bool wxGrid::MoveCursorLeftBlock()
5463 m_currentCellCoords
!= wxGridNoCellCoords
&&
5464 m_currentCellCoords
.GetCol() > 0 )
5466 int row
= m_currentCellCoords
.GetRow();
5467 int col
= m_currentCellCoords
.GetCol();
5469 if ( m_table
->IsEmptyCell(row
, col
) )
5471 // starting in an empty cell: find the next block of
5477 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5480 else if ( m_table
->IsEmptyCell(row
, col
-1) )
5482 // starting at the left of a block: find the next block
5488 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5493 // starting within a block: find the left of the block
5498 if ( m_table
->IsEmptyCell(row
, col
) )
5506 MakeCellVisible( row
, col
);
5507 SetCurrentCell( row
, col
);
5515 bool wxGrid::MoveCursorRightBlock()
5518 m_currentCellCoords
!= wxGridNoCellCoords
&&
5519 m_currentCellCoords
.GetCol() < m_numCols
-1 )
5521 int row
= m_currentCellCoords
.GetRow();
5522 int col
= m_currentCellCoords
.GetCol();
5524 if ( m_table
->IsEmptyCell(row
, col
) )
5526 // starting in an empty cell: find the next block of
5529 while ( col
< m_numCols
-1 )
5532 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5535 else if ( m_table
->IsEmptyCell(row
, col
+1) )
5537 // starting at the right of a block: find the next block
5540 while ( col
< m_numCols
-1 )
5543 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5548 // starting within a block: find the right of the block
5550 while ( col
< m_numCols
-1 )
5553 if ( m_table
->IsEmptyCell(row
, col
) )
5561 MakeCellVisible( row
, col
);
5562 SetCurrentCell( row
, col
);
5573 // ------ Label values and formatting
5576 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
5578 *horiz
= m_rowLabelHorizAlign
;
5579 *vert
= m_rowLabelVertAlign
;
5582 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
5584 *horiz
= m_colLabelHorizAlign
;
5585 *vert
= m_colLabelVertAlign
;
5588 wxString
wxGrid::GetRowLabelValue( int row
)
5592 return m_table
->GetRowLabelValue( row
);
5602 wxString
wxGrid::GetColLabelValue( int col
)
5606 return m_table
->GetColLabelValue( col
);
5617 void wxGrid::SetRowLabelSize( int width
)
5619 width
= wxMax( width
, 0 );
5620 if ( width
!= m_rowLabelWidth
)
5624 m_rowLabelWin
->Show( FALSE
);
5625 m_cornerLabelWin
->Show( FALSE
);
5627 else if ( m_rowLabelWidth
== 0 )
5629 m_rowLabelWin
->Show( TRUE
);
5630 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
5633 m_rowLabelWidth
= width
;
5640 void wxGrid::SetColLabelSize( int height
)
5642 height
= wxMax( height
, 0 );
5643 if ( height
!= m_colLabelHeight
)
5647 m_colLabelWin
->Show( FALSE
);
5648 m_cornerLabelWin
->Show( FALSE
);
5650 else if ( m_colLabelHeight
== 0 )
5652 m_colLabelWin
->Show( TRUE
);
5653 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
5656 m_colLabelHeight
= height
;
5663 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
5665 if ( m_labelBackgroundColour
!= colour
)
5667 m_labelBackgroundColour
= colour
;
5668 m_rowLabelWin
->SetBackgroundColour( colour
);
5669 m_colLabelWin
->SetBackgroundColour( colour
);
5670 m_cornerLabelWin
->SetBackgroundColour( colour
);
5672 if ( !GetBatchCount() )
5674 m_rowLabelWin
->Refresh();
5675 m_colLabelWin
->Refresh();
5676 m_cornerLabelWin
->Refresh();
5681 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
5683 if ( m_labelTextColour
!= colour
)
5685 m_labelTextColour
= colour
;
5686 if ( !GetBatchCount() )
5688 m_rowLabelWin
->Refresh();
5689 m_colLabelWin
->Refresh();
5694 void wxGrid::SetLabelFont( const wxFont
& font
)
5697 if ( !GetBatchCount() )
5699 m_rowLabelWin
->Refresh();
5700 m_colLabelWin
->Refresh();
5704 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
5706 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
5708 m_rowLabelHorizAlign
= horiz
;
5711 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
5713 m_rowLabelVertAlign
= vert
;
5716 if ( !GetBatchCount() )
5718 m_rowLabelWin
->Refresh();
5722 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
5724 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
5726 m_colLabelHorizAlign
= horiz
;
5729 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
5731 m_colLabelVertAlign
= vert
;
5734 if ( !GetBatchCount() )
5736 m_colLabelWin
->Refresh();
5740 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
5744 m_table
->SetRowLabelValue( row
, s
);
5745 if ( !GetBatchCount() )
5747 wxRect rect
= CellToRect( row
, 0);
5748 if ( rect
.height
> 0 )
5750 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
5752 rect
.width
= m_rowLabelWidth
;
5753 m_rowLabelWin
->Refresh( TRUE
, &rect
);
5759 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
5763 m_table
->SetColLabelValue( col
, s
);
5764 if ( !GetBatchCount() )
5766 wxRect rect
= CellToRect( 0, col
);
5767 if ( rect
.width
> 0 )
5769 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
5771 rect
.height
= m_colLabelHeight
;
5772 m_colLabelWin
->Refresh( TRUE
, &rect
);
5778 void wxGrid::SetGridLineColour( const wxColour
& colour
)
5780 if ( m_gridLineColour
!= colour
)
5782 m_gridLineColour
= colour
;
5784 wxClientDC
dc( m_gridWin
);
5786 DrawAllGridLines( dc
, wxRegion() );
5790 void wxGrid::EnableGridLines( bool enable
)
5792 if ( enable
!= m_gridLinesEnabled
)
5794 m_gridLinesEnabled
= enable
;
5796 if ( !GetBatchCount() )
5800 wxClientDC
dc( m_gridWin
);
5802 DrawAllGridLines( dc
, wxRegion() );
5806 m_gridWin
->Refresh();
5813 int wxGrid::GetDefaultRowSize()
5815 return m_defaultRowHeight
;
5818 int wxGrid::GetRowSize( int row
)
5820 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
5822 return GetRowHeight(row
);
5825 int wxGrid::GetDefaultColSize()
5827 return m_defaultColWidth
;
5830 int wxGrid::GetColSize( int col
)
5832 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
5834 return GetColWidth(col
);
5837 // ============================================================================
5838 // access to the grid attributes: each of them has a default value in the grid
5839 // itself and may be overidden on a per-cell basis
5840 // ============================================================================
5842 // ----------------------------------------------------------------------------
5843 // setting default attributes
5844 // ----------------------------------------------------------------------------
5846 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
5848 m_defaultCellAttr
->SetBackgroundColour(col
);
5850 m_gridWin
->SetBackgroundColour(col
);
5854 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
5856 m_defaultCellAttr
->SetTextColour(col
);
5859 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
5861 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
5864 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
5866 m_defaultCellAttr
->SetFont(font
);
5869 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
5871 m_defaultCellAttr
->SetRenderer(renderer
);
5874 void wxGrid::SetDefaultEditor(wxGridCellEditor
*editor
)
5876 m_defaultCellAttr
->SetEditor(editor
);
5879 // ----------------------------------------------------------------------------
5880 // access to the default attrbiutes
5881 // ----------------------------------------------------------------------------
5883 wxColour
wxGrid::GetDefaultCellBackgroundColour()
5885 return m_defaultCellAttr
->GetBackgroundColour();
5888 wxColour
wxGrid::GetDefaultCellTextColour()
5890 return m_defaultCellAttr
->GetTextColour();
5893 wxFont
wxGrid::GetDefaultCellFont()
5895 return m_defaultCellAttr
->GetFont();
5898 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
5900 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
5903 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
5905 return m_defaultCellAttr
->GetRenderer(NULL
);
5908 wxGridCellEditor
*wxGrid::GetDefaultEditor() const
5910 return m_defaultCellAttr
->GetEditor(NULL
);
5913 // ----------------------------------------------------------------------------
5914 // access to cell attributes
5915 // ----------------------------------------------------------------------------
5917 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
5919 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5920 wxColour colour
= attr
->GetBackgroundColour();
5925 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
5927 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5928 wxColour colour
= attr
->GetTextColour();
5933 wxFont
wxGrid::GetCellFont( int row
, int col
)
5935 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5936 wxFont font
= attr
->GetFont();
5941 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
5943 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5944 attr
->GetAlignment(horiz
, vert
);
5948 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
)
5950 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5951 wxGridCellRenderer
* renderer
= attr
->GetRenderer(GetDefaultRendererForCell(row
,col
));
5956 wxGridCellEditor
* wxGrid::GetCellEditor(int row
, int col
)
5958 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5959 wxGridCellEditor
* editor
= attr
->GetEditor(GetDefaultEditorForCell(row
, col
));
5964 bool wxGrid::IsReadOnly(int row
, int col
) const
5966 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5967 bool isReadOnly
= attr
->IsReadOnly();
5972 // ----------------------------------------------------------------------------
5973 // attribute support: cache, automatic provider creation, ...
5974 // ----------------------------------------------------------------------------
5976 bool wxGrid::CanHaveAttributes()
5983 return m_table
->CanHaveAttributes();
5986 void wxGrid::ClearAttrCache()
5988 if ( m_attrCache
.row
!= -1 )
5990 m_attrCache
.attr
->SafeDecRef();
5991 m_attrCache
.row
= -1;
5995 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
5997 wxGrid
*self
= (wxGrid
*)this; // const_cast
5999 self
->ClearAttrCache();
6000 self
->m_attrCache
.row
= row
;
6001 self
->m_attrCache
.col
= col
;
6002 self
->m_attrCache
.attr
= attr
;
6006 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
6008 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
6010 *attr
= m_attrCache
.attr
;
6011 (*attr
)->SafeIncRef();
6013 #ifdef DEBUG_ATTR_CACHE
6014 gs_nAttrCacheHits
++;
6021 #ifdef DEBUG_ATTR_CACHE
6022 gs_nAttrCacheMisses
++;
6028 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
6030 wxGridCellAttr
*attr
;
6031 if ( !LookupAttr(row
, col
, &attr
) )
6033 attr
= m_table
? m_table
->GetAttr(row
, col
) : (wxGridCellAttr
*)NULL
;
6034 CacheAttr(row
, col
, attr
);
6038 attr
->SetDefAttr(m_defaultCellAttr
);
6042 attr
= m_defaultCellAttr
;
6049 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
6051 wxGridCellAttr
*attr
;
6052 if ( !LookupAttr(row
, col
, &attr
) || !attr
)
6054 wxASSERT_MSG( m_table
,
6055 _T("we may only be called if CanHaveAttributes() "
6056 "returned TRUE and then m_table should be !NULL") );
6058 attr
= m_table
->GetAttr(row
, col
);
6061 attr
= new wxGridCellAttr
;
6063 // artificially inc the ref count to match DecRef() in caller
6066 m_table
->SetAttr(attr
, row
, col
);
6069 CacheAttr(row
, col
, attr
);
6071 attr
->SetDefAttr(m_defaultCellAttr
);
6075 // ----------------------------------------------------------------------------
6076 // setting cell attributes: this is forwarded to the table
6077 // ----------------------------------------------------------------------------
6079 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
6081 if ( CanHaveAttributes() )
6083 m_table
->SetRowAttr(attr
, row
);
6091 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
6093 if ( CanHaveAttributes() )
6095 m_table
->SetColAttr(attr
, col
);
6103 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
6105 if ( CanHaveAttributes() )
6107 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6108 attr
->SetBackgroundColour(colour
);
6113 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
6115 if ( CanHaveAttributes() )
6117 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6118 attr
->SetTextColour(colour
);
6123 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
6125 if ( CanHaveAttributes() )
6127 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6128 attr
->SetFont(font
);
6133 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
6135 if ( CanHaveAttributes() )
6137 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6138 attr
->SetAlignment(horiz
, vert
);
6143 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
6145 if ( CanHaveAttributes() )
6147 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6148 attr
->SetRenderer(renderer
);
6153 void wxGrid::SetCellEditor(int row
, int col
, wxGridCellEditor
* editor
)
6155 if ( CanHaveAttributes() )
6157 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6158 attr
->SetEditor(editor
);
6163 void wxGrid::SetReadOnly(int row
, int col
, bool isReadOnly
)
6165 if ( CanHaveAttributes() )
6167 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6168 attr
->SetReadOnly(isReadOnly
);
6173 // ----------------------------------------------------------------------------
6174 // Data type registration
6175 // ----------------------------------------------------------------------------
6177 void wxGrid::RegisterDataType(const wxString
& typeName
,
6178 wxGridCellRenderer
* renderer
,
6179 wxGridCellEditor
* editor
)
6181 m_typeRegistry
->RegisterDataType(typeName
, renderer
, editor
);
6185 wxGridCellEditor
* wxGrid::GetDefaultEditorForCell(int row
, int col
) const
6187 wxString typeName
= m_table
->GetTypeName(row
, col
);
6188 return GetDefaultEditorForType(typeName
);
6191 wxGridCellRenderer
* wxGrid::GetDefaultRendererForCell(int row
, int col
) const
6193 wxString typeName
= m_table
->GetTypeName(row
, col
);
6194 return GetDefaultRendererForType(typeName
);
6198 wxGrid::GetDefaultEditorForType(const wxString
& typeName
) const
6200 int index
= m_typeRegistry
->FindDataType(typeName
);
6202 // Should we force the failure here or let it fallback to string handling???
6203 // wxFAIL_MSG(wxT("Unknown data type name"));
6206 return m_typeRegistry
->GetEditor(index
);
6210 wxGrid::GetDefaultRendererForType(const wxString
& typeName
) const
6212 int index
= m_typeRegistry
->FindDataType(typeName
);
6214 // Should we force the failure here or let it fallback to string handling???
6215 // wxFAIL_MSG(wxT("Unknown data type name"));
6218 return m_typeRegistry
->GetRenderer(index
);
6222 // ----------------------------------------------------------------------------
6224 // ----------------------------------------------------------------------------
6226 void wxGrid::EnableDragRowSize( bool enable
)
6228 m_canDragRowSize
= enable
;
6232 void wxGrid::EnableDragColSize( bool enable
)
6234 m_canDragColSize
= enable
;
6238 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
6240 m_defaultRowHeight
= wxMax( height
, WXGRID_MIN_ROW_HEIGHT
);
6242 if ( resizeExistingRows
)
6250 void wxGrid::SetRowSize( int row
, int height
)
6252 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
6254 if ( m_rowHeights
.IsEmpty() )
6256 // need to really create the array
6260 int h
= wxMax( 0, height
);
6261 int diff
= h
- m_rowHeights
[row
];
6263 m_rowHeights
[row
] = h
;
6265 for ( i
= row
; i
< m_numRows
; i
++ )
6267 m_rowBottoms
[i
] += diff
;
6272 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
6274 m_defaultColWidth
= wxMax( width
, WXGRID_MIN_COL_WIDTH
);
6276 if ( resizeExistingCols
)
6284 void wxGrid::SetColSize( int col
, int width
)
6286 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
6288 // should we check that it's bigger than GetColMinimalWidth(col) here?
6290 if ( m_colWidths
.IsEmpty() )
6292 // need to really create the array
6296 int w
= wxMax( 0, width
);
6297 int diff
= w
- m_colWidths
[col
];
6298 m_colWidths
[col
] = w
;
6301 for ( i
= col
; i
< m_numCols
; i
++ )
6303 m_colRights
[i
] += diff
;
6309 void wxGrid::SetColMinimalWidth( int col
, int width
)
6311 m_colMinWidths
.Put(col
, (wxObject
*)width
);
6314 int wxGrid::GetColMinimalWidth(int col
) const
6316 wxObject
*obj
= m_colMinWidths
.Get(m_dragRowOrCol
);
6317 return obj
? (int)obj
: WXGRID_MIN_COL_WIDTH
;
6321 // ------ cell value accessor functions
6324 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
6328 m_table
->SetValue( row
, col
, s
.c_str() );
6329 if ( !GetBatchCount() )
6331 wxClientDC
dc( m_gridWin
);
6333 DrawCell( dc
, wxGridCellCoords(row
, col
) );
6336 #if 0 // TODO: edit in place
6338 if ( m_currentCellCoords
.GetRow() == row
&&
6339 m_currentCellCoords
.GetCol() == col
)
6341 SetEditControlValue( s
);
6350 // ------ Block, row and col selection
6353 void wxGrid::SelectRow( int row
, bool addToSelected
)
6357 if ( IsSelection() && addToSelected
)
6360 bool need_refresh
[4];
6364 need_refresh
[3] = FALSE
;
6368 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
6369 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
6370 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
6371 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
6375 need_refresh
[0] = TRUE
;
6376 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( row
, 0 ),
6377 wxGridCellCoords ( oldTop
- 1,
6379 m_selectedTopLeft
.SetRow( row
);
6384 need_refresh
[1] = TRUE
;
6385 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
, 0 ),
6386 wxGridCellCoords ( oldBottom
,
6389 m_selectedTopLeft
.SetCol( 0 );
6392 if ( oldBottom
< row
)
6394 need_refresh
[2] = TRUE
;
6395 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1, 0 ),
6396 wxGridCellCoords ( row
,
6398 m_selectedBottomRight
.SetRow( row
);
6401 if ( oldRight
< m_numCols
- 1 )
6403 need_refresh
[3] = TRUE
;
6404 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6406 wxGridCellCoords ( oldBottom
,
6408 m_selectedBottomRight
.SetCol( m_numCols
- 1 );
6411 for (i
= 0; i
< 4; i
++ )
6412 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
6413 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
6417 r
= SelectionToDeviceRect();
6419 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
6421 m_selectedTopLeft
.Set( row
, 0 );
6422 m_selectedBottomRight
.Set( row
, m_numCols
-1 );
6423 r
= SelectionToDeviceRect();
6424 m_gridWin
->Refresh( FALSE
, &r
);
6427 wxGridRangeSelectEvent
gridEvt( GetId(),
6428 wxEVT_GRID_RANGE_SELECT
,
6431 m_selectedBottomRight
);
6433 GetEventHandler()->ProcessEvent(gridEvt
);
6437 void wxGrid::SelectCol( int col
, bool addToSelected
)
6439 if ( IsSelection() && addToSelected
)
6442 bool need_refresh
[4];
6446 need_refresh
[3] = FALSE
;
6449 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
6450 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
6451 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
6452 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
6454 if ( oldLeft
> col
)
6456 need_refresh
[0] = TRUE
;
6457 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( 0, col
),
6458 wxGridCellCoords ( m_numRows
- 1,
6460 m_selectedTopLeft
.SetCol( col
);
6465 need_refresh
[1] = TRUE
;
6466 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( 0, oldLeft
),
6467 wxGridCellCoords ( oldTop
- 1,
6469 m_selectedTopLeft
.SetRow( 0 );
6472 if ( oldRight
< col
)
6474 need_refresh
[2] = TRUE
;
6475 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( 0, oldRight
+ 1 ),
6476 wxGridCellCoords ( m_numRows
- 1,
6478 m_selectedBottomRight
.SetCol( col
);
6481 if ( oldBottom
< m_numRows
- 1 )
6483 need_refresh
[3] = TRUE
;
6484 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1,
6486 wxGridCellCoords ( m_numRows
- 1,
6488 m_selectedBottomRight
.SetRow( m_numRows
- 1 );
6491 for (i
= 0; i
< 4; i
++ )
6492 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
6493 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
6499 r
= SelectionToDeviceRect();
6501 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
6503 m_selectedTopLeft
.Set( 0, col
);
6504 m_selectedBottomRight
.Set( m_numRows
-1, col
);
6505 r
= SelectionToDeviceRect();
6506 m_gridWin
->Refresh( FALSE
, &r
);
6509 wxGridRangeSelectEvent
gridEvt( GetId(),
6510 wxEVT_GRID_RANGE_SELECT
,
6513 m_selectedBottomRight
);
6515 GetEventHandler()->ProcessEvent(gridEvt
);
6519 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
6522 wxGridCellCoords updateTopLeft
, updateBottomRight
;
6524 if ( topRow
> bottomRow
)
6531 if ( leftCol
> rightCol
)
6538 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
6539 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
6541 if ( m_selectedTopLeft
!= updateTopLeft
||
6542 m_selectedBottomRight
!= updateBottomRight
)
6544 // Compute two optimal update rectangles:
6545 // Either one rectangle is a real subset of the
6546 // other, or they are (almost) disjoint!
6548 bool need_refresh
[4];
6552 need_refresh
[3] = FALSE
;
6555 // Store intermediate values
6556 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
6557 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
6558 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
6559 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
6561 // Determine the outer/inner coordinates.
6562 if (oldLeft
> leftCol
)
6568 if (oldTop
> topRow
)
6574 if (oldRight
< rightCol
)
6577 oldRight
= rightCol
;
6580 if (oldBottom
< bottomRow
)
6583 oldBottom
= bottomRow
;
6587 // Now, either the stuff marked old is the outer
6588 // rectangle or we don't have a situation where one
6589 // is contained in the other.
6591 if ( oldLeft
< leftCol
)
6593 need_refresh
[0] = TRUE
;
6594 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6596 wxGridCellCoords ( oldBottom
,
6600 if ( oldTop
< topRow
)
6602 need_refresh
[1] = TRUE
;
6603 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6605 wxGridCellCoords ( topRow
- 1,
6609 if ( oldRight
> rightCol
)
6611 need_refresh
[2] = TRUE
;
6612 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6614 wxGridCellCoords ( oldBottom
,
6618 if ( oldBottom
> bottomRow
)
6620 need_refresh
[3] = TRUE
;
6621 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
6623 wxGridCellCoords ( oldBottom
,
6629 m_selectedTopLeft
= updateTopLeft
;
6630 m_selectedBottomRight
= updateBottomRight
;
6632 // various Refresh() calls
6633 for (i
= 0; i
< 4; i
++ )
6634 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
6635 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
6638 // only generate an event if the block is not being selected by
6639 // dragging the mouse (in which case the event will be generated in
6640 // the mouse event handler)
6641 if ( !m_isDragging
)
6643 wxGridRangeSelectEvent
gridEvt( GetId(),
6644 wxEVT_GRID_RANGE_SELECT
,
6647 m_selectedBottomRight
);
6649 GetEventHandler()->ProcessEvent(gridEvt
);
6653 void wxGrid::SelectAll()
6655 m_selectedTopLeft
.Set( 0, 0 );
6656 m_selectedBottomRight
.Set( m_numRows
-1, m_numCols
-1 );
6658 m_gridWin
->Refresh();
6662 void wxGrid::ClearSelection()
6664 m_selectedTopLeft
= wxGridNoCellCoords
;
6665 m_selectedBottomRight
= wxGridNoCellCoords
;
6669 // This function returns the rectangle that encloses the given block
6670 // in device coords clipped to the client size of the grid window.
6672 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
6673 const wxGridCellCoords
&bottomRight
)
6675 wxRect
rect( wxGridNoCellRect
);
6678 cellRect
= CellToRect( topLeft
);
6679 if ( cellRect
!= wxGridNoCellRect
)
6685 rect
= wxRect( 0, 0, 0, 0 );
6688 cellRect
= CellToRect( bottomRight
);
6689 if ( cellRect
!= wxGridNoCellRect
)
6695 return wxGridNoCellRect
;
6698 // convert to scrolled coords
6700 int left
, top
, right
, bottom
;
6701 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
6702 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
6705 m_gridWin
->GetClientSize( &cw
, &ch
);
6707 rect
.SetLeft( wxMax(0, left
) );
6708 rect
.SetTop( wxMax(0, top
) );
6709 rect
.SetRight( wxMin(cw
, right
) );
6710 rect
.SetBottom( wxMin(ch
, bottom
) );
6718 // ------ Grid event classes
6721 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxEvent
)
6723 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
6724 int row
, int col
, int x
, int y
,
6725 bool control
, bool shift
, bool alt
, bool meta
)
6726 : wxNotifyEvent( type
, id
)
6732 m_control
= control
;
6737 SetEventObject(obj
);
6741 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxEvent
)
6743 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
6744 int rowOrCol
, int x
, int y
,
6745 bool control
, bool shift
, bool alt
, bool meta
)
6746 : wxNotifyEvent( type
, id
)
6748 m_rowOrCol
= rowOrCol
;
6751 m_control
= control
;
6756 SetEventObject(obj
);
6760 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxEvent
)
6762 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
6763 const wxGridCellCoords
& topLeft
,
6764 const wxGridCellCoords
& bottomRight
,
6765 bool control
, bool shift
, bool alt
, bool meta
)
6766 : wxNotifyEvent( type
, id
)
6768 m_topLeft
= topLeft
;
6769 m_bottomRight
= bottomRight
;
6770 m_control
= control
;
6775 SetEventObject(obj
);
6779 #endif // ifndef wxUSE_NEW_GRID