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 void wxGridCellEditor::StartingKey(wxKeyEvent
& event
)
323 wxGridCellTextEditor::wxGridCellTextEditor()
327 void wxGridCellTextEditor::Create(wxWindow
* parent
,
329 wxEvtHandler
* evtHandler
)
331 m_control
= new wxTextCtrl(parent
, -1, "",
332 wxDefaultPosition
, wxDefaultSize
333 #if defined(__WXMSW__)
334 , wxTE_MULTILINE
| wxTE_NO_VSCROLL
// necessary ???
339 m_control
->PushEventHandler(evtHandler
);
343 void wxGridCellTextEditor::BeginEdit(int row
, int col
, wxGrid
* grid
,
344 wxGridCellAttr
* attr
)
346 wxASSERT_MSG(m_control
,
347 wxT("The wxGridCellEditor must be Created first!"));
349 m_startValue
= grid
->GetTable()->GetValue(row
, col
);
350 ((wxTextCtrl
*)m_control
)->SetValue(m_startValue
);
351 ((wxTextCtrl
*)m_control
)->SetInsertionPointEnd();
352 ((wxTextCtrl
*)m_control
)->SetFocus();
354 // ??? Should we use attr and try to set colours and font?
359 bool wxGridCellTextEditor::EndEdit(int row
, int col
, bool saveValue
,
360 wxGrid
* grid
, wxGridCellAttr
* attr
)
362 wxASSERT_MSG(m_control
,
363 wxT("The wxGridCellEditor must be Created first!"));
365 bool changed
= FALSE
;
366 wxString value
= ((wxTextCtrl
*)m_control
)->GetValue();
367 if (value
!= m_startValue
)
371 grid
->GetTable()->SetValue(row
, col
, value
);
374 ((wxTextCtrl
*)m_control
)->SetValue(m_startValue
);
380 void wxGridCellTextEditor::Reset()
382 wxASSERT_MSG(m_control
,
383 wxT("The wxGridCellEditor must be Created first!"));
385 ((wxTextCtrl
*)m_control
)->SetValue(m_startValue
);
386 ((wxTextCtrl
*)m_control
)->SetInsertionPointEnd();
390 void wxGridCellTextEditor::StartingKey(wxKeyEvent
& event
)
392 wxASSERT_MSG(m_control
,
393 wxT("The wxGridCellEditor must be Created first!"));
395 int code
= event
.KeyCode();
396 if (code
>= 32 && code
< 255) {
397 wxString
st((char)code
);
398 if (! event
.ShiftDown())
400 ((wxTextCtrl
*)m_control
)->AppendText(st
);
405 void wxGridCellTextEditor::HandleReturn(wxKeyEvent
& event
)
407 #if defined(__WXMOTIF__) || defined(__WXGTK__)
408 // wxMotif needs a little extra help...
409 int pos
= ((wxTextCtrl
*)m_control
)->GetInsertionPoint();
410 wxString
s( ((wxTextCtrl
*)m_control
)->GetValue() );
411 s
= s
.Left(pos
) + "\n" + s
.Mid(pos
);
412 ((wxTextCtrl
*)m_control
)->SetValue(s
);
413 ((wxTextCtrl
*)m_control
)->SetInsertionPoint( pos
);
415 // the other ports can handle a Return key press
422 void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent
& event
)
424 switch ( event
.KeyCode() )
428 m_grid
->EnableCellEditControl(FALSE
);
440 // // send the event to the parent grid, skipping the
441 // // event if nothing happens
443 // event.Skip( m_grid->ProcessEvent( event ) );
448 if (!m_grid
->ProcessEvent(event
))
449 m_editor
->HandleReturn(event
);
458 // ----------------------------------------------------------------------------
459 // wxGridCellRenderer
460 // ----------------------------------------------------------------------------
462 void wxGridCellRenderer::Draw(wxGrid
& grid
,
463 wxGridCellAttr
& attr
,
469 dc
.SetBackgroundMode( wxSOLID
);
473 dc
.SetBrush( wxBrush(grid
.GetSelectionBackground(), wxSOLID
) );
477 dc
.SetBrush( wxBrush(attr
.GetBackgroundColour(), wxSOLID
) );
480 dc
.SetPen( *wxTRANSPARENT_PEN
);
481 dc
.DrawRectangle(rect
);
484 void wxGridCellStringRenderer::Draw(wxGrid
& grid
,
485 wxGridCellAttr
& attr
,
487 const wxRect
& rectCell
,
491 wxGridCellRenderer::Draw(grid
, attr
, dc
, rectCell
, row
, col
, isSelected
);
493 // now we only have to draw the text
494 dc
.SetBackgroundMode( wxTRANSPARENT
);
498 dc
.SetTextBackground( grid
.GetSelectionBackground() );
499 dc
.SetTextForeground( grid
.GetSelectionForeground() );
503 dc
.SetTextBackground( attr
.GetBackgroundColour() );
504 dc
.SetTextForeground( attr
.GetTextColour() );
506 dc
.SetFont( attr
.GetFont() );
509 attr
.GetAlignment(&hAlign
, &vAlign
);
511 wxRect rect
= rectCell
;
517 grid
.DrawTextRectangle(dc
, grid
.GetCellValue(row
, col
),
518 rect
, hAlign
, vAlign
);
521 // ----------------------------------------------------------------------------
523 // ----------------------------------------------------------------------------
525 const wxColour
& wxGridCellAttr::GetTextColour() const
529 else if (m_defGridAttr
!= this)
530 return m_defGridAttr
->GetTextColour();
532 wxFAIL_MSG(wxT("Missing default cell attribute"));
538 const wxColour
& wxGridCellAttr::GetBackgroundColour() const
540 if (HasBackgroundColour())
542 else if (m_defGridAttr
!= this)
543 return m_defGridAttr
->GetBackgroundColour();
545 wxFAIL_MSG(wxT("Missing default cell attribute"));
551 const wxFont
& wxGridCellAttr::GetFont() const
555 else if (m_defGridAttr
!= this)
556 return m_defGridAttr
->GetFont();
558 wxFAIL_MSG(wxT("Missing default cell attribute"));
564 void wxGridCellAttr::GetAlignment(int *hAlign
, int *vAlign
) const
566 if (HasAlignment()) {
567 if ( hAlign
) *hAlign
= m_hAlign
;
568 if ( vAlign
) *vAlign
= m_vAlign
;
570 else if (m_defGridAttr
!= this)
571 m_defGridAttr
->GetAlignment(hAlign
, vAlign
);
573 wxFAIL_MSG(wxT("Missing default cell attribute"));
578 wxGridCellRenderer
* wxGridCellAttr::GetRenderer() const
582 else if (m_defGridAttr
!= this)
583 return m_defGridAttr
->GetRenderer();
585 wxFAIL_MSG(wxT("Missing default cell attribute"));
590 wxGridCellEditor
* wxGridCellAttr::GetEditor() const
594 else if (m_defGridAttr
!= this)
595 return m_defGridAttr
->GetEditor();
597 wxFAIL_MSG(wxT("Missing default cell attribute"));
602 // ----------------------------------------------------------------------------
603 // wxGridCellAttrData
604 // ----------------------------------------------------------------------------
606 void wxGridCellAttrData::SetAttr(wxGridCellAttr
*attr
, int row
, int col
)
608 int n
= FindIndex(row
, col
);
609 if ( n
== wxNOT_FOUND
)
612 m_attrs
.Add(new wxGridCellWithAttr(row
, col
, attr
));
618 // change the attribute
619 m_attrs
[(size_t)n
].attr
= attr
;
623 // remove this attribute
624 m_attrs
.RemoveAt((size_t)n
);
629 wxGridCellAttr
*wxGridCellAttrData::GetAttr(int row
, int col
) const
631 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
633 int n
= FindIndex(row
, col
);
634 if ( n
!= wxNOT_FOUND
)
636 attr
= m_attrs
[(size_t)n
].attr
;
643 int wxGridCellAttrData::FindIndex(int row
, int col
) const
645 size_t count
= m_attrs
.GetCount();
646 for ( size_t n
= 0; n
< count
; n
++ )
648 const wxGridCellCoords
& coords
= m_attrs
[n
].coords
;
649 if ( (coords
.GetRow() == row
) && (coords
.GetCol() == col
) )
658 // ----------------------------------------------------------------------------
659 // wxGridRowOrColAttrData
660 // ----------------------------------------------------------------------------
662 wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
664 size_t count
= m_attrs
.Count();
665 for ( size_t n
= 0; n
< count
; n
++ )
667 m_attrs
[n
]->DecRef();
671 wxGridCellAttr
*wxGridRowOrColAttrData::GetAttr(int rowOrCol
) const
673 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
675 int n
= m_rowsOrCols
.Index(rowOrCol
);
676 if ( n
!= wxNOT_FOUND
)
678 attr
= m_attrs
[(size_t)n
];
685 void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr
*attr
, int rowOrCol
)
687 int n
= m_rowsOrCols
.Index(rowOrCol
);
688 if ( n
== wxNOT_FOUND
)
691 m_rowsOrCols
.Add(rowOrCol
);
698 // change the attribute
699 m_attrs
[(size_t)n
] = attr
;
703 // remove this attribute
704 m_attrs
[(size_t)n
]->DecRef();
705 m_rowsOrCols
.RemoveAt((size_t)n
);
706 m_attrs
.RemoveAt((size_t)n
);
711 // ----------------------------------------------------------------------------
712 // wxGridCellAttrProvider
713 // ----------------------------------------------------------------------------
715 wxGridCellAttrProvider::wxGridCellAttrProvider()
717 m_data
= (wxGridCellAttrProviderData
*)NULL
;
720 wxGridCellAttrProvider::~wxGridCellAttrProvider()
725 void wxGridCellAttrProvider::InitData()
727 m_data
= new wxGridCellAttrProviderData
;
730 wxGridCellAttr
*wxGridCellAttrProvider::GetAttr(int row
, int col
) const
732 wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
;
735 // first look for the attribute of this specific cell
736 attr
= m_data
->m_cellAttrs
.GetAttr(row
, col
);
740 // then look for the col attr (col attributes are more common than
741 // the row ones, hence they have priority)
742 attr
= m_data
->m_colAttrs
.GetAttr(col
);
747 // finally try the row attributes
748 attr
= m_data
->m_rowAttrs
.GetAttr(row
);
755 void wxGridCellAttrProvider::SetAttr(wxGridCellAttr
*attr
,
761 m_data
->m_cellAttrs
.SetAttr(attr
, row
, col
);
764 void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr
*attr
, int row
)
769 m_data
->m_rowAttrs
.SetAttr(attr
, row
);
772 void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr
*attr
, int col
)
777 m_data
->m_colAttrs
.SetAttr(attr
, col
);
780 // ----------------------------------------------------------------------------
782 // ----------------------------------------------------------------------------
784 //////////////////////////////////////////////////////////////////////
786 // Abstract base class for grid data (the model)
788 IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase
, wxObject
)
791 wxGridTableBase::wxGridTableBase()
793 m_view
= (wxGrid
*) NULL
;
794 m_attrProvider
= (wxGridCellAttrProvider
*) NULL
;
797 wxGridTableBase::~wxGridTableBase()
799 delete m_attrProvider
;
802 void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider
*attrProvider
)
804 delete m_attrProvider
;
805 m_attrProvider
= attrProvider
;
808 wxGridCellAttr
*wxGridTableBase::GetAttr(int row
, int col
)
810 if ( m_attrProvider
)
811 return m_attrProvider
->GetAttr(row
, col
);
813 return (wxGridCellAttr
*)NULL
;
816 void wxGridTableBase::SetAttr(wxGridCellAttr
* attr
, int row
, int col
)
818 if ( m_attrProvider
)
820 m_attrProvider
->SetAttr(attr
, row
, col
);
824 // as we take ownership of the pointer and don't store it, we must
830 void wxGridTableBase::SetRowAttr(wxGridCellAttr
*attr
, int row
)
832 if ( m_attrProvider
)
834 m_attrProvider
->SetRowAttr(attr
, row
);
838 // as we take ownership of the pointer and don't store it, we must
844 void wxGridTableBase::SetColAttr(wxGridCellAttr
*attr
, int col
)
846 if ( m_attrProvider
)
848 m_attrProvider
->SetColAttr(attr
, col
);
852 // as we take ownership of the pointer and don't store it, we must
858 bool wxGridTableBase::InsertRows( size_t pos
, size_t numRows
)
860 wxFAIL_MSG( wxT("Called grid table class function InsertRows\n"
861 "but your derived table class does not override this function") );
866 bool wxGridTableBase::AppendRows( size_t numRows
)
868 wxFAIL_MSG( wxT("Called grid table class function AppendRows\n"
869 "but your derived table class does not override this function"));
874 bool wxGridTableBase::DeleteRows( size_t pos
, size_t numRows
)
876 wxFAIL_MSG( wxT("Called grid table class function DeleteRows\n"
877 "but your derived table class does not override this function"));
882 bool wxGridTableBase::InsertCols( size_t pos
, size_t numCols
)
884 wxFAIL_MSG( wxT("Called grid table class function InsertCols\n"
885 "but your derived table class does not override this function"));
890 bool wxGridTableBase::AppendCols( size_t numCols
)
892 wxFAIL_MSG(wxT("Called grid table class function AppendCols\n"
893 "but your derived table class does not override this function"));
898 bool wxGridTableBase::DeleteCols( size_t pos
, size_t numCols
)
900 wxFAIL_MSG( wxT("Called grid table class function DeleteCols\n"
901 "but your derived table class does not override this function"));
907 wxString
wxGridTableBase::GetRowLabelValue( int row
)
914 wxString
wxGridTableBase::GetColLabelValue( int col
)
916 // default col labels are:
917 // cols 0 to 25 : A-Z
918 // cols 26 to 675 : AA-ZZ
925 s
+= (_T('A') + (wxChar
)( col%26
));
927 if ( col
< 0 ) break;
930 // reverse the string...
932 for ( i
= 0; i
< n
; i
++ )
942 //////////////////////////////////////////////////////////////////////
944 // Message class for the grid table to send requests and notifications
948 wxGridTableMessage::wxGridTableMessage()
950 m_table
= (wxGridTableBase
*) NULL
;
956 wxGridTableMessage::wxGridTableMessage( wxGridTableBase
*table
, int id
,
957 int commandInt1
, int commandInt2
)
961 m_comInt1
= commandInt1
;
962 m_comInt2
= commandInt2
;
967 //////////////////////////////////////////////////////////////////////
969 // A basic grid table for string data. An object of this class will
970 // created by wxGrid if you don't specify an alternative table class.
973 WX_DEFINE_OBJARRAY(wxGridStringArray
)
975 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable
, wxGridTableBase
)
977 wxGridStringTable::wxGridStringTable()
982 wxGridStringTable::wxGridStringTable( int numRows
, int numCols
)
987 m_data
.Alloc( numRows
);
991 for ( col
= 0; col
< numCols
; col
++ )
993 sa
.Add( wxEmptyString
);
996 for ( row
= 0; row
< numRows
; row
++ )
1002 wxGridStringTable::~wxGridStringTable()
1006 long wxGridStringTable::GetNumberRows()
1008 return m_data
.GetCount();
1011 long wxGridStringTable::GetNumberCols()
1013 if ( m_data
.GetCount() > 0 )
1014 return m_data
[0].GetCount();
1019 wxString
wxGridStringTable::GetValue( int row
, int col
)
1021 // TODO: bounds checking
1023 return m_data
[row
][col
];
1026 void wxGridStringTable::SetValue( int row
, int col
, const wxString
& s
)
1028 // TODO: bounds checking
1030 m_data
[row
][col
] = s
;
1033 bool wxGridStringTable::IsEmptyCell( int row
, int col
)
1035 // TODO: bounds checking
1037 return (m_data
[row
][col
] == wxEmptyString
);
1041 void wxGridStringTable::Clear()
1044 int numRows
, numCols
;
1046 numRows
= m_data
.GetCount();
1049 numCols
= m_data
[0].GetCount();
1051 for ( row
= 0; row
< numRows
; row
++ )
1053 for ( col
= 0; col
< numCols
; col
++ )
1055 m_data
[row
][col
] = wxEmptyString
;
1062 bool wxGridStringTable::InsertRows( size_t pos
, size_t numRows
)
1066 size_t curNumRows
= m_data
.GetCount();
1067 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1069 if ( pos
>= curNumRows
)
1071 return AppendRows( numRows
);
1075 sa
.Alloc( curNumCols
);
1076 for ( col
= 0; col
< curNumCols
; col
++ )
1078 sa
.Add( wxEmptyString
);
1081 for ( row
= pos
; row
< pos
+ numRows
; row
++ )
1083 m_data
.Insert( sa
, row
);
1088 wxGridTableMessage
msg( this,
1089 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
1093 GetView()->ProcessTableMessage( msg
);
1099 bool wxGridStringTable::AppendRows( size_t numRows
)
1103 size_t curNumRows
= m_data
.GetCount();
1104 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1107 if ( curNumCols
> 0 )
1109 sa
.Alloc( curNumCols
);
1110 for ( col
= 0; col
< curNumCols
; col
++ )
1112 sa
.Add( wxEmptyString
);
1116 for ( row
= 0; row
< numRows
; row
++ )
1123 wxGridTableMessage
msg( this,
1124 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
1127 GetView()->ProcessTableMessage( msg
);
1133 bool wxGridStringTable::DeleteRows( size_t pos
, size_t numRows
)
1137 size_t curNumRows
= m_data
.GetCount();
1139 if ( pos
>= curNumRows
)
1142 errmsg
.Printf("Called wxGridStringTable::DeleteRows(pos=%d, N=%d)\n"
1143 "Pos value is invalid for present table with %d rows",
1144 pos
, numRows
, curNumRows
);
1145 wxFAIL_MSG( wxT(errmsg
) );
1149 if ( numRows
> curNumRows
- pos
)
1151 numRows
= curNumRows
- pos
;
1154 if ( numRows
>= curNumRows
)
1156 m_data
.Empty(); // don't release memory just yet
1160 for ( n
= 0; n
< numRows
; n
++ )
1162 m_data
.Remove( pos
);
1168 wxGridTableMessage
msg( this,
1169 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
1173 GetView()->ProcessTableMessage( msg
);
1179 bool wxGridStringTable::InsertCols( size_t pos
, size_t numCols
)
1183 size_t curNumRows
= m_data
.GetCount();
1184 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1186 if ( pos
>= curNumCols
)
1188 return AppendCols( numCols
);
1191 for ( row
= 0; row
< curNumRows
; row
++ )
1193 for ( col
= pos
; col
< pos
+ numCols
; col
++ )
1195 m_data
[row
].Insert( wxEmptyString
, col
);
1201 wxGridTableMessage
msg( this,
1202 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
1206 GetView()->ProcessTableMessage( msg
);
1212 bool wxGridStringTable::AppendCols( size_t numCols
)
1216 size_t curNumRows
= m_data
.GetCount();
1219 // TODO: something better than this ?
1221 wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\n"
1222 "Call AppendRows() first") );
1226 for ( row
= 0; row
< curNumRows
; row
++ )
1228 for ( n
= 0; n
< numCols
; n
++ )
1230 m_data
[row
].Add( wxEmptyString
);
1236 wxGridTableMessage
msg( this,
1237 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
1240 GetView()->ProcessTableMessage( msg
);
1246 bool wxGridStringTable::DeleteCols( size_t pos
, size_t numCols
)
1250 size_t curNumRows
= m_data
.GetCount();
1251 size_t curNumCols
= ( curNumRows
> 0 ? m_data
[0].GetCount() : 0 );
1253 if ( pos
>= curNumCols
)
1256 errmsg
.Printf( "Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\n"
1257 "Pos value is invalid for present table with %d cols",
1258 pos
, numCols
, curNumCols
);
1259 wxFAIL_MSG( wxT( errmsg
) );
1263 if ( numCols
> curNumCols
- pos
)
1265 numCols
= curNumCols
- pos
;
1268 for ( row
= 0; row
< curNumRows
; row
++ )
1270 if ( numCols
>= curNumCols
)
1272 m_data
[row
].Clear();
1276 for ( n
= 0; n
< numCols
; n
++ )
1278 m_data
[row
].Remove( pos
);
1285 wxGridTableMessage
msg( this,
1286 wxGRIDTABLE_NOTIFY_COLS_DELETED
,
1290 GetView()->ProcessTableMessage( msg
);
1296 wxString
wxGridStringTable::GetRowLabelValue( int row
)
1298 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
1300 // using default label
1302 return wxGridTableBase::GetRowLabelValue( row
);
1306 return m_rowLabels
[ row
];
1310 wxString
wxGridStringTable::GetColLabelValue( int col
)
1312 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
1314 // using default label
1316 return wxGridTableBase::GetColLabelValue( col
);
1320 return m_colLabels
[ col
];
1324 void wxGridStringTable::SetRowLabelValue( int row
, const wxString
& value
)
1326 if ( row
> (int)(m_rowLabels
.GetCount()) - 1 )
1328 int n
= m_rowLabels
.GetCount();
1330 for ( i
= n
; i
<= row
; i
++ )
1332 m_rowLabels
.Add( wxGridTableBase::GetRowLabelValue(i
) );
1336 m_rowLabels
[row
] = value
;
1339 void wxGridStringTable::SetColLabelValue( int col
, const wxString
& value
)
1341 if ( col
> (int)(m_colLabels
.GetCount()) - 1 )
1343 int n
= m_colLabels
.GetCount();
1345 for ( i
= n
; i
<= col
; i
++ )
1347 m_colLabels
.Add( wxGridTableBase::GetColLabelValue(i
) );
1351 m_colLabels
[col
] = value
;
1356 //////////////////////////////////////////////////////////////////////
1358 IMPLEMENT_DYNAMIC_CLASS( wxGridTextCtrl
, wxTextCtrl
)
1360 BEGIN_EVENT_TABLE( wxGridTextCtrl
, wxTextCtrl
)
1361 EVT_KEY_DOWN( wxGridTextCtrl::OnKeyDown
)
1365 wxGridTextCtrl::wxGridTextCtrl( wxWindow
*par
,
1369 const wxString
& value
,
1373 : wxTextCtrl( par
, id
, value
, pos
, size
, style
)
1376 m_isCellControl
= isCellControl
;
1380 void wxGridTextCtrl::OnKeyDown( wxKeyEvent
& event
)
1382 switch ( event
.KeyCode() )
1386 m_grid
->SetEditControlValue( startValue
);
1387 SetInsertionPointEnd();
1391 m_grid
->EnableCellEditControl( FALSE
);
1400 if ( m_isCellControl
)
1402 // send the event to the parent grid, skipping the
1403 // event if nothing happens
1405 event
.Skip( m_grid
->ProcessEvent( event
) );
1409 // default text control response within the top edit
1417 if ( m_isCellControl
)
1419 if ( !m_grid
->ProcessEvent( event
) )
1421 #if defined(__WXMOTIF__) || defined(__WXGTK__)
1422 // wxMotif needs a little extra help...
1424 int pos
= GetInsertionPoint();
1425 wxString
s( GetValue() );
1426 s
= s
.Left(pos
) + "\n" + s
.Mid(pos
);
1428 SetInsertionPoint( pos
);
1430 // the other ports can handle a Return key press
1439 if ( m_isCellControl
)
1441 // send the event to the parent grid, skipping the
1442 // event if nothing happens
1444 event
.Skip( m_grid
->ProcessEvent( event
) );
1448 // default text control response within the top edit
1460 void wxGridTextCtrl::SetStartValue( const wxString
& s
)
1463 wxTextCtrl::SetValue(s
);
1468 //////////////////////////////////////////////////////////////////////
1470 IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow
, wxWindow
)
1472 BEGIN_EVENT_TABLE( wxGridRowLabelWindow
, wxWindow
)
1473 EVT_PAINT( wxGridRowLabelWindow::OnPaint
)
1474 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent
)
1475 EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown
)
1478 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid
*parent
,
1480 const wxPoint
&pos
, const wxSize
&size
)
1481 : wxWindow( parent
, id
, pos
, size
)
1486 void wxGridRowLabelWindow::OnPaint( wxPaintEvent
&event
)
1490 // NO - don't do this because it will set both the x and y origin
1491 // coords to match the parent scrolled window and we just want to
1492 // set the y coord - MB
1494 // m_owner->PrepareDC( dc );
1497 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
1498 dc
.SetDeviceOrigin( 0, -y
);
1500 m_owner
->CalcRowLabelsExposed( GetUpdateRegion() );
1501 m_owner
->DrawRowLabels( dc
);
1505 void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1507 m_owner
->ProcessRowLabelMouseEvent( event
);
1511 // This seems to be required for wxMotif otherwise the mouse
1512 // cursor must be in the cell edit control to get key events
1514 void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent
& event
)
1516 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1521 //////////////////////////////////////////////////////////////////////
1523 IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow
, wxWindow
)
1525 BEGIN_EVENT_TABLE( wxGridColLabelWindow
, wxWindow
)
1526 EVT_PAINT( wxGridColLabelWindow::OnPaint
)
1527 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent
)
1528 EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown
)
1531 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid
*parent
,
1533 const wxPoint
&pos
, const wxSize
&size
)
1534 : wxWindow( parent
, id
, pos
, size
)
1539 void wxGridColLabelWindow::OnPaint( wxPaintEvent
&event
)
1543 // NO - don't do this because it will set both the x and y origin
1544 // coords to match the parent scrolled window and we just want to
1545 // set the x coord - MB
1547 // m_owner->PrepareDC( dc );
1550 m_owner
->CalcUnscrolledPosition( 0, 0, &x
, &y
);
1551 dc
.SetDeviceOrigin( -x
, 0 );
1553 m_owner
->CalcColLabelsExposed( GetUpdateRegion() );
1554 m_owner
->DrawColLabels( dc
);
1558 void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1560 m_owner
->ProcessColLabelMouseEvent( event
);
1564 // This seems to be required for wxMotif otherwise the mouse
1565 // cursor must be in the cell edit control to get key events
1567 void wxGridColLabelWindow::OnKeyDown( wxKeyEvent
& event
)
1569 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1574 //////////////////////////////////////////////////////////////////////
1576 IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow
, wxWindow
)
1578 BEGIN_EVENT_TABLE( wxGridCornerLabelWindow
, wxWindow
)
1579 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent
)
1580 EVT_PAINT( wxGridCornerLabelWindow::OnPaint
)
1581 EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown
)
1584 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid
*parent
,
1586 const wxPoint
&pos
, const wxSize
&size
)
1587 : wxWindow( parent
, id
, pos
, size
)
1592 void wxGridCornerLabelWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1596 int client_height
= 0;
1597 int client_width
= 0;
1598 GetClientSize( &client_width
, &client_height
);
1600 dc
.SetPen( *wxBLACK_PEN
);
1601 dc
.DrawLine( client_width
-1, client_height
-1, client_width
-1, 0 );
1602 dc
.DrawLine( client_width
-1, client_height
-1, 0, client_height
-1 );
1604 dc
.SetPen( *wxWHITE_PEN
);
1605 dc
.DrawLine( 0, 0, client_width
, 0 );
1606 dc
.DrawLine( 0, 0, 0, client_height
);
1610 void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent
& event
)
1612 m_owner
->ProcessCornerLabelMouseEvent( event
);
1616 // This seems to be required for wxMotif otherwise the mouse
1617 // cursor must be in the cell edit control to get key events
1619 void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent
& event
)
1621 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1626 //////////////////////////////////////////////////////////////////////
1628 IMPLEMENT_DYNAMIC_CLASS( wxGridWindow
, wxPanel
)
1630 BEGIN_EVENT_TABLE( wxGridWindow
, wxPanel
)
1631 EVT_PAINT( wxGridWindow::OnPaint
)
1632 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent
)
1633 EVT_KEY_DOWN( wxGridWindow::OnKeyDown
)
1634 EVT_ERASE_BACKGROUND( wxGridWindow::OnEraseBackground
)
1637 wxGridWindow::wxGridWindow( wxGrid
*parent
,
1638 wxGridRowLabelWindow
*rowLblWin
,
1639 wxGridColLabelWindow
*colLblWin
,
1640 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
)
1641 : wxPanel( parent
, id
, pos
, size
, 0, "grid window" )
1644 m_rowLabelWin
= rowLblWin
;
1645 m_colLabelWin
= colLblWin
;
1646 SetBackgroundColour( "WHITE" );
1650 wxGridWindow::~wxGridWindow()
1655 void wxGridWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1657 wxPaintDC
dc( this );
1658 m_owner
->PrepareDC( dc
);
1659 wxRegion reg
= GetUpdateRegion();
1660 m_owner
->CalcCellsExposed( reg
);
1661 m_owner
->DrawGridCellArea( dc
);
1662 #if WXGRID_DRAW_LINES
1663 m_owner
->DrawAllGridLines( dc
, reg
);
1668 void wxGridWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
1670 wxPanel::ScrollWindow( dx
, dy
, rect
);
1671 m_rowLabelWin
->ScrollWindow( 0, dy
, rect
);
1672 m_colLabelWin
->ScrollWindow( dx
, 0, rect
);
1676 void wxGridWindow::OnMouseEvent( wxMouseEvent
& event
)
1678 m_owner
->ProcessGridCellMouseEvent( event
);
1682 // This seems to be required for wxMotif otherwise the mouse
1683 // cursor must be in the cell edit control to get key events
1685 void wxGridWindow::OnKeyDown( wxKeyEvent
& event
)
1687 if ( !m_owner
->ProcessEvent( event
) ) event
.Skip();
1690 void wxGridWindow::OnEraseBackground(wxEraseEvent
&)
1696 //////////////////////////////////////////////////////////////////////
1698 #define ID_EDIT_TIMER 1001
1700 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
1702 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
1703 EVT_PAINT( wxGrid::OnPaint
)
1704 EVT_SIZE( wxGrid::OnSize
)
1705 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
1706 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
1707 EVT_TIMER( ID_EDIT_TIMER
, wxGrid::OnEditTimer
)
1710 wxGrid::wxGrid( wxWindow
*parent
,
1715 const wxString
& name
)
1716 : wxScrolledWindow( parent
, id
, pos
, size
, style
, name
)
1725 m_defaultCellAttr
->SafeDecRef();
1727 #ifdef DEBUG_ATTR_CACHE
1728 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
1729 wxPrintf(_T("wxGrid attribute cache statistics: "
1730 "total: %u, hits: %u (%u%%)\n"),
1731 total
, gs_nAttrCacheHits
,
1732 total
? (gs_nAttrCacheHits
*100) / total
: 0);
1742 // ----- internal init and update functions
1745 void wxGrid::Create()
1747 m_created
= FALSE
; // set to TRUE by CreateGrid
1748 m_displayed
= FALSE
; // set to TRUE by OnPaint
1750 m_table
= (wxGridTableBase
*) NULL
;
1753 m_cellEditCtrlEnabled
= FALSE
;
1755 m_defaultCellAttr
= new wxGridCellAttr
;
1756 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
1757 // RD: Should we fill the default attrs now or is waiting until Init() okay?
1762 m_currentCellCoords
= wxGridNoCellCoords
;
1764 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
1765 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
1767 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
1772 m_rowLabelWin
= new wxGridRowLabelWindow( this,
1777 m_colLabelWin
= new wxGridColLabelWindow( this,
1782 m_gridWin
= new wxGridWindow( this,
1789 SetTargetWindow( m_gridWin
);
1793 bool wxGrid::CreateGrid( int numRows
, int numCols
)
1797 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
1802 m_numRows
= numRows
;
1803 m_numCols
= numCols
;
1805 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
1806 m_table
->SetView( this );
1815 bool wxGrid::SetTable( wxGridTableBase
*table
, bool takeOwnership
)
1819 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
1824 m_numRows
= table
->GetNumberRows();
1825 m_numCols
= table
->GetNumberCols();
1828 m_table
->SetView( this );
1843 if ( m_numRows
<= 0 )
1844 m_numRows
= WXGRID_DEFAULT_NUMBER_ROWS
;
1846 if ( m_numCols
<= 0 )
1847 m_numCols
= WXGRID_DEFAULT_NUMBER_COLS
;
1849 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
1850 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
1852 if ( m_rowLabelWin
)
1854 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
1858 m_labelBackgroundColour
= wxColour( _T("WHITE") );
1861 m_labelTextColour
= wxColour( _T("BLACK") );
1864 m_attrCache
.row
= -1;
1866 // TODO: something better than this ?
1868 m_labelFont
= this->GetFont();
1869 m_labelFont
.SetWeight( m_labelFont
.GetWeight() + 2 );
1871 m_rowLabelHorizAlign
= wxLEFT
;
1872 m_rowLabelVertAlign
= wxCENTRE
;
1874 m_colLabelHorizAlign
= wxCENTRE
;
1875 m_colLabelVertAlign
= wxTOP
;
1877 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
1878 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
1880 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
1881 m_defaultRowHeight
+= 8;
1883 m_defaultRowHeight
+= 4;
1886 m_rowHeights
.Alloc( m_numRows
);
1887 m_rowBottoms
.Alloc( m_numRows
);
1889 for ( i
= 0; i
< m_numRows
; i
++ )
1891 m_rowHeights
.Add( m_defaultRowHeight
);
1892 rowBottom
+= m_defaultRowHeight
;
1893 m_rowBottoms
.Add( rowBottom
);
1896 m_colWidths
.Alloc( m_numCols
);
1897 m_colRights
.Alloc( m_numCols
);
1899 for ( i
= 0; i
< m_numCols
; i
++ )
1901 m_colWidths
.Add( m_defaultColWidth
);
1902 colRight
+= m_defaultColWidth
;
1903 m_colRights
.Add( colRight
);
1906 // Set default cell attributes
1907 m_defaultCellAttr
->SetFont(GetFont());
1908 m_defaultCellAttr
->SetAlignment(wxLEFT
, wxTOP
);
1909 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
1910 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
1911 m_defaultCellAttr
->SetTextColour(
1912 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT
));
1913 m_defaultCellAttr
->SetBackgroundColour(
1914 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
1917 m_gridLineColour
= wxColour( 128, 128, 255 );
1918 m_gridLinesEnabled
= TRUE
;
1920 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
1921 m_winCapture
= (wxWindow
*)NULL
;
1923 m_dragRowOrCol
= -1;
1924 m_isDragging
= FALSE
;
1925 m_startDragPos
= wxDefaultPosition
;
1927 m_editTimer
= new wxTimer( this, ID_EDIT_TIMER
);
1928 m_waitForSlowClick
= FALSE
;
1930 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
1931 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
1933 m_currentCellCoords
= wxGridNoCellCoords
;
1935 m_selectedTopLeft
= wxGridNoCellCoords
;
1936 m_selectedBottomRight
= wxGridNoCellCoords
;
1937 m_selectionBackground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
);
1938 m_selectionForeground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1940 m_editable
= TRUE
; // default for whole grid
1942 m_inOnKeyDown
= FALSE
;
1948 void wxGrid::CalcDimensions()
1951 GetClientSize( &cw
, &ch
);
1953 if ( m_numRows
> 0 && m_numCols
> 0 )
1955 int right
= m_colRights
[ m_numCols
-1 ] + 50;
1956 int bottom
= m_rowBottoms
[ m_numRows
-1 ] + 50;
1958 // TODO: restore the scroll position that we had before sizing
1961 GetViewStart( &x
, &y
);
1962 SetScrollbars( GRID_SCROLL_LINE
, GRID_SCROLL_LINE
,
1963 right
/GRID_SCROLL_LINE
, bottom
/GRID_SCROLL_LINE
,
1969 void wxGrid::CalcWindowSizes()
1972 GetClientSize( &cw
, &ch
);
1974 if ( m_cornerLabelWin
->IsShown() )
1975 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
1977 if ( m_colLabelWin
->IsShown() )
1978 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
1980 if ( m_rowLabelWin
->IsShown() )
1981 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
1983 if ( m_gridWin
->IsShown() )
1984 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
1988 // this is called when the grid table sends a message to say that it
1989 // has been redimensioned
1991 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
1995 switch ( msg
.GetId() )
1997 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
1999 size_t pos
= msg
.GetCommandInt();
2000 int numRows
= msg
.GetCommandInt2();
2001 for ( i
= 0; i
< numRows
; i
++ )
2003 m_rowHeights
.Insert( m_defaultRowHeight
, pos
);
2004 m_rowBottoms
.Insert( 0, pos
);
2006 m_numRows
+= numRows
;
2009 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
2011 for ( i
= pos
; i
< m_numRows
; i
++ )
2013 bottom
+= m_rowHeights
[i
];
2014 m_rowBottoms
[i
] = bottom
;
2020 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
2022 int numRows
= msg
.GetCommandInt();
2023 for ( i
= 0; i
< numRows
; i
++ )
2025 m_rowHeights
.Add( m_defaultRowHeight
);
2026 m_rowBottoms
.Add( 0 );
2029 int oldNumRows
= m_numRows
;
2030 m_numRows
+= numRows
;
2033 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
2035 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
2037 bottom
+= m_rowHeights
[i
];
2038 m_rowBottoms
[i
] = bottom
;
2044 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
2046 size_t pos
= msg
.GetCommandInt();
2047 int numRows
= msg
.GetCommandInt2();
2048 for ( i
= 0; i
< numRows
; i
++ )
2050 m_rowHeights
.Remove( pos
);
2051 m_rowBottoms
.Remove( pos
);
2053 m_numRows
-= numRows
;
2058 m_colWidths
.Clear();
2059 m_colRights
.Clear();
2060 m_currentCellCoords
= wxGridNoCellCoords
;
2064 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
2065 m_currentCellCoords
.Set( 0, 0 );
2068 for ( i
= 0; i
< m_numRows
; i
++ )
2070 h
+= m_rowHeights
[i
];
2071 m_rowBottoms
[i
] = h
;
2079 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
2081 size_t pos
= msg
.GetCommandInt();
2082 int numCols
= msg
.GetCommandInt2();
2083 for ( i
= 0; i
< numCols
; i
++ )
2085 m_colWidths
.Insert( m_defaultColWidth
, pos
);
2086 m_colRights
.Insert( 0, pos
);
2088 m_numCols
+= numCols
;
2091 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
2093 for ( i
= pos
; i
< m_numCols
; i
++ )
2095 right
+= m_colWidths
[i
];
2096 m_colRights
[i
] = right
;
2102 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
2104 int numCols
= msg
.GetCommandInt();
2105 for ( i
= 0; i
< numCols
; i
++ )
2107 m_colWidths
.Add( m_defaultColWidth
);
2108 m_colRights
.Add( 0 );
2111 int oldNumCols
= m_numCols
;
2112 m_numCols
+= numCols
;
2115 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
2117 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
2119 right
+= m_colWidths
[i
];
2120 m_colRights
[i
] = right
;
2126 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
2128 size_t pos
= msg
.GetCommandInt();
2129 int numCols
= msg
.GetCommandInt2();
2130 for ( i
= 0; i
< numCols
; i
++ )
2132 m_colWidths
.Remove( pos
);
2133 m_colRights
.Remove( pos
);
2135 m_numCols
-= numCols
;
2139 #if 0 // leave the row alone here so that AppendCols will work subsequently
2141 m_rowHeights
.Clear();
2142 m_rowBottoms
.Clear();
2144 m_currentCellCoords
= wxGridNoCellCoords
;
2148 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
2149 m_currentCellCoords
.Set( 0, 0 );
2152 for ( i
= 0; i
< m_numCols
; i
++ )
2154 w
+= m_colWidths
[i
];
2167 void wxGrid::CalcRowLabelsExposed( wxRegion
& reg
)
2169 wxRegionIterator
iter( reg
);
2172 m_rowLabelsExposed
.Empty();
2179 // TODO: remove this when we can...
2180 // There is a bug in wxMotif that gives garbage update
2181 // rectangles if you jump-scroll a long way by clicking the
2182 // scrollbar with middle button. This is a work-around
2184 #if defined(__WXMOTIF__)
2186 m_gridWin
->GetClientSize( &cw
, &ch
);
2187 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
2188 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
2191 // logical bounds of update region
2194 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
2195 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
2197 // find the row labels within these bounds
2201 for ( row
= 0; row
< m_numRows
; row
++ )
2203 if ( m_rowBottoms
[row
] < top
) continue;
2205 rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
2206 if ( rowTop
> bottom
) break;
2208 m_rowLabelsExposed
.Add( row
);
2216 void wxGrid::CalcColLabelsExposed( wxRegion
& reg
)
2218 wxRegionIterator
iter( reg
);
2221 m_colLabelsExposed
.Empty();
2228 // TODO: remove this when we can...
2229 // There is a bug in wxMotif that gives garbage update
2230 // rectangles if you jump-scroll a long way by clicking the
2231 // scrollbar with middle button. This is a work-around
2233 #if defined(__WXMOTIF__)
2235 m_gridWin
->GetClientSize( &cw
, &ch
);
2236 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
2237 r
.SetRight( wxMin( r
.GetRight(), cw
) );
2240 // logical bounds of update region
2243 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
2244 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
2246 // find the cells within these bounds
2250 for ( col
= 0; col
< m_numCols
; col
++ )
2252 if ( m_colRights
[col
] < left
) continue;
2254 colLeft
= m_colRights
[col
] - m_colWidths
[col
];
2255 if ( colLeft
> right
) break;
2257 m_colLabelsExposed
.Add( col
);
2265 void wxGrid::CalcCellsExposed( wxRegion
& reg
)
2267 wxRegionIterator
iter( reg
);
2270 m_cellsExposed
.Empty();
2271 m_rowsExposed
.Empty();
2272 m_colsExposed
.Empty();
2274 int left
, top
, right
, bottom
;
2279 // TODO: remove this when we can...
2280 // There is a bug in wxMotif that gives garbage update
2281 // rectangles if you jump-scroll a long way by clicking the
2282 // scrollbar with middle button. This is a work-around
2284 #if defined(__WXMOTIF__)
2286 m_gridWin
->GetClientSize( &cw
, &ch
);
2287 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
2288 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
2289 r
.SetRight( wxMin( r
.GetRight(), cw
) );
2290 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
2293 // logical bounds of update region
2295 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
2296 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
2298 // find the cells within these bounds
2301 int colLeft
, rowTop
;
2302 for ( row
= 0; row
< m_numRows
; row
++ )
2304 if ( m_rowBottoms
[row
] < top
) continue;
2306 rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
2307 if ( rowTop
> bottom
) break;
2309 m_rowsExposed
.Add( row
);
2311 for ( col
= 0; col
< m_numCols
; col
++ )
2313 if ( m_colRights
[col
] < left
) continue;
2315 colLeft
= m_colRights
[col
] - m_colWidths
[col
];
2316 if ( colLeft
> right
) break;
2318 if ( m_colsExposed
.Index( col
) == wxNOT_FOUND
) m_colsExposed
.Add( col
);
2319 m_cellsExposed
.Add( wxGridCellCoords( row
, col
) );
2328 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
2331 wxPoint
pos( event
.GetPosition() );
2332 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2334 if ( event
.Dragging() )
2336 m_isDragging
= TRUE
;
2338 if ( event
.LeftIsDown() )
2340 switch( m_cursorMode
)
2342 case WXGRID_CURSOR_RESIZE_ROW
:
2344 int cw
, ch
, left
, dummy
;
2345 m_gridWin
->GetClientSize( &cw
, &ch
);
2346 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
2348 wxClientDC
dc( m_gridWin
);
2351 m_rowBottoms
[m_dragRowOrCol
] -
2352 m_rowHeights
[m_dragRowOrCol
] +
2353 WXGRID_MIN_ROW_HEIGHT
);
2354 dc
.SetLogicalFunction(wxINVERT
);
2355 if ( m_dragLastPos
>= 0 )
2357 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
2359 dc
.DrawLine( left
, y
, left
+cw
, y
);
2364 case WXGRID_CURSOR_SELECT_ROW
:
2365 if ( (row
= YToRow( y
)) >= 0 &&
2366 !IsInSelection( row
, 0 ) )
2368 SelectRow( row
, TRUE
);
2371 // default label to suppress warnings about "enumeration value
2372 // 'xxx' not handled in switch
2380 m_isDragging
= FALSE
;
2383 // ------------ Entering or leaving the window
2385 if ( event
.Entering() || event
.Leaving() )
2387 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
2391 // ------------ Left button pressed
2393 else if ( event
.LeftDown() )
2395 // don't send a label click event for a hit on the
2396 // edge of the row label - this is probably the user
2397 // wanting to resize the row
2399 if ( YToEdgeOfRow(y
) < 0 )
2403 !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
2405 SelectRow( row
, event
.ShiftDown() );
2406 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
2411 // starting to drag-resize a row
2413 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
2418 // ------------ Left double click
2420 else if (event
.LeftDClick() )
2422 if ( YToEdgeOfRow(y
) < 0 )
2425 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
);
2430 // ------------ Left button released
2432 else if ( event
.LeftUp() )
2434 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
2436 DoEndDragResizeRow();
2438 // Note: we are ending the event *after* doing
2439 // default processing in this case
2441 SendEvent( EVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
2444 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
2449 // ------------ Right button down
2451 else if ( event
.RightDown() )
2454 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
2456 // no default action at the moment
2461 // ------------ Right double click
2463 else if ( event
.RightDClick() )
2466 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
2468 // no default action at the moment
2473 // ------------ No buttons down and mouse moving
2475 else if ( event
.Moving() )
2477 m_dragRowOrCol
= YToEdgeOfRow( y
);
2478 if ( m_dragRowOrCol
>= 0 )
2480 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2482 // don't capture the mouse yet
2483 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, FALSE
);
2486 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
2488 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, FALSE
);
2494 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
2497 wxPoint
pos( event
.GetPosition() );
2498 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2500 if ( event
.Dragging() )
2502 m_isDragging
= TRUE
;
2504 if ( event
.LeftIsDown() )
2506 switch( m_cursorMode
)
2508 case WXGRID_CURSOR_RESIZE_COL
:
2510 int cw
, ch
, dummy
, top
;
2511 m_gridWin
->GetClientSize( &cw
, &ch
);
2512 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
2514 wxClientDC
dc( m_gridWin
);
2517 m_colRights
[m_dragRowOrCol
] -
2518 m_colWidths
[m_dragRowOrCol
] +
2519 WXGRID_MIN_COL_WIDTH
);
2520 dc
.SetLogicalFunction(wxINVERT
);
2521 if ( m_dragLastPos
>= 0 )
2523 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
2525 dc
.DrawLine( x
, top
, x
, top
+ch
);
2530 case WXGRID_CURSOR_SELECT_COL
:
2531 if ( (col
= XToCol( x
)) >= 0 &&
2532 !IsInSelection( 0, col
) )
2534 SelectCol( col
, TRUE
);
2537 // default label to suppress warnings about "enumeration value
2538 // 'xxx' not handled in switch
2546 m_isDragging
= FALSE
;
2549 // ------------ Entering or leaving the window
2551 if ( event
.Entering() || event
.Leaving() )
2553 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
2557 // ------------ Left button pressed
2559 else if ( event
.LeftDown() )
2561 // don't send a label click event for a hit on the
2562 // edge of the col label - this is probably the user
2563 // wanting to resize the col
2565 if ( XToEdgeOfCol(x
) < 0 )
2569 !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
2571 SelectCol( col
, event
.ShiftDown() );
2572 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, m_colLabelWin
);
2577 // starting to drag-resize a col
2579 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
);
2584 // ------------ Left double click
2586 if ( event
.LeftDClick() )
2588 if ( XToEdgeOfCol(x
) < 0 )
2591 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
);
2596 // ------------ Left button released
2598 else if ( event
.LeftUp() )
2600 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
2602 DoEndDragResizeCol();
2604 // Note: we are ending the event *after* doing
2605 // default processing in this case
2607 SendEvent( EVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
2610 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
2615 // ------------ Right button down
2617 else if ( event
.RightDown() )
2620 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
2622 // no default action at the moment
2627 // ------------ Right double click
2629 else if ( event
.RightDClick() )
2632 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
2634 // no default action at the moment
2639 // ------------ No buttons down and mouse moving
2641 else if ( event
.Moving() )
2643 m_dragRowOrCol
= XToEdgeOfCol( x
);
2644 if ( m_dragRowOrCol
>= 0 )
2646 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2648 // don't capture the cursor yet
2649 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
, FALSE
);
2652 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
2654 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
, FALSE
);
2660 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
2662 if ( event
.LeftDown() )
2664 // indicate corner label by having both row and
2667 if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
2673 else if ( event
.LeftDClick() )
2675 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
2678 else if ( event
.RightDown() )
2680 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
2682 // no default action at the moment
2686 else if ( event
.RightDClick() )
2688 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
2690 // no default action at the moment
2695 void wxGrid::ChangeCursorMode(CursorMode mode
,
2700 static const wxChar
*cursorModes
[] =
2709 wxLogTrace(_T("grid"),
2710 _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
2711 win
== m_colLabelWin
? _T("colLabelWin")
2712 : win
? _T("rowLabelWin")
2714 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
2715 #endif // __WXDEBUG__
2717 if ( mode
== m_cursorMode
)
2722 // by default use the grid itself
2728 m_winCapture
->ReleaseMouse();
2729 m_winCapture
= (wxWindow
*)NULL
;
2732 m_cursorMode
= mode
;
2734 switch ( m_cursorMode
)
2736 case WXGRID_CURSOR_RESIZE_ROW
:
2737 win
->SetCursor( m_rowResizeCursor
);
2740 case WXGRID_CURSOR_RESIZE_COL
:
2741 win
->SetCursor( m_colResizeCursor
);
2745 win
->SetCursor( *wxSTANDARD_CURSOR
);
2748 // we need to capture mouse when resizing
2749 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
2750 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
2752 if ( captureMouse
&& resize
)
2754 win
->CaptureMouse();
2759 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
2762 wxPoint
pos( event
.GetPosition() );
2763 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2765 wxGridCellCoords coords
;
2766 XYToCell( x
, y
, coords
);
2768 if ( event
.Dragging() )
2770 //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
2772 // Don't start doing anything until the mouse has been drug at
2773 // least 3 pixels in any direction...
2774 if (! m_isDragging
) {
2775 if (m_startDragPos
== wxDefaultPosition
) {
2776 m_startDragPos
= pos
;
2779 if (abs(m_startDragPos
.x
- pos
.x
) < 4 && abs(m_startDragPos
.y
- pos
.y
) < 4)
2783 m_isDragging
= TRUE
;
2784 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2786 // Hide the edit control, so it
2787 // won't interfer with drag-shrinking.
2788 if ( IsCellEditControlEnabled() )
2789 HideCellEditControl();
2791 // Have we captured the mouse yet?
2792 if (! m_winCapture
) {
2793 m_winCapture
= m_gridWin
;
2794 m_winCapture
->CaptureMouse();
2797 if ( coords
!= wxGridNoCellCoords
)
2799 if ( !IsSelection() )
2801 SelectBlock( coords
, coords
);
2805 SelectBlock( m_currentCellCoords
, coords
);
2808 if (! IsVisible(coords
)) {
2809 MakeCellVisible(coords
);
2810 // TODO: need to introduce a delay or something here. The
2811 // scrolling is way to fast, at least on MSW.
2815 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
2817 int cw
, ch
, left
, dummy
;
2818 m_gridWin
->GetClientSize( &cw
, &ch
);
2819 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
2821 wxClientDC
dc( m_gridWin
);
2824 m_rowBottoms
[m_dragRowOrCol
] -
2825 m_rowHeights
[m_dragRowOrCol
] +
2826 WXGRID_MIN_ROW_HEIGHT
);
2827 dc
.SetLogicalFunction(wxINVERT
);
2828 if ( m_dragLastPos
>= 0 )
2830 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
2832 dc
.DrawLine( left
, y
, left
+cw
, y
);
2835 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
2837 int cw
, ch
, dummy
, top
;
2838 m_gridWin
->GetClientSize( &cw
, &ch
);
2839 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
2841 wxClientDC
dc( m_gridWin
);
2844 m_colRights
[m_dragRowOrCol
] -
2845 m_colWidths
[m_dragRowOrCol
] + WXGRID_MIN_COL_WIDTH
);
2846 dc
.SetLogicalFunction(wxINVERT
);
2847 if ( m_dragLastPos
>= 0 )
2849 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
2851 dc
.DrawLine( x
, top
, x
, top
+ch
);
2858 m_isDragging
= FALSE
;
2859 m_startDragPos
= wxDefaultPosition
;
2862 if ( coords
!= wxGridNoCellCoords
)
2864 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
2865 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
2868 if ( event
.Entering() || event
.Leaving() )
2870 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
2871 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
2876 // ------------ Left button pressed
2878 if ( event
.LeftDown() )
2880 EnableCellEditControl( FALSE
);
2881 if ( event
.ShiftDown() )
2883 SelectBlock( m_currentCellCoords
, coords
);
2885 else if ( XToEdgeOfCol(x
) < 0 &&
2886 YToEdgeOfRow(y
) < 0 )
2888 if ( !SendEvent( EVT_GRID_CELL_LEFT_CLICK
,
2893 MakeCellVisible( coords
);
2895 // if this is the second click on this cell then start
2897 if (m_waitForSlowClick
&& coords
== m_currentCellCoords
) {
2898 EnableCellEditControl(TRUE
);
2899 ShowCellEditControl();
2902 SetCurrentCell( coords
);
2903 m_editTimer
->Start( 1500, TRUE
);
2904 m_waitForSlowClick
= TRUE
;
2911 // ------------ Left double click
2913 else if ( event
.LeftDClick() )
2915 EnableCellEditControl( FALSE
);
2916 if ( XToEdgeOfCol(x
) < 0 && YToEdgeOfRow(y
) < 0 )
2918 SendEvent( EVT_GRID_CELL_LEFT_DCLICK
,
2926 // ------------ Left button released
2928 else if ( event
.LeftUp() )
2930 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2932 if ( IsSelection() )
2935 m_winCapture
->ReleaseMouse();
2936 m_winCapture
= NULL
;
2938 SendEvent( EVT_GRID_RANGE_SELECT
, -1, -1, event
);
2941 // Show the edit control, if it has
2942 // been hidden for drag-shrinking.
2943 if ( IsCellEditControlEnabled() )
2944 ShowCellEditControl();
2946 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
2948 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
2949 DoEndDragResizeRow();
2951 // Note: we are ending the event *after* doing
2952 // default processing in this case
2954 SendEvent( EVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
2956 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
2958 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
2959 DoEndDragResizeCol();
2961 // Note: we are ending the event *after* doing
2962 // default processing in this case
2964 SendEvent( EVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
2971 // ------------ Right button down
2973 else if ( event
.RightDown() )
2975 EnableCellEditControl( FALSE
);
2976 if ( !SendEvent( EVT_GRID_CELL_RIGHT_CLICK
,
2981 // no default action at the moment
2986 // ------------ Right double click
2988 else if ( event
.RightDClick() )
2990 EnableCellEditControl( FALSE
);
2991 if ( !SendEvent( EVT_GRID_CELL_RIGHT_DCLICK
,
2996 // no default action at the moment
3000 // ------------ Moving and no button action
3002 else if ( event
.Moving() && !event
.IsButton() )
3004 int dragRow
= YToEdgeOfRow( y
);
3005 int dragCol
= XToEdgeOfCol( x
);
3007 // Dragging on the corner of a cell to resize in both
3008 // directions is not implemented yet...
3010 if ( dragRow
>= 0 && dragCol
>= 0 )
3012 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3018 m_dragRowOrCol
= dragRow
;
3020 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3022 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
);
3030 m_dragRowOrCol
= dragCol
;
3032 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3034 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
);
3040 // Neither on a row or col edge
3042 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3044 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3051 void wxGrid::DoEndDragResizeRow()
3053 if ( m_dragLastPos
>= 0 )
3055 // erase the last line and resize the row
3057 int cw
, ch
, left
, dummy
;
3058 m_gridWin
->GetClientSize( &cw
, &ch
);
3059 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
3061 wxClientDC
dc( m_gridWin
);
3063 dc
.SetLogicalFunction( wxINVERT
);
3064 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
3065 HideCellEditControl();
3067 int rowTop
= m_rowBottoms
[m_dragRowOrCol
] - m_rowHeights
[m_dragRowOrCol
];
3068 SetRowSize( m_dragRowOrCol
,
3069 wxMax( m_dragLastPos
- rowTop
, WXGRID_MIN_ROW_HEIGHT
) );
3071 if ( !GetBatchCount() )
3073 // Only needed to get the correct rect.y:
3074 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
3076 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
3077 rect
.width
= m_rowLabelWidth
;
3078 rect
.height
= ch
- rect
.y
;
3079 m_rowLabelWin
->Refresh( TRUE
, &rect
);
3081 m_gridWin
->Refresh( FALSE
, &rect
);
3084 ShowCellEditControl();
3089 void wxGrid::DoEndDragResizeCol()
3091 if ( m_dragLastPos
>= 0 )
3093 // erase the last line and resize the col
3095 int cw
, ch
, dummy
, top
;
3096 m_gridWin
->GetClientSize( &cw
, &ch
);
3097 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
3099 wxClientDC
dc( m_gridWin
);
3101 dc
.SetLogicalFunction( wxINVERT
);
3102 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
3103 HideCellEditControl();
3105 int colLeft
= m_colRights
[m_dragRowOrCol
] - m_colWidths
[m_dragRowOrCol
];
3106 SetColSize( m_dragRowOrCol
,
3107 wxMax( m_dragLastPos
- colLeft
, WXGRID_MIN_COL_WIDTH
) );
3109 if ( !GetBatchCount() )
3111 // Only needed to get the correct rect.x:
3112 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
3114 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
3115 rect
.width
= cw
- rect
.x
;
3116 rect
.height
= m_colLabelHeight
;
3117 m_colLabelWin
->Refresh( TRUE
, &rect
);
3119 m_gridWin
->Refresh( FALSE
, &rect
);
3122 ShowCellEditControl();
3129 // ------ interaction with data model
3131 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
3133 switch ( msg
.GetId() )
3135 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
3136 return GetModelValues();
3138 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
3139 return SetModelValues();
3141 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
3142 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
3143 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
3144 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
3145 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
3146 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
3147 return Redimension( msg
);
3156 // The behaviour of this function depends on the grid table class
3157 // Clear() function. For the default wxGridStringTable class the
3158 // behavious is to replace all cell contents with wxEmptyString but
3159 // not to change the number of rows or cols.
3161 void wxGrid::ClearGrid()
3166 SetEditControlValue();
3167 if ( !GetBatchCount() ) m_gridWin
->Refresh();
3172 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
3174 // TODO: something with updateLabels flag
3178 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
3184 bool ok
= m_table
->InsertRows( pos
, numRows
);
3186 // the table will have sent the results of the insert row
3187 // operation to this view object as a grid table message
3191 if ( m_numCols
== 0 )
3193 m_table
->AppendCols( WXGRID_DEFAULT_NUMBER_COLS
);
3195 // TODO: perhaps instead of appending the default number of cols
3196 // we should remember what the last non-zero number of cols was ?
3200 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3202 // if we have just inserted cols into an empty grid the current
3203 // cell will be undefined...
3205 SetCurrentCell( 0, 0 );
3209 if ( !GetBatchCount() ) Refresh();
3212 SetEditControlValue();
3222 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
3224 // TODO: something with updateLabels flag
3228 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
3232 if ( m_table
&& m_table
->AppendRows( numRows
) )
3234 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3236 // if we have just inserted cols into an empty grid the current
3237 // cell will be undefined...
3239 SetCurrentCell( 0, 0 );
3242 // the table will have sent the results of the append row
3243 // operation to this view object as a grid table message
3246 if ( !GetBatchCount() ) Refresh();
3256 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
3258 // TODO: something with updateLabels flag
3262 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
3266 if ( m_table
&& m_table
->DeleteRows( pos
, numRows
) )
3268 // the table will have sent the results of the delete row
3269 // operation to this view object as a grid table message
3271 if ( m_numRows
> 0 )
3272 SetEditControlValue();
3274 HideCellEditControl();
3277 if ( !GetBatchCount() ) Refresh();
3287 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
3289 // TODO: something with updateLabels flag
3293 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
3299 HideCellEditControl();
3300 bool ok
= m_table
->InsertCols( pos
, numCols
);
3302 // the table will have sent the results of the insert col
3303 // operation to this view object as a grid table message
3307 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3309 // if we have just inserted cols into an empty grid the current
3310 // cell will be undefined...
3312 SetCurrentCell( 0, 0 );
3316 if ( !GetBatchCount() ) Refresh();
3319 SetEditControlValue();
3329 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
3331 // TODO: something with updateLabels flag
3335 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
3339 if ( m_table
&& m_table
->AppendCols( numCols
) )
3341 // the table will have sent the results of the append col
3342 // operation to this view object as a grid table message
3344 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3346 // if we have just inserted cols into an empty grid the current
3347 // cell will be undefined...
3349 SetCurrentCell( 0, 0 );
3353 if ( !GetBatchCount() ) Refresh();
3363 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
3365 // TODO: something with updateLabels flag
3369 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
3373 if ( m_table
&& m_table
->DeleteCols( pos
, numCols
) )
3375 // the table will have sent the results of the delete col
3376 // operation to this view object as a grid table message
3378 if ( m_numCols
> 0 )
3379 SetEditControlValue();
3381 HideCellEditControl();
3384 if ( !GetBatchCount() ) Refresh();
3396 // ----- event handlers
3399 // Generate a grid event based on a mouse event and
3400 // return the result of ProcessEvent()
3402 bool wxGrid::SendEvent( const wxEventType type
,
3404 wxMouseEvent
& mouseEv
)
3406 if ( type
== EVT_GRID_ROW_SIZE
||
3407 type
== EVT_GRID_COL_SIZE
)
3409 int rowOrCol
= (row
== -1 ? col
: row
);
3411 wxGridSizeEvent
gridEvt( GetId(),
3415 mouseEv
.GetX(), mouseEv
.GetY(),
3416 mouseEv
.ControlDown(),
3417 mouseEv
.ShiftDown(),
3419 mouseEv
.MetaDown() );
3421 return GetEventHandler()->ProcessEvent(gridEvt
);
3423 else if ( type
== EVT_GRID_RANGE_SELECT
)
3425 wxGridRangeSelectEvent
gridEvt( GetId(),
3429 m_selectedBottomRight
,
3430 mouseEv
.ControlDown(),
3431 mouseEv
.ShiftDown(),
3433 mouseEv
.MetaDown() );
3435 return GetEventHandler()->ProcessEvent(gridEvt
);
3439 wxGridEvent
gridEvt( GetId(),
3443 mouseEv
.GetX(), mouseEv
.GetY(),
3444 mouseEv
.ControlDown(),
3445 mouseEv
.ShiftDown(),
3447 mouseEv
.MetaDown() );
3449 return GetEventHandler()->ProcessEvent(gridEvt
);
3454 // Generate a grid event of specified type and return the result
3455 // of ProcessEvent().
3457 bool wxGrid::SendEvent( const wxEventType type
,
3460 if ( type
== EVT_GRID_ROW_SIZE
||
3461 type
== EVT_GRID_COL_SIZE
)
3463 int rowOrCol
= (row
== -1 ? col
: row
);
3465 wxGridSizeEvent
gridEvt( GetId(),
3470 return GetEventHandler()->ProcessEvent(gridEvt
);
3474 wxGridEvent
gridEvt( GetId(),
3479 return GetEventHandler()->ProcessEvent(gridEvt
);
3484 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3486 wxPaintDC
dc( this );
3488 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
3489 m_numRows
&& m_numCols
)
3491 m_currentCellCoords
.Set(0, 0);
3492 SetEditControlValue();
3493 ShowCellEditControl();
3500 // This is just here to make sure that CalcDimensions gets called when
3501 // the grid view is resized... then the size event is skipped to allow
3502 // the box sizers to handle everything
3504 void wxGrid::OnSize( wxSizeEvent
& event
)
3511 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
3513 if ( m_inOnKeyDown
)
3515 // shouldn't be here - we are going round in circles...
3517 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
3520 m_inOnKeyDown
= TRUE
;
3522 // propagate the event up and see if it gets processed
3524 wxWindow
*parent
= GetParent();
3525 wxKeyEvent
keyEvt( event
);
3526 keyEvt
.SetEventObject( parent
);
3528 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
3530 // try local handlers
3532 switch ( event
.KeyCode() )
3535 if ( event
.ControlDown() )
3537 MoveCursorUpBlock();
3546 if ( event
.ControlDown() )
3548 MoveCursorDownBlock();
3557 if ( event
.ControlDown() )
3559 MoveCursorLeftBlock();
3568 if ( event
.ControlDown() )
3570 MoveCursorRightBlock();
3579 if ( event
.ControlDown() )
3581 event
.Skip(); // to let the edit control have the return
3590 if (event
.ShiftDown())
3597 if ( event
.ControlDown() )
3599 MakeCellVisible( 0, 0 );
3600 SetCurrentCell( 0, 0 );
3609 if ( event
.ControlDown() )
3611 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
3612 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
3628 // We don't want these keys to trigger the edit control, any others?
3637 if ( !IsEditable() )
3642 // Otherwise fall through to default
3645 // now try the cell edit control
3647 if ( !IsCellEditControlEnabled() )
3648 EnableCellEditControl( TRUE
);
3649 if (IsCellEditControlEnabled()) {
3650 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
3651 attr
->GetEditor()->StartingKey(event
);
3658 m_inOnKeyDown
= FALSE
;
3662 void wxGrid::OnEraseBackground(wxEraseEvent
&)
3666 void wxGrid::OnEditTimer(wxTimerEvent
&)
3668 m_waitForSlowClick
= FALSE
;
3673 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
3675 if ( SendEvent( EVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
3677 // the event has been intercepted - do nothing
3682 m_currentCellCoords
!= wxGridNoCellCoords
)
3684 HideCellEditControl();
3685 SaveEditControlValue();
3686 EnableCellEditControl(FALSE
);
3688 // Clear the old current cell highlight
3689 wxRect r
= BlockToDeviceRect(m_currentCellCoords
, m_currentCellCoords
);
3690 r
.x
--; r
.y
--; r
.width
++; r
.height
++;
3691 m_gridWin
->Refresh( FALSE
, &r
);
3694 m_currentCellCoords
= coords
;
3696 SetEditControlValue();
3701 ShowCellEditControl();
3703 wxClientDC
dc(m_gridWin
);
3705 DrawCellHighlight(dc
);
3708 if ( IsSelection() )
3710 wxRect
r( SelectionToDeviceRect() );
3712 if ( !GetBatchCount() ) m_gridWin
->Refresh( FALSE
, &r
);
3719 // ------ functions to get/send data (see also public functions)
3722 bool wxGrid::GetModelValues()
3726 // all we need to do is repaint the grid
3728 m_gridWin
->Refresh();
3736 bool wxGrid::SetModelValues()
3742 for ( row
= 0; row
< m_numRows
; row
++ )
3744 for ( col
= 0; col
< m_numCols
; col
++ )
3746 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
3758 // Note - this function only draws cells that are in the list of
3759 // exposed cells (usually set from the update region by
3760 // CalcExposedCells)
3762 void wxGrid::DrawGridCellArea( wxDC
& dc
)
3764 if ( !m_numRows
|| !m_numCols
) return;
3767 size_t numCells
= m_cellsExposed
.GetCount();
3769 for ( i
= 0; i
< numCells
; i
++ )
3771 DrawCell( dc
, m_cellsExposed
[i
] );
3776 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
3778 int row
= coords
.GetRow();
3779 int col
= coords
.GetCol();
3781 if ( m_colWidths
[col
] <= 0 || m_rowHeights
[row
] <= 0 )
3784 // we draw the cell border ourselves
3785 #if !WXGRID_DRAW_LINES
3786 if ( m_gridLinesEnabled
)
3787 DrawCellBorder( dc
, coords
);
3790 // but all the rest is drawn by the cell renderer and hence may be
3793 rect
.x
= m_colRights
[col
] - m_colWidths
[col
];
3794 rect
.y
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3795 rect
.width
= m_colWidths
[col
];
3796 rect
.height
= m_rowHeights
[row
];
3798 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
3799 attr
->GetRenderer()->Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
3802 if (m_currentCellCoords
== coords
)
3803 DrawCellHighlight(dc
);
3807 void wxGrid::DrawCellHighlight( wxDC
& dc
)
3809 int row
= m_currentCellCoords
.GetRow();
3810 int col
= m_currentCellCoords
.GetCol();
3812 if ( m_colWidths
[col
] <= 0 || m_rowHeights
[row
] <= 0 )
3816 rect
.x
= m_colRights
[col
] - m_colWidths
[col
];
3817 rect
.y
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3818 rect
.width
= m_colWidths
[col
] - 1;
3819 rect
.height
= m_rowHeights
[row
] - 1;
3821 dc
.SetPen(wxPen(m_gridLineColour
, 3, wxSOLID
));
3822 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
3823 //dc.SetLogicalFunction(wxINVERT);
3825 dc
.DrawRectangle(rect
);
3828 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
3830 if ( m_colWidths
[coords
.GetCol()] <=0 ||
3831 m_rowHeights
[coords
.GetRow()] <= 0 ) return;
3833 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
3834 int row
= coords
.GetRow();
3835 int col
= coords
.GetCol();
3837 // right hand border
3839 dc
.DrawLine( m_colRights
[col
], m_rowBottoms
[row
] - m_rowHeights
[row
],
3840 m_colRights
[col
], m_rowBottoms
[row
] );
3844 dc
.DrawLine( m_colRights
[col
] - m_colWidths
[col
], m_rowBottoms
[row
],
3845 m_colRights
[col
], m_rowBottoms
[row
] );
3849 // TODO: remove this ???
3850 // This is used to redraw all grid lines e.g. when the grid line colour
3853 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
)
3855 if ( !m_gridLinesEnabled
||
3857 !m_numCols
) return;
3859 int top
, bottom
, left
, right
;
3863 m_gridWin
->GetClientSize(&cw
, &ch
);
3865 // virtual coords of visible area
3867 CalcUnscrolledPosition( 0, 0, &left
, &top
);
3868 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
3872 reg
.GetBox(x
, y
, w
, h
);
3873 CalcUnscrolledPosition( x
, y
, &left
, &top
);
3874 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
3877 // avoid drawing grid lines past the last row and col
3879 right
= wxMin( right
, m_colRights
[m_numCols
-1] );
3880 bottom
= wxMin( bottom
, m_rowBottoms
[m_numRows
-1] );
3882 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
3884 // horizontal grid lines
3887 for ( i
= 0; i
< m_numRows
; i
++ )
3889 if ( m_rowBottoms
[i
]-1 > bottom
)
3893 else if ( m_rowBottoms
[i
]-1 >= top
)
3895 dc
.DrawLine( left
, m_rowBottoms
[i
]-1, right
, m_rowBottoms
[i
]-1 );
3900 // vertical grid lines
3902 for ( i
= 0; i
< m_numCols
; i
++ )
3904 if ( m_colRights
[i
]-1 > right
)
3908 else if ( m_colRights
[i
]-1 >= left
)
3910 dc
.DrawLine( m_colRights
[i
]-1, top
, m_colRights
[i
]-1, bottom
);
3916 void wxGrid::DrawRowLabels( wxDC
& dc
)
3918 if ( !m_numRows
|| !m_numCols
) return;
3921 size_t numLabels
= m_rowLabelsExposed
.GetCount();
3923 for ( i
= 0; i
< numLabels
; i
++ )
3925 DrawRowLabel( dc
, m_rowLabelsExposed
[i
] );
3930 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
3932 if ( m_rowHeights
[row
] <= 0 ) return;
3934 int rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3936 dc
.SetPen( *wxBLACK_PEN
);
3937 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
3938 m_rowLabelWidth
-1, m_rowBottoms
[row
]-1 );
3940 dc
.DrawLine( 0, m_rowBottoms
[row
]-1,
3941 m_rowLabelWidth
-1, m_rowBottoms
[row
]-1 );
3943 dc
.SetPen( *wxWHITE_PEN
);
3944 dc
.DrawLine( 0, rowTop
, 0, m_rowBottoms
[row
]-1 );
3945 dc
.DrawLine( 0, rowTop
, m_rowLabelWidth
-1, rowTop
);
3947 dc
.SetBackgroundMode( wxTRANSPARENT
);
3948 dc
.SetTextForeground( GetLabelTextColour() );
3949 dc
.SetFont( GetLabelFont() );
3952 GetRowLabelAlignment( &hAlign
, &vAlign
);
3956 rect
.SetY( m_rowBottoms
[row
] - m_rowHeights
[row
] + 2 );
3957 rect
.SetWidth( m_rowLabelWidth
- 4 );
3958 rect
.SetHeight( m_rowHeights
[row
] - 4 );
3959 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
3963 void wxGrid::DrawColLabels( wxDC
& dc
)
3965 if ( !m_numRows
|| !m_numCols
) return;
3968 size_t numLabels
= m_colLabelsExposed
.GetCount();
3970 for ( i
= 0; i
< numLabels
; i
++ )
3972 DrawColLabel( dc
, m_colLabelsExposed
[i
] );
3977 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
3979 if ( m_colWidths
[col
] <= 0 ) return;
3981 int colLeft
= m_colRights
[col
] - m_colWidths
[col
];
3983 dc
.SetPen( *wxBLACK_PEN
);
3984 dc
.DrawLine( m_colRights
[col
]-1, 0,
3985 m_colRights
[col
]-1, m_colLabelHeight
-1 );
3987 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
3988 m_colRights
[col
]-1, m_colLabelHeight
-1 );
3990 dc
.SetPen( *wxWHITE_PEN
);
3991 dc
.DrawLine( colLeft
, 0, colLeft
, m_colLabelHeight
-1 );
3992 dc
.DrawLine( colLeft
, 0, m_colRights
[col
]-1, 0 );
3994 dc
.SetBackgroundMode( wxTRANSPARENT
);
3995 dc
.SetTextForeground( GetLabelTextColour() );
3996 dc
.SetFont( GetLabelFont() );
3998 dc
.SetBackgroundMode( wxTRANSPARENT
);
3999 dc
.SetTextForeground( GetLabelTextColour() );
4000 dc
.SetFont( GetLabelFont() );
4003 GetColLabelAlignment( &hAlign
, &vAlign
);
4006 rect
.SetX( m_colRights
[col
] - m_colWidths
[col
] + 2 );
4008 rect
.SetWidth( m_colWidths
[col
] - 4 );
4009 rect
.SetHeight( m_colLabelHeight
- 4 );
4010 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
);
4014 void wxGrid::DrawTextRectangle( wxDC
& dc
,
4015 const wxString
& value
,
4020 long textWidth
, textHeight
;
4021 long lineWidth
, lineHeight
;
4022 wxArrayString lines
;
4024 dc
.SetClippingRegion( rect
);
4025 StringToLines( value
, lines
);
4026 if ( lines
.GetCount() )
4028 GetTextBoxSize( dc
, lines
, &textWidth
, &textHeight
);
4029 dc
.GetTextExtent( lines
[0], &lineWidth
, &lineHeight
);
4032 switch ( horizAlign
)
4035 x
= rect
.x
+ (rect
.width
- textWidth
- 1);
4039 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
4048 switch ( vertAlign
)
4051 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
4055 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
4064 for ( size_t i
= 0; i
< lines
.GetCount(); i
++ )
4066 dc
.DrawText( lines
[i
], (long)x
, (long)y
);
4071 dc
.DestroyClippingRegion();
4075 // Split multi line text up into an array of strings. Any existing
4076 // contents of the string array are preserved.
4078 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
4082 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
4083 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
4085 while ( startPos
< (int)tVal
.Length() )
4087 pos
= tVal
.Mid(startPos
).Find( eol
);
4092 else if ( pos
== 0 )
4094 lines
.Add( wxEmptyString
);
4098 lines
.Add( value
.Mid(startPos
, pos
) );
4102 if ( startPos
< (int)value
.Length() )
4104 lines
.Add( value
.Mid( startPos
) );
4109 void wxGrid::GetTextBoxSize( wxDC
& dc
,
4110 wxArrayString
& lines
,
4111 long *width
, long *height
)
4118 for ( i
= 0; i
< lines
.GetCount(); i
++ )
4120 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
4121 w
= wxMax( w
, lineW
);
4131 // ------ Edit control functions
4135 void wxGrid::EnableEditing( bool edit
)
4137 // TODO: improve this ?
4139 if ( edit
!= m_editable
)
4143 EnableCellEditControl(m_editable
);
4148 void wxGrid::EnableCellEditControl( bool enable
)
4153 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4154 SetCurrentCell( 0, 0 );
4156 if ( enable
!= m_cellEditCtrlEnabled
)
4160 m_cellEditCtrlEnabled
= enable
;
4161 SetEditControlValue();
4162 ShowCellEditControl();
4166 HideCellEditControl();
4167 SaveEditControlValue();
4168 m_cellEditCtrlEnabled
= enable
;
4174 void wxGrid::ShowCellEditControl()
4176 if ( IsCellEditControlEnabled() )
4178 if ( !IsVisible( m_currentCellCoords
) )
4184 wxRect rect
= CellToRect( m_currentCellCoords
);
4185 int row
= m_currentCellCoords
.GetRow();
4186 int col
= m_currentCellCoords
.GetCol();
4188 // convert to scrolled coords
4190 int left
, top
, right
, bottom
;
4191 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
4192 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
4193 left
--; top
--; right
--; bottom
--; // cell is shifted by one pixel
4195 m_gridWin
->GetClientSize( &cw
, &ch
);
4197 // Make the edit control large enough to allow for internal margins
4198 // TODO: remove this if the text ctrl sizing is improved esp. for unix
4201 #if defined(__WXMOTIF__)
4202 if ( row
== 0 || col
== 0 )
4211 if ( row
== 0 || col
== 0 )
4221 #if defined(__WXGTK__)
4224 if (left
!= 0) left_diff
++;
4225 if (top
!= 0) top_diff
++;
4226 rect
.SetLeft( left
+ left_diff
);
4227 rect
.SetTop( top
+ top_diff
);
4228 rect
.SetRight( rect
.GetRight() - left_diff
);
4229 rect
.SetBottom( rect
.GetBottom() - top_diff
);
4231 rect
.SetLeft( wxMax(0, left
- extra
) );
4232 rect
.SetTop( wxMax(0, top
- extra
) );
4233 rect
.SetRight( rect
.GetRight() + 2*extra
);
4234 rect
.SetBottom( rect
.GetBottom() + 2*extra
);
4237 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4238 wxGridCellEditor
* editor
= attr
->GetEditor();
4239 if (! editor
->IsCreated()) {
4240 editor
->Create(m_gridWin
, -1,
4241 new wxGridCellEditorEvtHandler(this, editor
));
4244 editor
->SetSize( rect
);
4245 editor
->Show( TRUE
);
4246 editor
->BeginEdit(row
, col
, this, attr
);
4253 void wxGrid::HideCellEditControl()
4255 if ( IsCellEditControlEnabled() )
4257 int row
= m_currentCellCoords
.GetRow();
4258 int col
= m_currentCellCoords
.GetCol();
4260 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4261 attr
->GetEditor()->Show( FALSE
);
4263 m_gridWin
->SetFocus();
4268 void wxGrid::SetEditControlValue( const wxString
& value
)
4273 void wxGrid::SaveEditControlValue()
4275 if (IsCellEditControlEnabled()) {
4276 int row
= m_currentCellCoords
.GetRow();
4277 int col
= m_currentCellCoords
.GetCol();
4279 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4280 bool changed
= attr
->GetEditor()->EndEdit(row
, col
, TRUE
, this, attr
);
4285 SendEvent( EVT_GRID_CELL_CHANGE
,
4286 m_currentCellCoords
.GetRow(),
4287 m_currentCellCoords
.GetCol() );
4294 // ------ Grid location functions
4295 // Note that all of these functions work with the logical coordinates of
4296 // grid cells and labels so you will need to convert from device
4297 // coordinates for mouse events etc.
4300 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
4302 int row
= YToRow(y
);
4303 int col
= XToCol(x
);
4305 if ( row
== -1 || col
== -1 )
4307 coords
= wxGridNoCellCoords
;
4311 coords
.Set( row
, col
);
4316 int wxGrid::YToRow( int y
)
4320 for ( i
= 0; i
< m_numRows
; i
++ )
4322 if ( y
< m_rowBottoms
[i
] ) return i
;
4325 return m_numRows
; //-1;
4329 int wxGrid::XToCol( int x
)
4333 for ( i
= 0; i
< m_numCols
; i
++ )
4335 if ( x
< m_colRights
[i
] ) return i
;
4338 return m_numCols
; //-1;
4342 // return the row number that that the y coord is near the edge of, or
4343 // -1 if not near an edge
4345 int wxGrid::YToEdgeOfRow( int y
)
4349 for ( i
= 0; i
< m_numRows
; i
++ )
4351 if ( m_rowHeights
[i
] > WXGRID_LABEL_EDGE_ZONE
)
4353 d
= abs( y
- m_rowBottoms
[i
] );
4355 if ( d
< WXGRID_LABEL_EDGE_ZONE
) return i
;
4364 // return the col number that that the x coord is near the edge of, or
4365 // -1 if not near an edge
4367 int wxGrid::XToEdgeOfCol( int x
)
4371 for ( i
= 0; i
< m_numCols
; i
++ )
4373 if ( m_colWidths
[i
] > WXGRID_LABEL_EDGE_ZONE
)
4375 d
= abs( x
- m_colRights
[i
] );
4377 if ( d
< WXGRID_LABEL_EDGE_ZONE
) return i
;
4386 wxRect
wxGrid::CellToRect( int row
, int col
)
4388 wxRect
rect( -1, -1, -1, -1 );
4390 if ( row
>= 0 && row
< m_numRows
&&
4391 col
>= 0 && col
< m_numCols
)
4393 rect
.x
= m_colRights
[col
] - m_colWidths
[col
];
4394 rect
.y
= m_rowBottoms
[row
] - m_rowHeights
[row
];
4395 rect
.width
= m_colWidths
[col
];
4396 rect
.height
= m_rowHeights
[ row
];
4403 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
4405 // get the cell rectangle in logical coords
4407 wxRect
r( CellToRect( row
, col
) );
4409 // convert to device coords
4411 int left
, top
, right
, bottom
;
4412 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
4413 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
4415 // check against the client area of the grid window
4418 m_gridWin
->GetClientSize( &cw
, &ch
);
4420 if ( wholeCellVisible
)
4422 // is the cell wholly visible ?
4424 return ( left
>= 0 && right
<= cw
&&
4425 top
>= 0 && bottom
<= ch
);
4429 // is the cell partly visible ?
4431 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
4432 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
4437 // make the specified cell location visible by doing a minimal amount
4440 void wxGrid::MakeCellVisible( int row
, int col
)
4443 int xpos
= -1, ypos
= -1;
4445 if ( row
>= 0 && row
< m_numRows
&&
4446 col
>= 0 && col
< m_numCols
)
4448 // get the cell rectangle in logical coords
4450 wxRect
r( CellToRect( row
, col
) );
4452 // convert to device coords
4454 int left
, top
, right
, bottom
;
4455 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
4456 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
4459 m_gridWin
->GetClientSize( &cw
, &ch
);
4465 else if ( bottom
> ch
)
4467 int h
= r
.GetHeight();
4469 for ( i
= row
-1; i
>= 0; i
-- )
4471 if ( h
+ m_rowHeights
[i
] > ch
) break;
4473 h
+= m_rowHeights
[i
];
4474 ypos
-= m_rowHeights
[i
];
4477 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
4478 // have rounding errors (this is important, because if we do, we
4479 // might not scroll at all and some cells won't be redrawn)
4480 ypos
+= GRID_SCROLL_LINE
/ 2;
4487 else if ( right
> cw
)
4489 int w
= r
.GetWidth();
4491 for ( i
= col
-1; i
>= 0; i
-- )
4493 if ( w
+ m_colWidths
[i
] > cw
) break;
4495 w
+= m_colWidths
[i
];
4496 xpos
-= m_colWidths
[i
];
4499 // see comment for ypos above
4500 xpos
+= GRID_SCROLL_LINE
/ 2;
4503 if ( xpos
!= -1 || ypos
!= -1 )
4505 if ( xpos
!= -1 ) xpos
/= GRID_SCROLL_LINE
;
4506 if ( ypos
!= -1 ) ypos
/= GRID_SCROLL_LINE
;
4507 Scroll( xpos
, ypos
);
4515 // ------ Grid cursor movement functions
4518 bool wxGrid::MoveCursorUp()
4520 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
4521 m_currentCellCoords
.GetRow() > 0 )
4523 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
4524 m_currentCellCoords
.GetCol() );
4526 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
4527 m_currentCellCoords
.GetCol() );
4536 bool wxGrid::MoveCursorDown()
4538 // TODO: allow for scrolling
4540 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
4541 m_currentCellCoords
.GetRow() < m_numRows
-1 )
4543 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
4544 m_currentCellCoords
.GetCol() );
4546 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
4547 m_currentCellCoords
.GetCol() );
4556 bool wxGrid::MoveCursorLeft()
4558 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
4559 m_currentCellCoords
.GetCol() > 0 )
4561 MakeCellVisible( m_currentCellCoords
.GetRow(),
4562 m_currentCellCoords
.GetCol() - 1 );
4564 SetCurrentCell( m_currentCellCoords
.GetRow(),
4565 m_currentCellCoords
.GetCol() - 1 );
4574 bool wxGrid::MoveCursorRight()
4576 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
4577 m_currentCellCoords
.GetCol() < m_numCols
- 1 )
4579 MakeCellVisible( m_currentCellCoords
.GetRow(),
4580 m_currentCellCoords
.GetCol() + 1 );
4582 SetCurrentCell( m_currentCellCoords
.GetRow(),
4583 m_currentCellCoords
.GetCol() + 1 );
4592 bool wxGrid::MovePageUp()
4594 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
4596 int row
= m_currentCellCoords
.GetRow();
4600 m_gridWin
->GetClientSize( &cw
, &ch
);
4602 int y
= m_rowBottoms
[ row
] - m_rowHeights
[ row
];
4603 int newRow
= YToRow( y
- ch
+ 1 );
4608 else if ( newRow
== row
)
4613 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
4614 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
4622 bool wxGrid::MovePageDown()
4624 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
4626 int row
= m_currentCellCoords
.GetRow();
4627 if ( row
< m_numRows
)
4630 m_gridWin
->GetClientSize( &cw
, &ch
);
4632 int y
= m_rowBottoms
[ row
] - m_rowHeights
[ row
];
4633 int newRow
= YToRow( y
+ ch
);
4636 newRow
= m_numRows
- 1;
4638 else if ( newRow
== row
)
4643 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
4644 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
4652 bool wxGrid::MoveCursorUpBlock()
4655 m_currentCellCoords
!= wxGridNoCellCoords
&&
4656 m_currentCellCoords
.GetRow() > 0 )
4658 int row
= m_currentCellCoords
.GetRow();
4659 int col
= m_currentCellCoords
.GetCol();
4661 if ( m_table
->IsEmptyCell(row
, col
) )
4663 // starting in an empty cell: find the next block of
4669 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4672 else if ( m_table
->IsEmptyCell(row
-1, col
) )
4674 // starting at the top of a block: find the next block
4680 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4685 // starting within a block: find the top of the block
4690 if ( m_table
->IsEmptyCell(row
, col
) )
4698 MakeCellVisible( row
, col
);
4699 SetCurrentCell( row
, col
);
4707 bool wxGrid::MoveCursorDownBlock()
4710 m_currentCellCoords
!= wxGridNoCellCoords
&&
4711 m_currentCellCoords
.GetRow() < m_numRows
-1 )
4713 int row
= m_currentCellCoords
.GetRow();
4714 int col
= m_currentCellCoords
.GetCol();
4716 if ( m_table
->IsEmptyCell(row
, col
) )
4718 // starting in an empty cell: find the next block of
4721 while ( row
< m_numRows
-1 )
4724 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4727 else if ( m_table
->IsEmptyCell(row
+1, col
) )
4729 // starting at the bottom of a block: find the next block
4732 while ( row
< m_numRows
-1 )
4735 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4740 // starting within a block: find the bottom of the block
4742 while ( row
< m_numRows
-1 )
4745 if ( m_table
->IsEmptyCell(row
, col
) )
4753 MakeCellVisible( row
, col
);
4754 SetCurrentCell( row
, col
);
4762 bool wxGrid::MoveCursorLeftBlock()
4765 m_currentCellCoords
!= wxGridNoCellCoords
&&
4766 m_currentCellCoords
.GetCol() > 0 )
4768 int row
= m_currentCellCoords
.GetRow();
4769 int col
= m_currentCellCoords
.GetCol();
4771 if ( m_table
->IsEmptyCell(row
, col
) )
4773 // starting in an empty cell: find the next block of
4779 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4782 else if ( m_table
->IsEmptyCell(row
, col
-1) )
4784 // starting at the left of a block: find the next block
4790 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4795 // starting within a block: find the left of the block
4800 if ( m_table
->IsEmptyCell(row
, col
) )
4808 MakeCellVisible( row
, col
);
4809 SetCurrentCell( row
, col
);
4817 bool wxGrid::MoveCursorRightBlock()
4820 m_currentCellCoords
!= wxGridNoCellCoords
&&
4821 m_currentCellCoords
.GetCol() < m_numCols
-1 )
4823 int row
= m_currentCellCoords
.GetRow();
4824 int col
= m_currentCellCoords
.GetCol();
4826 if ( m_table
->IsEmptyCell(row
, col
) )
4828 // starting in an empty cell: find the next block of
4831 while ( col
< m_numCols
-1 )
4834 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4837 else if ( m_table
->IsEmptyCell(row
, col
+1) )
4839 // starting at the right of a block: find the next block
4842 while ( col
< m_numCols
-1 )
4845 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4850 // starting within a block: find the right of the block
4852 while ( col
< m_numCols
-1 )
4855 if ( m_table
->IsEmptyCell(row
, col
) )
4863 MakeCellVisible( row
, col
);
4864 SetCurrentCell( row
, col
);
4875 // ------ Label values and formatting
4878 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
4880 *horiz
= m_rowLabelHorizAlign
;
4881 *vert
= m_rowLabelVertAlign
;
4884 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
4886 *horiz
= m_colLabelHorizAlign
;
4887 *vert
= m_colLabelVertAlign
;
4890 wxString
wxGrid::GetRowLabelValue( int row
)
4894 return m_table
->GetRowLabelValue( row
);
4904 wxString
wxGrid::GetColLabelValue( int col
)
4908 return m_table
->GetColLabelValue( col
);
4919 void wxGrid::SetRowLabelSize( int width
)
4921 width
= wxMax( width
, 0 );
4922 if ( width
!= m_rowLabelWidth
)
4926 m_rowLabelWin
->Show( FALSE
);
4927 m_cornerLabelWin
->Show( FALSE
);
4929 else if ( m_rowLabelWidth
== 0 )
4931 m_rowLabelWin
->Show( TRUE
);
4932 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
4935 m_rowLabelWidth
= width
;
4942 void wxGrid::SetColLabelSize( int height
)
4944 height
= wxMax( height
, 0 );
4945 if ( height
!= m_colLabelHeight
)
4949 m_colLabelWin
->Show( FALSE
);
4950 m_cornerLabelWin
->Show( FALSE
);
4952 else if ( m_colLabelHeight
== 0 )
4954 m_colLabelWin
->Show( TRUE
);
4955 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
4958 m_colLabelHeight
= height
;
4965 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
4967 if ( m_labelBackgroundColour
!= colour
)
4969 m_labelBackgroundColour
= colour
;
4970 m_rowLabelWin
->SetBackgroundColour( colour
);
4971 m_colLabelWin
->SetBackgroundColour( colour
);
4972 m_cornerLabelWin
->SetBackgroundColour( colour
);
4974 if ( !GetBatchCount() )
4976 m_rowLabelWin
->Refresh();
4977 m_colLabelWin
->Refresh();
4978 m_cornerLabelWin
->Refresh();
4983 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
4985 if ( m_labelTextColour
!= colour
)
4987 m_labelTextColour
= colour
;
4988 if ( !GetBatchCount() )
4990 m_rowLabelWin
->Refresh();
4991 m_colLabelWin
->Refresh();
4996 void wxGrid::SetLabelFont( const wxFont
& font
)
4999 if ( !GetBatchCount() )
5001 m_rowLabelWin
->Refresh();
5002 m_colLabelWin
->Refresh();
5006 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
5008 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
5010 m_rowLabelHorizAlign
= horiz
;
5013 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
5015 m_rowLabelVertAlign
= vert
;
5018 if ( !GetBatchCount() )
5020 m_rowLabelWin
->Refresh();
5024 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
5026 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
5028 m_colLabelHorizAlign
= horiz
;
5031 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
5033 m_colLabelVertAlign
= vert
;
5036 if ( !GetBatchCount() )
5038 m_colLabelWin
->Refresh();
5042 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
5046 m_table
->SetRowLabelValue( row
, s
);
5047 if ( !GetBatchCount() )
5049 wxRect rect
= CellToRect( row
, 0);
5050 if ( rect
.height
> 0 )
5052 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
5054 rect
.width
= m_rowLabelWidth
;
5055 m_rowLabelWin
->Refresh( TRUE
, &rect
);
5061 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
5065 m_table
->SetColLabelValue( col
, s
);
5066 if ( !GetBatchCount() )
5068 wxRect rect
= CellToRect( 0, col
);
5069 if ( rect
.width
> 0 )
5071 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
5073 rect
.height
= m_colLabelHeight
;
5074 m_colLabelWin
->Refresh( TRUE
, &rect
);
5080 void wxGrid::SetGridLineColour( const wxColour
& colour
)
5082 if ( m_gridLineColour
!= colour
)
5084 m_gridLineColour
= colour
;
5086 wxClientDC
dc( m_gridWin
);
5088 DrawAllGridLines( dc
, wxRegion() );
5092 void wxGrid::EnableGridLines( bool enable
)
5094 if ( enable
!= m_gridLinesEnabled
)
5096 m_gridLinesEnabled
= enable
;
5098 if ( !GetBatchCount() )
5102 wxClientDC
dc( m_gridWin
);
5104 DrawAllGridLines( dc
, wxRegion() );
5108 m_gridWin
->Refresh();
5115 int wxGrid::GetDefaultRowSize()
5117 return m_defaultRowHeight
;
5120 int wxGrid::GetRowSize( int row
)
5122 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
5124 return m_rowHeights
[row
];
5127 int wxGrid::GetDefaultColSize()
5129 return m_defaultColWidth
;
5132 int wxGrid::GetColSize( int col
)
5134 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
5136 return m_colWidths
[col
];
5139 // ============================================================================
5140 // access to the grid attributes: each of them has a default value in the grid
5141 // itself and may be overidden on a per-cell basis
5142 // ============================================================================
5144 // ----------------------------------------------------------------------------
5145 // setting default attributes
5146 // ----------------------------------------------------------------------------
5148 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
5150 m_defaultCellAttr
->SetBackgroundColour(col
);
5153 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
5155 m_defaultCellAttr
->SetTextColour(col
);
5158 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
5160 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
5163 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
5165 m_defaultCellAttr
->SetFont(font
);
5168 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
5170 m_defaultCellAttr
->SetRenderer(renderer
);
5173 // ----------------------------------------------------------------------------
5174 // access to the default attrbiutes
5175 // ----------------------------------------------------------------------------
5177 wxColour
wxGrid::GetDefaultCellBackgroundColour()
5179 return m_defaultCellAttr
->GetBackgroundColour();
5182 wxColour
wxGrid::GetDefaultCellTextColour()
5184 return m_defaultCellAttr
->GetTextColour();
5187 wxFont
wxGrid::GetDefaultCellFont()
5189 return m_defaultCellAttr
->GetFont();
5192 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
5194 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
5197 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
5199 return m_defaultCellAttr
->GetRenderer();
5202 // ----------------------------------------------------------------------------
5203 // access to cell attributes
5204 // ----------------------------------------------------------------------------
5206 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
5208 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5209 wxColour colour
= attr
->GetBackgroundColour();
5214 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
5216 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5217 wxColour colour
= attr
->GetTextColour();
5222 wxFont
wxGrid::GetCellFont( int row
, int col
)
5224 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5225 wxFont font
= attr
->GetFont();
5230 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
5232 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5233 attr
->GetAlignment(horiz
, vert
);
5237 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
)
5239 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5240 wxGridCellRenderer
* renderer
= attr
->GetRenderer();
5245 // ----------------------------------------------------------------------------
5246 // attribute support: cache, automatic provider creation, ...
5247 // ----------------------------------------------------------------------------
5249 bool wxGrid::CanHaveAttributes()
5256 // RD: Maybe m_table->CanHaveAttributes() would be better in case the
5257 // table is providing the attributes itself??? In which case
5258 // I don't think the grid should create a Provider object for the
5259 // table but the table should be smart enough to do that on its own.
5260 if ( !m_table
->GetAttrProvider() )
5262 // use the default attr provider by default
5263 // (another choice would be to just return FALSE thus forcing the user
5265 m_table
->SetAttrProvider(new wxGridCellAttrProvider
);
5271 void wxGrid::ClearAttrCache()
5273 if ( m_attrCache
.row
!= -1 )
5275 m_attrCache
.attr
->SafeDecRef();
5276 m_attrCache
.row
= -1;
5280 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
5282 wxGrid
*self
= (wxGrid
*)this; // const_cast
5284 self
->ClearAttrCache();
5285 self
->m_attrCache
.row
= row
;
5286 self
->m_attrCache
.col
= col
;
5287 self
->m_attrCache
.attr
= attr
;
5291 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
5293 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
5295 *attr
= m_attrCache
.attr
;
5296 (*attr
)->SafeIncRef();
5298 #ifdef DEBUG_ATTR_CACHE
5299 gs_nAttrCacheHits
++;
5306 #ifdef DEBUG_ATTR_CACHE
5307 gs_nAttrCacheMisses
++;
5313 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
5315 wxGridCellAttr
*attr
;
5316 if ( !LookupAttr(row
, col
, &attr
) )
5318 attr
= m_table
? m_table
->GetAttr(row
, col
) : (wxGridCellAttr
*)NULL
;
5319 CacheAttr(row
, col
, attr
);
5322 attr
->SetDefAttr(m_defaultCellAttr
);
5324 attr
= m_defaultCellAttr
;
5331 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
5333 wxGridCellAttr
*attr
;
5334 if ( !LookupAttr(row
, col
, &attr
) || !attr
)
5336 wxASSERT_MSG( m_table
,
5337 _T("we may only be called if CanHaveAttributes() "
5338 "returned TRUE and then m_table should be !NULL") );
5340 attr
= m_table
->GetAttr(row
, col
);
5343 attr
= new wxGridCellAttr
;
5345 // artificially inc the ref count to match DecRef() in caller
5348 m_table
->SetAttr(attr
, row
, col
);
5351 CacheAttr(row
, col
, attr
);
5353 attr
->SetDefAttr(m_defaultCellAttr
);
5357 // ----------------------------------------------------------------------------
5358 // setting cell attributes: this is forwarded to the table
5359 // ----------------------------------------------------------------------------
5361 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
5363 if ( CanHaveAttributes() )
5365 m_table
->SetRowAttr(attr
, row
);
5373 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
5375 if ( CanHaveAttributes() )
5377 m_table
->SetColAttr(attr
, col
);
5385 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
5387 if ( CanHaveAttributes() )
5389 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5390 attr
->SetBackgroundColour(colour
);
5395 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
5397 if ( CanHaveAttributes() )
5399 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5400 attr
->SetTextColour(colour
);
5405 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
5407 if ( CanHaveAttributes() )
5409 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5410 attr
->SetFont(font
);
5415 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
5417 if ( CanHaveAttributes() )
5419 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5420 attr
->SetAlignment(horiz
, vert
);
5425 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
5427 if ( CanHaveAttributes() )
5429 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5430 attr
->SetRenderer(renderer
);
5435 // ----------------------------------------------------------------------------
5437 // ----------------------------------------------------------------------------
5439 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
5441 m_defaultRowHeight
= wxMax( height
, WXGRID_MIN_ROW_HEIGHT
);
5443 if ( resizeExistingRows
)
5447 for ( row
= 0; row
< m_numRows
; row
++ )
5449 m_rowHeights
[row
] = m_defaultRowHeight
;
5450 bottom
+= m_defaultRowHeight
;
5451 m_rowBottoms
[row
] = bottom
;
5457 void wxGrid::SetRowSize( int row
, int height
)
5459 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
5463 int h
= wxMax( 0, height
);
5464 int diff
= h
- m_rowHeights
[row
];
5466 m_rowHeights
[row
] = h
;
5467 for ( i
= row
; i
< m_numRows
; i
++ )
5469 m_rowBottoms
[i
] += diff
;
5474 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
5476 m_defaultColWidth
= wxMax( width
, WXGRID_MIN_COL_WIDTH
);
5478 if ( resizeExistingCols
)
5482 for ( col
= 0; col
< m_numCols
; col
++ )
5484 m_colWidths
[col
] = m_defaultColWidth
;
5485 right
+= m_defaultColWidth
;
5486 m_colRights
[col
] = right
;
5492 void wxGrid::SetColSize( int col
, int width
)
5494 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
5498 int w
= wxMax( 0, width
);
5499 int diff
= w
- m_colWidths
[col
];
5500 m_colWidths
[col
] = w
;
5502 for ( i
= col
; i
< m_numCols
; i
++ )
5504 m_colRights
[i
] += diff
;
5511 // ------ cell value accessor functions
5514 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
5518 m_table
->SetValue( row
, col
, s
.c_str() );
5519 if ( !GetBatchCount() )
5521 wxClientDC
dc( m_gridWin
);
5523 DrawCell( dc
, wxGridCellCoords(row
, col
) );
5526 #if 0 // TODO: edit in place
5528 if ( m_currentCellCoords
.GetRow() == row
&&
5529 m_currentCellCoords
.GetCol() == col
)
5531 SetEditControlValue( s
);
5540 // ------ Block, row and col selection
5543 void wxGrid::SelectRow( int row
, bool addToSelected
)
5547 if ( IsSelection() && addToSelected
)
5550 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
5553 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
5554 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
5555 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
5556 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
5560 need_refresh
[0] = TRUE
;
5561 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( row
, 0 ),
5562 wxGridCellCoords ( oldTop
- 1,
5564 m_selectedTopLeft
.SetRow( row
);
5569 need_refresh
[1] = TRUE
;
5570 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
, 0 ),
5571 wxGridCellCoords ( oldBottom
,
5574 m_selectedTopLeft
.SetCol( 0 );
5577 if ( oldBottom
< row
)
5579 need_refresh
[2] = TRUE
;
5580 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1, 0 ),
5581 wxGridCellCoords ( row
,
5583 m_selectedBottomRight
.SetRow( row
);
5586 if ( oldRight
< m_numCols
- 1 )
5588 need_refresh
[3] = TRUE
;
5589 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5591 wxGridCellCoords ( oldBottom
,
5593 m_selectedBottomRight
.SetCol( m_numCols
- 1 );
5596 for (i
= 0; i
< 4; i
++ )
5597 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
5598 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
5602 r
= SelectionToDeviceRect();
5604 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
5606 m_selectedTopLeft
.Set( row
, 0 );
5607 m_selectedBottomRight
.Set( row
, m_numCols
-1 );
5608 r
= SelectionToDeviceRect();
5609 m_gridWin
->Refresh( FALSE
, &r
);
5612 wxGridRangeSelectEvent
gridEvt( GetId(),
5613 EVT_GRID_RANGE_SELECT
,
5616 m_selectedBottomRight
);
5618 GetEventHandler()->ProcessEvent(gridEvt
);
5622 void wxGrid::SelectCol( int col
, bool addToSelected
)
5624 if ( IsSelection() && addToSelected
)
5627 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
5630 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
5631 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
5632 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
5633 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
5635 if ( oldLeft
> col
)
5637 need_refresh
[0] = TRUE
;
5638 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( 0, col
),
5639 wxGridCellCoords ( m_numRows
- 1,
5641 m_selectedTopLeft
.SetCol( col
);
5646 need_refresh
[1] = TRUE
;
5647 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( 0, oldLeft
),
5648 wxGridCellCoords ( oldTop
- 1,
5650 m_selectedTopLeft
.SetRow( 0 );
5653 if ( oldRight
< col
)
5655 need_refresh
[2] = TRUE
;
5656 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( 0, oldRight
+ 1 ),
5657 wxGridCellCoords ( m_numRows
- 1,
5659 m_selectedBottomRight
.SetCol( col
);
5662 if ( oldBottom
< m_numRows
- 1 )
5664 need_refresh
[3] = TRUE
;
5665 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1,
5667 wxGridCellCoords ( m_numRows
- 1,
5669 m_selectedBottomRight
.SetRow( m_numRows
- 1 );
5672 for (i
= 0; i
< 4; i
++ )
5673 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
5674 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
5680 r
= SelectionToDeviceRect();
5682 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
5684 m_selectedTopLeft
.Set( 0, col
);
5685 m_selectedBottomRight
.Set( m_numRows
-1, col
);
5686 r
= SelectionToDeviceRect();
5687 m_gridWin
->Refresh( FALSE
, &r
);
5690 wxGridRangeSelectEvent
gridEvt( GetId(),
5691 EVT_GRID_RANGE_SELECT
,
5694 m_selectedBottomRight
);
5696 GetEventHandler()->ProcessEvent(gridEvt
);
5700 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
5703 wxGridCellCoords updateTopLeft
, updateBottomRight
;
5705 if ( topRow
> bottomRow
)
5712 if ( leftCol
> rightCol
)
5719 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
5720 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
5722 if ( m_selectedTopLeft
!= updateTopLeft
||
5723 m_selectedBottomRight
!= updateBottomRight
)
5725 // Compute two optimal update rectangles:
5726 // Either one rectangle is a real subset of the
5727 // other, or they are (almost) disjoint!
5729 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
5732 // Store intermediate values
5733 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
5734 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
5735 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
5736 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
5738 // Determine the outer/inner coordinates.
5739 if (oldLeft
> leftCol
)
5745 if (oldTop
> topRow
)
5751 if (oldRight
< rightCol
)
5754 oldRight
= rightCol
;
5757 if (oldBottom
< bottomRow
)
5760 oldBottom
= bottomRow
;
5764 // Now, either the stuff marked old is the outer
5765 // rectangle or we don't have a situation where one
5766 // is contained in the other.
5768 if ( oldLeft
< leftCol
)
5770 need_refresh
[0] = TRUE
;
5771 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5773 wxGridCellCoords ( oldBottom
,
5777 if ( oldTop
< topRow
)
5779 need_refresh
[1] = TRUE
;
5780 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5782 wxGridCellCoords ( topRow
- 1,
5786 if ( oldRight
> rightCol
)
5788 need_refresh
[2] = TRUE
;
5789 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5791 wxGridCellCoords ( oldBottom
,
5795 if ( oldBottom
> bottomRow
)
5797 need_refresh
[3] = TRUE
;
5798 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
5800 wxGridCellCoords ( oldBottom
,
5806 m_selectedTopLeft
= updateTopLeft
;
5807 m_selectedBottomRight
= updateBottomRight
;
5809 // various Refresh() calls
5810 for (i
= 0; i
< 4; i
++ )
5811 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
5812 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
5815 // only generate an event if the block is not being selected by
5816 // dragging the mouse (in which case the event will be generated in
5817 // the mouse event handler)
5818 if ( !m_isDragging
)
5820 wxGridRangeSelectEvent
gridEvt( GetId(),
5821 EVT_GRID_RANGE_SELECT
,
5824 m_selectedBottomRight
);
5826 GetEventHandler()->ProcessEvent(gridEvt
);
5830 void wxGrid::SelectAll()
5832 m_selectedTopLeft
.Set( 0, 0 );
5833 m_selectedBottomRight
.Set( m_numRows
-1, m_numCols
-1 );
5835 m_gridWin
->Refresh();
5839 void wxGrid::ClearSelection()
5841 m_selectedTopLeft
= wxGridNoCellCoords
;
5842 m_selectedBottomRight
= wxGridNoCellCoords
;
5846 // This function returns the rectangle that encloses the given block
5847 // in device coords clipped to the client size of the grid window.
5849 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
5850 const wxGridCellCoords
&bottomRight
)
5852 wxRect
rect( wxGridNoCellRect
);
5855 cellRect
= CellToRect( topLeft
);
5856 if ( cellRect
!= wxGridNoCellRect
)
5862 rect
= wxRect( 0, 0, 0, 0 );
5865 cellRect
= CellToRect( bottomRight
);
5866 if ( cellRect
!= wxGridNoCellRect
)
5872 return wxGridNoCellRect
;
5875 // convert to scrolled coords
5877 int left
, top
, right
, bottom
;
5878 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
5879 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
5882 m_gridWin
->GetClientSize( &cw
, &ch
);
5884 rect
.SetLeft( wxMax(0, left
) );
5885 rect
.SetTop( wxMax(0, top
) );
5886 rect
.SetRight( wxMin(cw
, right
) );
5887 rect
.SetBottom( wxMin(ch
, bottom
) );
5895 // ------ Grid event classes
5898 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxEvent
)
5900 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
5901 int row
, int col
, int x
, int y
,
5902 bool control
, bool shift
, bool alt
, bool meta
)
5903 : wxNotifyEvent( type
, id
)
5909 m_control
= control
;
5914 SetEventObject(obj
);
5918 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxEvent
)
5920 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
5921 int rowOrCol
, int x
, int y
,
5922 bool control
, bool shift
, bool alt
, bool meta
)
5923 : wxNotifyEvent( type
, id
)
5925 m_rowOrCol
= rowOrCol
;
5928 m_control
= control
;
5933 SetEventObject(obj
);
5937 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxEvent
)
5939 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
5940 const wxGridCellCoords
& topLeft
,
5941 const wxGridCellCoords
& bottomRight
,
5942 bool control
, bool shift
, bool alt
, bool meta
)
5943 : wxNotifyEvent( type
, id
)
5945 m_topLeft
= topLeft
;
5946 m_bottomRight
= bottomRight
;
5947 m_control
= control
;
5952 SetEventObject(obj
);
5956 #endif // ifndef wxUSE_NEW_GRID