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::BeginEdit(int row
, int col
, wxGrid
* grid
)
473 wxASSERT_MSG(m_control
,
474 wxT("The wxGridCellEditor must be Created first!"));
476 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
477 Text()->SetValue(m_startValue
);
478 Text()->SetInsertionPointEnd();
483 bool wxGridCellTextEditor::EndEdit(int row
, int col
, bool saveValue
,
486 wxASSERT_MSG(m_control
,
487 wxT("The wxGridCellEditor must be Created first!"));
489 bool changed
= FALSE
;
490 wxString value
= Text()->GetValue();
491 if (value
!= m_startValue
)
495 grid
->GetTable()->SetValue(row
, col
, value
);
497 m_startValue
= wxEmptyString
;
498 Text()->SetValue(m_startValue
);
504 void wxGridCellTextEditor::Reset()
506 wxASSERT_MSG(m_control
,
507 wxT("The wxGridCellEditor must be Created first!"));
509 Text()->SetValue(m_startValue
);
510 Text()->SetInsertionPointEnd();
513 void wxGridCellTextEditor::StartingKey(wxKeyEvent
& event
)
515 if ( !event
.AltDown() && !event
.MetaDown() && !event
.ControlDown() )
517 // insert the key in the control
518 long keycode
= event
.KeyCode();
519 if ( isprint(keycode
) )
521 // FIXME this is not going to work for non letters...
522 if ( !event
.ShiftDown() )
524 keycode
= tolower(keycode
);
527 Text()->AppendText((wxChar
)keycode
);
537 void wxGridCellTextEditor::HandleReturn(wxKeyEvent
& event
)
539 #if defined(__WXMOTIF__) || defined(__WXGTK__)
540 // wxMotif needs a little extra help...
541 int pos
= Text()->GetInsertionPoint();
542 wxString
s( Text()->GetValue() );
543 s
= s
.Left(pos
) + "\n" + s
.Mid(pos
);
545 Text()->SetInsertionPoint( pos
);
547 // the other ports can handle a Return key press
553 // ----------------------------------------------------------------------------
554 // wxGridCellBoolEditor
555 // ----------------------------------------------------------------------------
557 void wxGridCellBoolEditor::Create(wxWindow
* parent
,
559 wxEvtHandler
* evtHandler
)
561 m_control
= new wxCheckBox(parent
, id
, wxEmptyString
,
562 wxDefaultPosition
, wxDefaultSize
,
565 wxGridCellEditor::Create(parent
, id
, evtHandler
);
568 void wxGridCellBoolEditor::SetSize(const wxRect
& r
)
570 // position it in the centre of the rectangle (TODO: support alignment?)
572 m_control
->GetSize(&w
, &h
);
574 // the checkbox without label still has some space to the right in wxGTK,
575 // so shift it to the right
580 m_control
->Move(r
.x
+ r
.width
/2 - w
/2, r
.y
+ r
.height
/2 - h
/2);
583 void wxGridCellBoolEditor::Show(bool show
, wxGridCellAttr
*attr
)
585 wxGridCellEditor::Show(show
, attr
);
588 // VZ: normally base class already does it, but it doesn't work (FIXME)
589 wxColour colBg
= attr
? attr
->GetBackgroundColour() : *wxLIGHT_GREY
;
590 CBox()->SetBackgroundColour(colBg
);
594 void wxGridCellBoolEditor::BeginEdit(int row
, int col
, wxGrid
* grid
)
596 wxASSERT_MSG(m_control
,
597 wxT("The wxGridCellEditor must be Created first!"));
599 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxT("bool")))
600 m_startValue
= grid
->GetTable()->GetValueAsBool(row
, col
);
602 m_startValue
= !!grid
->GetTable()->GetValue(row
, col
);
603 CBox()->SetValue(m_startValue
);
607 bool wxGridCellBoolEditor::EndEdit(int row
, int col
,
611 wxASSERT_MSG(m_control
,
612 wxT("The wxGridCellEditor must be Created first!"));
614 bool changed
= FALSE
;
615 bool value
= CBox()->GetValue();
616 if ( value
!= m_startValue
)
621 if (grid
->GetTable()->CanGetValueAs(row
, col
, wxT("bool")))
622 grid
->GetTable()->SetValueAsBool(row
, col
, value
);
624 grid
->GetTable()->SetValue(row
, col
, value
? _T("1") : wxEmptyString
);
630 void wxGridCellBoolEditor::Reset()
632 wxASSERT_MSG(m_control
,
633 wxT("The wxGridCellEditor must be Created first!"));
635 CBox()->SetValue(m_startValue
);
638 void wxGridCellBoolEditor::StartingClick()
640 CBox()->SetValue(!CBox()->GetValue());
643 // ----------------------------------------------------------------------------
644 // wxGridCellEditorEvtHandler
645 // ----------------------------------------------------------------------------
647 void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent
& event
)
649 switch ( event
.KeyCode() )
653 m_grid
->DisableCellEditControl();
657 event
.Skip( m_grid
->ProcessEvent( event
) );
661 if (!m_grid
->ProcessEvent(event
))
662 m_editor
->HandleReturn(event
);
671 void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent
& event
)
673 switch ( event
.KeyCode() )
685 // ============================================================================
687 // ============================================================================
689 // ----------------------------------------------------------------------------
690 // wxGridCellRenderer
691 // ----------------------------------------------------------------------------
693 void wxGridCellRenderer::Draw(wxGrid
& grid
,
694 wxGridCellAttr
& attr
,
700 dc
.SetBackgroundMode( wxSOLID
);
704 dc
.SetBrush( wxBrush(grid
.GetSelectionBackground(), wxSOLID
) );
708 dc
.SetBrush( wxBrush(attr
.GetBackgroundColour(), wxSOLID
) );
711 dc
.SetPen( *wxTRANSPARENT_PEN
);
712 dc
.DrawRectangle(rect
);
715 // ----------------------------------------------------------------------------
716 // wxGridCellStringRenderer
717 // ----------------------------------------------------------------------------
719 void wxGridCellStringRenderer::Draw(wxGrid
& grid
,
720 wxGridCellAttr
& attr
,
722 const wxRect
& rectCell
,
726 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
728 // now we only have to draw the text
729 dc
.SetBackgroundMode( wxTRANSPARENT
);
731 // TODO some special colours for attr.IsReadOnly() case?
735 dc
.SetTextBackground( grid
.GetSelectionBackground() );
736 dc
.SetTextForeground( grid
.GetSelectionForeground() );
740 dc
.SetTextBackground( attr
.GetBackgroundColour() );
741 dc
.SetTextForeground( attr
.GetTextColour() );
743 dc
.SetFont( attr
.GetFont() );
746 attr
.GetAlignment(&hAlign
, &vAlign
);
748 wxRect rect
= rectCell
;
754 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
755 rect
, hAlign
, vAlign
);
758 // ----------------------------------------------------------------------------
759 // wxGridCellBoolRenderer
760 // ----------------------------------------------------------------------------
762 void wxGridCellBoolRenderer::Draw(wxGrid
& grid
,
763 wxGridCellAttr
& attr
,
769 wxGridCellRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
771 // between checkmark and box
772 static const wxCoord margin
= 4;
775 static wxCoord s_checkSize
= 0;
776 if ( s_checkSize
== 0 )
778 // compute it only once (no locks for MT safeness in GUI thread...)
779 wxCheckBox
*checkbox
= new wxCheckBox(&grid
, -1, wxEmptyString
);
780 wxSize size
= checkbox
->GetBestSize();
781 s_checkSize
= size
.y
+ margin
;
783 // FIXME wxGTK::wxCheckBox::GetBestSize() is really weird...
785 s_checkSize
-= size
.y
/ 2;
791 // draw a check mark in the centre (ignoring alignment - TODO)
793 rectMark
.x
= rect
.x
+ rect
.width
/2 - s_checkSize
/2;
794 rectMark
.y
= rect
.y
+ rect
.height
/2 - s_checkSize
/2;
795 rectMark
.width
= rectMark
.height
= s_checkSize
;
797 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
798 dc
.SetPen(wxPen(attr
.GetTextColour(), 1, wxSOLID
));
799 dc
.DrawRectangle(rectMark
);
801 rectMark
.Inflate(-margin
);
804 if (grid
.GetTable()->CanGetValueAs(row
, col
, wxT("bool")))
805 value
= grid
.GetTable()->GetValueAsBool(row
, col
);
807 value
= !!grid
.GetTable()->GetValue(row
, col
);
811 dc
.SetTextForeground(attr
.GetTextColour());
812 dc
.DrawCheckMark(rectMark
);
816 // ----------------------------------------------------------------------------
818 // ----------------------------------------------------------------------------
820 const wxColour
& wxGridCellAttr::GetTextColour() const
826 else if (m_defGridAttr
!= this)
828 return m_defGridAttr
->GetTextColour();
832 wxFAIL_MSG(wxT("Missing default cell attribute"));
838 const wxColour
& wxGridCellAttr::GetBackgroundColour() const
840 if (HasBackgroundColour())
842 else if (m_defGridAttr
!= this)
843 return m_defGridAttr
->GetBackgroundColour();
846 wxFAIL_MSG(wxT("Missing default cell attribute"));
852 const wxFont
& wxGridCellAttr::GetFont() const
856 else if (m_defGridAttr
!= this)
857 return m_defGridAttr
->GetFont();
860 wxFAIL_MSG(wxT("Missing default cell attribute"));
866 void wxGridCellAttr::GetAlignment(int *hAlign
, int *vAlign
) const
870 if ( hAlign
) *hAlign
= m_hAlign
;
871 if ( vAlign
) *vAlign
= m_vAlign
;
873 else if (m_defGridAttr
!= this)
874 m_defGridAttr
->GetAlignment(hAlign
, vAlign
);
877 wxFAIL_MSG(wxT("Missing default cell attribute"));
882 // GetRenderer and GetEditor use a slightly different decision path about
883 // which to use. If a non-default attr object has one then it is used,
884 // otherwise the default editor or renderer passed in is used. It should be
885 // the default for the data type of the cell. If it is NULL (because the
886 // table has a type that the grid does not have in its registry,) then the
887 // grid's default editor or renderer is used.
889 wxGridCellRenderer
* wxGridCellAttr::GetRenderer(wxGridCellRenderer
* def
) const
891 if ((m_defGridAttr
!= this || def
== NULL
) && HasRenderer())
895 else if (m_defGridAttr
!= this)
896 return m_defGridAttr
->GetRenderer(NULL
);
899 wxFAIL_MSG(wxT("Missing default cell attribute"));
904 wxGridCellEditor
* wxGridCellAttr::GetEditor(wxGridCellEditor
* def
) const
906 if ((m_defGridAttr
!= this || def
== NULL
) && HasEditor())
910 else if (m_defGridAttr
!= this)
911 return m_defGridAttr
->GetEditor(NULL
);
914 wxFAIL_MSG(wxT("Missing default cell attribute"));
919 // ----------------------------------------------------------------------------
920 // wxGridCellAttrData
921 // ----------------------------------------------------------------------------
923 void wxGridCellAttrData::SetAttr(wxGridCellAttr
*attr
, int row
, int col
)
925 int n
= FindIndex(row
, col
);
926 if ( n
== wxNOT_FOUND
)
929 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
935 // change the attribute
936 m_attrs
[(size_t)n
].attr
= attr
;
940 // remove this attribute
941 m_attrs
.RemoveAt((size_t)n
);
946 wxGridCellAttr
*wxGridCellAttrData::GetAttr(int row
, int col
) const
948 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
950 int n
= FindIndex(row
, col
);
951 if ( n
!= wxNOT_FOUND
)
953 attr
= m_attrs
[(size_t)n
].attr
;
960 void wxGridCellAttrData::UpdateAttrRows( size_t pos
, int numRows
)
962 size_t count
= m_attrs
.GetCount();
963 for ( size_t n
= 0; n
< count
; n
++ )
965 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
966 wxCoord row
= coords
.GetRow();
967 if ((size_t)row
>= pos
)
971 // If rows inserted, include row counter where necessary
972 coords
.SetRow(row
+ numRows
);
974 else if (numRows
< 0)
976 // If rows deleted ...
977 if ((size_t)row
>= pos
- numRows
)
979 // ...either decrement row counter (if row still exists)...
980 coords
.SetRow(row
+ numRows
);
984 // ...or remove the attribute
985 m_attrs
.RemoveAt((size_t)n
);
993 void wxGridCellAttrData::UpdateAttrCols( size_t pos
, int numCols
)
995 size_t count
= m_attrs
.GetCount();
996 for ( size_t n
= 0; n
< count
; n
++ )
998 wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
999 wxCoord col
= coords
.GetCol();
1000 if ( (size_t)col
>= pos
)
1004 // If rows inserted, include row counter where necessary
1005 coords
.SetCol(col
+ numCols
);
1007 else if (numCols
< 0)
1009 // If rows deleted ...
1010 if ((size_t)col
>= pos
- numCols
)
1012 // ...either decrement row counter (if row still exists)...
1013 coords
.SetCol(col
+ numCols
);
1017 // ...or remove the attribute
1018 m_attrs
.RemoveAt((size_t)n
);
1026 int wxGridCellAttrData::FindIndex(int row
, int col
) const
1028 size_t count
= m_attrs
.GetCount();
1029 for ( size_t n
= 0; n
< count
; n
++ )
1031 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
1032 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
1041 // ----------------------------------------------------------------------------
1042 // wxGridRowOrColAttrData
1043 // ----------------------------------------------------------------------------
1045 wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
1047 size_t count
= m_attrs
.Count();
1048 for ( size_t n
= 0; n
< count
; n
++ )
1050 m_attrs
[n
]->DecRef();
1054 wxGridCellAttr
*wxGridRowOrColAttrData::GetAttr(int rowOrCol
) const
1056 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
1058 int n
= m_rowsOrCols
.Index(rowOrCol
);
1059 if ( n
!= wxNOT_FOUND
)
1061 attr
= m_attrs
[(size_t)n
];
1068 void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr
*attr
, int rowOrCol
)
1070 int n
= m_rowsOrCols
.Index(rowOrCol
);
1071 if ( n
== wxNOT_FOUND
)
1073 // add the attribute
1074 m_rowsOrCols
.Add(rowOrCol
);
1081 // change the attribute
1082 m_attrs
[(size_t)n
] = attr
;
1086 // remove this attribute
1087 m_attrs
[(size_t)n
]->DecRef();
1088 m_rowsOrCols
.RemoveAt((size_t)n
);
1089 m_attrs
.RemoveAt((size_t)n
);
1094 void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
)
1096 size_t count
= m_attrs
.GetCount();
1097 for ( size_t n
= 0; n
< count
; n
++ )
1099 int & rowOrCol
= m_rowsOrCols
[n
];
1100 if ( (size_t)rowOrCol
>= pos
)
1102 if ( numRowsOrCols
> 0 )
1104 // If rows inserted, include row counter where necessary
1105 rowOrCol
+= numRowsOrCols
;
1107 else if ( numRowsOrCols
< 0)
1109 // If rows deleted, either decrement row counter (if row still exists)
1110 if ((size_t)rowOrCol
>= pos
- numRowsOrCols
)
1111 rowOrCol
+= numRowsOrCols
;
1114 m_rowsOrCols
.RemoveAt((size_t)n
);
1115 m_attrs
.RemoveAt((size_t)n
);
1123 // ----------------------------------------------------------------------------
1124 // wxGridCellAttrProvider
1125 // ----------------------------------------------------------------------------
1127 wxGridCellAttrProvider::wxGridCellAttrProvider()
1129 m_data
= (wxGridCellAttrProviderData
*)NULL
;
1132 wxGridCellAttrProvider::~wxGridCellAttrProvider()
1137 void wxGridCellAttrProvider::InitData()
1139 m_data
= new wxGridCellAttrProviderData
;
1142 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
) const
1144 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
1147 // first look for the attribute of this specific cell
1148 attr
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
1152 // then look for the col attr (col attributes are more common than
1153 // the row ones, hence they have priority)
1154 attr
= m_data
->m_colAttrs
.GetAttr(col
);
1159 // finally try the row attributes
1160 attr
= m_data
->m_rowAttrs
.GetAttr(row
);
1167 void wxGridCellAttrProvider::SetAttr(wxGridCellAttr
*attr
,
1173 m_data
->m_cellAttrs
.SetAttr(attr
, row
, col
);
1176 void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr
*attr
, int row
)
1181 m_data
->m_rowAttrs
.SetAttr(attr
, row
);
1184 void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr
*attr
, int col
)
1189 m_data
->m_colAttrs
.SetAttr(attr
, col
);
1192 void wxGridCellAttrProvider::UpdateAttrRows( size_t pos
, int numRows
)
1196 m_data
->m_cellAttrs
.UpdateAttrRows( pos
, numRows
);
1198 m_data
->m_rowAttrs
.UpdateAttrRowsOrCols( pos
, numRows
);
1202 void wxGridCellAttrProvider::UpdateAttrCols( size_t pos
, int numCols
)
1206 m_data
->m_cellAttrs
.UpdateAttrCols( pos
, numCols
);
1208 m_data
->m_colAttrs
.UpdateAttrRowsOrCols( pos
, numCols
);
1212 // ----------------------------------------------------------------------------
1213 // wxGridTypeRegistry
1214 // ----------------------------------------------------------------------------
1216 wxGridTypeRegistry::~wxGridTypeRegistry()
1218 for (size_t i
=0; i
<m_typeinfo
.Count(); i
++)
1219 delete m_typeinfo
[i
];
1223 void wxGridTypeRegistry::RegisterDataType(const wxString
& typeName
,
1224 wxGridCellRenderer
* renderer
,
1225 wxGridCellEditor
* editor
)
1228 wxGridDataTypeInfo
* info
= new wxGridDataTypeInfo(typeName
, renderer
, editor
);
1230 // is it already registered?
1231 if ((loc
= FindDataType(typeName
)) != -1) {
1232 delete m_typeinfo
[loc
];
1233 m_typeinfo
[loc
] = info
;
1236 m_typeinfo
.Add(info
);
1240 int wxGridTypeRegistry::FindDataType(const wxString
& typeName
)
1244 for (size_t i
=0; i
<m_typeinfo
.Count(); i
++) {
1245 if (typeName
== m_typeinfo
[i
]->m_typeName
) {
1254 wxGridCellRenderer
* wxGridTypeRegistry::GetRenderer(int index
)
1256 wxGridCellRenderer
* renderer
= m_typeinfo
[index
]->m_renderer
;
1260 wxGridCellEditor
* wxGridTypeRegistry::GetEditor(int index
)
1262 wxGridCellEditor
* editor
= m_typeinfo
[index
]->m_editor
;
1266 // ----------------------------------------------------------------------------
1268 // ----------------------------------------------------------------------------
1270 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
1273 wxGridTableBase::wxGridTableBase()
1275 m_view
= (wxGrid
*) NULL
;
1276 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
1279 wxGridTableBase::~wxGridTableBase()
1281 delete m_attrProvider
;
1284 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
1286 delete m_attrProvider
;
1287 m_attrProvider
= attrProvider
;
1290 bool wxGridTableBase::CanHaveAttributes()
1292 if ( ! GetAttrProvider() )
1294 // use the default attr provider by default
1295 SetAttrProvider(new wxGridCellAttrProvider
);
1300 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
)
1302 if ( m_attrProvider
)
1303 return m_attrProvider
->GetAttr(row
, col
);
1305 return (wxGridCellAttr
*)NULL
;
1308 void wxGridTableBase::SetAttr(wxGridCellAttr
* attr
, int row
, int col
)
1310 if ( m_attrProvider
)
1312 m_attrProvider
->SetAttr(attr
, row
, col
);
1316 // as we take ownership of the pointer and don't store it, we must
1322 void wxGridTableBase::SetRowAttr(wxGridCellAttr
*attr
, int row
)
1324 if ( m_attrProvider
)
1326 m_attrProvider
->SetRowAttr(attr
, row
);
1330 // as we take ownership of the pointer and don't store it, we must
1336 void wxGridTableBase::SetColAttr(wxGridCellAttr
*attr
, int col
)
1338 if ( m_attrProvider
)
1340 m_attrProvider
->SetColAttr(attr
, col
);
1344 // as we take ownership of the pointer and don't store it, we must
1350 void wxGridTableBase::UpdateAttrRows( size_t pos
, int numRows
)
1352 if ( m_attrProvider
)
1354 m_attrProvider
->UpdateAttrRows( pos
, numRows
);
1358 void wxGridTableBase::UpdateAttrCols( size_t pos
, int numCols
)
1360 if ( m_attrProvider
)
1362 m_attrProvider
->UpdateAttrCols( pos
, numCols
);
1366 bool wxGridTableBase::InsertRows( size_t pos
, size_t numRows
)
1368 wxFAIL_MSG( wxT("Called grid table class function InsertRows\n"
1369 "but your derived table class does not override this function") );
1374 bool wxGridTableBase::AppendRows( size_t numRows
)
1376 wxFAIL_MSG( wxT("Called grid table class function AppendRows\n"
1377 "but your derived table class does not override this function"));
1382 bool wxGridTableBase::DeleteRows( size_t pos
, size_t numRows
)
1384 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\n"
1385 "but your derived table class does not override this function"));
1390 bool wxGridTableBase::InsertCols( size_t pos
, size_t numCols
)
1392 wxFAIL_MSG( wxT("Called grid table class function InsertCols\n"
1393 "but your derived table class does not override this function"));
1398 bool wxGridTableBase::AppendCols( size_t numCols
)
1400 wxFAIL_MSG(wxT("Called grid table class function AppendCols\n"
1401 "but your derived table class does not override this function"));
1406 bool wxGridTableBase::DeleteCols( size_t pos
, size_t numCols
)
1408 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\n"
1409 "but your derived table class does not override this function"));
1415 wxString
wxGridTableBase::GetRowLabelValue( int row
)
1418 s
<< row
+ 1; // RD: Starting the rows at zero confuses users, no matter
1419 // how much it makes sense to us geeks.
1423 wxString
wxGridTableBase::GetColLabelValue( int col
)
1425 // default col labels are:
1426 // cols 0 to 25 : A-Z
1427 // cols 26 to 675 : AA-ZZ
1432 for ( n
= 1; ; n
++ )
1434 s
+= (_T('A') + (wxChar
)( col%26
));
1436 if ( col
< 0 ) break;
1439 // reverse the string...
1441 for ( i
= 0; i
< n
; i
++ )
1450 wxString
wxGridTableBase::GetTypeName( int WXUNUSED(row
), int WXUNUSED(col
) )
1452 return wxT("string");
1455 bool wxGridTableBase::CanGetValueAs( int WXUNUSED(row
), int WXUNUSED(col
),
1456 const wxString
& typeName
)
1458 return typeName
== wxT("string");
1461 bool wxGridTableBase::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
1463 return CanGetValueAs(row
, col
, typeName
);
1466 long wxGridTableBase::GetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
) )
1471 double wxGridTableBase::GetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
) )
1476 bool wxGridTableBase::GetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
) )
1481 void wxGridTableBase::SetValueAsLong( int WXUNUSED(row
), int WXUNUSED(col
),
1482 long WXUNUSED(value
) )
1486 void wxGridTableBase::SetValueAsDouble( int WXUNUSED(row
), int WXUNUSED(col
),
1487 double WXUNUSED(value
) )
1491 void wxGridTableBase::SetValueAsBool( int WXUNUSED(row
), int WXUNUSED(col
),
1492 bool WXUNUSED(value
) )
1497 void* wxGridTableBase::GetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
1498 const wxString
& WXUNUSED(typeName
) )
1503 void wxGridTableBase::SetValueAsCustom( int WXUNUSED(row
), int WXUNUSED(col
),
1504 const wxString
& WXUNUSED(typeName
),
1505 void* WXUNUSED(value
) )
1510 //////////////////////////////////////////////////////////////////////
1512 // Message class for the grid table to send requests and notifications
1516 wxGridTableMessage::wxGridTableMessage()
1518 m_table
= (wxGridTableBase
*) NULL
;
1524 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
1525 int commandInt1
, int commandInt2
)
1529 m_comInt1
= commandInt1
;
1530 m_comInt2
= commandInt2
;
1535 //////////////////////////////////////////////////////////////////////
1537 // A basic grid table for string data. An object of this class will
1538 // created by wxGrid if you don't specify an alternative table class.
1541 WX_DEFINE_OBJARRAY(wxGridStringArray
)
1543 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
1545 wxGridStringTable::wxGridStringTable()
1550 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
1555 m_data
.Alloc( numRows
);
1558 sa
.Alloc( numCols
);
1559 for ( col
= 0; col
< numCols
; col
++ )
1561 sa
.Add( wxEmptyString
);
1564 for ( row
= 0; row
< numRows
; row
++ )
1570 wxGridStringTable::~wxGridStringTable()
1574 long wxGridStringTable::GetNumberRows()
1576 return m_data
.GetCount();
1579 long wxGridStringTable::GetNumberCols()
1581 if ( m_data
.GetCount() > 0 )
1582 return m_data
[0].GetCount();
1587 wxString
wxGridStringTable::GetValue( int row
, int col
)
1589 // TODO: bounds checking
1591 return m_data
[row
][col
];
1594 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& value
)
1596 // TODO: bounds checking
1598 m_data
[row
][col
] = value
;
1601 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
1603 // TODO: bounds checking
1605 return (m_data
[row
][col
] == wxEmptyString
);
1609 void wxGridStringTable::Clear()
1612 int numRows
, numCols
;
1614 numRows
= m_data
.GetCount();
1617 numCols
= m_data
[0].GetCount();
1619 for ( row
= 0; row
< numRows
; row
++ )
1621 for ( col
= 0; col
< numCols
; col
++ )
1623 m_data
[row
][col
] = wxEmptyString
;
1630 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
1634 size_t curNumRows
= m_data
.GetCount();
1635 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1637 if ( pos
>= curNumRows
)
1639 return AppendRows( numRows
);
1643 sa
.Alloc( curNumCols
);
1644 for ( col
= 0; col
< curNumCols
; col
++ )
1646 sa
.Add( wxEmptyString
);
1649 for ( row
= pos
; row
< pos
+ numRows
; row
++ )
1651 m_data
.Insert( sa
, row
);
1653 UpdateAttrRows( pos
, numRows
);
1656 wxGridTableMessage
msg( this,
1657 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
1661 GetView()->ProcessTableMessage( msg
);
1667 bool wxGridStringTable::AppendRows( size_t numRows
)
1671 size_t curNumRows
= m_data
.GetCount();
1672 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1675 if ( curNumCols
> 0 )
1677 sa
.Alloc( curNumCols
);
1678 for ( col
= 0; col
< curNumCols
; col
++ )
1680 sa
.Add( wxEmptyString
);
1684 for ( row
= 0; row
< numRows
; row
++ )
1691 wxGridTableMessage
msg( this,
1692 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
1695 GetView()->ProcessTableMessage( msg
);
1701 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
1705 size_t curNumRows
= m_data
.GetCount();
1707 if ( pos
>= curNumRows
)
1710 errmsg
.Printf("Called wxGridStringTable::DeleteRows(pos=%d, N=%d)\n"
1711 "Pos value is invalid for present table with %d rows",
1712 pos
, numRows
, curNumRows
);
1713 wxFAIL_MSG( wxT(errmsg
) );
1717 if ( numRows
> curNumRows
- pos
)
1719 numRows
= curNumRows
- pos
;
1722 if ( numRows
>= curNumRows
)
1724 m_data
.Empty(); // don't release memory just yet
1728 for ( n
= 0; n
< numRows
; n
++ )
1730 m_data
.Remove( pos
);
1733 UpdateAttrRows( pos
, -((int)numRows
) );
1736 wxGridTableMessage
msg( this,
1737 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
1741 GetView()->ProcessTableMessage( msg
);
1747 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
1751 size_t curNumRows
= m_data
.GetCount();
1752 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1754 if ( pos
>= curNumCols
)
1756 return AppendCols( numCols
);
1759 for ( row
= 0; row
< curNumRows
; row
++ )
1761 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
1763 m_data
[row
].Insert( wxEmptyString
, col
);
1766 UpdateAttrCols( pos
, numCols
);
1769 wxGridTableMessage
msg( this,
1770 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
1774 GetView()->ProcessTableMessage( msg
);
1780 bool wxGridStringTable::AppendCols( size_t numCols
)
1784 size_t curNumRows
= m_data
.GetCount();
1787 // TODO: something better than this ?
1789 wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\n"
1790 "Call AppendRows() first") );
1794 for ( row
= 0; row
< curNumRows
; row
++ )
1796 for ( n
= 0; n
< numCols
; n
++ )
1798 m_data
[row
].Add( wxEmptyString
);
1804 wxGridTableMessage
msg( this,
1805 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
1808 GetView()->ProcessTableMessage( msg
);
1814 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
1818 size_t curNumRows
= m_data
.GetCount();
1819 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1821 if ( pos
>= curNumCols
)
1824 errmsg
.Printf( "Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\n"
1825 "Pos value is invalid for present table with %d cols",
1826 pos
, numCols
, curNumCols
);
1827 wxFAIL_MSG( wxT( errmsg
) );
1831 if ( numCols
> curNumCols
- pos
)
1833 numCols
= curNumCols
- pos
;
1836 for ( row
= 0; row
< curNumRows
; row
++ )
1838 if ( numCols
>= curNumCols
)
1840 m_data
[row
].Clear();
1844 for ( n
= 0; n
< numCols
; n
++ )
1846 m_data
[row
].Remove( pos
);
1850 UpdateAttrCols( pos
, -((int)numCols
) );
1853 wxGridTableMessage
msg( this,
1854 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
1858 GetView()->ProcessTableMessage( msg
);
1864 wxString
wxGridStringTable::GetRowLabelValue( int row
)
1866 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
1868 // using default label
1870 return wxGridTableBase::GetRowLabelValue( row
);
1874 return m_rowLabels
[ row
];
1878 wxString
wxGridStringTable::GetColLabelValue( int col
)
1880 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
1882 // using default label
1884 return wxGridTableBase::GetColLabelValue( col
);
1888 return m_colLabels
[ col
];
1892 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
1894 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
1896 int n
= m_rowLabels
.GetCount();
1898 for ( i
= n
; i
<= row
; i
++ )
1900 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
1904 m_rowLabels
[row
] = value
;
1907 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
1909 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
1911 int n
= m_colLabels
.GetCount();
1913 for ( i
= n
; i
<= col
; i
++ )
1915 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
1919 m_colLabels
[col
] = value
;
1924 //////////////////////////////////////////////////////////////////////
1925 //////////////////////////////////////////////////////////////////////
1927 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
1929 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
1930 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
1931 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
1932 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
1935 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
1937 const wxPoint
&pos
, const wxSize
&size
)
1938 : wxWindow( parent
, id
, pos
, size
)
1943 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
&event
)
1947 // NO - don't do this because it will set both the x and y origin
1948 // coords to match the parent scrolled window and we just want to
1949 // set the y coord - MB
1951 // m_owner->PrepareDC( dc );
1954 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
1955 dc
.SetDeviceOrigin( 0, -y
);
1957 m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
1958 m_owner
->DrawRowLabels( dc
);
1962 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1964 m_owner
->ProcessRowLabelMouseEvent( event
);
1968 // This seems to be required for wxMotif otherwise the mouse
1969 // cursor must be in the cell edit control to get key events
1971 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
1973 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1978 //////////////////////////////////////////////////////////////////////
1980 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
1982 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
1983 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
1984 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
1985 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
1988 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
1990 const wxPoint
&pos
, const wxSize
&size
)
1991 : wxWindow( parent
, id
, pos
, size
)
1996 void wxGridColLabelWindow::OnPaint( wxPaintEvent
&event
)
2000 // NO - don't do this because it will set both the x and y origin
2001 // coords to match the parent scrolled window and we just want to
2002 // set the x coord - MB
2004 // m_owner->PrepareDC( dc );
2007 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
2008 dc
.SetDeviceOrigin( -x
, 0 );
2010 m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
2011 m_owner
->DrawColLabels( dc
);
2015 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
2017 m_owner
->ProcessColLabelMouseEvent( event
);
2021 // This seems to be required for wxMotif otherwise the mouse
2022 // cursor must be in the cell edit control to get key events
2024 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
2026 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
2031 //////////////////////////////////////////////////////////////////////
2033 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
2035 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
2036 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
2037 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
2038 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
2041 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
2043 const wxPoint
&pos
, const wxSize
&size
)
2044 : wxWindow( parent
, id
, pos
, size
)
2049 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2053 int client_height
= 0;
2054 int client_width
= 0;
2055 GetClientSize( &client_width
, &client_height
);
2057 dc
.SetPen( *wxBLACK_PEN
);
2058 dc
.DrawLine( client_width
-1, client_height
-1, client_width
-1, 0 );
2059 dc
.DrawLine( client_width
-1, client_height
-1, 0, client_height
-1 );
2061 dc
.SetPen( *wxWHITE_PEN
);
2062 dc
.DrawLine( 0, 0, client_width
, 0 );
2063 dc
.DrawLine( 0, 0, 0, client_height
);
2067 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
2069 m_owner
->ProcessCornerLabelMouseEvent( event
);
2073 // This seems to be required for wxMotif otherwise the mouse
2074 // cursor must be in the cell edit control to get key events
2076 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
2078 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
2083 //////////////////////////////////////////////////////////////////////
2085 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxPanel
)
2087 BEGIN_EVENT_TABLE( wxGridWindow
, wxPanel
)
2088 EVT_PAINT( wxGridWindow::OnPaint
)
2089 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
2090 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
2091 EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground
)
2094 wxGridWindow::wxGridWindow( wxGrid
*parent
,
2095 wxGridRowLabelWindow
*rowLblWin
,
2096 wxGridColLabelWindow
*colLblWin
,
2097 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
)
2098 : wxPanel( parent
, id
, pos
, size
, 0, "grid window" )
2101 m_rowLabelWin
= rowLblWin
;
2102 m_colLabelWin
= colLblWin
;
2103 SetBackgroundColour( "WHITE" );
2107 wxGridWindow::~wxGridWindow()
2112 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2114 wxPaintDC
dc( this );
2115 m_owner
->PrepareDC( dc
);
2116 wxRegion reg
= GetUpdateRegion();
2117 m_owner
->CalcCellsExposed( reg
);
2118 m_owner
->DrawGridCellArea( dc
);
2119 #if WXGRID_DRAW_LINES
2120 m_owner
->DrawAllGridLines( dc
, reg
);
2122 m_owner
->DrawHighlight( dc
);
2126 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2128 wxPanel::ScrollWindow( dx
, dy
, rect
);
2129 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
2130 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
2134 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
2136 m_owner
->ProcessGridCellMouseEvent( event
);
2140 // This seems to be required for wxMotif otherwise the mouse
2141 // cursor must be in the cell edit control to get key events
2143 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
2145 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
2148 // We are trapping erase background events to reduce flicker under MSW
2149 // and GTK but this can leave junk in the space beyond the last row and
2150 // col. So here we paint these spaces if they are visible.
2152 void wxGridWindow::OnEraseBackground(wxEraseEvent
& event
)
2155 GetClientSize( &cw
, &ch
);
2158 m_owner
->CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
2161 rightRect
= m_owner
->CellToRect( 0, m_owner
->GetNumberCols()-1 );
2164 bottomRect
= m_owner
->CellToRect( m_owner
->GetNumberRows()-1, 0 );
2166 if ( right
> rightRect
.GetRight() || bottom
> bottomRect
.GetBottom() )
2169 m_owner
->CalcUnscrolledPosition( 0, 0, &left
, &top
);
2171 wxClientDC
dc( this );
2172 m_owner
->PrepareDC( dc
);
2173 dc
.SetBrush( wxBrush(m_owner
->GetDefaultCellBackgroundColour(), wxSOLID
) );
2174 dc
.SetPen( *wxTRANSPARENT_PEN
);
2176 if ( right
> rightRect
.GetRight() )
2177 dc
.DrawRectangle( rightRect
.GetRight()+1, top
, right
- rightRect
.GetRight(), ch
);
2179 if ( bottom
> bottomRect
.GetBottom() )
2180 dc
.DrawRectangle( left
, bottomRect
.GetBottom()+1, cw
, bottom
- bottomRect
.GetBottom() );
2185 //////////////////////////////////////////////////////////////////////
2188 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
2190 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
2191 EVT_PAINT( wxGrid::OnPaint
)
2192 EVT_SIZE( wxGrid::OnSize
)
2193 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
2194 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
2197 wxGrid::wxGrid( wxWindow
*parent
,
2202 const wxString
& name
)
2203 : wxScrolledWindow( parent
, id
, pos
, size
, style
, name
),
2204 m_colMinWidths(wxKEY_INTEGER
, GRID_HASH_SIZE
)
2213 m_defaultCellAttr
->SafeDecRef();
2215 #ifdef DEBUG_ATTR_CACHE
2216 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
2217 wxPrintf(_T("wxGrid attribute cache statistics: "
2218 "total: %u, hits: %u (%u%%)\n"),
2219 total
, gs_nAttrCacheHits
,
2220 total
? (gs_nAttrCacheHits
*100) / total
: 0);
2226 delete m_typeRegistry
;
2231 // ----- internal init and update functions
2234 void wxGrid::Create()
2236 m_created
= FALSE
; // set to TRUE by CreateGrid
2237 m_displayed
= TRUE
; // FALSE; // set to TRUE by OnPaint
2239 m_table
= (wxGridTableBase
*) NULL
;
2242 m_cellEditCtrlEnabled
= FALSE
;
2244 m_defaultCellAttr
= new wxGridCellAttr
;
2245 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
2247 // Set default cell attributes
2248 m_defaultCellAttr
->SetFont(GetFont());
2249 m_defaultCellAttr
->SetAlignment(wxLEFT
, wxTOP
);
2250 m_defaultCellAttr
->SetTextColour(
2251 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT
));
2252 m_defaultCellAttr
->SetBackgroundColour(
2253 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
2254 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
2255 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
2260 m_currentCellCoords
= wxGridNoCellCoords
;
2262 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
2263 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
2265 // data type registration
2266 m_typeRegistry
= new wxGridTypeRegistry
;
2267 RegisterDataType(wxT("string"), new wxGridCellStringRenderer
,
2268 new wxGridCellTextEditor
);
2269 RegisterDataType(wxT("bool"), new wxGridCellBoolRenderer
,
2270 new wxGridCellBoolEditor
);
2273 // subwindow components that make up the wxGrid
2274 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
2279 m_rowLabelWin
= new wxGridRowLabelWindow( this,
2284 m_colLabelWin
= new wxGridColLabelWindow( this,
2289 m_gridWin
= new wxGridWindow( this,
2296 SetTargetWindow( m_gridWin
);
2300 bool wxGrid::CreateGrid( int numRows
, int numCols
)
2304 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
2309 m_numRows
= numRows
;
2310 m_numCols
= numCols
;
2312 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
2313 m_table
->SetView( this );
2322 bool wxGrid::SetTable( wxGridTableBase
*table
, bool takeOwnership
)
2326 // RD: Actually, this should probably be allowed. I think it would be
2327 // nice to be able to switch multiple Tables in and out of a single
2328 // View at runtime. Is there anything in the implmentation that would
2331 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
2336 m_numRows
= table
->GetNumberRows();
2337 m_numCols
= table
->GetNumberCols();
2340 m_table
->SetView( this );
2353 if ( m_numRows
<= 0 )
2354 m_numRows
= WXGRID_DEFAULT_NUMBER_ROWS
;
2356 if ( m_numCols
<= 0 )
2357 m_numCols
= WXGRID_DEFAULT_NUMBER_COLS
;
2359 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
2360 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
2362 if ( m_rowLabelWin
)
2364 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
2368 m_labelBackgroundColour
= wxColour( _T("WHITE") );
2371 m_labelTextColour
= wxColour( _T("BLACK") );
2374 m_attrCache
.row
= -1;
2376 // TODO: something better than this ?
2378 m_labelFont
= this->GetFont();
2379 m_labelFont
.SetWeight( m_labelFont
.GetWeight() + 2 );
2381 m_rowLabelHorizAlign
= wxLEFT
;
2382 m_rowLabelVertAlign
= wxCENTRE
;
2384 m_colLabelHorizAlign
= wxCENTRE
;
2385 m_colLabelVertAlign
= wxTOP
;
2387 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
2388 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
2390 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
2391 m_defaultRowHeight
+= 8;
2393 m_defaultRowHeight
+= 4;
2396 m_gridLineColour
= wxColour( 128, 128, 255 );
2397 m_gridLinesEnabled
= TRUE
;
2399 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
2400 m_winCapture
= (wxWindow
*)NULL
;
2401 m_canDragRowSize
= TRUE
;
2402 m_canDragColSize
= TRUE
;
2404 m_dragRowOrCol
= -1;
2405 m_isDragging
= FALSE
;
2406 m_startDragPos
= wxDefaultPosition
;
2408 m_waitForSlowClick
= FALSE
;
2410 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
2411 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
2413 m_currentCellCoords
= wxGridNoCellCoords
;
2415 m_selectedTopLeft
= wxGridNoCellCoords
;
2416 m_selectedBottomRight
= wxGridNoCellCoords
;
2417 m_selectionBackground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
);
2418 m_selectionForeground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
2420 m_editable
= TRUE
; // default for whole grid
2422 m_inOnKeyDown
= FALSE
;
2426 // ----------------------------------------------------------------------------
2427 // the idea is to call these functions only when necessary because they create
2428 // quite big arrays which eat memory mostly unnecessary - in particular, if
2429 // default widths/heights are used for all rows/columns, we may not use these
2432 // with some extra code, it should be possible to only store the
2433 // widths/heights different from default ones but this will be done later...
2434 // ----------------------------------------------------------------------------
2436 void wxGrid::InitRowHeights()
2438 m_rowHeights
.Empty();
2439 m_rowBottoms
.Empty();
2441 m_rowHeights
.Alloc( m_numRows
);
2442 m_rowBottoms
.Alloc( m_numRows
);
2445 for ( int i
= 0; i
< m_numRows
; i
++ )
2447 m_rowHeights
.Add( m_defaultRowHeight
);
2448 rowBottom
+= m_defaultRowHeight
;
2449 m_rowBottoms
.Add( rowBottom
);
2453 void wxGrid::InitColWidths()
2455 m_colWidths
.Empty();
2456 m_colRights
.Empty();
2458 m_colWidths
.Alloc( m_numCols
);
2459 m_colRights
.Alloc( m_numCols
);
2461 for ( int i
= 0; i
< m_numCols
; i
++ )
2463 m_colWidths
.Add( m_defaultColWidth
);
2464 colRight
+= m_defaultColWidth
;
2465 m_colRights
.Add( colRight
);
2469 int wxGrid::GetColWidth(int col
) const
2471 return m_colWidths
.IsEmpty() ? m_defaultColWidth
: m_colWidths
[col
];
2474 int wxGrid::GetColLeft(int col
) const
2476 return m_colRights
.IsEmpty() ? col
* m_defaultColWidth
2477 : m_colRights
[col
] - m_colWidths
[col
];
2480 int wxGrid::GetColRight(int col
) const
2482 return m_colRights
.IsEmpty() ? (col
+ 1) * m_defaultColWidth
2486 int wxGrid::GetRowHeight(int row
) const
2488 return m_rowHeights
.IsEmpty() ? m_defaultRowHeight
: m_rowHeights
[row
];
2491 int wxGrid::GetRowTop(int row
) const
2493 return m_rowBottoms
.IsEmpty() ? row
* m_defaultRowHeight
2494 : m_rowBottoms
[row
] - m_rowHeights
[row
];
2497 int wxGrid::GetRowBottom(int row
) const
2499 return m_rowBottoms
.IsEmpty() ? (row
+ 1) * m_defaultRowHeight
2500 : m_rowBottoms
[row
];
2503 void wxGrid::CalcDimensions()
2506 GetClientSize( &cw
, &ch
);
2508 if ( m_numRows
> 0 && m_numCols
> 0 )
2510 int right
= GetColRight( m_numCols
-1 ) + 50;
2511 int bottom
= GetRowBottom( m_numRows
-1 ) + 50;
2513 // TODO: restore the scroll position that we had before sizing
2516 GetViewStart( &x
, &y
);
2517 SetScrollbars( GRID_SCROLL_LINE
, GRID_SCROLL_LINE
,
2518 right
/GRID_SCROLL_LINE
, bottom
/GRID_SCROLL_LINE
,
2524 void wxGrid::CalcWindowSizes()
2527 GetClientSize( &cw
, &ch
);
2529 if ( m_cornerLabelWin
->IsShown() )
2530 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
2532 if ( m_colLabelWin
->IsShown() )
2533 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
2535 if ( m_rowLabelWin
->IsShown() )
2536 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
2538 if ( m_gridWin
->IsShown() )
2539 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
2543 // this is called when the grid table sends a message to say that it
2544 // has been redimensioned
2546 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
2550 // if we were using the default widths/heights so far, we must change them
2552 if ( m_colWidths
.IsEmpty() )
2557 if ( m_rowHeights
.IsEmpty() )
2562 switch ( msg
.GetId() )
2564 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
2566 size_t pos
= msg
.GetCommandInt();
2567 int numRows
= msg
.GetCommandInt2();
2568 for ( i
= 0; i
< numRows
; i
++ )
2570 m_rowHeights
.Insert( m_defaultRowHeight
, pos
);
2571 m_rowBottoms
.Insert( 0, pos
);
2573 m_numRows
+= numRows
;
2576 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
2578 for ( i
= pos
; i
< m_numRows
; i
++ )
2580 bottom
+= m_rowHeights
[i
];
2581 m_rowBottoms
[i
] = bottom
;
2587 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
2589 int numRows
= msg
.GetCommandInt();
2590 for ( i
= 0; i
< numRows
; i
++ )
2592 m_rowHeights
.Add( m_defaultRowHeight
);
2593 m_rowBottoms
.Add( 0 );
2596 int oldNumRows
= m_numRows
;
2597 m_numRows
+= numRows
;
2600 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
2602 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
2604 bottom
+= m_rowHeights
[i
];
2605 m_rowBottoms
[i
] = bottom
;
2611 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
2613 size_t pos
= msg
.GetCommandInt();
2614 int numRows
= msg
.GetCommandInt2();
2615 for ( i
= 0; i
< numRows
; i
++ )
2617 m_rowHeights
.Remove( pos
);
2618 m_rowBottoms
.Remove( pos
);
2620 m_numRows
-= numRows
;
2625 m_colWidths
.Clear();
2626 m_colRights
.Clear();
2627 m_currentCellCoords
= wxGridNoCellCoords
;
2631 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
2632 m_currentCellCoords
.Set( 0, 0 );
2635 for ( i
= 0; i
< m_numRows
; i
++ )
2637 h
+= m_rowHeights
[i
];
2638 m_rowBottoms
[i
] = h
;
2646 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
2648 size_t pos
= msg
.GetCommandInt();
2649 int numCols
= msg
.GetCommandInt2();
2650 for ( i
= 0; i
< numCols
; i
++ )
2652 m_colWidths
.Insert( m_defaultColWidth
, pos
);
2653 m_colRights
.Insert( 0, pos
);
2655 m_numCols
+= numCols
;
2658 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
2660 for ( i
= pos
; i
< m_numCols
; i
++ )
2662 right
+= m_colWidths
[i
];
2663 m_colRights
[i
] = right
;
2669 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
2671 int numCols
= msg
.GetCommandInt();
2672 for ( i
= 0; i
< numCols
; i
++ )
2674 m_colWidths
.Add( m_defaultColWidth
);
2675 m_colRights
.Add( 0 );
2678 int oldNumCols
= m_numCols
;
2679 m_numCols
+= numCols
;
2682 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
2684 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
2686 right
+= m_colWidths
[i
];
2687 m_colRights
[i
] = right
;
2693 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
2695 size_t pos
= msg
.GetCommandInt();
2696 int numCols
= msg
.GetCommandInt2();
2697 for ( i
= 0; i
< numCols
; i
++ )
2699 m_colWidths
.Remove( pos
);
2700 m_colRights
.Remove( pos
);
2702 m_numCols
-= numCols
;
2706 #if 0 // leave the row alone here so that AppendCols will work subsequently
2708 m_rowHeights
.Clear();
2709 m_rowBottoms
.Clear();
2711 m_currentCellCoords
= wxGridNoCellCoords
;
2715 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
2716 m_currentCellCoords
.Set( 0, 0 );
2719 for ( i
= 0; i
< m_numCols
; i
++ )
2721 w
+= m_colWidths
[i
];
2734 void wxGrid::CalcRowLabelsExposed( wxRegion
& reg
)
2736 wxRegionIterator
iter( reg
);
2739 m_rowLabelsExposed
.Empty();
2746 // TODO: remove this when we can...
2747 // There is a bug in wxMotif that gives garbage update
2748 // rectangles if you jump-scroll a long way by clicking the
2749 // scrollbar with middle button. This is a work-around
2751 #if defined(__WXMOTIF__)
2753 m_gridWin
->GetClientSize( &cw
, &ch
);
2754 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
2755 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
2758 // logical bounds of update region
2761 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
2762 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
2764 // find the row labels within these bounds
2767 for ( row
= 0; row
< m_numRows
; row
++ )
2769 if ( GetRowBottom(row
) < top
)
2772 if ( GetRowTop(row
) > bottom
)
2775 m_rowLabelsExposed
.Add( row
);
2783 void wxGrid::CalcColLabelsExposed( wxRegion
& reg
)
2785 wxRegionIterator
iter( reg
);
2788 m_colLabelsExposed
.Empty();
2795 // TODO: remove this when we can...
2796 // There is a bug in wxMotif that gives garbage update
2797 // rectangles if you jump-scroll a long way by clicking the
2798 // scrollbar with middle button. This is a work-around
2800 #if defined(__WXMOTIF__)
2802 m_gridWin
->GetClientSize( &cw
, &ch
);
2803 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
2804 r
.SetRight( wxMin( r
.GetRight(), cw
) );
2807 // logical bounds of update region
2810 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
2811 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
2813 // find the cells within these bounds
2816 for ( col
= 0; col
< m_numCols
; col
++ )
2818 if ( GetColRight(col
) < left
)
2821 if ( GetColLeft(col
) > right
)
2824 m_colLabelsExposed
.Add( col
);
2832 void wxGrid::CalcCellsExposed( wxRegion
& reg
)
2834 wxRegionIterator
iter( reg
);
2837 m_cellsExposed
.Empty();
2838 m_rowsExposed
.Empty();
2839 m_colsExposed
.Empty();
2841 int left
, top
, right
, bottom
;
2846 // TODO: remove this when we can...
2847 // There is a bug in wxMotif that gives garbage update
2848 // rectangles if you jump-scroll a long way by clicking the
2849 // scrollbar with middle button. This is a work-around
2851 #if defined(__WXMOTIF__)
2853 m_gridWin
->GetClientSize( &cw
, &ch
);
2854 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
2855 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
2856 r
.SetRight( wxMin( r
.GetRight(), cw
) );
2857 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
2860 // logical bounds of update region
2862 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
2863 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
2865 // find the cells within these bounds
2868 for ( row
= 0; row
< m_numRows
; row
++ )
2870 if ( GetRowBottom(row
) <= top
)
2873 if ( GetRowTop(row
) > bottom
)
2876 m_rowsExposed
.Add( row
);
2878 for ( col
= 0; col
< m_numCols
; col
++ )
2880 if ( GetColRight(col
) <= left
)
2883 if ( GetColLeft(col
) > right
)
2886 if ( m_colsExposed
.Index( col
) == wxNOT_FOUND
)
2887 m_colsExposed
.Add( col
);
2888 m_cellsExposed
.Add( wxGridCellCoords( row
, col
) );
2897 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
2900 wxPoint
pos( event
.GetPosition() );
2901 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2903 if ( event
.Dragging() )
2905 m_isDragging
= TRUE
;
2907 if ( event
.LeftIsDown() )
2909 switch( m_cursorMode
)
2911 case WXGRID_CURSOR_RESIZE_ROW
:
2913 int cw
, ch
, left
, dummy
;
2914 m_gridWin
->GetClientSize( &cw
, &ch
);
2915 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
2917 wxClientDC
dc( m_gridWin
);
2919 y
= wxMax( y
, GetRowTop(m_dragRowOrCol
) + WXGRID_MIN_ROW_HEIGHT
);
2920 dc
.SetLogicalFunction(wxINVERT
);
2921 if ( m_dragLastPos
>= 0 )
2923 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
2925 dc
.DrawLine( left
, y
, left
+cw
, y
);
2930 case WXGRID_CURSOR_SELECT_ROW
:
2931 if ( (row
= YToRow( y
)) >= 0 &&
2932 !IsInSelection( row
, 0 ) )
2934 SelectRow( row
, TRUE
);
2937 // default label to suppress warnings about "enumeration value
2938 // 'xxx' not handled in switch
2946 m_isDragging
= FALSE
;
2949 // ------------ Entering or leaving the window
2951 if ( event
.Entering() || event
.Leaving() )
2953 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
2957 // ------------ Left button pressed
2959 else if ( event
.LeftDown() )
2961 // don't send a label click event for a hit on the
2962 // edge of the row label - this is probably the user
2963 // wanting to resize the row
2965 if ( YToEdgeOfRow(y
) < 0 )
2969 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
2971 SelectRow( row
, event
.ShiftDown() );
2972 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
2977 // starting to drag-resize a row
2979 if ( CanDragRowSize() )
2980 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
2985 // ------------ Left double click
2987 else if (event
.LeftDClick() )
2989 if ( YToEdgeOfRow(y
) < 0 )
2992 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
);
2997 // ------------ Left button released
2999 else if ( event
.LeftUp() )
3001 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
3003 DoEndDragResizeRow();
3005 // Note: we are ending the event *after* doing
3006 // default processing in this case
3008 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
3011 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
3016 // ------------ Right button down
3018 else if ( event
.RightDown() )
3021 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
3023 // no default action at the moment
3028 // ------------ Right double click
3030 else if ( event
.RightDClick() )
3033 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
3035 // no default action at the moment
3040 // ------------ No buttons down and mouse moving
3042 else if ( event
.Moving() )
3044 m_dragRowOrCol
= YToEdgeOfRow( y
);
3045 if ( m_dragRowOrCol
>= 0 )
3047 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3049 // don't capture the mouse yet
3050 if ( CanDragRowSize() )
3051 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, FALSE
);
3054 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3056 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, FALSE
);
3062 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
3065 wxPoint
pos( event
.GetPosition() );
3066 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
3068 if ( event
.Dragging() )
3070 m_isDragging
= TRUE
;
3072 if ( event
.LeftIsDown() )
3074 switch( m_cursorMode
)
3076 case WXGRID_CURSOR_RESIZE_COL
:
3078 int cw
, ch
, dummy
, top
;
3079 m_gridWin
->GetClientSize( &cw
, &ch
);
3080 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
3082 wxClientDC
dc( m_gridWin
);
3085 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
3086 GetColMinimalWidth(m_dragRowOrCol
));
3087 dc
.SetLogicalFunction(wxINVERT
);
3088 if ( m_dragLastPos
>= 0 )
3090 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
3092 dc
.DrawLine( x
, top
, x
, top
+ch
);
3097 case WXGRID_CURSOR_SELECT_COL
:
3098 if ( (col
= XToCol( x
)) >= 0 &&
3099 !IsInSelection( 0, col
) )
3101 SelectCol( col
, TRUE
);
3104 // default label to suppress warnings about "enumeration value
3105 // 'xxx' not handled in switch
3113 m_isDragging
= FALSE
;
3116 // ------------ Entering or leaving the window
3118 if ( event
.Entering() || event
.Leaving() )
3120 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
3124 // ------------ Left button pressed
3126 else if ( event
.LeftDown() )
3128 // don't send a label click event for a hit on the
3129 // edge of the col label - this is probably the user
3130 // wanting to resize the col
3132 if ( XToEdgeOfCol(x
) < 0 )
3136 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
3138 SelectCol( col
, event
.ShiftDown() );
3139 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, m_colLabelWin
);
3144 // starting to drag-resize a col
3146 if ( CanDragColSize() )
3147 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
);
3152 // ------------ Left double click
3154 if ( event
.LeftDClick() )
3156 if ( XToEdgeOfCol(x
) < 0 )
3159 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
);
3164 // ------------ Left button released
3166 else if ( event
.LeftUp() )
3168 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
3170 DoEndDragResizeCol();
3172 // Note: we are ending the event *after* doing
3173 // default processing in this case
3175 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
3178 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
3183 // ------------ Right button down
3185 else if ( event
.RightDown() )
3188 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
3190 // no default action at the moment
3195 // ------------ Right double click
3197 else if ( event
.RightDClick() )
3200 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
3202 // no default action at the moment
3207 // ------------ No buttons down and mouse moving
3209 else if ( event
.Moving() )
3211 m_dragRowOrCol
= XToEdgeOfCol( x
);
3212 if ( m_dragRowOrCol
>= 0 )
3214 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3216 // don't capture the cursor yet
3217 if ( CanDragColSize() )
3218 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
, FALSE
);
3221 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3223 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
, FALSE
);
3229 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
3231 if ( event
.LeftDown() )
3233 // indicate corner label by having both row and
3236 if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
3242 else if ( event
.LeftDClick() )
3244 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
3247 else if ( event
.RightDown() )
3249 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
3251 // no default action at the moment
3255 else if ( event
.RightDClick() )
3257 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
3259 // no default action at the moment
3264 void wxGrid::ChangeCursorMode(CursorMode mode
,
3269 static const wxChar
*cursorModes
[] =
3278 wxLogTrace(_T("grid"),
3279 _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
3280 win
== m_colLabelWin
? _T("colLabelWin")
3281 : win
? _T("rowLabelWin")
3283 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
3284 #endif // __WXDEBUG__
3286 if ( mode
== m_cursorMode
)
3291 // by default use the grid itself
3297 m_winCapture
->ReleaseMouse();
3298 m_winCapture
= (wxWindow
*)NULL
;
3301 m_cursorMode
= mode
;
3303 switch ( m_cursorMode
)
3305 case WXGRID_CURSOR_RESIZE_ROW
:
3306 win
->SetCursor( m_rowResizeCursor
);
3309 case WXGRID_CURSOR_RESIZE_COL
:
3310 win
->SetCursor( m_colResizeCursor
);
3314 win
->SetCursor( *wxSTANDARD_CURSOR
);
3317 // we need to capture mouse when resizing
3318 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
3319 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
3321 if ( captureMouse
&& resize
)
3323 win
->CaptureMouse();
3328 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
3331 wxPoint
pos( event
.GetPosition() );
3332 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
3334 wxGridCellCoords coords
;
3335 XYToCell( x
, y
, coords
);
3337 if ( event
.Dragging() )
3339 //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
3341 // Don't start doing anything until the mouse has been drug at
3342 // least 3 pixels in any direction...
3345 if (m_startDragPos
== wxDefaultPosition
)
3347 m_startDragPos
= pos
;
3350 if (abs(m_startDragPos
.x
- pos
.x
) < 4 && abs(m_startDragPos
.y
- pos
.y
) < 4)
3354 m_isDragging
= TRUE
;
3355 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3357 // Hide the edit control, so it
3358 // won't interfer with drag-shrinking.
3359 if ( IsCellEditControlEnabled() )
3360 HideCellEditControl();
3362 // Have we captured the mouse yet?
3365 m_winCapture
= m_gridWin
;
3366 m_winCapture
->CaptureMouse();
3369 if ( coords
!= wxGridNoCellCoords
)
3371 if ( !IsSelection() )
3373 SelectBlock( coords
, coords
);
3377 SelectBlock( m_currentCellCoords
, coords
);
3380 if (! IsVisible(coords
))
3382 MakeCellVisible(coords
);
3383 // TODO: need to introduce a delay or something here. The
3384 // scrolling is way to fast, at least on MSW.
3388 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
3390 int cw
, ch
, left
, dummy
;
3391 m_gridWin
->GetClientSize( &cw
, &ch
);
3392 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
3394 wxClientDC
dc( m_gridWin
);
3396 y
= wxMax( y
, GetRowTop(m_dragRowOrCol
) + WXGRID_MIN_ROW_HEIGHT
);
3397 dc
.SetLogicalFunction(wxINVERT
);
3398 if ( m_dragLastPos
>= 0 )
3400 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
3402 dc
.DrawLine( left
, y
, left
+cw
, y
);
3405 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
3407 int cw
, ch
, dummy
, top
;
3408 m_gridWin
->GetClientSize( &cw
, &ch
);
3409 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
3411 wxClientDC
dc( m_gridWin
);
3413 x
= wxMax( x
, GetColLeft(m_dragRowOrCol
) +
3414 GetColMinimalWidth(m_dragRowOrCol
) );
3415 dc
.SetLogicalFunction(wxINVERT
);
3416 if ( m_dragLastPos
>= 0 )
3418 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
3420 dc
.DrawLine( x
, top
, x
, top
+ch
);
3427 m_isDragging
= FALSE
;
3428 m_startDragPos
= wxDefaultPosition
;
3431 if ( coords
!= wxGridNoCellCoords
)
3433 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
3434 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
3437 if ( event
.Entering() || event
.Leaving() )
3439 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3440 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
3445 // ------------ Left button pressed
3447 if ( event
.LeftDown() )
3449 DisableCellEditControl();
3450 if ( event
.ShiftDown() )
3452 SelectBlock( m_currentCellCoords
, coords
);
3454 else if ( XToEdgeOfCol(x
) < 0 &&
3455 YToEdgeOfRow(y
) < 0 )
3457 if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK
,
3462 MakeCellVisible( coords
);
3464 // if this is the second click on this cell then start
3466 if ( m_waitForSlowClick
&&
3467 (coords
== m_currentCellCoords
) &&
3468 CanEnableCellControl())
3470 EnableCellEditControl();
3472 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
3473 attr
->GetEditor(GetDefaultEditorForCell(coords
.GetRow(), coords
.GetCol()))->StartingClick();
3476 m_waitForSlowClick
= FALSE
;
3480 SetCurrentCell( coords
);
3481 m_waitForSlowClick
= TRUE
;
3488 // ------------ Left double click
3490 else if ( event
.LeftDClick() )
3492 DisableCellEditControl();
3493 if ( XToEdgeOfCol(x
) < 0 && YToEdgeOfRow(y
) < 0 )
3495 SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK
,
3503 // ------------ Left button released
3505 else if ( event
.LeftUp() )
3507 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3509 if ( IsSelection() )
3513 m_winCapture
->ReleaseMouse();
3514 m_winCapture
= NULL
;
3516 SendEvent( wxEVT_GRID_RANGE_SELECT
, -1, -1, event
);
3519 // Show the edit control, if it has been hidden for
3521 ShowCellEditControl();
3523 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
3525 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3526 DoEndDragResizeRow();
3528 // Note: we are ending the event *after* doing
3529 // default processing in this case
3531 SendEvent( wxEVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
3533 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
3535 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3536 DoEndDragResizeCol();
3538 // Note: we are ending the event *after* doing
3539 // default processing in this case
3541 SendEvent( wxEVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
3548 // ------------ Right button down
3550 else if ( event
.RightDown() )
3552 DisableCellEditControl();
3553 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK
,
3558 // no default action at the moment
3563 // ------------ Right double click
3565 else if ( event
.RightDClick() )
3567 DisableCellEditControl();
3568 if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK
,
3573 // no default action at the moment
3577 // ------------ Moving and no button action
3579 else if ( event
.Moving() && !event
.IsButton() )
3581 int dragRow
= YToEdgeOfRow( y
);
3582 int dragCol
= XToEdgeOfCol( x
);
3584 // Dragging on the corner of a cell to resize in both
3585 // directions is not implemented yet...
3587 if ( dragRow
>= 0 && dragCol
>= 0 )
3589 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3595 m_dragRowOrCol
= dragRow
;
3597 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3599 if ( CanDragRowSize() )
3600 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
);
3608 m_dragRowOrCol
= dragCol
;
3610 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3612 if ( CanDragColSize() )
3613 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
);
3619 // Neither on a row or col edge
3621 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3623 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3630 void wxGrid::DoEndDragResizeRow()
3632 if ( m_dragLastPos
>= 0 )
3634 // erase the last line and resize the row
3636 int cw
, ch
, left
, dummy
;
3637 m_gridWin
->GetClientSize( &cw
, &ch
);
3638 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
3640 wxClientDC
dc( m_gridWin
);
3642 dc
.SetLogicalFunction( wxINVERT
);
3643 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
3644 HideCellEditControl();
3646 int rowTop
= GetRowTop(m_dragRowOrCol
);
3647 SetRowSize( m_dragRowOrCol
,
3648 wxMax( m_dragLastPos
- rowTop
, WXGRID_MIN_ROW_HEIGHT
) );
3650 if ( !GetBatchCount() )
3652 // Only needed to get the correct rect.y:
3653 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
3655 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
3656 rect
.width
= m_rowLabelWidth
;
3657 rect
.height
= ch
- rect
.y
;
3658 m_rowLabelWin
->Refresh( TRUE
, &rect
);
3660 m_gridWin
->Refresh( FALSE
, &rect
);
3663 ShowCellEditControl();
3668 void wxGrid::DoEndDragResizeCol()
3670 if ( m_dragLastPos
>= 0 )
3672 // erase the last line and resize the col
3674 int cw
, ch
, dummy
, top
;
3675 m_gridWin
->GetClientSize( &cw
, &ch
);
3676 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
3678 wxClientDC
dc( m_gridWin
);
3680 dc
.SetLogicalFunction( wxINVERT
);
3681 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
3682 HideCellEditControl();
3684 int colLeft
= GetColLeft(m_dragRowOrCol
);
3685 SetColSize( m_dragRowOrCol
,
3686 wxMax( m_dragLastPos
- colLeft
,
3687 GetColMinimalWidth(m_dragRowOrCol
) ) );
3689 if ( !GetBatchCount() )
3691 // Only needed to get the correct rect.x:
3692 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
3694 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
3695 rect
.width
= cw
- rect
.x
;
3696 rect
.height
= m_colLabelHeight
;
3697 m_colLabelWin
->Refresh( TRUE
, &rect
);
3699 m_gridWin
->Refresh( FALSE
, &rect
);
3702 ShowCellEditControl();
3709 // ------ interaction with data model
3711 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
3713 switch ( msg
.GetId() )
3715 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
3716 return GetModelValues();
3718 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
3719 return SetModelValues();
3721 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
3722 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
3723 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
3724 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
3725 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
3726 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
3727 return Redimension( msg
);
3736 // The behaviour of this function depends on the grid table class
3737 // Clear() function. For the default wxGridStringTable class the
3738 // behavious is to replace all cell contents with wxEmptyString but
3739 // not to change the number of rows or cols.
3741 void wxGrid::ClearGrid()
3746 SetEditControlValue();
3747 if ( !GetBatchCount() ) m_gridWin
->Refresh();
3752 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
3754 // TODO: something with updateLabels flag
3758 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
3764 if (IsCellEditControlEnabled())
3765 DisableCellEditControl();
3767 bool ok
= m_table
->InsertRows( pos
, numRows
);
3769 // the table will have sent the results of the insert row
3770 // operation to this view object as a grid table message
3774 if ( m_numCols
== 0 )
3776 m_table
->AppendCols( WXGRID_DEFAULT_NUMBER_COLS
);
3778 // TODO: perhaps instead of appending the default number of cols
3779 // we should remember what the last non-zero number of cols was ?
3783 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3785 // if we have just inserted cols into an empty grid the current
3786 // cell will be undefined...
3788 SetCurrentCell( 0, 0 );
3792 if ( !GetBatchCount() ) Refresh();
3795 SetEditControlValue();
3805 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
3807 // TODO: something with updateLabels flag
3811 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
3815 if ( m_table
&& m_table
->AppendRows( numRows
) )
3817 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3819 // if we have just inserted cols into an empty grid the current
3820 // cell will be undefined...
3822 SetCurrentCell( 0, 0 );
3825 // the table will have sent the results of the append row
3826 // operation to this view object as a grid table message
3829 if ( !GetBatchCount() ) Refresh();
3839 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
3841 // TODO: something with updateLabels flag
3845 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
3851 if (IsCellEditControlEnabled())
3852 DisableCellEditControl();
3854 if (m_table
->DeleteRows( pos
, numRows
))
3857 // the table will have sent the results of the delete row
3858 // operation to this view object as a grid table message
3861 if ( !GetBatchCount() ) Refresh();
3869 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
3871 // TODO: something with updateLabels flag
3875 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
3881 if (IsCellEditControlEnabled())
3882 DisableCellEditControl();
3884 bool ok
= m_table
->InsertCols( pos
, numCols
);
3886 // the table will have sent the results of the insert col
3887 // operation to this view object as a grid table message
3891 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3893 // if we have just inserted cols into an empty grid the current
3894 // cell will be undefined...
3896 SetCurrentCell( 0, 0 );
3900 if ( !GetBatchCount() ) Refresh();
3903 SetEditControlValue();
3913 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
3915 // TODO: something with updateLabels flag
3919 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
3923 if ( m_table
&& m_table
->AppendCols( numCols
) )
3925 // the table will have sent the results of the append col
3926 // operation to this view object as a grid table message
3928 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3930 // if we have just inserted cols into an empty grid the current
3931 // cell will be undefined...
3933 SetCurrentCell( 0, 0 );
3937 if ( !GetBatchCount() ) Refresh();
3947 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
3949 // TODO: something with updateLabels flag
3953 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
3959 if (IsCellEditControlEnabled())
3960 DisableCellEditControl();
3962 if ( m_table
->DeleteCols( pos
, numCols
) )
3964 // the table will have sent the results of the delete col
3965 // operation to this view object as a grid table message
3968 if ( !GetBatchCount() ) Refresh();
3978 // ----- event handlers
3981 // Generate a grid event based on a mouse event and
3982 // return the result of ProcessEvent()
3984 bool wxGrid::SendEvent( const wxEventType type
,
3986 wxMouseEvent
& mouseEv
)
3988 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
3990 int rowOrCol
= (row
== -1 ? col
: row
);
3992 wxGridSizeEvent
gridEvt( GetId(),
3996 mouseEv
.GetX(), mouseEv
.GetY(),
3997 mouseEv
.ControlDown(),
3998 mouseEv
.ShiftDown(),
4000 mouseEv
.MetaDown() );
4002 return GetEventHandler()->ProcessEvent(gridEvt
);
4004 else if ( type
== wxEVT_GRID_RANGE_SELECT
)
4006 wxGridRangeSelectEvent
gridEvt( GetId(),
4010 m_selectedBottomRight
,
4011 mouseEv
.ControlDown(),
4012 mouseEv
.ShiftDown(),
4014 mouseEv
.MetaDown() );
4016 return GetEventHandler()->ProcessEvent(gridEvt
);
4020 wxGridEvent
gridEvt( GetId(),
4024 mouseEv
.GetX(), mouseEv
.GetY(),
4025 mouseEv
.ControlDown(),
4026 mouseEv
.ShiftDown(),
4028 mouseEv
.MetaDown() );
4030 return GetEventHandler()->ProcessEvent(gridEvt
);
4035 // Generate a grid event of specified type and return the result
4036 // of ProcessEvent().
4038 bool wxGrid::SendEvent( const wxEventType type
,
4041 if ( type
== wxEVT_GRID_ROW_SIZE
|| type
== wxEVT_GRID_COL_SIZE
)
4043 int rowOrCol
= (row
== -1 ? col
: row
);
4045 wxGridSizeEvent
gridEvt( GetId(),
4050 return GetEventHandler()->ProcessEvent(gridEvt
);
4054 wxGridEvent
gridEvt( GetId(),
4059 return GetEventHandler()->ProcessEvent(gridEvt
);
4064 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
4066 wxPaintDC
dc( this );
4068 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
4069 m_numRows
&& m_numCols
)
4071 m_currentCellCoords
.Set(0, 0);
4072 SetEditControlValue();
4073 ShowCellEditControl();
4080 // This is just here to make sure that CalcDimensions gets called when
4081 // the grid view is resized... then the size event is skipped to allow
4082 // the box sizers to handle everything
4084 void wxGrid::OnSize( wxSizeEvent
& event
)
4091 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
4093 if ( m_inOnKeyDown
)
4095 // shouldn't be here - we are going round in circles...
4097 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
4100 m_inOnKeyDown
= TRUE
;
4102 // propagate the event up and see if it gets processed
4104 wxWindow
*parent
= GetParent();
4105 wxKeyEvent
keyEvt( event
);
4106 keyEvt
.SetEventObject( parent
);
4108 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
4111 // TODO: Should also support Shift-cursor keys for
4112 // extending the selection. Maybe add a flag to
4113 // MoveCursorXXX() and MoveCursorXXXBlock() and
4114 // just send event.ShiftDown().
4116 // try local handlers
4118 switch ( event
.KeyCode() )
4121 if ( event
.ControlDown() )
4123 MoveCursorUpBlock();
4132 if ( event
.ControlDown() )
4134 MoveCursorDownBlock();
4143 if ( event
.ControlDown() )
4145 MoveCursorLeftBlock();
4154 if ( event
.ControlDown() )
4156 MoveCursorRightBlock();
4165 if ( event
.ControlDown() )
4167 event
.Skip(); // to let the edit control have the return
4176 if (event
.ShiftDown())
4183 if ( event
.ControlDown() )
4185 MakeCellVisible( 0, 0 );
4186 SetCurrentCell( 0, 0 );
4195 if ( event
.ControlDown() )
4197 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
4198 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
4214 // We don't want these keys to trigger the edit control, any others?
4223 if ( !IsEditable() )
4228 // Otherwise fall through to default
4231 // now try the cell edit control
4233 if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
4235 EnableCellEditControl();
4236 int row
= m_currentCellCoords
.GetRow();
4237 int col
= m_currentCellCoords
.GetCol();
4238 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4239 attr
->GetEditor(GetDefaultEditorForCell(row
, col
))->StartingKey(event
);
4244 // let others process char events for readonly cells
4251 m_inOnKeyDown
= FALSE
;
4255 void wxGrid::OnEraseBackground(wxEraseEvent
&)
4259 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
4261 if ( SendEvent( wxEVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
4263 // the event has been intercepted - do nothing
4268 m_currentCellCoords
!= wxGridNoCellCoords
)
4270 HideCellEditControl();
4271 SaveEditControlValue();
4272 DisableCellEditControl();
4274 // Clear the old current cell highlight
4275 wxRect r
= BlockToDeviceRect(m_currentCellCoords
, m_currentCellCoords
);
4277 // Otherwise refresh redraws the highlight!
4278 m_currentCellCoords
= coords
;
4280 m_gridWin
->Refresh( FALSE
, &r
);
4283 m_currentCellCoords
= coords
;
4285 SetEditControlValue();
4289 wxClientDC
dc(m_gridWin
);
4292 wxGridCellAttr
* attr
= GetCellAttr(coords
);
4293 DrawCellHighlight(dc
, attr
);
4296 if ( IsSelection() )
4298 wxRect
r( SelectionToDeviceRect() );
4300 if ( !GetBatchCount() ) m_gridWin
->Refresh( FALSE
, &r
);
4307 // ------ functions to get/send data (see also public functions)
4310 bool wxGrid::GetModelValues()
4314 // all we need to do is repaint the grid
4316 m_gridWin
->Refresh();
4324 bool wxGrid::SetModelValues()
4330 for ( row
= 0; row
< m_numRows
; row
++ )
4332 for ( col
= 0; col
< m_numCols
; col
++ )
4334 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
4346 // Note - this function only draws cells that are in the list of
4347 // exposed cells (usually set from the update region by
4348 // CalcExposedCells)
4350 void wxGrid::DrawGridCellArea( wxDC
& dc
)
4352 if ( !m_numRows
|| !m_numCols
) return;
4355 size_t numCells
= m_cellsExposed
.GetCount();
4357 for ( i
= 0; i
< numCells
; i
++ )
4359 DrawCell( dc
, m_cellsExposed
[i
] );
4364 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
4366 int row
= coords
.GetRow();
4367 int col
= coords
.GetCol();
4369 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
4372 // we draw the cell border ourselves
4373 #if !WXGRID_DRAW_LINES
4374 if ( m_gridLinesEnabled
)
4375 DrawCellBorder( dc
, coords
);
4378 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4380 bool isCurrent
= coords
== m_currentCellCoords
;
4383 rect
.x
= GetColLeft(col
);
4384 rect
.y
= GetRowTop(row
);
4385 rect
.width
= GetColWidth(col
) - 1;
4386 rect
.height
= GetRowHeight(row
) - 1;
4388 // if the editor is shown, we should use it and not the renderer
4389 if ( isCurrent
&& IsCellEditControlEnabled() )
4391 attr
->GetEditor(GetDefaultEditorForCell(row
, col
))->
4392 PaintBackground(rect
, attr
);
4396 // but all the rest is drawn by the cell renderer and hence may be
4398 attr
->GetRenderer(GetDefaultRendererForCell(row
,col
))->
4399 Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
4406 void wxGrid::DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
)
4408 int row
= m_currentCellCoords
.GetRow();
4409 int col
= m_currentCellCoords
.GetCol();
4411 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
4415 rect
.x
= GetColLeft(col
);
4416 rect
.y
= GetRowTop(row
);
4417 rect
.width
= GetColWidth(col
) - 1;
4418 rect
.height
= GetRowHeight(row
) - 1;
4420 // hmmm... what could we do here to show that the cell is disabled?
4421 // for now, I just draw a thinner border than for the other ones, but
4422 // it doesn't look really good
4423 dc
.SetPen(wxPen(m_gridLineColour
, attr
->IsReadOnly() ? 1 : 3, wxSOLID
));
4424 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
4426 dc
.DrawRectangle(rect
);
4429 // VZ: my experiments with 3d borders...
4431 // how to properly set colours for arbitrary bg?
4432 wxCoord x1
= rect
.x
,
4434 x2
= rect
.x
+ rect
.width
-1,
4435 y2
= rect
.y
+ rect
.height
-1;
4437 dc
.SetPen(*wxWHITE_PEN
);
4438 dc
.DrawLine(x1
, y1
, x2
, y1
);
4439 dc
.DrawLine(x1
, y1
, x1
, y2
);
4441 dc
.DrawLine(x1
+ 1, y2
- 1, x2
- 1, y2
- 1);
4442 dc
.DrawLine(x2
- 1, y1
+ 1, x2
- 1, y2
);
4444 dc
.SetPen(*wxBLACK_PEN
);
4445 dc
.DrawLine(x1
, y2
, x2
, y2
);
4446 dc
.DrawLine(x2
, y1
, x2
, y2
+1);
4451 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
4453 int row
= coords
.GetRow();
4454 int col
= coords
.GetCol();
4455 if ( GetColWidth(col
) <= 0 || GetRowHeight(row
) <= 0 )
4458 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
4460 // right hand border
4462 dc
.DrawLine( GetColRight(col
), GetRowTop(row
),
4463 GetColRight(col
), GetRowBottom(row
) );
4467 dc
.DrawLine( GetColLeft(col
), GetRowBottom(row
),
4468 GetColRight(col
), GetRowBottom(row
) );
4471 void wxGrid::DrawHighlight(wxDC
& dc
)
4473 // if the active cell was repainted, repaint its highlight too because it
4474 // might have been damaged by the grid lines
4475 size_t count
= m_cellsExposed
.GetCount();
4476 for ( size_t n
= 0; n
< count
; n
++ )
4478 if ( m_cellsExposed
[n
] == m_currentCellCoords
)
4480 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
4481 DrawCellHighlight(dc
, attr
);
4489 // TODO: remove this ???
4490 // This is used to redraw all grid lines e.g. when the grid line colour
4493 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
)
4495 if ( !m_gridLinesEnabled
||
4497 !m_numCols
) return;
4499 int top
, bottom
, left
, right
;
4504 m_gridWin
->GetClientSize(&cw
, &ch
);
4506 // virtual coords of visible area
4508 CalcUnscrolledPosition( 0, 0, &left
, &top
);
4509 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
4514 reg
.GetBox(x
, y
, w
, h
);
4515 CalcUnscrolledPosition( x
, y
, &left
, &top
);
4516 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
4519 // avoid drawing grid lines past the last row and col
4521 right
= wxMin( right
, GetColRight(m_numCols
- 1) );
4522 bottom
= wxMin( bottom
, GetRowBottom(m_numRows
- 1) );
4524 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
4526 // horizontal grid lines
4529 for ( i
= 0; i
< m_numRows
; i
++ )
4531 int bot
= GetRowBottom(i
) - 1;
4540 dc
.DrawLine( left
, bot
, right
, bot
);
4545 // vertical grid lines
4547 for ( i
= 0; i
< m_numCols
; i
++ )
4549 int colRight
= GetColRight(i
) - 1;
4550 if ( colRight
> right
)
4555 if ( colRight
>= left
)
4557 dc
.DrawLine( colRight
, top
, colRight
, bottom
);
4563 void wxGrid::DrawRowLabels( wxDC
& dc
)
4565 if ( !m_numRows
|| !m_numCols
) return;
4568 size_t numLabels
= m_rowLabelsExposed
.GetCount();
4570 for ( i
= 0; i
< numLabels
; i
++ )
4572 DrawRowLabel( dc
, m_rowLabelsExposed
[i
] );
4577 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
4579 if ( GetRowHeight(row
) <= 0 )
4582 int rowTop
= GetRowTop(row
),
4583 rowBottom
= GetRowBottom(row
) - 1;
4585 dc
.SetPen( *wxBLACK_PEN
);
4586 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
4587 m_rowLabelWidth
-1, rowBottom
);
4589 dc
.DrawLine( 0, rowBottom
, m_rowLabelWidth
-1, rowBottom
);
4591 dc
.SetPen( *wxWHITE_PEN
);
4592 dc
.DrawLine( 0, rowTop
, 0, rowBottom
);
4593 dc
.DrawLine( 0, rowTop
, m_rowLabelWidth
-1, rowTop
);
4595 dc
.SetBackgroundMode( wxTRANSPARENT
);
4596 dc
.SetTextForeground( GetLabelTextColour() );
4597 dc
.SetFont( GetLabelFont() );
4600 GetRowLabelAlignment( &hAlign
, &vAlign
);
4604 rect
.SetY( GetRowTop(row
) + 2 );
4605 rect
.SetWidth( m_rowLabelWidth
- 4 );
4606 rect
.SetHeight( GetRowHeight(row
) - 4 );
4607 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
4611 void wxGrid::DrawColLabels( wxDC
& dc
)
4613 if ( !m_numRows
|| !m_numCols
) return;
4616 size_t numLabels
= m_colLabelsExposed
.GetCount();
4618 for ( i
= 0; i
< numLabels
; i
++ )
4620 DrawColLabel( dc
, m_colLabelsExposed
[i
] );
4625 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
4627 if ( GetColWidth(col
) <= 0 )
4630 int colLeft
= GetColLeft(col
),
4631 colRight
= GetColRight(col
) - 1;
4633 dc
.SetPen( *wxBLACK_PEN
);
4634 dc
.DrawLine( colRight
, 0,
4635 colRight
, m_colLabelHeight
-1 );
4637 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
4638 colRight
, m_colLabelHeight
-1 );
4640 dc
.SetPen( *wxWHITE_PEN
);
4641 dc
.DrawLine( colLeft
, 0, colLeft
, m_colLabelHeight
-1 );
4642 dc
.DrawLine( colLeft
, 0, colRight
, 0 );
4644 dc
.SetBackgroundMode( wxTRANSPARENT
);
4645 dc
.SetTextForeground( GetLabelTextColour() );
4646 dc
.SetFont( GetLabelFont() );
4648 dc
.SetBackgroundMode( wxTRANSPARENT
);
4649 dc
.SetTextForeground( GetLabelTextColour() );
4650 dc
.SetFont( GetLabelFont() );
4653 GetColLabelAlignment( &hAlign
, &vAlign
);
4656 rect
.SetX( colLeft
+ 2 );
4658 rect
.SetWidth( GetColWidth(col
) - 4 );
4659 rect
.SetHeight( m_colLabelHeight
- 4 );
4660 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
);
4664 void wxGrid::DrawTextRectangle( wxDC
& dc
,
4665 const wxString
& value
,
4670 long textWidth
, textHeight
;
4671 long lineWidth
, lineHeight
;
4672 wxArrayString lines
;
4674 dc
.SetClippingRegion( rect
);
4675 StringToLines( value
, lines
);
4676 if ( lines
.GetCount() )
4678 GetTextBoxSize( dc
, lines
, &textWidth
, &textHeight
);
4679 dc
.GetTextExtent( lines
[0], &lineWidth
, &lineHeight
);
4682 switch ( horizAlign
)
4685 x
= rect
.x
+ (rect
.width
- textWidth
- 1);
4689 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
4698 switch ( vertAlign
)
4701 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
4705 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
4714 for ( size_t i
= 0; i
< lines
.GetCount(); i
++ )
4716 dc
.DrawText( lines
[i
], (long)x
, (long)y
);
4721 dc
.DestroyClippingRegion();
4725 // Split multi line text up into an array of strings. Any existing
4726 // contents of the string array are preserved.
4728 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
4732 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
4733 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
4735 while ( startPos
< (int)tVal
.Length() )
4737 pos
= tVal
.Mid(startPos
).Find( eol
);
4742 else if ( pos
== 0 )
4744 lines
.Add( wxEmptyString
);
4748 lines
.Add( value
.Mid(startPos
, pos
) );
4752 if ( startPos
< (int)value
.Length() )
4754 lines
.Add( value
.Mid( startPos
) );
4759 void wxGrid::GetTextBoxSize( wxDC
& dc
,
4760 wxArrayString
& lines
,
4761 long *width
, long *height
)
4768 for ( i
= 0; i
< lines
.GetCount(); i
++ )
4770 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
4771 w
= wxMax( w
, lineW
);
4781 // ------ Edit control functions
4785 void wxGrid::EnableEditing( bool edit
)
4787 // TODO: improve this ?
4789 if ( edit
!= m_editable
)
4793 // FIXME IMHO this won't disable the edit control if edit == FALSE
4794 // because of the check in the beginning of
4795 // EnableCellEditControl() just below (VZ)
4796 EnableCellEditControl(m_editable
);
4801 void wxGrid::EnableCellEditControl( bool enable
)
4806 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4807 SetCurrentCell( 0, 0 );
4809 if ( enable
!= m_cellEditCtrlEnabled
)
4811 // TODO allow the app to Veto() this event?
4812 SendEvent(enable
? wxEVT_GRID_EDITOR_SHOWN
: wxEVT_GRID_EDITOR_HIDDEN
);
4816 // this should be checked by the caller!
4817 wxASSERT_MSG( CanEnableCellControl(),
4818 _T("can't enable editing for this cell!") );
4820 // do it before ShowCellEditControl()
4821 m_cellEditCtrlEnabled
= enable
;
4823 SetEditControlValue();
4824 ShowCellEditControl();
4828 HideCellEditControl();
4829 SaveEditControlValue();
4831 // do it after HideCellEditControl()
4832 m_cellEditCtrlEnabled
= enable
;
4837 bool wxGrid::IsCurrentCellReadOnly() const
4840 wxGridCellAttr
* attr
= ((wxGrid
*)this)->GetCellAttr(m_currentCellCoords
);
4841 bool readonly
= attr
->IsReadOnly();
4847 bool wxGrid::CanEnableCellControl() const
4849 return m_editable
&& !IsCurrentCellReadOnly();
4852 bool wxGrid::IsCellEditControlEnabled() const
4854 // the cell edit control might be disable for all cells or just for the
4855 // current one if it's read only
4856 return m_cellEditCtrlEnabled
? !IsCurrentCellReadOnly() : FALSE
;
4859 wxWindow
*wxGrid::GetGridWindow() const
4864 void wxGrid::ShowCellEditControl()
4866 if ( IsCellEditControlEnabled() )
4868 if ( !IsVisible( m_currentCellCoords
) )
4874 wxRect rect
= CellToRect( m_currentCellCoords
);
4875 int row
= m_currentCellCoords
.GetRow();
4876 int col
= m_currentCellCoords
.GetCol();
4878 // convert to scrolled coords
4880 int left
, top
, right
, bottom
;
4881 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
4882 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
4884 // cell is shifted by one pixel
4890 // Make the edit control large enough to allow for internal
4893 // TODO: remove this if the text ctrl sizing is improved esp. for
4897 #if defined(__WXMOTIF__)
4898 if ( row
== 0 || col
== 0 )
4907 if ( row
== 0 || col
== 0 )
4917 #if defined(__WXGTK__)
4920 if (left
!= 0) left_diff
++;
4921 if (top
!= 0) top_diff
++;
4922 rect
.SetLeft( left
+ left_diff
);
4923 rect
.SetTop( top
+ top_diff
);
4924 rect
.SetRight( rect
.GetRight() - left_diff
);
4925 rect
.SetBottom( rect
.GetBottom() - top_diff
);
4927 rect
.SetLeft( wxMax(0, left
- extra
) );
4928 rect
.SetTop( wxMax(0, top
- extra
) );
4929 rect
.SetRight( rect
.GetRight() + 2*extra
);
4930 rect
.SetBottom( rect
.GetBottom() + 2*extra
);
4933 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4934 wxGridCellEditor
* editor
= attr
->GetEditor(GetDefaultEditorForCell(row
, col
));
4935 if ( !editor
->IsCreated() )
4937 editor
->Create(m_gridWin
, -1,
4938 new wxGridCellEditorEvtHandler(this, editor
));
4941 editor
->SetSize( rect
);
4942 editor
->Show( TRUE
, attr
);
4943 editor
->BeginEdit(row
, col
, this);
4950 void wxGrid::HideCellEditControl()
4952 if ( IsCellEditControlEnabled() )
4954 int row
= m_currentCellCoords
.GetRow();
4955 int col
= m_currentCellCoords
.GetCol();
4957 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4958 attr
->GetEditor(GetDefaultEditorForCell(row
, col
))->Show( FALSE
);
4960 m_gridWin
->SetFocus();
4965 void wxGrid::SetEditControlValue( const wxString
& value
)
4967 // RD: The new Editors get the value from the table themselves now. This
4968 // method can probably be removed...
4972 void wxGrid::SaveEditControlValue()
4974 if ( IsCellEditControlEnabled() )
4976 int row
= m_currentCellCoords
.GetRow();
4977 int col
= m_currentCellCoords
.GetCol();
4979 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4980 wxGridCellEditor
* editor
= attr
->GetEditor(GetDefaultEditorForCell(row
, col
));
4981 bool changed
= editor
->EndEdit(row
, col
, TRUE
, this);
4987 SendEvent( wxEVT_GRID_CELL_CHANGE
,
4988 m_currentCellCoords
.GetRow(),
4989 m_currentCellCoords
.GetCol() );
4996 // ------ Grid location functions
4997 // Note that all of these functions work with the logical coordinates of
4998 // grid cells and labels so you will need to convert from device
4999 // coordinates for mouse events etc.
5002 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
5004 int row
= YToRow(y
);
5005 int col
= XToCol(x
);
5007 if ( row
== -1 || col
== -1 )
5009 coords
= wxGridNoCellCoords
;
5013 coords
.Set( row
, col
);
5018 int wxGrid::YToRow( int y
)
5022 for ( i
= 0; i
< m_numRows
; i
++ )
5024 if ( y
< GetRowBottom(i
) )
5028 return m_numRows
; //-1;
5032 int wxGrid::XToCol( int x
)
5036 for ( i
= 0; i
< m_numCols
; i
++ )
5038 if ( x
< GetColRight(i
) )
5042 return m_numCols
; //-1;
5046 // return the row number that that the y coord is near the edge of, or
5047 // -1 if not near an edge
5049 int wxGrid::YToEdgeOfRow( int y
)
5053 for ( i
= 0; i
< m_numRows
; i
++ )
5055 if ( GetRowHeight(i
) > WXGRID_LABEL_EDGE_ZONE
)
5057 d
= abs( y
- GetRowBottom(i
) );
5058 if ( d
< WXGRID_LABEL_EDGE_ZONE
)
5067 // return the col number that that the x coord is near the edge of, or
5068 // -1 if not near an edge
5070 int wxGrid::XToEdgeOfCol( int x
)
5074 for ( i
= 0; i
< m_numCols
; i
++ )
5076 if ( GetColWidth(i
) > WXGRID_LABEL_EDGE_ZONE
)
5078 d
= abs( x
- GetColRight(i
) );
5079 if ( d
< WXGRID_LABEL_EDGE_ZONE
)
5088 wxRect
wxGrid::CellToRect( int row
, int col
)
5090 wxRect
rect( -1, -1, -1, -1 );
5092 if ( row
>= 0 && row
< m_numRows
&&
5093 col
>= 0 && col
< m_numCols
)
5095 rect
.x
= GetColLeft(col
);
5096 rect
.y
= GetRowTop(row
);
5097 rect
.width
= GetColWidth(col
);
5098 rect
.height
= GetRowHeight(row
);
5105 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
5107 // get the cell rectangle in logical coords
5109 wxRect
r( CellToRect( row
, col
) );
5111 // convert to device coords
5113 int left
, top
, right
, bottom
;
5114 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
5115 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
5117 // check against the client area of the grid window
5120 m_gridWin
->GetClientSize( &cw
, &ch
);
5122 if ( wholeCellVisible
)
5124 // is the cell wholly visible ?
5126 return ( left
>= 0 && right
<= cw
&&
5127 top
>= 0 && bottom
<= ch
);
5131 // is the cell partly visible ?
5133 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
5134 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
5139 // make the specified cell location visible by doing a minimal amount
5142 void wxGrid::MakeCellVisible( int row
, int col
)
5145 int xpos
= -1, ypos
= -1;
5147 if ( row
>= 0 && row
< m_numRows
&&
5148 col
>= 0 && col
< m_numCols
)
5150 // get the cell rectangle in logical coords
5152 wxRect
r( CellToRect( row
, col
) );
5154 // convert to device coords
5156 int left
, top
, right
, bottom
;
5157 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
5158 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
5161 m_gridWin
->GetClientSize( &cw
, &ch
);
5167 else if ( bottom
> ch
)
5169 int h
= r
.GetHeight();
5171 for ( i
= row
-1; i
>= 0; i
-- )
5173 int rowHeight
= GetRowHeight(i
);
5174 if ( h
+ rowHeight
> ch
)
5181 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
5182 // have rounding errors (this is important, because if we do, we
5183 // might not scroll at all and some cells won't be redrawn)
5184 ypos
+= GRID_SCROLL_LINE
/ 2;
5191 else if ( right
> cw
)
5193 int w
= r
.GetWidth();
5195 for ( i
= col
-1; i
>= 0; i
-- )
5197 int colWidth
= GetColWidth(i
);
5198 if ( w
+ colWidth
> cw
)
5205 // see comment for ypos above
5206 xpos
+= GRID_SCROLL_LINE
/ 2;
5209 if ( xpos
!= -1 || ypos
!= -1 )
5211 if ( xpos
!= -1 ) xpos
/= GRID_SCROLL_LINE
;
5212 if ( ypos
!= -1 ) ypos
/= GRID_SCROLL_LINE
;
5213 Scroll( xpos
, ypos
);
5221 // ------ Grid cursor movement functions
5224 bool wxGrid::MoveCursorUp()
5226 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
5227 m_currentCellCoords
.GetRow() > 0 )
5229 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
5230 m_currentCellCoords
.GetCol() );
5232 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
5233 m_currentCellCoords
.GetCol() );
5242 bool wxGrid::MoveCursorDown()
5244 // TODO: allow for scrolling
5246 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
5247 m_currentCellCoords
.GetRow() < m_numRows
-1 )
5249 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
5250 m_currentCellCoords
.GetCol() );
5252 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
5253 m_currentCellCoords
.GetCol() );
5262 bool wxGrid::MoveCursorLeft()
5264 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
5265 m_currentCellCoords
.GetCol() > 0 )
5267 MakeCellVisible( m_currentCellCoords
.GetRow(),
5268 m_currentCellCoords
.GetCol() - 1 );
5270 SetCurrentCell( m_currentCellCoords
.GetRow(),
5271 m_currentCellCoords
.GetCol() - 1 );
5280 bool wxGrid::MoveCursorRight()
5282 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
5283 m_currentCellCoords
.GetCol() < m_numCols
- 1 )
5285 MakeCellVisible( m_currentCellCoords
.GetRow(),
5286 m_currentCellCoords
.GetCol() + 1 );
5288 SetCurrentCell( m_currentCellCoords
.GetRow(),
5289 m_currentCellCoords
.GetCol() + 1 );
5298 bool wxGrid::MovePageUp()
5300 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
5302 int row
= m_currentCellCoords
.GetRow();
5306 m_gridWin
->GetClientSize( &cw
, &ch
);
5308 int y
= GetRowTop(row
);
5309 int newRow
= YToRow( y
- ch
+ 1 );
5314 else if ( newRow
== row
)
5319 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
5320 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
5328 bool wxGrid::MovePageDown()
5330 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
5332 int row
= m_currentCellCoords
.GetRow();
5333 if ( row
< m_numRows
)
5336 m_gridWin
->GetClientSize( &cw
, &ch
);
5338 int y
= GetRowTop(row
);
5339 int newRow
= YToRow( y
+ ch
);
5342 newRow
= m_numRows
- 1;
5344 else if ( newRow
== row
)
5349 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
5350 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
5358 bool wxGrid::MoveCursorUpBlock()
5361 m_currentCellCoords
!= wxGridNoCellCoords
&&
5362 m_currentCellCoords
.GetRow() > 0 )
5364 int row
= m_currentCellCoords
.GetRow();
5365 int col
= m_currentCellCoords
.GetCol();
5367 if ( m_table
->IsEmptyCell(row
, col
) )
5369 // starting in an empty cell: find the next block of
5375 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5378 else if ( m_table
->IsEmptyCell(row
-1, col
) )
5380 // starting at the top of a block: find the next block
5386 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5391 // starting within a block: find the top of the block
5396 if ( m_table
->IsEmptyCell(row
, col
) )
5404 MakeCellVisible( row
, col
);
5405 SetCurrentCell( row
, col
);
5413 bool wxGrid::MoveCursorDownBlock()
5416 m_currentCellCoords
!= wxGridNoCellCoords
&&
5417 m_currentCellCoords
.GetRow() < m_numRows
-1 )
5419 int row
= m_currentCellCoords
.GetRow();
5420 int col
= m_currentCellCoords
.GetCol();
5422 if ( m_table
->IsEmptyCell(row
, col
) )
5424 // starting in an empty cell: find the next block of
5427 while ( row
< m_numRows
-1 )
5430 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5433 else if ( m_table
->IsEmptyCell(row
+1, col
) )
5435 // starting at the bottom of a block: find the next block
5438 while ( row
< m_numRows
-1 )
5441 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5446 // starting within a block: find the bottom of the block
5448 while ( row
< m_numRows
-1 )
5451 if ( m_table
->IsEmptyCell(row
, col
) )
5459 MakeCellVisible( row
, col
);
5460 SetCurrentCell( row
, col
);
5468 bool wxGrid::MoveCursorLeftBlock()
5471 m_currentCellCoords
!= wxGridNoCellCoords
&&
5472 m_currentCellCoords
.GetCol() > 0 )
5474 int row
= m_currentCellCoords
.GetRow();
5475 int col
= m_currentCellCoords
.GetCol();
5477 if ( m_table
->IsEmptyCell(row
, col
) )
5479 // starting in an empty cell: find the next block of
5485 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5488 else if ( m_table
->IsEmptyCell(row
, col
-1) )
5490 // starting at the left of a block: find the next block
5496 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5501 // starting within a block: find the left of the block
5506 if ( m_table
->IsEmptyCell(row
, col
) )
5514 MakeCellVisible( row
, col
);
5515 SetCurrentCell( row
, col
);
5523 bool wxGrid::MoveCursorRightBlock()
5526 m_currentCellCoords
!= wxGridNoCellCoords
&&
5527 m_currentCellCoords
.GetCol() < m_numCols
-1 )
5529 int row
= m_currentCellCoords
.GetRow();
5530 int col
= m_currentCellCoords
.GetCol();
5532 if ( m_table
->IsEmptyCell(row
, col
) )
5534 // starting in an empty cell: find the next block of
5537 while ( col
< m_numCols
-1 )
5540 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5543 else if ( m_table
->IsEmptyCell(row
, col
+1) )
5545 // starting at the right of a block: find the next block
5548 while ( col
< m_numCols
-1 )
5551 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
5556 // starting within a block: find the right of the block
5558 while ( col
< m_numCols
-1 )
5561 if ( m_table
->IsEmptyCell(row
, col
) )
5569 MakeCellVisible( row
, col
);
5570 SetCurrentCell( row
, col
);
5581 // ------ Label values and formatting
5584 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
5586 *horiz
= m_rowLabelHorizAlign
;
5587 *vert
= m_rowLabelVertAlign
;
5590 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
5592 *horiz
= m_colLabelHorizAlign
;
5593 *vert
= m_colLabelVertAlign
;
5596 wxString
wxGrid::GetRowLabelValue( int row
)
5600 return m_table
->GetRowLabelValue( row
);
5610 wxString
wxGrid::GetColLabelValue( int col
)
5614 return m_table
->GetColLabelValue( col
);
5625 void wxGrid::SetRowLabelSize( int width
)
5627 width
= wxMax( width
, 0 );
5628 if ( width
!= m_rowLabelWidth
)
5632 m_rowLabelWin
->Show( FALSE
);
5633 m_cornerLabelWin
->Show( FALSE
);
5635 else if ( m_rowLabelWidth
== 0 )
5637 m_rowLabelWin
->Show( TRUE
);
5638 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
5641 m_rowLabelWidth
= width
;
5648 void wxGrid::SetColLabelSize( int height
)
5650 height
= wxMax( height
, 0 );
5651 if ( height
!= m_colLabelHeight
)
5655 m_colLabelWin
->Show( FALSE
);
5656 m_cornerLabelWin
->Show( FALSE
);
5658 else if ( m_colLabelHeight
== 0 )
5660 m_colLabelWin
->Show( TRUE
);
5661 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
5664 m_colLabelHeight
= height
;
5671 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
5673 if ( m_labelBackgroundColour
!= colour
)
5675 m_labelBackgroundColour
= colour
;
5676 m_rowLabelWin
->SetBackgroundColour( colour
);
5677 m_colLabelWin
->SetBackgroundColour( colour
);
5678 m_cornerLabelWin
->SetBackgroundColour( colour
);
5680 if ( !GetBatchCount() )
5682 m_rowLabelWin
->Refresh();
5683 m_colLabelWin
->Refresh();
5684 m_cornerLabelWin
->Refresh();
5689 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
5691 if ( m_labelTextColour
!= colour
)
5693 m_labelTextColour
= colour
;
5694 if ( !GetBatchCount() )
5696 m_rowLabelWin
->Refresh();
5697 m_colLabelWin
->Refresh();
5702 void wxGrid::SetLabelFont( const wxFont
& font
)
5705 if ( !GetBatchCount() )
5707 m_rowLabelWin
->Refresh();
5708 m_colLabelWin
->Refresh();
5712 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
5714 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
5716 m_rowLabelHorizAlign
= horiz
;
5719 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
5721 m_rowLabelVertAlign
= vert
;
5724 if ( !GetBatchCount() )
5726 m_rowLabelWin
->Refresh();
5730 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
5732 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
5734 m_colLabelHorizAlign
= horiz
;
5737 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
5739 m_colLabelVertAlign
= vert
;
5742 if ( !GetBatchCount() )
5744 m_colLabelWin
->Refresh();
5748 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
5752 m_table
->SetRowLabelValue( row
, s
);
5753 if ( !GetBatchCount() )
5755 wxRect rect
= CellToRect( row
, 0);
5756 if ( rect
.height
> 0 )
5758 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
5760 rect
.width
= m_rowLabelWidth
;
5761 m_rowLabelWin
->Refresh( TRUE
, &rect
);
5767 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
5771 m_table
->SetColLabelValue( col
, s
);
5772 if ( !GetBatchCount() )
5774 wxRect rect
= CellToRect( 0, col
);
5775 if ( rect
.width
> 0 )
5777 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
5779 rect
.height
= m_colLabelHeight
;
5780 m_colLabelWin
->Refresh( TRUE
, &rect
);
5786 void wxGrid::SetGridLineColour( const wxColour
& colour
)
5788 if ( m_gridLineColour
!= colour
)
5790 m_gridLineColour
= colour
;
5792 wxClientDC
dc( m_gridWin
);
5794 DrawAllGridLines( dc
, wxRegion() );
5798 void wxGrid::EnableGridLines( bool enable
)
5800 if ( enable
!= m_gridLinesEnabled
)
5802 m_gridLinesEnabled
= enable
;
5804 if ( !GetBatchCount() )
5808 wxClientDC
dc( m_gridWin
);
5810 DrawAllGridLines( dc
, wxRegion() );
5814 m_gridWin
->Refresh();
5821 int wxGrid::GetDefaultRowSize()
5823 return m_defaultRowHeight
;
5826 int wxGrid::GetRowSize( int row
)
5828 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
5830 return GetRowHeight(row
);
5833 int wxGrid::GetDefaultColSize()
5835 return m_defaultColWidth
;
5838 int wxGrid::GetColSize( int col
)
5840 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
5842 return GetColWidth(col
);
5845 // ============================================================================
5846 // access to the grid attributes: each of them has a default value in the grid
5847 // itself and may be overidden on a per-cell basis
5848 // ============================================================================
5850 // ----------------------------------------------------------------------------
5851 // setting default attributes
5852 // ----------------------------------------------------------------------------
5854 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
5856 m_defaultCellAttr
->SetBackgroundColour(col
);
5858 m_gridWin
->SetBackgroundColour(col
);
5862 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
5864 m_defaultCellAttr
->SetTextColour(col
);
5867 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
5869 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
5872 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
5874 m_defaultCellAttr
->SetFont(font
);
5877 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
5879 m_defaultCellAttr
->SetRenderer(renderer
);
5882 void wxGrid::SetDefaultEditor(wxGridCellEditor
*editor
)
5884 m_defaultCellAttr
->SetEditor(editor
);
5887 // ----------------------------------------------------------------------------
5888 // access to the default attrbiutes
5889 // ----------------------------------------------------------------------------
5891 wxColour
wxGrid::GetDefaultCellBackgroundColour()
5893 return m_defaultCellAttr
->GetBackgroundColour();
5896 wxColour
wxGrid::GetDefaultCellTextColour()
5898 return m_defaultCellAttr
->GetTextColour();
5901 wxFont
wxGrid::GetDefaultCellFont()
5903 return m_defaultCellAttr
->GetFont();
5906 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
5908 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
5911 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
5913 return m_defaultCellAttr
->GetRenderer(NULL
);
5916 wxGridCellEditor
*wxGrid::GetDefaultEditor() const
5918 return m_defaultCellAttr
->GetEditor(NULL
);
5921 // ----------------------------------------------------------------------------
5922 // access to cell attributes
5923 // ----------------------------------------------------------------------------
5925 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
5927 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5928 wxColour colour
= attr
->GetBackgroundColour();
5933 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
5935 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5936 wxColour colour
= attr
->GetTextColour();
5941 wxFont
wxGrid::GetCellFont( int row
, int col
)
5943 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5944 wxFont font
= attr
->GetFont();
5949 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
5951 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5952 attr
->GetAlignment(horiz
, vert
);
5956 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
)
5958 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5959 wxGridCellRenderer
* renderer
= attr
->GetRenderer(GetDefaultRendererForCell(row
,col
));
5964 wxGridCellEditor
* wxGrid::GetCellEditor(int row
, int col
)
5966 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5967 wxGridCellEditor
* editor
= attr
->GetEditor(GetDefaultEditorForCell(row
, col
));
5972 bool wxGrid::IsReadOnly(int row
, int col
) const
5974 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5975 bool isReadOnly
= attr
->IsReadOnly();
5980 // ----------------------------------------------------------------------------
5981 // attribute support: cache, automatic provider creation, ...
5982 // ----------------------------------------------------------------------------
5984 bool wxGrid::CanHaveAttributes()
5991 return m_table
->CanHaveAttributes();
5994 void wxGrid::ClearAttrCache()
5996 if ( m_attrCache
.row
!= -1 )
5998 m_attrCache
.attr
->SafeDecRef();
5999 m_attrCache
.row
= -1;
6003 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
6005 wxGrid
*self
= (wxGrid
*)this; // const_cast
6007 self
->ClearAttrCache();
6008 self
->m_attrCache
.row
= row
;
6009 self
->m_attrCache
.col
= col
;
6010 self
->m_attrCache
.attr
= attr
;
6014 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
6016 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
6018 *attr
= m_attrCache
.attr
;
6019 (*attr
)->SafeIncRef();
6021 #ifdef DEBUG_ATTR_CACHE
6022 gs_nAttrCacheHits
++;
6029 #ifdef DEBUG_ATTR_CACHE
6030 gs_nAttrCacheMisses
++;
6036 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
6038 wxGridCellAttr
*attr
;
6039 if ( !LookupAttr(row
, col
, &attr
) )
6041 attr
= m_table
? m_table
->GetAttr(row
, col
) : (wxGridCellAttr
*)NULL
;
6042 CacheAttr(row
, col
, attr
);
6046 attr
->SetDefAttr(m_defaultCellAttr
);
6050 attr
= m_defaultCellAttr
;
6057 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
6059 wxGridCellAttr
*attr
;
6060 if ( !LookupAttr(row
, col
, &attr
) || !attr
)
6062 wxASSERT_MSG( m_table
,
6063 _T("we may only be called if CanHaveAttributes() "
6064 "returned TRUE and then m_table should be !NULL") );
6066 attr
= m_table
->GetAttr(row
, col
);
6069 attr
= new wxGridCellAttr
;
6071 // artificially inc the ref count to match DecRef() in caller
6074 m_table
->SetAttr(attr
, row
, col
);
6077 CacheAttr(row
, col
, attr
);
6079 attr
->SetDefAttr(m_defaultCellAttr
);
6083 // ----------------------------------------------------------------------------
6084 // setting cell attributes: this is forwarded to the table
6085 // ----------------------------------------------------------------------------
6087 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
6089 if ( CanHaveAttributes() )
6091 m_table
->SetRowAttr(attr
, row
);
6099 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
6101 if ( CanHaveAttributes() )
6103 m_table
->SetColAttr(attr
, col
);
6111 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
6113 if ( CanHaveAttributes() )
6115 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6116 attr
->SetBackgroundColour(colour
);
6121 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
6123 if ( CanHaveAttributes() )
6125 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6126 attr
->SetTextColour(colour
);
6131 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
6133 if ( CanHaveAttributes() )
6135 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6136 attr
->SetFont(font
);
6141 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
6143 if ( CanHaveAttributes() )
6145 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6146 attr
->SetAlignment(horiz
, vert
);
6151 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
6153 if ( CanHaveAttributes() )
6155 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6156 attr
->SetRenderer(renderer
);
6161 void wxGrid::SetCellEditor(int row
, int col
, wxGridCellEditor
* editor
)
6163 if ( CanHaveAttributes() )
6165 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6166 attr
->SetEditor(editor
);
6171 void wxGrid::SetReadOnly(int row
, int col
, bool isReadOnly
)
6173 if ( CanHaveAttributes() )
6175 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
6176 attr
->SetReadOnly(isReadOnly
);
6181 // ----------------------------------------------------------------------------
6182 // Data type registration
6183 // ----------------------------------------------------------------------------
6185 void wxGrid::RegisterDataType(const wxString
& typeName
,
6186 wxGridCellRenderer
* renderer
,
6187 wxGridCellEditor
* editor
)
6189 m_typeRegistry
->RegisterDataType(typeName
, renderer
, editor
);
6193 wxGridCellEditor
* wxGrid::GetDefaultEditorForCell(int row
, int col
)
6195 wxString typeName
= m_table
->GetTypeName(row
, col
);
6196 return GetDefaultEditorForType(typeName
);
6199 wxGridCellRenderer
* wxGrid::GetDefaultRendererForCell(int row
, int col
)
6201 wxString typeName
= m_table
->GetTypeName(row
, col
);
6202 return GetDefaultRendererForType(typeName
);
6205 wxGridCellEditor
* wxGrid::GetDefaultEditorForType(const wxString
& typeName
)
6207 int index
= m_typeRegistry
->FindDataType(typeName
);
6209 // Should we force the failure here or let it fallback to string handling???
6210 // wxFAIL_MSG(wxT("Unknown data type name"));
6213 return m_typeRegistry
->GetEditor(index
);
6216 wxGridCellRenderer
* wxGrid::GetDefaultRendererForType(const wxString
& typeName
)
6218 int index
= m_typeRegistry
->FindDataType(typeName
);
6220 // Should we force the failure here or let it fallback to string handling???
6221 // wxFAIL_MSG(wxT("Unknown data type name"));
6224 return m_typeRegistry
->GetRenderer(index
);
6228 // ----------------------------------------------------------------------------
6230 // ----------------------------------------------------------------------------
6232 void wxGrid::EnableDragRowSize( bool enable
)
6234 m_canDragRowSize
= enable
;
6238 void wxGrid::EnableDragColSize( bool enable
)
6240 m_canDragColSize
= enable
;
6244 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
6246 m_defaultRowHeight
= wxMax( height
, WXGRID_MIN_ROW_HEIGHT
);
6248 if ( resizeExistingRows
)
6256 void wxGrid::SetRowSize( int row
, int height
)
6258 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
6260 if ( m_rowHeights
.IsEmpty() )
6262 // need to really create the array
6266 int h
= wxMax( 0, height
);
6267 int diff
= h
- m_rowHeights
[row
];
6269 m_rowHeights
[row
] = h
;
6271 for ( i
= row
; i
< m_numRows
; i
++ )
6273 m_rowBottoms
[i
] += diff
;
6278 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
6280 m_defaultColWidth
= wxMax( width
, WXGRID_MIN_COL_WIDTH
);
6282 if ( resizeExistingCols
)
6290 void wxGrid::SetColSize( int col
, int width
)
6292 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
6294 // should we check that it's bigger than GetColMinimalWidth(col) here?
6296 if ( m_colWidths
.IsEmpty() )
6298 // need to really create the array
6302 int w
= wxMax( 0, width
);
6303 int diff
= w
- m_colWidths
[col
];
6304 m_colWidths
[col
] = w
;
6307 for ( i
= col
; i
< m_numCols
; i
++ )
6309 m_colRights
[i
] += diff
;
6315 void wxGrid::SetColMinimalWidth( int col
, int width
)
6317 m_colMinWidths
.Put(col
, (wxObject
*)width
);
6320 int wxGrid::GetColMinimalWidth(int col
) const
6322 wxObject
*obj
= m_colMinWidths
.Get(m_dragRowOrCol
);
6323 return obj
? (int)obj
: WXGRID_MIN_COL_WIDTH
;
6327 // ------ cell value accessor functions
6330 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
6334 m_table
->SetValue( row
, col
, s
.c_str() );
6335 if ( !GetBatchCount() )
6337 wxClientDC
dc( m_gridWin
);
6339 DrawCell( dc
, wxGridCellCoords(row
, col
) );
6342 #if 0 // TODO: edit in place
6344 if ( m_currentCellCoords
.GetRow() == row
&&
6345 m_currentCellCoords
.GetCol() == col
)
6347 SetEditControlValue( s
);
6356 // ------ Block, row and col selection
6359 void wxGrid::SelectRow( int row
, bool addToSelected
)
6363 if ( IsSelection() && addToSelected
)
6366 bool need_refresh
[4];
6370 need_refresh
[3] = FALSE
;
6374 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
6375 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
6376 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
6377 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
6381 need_refresh
[0] = TRUE
;
6382 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( row
, 0 ),
6383 wxGridCellCoords ( oldTop
- 1,
6385 m_selectedTopLeft
.SetRow( row
);
6390 need_refresh
[1] = TRUE
;
6391 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
, 0 ),
6392 wxGridCellCoords ( oldBottom
,
6395 m_selectedTopLeft
.SetCol( 0 );
6398 if ( oldBottom
< row
)
6400 need_refresh
[2] = TRUE
;
6401 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1, 0 ),
6402 wxGridCellCoords ( row
,
6404 m_selectedBottomRight
.SetRow( row
);
6407 if ( oldRight
< m_numCols
- 1 )
6409 need_refresh
[3] = TRUE
;
6410 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6412 wxGridCellCoords ( oldBottom
,
6414 m_selectedBottomRight
.SetCol( m_numCols
- 1 );
6417 for (i
= 0; i
< 4; i
++ )
6418 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
6419 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
6423 r
= SelectionToDeviceRect();
6425 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
6427 m_selectedTopLeft
.Set( row
, 0 );
6428 m_selectedBottomRight
.Set( row
, m_numCols
-1 );
6429 r
= SelectionToDeviceRect();
6430 m_gridWin
->Refresh( FALSE
, &r
);
6433 wxGridRangeSelectEvent
gridEvt( GetId(),
6434 wxEVT_GRID_RANGE_SELECT
,
6437 m_selectedBottomRight
);
6439 GetEventHandler()->ProcessEvent(gridEvt
);
6443 void wxGrid::SelectCol( int col
, bool addToSelected
)
6445 if ( IsSelection() && addToSelected
)
6448 bool need_refresh
[4];
6452 need_refresh
[3] = FALSE
;
6455 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
6456 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
6457 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
6458 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
6460 if ( oldLeft
> col
)
6462 need_refresh
[0] = TRUE
;
6463 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( 0, col
),
6464 wxGridCellCoords ( m_numRows
- 1,
6466 m_selectedTopLeft
.SetCol( col
);
6471 need_refresh
[1] = TRUE
;
6472 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( 0, oldLeft
),
6473 wxGridCellCoords ( oldTop
- 1,
6475 m_selectedTopLeft
.SetRow( 0 );
6478 if ( oldRight
< col
)
6480 need_refresh
[2] = TRUE
;
6481 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( 0, oldRight
+ 1 ),
6482 wxGridCellCoords ( m_numRows
- 1,
6484 m_selectedBottomRight
.SetCol( col
);
6487 if ( oldBottom
< m_numRows
- 1 )
6489 need_refresh
[3] = TRUE
;
6490 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1,
6492 wxGridCellCoords ( m_numRows
- 1,
6494 m_selectedBottomRight
.SetRow( m_numRows
- 1 );
6497 for (i
= 0; i
< 4; i
++ )
6498 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
6499 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
6505 r
= SelectionToDeviceRect();
6507 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
6509 m_selectedTopLeft
.Set( 0, col
);
6510 m_selectedBottomRight
.Set( m_numRows
-1, col
);
6511 r
= SelectionToDeviceRect();
6512 m_gridWin
->Refresh( FALSE
, &r
);
6515 wxGridRangeSelectEvent
gridEvt( GetId(),
6516 wxEVT_GRID_RANGE_SELECT
,
6519 m_selectedBottomRight
);
6521 GetEventHandler()->ProcessEvent(gridEvt
);
6525 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
6528 wxGridCellCoords updateTopLeft
, updateBottomRight
;
6530 if ( topRow
> bottomRow
)
6537 if ( leftCol
> rightCol
)
6544 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
6545 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
6547 if ( m_selectedTopLeft
!= updateTopLeft
||
6548 m_selectedBottomRight
!= updateBottomRight
)
6550 // Compute two optimal update rectangles:
6551 // Either one rectangle is a real subset of the
6552 // other, or they are (almost) disjoint!
6554 bool need_refresh
[4];
6558 need_refresh
[3] = FALSE
;
6561 // Store intermediate values
6562 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
6563 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
6564 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
6565 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
6567 // Determine the outer/inner coordinates.
6568 if (oldLeft
> leftCol
)
6574 if (oldTop
> topRow
)
6580 if (oldRight
< rightCol
)
6583 oldRight
= rightCol
;
6586 if (oldBottom
< bottomRow
)
6589 oldBottom
= bottomRow
;
6593 // Now, either the stuff marked old is the outer
6594 // rectangle or we don't have a situation where one
6595 // is contained in the other.
6597 if ( oldLeft
< leftCol
)
6599 need_refresh
[0] = TRUE
;
6600 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6602 wxGridCellCoords ( oldBottom
,
6606 if ( oldTop
< topRow
)
6608 need_refresh
[1] = TRUE
;
6609 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6611 wxGridCellCoords ( topRow
- 1,
6615 if ( oldRight
> rightCol
)
6617 need_refresh
[2] = TRUE
;
6618 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
6620 wxGridCellCoords ( oldBottom
,
6624 if ( oldBottom
> bottomRow
)
6626 need_refresh
[3] = TRUE
;
6627 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
6629 wxGridCellCoords ( oldBottom
,
6635 m_selectedTopLeft
= updateTopLeft
;
6636 m_selectedBottomRight
= updateBottomRight
;
6638 // various Refresh() calls
6639 for (i
= 0; i
< 4; i
++ )
6640 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
6641 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
6644 // only generate an event if the block is not being selected by
6645 // dragging the mouse (in which case the event will be generated in
6646 // the mouse event handler)
6647 if ( !m_isDragging
)
6649 wxGridRangeSelectEvent
gridEvt( GetId(),
6650 wxEVT_GRID_RANGE_SELECT
,
6653 m_selectedBottomRight
);
6655 GetEventHandler()->ProcessEvent(gridEvt
);
6659 void wxGrid::SelectAll()
6661 m_selectedTopLeft
.Set( 0, 0 );
6662 m_selectedBottomRight
.Set( m_numRows
-1, m_numCols
-1 );
6664 m_gridWin
->Refresh();
6668 void wxGrid::ClearSelection()
6670 m_selectedTopLeft
= wxGridNoCellCoords
;
6671 m_selectedBottomRight
= wxGridNoCellCoords
;
6675 // This function returns the rectangle that encloses the given block
6676 // in device coords clipped to the client size of the grid window.
6678 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
6679 const wxGridCellCoords
&bottomRight
)
6681 wxRect
rect( wxGridNoCellRect
);
6684 cellRect
= CellToRect( topLeft
);
6685 if ( cellRect
!= wxGridNoCellRect
)
6691 rect
= wxRect( 0, 0, 0, 0 );
6694 cellRect
= CellToRect( bottomRight
);
6695 if ( cellRect
!= wxGridNoCellRect
)
6701 return wxGridNoCellRect
;
6704 // convert to scrolled coords
6706 int left
, top
, right
, bottom
;
6707 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
6708 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
6711 m_gridWin
->GetClientSize( &cw
, &ch
);
6713 rect
.SetLeft( wxMax(0, left
) );
6714 rect
.SetTop( wxMax(0, top
) );
6715 rect
.SetRight( wxMin(cw
, right
) );
6716 rect
.SetBottom( wxMin(ch
, bottom
) );
6724 // ------ Grid event classes
6727 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxEvent
)
6729 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
6730 int row
, int col
, int x
, int y
,
6731 bool control
, bool shift
, bool alt
, bool meta
)
6732 : wxNotifyEvent( type
, id
)
6738 m_control
= control
;
6743 SetEventObject(obj
);
6747 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxEvent
)
6749 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
6750 int rowOrCol
, int x
, int y
,
6751 bool control
, bool shift
, bool alt
, bool meta
)
6752 : wxNotifyEvent( type
, id
)
6754 m_rowOrCol
= rowOrCol
;
6757 m_control
= control
;
6762 SetEventObject(obj
);
6766 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxEvent
)
6768 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
6769 const wxGridCellCoords
& topLeft
,
6770 const wxGridCellCoords
& bottomRight
,
6771 bool control
, bool shift
, bool alt
, bool meta
)
6772 : wxNotifyEvent( type
, id
)
6774 m_topLeft
= topLeft
;
6775 m_bottomRight
= bottomRight
;
6776 m_control
= control
;
6781 SetEventObject(obj
);
6785 #endif // ifndef wxUSE_NEW_GRID