1 ///////////////////////////////////////////////////////////////////////////
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"
44 // this include needs to be outside precomp for BCC
45 #include "wx/textfile.h"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 WX_DEFINE_ARRAY(wxGridCellAttr
*, wxArrayAttrs
);
56 struct wxGridCellWithAttr
58 wxGridCellWithAttr(int row
, int col
, wxGridCellAttr
*attr_
)
59 : coords(row
, col
), attr(attr_
)
68 wxGridCellCoords coords
;
72 WX_DECLARE_OBJARRAY(wxGridCellWithAttr
, wxGridCellWithAttrArray
);
74 #include "wx/arrimpl.cpp"
76 WX_DEFINE_OBJARRAY(wxGridCellCoordsArray
)
77 WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray
)
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 class WXDLLEXPORT wxGridRowLabelWindow
: public wxWindow
86 wxGridRowLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
87 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
88 const wxPoint
&pos
, const wxSize
&size
);
93 void OnPaint( wxPaintEvent
& event
);
94 void OnMouseEvent( wxMouseEvent
& event
);
95 void OnKeyDown( wxKeyEvent
& event
);
97 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
102 class WXDLLEXPORT wxGridColLabelWindow
: public wxWindow
105 wxGridColLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
106 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
107 const wxPoint
&pos
, const wxSize
&size
);
112 void OnPaint( wxPaintEvent
&event
);
113 void OnMouseEvent( wxMouseEvent
& event
);
114 void OnKeyDown( wxKeyEvent
& event
);
116 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
117 DECLARE_EVENT_TABLE()
121 class WXDLLEXPORT wxGridCornerLabelWindow
: public wxWindow
124 wxGridCornerLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
125 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
126 const wxPoint
&pos
, const wxSize
&size
);
131 void OnMouseEvent( wxMouseEvent
& event
);
132 void OnKeyDown( wxKeyEvent
& event
);
133 void OnPaint( wxPaintEvent
& event
);
135 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
136 DECLARE_EVENT_TABLE()
139 class WXDLLEXPORT wxGridWindow
: public wxPanel
144 m_owner
= (wxGrid
*)NULL
;
145 m_rowLabelWin
= (wxGridRowLabelWindow
*)NULL
;
146 m_colLabelWin
= (wxGridColLabelWindow
*)NULL
;
149 wxGridWindow( wxGrid
*parent
,
150 wxGridRowLabelWindow
*rowLblWin
,
151 wxGridColLabelWindow
*colLblWin
,
152 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
155 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
159 wxGridRowLabelWindow
*m_rowLabelWin
;
160 wxGridColLabelWindow
*m_colLabelWin
;
162 void OnPaint( wxPaintEvent
&event
);
163 void OnMouseEvent( wxMouseEvent
& event
);
164 void OnKeyDown( wxKeyEvent
& );
165 void OnEraseBackground( wxEraseEvent
& );
168 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
169 DECLARE_EVENT_TABLE()
174 class wxGridCellEditorEvtHandler
: public wxEvtHandler
177 wxGridCellEditorEvtHandler()
178 : m_grid(0), m_editor(0)
180 wxGridCellEditorEvtHandler(wxGrid
* grid
, wxGridCellEditor
* editor
)
181 : m_grid(grid
), m_editor(editor
)
184 void OnKeyDown(wxKeyEvent
& event
);
188 wxGridCellEditor
* m_editor
;
189 DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler
)
190 DECLARE_EVENT_TABLE()
194 IMPLEMENT_DYNAMIC_CLASS( wxGridCellEditorEvtHandler
, wxEvtHandler
)
195 BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler
, wxEvtHandler
)
196 EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown
)
201 // ----------------------------------------------------------------------------
202 // the internal data representation used by wxGridCellAttrProvider
203 // ----------------------------------------------------------------------------
205 // this class stores attributes set for cells
206 class WXDLLEXPORT wxGridCellAttrData
209 void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
210 wxGridCellAttr
*GetAttr(int row
, int col
) const;
213 // searches for the attr for given cell, returns wxNOT_FOUND if not found
214 int FindIndex(int row
, int col
) const;
216 wxGridCellWithAttrArray m_attrs
;
219 // this class stores attributes set for rows or columns
220 class WXDLLEXPORT wxGridRowOrColAttrData
223 ~wxGridRowOrColAttrData();
225 void SetAttr(wxGridCellAttr
*attr
, int rowOrCol
);
226 wxGridCellAttr
*GetAttr(int rowOrCol
) const;
229 wxArrayInt m_rowsOrCols
;
230 wxArrayAttrs m_attrs
;
233 // NB: this is just a wrapper around 3 objects: one which stores cell
234 // attributes, and 2 others for row/col ones
235 class WXDLLEXPORT wxGridCellAttrProviderData
238 wxGridCellAttrData m_cellAttrs
;
239 wxGridRowOrColAttrData m_rowAttrs
,
243 // ----------------------------------------------------------------------------
244 // conditional compilation
245 // ----------------------------------------------------------------------------
247 #ifndef WXGRID_DRAW_LINES
248 #define WXGRID_DRAW_LINES 1
251 // ----------------------------------------------------------------------------
253 // ----------------------------------------------------------------------------
255 //#define DEBUG_ATTR_CACHE
256 #ifdef DEBUG_ATTR_CACHE
257 static size_t gs_nAttrCacheHits
= 0;
258 static size_t gs_nAttrCacheMisses
= 0;
259 #endif // DEBUG_ATTR_CACHE
261 wxGridCellCoords
wxGridNoCellCoords( -1, -1 );
262 wxRect
wxGridNoCellRect( -1, -1, -1, -1 );
265 // TODO: fixed so far - make configurable later (and also different for x/y)
266 static const size_t GRID_SCROLL_LINE
= 10;
268 // ============================================================================
270 // ============================================================================
273 // ----------------------------------------------------------------------------
275 // ----------------------------------------------------------------------------
277 wxGridCellEditor::wxGridCellEditor()
283 wxGridCellEditor::~wxGridCellEditor()
289 void wxGridCellEditor::Destroy()
292 m_control
->Destroy();
297 void wxGridCellEditor::Show(bool show
)
299 wxASSERT_MSG(m_control
,
300 wxT("The wxGridCellEditor must be Created first!"));
301 m_control
->Show(show
);
304 void wxGridCellEditor::SetSize(const wxRect
& rect
)
306 wxASSERT_MSG(m_control
,
307 wxT("The wxGridCellEditor must be Created first!"));
308 m_control
->SetSize(rect
);
311 void wxGridCellEditor::HandleReturn(wxKeyEvent
& event
)
317 wxGridCellTextEditor::wxGridCellTextEditor()
321 void wxGridCellTextEditor::Create(wxWindow
* parent
,
325 wxEvtHandler
* evtHandler
)
327 m_control
= new wxTextCtrl(parent
, -1, "", pos
, size
328 #if defined(__WXMSW__)
329 , wxTE_MULTILINE
| wxTE_NO_VSCROLL
334 m_control
->PushEventHandler(evtHandler
);
338 void wxGridCellTextEditor::BeginEdit(int row
, int col
, wxGrid
* grid
,
339 wxGridCellAttr
* attr
)
341 wxASSERT_MSG(m_control
,
342 wxT("The wxGridCellEditor must be Created first!"));
344 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
345 ((wxTextCtrl
*)m_control
)->SetValue(m_startValue
);
346 ((wxTextCtrl
*)m_control
)->SetInsertionPointEnd();
347 ((wxTextCtrl
*)m_control
)->SetFocus();
349 // ??? Should we use attr and try to set colours and font?
354 bool wxGridCellTextEditor::EndEdit(int row
, int col
, bool saveValue
,
355 wxGrid
* grid
, wxGridCellAttr
* attr
)
357 wxASSERT_MSG(m_control
,
358 wxT("The wxGridCellEditor must be Created first!"));
360 bool changed
= FALSE
;
361 wxString value
= ((wxTextCtrl
*)m_control
)->GetValue();
362 if (value
!= m_startValue
)
366 grid
->GetTable()->SetValue(row
, col
, value
);
373 void wxGridCellTextEditor::Reset()
375 wxASSERT_MSG(m_control
,
376 wxT("The wxGridCellEditor must be Created first!"));
378 ((wxTextCtrl
*)m_control
)->SetValue(m_startValue
);
379 ((wxTextCtrl
*)m_control
)->SetInsertionPointEnd();
382 void wxGridCellTextEditor::HandleReturn(wxKeyEvent
& event
)
384 #if defined(__WXMOTIF__) || defined(__WXGTK__)
385 // wxMotif needs a little extra help...
386 int pos
= ((wxTextCtrl
*)m_control
)->GetInsertionPoint();
387 wxString
s( ((wxTextCtrl
*)m_control
)->GetValue() );
388 s
= s
.Left(pos
) + "\n" + s
.Mid(pos
);
389 ((wxTextCtrl
*)m_control
)->SetValue(s
);
390 ((wxTextCtrl
*)m_control
)->SetInsertionPoint( pos
);
392 // the other ports can handle a Return key press
399 void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent
& event
)
401 switch ( event
.KeyCode() )
414 // send the event to the parent grid, skipping the
415 // event if nothing happens
417 event
.Skip( m_grid
->ProcessEvent( event
) );
421 if (!m_grid
->ProcessEvent(event
))
422 m_editor
->HandleReturn(event
);
427 // send the event to the parent grid, skipping the
428 // event if nothing happens
430 event
.Skip( m_grid
->ProcessEvent( event
) );
438 // ----------------------------------------------------------------------------
439 // wxGridCellRenderer
440 // ----------------------------------------------------------------------------
442 void wxGridCellRenderer::Draw(wxGrid
& grid
,
443 wxGridCellAttr
& attr
,
449 dc
.SetBackgroundMode( wxSOLID
);
453 dc
.SetBrush( wxBrush(grid
.GetSelectionBackground(), wxSOLID
) );
457 dc
.SetBrush( wxBrush(attr
.GetBackgroundColour(), wxSOLID
) );
460 dc
.SetPen( *wxTRANSPARENT_PEN
);
461 dc
.DrawRectangle(rect
);
464 void wxGridCellStringRenderer::Draw(wxGrid
& grid
,
465 wxGridCellAttr
& attr
,
467 const wxRect
& rectCell
,
471 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
473 // now we only have to draw the text
474 dc
.SetBackgroundMode( wxTRANSPARENT
);
478 dc
.SetTextBackground( grid
.GetSelectionBackground() );
479 dc
.SetTextForeground( grid
.GetSelectionForeground() );
483 dc
.SetTextBackground( attr
.GetBackgroundColour() );
484 dc
.SetTextForeground( attr
.GetTextColour() );
486 dc
.SetFont( attr
.GetFont() );
489 attr
.GetAlignment(&hAlign
, &vAlign
);
491 wxRect rect
= rectCell
;
497 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
498 rect
, hAlign
, vAlign
);
501 // ----------------------------------------------------------------------------
503 // ----------------------------------------------------------------------------
505 const wxColour
& wxGridCellAttr::GetTextColour() const
509 else if (m_defGridAttr
!= this)
510 return m_defGridAttr
->GetTextColour();
512 wxFAIL_MSG(wxT("Missing default cell attribute"));
518 const wxColour
& wxGridCellAttr::GetBackgroundColour() const
520 if (HasBackgroundColour())
522 else if (m_defGridAttr
!= this)
523 return m_defGridAttr
->GetBackgroundColour();
525 wxFAIL_MSG(wxT("Missing default cell attribute"));
531 const wxFont
& wxGridCellAttr::GetFont() const
535 else if (m_defGridAttr
!= this)
536 return m_defGridAttr
->GetFont();
538 wxFAIL_MSG(wxT("Missing default cell attribute"));
544 void wxGridCellAttr::GetAlignment(int *hAlign
, int *vAlign
) const
546 if (HasAlignment()) {
547 if ( hAlign
) *hAlign
= m_hAlign
;
548 if ( vAlign
) *vAlign
= m_vAlign
;
550 else if (m_defGridAttr
!= this)
551 m_defGridAttr
->GetAlignment(hAlign
, vAlign
);
553 wxFAIL_MSG(wxT("Missing default cell attribute"));
558 wxGridCellRenderer
* wxGridCellAttr::GetRenderer() const
562 else if (m_defGridAttr
!= this)
563 return m_defGridAttr
->GetRenderer();
565 wxFAIL_MSG(wxT("Missing default cell attribute"));
570 wxGridCellEditor
* wxGridCellAttr::GetEditor() const
574 else if (m_defGridAttr
!= this)
575 return m_defGridAttr
->GetEditor();
577 wxFAIL_MSG(wxT("Missing default cell attribute"));
582 // ----------------------------------------------------------------------------
583 // wxGridCellAttrData
584 // ----------------------------------------------------------------------------
586 void wxGridCellAttrData::SetAttr(wxGridCellAttr
*attr
, int row
, int col
)
588 int n
= FindIndex(row
, col
);
589 if ( n
== wxNOT_FOUND
)
592 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
598 // change the attribute
599 m_attrs
[(size_t)n
].attr
= attr
;
603 // remove this attribute
604 m_attrs
.RemoveAt((size_t)n
);
609 wxGridCellAttr
*wxGridCellAttrData::GetAttr(int row
, int col
) const
611 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
613 int n
= FindIndex(row
, col
);
614 if ( n
!= wxNOT_FOUND
)
616 attr
= m_attrs
[(size_t)n
].attr
;
623 int wxGridCellAttrData::FindIndex(int row
, int col
) const
625 size_t count
= m_attrs
.GetCount();
626 for ( size_t n
= 0; n
< count
; n
++ )
628 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
629 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
638 // ----------------------------------------------------------------------------
639 // wxGridRowOrColAttrData
640 // ----------------------------------------------------------------------------
642 wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
644 size_t count
= m_attrs
.Count();
645 for ( size_t n
= 0; n
< count
; n
++ )
647 m_attrs
[n
]->DecRef();
651 wxGridCellAttr
*wxGridRowOrColAttrData::GetAttr(int rowOrCol
) const
653 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
655 int n
= m_rowsOrCols
.Index(rowOrCol
);
656 if ( n
!= wxNOT_FOUND
)
658 attr
= m_attrs
[(size_t)n
];
665 void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr
*attr
, int rowOrCol
)
667 int n
= m_rowsOrCols
.Index(rowOrCol
);
668 if ( n
== wxNOT_FOUND
)
671 m_rowsOrCols
.Add(rowOrCol
);
678 // change the attribute
679 m_attrs
[(size_t)n
] = attr
;
683 // remove this attribute
684 m_attrs
[(size_t)n
]->DecRef();
685 m_rowsOrCols
.RemoveAt((size_t)n
);
686 m_attrs
.RemoveAt((size_t)n
);
691 // ----------------------------------------------------------------------------
692 // wxGridCellAttrProvider
693 // ----------------------------------------------------------------------------
695 wxGridCellAttrProvider::wxGridCellAttrProvider()
697 m_data
= (wxGridCellAttrProviderData
*)NULL
;
700 wxGridCellAttrProvider::~wxGridCellAttrProvider()
705 void wxGridCellAttrProvider::InitData()
707 m_data
= new wxGridCellAttrProviderData
;
710 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
) const
712 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
715 // first look for the attribute of this specific cell
716 attr
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
720 // then look for the col attr (col attributes are more common than
721 // the row ones, hence they have priority)
722 attr
= m_data
->m_colAttrs
.GetAttr(col
);
727 // finally try the row attributes
728 attr
= m_data
->m_rowAttrs
.GetAttr(row
);
735 void wxGridCellAttrProvider::SetAttr(wxGridCellAttr
*attr
,
741 m_data
->m_cellAttrs
.SetAttr(attr
, row
, col
);
744 void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr
*attr
, int row
)
749 m_data
->m_rowAttrs
.SetAttr(attr
, row
);
752 void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr
*attr
, int col
)
757 m_data
->m_colAttrs
.SetAttr(attr
, col
);
760 // ----------------------------------------------------------------------------
762 // ----------------------------------------------------------------------------
764 //////////////////////////////////////////////////////////////////////
766 // Abstract base class for grid data (the model)
768 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
771 wxGridTableBase::wxGridTableBase()
773 m_view
= (wxGrid
*) NULL
;
774 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
777 wxGridTableBase::~wxGridTableBase()
779 delete m_attrProvider
;
782 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
784 delete m_attrProvider
;
785 m_attrProvider
= attrProvider
;
788 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
)
790 if ( m_attrProvider
)
791 return m_attrProvider
->GetAttr(row
, col
);
793 return (wxGridCellAttr
*)NULL
;
796 void wxGridTableBase::SetAttr(wxGridCellAttr
* attr
, int row
, int col
)
798 if ( m_attrProvider
)
800 m_attrProvider
->SetAttr(attr
, row
, col
);
804 // as we take ownership of the pointer and don't store it, we must
810 void wxGridTableBase::SetRowAttr(wxGridCellAttr
*attr
, int row
)
812 if ( m_attrProvider
)
814 m_attrProvider
->SetRowAttr(attr
, row
);
818 // as we take ownership of the pointer and don't store it, we must
824 void wxGridTableBase::SetColAttr(wxGridCellAttr
*attr
, int col
)
826 if ( m_attrProvider
)
828 m_attrProvider
->SetColAttr(attr
, col
);
832 // as we take ownership of the pointer and don't store it, we must
838 bool wxGridTableBase::InsertRows( size_t pos
, size_t numRows
)
840 wxFAIL_MSG( wxT("Called grid table class function InsertRows\n"
841 "but your derived table class does not override this function") );
846 bool wxGridTableBase::AppendRows( size_t numRows
)
848 wxFAIL_MSG( wxT("Called grid table class function AppendRows\n"
849 "but your derived table class does not override this function"));
854 bool wxGridTableBase::DeleteRows( size_t pos
, size_t numRows
)
856 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\n"
857 "but your derived table class does not override this function"));
862 bool wxGridTableBase::InsertCols( size_t pos
, size_t numCols
)
864 wxFAIL_MSG( wxT("Called grid table class function InsertCols\n"
865 "but your derived table class does not override this function"));
870 bool wxGridTableBase::AppendCols( size_t numCols
)
872 wxFAIL_MSG(wxT("Called grid table class function AppendCols\n"
873 "but your derived table class does not override this function"));
878 bool wxGridTableBase::DeleteCols( size_t pos
, size_t numCols
)
880 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\n"
881 "but your derived table class does not override this function"));
887 wxString
wxGridTableBase::GetRowLabelValue( int row
)
894 wxString
wxGridTableBase::GetColLabelValue( int col
)
896 // default col labels are:
897 // cols 0 to 25 : A-Z
898 // cols 26 to 675 : AA-ZZ
905 s
+= (_T('A') + (wxChar
)( col%26
));
907 if ( col
< 0 ) break;
910 // reverse the string...
912 for ( i
= 0; i
< n
; i
++ )
922 //////////////////////////////////////////////////////////////////////
924 // Message class for the grid table to send requests and notifications
928 wxGridTableMessage::wxGridTableMessage()
930 m_table
= (wxGridTableBase
*) NULL
;
936 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
937 int commandInt1
, int commandInt2
)
941 m_comInt1
= commandInt1
;
942 m_comInt2
= commandInt2
;
947 //////////////////////////////////////////////////////////////////////
949 // A basic grid table for string data. An object of this class will
950 // created by wxGrid if you don't specify an alternative table class.
953 WX_DEFINE_OBJARRAY(wxGridStringArray
)
955 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
957 wxGridStringTable::wxGridStringTable()
962 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
967 m_data
.Alloc( numRows
);
971 for ( col
= 0; col
< numCols
; col
++ )
973 sa
.Add( wxEmptyString
);
976 for ( row
= 0; row
< numRows
; row
++ )
982 wxGridStringTable::~wxGridStringTable()
986 long wxGridStringTable::GetNumberRows()
988 return m_data
.GetCount();
991 long wxGridStringTable::GetNumberCols()
993 if ( m_data
.GetCount() > 0 )
994 return m_data
[0].GetCount();
999 wxString
wxGridStringTable::GetValue( int row
, int col
)
1001 // TODO: bounds checking
1003 return m_data
[row
][col
];
1006 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& s
)
1008 // TODO: bounds checking
1010 m_data
[row
][col
] = s
;
1013 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
1015 // TODO: bounds checking
1017 return (m_data
[row
][col
] == wxEmptyString
);
1021 void wxGridStringTable::Clear()
1024 int numRows
, numCols
;
1026 numRows
= m_data
.GetCount();
1029 numCols
= m_data
[0].GetCount();
1031 for ( row
= 0; row
< numRows
; row
++ )
1033 for ( col
= 0; col
< numCols
; col
++ )
1035 m_data
[row
][col
] = wxEmptyString
;
1042 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
1046 size_t curNumRows
= m_data
.GetCount();
1047 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1049 if ( pos
>= curNumRows
)
1051 return AppendRows( numRows
);
1055 sa
.Alloc( curNumCols
);
1056 for ( col
= 0; col
< curNumCols
; col
++ )
1058 sa
.Add( wxEmptyString
);
1061 for ( row
= pos
; row
< pos
+ numRows
; row
++ )
1063 m_data
.Insert( sa
, row
);
1068 wxGridTableMessage
msg( this,
1069 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
1073 GetView()->ProcessTableMessage( msg
);
1079 bool wxGridStringTable::AppendRows( size_t numRows
)
1083 size_t curNumRows
= m_data
.GetCount();
1084 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1087 if ( curNumCols
> 0 )
1089 sa
.Alloc( curNumCols
);
1090 for ( col
= 0; col
< curNumCols
; col
++ )
1092 sa
.Add( wxEmptyString
);
1096 for ( row
= 0; row
< numRows
; row
++ )
1103 wxGridTableMessage
msg( this,
1104 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
1107 GetView()->ProcessTableMessage( msg
);
1113 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
1117 size_t curNumRows
= m_data
.GetCount();
1119 if ( pos
>= curNumRows
)
1122 errmsg
.Printf("Called wxGridStringTable::DeleteRows(pos=%d, N=%d)\n"
1123 "Pos value is invalid for present table with %d rows",
1124 pos
, numRows
, curNumRows
);
1125 wxFAIL_MSG( wxT(errmsg
) );
1129 if ( numRows
> curNumRows
- pos
)
1131 numRows
= curNumRows
- pos
;
1134 if ( numRows
>= curNumRows
)
1136 m_data
.Empty(); // don't release memory just yet
1140 for ( n
= 0; n
< numRows
; n
++ )
1142 m_data
.Remove( pos
);
1148 wxGridTableMessage
msg( this,
1149 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
1153 GetView()->ProcessTableMessage( msg
);
1159 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
1163 size_t curNumRows
= m_data
.GetCount();
1164 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1166 if ( pos
>= curNumCols
)
1168 return AppendCols( numCols
);
1171 for ( row
= 0; row
< curNumRows
; row
++ )
1173 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
1175 m_data
[row
].Insert( wxEmptyString
, col
);
1181 wxGridTableMessage
msg( this,
1182 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
1186 GetView()->ProcessTableMessage( msg
);
1192 bool wxGridStringTable::AppendCols( size_t numCols
)
1196 size_t curNumRows
= m_data
.GetCount();
1199 // TODO: something better than this ?
1201 wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\n"
1202 "Call AppendRows() first") );
1206 for ( row
= 0; row
< curNumRows
; row
++ )
1208 for ( n
= 0; n
< numCols
; n
++ )
1210 m_data
[row
].Add( wxEmptyString
);
1216 wxGridTableMessage
msg( this,
1217 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
1220 GetView()->ProcessTableMessage( msg
);
1226 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
1230 size_t curNumRows
= m_data
.GetCount();
1231 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1233 if ( pos
>= curNumCols
)
1236 errmsg
.Printf( "Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\n"
1237 "Pos value is invalid for present table with %d cols",
1238 pos
, numCols
, curNumCols
);
1239 wxFAIL_MSG( wxT( errmsg
) );
1243 if ( numCols
> curNumCols
- pos
)
1245 numCols
= curNumCols
- pos
;
1248 for ( row
= 0; row
< curNumRows
; row
++ )
1250 if ( numCols
>= curNumCols
)
1252 m_data
[row
].Clear();
1256 for ( n
= 0; n
< numCols
; n
++ )
1258 m_data
[row
].Remove( pos
);
1265 wxGridTableMessage
msg( this,
1266 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
1270 GetView()->ProcessTableMessage( msg
);
1276 wxString
wxGridStringTable::GetRowLabelValue( int row
)
1278 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
1280 // using default label
1282 return wxGridTableBase::GetRowLabelValue( row
);
1286 return m_rowLabels
[ row
];
1290 wxString
wxGridStringTable::GetColLabelValue( int col
)
1292 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
1294 // using default label
1296 return wxGridTableBase::GetColLabelValue( col
);
1300 return m_colLabels
[ col
];
1304 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
1306 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
1308 int n
= m_rowLabels
.GetCount();
1310 for ( i
= n
; i
<= row
; i
++ )
1312 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
1316 m_rowLabels
[row
] = value
;
1319 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
1321 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
1323 int n
= m_colLabels
.GetCount();
1325 for ( i
= n
; i
<= col
; i
++ )
1327 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
1331 m_colLabels
[col
] = value
;
1336 //////////////////////////////////////////////////////////////////////
1338 IMPLEMENT_DYNAMIC_CLASS( wxGridTextCtrl
, wxTextCtrl
)
1340 BEGIN_EVENT_TABLE( wxGridTextCtrl
, wxTextCtrl
)
1341 EVT_KEY_DOWN( wxGridTextCtrl::OnKeyDown
)
1345 wxGridTextCtrl::wxGridTextCtrl( wxWindow
*par
,
1349 const wxString
& value
,
1353 : wxTextCtrl( par
, id
, value
, pos
, size
, style
)
1356 m_isCellControl
= isCellControl
;
1360 void wxGridTextCtrl::OnKeyDown( wxKeyEvent
& event
)
1362 switch ( event
.KeyCode() )
1366 m_grid
->SetEditControlValue( startValue
);
1367 SetInsertionPointEnd();
1371 m_grid
->EnableCellEditControl( FALSE
);
1380 if ( m_isCellControl
)
1382 // send the event to the parent grid, skipping the
1383 // event if nothing happens
1385 event
.Skip( m_grid
->ProcessEvent( event
) );
1389 // default text control response within the top edit
1397 if ( m_isCellControl
)
1399 if ( !m_grid
->ProcessEvent( event
) )
1401 #if defined(__WXMOTIF__) || defined(__WXGTK__)
1402 // wxMotif needs a little extra help...
1404 int pos
= GetInsertionPoint();
1405 wxString
s( GetValue() );
1406 s
= s
.Left(pos
) + "\n" + s
.Mid(pos
);
1408 SetInsertionPoint( pos
);
1410 // the other ports can handle a Return key press
1419 if ( m_isCellControl
)
1421 // send the event to the parent grid, skipping the
1422 // event if nothing happens
1424 event
.Skip( m_grid
->ProcessEvent( event
) );
1428 // default text control response within the top edit
1440 void wxGridTextCtrl::SetStartValue( const wxString
& s
)
1443 wxTextCtrl::SetValue(s
);
1448 //////////////////////////////////////////////////////////////////////
1450 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
1452 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
1453 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
1454 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
1455 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
1458 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
1460 const wxPoint
&pos
, const wxSize
&size
)
1461 : wxWindow( parent
, id
, pos
, size
)
1466 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
&event
)
1470 // NO - don't do this because it will set both the x and y origin
1471 // coords to match the parent scrolled window and we just want to
1472 // set the y coord - MB
1474 // m_owner->PrepareDC( dc );
1477 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
1478 dc
.SetDeviceOrigin( 0, -y
);
1480 m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
1481 m_owner
->DrawRowLabels( dc
);
1485 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1487 m_owner
->ProcessRowLabelMouseEvent( event
);
1491 // This seems to be required for wxMotif otherwise the mouse
1492 // cursor must be in the cell edit control to get key events
1494 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
1496 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1501 //////////////////////////////////////////////////////////////////////
1503 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
1505 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
1506 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
1507 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
1508 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
1511 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
1513 const wxPoint
&pos
, const wxSize
&size
)
1514 : wxWindow( parent
, id
, pos
, size
)
1519 void wxGridColLabelWindow::OnPaint( wxPaintEvent
&event
)
1523 // NO - don't do this because it will set both the x and y origin
1524 // coords to match the parent scrolled window and we just want to
1525 // set the x coord - MB
1527 // m_owner->PrepareDC( dc );
1530 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
1531 dc
.SetDeviceOrigin( -x
, 0 );
1533 m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
1534 m_owner
->DrawColLabels( dc
);
1538 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1540 m_owner
->ProcessColLabelMouseEvent( event
);
1544 // This seems to be required for wxMotif otherwise the mouse
1545 // cursor must be in the cell edit control to get key events
1547 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
1549 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1554 //////////////////////////////////////////////////////////////////////
1556 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
1558 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
1559 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
1560 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
1561 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
1564 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
1566 const wxPoint
&pos
, const wxSize
&size
)
1567 : wxWindow( parent
, id
, pos
, size
)
1572 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1576 int client_height
= 0;
1577 int client_width
= 0;
1578 GetClientSize( &client_width
, &client_height
);
1580 dc
.SetPen( *wxBLACK_PEN
);
1581 dc
.DrawLine( client_width
-1, client_height
-1, client_width
-1, 0 );
1582 dc
.DrawLine( client_width
-1, client_height
-1, 0, client_height
-1 );
1584 dc
.SetPen( *wxWHITE_PEN
);
1585 dc
.DrawLine( 0, 0, client_width
, 0 );
1586 dc
.DrawLine( 0, 0, 0, client_height
);
1590 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1592 m_owner
->ProcessCornerLabelMouseEvent( event
);
1596 // This seems to be required for wxMotif otherwise the mouse
1597 // cursor must be in the cell edit control to get key events
1599 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
1601 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1606 //////////////////////////////////////////////////////////////////////
1608 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxPanel
)
1610 BEGIN_EVENT_TABLE( wxGridWindow
, wxPanel
)
1611 EVT_PAINT( wxGridWindow::OnPaint
)
1612 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
1613 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
1614 EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground
)
1617 wxGridWindow::wxGridWindow( wxGrid
*parent
,
1618 wxGridRowLabelWindow
*rowLblWin
,
1619 wxGridColLabelWindow
*colLblWin
,
1620 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
)
1621 : wxPanel( parent
, id
, pos
, size
, 0, "grid window" )
1624 m_rowLabelWin
= rowLblWin
;
1625 m_colLabelWin
= colLblWin
;
1626 SetBackgroundColour( "WHITE" );
1630 wxGridWindow::~wxGridWindow()
1635 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1637 wxPaintDC
dc( this );
1638 m_owner
->PrepareDC( dc
);
1639 wxRegion reg
= GetUpdateRegion();
1640 m_owner
->CalcCellsExposed( reg
);
1641 m_owner
->DrawGridCellArea( dc
);
1642 #if WXGRID_DRAW_LINES
1643 m_owner
->DrawAllGridLines( dc
, reg
);
1648 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
1650 wxPanel::ScrollWindow( dx
, dy
, rect
);
1651 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
1652 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
1656 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
1658 m_owner
->ProcessGridCellMouseEvent( event
);
1662 // This seems to be required for wxMotif otherwise the mouse
1663 // cursor must be in the cell edit control to get key events
1665 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
1667 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1670 void wxGridWindow::OnEraseBackground(wxEraseEvent
&)
1676 //////////////////////////////////////////////////////////////////////
1678 #define ID_EDIT_TIMER 1001
1680 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
1682 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
1683 EVT_PAINT( wxGrid::OnPaint
)
1684 EVT_SIZE( wxGrid::OnSize
)
1685 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
1686 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
1687 EVT_TIMER( ID_EDIT_TIMER
, wxGrid::OnEditTimer
)
1690 wxGrid::wxGrid( wxWindow
*parent
,
1695 const wxString
& name
)
1696 : wxScrolledWindow( parent
, id
, pos
, size
, style
, name
)
1705 m_defaultCellAttr
->SafeDecRef();
1707 #ifdef DEBUG_ATTR_CACHE
1708 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
1709 wxPrintf(_T("wxGrid attribute cache statistics: "
1710 "total: %u, hits: %u (%u%%)\n"),
1711 total
, gs_nAttrCacheHits
,
1712 total
? (gs_nAttrCacheHits
*100) / total
: 0);
1722 // ----- internal init and update functions
1725 void wxGrid::Create()
1727 m_created
= FALSE
; // set to TRUE by CreateGrid
1728 m_displayed
= FALSE
; // set to TRUE by OnPaint
1730 m_table
= (wxGridTableBase
*) NULL
;
1732 m_cellEditCtrl
= (wxWindow
*) NULL
;
1734 m_defaultCellAttr
= new wxGridCellAttr
;
1735 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
1736 // RD: Should we fill the default attrs now or is waiting until Init() okay?
1741 m_currentCellCoords
= wxGridNoCellCoords
;
1743 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
1744 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
1746 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
1751 m_rowLabelWin
= new wxGridRowLabelWindow( this,
1756 m_colLabelWin
= new wxGridColLabelWindow( this,
1761 m_gridWin
= new wxGridWindow( this,
1768 SetTargetWindow( m_gridWin
);
1772 bool wxGrid::CreateGrid( int numRows
, int numCols
)
1776 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
1781 m_numRows
= numRows
;
1782 m_numCols
= numCols
;
1784 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
1785 m_table
->SetView( this );
1794 bool wxGrid::SetTable( wxGridTableBase
*table
, bool takeOwnership
)
1798 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
1803 m_numRows
= table
->GetNumberRows();
1804 m_numCols
= table
->GetNumberCols();
1807 m_table
->SetView( this );
1822 if ( m_numRows
<= 0 )
1823 m_numRows
= WXGRID_DEFAULT_NUMBER_ROWS
;
1825 if ( m_numCols
<= 0 )
1826 m_numCols
= WXGRID_DEFAULT_NUMBER_COLS
;
1828 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
1829 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
1831 if ( m_rowLabelWin
)
1833 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
1837 m_labelBackgroundColour
= wxColour( _T("WHITE") );
1840 m_labelTextColour
= wxColour( _T("BLACK") );
1843 m_attrCache
.row
= -1;
1845 // TODO: something better than this ?
1847 m_labelFont
= this->GetFont();
1848 m_labelFont
.SetWeight( m_labelFont
.GetWeight() + 2 );
1850 m_rowLabelHorizAlign
= wxLEFT
;
1851 m_rowLabelVertAlign
= wxCENTRE
;
1853 m_colLabelHorizAlign
= wxCENTRE
;
1854 m_colLabelVertAlign
= wxTOP
;
1856 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
1857 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
1859 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
1860 m_defaultRowHeight
+= 8;
1862 m_defaultRowHeight
+= 4;
1865 m_rowHeights
.Alloc( m_numRows
);
1866 m_rowBottoms
.Alloc( m_numRows
);
1868 for ( i
= 0; i
< m_numRows
; i
++ )
1870 m_rowHeights
.Add( m_defaultRowHeight
);
1871 rowBottom
+= m_defaultRowHeight
;
1872 m_rowBottoms
.Add( rowBottom
);
1875 m_colWidths
.Alloc( m_numCols
);
1876 m_colRights
.Alloc( m_numCols
);
1878 for ( i
= 0; i
< m_numCols
; i
++ )
1880 m_colWidths
.Add( m_defaultColWidth
);
1881 colRight
+= m_defaultColWidth
;
1882 m_colRights
.Add( colRight
);
1885 // Set default cell attributes
1886 m_defaultCellAttr
->SetFont(GetFont());
1887 m_defaultCellAttr
->SetAlignment(wxLEFT
, wxTOP
);
1888 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
1889 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
1890 m_defaultCellAttr
->SetTextColour(
1891 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT
));
1892 m_defaultCellAttr
->SetBackgroundColour(
1893 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
1896 m_gridLineColour
= wxColour( 128, 128, 255 );
1897 m_gridLinesEnabled
= TRUE
;
1899 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
1900 m_winCapture
= (wxWindow
*)NULL
;
1902 m_dragRowOrCol
= -1;
1903 m_isDragging
= FALSE
;
1904 m_startDragPos
= wxDefaultPosition
;
1906 m_editTimer
= new wxTimer( this, ID_EDIT_TIMER
);
1907 m_waitForSlowClick
= FALSE
;
1909 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
1910 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
1912 m_currentCellCoords
= wxGridNoCellCoords
;
1914 m_selectedTopLeft
= wxGridNoCellCoords
;
1915 m_selectedBottomRight
= wxGridNoCellCoords
;
1916 m_selectionBackground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
);
1917 m_selectionForeground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1919 m_editable
= TRUE
; // default for whole grid
1921 m_inOnKeyDown
= FALSE
;
1924 // TODO: extend this to other types of controls
1926 m_cellEditCtrl
= new wxGridTextCtrl( m_gridWin
,
1933 #if defined(__WXMSW__)
1934 , wxTE_MULTILINE
| wxTE_NO_VSCROLL
1938 m_cellEditCtrl
->Show( FALSE
);
1939 m_cellEditCtrlEnabled
= FALSE
;
1940 m_editCtrlType
= wxGRID_TEXTCTRL
;
1944 void wxGrid::CalcDimensions()
1947 GetClientSize( &cw
, &ch
);
1949 if ( m_numRows
> 0 && m_numCols
> 0 )
1951 int right
= m_colRights
[ m_numCols
-1 ] + 50;
1952 int bottom
= m_rowBottoms
[ m_numRows
-1 ] + 50;
1954 // TODO: restore the scroll position that we had before sizing
1957 GetViewStart( &x
, &y
);
1958 SetScrollbars( GRID_SCROLL_LINE
, GRID_SCROLL_LINE
,
1959 right
/GRID_SCROLL_LINE
, bottom
/GRID_SCROLL_LINE
,
1965 void wxGrid::CalcWindowSizes()
1968 GetClientSize( &cw
, &ch
);
1970 if ( m_cornerLabelWin
->IsShown() )
1971 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
1973 if ( m_colLabelWin
->IsShown() )
1974 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
1976 if ( m_rowLabelWin
->IsShown() )
1977 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
1979 if ( m_gridWin
->IsShown() )
1980 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
1984 // this is called when the grid table sends a message to say that it
1985 // has been redimensioned
1987 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
1991 switch ( msg
.GetId() )
1993 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
1995 size_t pos
= msg
.GetCommandInt();
1996 int numRows
= msg
.GetCommandInt2();
1997 for ( i
= 0; i
< numRows
; i
++ )
1999 m_rowHeights
.Insert( m_defaultRowHeight
, pos
);
2000 m_rowBottoms
.Insert( 0, pos
);
2002 m_numRows
+= numRows
;
2005 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
2007 for ( i
= pos
; i
< m_numRows
; i
++ )
2009 bottom
+= m_rowHeights
[i
];
2010 m_rowBottoms
[i
] = bottom
;
2016 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
2018 int numRows
= msg
.GetCommandInt();
2019 for ( i
= 0; i
< numRows
; i
++ )
2021 m_rowHeights
.Add( m_defaultRowHeight
);
2022 m_rowBottoms
.Add( 0 );
2025 int oldNumRows
= m_numRows
;
2026 m_numRows
+= numRows
;
2029 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
2031 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
2033 bottom
+= m_rowHeights
[i
];
2034 m_rowBottoms
[i
] = bottom
;
2040 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
2042 size_t pos
= msg
.GetCommandInt();
2043 int numRows
= msg
.GetCommandInt2();
2044 for ( i
= 0; i
< numRows
; i
++ )
2046 m_rowHeights
.Remove( pos
);
2047 m_rowBottoms
.Remove( pos
);
2049 m_numRows
-= numRows
;
2054 m_colWidths
.Clear();
2055 m_colRights
.Clear();
2056 m_currentCellCoords
= wxGridNoCellCoords
;
2060 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
2061 m_currentCellCoords
.Set( 0, 0 );
2064 for ( i
= 0; i
< m_numRows
; i
++ )
2066 h
+= m_rowHeights
[i
];
2067 m_rowBottoms
[i
] = h
;
2075 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
2077 size_t pos
= msg
.GetCommandInt();
2078 int numCols
= msg
.GetCommandInt2();
2079 for ( i
= 0; i
< numCols
; i
++ )
2081 m_colWidths
.Insert( m_defaultColWidth
, pos
);
2082 m_colRights
.Insert( 0, pos
);
2084 m_numCols
+= numCols
;
2087 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
2089 for ( i
= pos
; i
< m_numCols
; i
++ )
2091 right
+= m_colWidths
[i
];
2092 m_colRights
[i
] = right
;
2098 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
2100 int numCols
= msg
.GetCommandInt();
2101 for ( i
= 0; i
< numCols
; i
++ )
2103 m_colWidths
.Add( m_defaultColWidth
);
2104 m_colRights
.Add( 0 );
2107 int oldNumCols
= m_numCols
;
2108 m_numCols
+= numCols
;
2111 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
2113 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
2115 right
+= m_colWidths
[i
];
2116 m_colRights
[i
] = right
;
2122 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
2124 size_t pos
= msg
.GetCommandInt();
2125 int numCols
= msg
.GetCommandInt2();
2126 for ( i
= 0; i
< numCols
; i
++ )
2128 m_colWidths
.Remove( pos
);
2129 m_colRights
.Remove( pos
);
2131 m_numCols
-= numCols
;
2135 #if 0 // leave the row alone here so that AppendCols will work subsequently
2137 m_rowHeights
.Clear();
2138 m_rowBottoms
.Clear();
2140 m_currentCellCoords
= wxGridNoCellCoords
;
2144 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
2145 m_currentCellCoords
.Set( 0, 0 );
2148 for ( i
= 0; i
< m_numCols
; i
++ )
2150 w
+= m_colWidths
[i
];
2163 void wxGrid::CalcRowLabelsExposed( wxRegion
& reg
)
2165 wxRegionIterator
iter( reg
);
2168 m_rowLabelsExposed
.Empty();
2175 // TODO: remove this when we can...
2176 // There is a bug in wxMotif that gives garbage update
2177 // rectangles if you jump-scroll a long way by clicking the
2178 // scrollbar with middle button. This is a work-around
2180 #if defined(__WXMOTIF__)
2182 m_gridWin
->GetClientSize( &cw
, &ch
);
2183 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
2184 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
2187 // logical bounds of update region
2190 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
2191 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
2193 // find the row labels within these bounds
2197 for ( row
= 0; row
< m_numRows
; row
++ )
2199 if ( m_rowBottoms
[row
] < top
) continue;
2201 rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
2202 if ( rowTop
> bottom
) break;
2204 m_rowLabelsExposed
.Add( row
);
2212 void wxGrid::CalcColLabelsExposed( wxRegion
& reg
)
2214 wxRegionIterator
iter( reg
);
2217 m_colLabelsExposed
.Empty();
2224 // TODO: remove this when we can...
2225 // There is a bug in wxMotif that gives garbage update
2226 // rectangles if you jump-scroll a long way by clicking the
2227 // scrollbar with middle button. This is a work-around
2229 #if defined(__WXMOTIF__)
2231 m_gridWin
->GetClientSize( &cw
, &ch
);
2232 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
2233 r
.SetRight( wxMin( r
.GetRight(), cw
) );
2236 // logical bounds of update region
2239 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
2240 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
2242 // find the cells within these bounds
2246 for ( col
= 0; col
< m_numCols
; col
++ )
2248 if ( m_colRights
[col
] < left
) continue;
2250 colLeft
= m_colRights
[col
] - m_colWidths
[col
];
2251 if ( colLeft
> right
) break;
2253 m_colLabelsExposed
.Add( col
);
2261 void wxGrid::CalcCellsExposed( wxRegion
& reg
)
2263 wxRegionIterator
iter( reg
);
2266 m_cellsExposed
.Empty();
2267 m_rowsExposed
.Empty();
2268 m_colsExposed
.Empty();
2270 int left
, top
, right
, bottom
;
2275 // TODO: remove this when we can...
2276 // There is a bug in wxMotif that gives garbage update
2277 // rectangles if you jump-scroll a long way by clicking the
2278 // scrollbar with middle button. This is a work-around
2280 #if defined(__WXMOTIF__)
2282 m_gridWin
->GetClientSize( &cw
, &ch
);
2283 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
2284 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
2285 r
.SetRight( wxMin( r
.GetRight(), cw
) );
2286 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
2289 // logical bounds of update region
2291 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
2292 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
2294 // find the cells within these bounds
2297 int colLeft
, rowTop
;
2298 for ( row
= 0; row
< m_numRows
; row
++ )
2300 if ( m_rowBottoms
[row
] < top
) continue;
2302 rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
2303 if ( rowTop
> bottom
) break;
2305 m_rowsExposed
.Add( row
);
2307 for ( col
= 0; col
< m_numCols
; col
++ )
2309 if ( m_colRights
[col
] < left
) continue;
2311 colLeft
= m_colRights
[col
] - m_colWidths
[col
];
2312 if ( colLeft
> right
) break;
2314 if ( m_colsExposed
.Index( col
) == wxNOT_FOUND
) m_colsExposed
.Add( col
);
2315 m_cellsExposed
.Add( wxGridCellCoords( row
, col
) );
2324 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
2327 wxPoint
pos( event
.GetPosition() );
2328 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2330 if ( event
.Dragging() )
2332 m_isDragging
= TRUE
;
2334 if ( event
.LeftIsDown() )
2336 switch( m_cursorMode
)
2338 case WXGRID_CURSOR_RESIZE_ROW
:
2340 int cw
, ch
, left
, dummy
;
2341 m_gridWin
->GetClientSize( &cw
, &ch
);
2342 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
2344 wxClientDC
dc( m_gridWin
);
2347 m_rowBottoms
[m_dragRowOrCol
] -
2348 m_rowHeights
[m_dragRowOrCol
] +
2349 WXGRID_MIN_ROW_HEIGHT
);
2350 dc
.SetLogicalFunction(wxINVERT
);
2351 if ( m_dragLastPos
>= 0 )
2353 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
2355 dc
.DrawLine( left
, y
, left
+cw
, y
);
2360 case WXGRID_CURSOR_SELECT_ROW
:
2361 if ( (row
= YToRow( y
)) >= 0 &&
2362 !IsInSelection( row
, 0 ) )
2364 SelectRow( row
, TRUE
);
2367 // default label to suppress warnings about "enumeration value
2368 // 'xxx' not handled in switch
2376 m_isDragging
= FALSE
;
2379 // ------------ Entering or leaving the window
2381 if ( event
.Entering() || event
.Leaving() )
2383 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
2387 // ------------ Left button pressed
2389 else if ( event
.LeftDown() )
2391 // don't send a label click event for a hit on the
2392 // edge of the row label - this is probably the user
2393 // wanting to resize the row
2395 if ( YToEdgeOfRow(y
) < 0 )
2399 !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
2401 SelectRow( row
, event
.ShiftDown() );
2402 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
2407 // starting to drag-resize a row
2409 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
2414 // ------------ Left double click
2416 else if (event
.LeftDClick() )
2418 if ( YToEdgeOfRow(y
) < 0 )
2421 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
);
2426 // ------------ Left button released
2428 else if ( event
.LeftUp() )
2430 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
2432 DoEndDragResizeRow();
2434 // Note: we are ending the event *after* doing
2435 // default processing in this case
2437 SendEvent( EVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
2440 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
2445 // ------------ Right button down
2447 else if ( event
.RightDown() )
2450 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
2452 // no default action at the moment
2457 // ------------ Right double click
2459 else if ( event
.RightDClick() )
2462 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
2464 // no default action at the moment
2469 // ------------ No buttons down and mouse moving
2471 else if ( event
.Moving() )
2473 m_dragRowOrCol
= YToEdgeOfRow( y
);
2474 if ( m_dragRowOrCol
>= 0 )
2476 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2478 // don't capture the mouse yet
2479 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, FALSE
);
2482 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
2484 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, FALSE
);
2490 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
2493 wxPoint
pos( event
.GetPosition() );
2494 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2496 if ( event
.Dragging() )
2498 m_isDragging
= TRUE
;
2500 if ( event
.LeftIsDown() )
2502 switch( m_cursorMode
)
2504 case WXGRID_CURSOR_RESIZE_COL
:
2506 int cw
, ch
, dummy
, top
;
2507 m_gridWin
->GetClientSize( &cw
, &ch
);
2508 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
2510 wxClientDC
dc( m_gridWin
);
2513 m_colRights
[m_dragRowOrCol
] -
2514 m_colWidths
[m_dragRowOrCol
] +
2515 WXGRID_MIN_COL_WIDTH
);
2516 dc
.SetLogicalFunction(wxINVERT
);
2517 if ( m_dragLastPos
>= 0 )
2519 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
2521 dc
.DrawLine( x
, top
, x
, top
+ch
);
2526 case WXGRID_CURSOR_SELECT_COL
:
2527 if ( (col
= XToCol( x
)) >= 0 &&
2528 !IsInSelection( 0, col
) )
2530 SelectCol( col
, TRUE
);
2533 // default label to suppress warnings about "enumeration value
2534 // 'xxx' not handled in switch
2542 m_isDragging
= FALSE
;
2545 // ------------ Entering or leaving the window
2547 if ( event
.Entering() || event
.Leaving() )
2549 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
2553 // ------------ Left button pressed
2555 else if ( event
.LeftDown() )
2557 // don't send a label click event for a hit on the
2558 // edge of the col label - this is probably the user
2559 // wanting to resize the col
2561 if ( XToEdgeOfCol(x
) < 0 )
2565 !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
2567 SelectCol( col
, event
.ShiftDown() );
2568 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, m_colLabelWin
);
2573 // starting to drag-resize a col
2575 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
);
2580 // ------------ Left double click
2582 if ( event
.LeftDClick() )
2584 if ( XToEdgeOfCol(x
) < 0 )
2587 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
);
2592 // ------------ Left button released
2594 else if ( event
.LeftUp() )
2596 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
2598 DoEndDragResizeCol();
2600 // Note: we are ending the event *after* doing
2601 // default processing in this case
2603 SendEvent( EVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
2606 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
2611 // ------------ Right button down
2613 else if ( event
.RightDown() )
2616 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
2618 // no default action at the moment
2623 // ------------ Right double click
2625 else if ( event
.RightDClick() )
2628 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
2630 // no default action at the moment
2635 // ------------ No buttons down and mouse moving
2637 else if ( event
.Moving() )
2639 m_dragRowOrCol
= XToEdgeOfCol( x
);
2640 if ( m_dragRowOrCol
>= 0 )
2642 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2644 // don't capture the cursor yet
2645 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
, FALSE
);
2648 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
2650 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
, FALSE
);
2656 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
2658 if ( event
.LeftDown() )
2660 // indicate corner label by having both row and
2663 if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
2669 else if ( event
.LeftDClick() )
2671 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
2674 else if ( event
.RightDown() )
2676 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
2678 // no default action at the moment
2682 else if ( event
.RightDClick() )
2684 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
2686 // no default action at the moment
2691 void wxGrid::ChangeCursorMode(CursorMode mode
,
2696 static const wxChar
*cursorModes
[] =
2705 wxLogTrace(_T("grid"),
2706 _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
2707 win
== m_colLabelWin
? _T("colLabelWin")
2708 : win
? _T("rowLabelWin")
2710 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
2711 #endif // __WXDEBUG__
2713 if ( mode
== m_cursorMode
)
2718 // by default use the grid itself
2724 m_winCapture
->ReleaseMouse();
2725 m_winCapture
= (wxWindow
*)NULL
;
2728 m_cursorMode
= mode
;
2730 switch ( m_cursorMode
)
2732 case WXGRID_CURSOR_RESIZE_ROW
:
2733 win
->SetCursor( m_rowResizeCursor
);
2736 case WXGRID_CURSOR_RESIZE_COL
:
2737 win
->SetCursor( m_colResizeCursor
);
2741 win
->SetCursor( *wxSTANDARD_CURSOR
);
2744 // we need to capture mouse when resizing
2745 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
2746 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
2748 if ( captureMouse
&& resize
)
2750 win
->CaptureMouse();
2755 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
2758 wxPoint
pos( event
.GetPosition() );
2759 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2761 wxGridCellCoords coords
;
2762 XYToCell( x
, y
, coords
);
2764 if ( event
.Dragging() )
2766 //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
2768 // Don't start doing anything until the mouse has been drug at
2769 // least 3 pixels in any direction...
2770 if (! m_isDragging
) {
2771 if (m_startDragPos
== wxDefaultPosition
) {
2772 m_startDragPos
= pos
;
2775 if (abs(m_startDragPos
.x
- pos
.x
) < 4 && abs(m_startDragPos
.y
- pos
.y
) < 4)
2779 m_isDragging
= TRUE
;
2780 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2782 // Hide the edit control, so it
2783 // won't interfer with drag-shrinking.
2784 if ( IsCellEditControlEnabled() )
2785 HideCellEditControl();
2787 // Have we captured the mouse yet?
2788 if (! m_winCapture
) {
2789 m_winCapture
= m_gridWin
;
2790 m_winCapture
->CaptureMouse();
2793 if ( coords
!= wxGridNoCellCoords
)
2795 if ( !IsSelection() )
2797 SelectBlock( coords
, coords
);
2801 SelectBlock( m_currentCellCoords
, coords
);
2804 if (! IsVisible(coords
)) {
2805 MakeCellVisible(coords
);
2806 // TODO: need to introduce a delay or something here. The
2807 // scrolling is way to fast, at least on MSW.
2811 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
2813 int cw
, ch
, left
, dummy
;
2814 m_gridWin
->GetClientSize( &cw
, &ch
);
2815 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
2817 wxClientDC
dc( m_gridWin
);
2820 m_rowBottoms
[m_dragRowOrCol
] -
2821 m_rowHeights
[m_dragRowOrCol
] +
2822 WXGRID_MIN_ROW_HEIGHT
);
2823 dc
.SetLogicalFunction(wxINVERT
);
2824 if ( m_dragLastPos
>= 0 )
2826 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
2828 dc
.DrawLine( left
, y
, left
+cw
, y
);
2831 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
2833 int cw
, ch
, dummy
, top
;
2834 m_gridWin
->GetClientSize( &cw
, &ch
);
2835 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
2837 wxClientDC
dc( m_gridWin
);
2840 m_colRights
[m_dragRowOrCol
] -
2841 m_colWidths
[m_dragRowOrCol
] + WXGRID_MIN_COL_WIDTH
);
2842 dc
.SetLogicalFunction(wxINVERT
);
2843 if ( m_dragLastPos
>= 0 )
2845 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
2847 dc
.DrawLine( x
, top
, x
, top
+ch
);
2854 m_isDragging
= FALSE
;
2855 m_startDragPos
= wxDefaultPosition
;
2858 if ( coords
!= wxGridNoCellCoords
)
2860 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
2861 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
2864 if ( event
.Entering() || event
.Leaving() )
2866 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
2867 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
2872 // ------------ Left button pressed
2874 if ( event
.LeftDown() )
2876 EnableCellEditControl( FALSE
);
2877 if ( event
.ShiftDown() )
2879 SelectBlock( m_currentCellCoords
, coords
);
2881 else if ( XToEdgeOfCol(x
) < 0 &&
2882 YToEdgeOfRow(y
) < 0 )
2884 if ( !SendEvent( EVT_GRID_CELL_LEFT_CLICK
,
2889 MakeCellVisible( coords
);
2891 // if this is the second click on this cell then start
2893 if (m_waitForSlowClick
&& coords
== m_currentCellCoords
) {
2894 EnableCellEditControl(TRUE
);
2895 ShowCellEditControl();
2898 SetCurrentCell( coords
);
2899 m_editTimer
->Start( 1500, TRUE
);
2900 m_waitForSlowClick
= TRUE
;
2907 // ------------ Left double click
2909 else if ( event
.LeftDClick() )
2911 EnableCellEditControl( FALSE
);
2912 if ( XToEdgeOfCol(x
) < 0 && YToEdgeOfRow(y
) < 0 )
2914 SendEvent( EVT_GRID_CELL_LEFT_DCLICK
,
2922 // ------------ Left button released
2924 else if ( event
.LeftUp() )
2926 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2928 if ( IsSelection() )
2931 m_winCapture
->ReleaseMouse();
2932 m_winCapture
= NULL
;
2934 SendEvent( EVT_GRID_RANGE_SELECT
, -1, -1, event
);
2937 // Show the edit control, if it has
2938 // been hidden for drag-shrinking.
2939 if ( IsCellEditControlEnabled() )
2940 ShowCellEditControl();
2942 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
2944 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
2945 DoEndDragResizeRow();
2947 // Note: we are ending the event *after* doing
2948 // default processing in this case
2950 SendEvent( EVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
2952 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
2954 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
2955 DoEndDragResizeCol();
2957 // Note: we are ending the event *after* doing
2958 // default processing in this case
2960 SendEvent( EVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
2967 // ------------ Right button down
2969 else if ( event
.RightDown() )
2971 EnableCellEditControl( FALSE
);
2972 if ( !SendEvent( EVT_GRID_CELL_RIGHT_CLICK
,
2977 // no default action at the moment
2982 // ------------ Right double click
2984 else if ( event
.RightDClick() )
2986 EnableCellEditControl( FALSE
);
2987 if ( !SendEvent( EVT_GRID_CELL_RIGHT_DCLICK
,
2992 // no default action at the moment
2996 // ------------ Moving and no button action
2998 else if ( event
.Moving() && !event
.IsButton() )
3000 int dragRow
= YToEdgeOfRow( y
);
3001 int dragCol
= XToEdgeOfCol( x
);
3003 // Dragging on the corner of a cell to resize in both
3004 // directions is not implemented yet...
3006 if ( dragRow
>= 0 && dragCol
>= 0 )
3008 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3014 m_dragRowOrCol
= dragRow
;
3016 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3018 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
);
3026 m_dragRowOrCol
= dragCol
;
3028 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3030 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
);
3036 // Neither on a row or col edge
3038 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3040 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3047 void wxGrid::DoEndDragResizeRow()
3049 if ( m_dragLastPos
>= 0 )
3051 // erase the last line and resize the row
3053 int cw
, ch
, left
, dummy
;
3054 m_gridWin
->GetClientSize( &cw
, &ch
);
3055 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
3057 wxClientDC
dc( m_gridWin
);
3059 dc
.SetLogicalFunction( wxINVERT
);
3060 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
3061 HideCellEditControl();
3063 int rowTop
= m_rowBottoms
[m_dragRowOrCol
] - m_rowHeights
[m_dragRowOrCol
];
3064 SetRowSize( m_dragRowOrCol
,
3065 wxMax( m_dragLastPos
- rowTop
, WXGRID_MIN_ROW_HEIGHT
) );
3067 if ( !GetBatchCount() )
3069 // Only needed to get the correct rect.y:
3070 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
3072 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
3073 rect
.width
= m_rowLabelWidth
;
3074 rect
.height
= ch
- rect
.y
;
3075 m_rowLabelWin
->Refresh( TRUE
, &rect
);
3077 m_gridWin
->Refresh( FALSE
, &rect
);
3080 ShowCellEditControl();
3085 void wxGrid::DoEndDragResizeCol()
3087 if ( m_dragLastPos
>= 0 )
3089 // erase the last line and resize the col
3091 int cw
, ch
, dummy
, top
;
3092 m_gridWin
->GetClientSize( &cw
, &ch
);
3093 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
3095 wxClientDC
dc( m_gridWin
);
3097 dc
.SetLogicalFunction( wxINVERT
);
3098 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
3099 HideCellEditControl();
3101 int colLeft
= m_colRights
[m_dragRowOrCol
] - m_colWidths
[m_dragRowOrCol
];
3102 SetColSize( m_dragRowOrCol
,
3103 wxMax( m_dragLastPos
- colLeft
, WXGRID_MIN_COL_WIDTH
) );
3105 if ( !GetBatchCount() )
3107 // Only needed to get the correct rect.x:
3108 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
3110 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
3111 rect
.width
= cw
- rect
.x
;
3112 rect
.height
= m_colLabelHeight
;
3113 m_colLabelWin
->Refresh( TRUE
, &rect
);
3115 m_gridWin
->Refresh( FALSE
, &rect
);
3118 ShowCellEditControl();
3125 // ------ interaction with data model
3127 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
3129 switch ( msg
.GetId() )
3131 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
3132 return GetModelValues();
3134 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
3135 return SetModelValues();
3137 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
3138 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
3139 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
3140 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
3141 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
3142 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
3143 return Redimension( msg
);
3152 // The behaviour of this function depends on the grid table class
3153 // Clear() function. For the default wxGridStringTable class the
3154 // behavious is to replace all cell contents with wxEmptyString but
3155 // not to change the number of rows or cols.
3157 void wxGrid::ClearGrid()
3162 SetEditControlValue();
3163 if ( !GetBatchCount() ) m_gridWin
->Refresh();
3168 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
3170 // TODO: something with updateLabels flag
3174 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
3180 bool ok
= m_table
->InsertRows( pos
, numRows
);
3182 // the table will have sent the results of the insert row
3183 // operation to this view object as a grid table message
3187 if ( m_numCols
== 0 )
3189 m_table
->AppendCols( WXGRID_DEFAULT_NUMBER_COLS
);
3191 // TODO: perhaps instead of appending the default number of cols
3192 // we should remember what the last non-zero number of cols was ?
3196 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3198 // if we have just inserted cols into an empty grid the current
3199 // cell will be undefined...
3201 SetCurrentCell( 0, 0 );
3205 if ( !GetBatchCount() ) Refresh();
3208 SetEditControlValue();
3218 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
3220 // TODO: something with updateLabels flag
3224 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
3228 if ( m_table
&& m_table
->AppendRows( numRows
) )
3230 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3232 // if we have just inserted cols into an empty grid the current
3233 // cell will be undefined...
3235 SetCurrentCell( 0, 0 );
3238 // the table will have sent the results of the append row
3239 // operation to this view object as a grid table message
3242 if ( !GetBatchCount() ) Refresh();
3252 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
3254 // TODO: something with updateLabels flag
3258 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
3262 if ( m_table
&& m_table
->DeleteRows( pos
, numRows
) )
3264 // the table will have sent the results of the delete row
3265 // operation to this view object as a grid table message
3267 if ( m_numRows
> 0 )
3268 SetEditControlValue();
3270 HideCellEditControl();
3273 if ( !GetBatchCount() ) Refresh();
3283 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
3285 // TODO: something with updateLabels flag
3289 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
3295 HideCellEditControl();
3296 bool ok
= m_table
->InsertCols( pos
, numCols
);
3298 // the table will have sent the results of the insert col
3299 // operation to this view object as a grid table message
3303 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3305 // if we have just inserted cols into an empty grid the current
3306 // cell will be undefined...
3308 SetCurrentCell( 0, 0 );
3312 if ( !GetBatchCount() ) Refresh();
3315 SetEditControlValue();
3325 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
3327 // TODO: something with updateLabels flag
3331 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
3335 if ( m_table
&& m_table
->AppendCols( numCols
) )
3337 // the table will have sent the results of the append col
3338 // operation to this view object as a grid table message
3340 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3342 // if we have just inserted cols into an empty grid the current
3343 // cell will be undefined...
3345 SetCurrentCell( 0, 0 );
3349 if ( !GetBatchCount() ) Refresh();
3359 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
3361 // TODO: something with updateLabels flag
3365 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
3369 if ( m_table
&& m_table
->DeleteCols( pos
, numCols
) )
3371 // the table will have sent the results of the delete col
3372 // operation to this view object as a grid table message
3374 if ( m_numCols
> 0 )
3375 SetEditControlValue();
3377 HideCellEditControl();
3380 if ( !GetBatchCount() ) Refresh();
3392 // ----- event handlers
3395 // Generate a grid event based on a mouse event and
3396 // return the result of ProcessEvent()
3398 bool wxGrid::SendEvent( const wxEventType type
,
3400 wxMouseEvent
& mouseEv
)
3402 if ( type
== EVT_GRID_ROW_SIZE
||
3403 type
== EVT_GRID_COL_SIZE
)
3405 int rowOrCol
= (row
== -1 ? col
: row
);
3407 wxGridSizeEvent
gridEvt( GetId(),
3411 mouseEv
.GetX(), mouseEv
.GetY(),
3412 mouseEv
.ControlDown(),
3413 mouseEv
.ShiftDown(),
3415 mouseEv
.MetaDown() );
3417 return GetEventHandler()->ProcessEvent(gridEvt
);
3419 else if ( type
== EVT_GRID_RANGE_SELECT
)
3421 wxGridRangeSelectEvent
gridEvt( GetId(),
3425 m_selectedBottomRight
,
3426 mouseEv
.ControlDown(),
3427 mouseEv
.ShiftDown(),
3429 mouseEv
.MetaDown() );
3431 return GetEventHandler()->ProcessEvent(gridEvt
);
3435 wxGridEvent
gridEvt( GetId(),
3439 mouseEv
.GetX(), mouseEv
.GetY(),
3440 mouseEv
.ControlDown(),
3441 mouseEv
.ShiftDown(),
3443 mouseEv
.MetaDown() );
3445 return GetEventHandler()->ProcessEvent(gridEvt
);
3450 // Generate a grid event of specified type and return the result
3451 // of ProcessEvent().
3453 bool wxGrid::SendEvent( const wxEventType type
,
3456 if ( type
== EVT_GRID_ROW_SIZE
||
3457 type
== EVT_GRID_COL_SIZE
)
3459 int rowOrCol
= (row
== -1 ? col
: row
);
3461 wxGridSizeEvent
gridEvt( GetId(),
3466 return GetEventHandler()->ProcessEvent(gridEvt
);
3470 wxGridEvent
gridEvt( GetId(),
3475 return GetEventHandler()->ProcessEvent(gridEvt
);
3480 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3482 wxPaintDC
dc( this );
3484 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
3485 m_numRows
&& m_numCols
)
3487 m_currentCellCoords
.Set(0, 0);
3488 SetEditControlValue();
3489 ShowCellEditControl();
3496 // This is just here to make sure that CalcDimensions gets called when
3497 // the grid view is resized... then the size event is skipped to allow
3498 // the box sizers to handle everything
3500 void wxGrid::OnSize( wxSizeEvent
& event
)
3507 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
3509 if ( m_inOnKeyDown
)
3511 // shouldn't be here - we are going round in circles...
3513 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
3516 m_inOnKeyDown
= TRUE
;
3518 // propagate the event up and see if it gets processed
3520 wxWindow
*parent
= GetParent();
3521 wxKeyEvent
keyEvt( event
);
3522 keyEvt
.SetEventObject( parent
);
3524 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
3526 // try local handlers
3528 switch ( event
.KeyCode() )
3531 if ( event
.ControlDown() )
3533 MoveCursorUpBlock();
3542 if ( event
.ControlDown() )
3544 MoveCursorDownBlock();
3553 if ( event
.ControlDown() )
3555 MoveCursorLeftBlock();
3564 if ( event
.ControlDown() )
3566 MoveCursorRightBlock();
3575 if ( event
.ControlDown() )
3577 event
.Skip(); // to let the edit control have the return
3586 if ( event
.ControlDown() )
3588 MakeCellVisible( 0, 0 );
3589 SetCurrentCell( 0, 0 );
3598 if ( event
.ControlDown() )
3600 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
3601 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
3617 // We don't want these keys to trigger the edit control, any others?
3625 if ( !IsEditable() )
3630 // Otherwise fall through to default
3633 // now try the cell edit control
3635 if ( !IsCellEditControlEnabled() )
3636 EnableCellEditControl( TRUE
);
3637 wxKeyEvent
evt(event
);
3638 evt
.SetEventObject( m_cellEditCtrl
);
3639 m_cellEditCtrl
->GetEventHandler()->ProcessEvent( evt
);
3644 m_inOnKeyDown
= FALSE
;
3648 void wxGrid::OnEraseBackground(wxEraseEvent
&)
3652 void wxGrid::OnEditTimer(wxTimerEvent
&)
3654 m_waitForSlowClick
= FALSE
;
3659 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
3661 if ( SendEvent( EVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
3663 // the event has been intercepted - do nothing
3668 m_currentCellCoords
!= wxGridNoCellCoords
)
3670 HideCellEditControl();
3671 SaveEditControlValue();
3673 // Clear the old current cell highlight
3674 wxRect r
= BlockToDeviceRect(m_currentCellCoords
, m_currentCellCoords
);
3675 r
.x
--; r
.y
--; r
.width
++; r
.height
++;
3676 m_gridWin
->Refresh( FALSE
, &r
);
3679 m_currentCellCoords
= coords
;
3681 SetEditControlValue();
3686 ShowCellEditControl();
3688 wxClientDC
dc(m_gridWin
);
3690 DrawCellHighlight(dc
);
3693 if ( IsSelection() )
3695 wxRect
r( SelectionToDeviceRect() );
3697 if ( !GetBatchCount() ) m_gridWin
->Refresh( FALSE
, &r
);
3704 // ------ functions to get/send data (see also public functions)
3707 bool wxGrid::GetModelValues()
3711 // all we need to do is repaint the grid
3713 m_gridWin
->Refresh();
3721 bool wxGrid::SetModelValues()
3727 for ( row
= 0; row
< m_numRows
; row
++ )
3729 for ( col
= 0; col
< m_numCols
; col
++ )
3731 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
3743 // Note - this function only draws cells that are in the list of
3744 // exposed cells (usually set from the update region by
3745 // CalcExposedCells)
3747 void wxGrid::DrawGridCellArea( wxDC
& dc
)
3749 if ( !m_numRows
|| !m_numCols
) return;
3752 size_t numCells
= m_cellsExposed
.GetCount();
3754 for ( i
= 0; i
< numCells
; i
++ )
3756 DrawCell( dc
, m_cellsExposed
[i
] );
3761 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
3763 int row
= coords
.GetRow();
3764 int col
= coords
.GetCol();
3766 if ( m_colWidths
[col
] <= 0 || m_rowHeights
[row
] <= 0 )
3769 // we draw the cell border ourselves
3770 #if !WXGRID_DRAW_LINES
3771 if ( m_gridLinesEnabled
)
3772 DrawCellBorder( dc
, coords
);
3775 // but all the rest is drawn by the cell renderer and hence may be
3778 rect
.x
= m_colRights
[col
] - m_colWidths
[col
];
3779 rect
.y
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3780 rect
.width
= m_colWidths
[col
];
3781 rect
.height
= m_rowHeights
[row
];
3783 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
3784 attr
->GetRenderer()->Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
3787 if (m_currentCellCoords
== coords
)
3788 DrawCellHighlight(dc
);
3792 void wxGrid::DrawCellHighlight( wxDC
& dc
)
3794 int row
= m_currentCellCoords
.GetRow();
3795 int col
= m_currentCellCoords
.GetCol();
3797 if ( m_colWidths
[col
] <= 0 || m_rowHeights
[row
] <= 0 )
3801 rect
.x
= m_colRights
[col
] - m_colWidths
[col
];
3802 rect
.y
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3803 rect
.width
= m_colWidths
[col
] - 1;
3804 rect
.height
= m_rowHeights
[row
] - 1;
3806 dc
.SetPen(wxPen(m_gridLineColour
, 3, wxSOLID
));
3807 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
3808 //dc.SetLogicalFunction(wxINVERT);
3810 dc
.DrawRectangle(rect
);
3813 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
3815 if ( m_colWidths
[coords
.GetCol()] <=0 ||
3816 m_rowHeights
[coords
.GetRow()] <= 0 ) return;
3818 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
3819 int row
= coords
.GetRow();
3820 int col
= coords
.GetCol();
3822 // right hand border
3824 dc
.DrawLine( m_colRights
[col
], m_rowBottoms
[row
] - m_rowHeights
[row
],
3825 m_colRights
[col
], m_rowBottoms
[row
] );
3829 dc
.DrawLine( m_colRights
[col
] - m_colWidths
[col
], m_rowBottoms
[row
],
3830 m_colRights
[col
], m_rowBottoms
[row
] );
3834 // TODO: remove this ???
3835 // This is used to redraw all grid lines e.g. when the grid line colour
3838 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
)
3840 if ( !m_gridLinesEnabled
||
3842 !m_numCols
) return;
3844 int top
, bottom
, left
, right
;
3848 m_gridWin
->GetClientSize(&cw
, &ch
);
3850 // virtual coords of visible area
3852 CalcUnscrolledPosition( 0, 0, &left
, &top
);
3853 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
3857 reg
.GetBox(x
, y
, w
, h
);
3858 CalcUnscrolledPosition( x
, y
, &left
, &top
);
3859 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
3862 // avoid drawing grid lines past the last row and col
3864 right
= wxMin( right
, m_colRights
[m_numCols
-1] );
3865 bottom
= wxMin( bottom
, m_rowBottoms
[m_numRows
-1] );
3867 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
3869 // horizontal grid lines
3872 for ( i
= 0; i
< m_numRows
; i
++ )
3874 if ( m_rowBottoms
[i
]-1 > bottom
)
3878 else if ( m_rowBottoms
[i
]-1 >= top
)
3880 dc
.DrawLine( left
, m_rowBottoms
[i
]-1, right
, m_rowBottoms
[i
]-1 );
3885 // vertical grid lines
3887 for ( i
= 0; i
< m_numCols
; i
++ )
3889 if ( m_colRights
[i
]-1 > right
)
3893 else if ( m_colRights
[i
]-1 >= left
)
3895 dc
.DrawLine( m_colRights
[i
]-1, top
, m_colRights
[i
]-1, bottom
);
3901 void wxGrid::DrawRowLabels( wxDC
& dc
)
3903 if ( !m_numRows
|| !m_numCols
) return;
3906 size_t numLabels
= m_rowLabelsExposed
.GetCount();
3908 for ( i
= 0; i
< numLabels
; i
++ )
3910 DrawRowLabel( dc
, m_rowLabelsExposed
[i
] );
3915 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
3917 if ( m_rowHeights
[row
] <= 0 ) return;
3919 int rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3921 dc
.SetPen( *wxBLACK_PEN
);
3922 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
3923 m_rowLabelWidth
-1, m_rowBottoms
[row
]-1 );
3925 dc
.DrawLine( 0, m_rowBottoms
[row
]-1,
3926 m_rowLabelWidth
-1, m_rowBottoms
[row
]-1 );
3928 dc
.SetPen( *wxWHITE_PEN
);
3929 dc
.DrawLine( 0, rowTop
, 0, m_rowBottoms
[row
]-1 );
3930 dc
.DrawLine( 0, rowTop
, m_rowLabelWidth
-1, rowTop
);
3932 dc
.SetBackgroundMode( wxTRANSPARENT
);
3933 dc
.SetTextForeground( GetLabelTextColour() );
3934 dc
.SetFont( GetLabelFont() );
3937 GetRowLabelAlignment( &hAlign
, &vAlign
);
3941 rect
.SetY( m_rowBottoms
[row
] - m_rowHeights
[row
] + 2 );
3942 rect
.SetWidth( m_rowLabelWidth
- 4 );
3943 rect
.SetHeight( m_rowHeights
[row
] - 4 );
3944 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
3948 void wxGrid::DrawColLabels( wxDC
& dc
)
3950 if ( !m_numRows
|| !m_numCols
) return;
3953 size_t numLabels
= m_colLabelsExposed
.GetCount();
3955 for ( i
= 0; i
< numLabels
; i
++ )
3957 DrawColLabel( dc
, m_colLabelsExposed
[i
] );
3962 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
3964 if ( m_colWidths
[col
] <= 0 ) return;
3966 int colLeft
= m_colRights
[col
] - m_colWidths
[col
];
3968 dc
.SetPen( *wxBLACK_PEN
);
3969 dc
.DrawLine( m_colRights
[col
]-1, 0,
3970 m_colRights
[col
]-1, m_colLabelHeight
-1 );
3972 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
3973 m_colRights
[col
]-1, m_colLabelHeight
-1 );
3975 dc
.SetPen( *wxWHITE_PEN
);
3976 dc
.DrawLine( colLeft
, 0, colLeft
, m_colLabelHeight
-1 );
3977 dc
.DrawLine( colLeft
, 0, m_colRights
[col
]-1, 0 );
3979 dc
.SetBackgroundMode( wxTRANSPARENT
);
3980 dc
.SetTextForeground( GetLabelTextColour() );
3981 dc
.SetFont( GetLabelFont() );
3983 dc
.SetBackgroundMode( wxTRANSPARENT
);
3984 dc
.SetTextForeground( GetLabelTextColour() );
3985 dc
.SetFont( GetLabelFont() );
3988 GetColLabelAlignment( &hAlign
, &vAlign
);
3991 rect
.SetX( m_colRights
[col
] - m_colWidths
[col
] + 2 );
3993 rect
.SetWidth( m_colWidths
[col
] - 4 );
3994 rect
.SetHeight( m_colLabelHeight
- 4 );
3995 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
);
3999 void wxGrid::DrawTextRectangle( wxDC
& dc
,
4000 const wxString
& value
,
4005 long textWidth
, textHeight
;
4006 long lineWidth
, lineHeight
;
4007 wxArrayString lines
;
4009 dc
.SetClippingRegion( rect
);
4010 StringToLines( value
, lines
);
4011 if ( lines
.GetCount() )
4013 GetTextBoxSize( dc
, lines
, &textWidth
, &textHeight
);
4014 dc
.GetTextExtent( lines
[0], &lineWidth
, &lineHeight
);
4017 switch ( horizAlign
)
4020 x
= rect
.x
+ (rect
.width
- textWidth
- 1);
4024 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
4033 switch ( vertAlign
)
4036 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
4040 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
4049 for ( size_t i
= 0; i
< lines
.GetCount(); i
++ )
4051 dc
.DrawText( lines
[i
], (long)x
, (long)y
);
4056 dc
.DestroyClippingRegion();
4060 // Split multi line text up into an array of strings. Any existing
4061 // contents of the string array are preserved.
4063 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
4067 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
4068 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
4070 while ( startPos
< (int)tVal
.Length() )
4072 pos
= tVal
.Mid(startPos
).Find( eol
);
4077 else if ( pos
== 0 )
4079 lines
.Add( wxEmptyString
);
4083 lines
.Add( value
.Mid(startPos
, pos
) );
4087 if ( startPos
< (int)value
.Length() )
4089 lines
.Add( value
.Mid( startPos
) );
4094 void wxGrid::GetTextBoxSize( wxDC
& dc
,
4095 wxArrayString
& lines
,
4096 long *width
, long *height
)
4103 for ( i
= 0; i
< lines
.GetCount(); i
++ )
4105 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
4106 w
= wxMax( w
, lineW
);
4116 // ------ Edit control functions
4120 void wxGrid::EnableEditing( bool edit
)
4122 // TODO: improve this ?
4124 if ( edit
!= m_editable
)
4128 // TODO: extend this for other edit control types
4130 if ( m_editCtrlType
== wxGRID_TEXTCTRL
)
4132 ((wxTextCtrl
*)m_cellEditCtrl
)->SetEditable( m_editable
);
4138 void wxGrid::EnableCellEditControl( bool enable
)
4140 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4141 SetCurrentCell( 0, 0 );
4142 if ( m_cellEditCtrl
&&
4143 enable
!= m_cellEditCtrlEnabled
)
4148 m_cellEditCtrlEnabled
= enable
;
4149 SetEditControlValue();
4150 // requires m_cellEditCtrlEnabled to be already true
4151 ShowCellEditControl();
4155 HideCellEditControl();
4156 // requires m_cellEditCtrlEnabled to be still true
4157 SaveEditControlValue();
4158 m_cellEditCtrlEnabled
= enable
;
4164 void wxGrid::ShowCellEditControl()
4168 if ( IsCellEditControlEnabled() )
4170 if ( !IsVisible( m_currentCellCoords
) )
4176 rect
= CellToRect( m_currentCellCoords
);
4178 // convert to scrolled coords
4180 int left
, top
, right
, bottom
;
4181 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
4182 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
4183 left
--; top
--; right
--; bottom
--; // cell is shifted by one pixel
4185 m_gridWin
->GetClientSize( &cw
, &ch
);
4187 // Make the edit control large enough to allow for internal margins
4188 // TODO: remove this if the text ctrl sizing is improved esp. for unix
4191 #if defined(__WXMOTIF__)
4192 if ( m_currentCellCoords
.GetRow() == 0 ||
4193 m_currentCellCoords
.GetCol() == 0 )
4202 if ( m_currentCellCoords
.GetRow() == 0 ||
4203 m_currentCellCoords
.GetCol() == 0 )
4213 #if defined(__WXGTK__)
4216 if (left
!= 0) left_diff
++;
4217 if (top
!= 0) top_diff
++;
4218 rect
.SetLeft( left
+ left_diff
);
4219 rect
.SetTop( top
+ top_diff
);
4220 rect
.SetRight( rect
.GetRight() - left_diff
);
4221 rect
.SetBottom( rect
.GetBottom() - top_diff
);
4223 rect
.SetLeft( wxMax(0, left
- extra
) );
4224 rect
.SetTop( wxMax(0, top
- extra
) );
4225 rect
.SetRight( rect
.GetRight() + 2*extra
);
4226 rect
.SetBottom( rect
.GetBottom() + 2*extra
);
4229 m_cellEditCtrl
->SetSize( rect
);
4230 m_cellEditCtrl
->Show( TRUE
);
4232 switch ( m_editCtrlType
)
4234 case wxGRID_TEXTCTRL
:
4235 ((wxTextCtrl
*) m_cellEditCtrl
)->SetInsertionPointEnd();
4238 case wxGRID_CHECKBOX
:
4239 // TODO: anything ???
4244 // TODO: anything ???
4248 case wxGRID_COMBOBOX
:
4249 // TODO: anything ???
4254 m_cellEditCtrl
->SetFocus();
4260 void wxGrid::HideCellEditControl()
4262 if ( IsCellEditControlEnabled() )
4264 m_cellEditCtrl
->Show( FALSE
);
4270 void wxGrid::SetEditControlValue( const wxString
& value
)
4276 s
= GetCellValue(m_currentCellCoords
);
4280 if ( IsCellEditControlEnabled() )
4282 switch ( m_editCtrlType
)
4284 case wxGRID_TEXTCTRL
:
4285 ((wxGridTextCtrl
*)m_cellEditCtrl
)->SetStartValue(s
);
4288 case wxGRID_CHECKBOX
:
4289 // TODO: implement this
4294 // TODO: implement this
4298 case wxGRID_COMBOBOX
:
4299 // TODO: implement this
4308 void wxGrid::SaveEditControlValue()
4312 wxWindow
*ctrl
= (wxWindow
*)NULL
;
4314 if ( IsCellEditControlEnabled() )
4316 ctrl
= m_cellEditCtrl
;
4323 bool valueChanged
= FALSE
;
4325 switch ( m_editCtrlType
)
4327 case wxGRID_TEXTCTRL
:
4328 valueChanged
= (((wxGridTextCtrl
*)ctrl
)->GetValue() !=
4329 ((wxGridTextCtrl
*)ctrl
)->GetStartValue());
4330 SetCellValue( m_currentCellCoords
,
4331 ((wxTextCtrl
*) ctrl
)->GetValue() );
4334 case wxGRID_CHECKBOX
:
4335 // TODO: implement this
4340 // TODO: implement this
4344 case wxGRID_COMBOBOX
:
4345 // TODO: implement this
4352 SendEvent( EVT_GRID_CELL_CHANGE
,
4353 m_currentCellCoords
.GetRow(),
4354 m_currentCellCoords
.GetCol() );
4361 // ------ Grid location functions
4362 // Note that all of these functions work with the logical coordinates of
4363 // grid cells and labels so you will need to convert from device
4364 // coordinates for mouse events etc.
4367 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
4369 int row
= YToRow(y
);
4370 int col
= XToCol(x
);
4372 if ( row
== -1 || col
== -1 )
4374 coords
= wxGridNoCellCoords
;
4378 coords
.Set( row
, col
);
4383 int wxGrid::YToRow( int y
)
4387 for ( i
= 0; i
< m_numRows
; i
++ )
4389 if ( y
< m_rowBottoms
[i
] ) return i
;
4392 return m_numRows
; //-1;
4396 int wxGrid::XToCol( int x
)
4400 for ( i
= 0; i
< m_numCols
; i
++ )
4402 if ( x
< m_colRights
[i
] ) return i
;
4405 return m_numCols
; //-1;
4409 // return the row number that that the y coord is near the edge of, or
4410 // -1 if not near an edge
4412 int wxGrid::YToEdgeOfRow( int y
)
4416 for ( i
= 0; i
< m_numRows
; i
++ )
4418 if ( m_rowHeights
[i
] > WXGRID_LABEL_EDGE_ZONE
)
4420 d
= abs( y
- m_rowBottoms
[i
] );
4422 if ( d
< WXGRID_LABEL_EDGE_ZONE
) return i
;
4431 // return the col number that that the x coord is near the edge of, or
4432 // -1 if not near an edge
4434 int wxGrid::XToEdgeOfCol( int x
)
4438 for ( i
= 0; i
< m_numCols
; i
++ )
4440 if ( m_colWidths
[i
] > WXGRID_LABEL_EDGE_ZONE
)
4442 d
= abs( x
- m_colRights
[i
] );
4444 if ( d
< WXGRID_LABEL_EDGE_ZONE
) return i
;
4453 wxRect
wxGrid::CellToRect( int row
, int col
)
4455 wxRect
rect( -1, -1, -1, -1 );
4457 if ( row
>= 0 && row
< m_numRows
&&
4458 col
>= 0 && col
< m_numCols
)
4460 rect
.x
= m_colRights
[col
] - m_colWidths
[col
];
4461 rect
.y
= m_rowBottoms
[row
] - m_rowHeights
[row
];
4462 rect
.width
= m_colWidths
[col
];
4463 rect
.height
= m_rowHeights
[ row
];
4470 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
4472 // get the cell rectangle in logical coords
4474 wxRect
r( CellToRect( row
, col
) );
4476 // convert to device coords
4478 int left
, top
, right
, bottom
;
4479 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
4480 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
4482 // check against the client area of the grid window
4485 m_gridWin
->GetClientSize( &cw
, &ch
);
4487 if ( wholeCellVisible
)
4489 // is the cell wholly visible ?
4491 return ( left
>= 0 && right
<= cw
&&
4492 top
>= 0 && bottom
<= ch
);
4496 // is the cell partly visible ?
4498 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
4499 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
4504 // make the specified cell location visible by doing a minimal amount
4507 void wxGrid::MakeCellVisible( int row
, int col
)
4510 int xpos
= -1, ypos
= -1;
4512 if ( row
>= 0 && row
< m_numRows
&&
4513 col
>= 0 && col
< m_numCols
)
4515 // get the cell rectangle in logical coords
4517 wxRect
r( CellToRect( row
, col
) );
4519 // convert to device coords
4521 int left
, top
, right
, bottom
;
4522 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
4523 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
4526 m_gridWin
->GetClientSize( &cw
, &ch
);
4532 else if ( bottom
> ch
)
4534 int h
= r
.GetHeight();
4536 for ( i
= row
-1; i
>= 0; i
-- )
4538 if ( h
+ m_rowHeights
[i
] > ch
) break;
4540 h
+= m_rowHeights
[i
];
4541 ypos
-= m_rowHeights
[i
];
4544 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
4545 // have rounding errors (this is important, because if we do, we
4546 // might not scroll at all and some cells won't be redrawn)
4547 ypos
+= GRID_SCROLL_LINE
/ 2;
4554 else if ( right
> cw
)
4556 int w
= r
.GetWidth();
4558 for ( i
= col
-1; i
>= 0; i
-- )
4560 if ( w
+ m_colWidths
[i
] > cw
) break;
4562 w
+= m_colWidths
[i
];
4563 xpos
-= m_colWidths
[i
];
4566 // see comment for ypos above
4567 xpos
+= GRID_SCROLL_LINE
/ 2;
4570 if ( xpos
!= -1 || ypos
!= -1 )
4572 if ( xpos
!= -1 ) xpos
/= GRID_SCROLL_LINE
;
4573 if ( ypos
!= -1 ) ypos
/= GRID_SCROLL_LINE
;
4574 Scroll( xpos
, ypos
);
4582 // ------ Grid cursor movement functions
4585 bool wxGrid::MoveCursorUp()
4587 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
4588 m_currentCellCoords
.GetRow() > 0 )
4590 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
4591 m_currentCellCoords
.GetCol() );
4593 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
4594 m_currentCellCoords
.GetCol() );
4603 bool wxGrid::MoveCursorDown()
4605 // TODO: allow for scrolling
4607 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
4608 m_currentCellCoords
.GetRow() < m_numRows
-1 )
4610 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
4611 m_currentCellCoords
.GetCol() );
4613 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
4614 m_currentCellCoords
.GetCol() );
4623 bool wxGrid::MoveCursorLeft()
4625 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
4626 m_currentCellCoords
.GetCol() > 0 )
4628 MakeCellVisible( m_currentCellCoords
.GetRow(),
4629 m_currentCellCoords
.GetCol() - 1 );
4631 SetCurrentCell( m_currentCellCoords
.GetRow(),
4632 m_currentCellCoords
.GetCol() - 1 );
4641 bool wxGrid::MoveCursorRight()
4643 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
4644 m_currentCellCoords
.GetCol() < m_numCols
- 1 )
4646 MakeCellVisible( m_currentCellCoords
.GetRow(),
4647 m_currentCellCoords
.GetCol() + 1 );
4649 SetCurrentCell( m_currentCellCoords
.GetRow(),
4650 m_currentCellCoords
.GetCol() + 1 );
4659 bool wxGrid::MovePageUp()
4661 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
4663 int row
= m_currentCellCoords
.GetRow();
4667 m_gridWin
->GetClientSize( &cw
, &ch
);
4669 int y
= m_rowBottoms
[ row
] - m_rowHeights
[ row
];
4670 int newRow
= YToRow( y
- ch
+ 1 );
4675 else if ( newRow
== row
)
4680 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
4681 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
4689 bool wxGrid::MovePageDown()
4691 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
4693 int row
= m_currentCellCoords
.GetRow();
4694 if ( row
< m_numRows
)
4697 m_gridWin
->GetClientSize( &cw
, &ch
);
4699 int y
= m_rowBottoms
[ row
] - m_rowHeights
[ row
];
4700 int newRow
= YToRow( y
+ ch
);
4703 newRow
= m_numRows
- 1;
4705 else if ( newRow
== row
)
4710 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
4711 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
4719 bool wxGrid::MoveCursorUpBlock()
4722 m_currentCellCoords
!= wxGridNoCellCoords
&&
4723 m_currentCellCoords
.GetRow() > 0 )
4725 int row
= m_currentCellCoords
.GetRow();
4726 int col
= m_currentCellCoords
.GetCol();
4728 if ( m_table
->IsEmptyCell(row
, col
) )
4730 // starting in an empty cell: find the next block of
4736 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4739 else if ( m_table
->IsEmptyCell(row
-1, col
) )
4741 // starting at the top of a block: find the next block
4747 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4752 // starting within a block: find the top of the block
4757 if ( m_table
->IsEmptyCell(row
, col
) )
4765 MakeCellVisible( row
, col
);
4766 SetCurrentCell( row
, col
);
4774 bool wxGrid::MoveCursorDownBlock()
4777 m_currentCellCoords
!= wxGridNoCellCoords
&&
4778 m_currentCellCoords
.GetRow() < m_numRows
-1 )
4780 int row
= m_currentCellCoords
.GetRow();
4781 int col
= m_currentCellCoords
.GetCol();
4783 if ( m_table
->IsEmptyCell(row
, col
) )
4785 // starting in an empty cell: find the next block of
4788 while ( row
< m_numRows
-1 )
4791 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4794 else if ( m_table
->IsEmptyCell(row
+1, col
) )
4796 // starting at the bottom of a block: find the next block
4799 while ( row
< m_numRows
-1 )
4802 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4807 // starting within a block: find the bottom of the block
4809 while ( row
< m_numRows
-1 )
4812 if ( m_table
->IsEmptyCell(row
, col
) )
4820 MakeCellVisible( row
, col
);
4821 SetCurrentCell( row
, col
);
4829 bool wxGrid::MoveCursorLeftBlock()
4832 m_currentCellCoords
!= wxGridNoCellCoords
&&
4833 m_currentCellCoords
.GetCol() > 0 )
4835 int row
= m_currentCellCoords
.GetRow();
4836 int col
= m_currentCellCoords
.GetCol();
4838 if ( m_table
->IsEmptyCell(row
, col
) )
4840 // starting in an empty cell: find the next block of
4846 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4849 else if ( m_table
->IsEmptyCell(row
, col
-1) )
4851 // starting at the left of a block: find the next block
4857 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4862 // starting within a block: find the left of the block
4867 if ( m_table
->IsEmptyCell(row
, col
) )
4875 MakeCellVisible( row
, col
);
4876 SetCurrentCell( row
, col
);
4884 bool wxGrid::MoveCursorRightBlock()
4887 m_currentCellCoords
!= wxGridNoCellCoords
&&
4888 m_currentCellCoords
.GetCol() < m_numCols
-1 )
4890 int row
= m_currentCellCoords
.GetRow();
4891 int col
= m_currentCellCoords
.GetCol();
4893 if ( m_table
->IsEmptyCell(row
, col
) )
4895 // starting in an empty cell: find the next block of
4898 while ( col
< m_numCols
-1 )
4901 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4904 else if ( m_table
->IsEmptyCell(row
, col
+1) )
4906 // starting at the right of a block: find the next block
4909 while ( col
< m_numCols
-1 )
4912 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4917 // starting within a block: find the right of the block
4919 while ( col
< m_numCols
-1 )
4922 if ( m_table
->IsEmptyCell(row
, col
) )
4930 MakeCellVisible( row
, col
);
4931 SetCurrentCell( row
, col
);
4942 // ------ Label values and formatting
4945 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
4947 *horiz
= m_rowLabelHorizAlign
;
4948 *vert
= m_rowLabelVertAlign
;
4951 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
4953 *horiz
= m_colLabelHorizAlign
;
4954 *vert
= m_colLabelVertAlign
;
4957 wxString
wxGrid::GetRowLabelValue( int row
)
4961 return m_table
->GetRowLabelValue( row
);
4971 wxString
wxGrid::GetColLabelValue( int col
)
4975 return m_table
->GetColLabelValue( col
);
4986 void wxGrid::SetRowLabelSize( int width
)
4988 width
= wxMax( width
, 0 );
4989 if ( width
!= m_rowLabelWidth
)
4993 m_rowLabelWin
->Show( FALSE
);
4994 m_cornerLabelWin
->Show( FALSE
);
4996 else if ( m_rowLabelWidth
== 0 )
4998 m_rowLabelWin
->Show( TRUE
);
4999 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
5002 m_rowLabelWidth
= width
;
5009 void wxGrid::SetColLabelSize( int height
)
5011 height
= wxMax( height
, 0 );
5012 if ( height
!= m_colLabelHeight
)
5016 m_colLabelWin
->Show( FALSE
);
5017 m_cornerLabelWin
->Show( FALSE
);
5019 else if ( m_colLabelHeight
== 0 )
5021 m_colLabelWin
->Show( TRUE
);
5022 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
5025 m_colLabelHeight
= height
;
5032 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
5034 if ( m_labelBackgroundColour
!= colour
)
5036 m_labelBackgroundColour
= colour
;
5037 m_rowLabelWin
->SetBackgroundColour( colour
);
5038 m_colLabelWin
->SetBackgroundColour( colour
);
5039 m_cornerLabelWin
->SetBackgroundColour( colour
);
5041 if ( !GetBatchCount() )
5043 m_rowLabelWin
->Refresh();
5044 m_colLabelWin
->Refresh();
5045 m_cornerLabelWin
->Refresh();
5050 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
5052 if ( m_labelTextColour
!= colour
)
5054 m_labelTextColour
= colour
;
5055 if ( !GetBatchCount() )
5057 m_rowLabelWin
->Refresh();
5058 m_colLabelWin
->Refresh();
5063 void wxGrid::SetLabelFont( const wxFont
& font
)
5066 if ( !GetBatchCount() )
5068 m_rowLabelWin
->Refresh();
5069 m_colLabelWin
->Refresh();
5073 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
5075 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
5077 m_rowLabelHorizAlign
= horiz
;
5080 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
5082 m_rowLabelVertAlign
= vert
;
5085 if ( !GetBatchCount() )
5087 m_rowLabelWin
->Refresh();
5091 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
5093 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
5095 m_colLabelHorizAlign
= horiz
;
5098 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
5100 m_colLabelVertAlign
= vert
;
5103 if ( !GetBatchCount() )
5105 m_colLabelWin
->Refresh();
5109 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
5113 m_table
->SetRowLabelValue( row
, s
);
5114 if ( !GetBatchCount() )
5116 wxRect rect
= CellToRect( row
, 0);
5117 if ( rect
.height
> 0 )
5119 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
5121 rect
.width
= m_rowLabelWidth
;
5122 m_rowLabelWin
->Refresh( TRUE
, &rect
);
5128 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
5132 m_table
->SetColLabelValue( col
, s
);
5133 if ( !GetBatchCount() )
5135 wxRect rect
= CellToRect( 0, col
);
5136 if ( rect
.width
> 0 )
5138 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
5140 rect
.height
= m_colLabelHeight
;
5141 m_colLabelWin
->Refresh( TRUE
, &rect
);
5147 void wxGrid::SetGridLineColour( const wxColour
& colour
)
5149 if ( m_gridLineColour
!= colour
)
5151 m_gridLineColour
= colour
;
5153 wxClientDC
dc( m_gridWin
);
5155 DrawAllGridLines( dc
, wxRegion() );
5159 void wxGrid::EnableGridLines( bool enable
)
5161 if ( enable
!= m_gridLinesEnabled
)
5163 m_gridLinesEnabled
= enable
;
5165 if ( !GetBatchCount() )
5169 wxClientDC
dc( m_gridWin
);
5171 DrawAllGridLines( dc
, wxRegion() );
5175 m_gridWin
->Refresh();
5182 int wxGrid::GetDefaultRowSize()
5184 return m_defaultRowHeight
;
5187 int wxGrid::GetRowSize( int row
)
5189 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
5191 return m_rowHeights
[row
];
5194 int wxGrid::GetDefaultColSize()
5196 return m_defaultColWidth
;
5199 int wxGrid::GetColSize( int col
)
5201 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
5203 return m_colWidths
[col
];
5206 // ============================================================================
5207 // access to the grid attributes: each of them has a default value in the grid
5208 // itself and may be overidden on a per-cell basis
5209 // ============================================================================
5211 // ----------------------------------------------------------------------------
5212 // setting default attributes
5213 // ----------------------------------------------------------------------------
5215 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
5217 m_defaultCellAttr
->SetBackgroundColour(col
);
5220 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
5222 m_defaultCellAttr
->SetTextColour(col
);
5225 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
5227 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
5230 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
5232 m_defaultCellAttr
->SetFont(font
);
5235 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
5237 m_defaultCellAttr
->SetRenderer(renderer
);
5240 // ----------------------------------------------------------------------------
5241 // access to the default attrbiutes
5242 // ----------------------------------------------------------------------------
5244 wxColour
wxGrid::GetDefaultCellBackgroundColour()
5246 return m_defaultCellAttr
->GetBackgroundColour();
5249 wxColour
wxGrid::GetDefaultCellTextColour()
5251 return m_defaultCellAttr
->GetTextColour();
5254 wxFont
wxGrid::GetDefaultCellFont()
5256 return m_defaultCellAttr
->GetFont();
5259 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
5261 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
5264 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
5266 return m_defaultCellAttr
->GetRenderer();
5269 // ----------------------------------------------------------------------------
5270 // access to cell attributes
5271 // ----------------------------------------------------------------------------
5273 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
5275 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5276 wxColour colour
= attr
->GetBackgroundColour();
5281 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
5283 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5284 wxColour colour
= attr
->GetTextColour();
5289 wxFont
wxGrid::GetCellFont( int row
, int col
)
5291 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5292 wxFont font
= attr
->GetFont();
5297 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
5299 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5300 attr
->GetAlignment(horiz
, vert
);
5304 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
)
5306 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5307 wxGridCellRenderer
* renderer
= attr
->GetRenderer();
5312 // ----------------------------------------------------------------------------
5313 // attribute support: cache, automatic provider creation, ...
5314 // ----------------------------------------------------------------------------
5316 bool wxGrid::CanHaveAttributes()
5323 // RD: Maybe m_table->CanHaveAttributes() would be better in case the
5324 // table is providing the attributes itself??? In which case
5325 // I don't think the grid should create a Provider object for the
5326 // table but the table should be smart enough to do that on its own.
5327 if ( !m_table
->GetAttrProvider() )
5329 // use the default attr provider by default
5330 // (another choice would be to just return FALSE thus forcing the user
5332 m_table
->SetAttrProvider(new wxGridCellAttrProvider
);
5338 void wxGrid::ClearAttrCache()
5340 if ( m_attrCache
.row
!= -1 )
5342 m_attrCache
.attr
->SafeDecRef();
5343 m_attrCache
.row
= -1;
5347 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
5349 wxGrid
*self
= (wxGrid
*)this; // const_cast
5351 self
->ClearAttrCache();
5352 self
->m_attrCache
.row
= row
;
5353 self
->m_attrCache
.col
= col
;
5354 self
->m_attrCache
.attr
= attr
;
5358 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
5360 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
5362 *attr
= m_attrCache
.attr
;
5363 (*attr
)->SafeIncRef();
5365 #ifdef DEBUG_ATTR_CACHE
5366 gs_nAttrCacheHits
++;
5373 #ifdef DEBUG_ATTR_CACHE
5374 gs_nAttrCacheMisses
++;
5380 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
5382 wxGridCellAttr
*attr
;
5383 if ( !LookupAttr(row
, col
, &attr
) )
5385 attr
= m_table
? m_table
->GetAttr(row
, col
) : (wxGridCellAttr
*)NULL
;
5386 CacheAttr(row
, col
, attr
);
5389 attr
->SetDefAttr(m_defaultCellAttr
);
5391 attr
= m_defaultCellAttr
;
5398 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
5400 wxGridCellAttr
*attr
;
5401 if ( !LookupAttr(row
, col
, &attr
) || !attr
)
5403 wxASSERT_MSG( m_table
,
5404 _T("we may only be called if CanHaveAttributes() "
5405 "returned TRUE and then m_table should be !NULL") );
5407 attr
= m_table
->GetAttr(row
, col
);
5410 attr
= new wxGridCellAttr
;
5412 // artificially inc the ref count to match DecRef() in caller
5415 m_table
->SetAttr(attr
, row
, col
);
5418 CacheAttr(row
, col
, attr
);
5420 attr
->SetDefAttr(m_defaultCellAttr
);
5424 // ----------------------------------------------------------------------------
5425 // setting cell attributes: this is forwarded to the table
5426 // ----------------------------------------------------------------------------
5428 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
5430 if ( CanHaveAttributes() )
5432 m_table
->SetRowAttr(attr
, row
);
5440 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
5442 if ( CanHaveAttributes() )
5444 m_table
->SetColAttr(attr
, col
);
5452 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
5454 if ( CanHaveAttributes() )
5456 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5457 attr
->SetBackgroundColour(colour
);
5462 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
5464 if ( CanHaveAttributes() )
5466 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5467 attr
->SetTextColour(colour
);
5472 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
5474 if ( CanHaveAttributes() )
5476 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5477 attr
->SetFont(font
);
5482 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
5484 if ( CanHaveAttributes() )
5486 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5487 attr
->SetAlignment(horiz
, vert
);
5492 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
5494 if ( CanHaveAttributes() )
5496 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5497 attr
->SetRenderer(renderer
);
5502 // ----------------------------------------------------------------------------
5504 // ----------------------------------------------------------------------------
5506 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
5508 m_defaultRowHeight
= wxMax( height
, WXGRID_MIN_ROW_HEIGHT
);
5510 if ( resizeExistingRows
)
5514 for ( row
= 0; row
< m_numRows
; row
++ )
5516 m_rowHeights
[row
] = m_defaultRowHeight
;
5517 bottom
+= m_defaultRowHeight
;
5518 m_rowBottoms
[row
] = bottom
;
5524 void wxGrid::SetRowSize( int row
, int height
)
5526 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
5530 int h
= wxMax( 0, height
);
5531 int diff
= h
- m_rowHeights
[row
];
5533 m_rowHeights
[row
] = h
;
5534 for ( i
= row
; i
< m_numRows
; i
++ )
5536 m_rowBottoms
[i
] += diff
;
5541 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
5543 m_defaultColWidth
= wxMax( width
, WXGRID_MIN_COL_WIDTH
);
5545 if ( resizeExistingCols
)
5549 for ( col
= 0; col
< m_numCols
; col
++ )
5551 m_colWidths
[col
] = m_defaultColWidth
;
5552 right
+= m_defaultColWidth
;
5553 m_colRights
[col
] = right
;
5559 void wxGrid::SetColSize( int col
, int width
)
5561 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
5565 int w
= wxMax( 0, width
);
5566 int diff
= w
- m_colWidths
[col
];
5567 m_colWidths
[col
] = w
;
5569 for ( i
= col
; i
< m_numCols
; i
++ )
5571 m_colRights
[i
] += diff
;
5578 // ------ cell value accessor functions
5581 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
5585 m_table
->SetValue( row
, col
, s
.c_str() );
5586 if ( !GetBatchCount() )
5588 wxClientDC
dc( m_gridWin
);
5590 DrawCell( dc
, wxGridCellCoords(row
, col
) );
5593 #if 0 // TODO: edit in place
5595 if ( m_currentCellCoords
.GetRow() == row
&&
5596 m_currentCellCoords
.GetCol() == col
)
5598 SetEditControlValue( s
);
5607 // ------ Block, row and col selection
5610 void wxGrid::SelectRow( int row
, bool addToSelected
)
5614 if ( IsSelection() && addToSelected
)
5617 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
5620 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
5621 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
5622 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
5623 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
5627 need_refresh
[0] = TRUE
;
5628 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( row
, 0 ),
5629 wxGridCellCoords ( oldTop
- 1,
5631 m_selectedTopLeft
.SetRow( row
);
5636 need_refresh
[1] = TRUE
;
5637 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
, 0 ),
5638 wxGridCellCoords ( oldBottom
,
5641 m_selectedTopLeft
.SetCol( 0 );
5644 if ( oldBottom
< row
)
5646 need_refresh
[2] = TRUE
;
5647 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1, 0 ),
5648 wxGridCellCoords ( row
,
5650 m_selectedBottomRight
.SetRow( row
);
5653 if ( oldRight
< m_numCols
- 1 )
5655 need_refresh
[3] = TRUE
;
5656 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5658 wxGridCellCoords ( oldBottom
,
5660 m_selectedBottomRight
.SetCol( m_numCols
- 1 );
5663 for (i
= 0; i
< 4; i
++ )
5664 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
5665 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
5669 r
= SelectionToDeviceRect();
5671 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
5673 m_selectedTopLeft
.Set( row
, 0 );
5674 m_selectedBottomRight
.Set( row
, m_numCols
-1 );
5675 r
= SelectionToDeviceRect();
5676 m_gridWin
->Refresh( FALSE
, &r
);
5679 wxGridRangeSelectEvent
gridEvt( GetId(),
5680 EVT_GRID_RANGE_SELECT
,
5683 m_selectedBottomRight
);
5685 GetEventHandler()->ProcessEvent(gridEvt
);
5689 void wxGrid::SelectCol( int col
, bool addToSelected
)
5691 if ( IsSelection() && addToSelected
)
5694 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
5697 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
5698 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
5699 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
5700 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
5702 if ( oldLeft
> col
)
5704 need_refresh
[0] = TRUE
;
5705 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( 0, col
),
5706 wxGridCellCoords ( m_numRows
- 1,
5708 m_selectedTopLeft
.SetCol( col
);
5713 need_refresh
[1] = TRUE
;
5714 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( 0, oldLeft
),
5715 wxGridCellCoords ( oldTop
- 1,
5717 m_selectedTopLeft
.SetRow( 0 );
5720 if ( oldRight
< col
)
5722 need_refresh
[2] = TRUE
;
5723 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( 0, oldRight
+ 1 ),
5724 wxGridCellCoords ( m_numRows
- 1,
5726 m_selectedBottomRight
.SetCol( col
);
5729 if ( oldBottom
< m_numRows
- 1 )
5731 need_refresh
[3] = TRUE
;
5732 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1,
5734 wxGridCellCoords ( m_numRows
- 1,
5736 m_selectedBottomRight
.SetRow( m_numRows
- 1 );
5739 for (i
= 0; i
< 4; i
++ )
5740 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
5741 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
5747 r
= SelectionToDeviceRect();
5749 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
5751 m_selectedTopLeft
.Set( 0, col
);
5752 m_selectedBottomRight
.Set( m_numRows
-1, col
);
5753 r
= SelectionToDeviceRect();
5754 m_gridWin
->Refresh( FALSE
, &r
);
5757 wxGridRangeSelectEvent
gridEvt( GetId(),
5758 EVT_GRID_RANGE_SELECT
,
5761 m_selectedBottomRight
);
5763 GetEventHandler()->ProcessEvent(gridEvt
);
5767 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
5770 wxGridCellCoords updateTopLeft
, updateBottomRight
;
5772 if ( topRow
> bottomRow
)
5779 if ( leftCol
> rightCol
)
5786 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
5787 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
5789 if ( m_selectedTopLeft
!= updateTopLeft
||
5790 m_selectedBottomRight
!= updateBottomRight
)
5792 // Compute two optimal update rectangles:
5793 // Either one rectangle is a real subset of the
5794 // other, or they are (almost) disjoint!
5796 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
5799 // Store intermediate values
5800 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
5801 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
5802 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
5803 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
5805 // Determine the outer/inner coordinates.
5806 if (oldLeft
> leftCol
)
5812 if (oldTop
> topRow
)
5818 if (oldRight
< rightCol
)
5821 oldRight
= rightCol
;
5824 if (oldBottom
< bottomRow
)
5827 oldBottom
= bottomRow
;
5831 // Now, either the stuff marked old is the outer
5832 // rectangle or we don't have a situation where one
5833 // is contained in the other.
5835 if ( oldLeft
< leftCol
)
5837 need_refresh
[0] = TRUE
;
5838 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5840 wxGridCellCoords ( oldBottom
,
5844 if ( oldTop
< topRow
)
5846 need_refresh
[1] = TRUE
;
5847 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5849 wxGridCellCoords ( topRow
- 1,
5853 if ( oldRight
> rightCol
)
5855 need_refresh
[2] = TRUE
;
5856 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5858 wxGridCellCoords ( oldBottom
,
5862 if ( oldBottom
> bottomRow
)
5864 need_refresh
[3] = TRUE
;
5865 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
5867 wxGridCellCoords ( oldBottom
,
5873 m_selectedTopLeft
= updateTopLeft
;
5874 m_selectedBottomRight
= updateBottomRight
;
5876 // various Refresh() calls
5877 for (i
= 0; i
< 4; i
++ )
5878 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
5879 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
5882 // only generate an event if the block is not being selected by
5883 // dragging the mouse (in which case the event will be generated in
5884 // the mouse event handler)
5885 if ( !m_isDragging
)
5887 wxGridRangeSelectEvent
gridEvt( GetId(),
5888 EVT_GRID_RANGE_SELECT
,
5891 m_selectedBottomRight
);
5893 GetEventHandler()->ProcessEvent(gridEvt
);
5897 void wxGrid::SelectAll()
5899 m_selectedTopLeft
.Set( 0, 0 );
5900 m_selectedBottomRight
.Set( m_numRows
-1, m_numCols
-1 );
5902 m_gridWin
->Refresh();
5906 void wxGrid::ClearSelection()
5908 m_selectedTopLeft
= wxGridNoCellCoords
;
5909 m_selectedBottomRight
= wxGridNoCellCoords
;
5913 // This function returns the rectangle that encloses the given block
5914 // in device coords clipped to the client size of the grid window.
5916 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
5917 const wxGridCellCoords
&bottomRight
)
5919 wxRect
rect( wxGridNoCellRect
);
5922 cellRect
= CellToRect( topLeft
);
5923 if ( cellRect
!= wxGridNoCellRect
)
5929 rect
= wxRect( 0, 0, 0, 0 );
5932 cellRect
= CellToRect( bottomRight
);
5933 if ( cellRect
!= wxGridNoCellRect
)
5939 return wxGridNoCellRect
;
5942 // convert to scrolled coords
5944 int left
, top
, right
, bottom
;
5945 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
5946 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
5949 m_gridWin
->GetClientSize( &cw
, &ch
);
5951 rect
.SetLeft( wxMax(0, left
) );
5952 rect
.SetTop( wxMax(0, top
) );
5953 rect
.SetRight( wxMin(cw
, right
) );
5954 rect
.SetBottom( wxMin(ch
, bottom
) );
5962 // ------ Grid event classes
5965 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxEvent
)
5967 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
5968 int row
, int col
, int x
, int y
,
5969 bool control
, bool shift
, bool alt
, bool meta
)
5970 : wxNotifyEvent( type
, id
)
5976 m_control
= control
;
5981 SetEventObject(obj
);
5985 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxEvent
)
5987 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
5988 int rowOrCol
, int x
, int y
,
5989 bool control
, bool shift
, bool alt
, bool meta
)
5990 : wxNotifyEvent( type
, id
)
5992 m_rowOrCol
= rowOrCol
;
5995 m_control
= control
;
6000 SetEventObject(obj
);
6004 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxEvent
)
6006 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
6007 const wxGridCellCoords
& topLeft
,
6008 const wxGridCellCoords
& bottomRight
,
6009 bool control
, bool shift
, bool alt
, bool meta
)
6010 : wxNotifyEvent( type
, id
)
6012 m_topLeft
= topLeft
;
6013 m_bottomRight
= bottomRight
;
6014 m_control
= control
;
6019 SetEventObject(obj
);
6023 #endif // ifndef wxUSE_NEW_GRID