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 //////////////////////////////////////////////////////////////////////
1699 IMPLEMENT_DYNAMIC_CLASS( wxGrid
, wxScrolledWindow
)
1701 BEGIN_EVENT_TABLE( wxGrid
, wxScrolledWindow
)
1702 EVT_PAINT( wxGrid::OnPaint
)
1703 EVT_SIZE( wxGrid::OnSize
)
1704 EVT_KEY_DOWN( wxGrid::OnKeyDown
)
1705 EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground
)
1708 wxGrid::wxGrid( wxWindow
*parent
,
1713 const wxString
& name
)
1714 : wxScrolledWindow( parent
, id
, pos
, size
, style
, name
)
1723 m_defaultCellAttr
->SafeDecRef();
1725 #ifdef DEBUG_ATTR_CACHE
1726 size_t total
= gs_nAttrCacheHits
+ gs_nAttrCacheMisses
;
1727 wxPrintf(_T("wxGrid attribute cache statistics: "
1728 "total: %u, hits: %u (%u%%)\n"),
1729 total
, gs_nAttrCacheHits
,
1730 total
? (gs_nAttrCacheHits
*100) / total
: 0);
1739 // ----- internal init and update functions
1742 void wxGrid::Create()
1744 m_created
= FALSE
; // set to TRUE by CreateGrid
1745 m_displayed
= TRUE
; // FALSE; // set to TRUE by OnPaint
1747 m_table
= (wxGridTableBase
*) NULL
;
1750 m_cellEditCtrlEnabled
= FALSE
;
1752 m_defaultCellAttr
= new wxGridCellAttr
;
1753 m_defaultCellAttr
->SetDefAttr(m_defaultCellAttr
);
1754 // RD: Should we fill the default attrs now or is waiting until Init() okay?
1759 m_currentCellCoords
= wxGridNoCellCoords
;
1761 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
1762 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
1764 m_cornerLabelWin
= new wxGridCornerLabelWindow( this,
1769 m_rowLabelWin
= new wxGridRowLabelWindow( this,
1774 m_colLabelWin
= new wxGridColLabelWindow( this,
1779 m_gridWin
= new wxGridWindow( this,
1786 SetTargetWindow( m_gridWin
);
1790 bool wxGrid::CreateGrid( int numRows
, int numCols
)
1794 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
1799 m_numRows
= numRows
;
1800 m_numCols
= numCols
;
1802 m_table
= new wxGridStringTable( m_numRows
, m_numCols
);
1803 m_table
->SetView( this );
1812 bool wxGrid::SetTable( wxGridTableBase
*table
, bool takeOwnership
)
1816 wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
1821 m_numRows
= table
->GetNumberRows();
1822 m_numCols
= table
->GetNumberCols();
1825 m_table
->SetView( this );
1840 if ( m_numRows
<= 0 )
1841 m_numRows
= WXGRID_DEFAULT_NUMBER_ROWS
;
1843 if ( m_numCols
<= 0 )
1844 m_numCols
= WXGRID_DEFAULT_NUMBER_COLS
;
1846 m_rowLabelWidth
= WXGRID_DEFAULT_ROW_LABEL_WIDTH
;
1847 m_colLabelHeight
= WXGRID_DEFAULT_COL_LABEL_HEIGHT
;
1849 if ( m_rowLabelWin
)
1851 m_labelBackgroundColour
= m_rowLabelWin
->GetBackgroundColour();
1855 m_labelBackgroundColour
= wxColour( _T("WHITE") );
1858 m_labelTextColour
= wxColour( _T("BLACK") );
1861 m_attrCache
.row
= -1;
1863 // TODO: something better than this ?
1865 m_labelFont
= this->GetFont();
1866 m_labelFont
.SetWeight( m_labelFont
.GetWeight() + 2 );
1868 m_rowLabelHorizAlign
= wxLEFT
;
1869 m_rowLabelVertAlign
= wxCENTRE
;
1871 m_colLabelHorizAlign
= wxCENTRE
;
1872 m_colLabelVertAlign
= wxTOP
;
1874 m_defaultColWidth
= WXGRID_DEFAULT_COL_WIDTH
;
1875 m_defaultRowHeight
= m_gridWin
->GetCharHeight();
1877 #if defined(__WXMOTIF__) || defined(__WXGTK__) // see also text ctrl sizing in ShowCellEditControl()
1878 m_defaultRowHeight
+= 8;
1880 m_defaultRowHeight
+= 4;
1883 m_rowHeights
.Alloc( m_numRows
);
1884 m_rowBottoms
.Alloc( m_numRows
);
1886 for ( i
= 0; i
< m_numRows
; i
++ )
1888 m_rowHeights
.Add( m_defaultRowHeight
);
1889 rowBottom
+= m_defaultRowHeight
;
1890 m_rowBottoms
.Add( rowBottom
);
1893 m_colWidths
.Alloc( m_numCols
);
1894 m_colRights
.Alloc( m_numCols
);
1896 for ( i
= 0; i
< m_numCols
; i
++ )
1898 m_colWidths
.Add( m_defaultColWidth
);
1899 colRight
+= m_defaultColWidth
;
1900 m_colRights
.Add( colRight
);
1903 // Set default cell attributes
1904 m_defaultCellAttr
->SetFont(GetFont());
1905 m_defaultCellAttr
->SetAlignment(wxLEFT
, wxTOP
);
1906 m_defaultCellAttr
->SetRenderer(new wxGridCellStringRenderer
);
1907 m_defaultCellAttr
->SetEditor(new wxGridCellTextEditor
);
1908 m_defaultCellAttr
->SetTextColour(
1909 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT
));
1910 m_defaultCellAttr
->SetBackgroundColour(
1911 wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
1914 m_gridLineColour
= wxColour( 128, 128, 255 );
1915 m_gridLinesEnabled
= TRUE
;
1917 m_cursorMode
= WXGRID_CURSOR_SELECT_CELL
;
1918 m_winCapture
= (wxWindow
*)NULL
;
1920 m_dragRowOrCol
= -1;
1921 m_isDragging
= FALSE
;
1922 m_startDragPos
= wxDefaultPosition
;
1924 m_waitForSlowClick
= FALSE
;
1926 m_rowResizeCursor
= wxCursor( wxCURSOR_SIZENS
);
1927 m_colResizeCursor
= wxCursor( wxCURSOR_SIZEWE
);
1929 m_currentCellCoords
= wxGridNoCellCoords
;
1931 m_selectedTopLeft
= wxGridNoCellCoords
;
1932 m_selectedBottomRight
= wxGridNoCellCoords
;
1933 m_selectionBackground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
);
1934 m_selectionForeground
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1936 m_editable
= TRUE
; // default for whole grid
1938 m_inOnKeyDown
= FALSE
;
1944 void wxGrid::CalcDimensions()
1947 GetClientSize( &cw
, &ch
);
1949 if ( m_numRows
> 0 && m_numCols
> 0 )
1951 int right
= m_colRights
[ m_numCols
-1 ] + 50;
1952 int bottom
= m_rowBottoms
[ m_numRows
-1 ] + 50;
1954 // TODO: restore the scroll position that we had before sizing
1957 GetViewStart( &x
, &y
);
1958 SetScrollbars( GRID_SCROLL_LINE
, GRID_SCROLL_LINE
,
1959 right
/GRID_SCROLL_LINE
, bottom
/GRID_SCROLL_LINE
,
1965 void wxGrid::CalcWindowSizes()
1968 GetClientSize( &cw
, &ch
);
1970 if ( m_cornerLabelWin
->IsShown() )
1971 m_cornerLabelWin
->SetSize( 0, 0, m_rowLabelWidth
, m_colLabelHeight
);
1973 if ( m_colLabelWin
->IsShown() )
1974 m_colLabelWin
->SetSize( m_rowLabelWidth
, 0, cw
-m_rowLabelWidth
, m_colLabelHeight
);
1976 if ( m_rowLabelWin
->IsShown() )
1977 m_rowLabelWin
->SetSize( 0, m_colLabelHeight
, m_rowLabelWidth
, ch
-m_colLabelHeight
);
1979 if ( m_gridWin
->IsShown() )
1980 m_gridWin
->SetSize( m_rowLabelWidth
, m_colLabelHeight
, cw
-m_rowLabelWidth
, ch
-m_colLabelHeight
);
1984 // this is called when the grid table sends a message to say that it
1985 // has been redimensioned
1987 bool wxGrid::Redimension( wxGridTableMessage
& msg
)
1991 switch ( msg
.GetId() )
1993 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
1995 size_t pos
= msg
.GetCommandInt();
1996 int numRows
= msg
.GetCommandInt2();
1997 for ( i
= 0; i
< numRows
; i
++ )
1999 m_rowHeights
.Insert( m_defaultRowHeight
, pos
);
2000 m_rowBottoms
.Insert( 0, pos
);
2002 m_numRows
+= numRows
;
2005 if ( pos
> 0 ) bottom
= m_rowBottoms
[pos
-1];
2007 for ( i
= pos
; i
< m_numRows
; i
++ )
2009 bottom
+= m_rowHeights
[i
];
2010 m_rowBottoms
[i
] = bottom
;
2016 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
2018 int numRows
= msg
.GetCommandInt();
2019 for ( i
= 0; i
< numRows
; i
++ )
2021 m_rowHeights
.Add( m_defaultRowHeight
);
2022 m_rowBottoms
.Add( 0 );
2025 int oldNumRows
= m_numRows
;
2026 m_numRows
+= numRows
;
2029 if ( oldNumRows
> 0 ) bottom
= m_rowBottoms
[oldNumRows
-1];
2031 for ( i
= oldNumRows
; i
< m_numRows
; i
++ )
2033 bottom
+= m_rowHeights
[i
];
2034 m_rowBottoms
[i
] = bottom
;
2040 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
2042 size_t pos
= msg
.GetCommandInt();
2043 int numRows
= msg
.GetCommandInt2();
2044 for ( i
= 0; i
< numRows
; i
++ )
2046 m_rowHeights
.Remove( pos
);
2047 m_rowBottoms
.Remove( pos
);
2049 m_numRows
-= numRows
;
2054 m_colWidths
.Clear();
2055 m_colRights
.Clear();
2056 m_currentCellCoords
= wxGridNoCellCoords
;
2060 if ( m_currentCellCoords
.GetRow() >= m_numRows
)
2061 m_currentCellCoords
.Set( 0, 0 );
2064 for ( i
= 0; i
< m_numRows
; i
++ )
2066 h
+= m_rowHeights
[i
];
2067 m_rowBottoms
[i
] = h
;
2075 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
2077 size_t pos
= msg
.GetCommandInt();
2078 int numCols
= msg
.GetCommandInt2();
2079 for ( i
= 0; i
< numCols
; i
++ )
2081 m_colWidths
.Insert( m_defaultColWidth
, pos
);
2082 m_colRights
.Insert( 0, pos
);
2084 m_numCols
+= numCols
;
2087 if ( pos
> 0 ) right
= m_colRights
[pos
-1];
2089 for ( i
= pos
; i
< m_numCols
; i
++ )
2091 right
+= m_colWidths
[i
];
2092 m_colRights
[i
] = right
;
2098 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
2100 int numCols
= msg
.GetCommandInt();
2101 for ( i
= 0; i
< numCols
; i
++ )
2103 m_colWidths
.Add( m_defaultColWidth
);
2104 m_colRights
.Add( 0 );
2107 int oldNumCols
= m_numCols
;
2108 m_numCols
+= numCols
;
2111 if ( oldNumCols
> 0 ) right
= m_colRights
[oldNumCols
-1];
2113 for ( i
= oldNumCols
; i
< m_numCols
; i
++ )
2115 right
+= m_colWidths
[i
];
2116 m_colRights
[i
] = right
;
2122 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
2124 size_t pos
= msg
.GetCommandInt();
2125 int numCols
= msg
.GetCommandInt2();
2126 for ( i
= 0; i
< numCols
; i
++ )
2128 m_colWidths
.Remove( pos
);
2129 m_colRights
.Remove( pos
);
2131 m_numCols
-= numCols
;
2135 #if 0 // leave the row alone here so that AppendCols will work subsequently
2137 m_rowHeights
.Clear();
2138 m_rowBottoms
.Clear();
2140 m_currentCellCoords
= wxGridNoCellCoords
;
2144 if ( m_currentCellCoords
.GetCol() >= m_numCols
)
2145 m_currentCellCoords
.Set( 0, 0 );
2148 for ( i
= 0; i
< m_numCols
; i
++ )
2150 w
+= m_colWidths
[i
];
2163 void wxGrid::CalcRowLabelsExposed( wxRegion
& reg
)
2165 wxRegionIterator
iter( reg
);
2168 m_rowLabelsExposed
.Empty();
2175 // TODO: remove this when we can...
2176 // There is a bug in wxMotif that gives garbage update
2177 // rectangles if you jump-scroll a long way by clicking the
2178 // scrollbar with middle button. This is a work-around
2180 #if defined(__WXMOTIF__)
2182 m_gridWin
->GetClientSize( &cw
, &ch
);
2183 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
2184 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
2187 // logical bounds of update region
2190 CalcUnscrolledPosition( 0, r
.GetTop(), &dummy
, &top
);
2191 CalcUnscrolledPosition( 0, r
.GetBottom(), &dummy
, &bottom
);
2193 // find the row labels within these bounds
2197 for ( row
= 0; row
< m_numRows
; row
++ )
2199 if ( m_rowBottoms
[row
] < top
) continue;
2201 rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
2202 if ( rowTop
> bottom
) break;
2204 m_rowLabelsExposed
.Add( row
);
2212 void wxGrid::CalcColLabelsExposed( wxRegion
& reg
)
2214 wxRegionIterator
iter( reg
);
2217 m_colLabelsExposed
.Empty();
2224 // TODO: remove this when we can...
2225 // There is a bug in wxMotif that gives garbage update
2226 // rectangles if you jump-scroll a long way by clicking the
2227 // scrollbar with middle button. This is a work-around
2229 #if defined(__WXMOTIF__)
2231 m_gridWin
->GetClientSize( &cw
, &ch
);
2232 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
2233 r
.SetRight( wxMin( r
.GetRight(), cw
) );
2236 // logical bounds of update region
2239 CalcUnscrolledPosition( r
.GetLeft(), 0, &left
, &dummy
);
2240 CalcUnscrolledPosition( r
.GetRight(), 0, &right
, &dummy
);
2242 // find the cells within these bounds
2246 for ( col
= 0; col
< m_numCols
; col
++ )
2248 if ( m_colRights
[col
] < left
) continue;
2250 colLeft
= m_colRights
[col
] - m_colWidths
[col
];
2251 if ( colLeft
> right
) break;
2253 m_colLabelsExposed
.Add( col
);
2261 void wxGrid::CalcCellsExposed( wxRegion
& reg
)
2263 wxRegionIterator
iter( reg
);
2266 m_cellsExposed
.Empty();
2267 m_rowsExposed
.Empty();
2268 m_colsExposed
.Empty();
2270 int left
, top
, right
, bottom
;
2275 // TODO: remove this when we can...
2276 // There is a bug in wxMotif that gives garbage update
2277 // rectangles if you jump-scroll a long way by clicking the
2278 // scrollbar with middle button. This is a work-around
2280 #if defined(__WXMOTIF__)
2282 m_gridWin
->GetClientSize( &cw
, &ch
);
2283 if ( r
.GetTop() > ch
) r
.SetTop( 0 );
2284 if ( r
.GetLeft() > cw
) r
.SetLeft( 0 );
2285 r
.SetRight( wxMin( r
.GetRight(), cw
) );
2286 r
.SetBottom( wxMin( r
.GetBottom(), ch
) );
2289 // logical bounds of update region
2291 CalcUnscrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
2292 CalcUnscrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
2294 // find the cells within these bounds
2297 int colLeft
, rowTop
;
2298 for ( row
= 0; row
< m_numRows
; row
++ )
2300 if ( m_rowBottoms
[row
] <= top
) continue;
2302 rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
2303 if ( rowTop
> bottom
) break;
2305 m_rowsExposed
.Add( row
);
2307 for ( col
= 0; col
< m_numCols
; col
++ )
2309 if ( m_colRights
[col
] <= left
) continue;
2311 colLeft
= m_colRights
[col
] - m_colWidths
[col
];
2312 if ( colLeft
> right
) break;
2314 if ( m_colsExposed
.Index( col
) == wxNOT_FOUND
) m_colsExposed
.Add( col
);
2315 m_cellsExposed
.Add( wxGridCellCoords( row
, col
) );
2324 void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent
& event
)
2327 wxPoint
pos( event
.GetPosition() );
2328 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2330 if ( event
.Dragging() )
2332 m_isDragging
= TRUE
;
2334 if ( event
.LeftIsDown() )
2336 switch( m_cursorMode
)
2338 case WXGRID_CURSOR_RESIZE_ROW
:
2340 int cw
, ch
, left
, dummy
;
2341 m_gridWin
->GetClientSize( &cw
, &ch
);
2342 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
2344 wxClientDC
dc( m_gridWin
);
2347 m_rowBottoms
[m_dragRowOrCol
] -
2348 m_rowHeights
[m_dragRowOrCol
] +
2349 WXGRID_MIN_ROW_HEIGHT
);
2350 dc
.SetLogicalFunction(wxINVERT
);
2351 if ( m_dragLastPos
>= 0 )
2353 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
2355 dc
.DrawLine( left
, y
, left
+cw
, y
);
2360 case WXGRID_CURSOR_SELECT_ROW
:
2361 if ( (row
= YToRow( y
)) >= 0 &&
2362 !IsInSelection( row
, 0 ) )
2364 SelectRow( row
, TRUE
);
2367 // default label to suppress warnings about "enumeration value
2368 // 'xxx' not handled in switch
2376 m_isDragging
= FALSE
;
2379 // ------------ Entering or leaving the window
2381 if ( event
.Entering() || event
.Leaving() )
2383 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
2387 // ------------ Left button pressed
2389 else if ( event
.LeftDown() )
2391 // don't send a label click event for a hit on the
2392 // edge of the row label - this is probably the user
2393 // wanting to resize the row
2395 if ( YToEdgeOfRow(y
) < 0 )
2399 !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, row
, -1, event
) )
2401 SelectRow( row
, event
.ShiftDown() );
2402 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW
, m_rowLabelWin
);
2407 // starting to drag-resize a row
2409 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
);
2414 // ------------ Left double click
2416 else if (event
.LeftDClick() )
2418 if ( YToEdgeOfRow(y
) < 0 )
2421 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, row
, -1, event
);
2426 // ------------ Left button released
2428 else if ( event
.LeftUp() )
2430 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
2432 DoEndDragResizeRow();
2434 // Note: we are ending the event *after* doing
2435 // default processing in this case
2437 SendEvent( EVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
2440 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
);
2445 // ------------ Right button down
2447 else if ( event
.RightDown() )
2450 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, row
, -1, event
) )
2452 // no default action at the moment
2457 // ------------ Right double click
2459 else if ( event
.RightDClick() )
2462 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, row
, -1, event
) )
2464 // no default action at the moment
2469 // ------------ No buttons down and mouse moving
2471 else if ( event
.Moving() )
2473 m_dragRowOrCol
= YToEdgeOfRow( y
);
2474 if ( m_dragRowOrCol
>= 0 )
2476 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2478 // don't capture the mouse yet
2479 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
, m_rowLabelWin
, FALSE
);
2482 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
2484 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_rowLabelWin
, FALSE
);
2490 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent
& event
)
2493 wxPoint
pos( event
.GetPosition() );
2494 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2496 if ( event
.Dragging() )
2498 m_isDragging
= TRUE
;
2500 if ( event
.LeftIsDown() )
2502 switch( m_cursorMode
)
2504 case WXGRID_CURSOR_RESIZE_COL
:
2506 int cw
, ch
, dummy
, top
;
2507 m_gridWin
->GetClientSize( &cw
, &ch
);
2508 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
2510 wxClientDC
dc( m_gridWin
);
2513 m_colRights
[m_dragRowOrCol
] -
2514 m_colWidths
[m_dragRowOrCol
] +
2515 WXGRID_MIN_COL_WIDTH
);
2516 dc
.SetLogicalFunction(wxINVERT
);
2517 if ( m_dragLastPos
>= 0 )
2519 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
2521 dc
.DrawLine( x
, top
, x
, top
+ch
);
2526 case WXGRID_CURSOR_SELECT_COL
:
2527 if ( (col
= XToCol( x
)) >= 0 &&
2528 !IsInSelection( 0, col
) )
2530 SelectCol( col
, TRUE
);
2533 // default label to suppress warnings about "enumeration value
2534 // 'xxx' not handled in switch
2542 m_isDragging
= FALSE
;
2545 // ------------ Entering or leaving the window
2547 if ( event
.Entering() || event
.Leaving() )
2549 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
2553 // ------------ Left button pressed
2555 else if ( event
.LeftDown() )
2557 // don't send a label click event for a hit on the
2558 // edge of the col label - this is probably the user
2559 // wanting to resize the col
2561 if ( XToEdgeOfCol(x
) < 0 )
2565 !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, -1, col
, event
) )
2567 SelectCol( col
, event
.ShiftDown() );
2568 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL
, m_colLabelWin
);
2573 // starting to drag-resize a col
2575 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
);
2580 // ------------ Left double click
2582 if ( event
.LeftDClick() )
2584 if ( XToEdgeOfCol(x
) < 0 )
2587 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, -1, col
, event
);
2592 // ------------ Left button released
2594 else if ( event
.LeftUp() )
2596 if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
2598 DoEndDragResizeCol();
2600 // Note: we are ending the event *after* doing
2601 // default processing in this case
2603 SendEvent( EVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
2606 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
);
2611 // ------------ Right button down
2613 else if ( event
.RightDown() )
2616 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, -1, col
, event
) )
2618 // no default action at the moment
2623 // ------------ Right double click
2625 else if ( event
.RightDClick() )
2628 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, -1, col
, event
) )
2630 // no default action at the moment
2635 // ------------ No buttons down and mouse moving
2637 else if ( event
.Moving() )
2639 m_dragRowOrCol
= XToEdgeOfCol( x
);
2640 if ( m_dragRowOrCol
>= 0 )
2642 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2644 // don't capture the cursor yet
2645 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
, m_colLabelWin
, FALSE
);
2648 else if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
2650 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
, m_colLabelWin
, FALSE
);
2656 void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent
& event
)
2658 if ( event
.LeftDown() )
2660 // indicate corner label by having both row and
2663 if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK
, -1, -1, event
) )
2669 else if ( event
.LeftDClick() )
2671 SendEvent( EVT_GRID_LABEL_LEFT_DCLICK
, -1, -1, event
);
2674 else if ( event
.RightDown() )
2676 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK
, -1, -1, event
) )
2678 // no default action at the moment
2682 else if ( event
.RightDClick() )
2684 if ( !SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK
, -1, -1, event
) )
2686 // no default action at the moment
2691 void wxGrid::ChangeCursorMode(CursorMode mode
,
2696 static const wxChar
*cursorModes
[] =
2705 wxLogTrace(_T("grid"),
2706 _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
2707 win
== m_colLabelWin
? _T("colLabelWin")
2708 : win
? _T("rowLabelWin")
2710 cursorModes
[m_cursorMode
], cursorModes
[mode
]);
2711 #endif // __WXDEBUG__
2713 if ( mode
== m_cursorMode
)
2718 // by default use the grid itself
2724 m_winCapture
->ReleaseMouse();
2725 m_winCapture
= (wxWindow
*)NULL
;
2728 m_cursorMode
= mode
;
2730 switch ( m_cursorMode
)
2732 case WXGRID_CURSOR_RESIZE_ROW
:
2733 win
->SetCursor( m_rowResizeCursor
);
2736 case WXGRID_CURSOR_RESIZE_COL
:
2737 win
->SetCursor( m_colResizeCursor
);
2741 win
->SetCursor( *wxSTANDARD_CURSOR
);
2744 // we need to capture mouse when resizing
2745 bool resize
= m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
||
2746 m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
;
2748 if ( captureMouse
&& resize
)
2750 win
->CaptureMouse();
2755 void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent
& event
)
2758 wxPoint
pos( event
.GetPosition() );
2759 CalcUnscrolledPosition( pos
.x
, pos
.y
, &x
, &y
);
2761 wxGridCellCoords coords
;
2762 XYToCell( x
, y
, coords
);
2764 if ( event
.Dragging() )
2766 //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
2768 // Don't start doing anything until the mouse has been drug at
2769 // least 3 pixels in any direction...
2770 if (! m_isDragging
) {
2771 if (m_startDragPos
== wxDefaultPosition
) {
2772 m_startDragPos
= pos
;
2775 if (abs(m_startDragPos
.x
- pos
.x
) < 4 && abs(m_startDragPos
.y
- pos
.y
) < 4)
2779 m_isDragging
= TRUE
;
2780 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2782 // Hide the edit control, so it
2783 // won't interfer with drag-shrinking.
2784 if ( IsCellEditControlEnabled() )
2785 HideCellEditControl();
2787 // Have we captured the mouse yet?
2788 if (! m_winCapture
) {
2789 m_winCapture
= m_gridWin
;
2790 m_winCapture
->CaptureMouse();
2793 if ( coords
!= wxGridNoCellCoords
)
2795 if ( !IsSelection() )
2797 SelectBlock( coords
, coords
);
2801 SelectBlock( m_currentCellCoords
, coords
);
2804 if (! IsVisible(coords
)) {
2805 MakeCellVisible(coords
);
2806 // TODO: need to introduce a delay or something here. The
2807 // scrolling is way to fast, at least on MSW.
2811 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
2813 int cw
, ch
, left
, dummy
;
2814 m_gridWin
->GetClientSize( &cw
, &ch
);
2815 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
2817 wxClientDC
dc( m_gridWin
);
2820 m_rowBottoms
[m_dragRowOrCol
] -
2821 m_rowHeights
[m_dragRowOrCol
] +
2822 WXGRID_MIN_ROW_HEIGHT
);
2823 dc
.SetLogicalFunction(wxINVERT
);
2824 if ( m_dragLastPos
>= 0 )
2826 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
2828 dc
.DrawLine( left
, y
, left
+cw
, y
);
2831 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
2833 int cw
, ch
, dummy
, top
;
2834 m_gridWin
->GetClientSize( &cw
, &ch
);
2835 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
2837 wxClientDC
dc( m_gridWin
);
2840 m_colRights
[m_dragRowOrCol
] -
2841 m_colWidths
[m_dragRowOrCol
] + WXGRID_MIN_COL_WIDTH
);
2842 dc
.SetLogicalFunction(wxINVERT
);
2843 if ( m_dragLastPos
>= 0 )
2845 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
2847 dc
.DrawLine( x
, top
, x
, top
+ch
);
2854 m_isDragging
= FALSE
;
2855 m_startDragPos
= wxDefaultPosition
;
2858 if ( coords
!= wxGridNoCellCoords
)
2860 // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
2861 // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
2864 if ( event
.Entering() || event
.Leaving() )
2866 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
2867 m_gridWin
->SetCursor( *wxSTANDARD_CURSOR
);
2872 // ------------ Left button pressed
2874 if ( event
.LeftDown() )
2876 EnableCellEditControl( FALSE
);
2877 if ( event
.ShiftDown() )
2879 SelectBlock( m_currentCellCoords
, coords
);
2881 else if ( XToEdgeOfCol(x
) < 0 &&
2882 YToEdgeOfRow(y
) < 0 )
2884 if ( !SendEvent( EVT_GRID_CELL_LEFT_CLICK
,
2889 MakeCellVisible( coords
);
2891 // if this is the second click on this cell then start
2893 if (m_waitForSlowClick
&& coords
== m_currentCellCoords
) {
2894 EnableCellEditControl(TRUE
);
2895 ShowCellEditControl();
2896 m_waitForSlowClick
= FALSE
;
2899 SetCurrentCell( coords
);
2900 m_waitForSlowClick
= TRUE
;
2907 // ------------ Left double click
2909 else if ( event
.LeftDClick() )
2911 EnableCellEditControl( FALSE
);
2912 if ( XToEdgeOfCol(x
) < 0 && YToEdgeOfRow(y
) < 0 )
2914 SendEvent( EVT_GRID_CELL_LEFT_DCLICK
,
2922 // ------------ Left button released
2924 else if ( event
.LeftUp() )
2926 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
2928 if ( IsSelection() )
2931 m_winCapture
->ReleaseMouse();
2932 m_winCapture
= NULL
;
2934 SendEvent( EVT_GRID_RANGE_SELECT
, -1, -1, event
);
2937 // Show the edit control, if it has
2938 // been hidden for drag-shrinking.
2939 if ( IsCellEditControlEnabled() )
2940 ShowCellEditControl();
2942 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_ROW
)
2944 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
2945 DoEndDragResizeRow();
2947 // Note: we are ending the event *after* doing
2948 // default processing in this case
2950 SendEvent( EVT_GRID_ROW_SIZE
, m_dragRowOrCol
, -1, event
);
2952 else if ( m_cursorMode
== WXGRID_CURSOR_RESIZE_COL
)
2954 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
2955 DoEndDragResizeCol();
2957 // Note: we are ending the event *after* doing
2958 // default processing in this case
2960 SendEvent( EVT_GRID_COL_SIZE
, -1, m_dragRowOrCol
, event
);
2967 // ------------ Right button down
2969 else if ( event
.RightDown() )
2971 EnableCellEditControl( FALSE
);
2972 if ( !SendEvent( EVT_GRID_CELL_RIGHT_CLICK
,
2977 // no default action at the moment
2982 // ------------ Right double click
2984 else if ( event
.RightDClick() )
2986 EnableCellEditControl( FALSE
);
2987 if ( !SendEvent( EVT_GRID_CELL_RIGHT_DCLICK
,
2992 // no default action at the moment
2996 // ------------ Moving and no button action
2998 else if ( event
.Moving() && !event
.IsButton() )
3000 int dragRow
= YToEdgeOfRow( y
);
3001 int dragCol
= XToEdgeOfCol( x
);
3003 // Dragging on the corner of a cell to resize in both
3004 // directions is not implemented yet...
3006 if ( dragRow
>= 0 && dragCol
>= 0 )
3008 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3014 m_dragRowOrCol
= dragRow
;
3016 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3018 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW
);
3026 m_dragRowOrCol
= dragCol
;
3028 if ( m_cursorMode
== WXGRID_CURSOR_SELECT_CELL
)
3030 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL
);
3036 // Neither on a row or col edge
3038 if ( m_cursorMode
!= WXGRID_CURSOR_SELECT_CELL
)
3040 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL
);
3047 void wxGrid::DoEndDragResizeRow()
3049 if ( m_dragLastPos
>= 0 )
3051 // erase the last line and resize the row
3053 int cw
, ch
, left
, dummy
;
3054 m_gridWin
->GetClientSize( &cw
, &ch
);
3055 CalcUnscrolledPosition( 0, 0, &left
, &dummy
);
3057 wxClientDC
dc( m_gridWin
);
3059 dc
.SetLogicalFunction( wxINVERT
);
3060 dc
.DrawLine( left
, m_dragLastPos
, left
+cw
, m_dragLastPos
);
3061 HideCellEditControl();
3063 int rowTop
= m_rowBottoms
[m_dragRowOrCol
] - m_rowHeights
[m_dragRowOrCol
];
3064 SetRowSize( m_dragRowOrCol
,
3065 wxMax( m_dragLastPos
- rowTop
, WXGRID_MIN_ROW_HEIGHT
) );
3067 if ( !GetBatchCount() )
3069 // Only needed to get the correct rect.y:
3070 wxRect
rect ( CellToRect( m_dragRowOrCol
, 0 ) );
3072 CalcScrolledPosition(0, rect
.y
, &dummy
, &rect
.y
);
3073 rect
.width
= m_rowLabelWidth
;
3074 rect
.height
= ch
- rect
.y
;
3075 m_rowLabelWin
->Refresh( TRUE
, &rect
);
3077 m_gridWin
->Refresh( FALSE
, &rect
);
3080 ShowCellEditControl();
3085 void wxGrid::DoEndDragResizeCol()
3087 if ( m_dragLastPos
>= 0 )
3089 // erase the last line and resize the col
3091 int cw
, ch
, dummy
, top
;
3092 m_gridWin
->GetClientSize( &cw
, &ch
);
3093 CalcUnscrolledPosition( 0, 0, &dummy
, &top
);
3095 wxClientDC
dc( m_gridWin
);
3097 dc
.SetLogicalFunction( wxINVERT
);
3098 dc
.DrawLine( m_dragLastPos
, top
, m_dragLastPos
, top
+ch
);
3099 HideCellEditControl();
3101 int colLeft
= m_colRights
[m_dragRowOrCol
] - m_colWidths
[m_dragRowOrCol
];
3102 SetColSize( m_dragRowOrCol
,
3103 wxMax( m_dragLastPos
- colLeft
, WXGRID_MIN_COL_WIDTH
) );
3105 if ( !GetBatchCount() )
3107 // Only needed to get the correct rect.x:
3108 wxRect
rect ( CellToRect( 0, m_dragRowOrCol
) );
3110 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &dummy
);
3111 rect
.width
= cw
- rect
.x
;
3112 rect
.height
= m_colLabelHeight
;
3113 m_colLabelWin
->Refresh( TRUE
, &rect
);
3115 m_gridWin
->Refresh( FALSE
, &rect
);
3118 ShowCellEditControl();
3125 // ------ interaction with data model
3127 bool wxGrid::ProcessTableMessage( wxGridTableMessage
& msg
)
3129 switch ( msg
.GetId() )
3131 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
:
3132 return GetModelValues();
3134 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
:
3135 return SetModelValues();
3137 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED
:
3138 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED
:
3139 case wxGRIDTABLE_NOTIFY_ROWS_DELETED
:
3140 case wxGRIDTABLE_NOTIFY_COLS_INSERTED
:
3141 case wxGRIDTABLE_NOTIFY_COLS_APPENDED
:
3142 case wxGRIDTABLE_NOTIFY_COLS_DELETED
:
3143 return Redimension( msg
);
3152 // The behaviour of this function depends on the grid table class
3153 // Clear() function. For the default wxGridStringTable class the
3154 // behavious is to replace all cell contents with wxEmptyString but
3155 // not to change the number of rows or cols.
3157 void wxGrid::ClearGrid()
3162 SetEditControlValue();
3163 if ( !GetBatchCount() ) m_gridWin
->Refresh();
3168 bool wxGrid::InsertRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
3170 // TODO: something with updateLabels flag
3174 wxFAIL_MSG( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
3180 bool ok
= m_table
->InsertRows( pos
, numRows
);
3182 // the table will have sent the results of the insert row
3183 // operation to this view object as a grid table message
3187 if ( m_numCols
== 0 )
3189 m_table
->AppendCols( WXGRID_DEFAULT_NUMBER_COLS
);
3191 // TODO: perhaps instead of appending the default number of cols
3192 // we should remember what the last non-zero number of cols was ?
3196 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3198 // if we have just inserted cols into an empty grid the current
3199 // cell will be undefined...
3201 SetCurrentCell( 0, 0 );
3205 if ( !GetBatchCount() ) Refresh();
3208 SetEditControlValue();
3218 bool wxGrid::AppendRows( int numRows
, bool WXUNUSED(updateLabels
) )
3220 // TODO: something with updateLabels flag
3224 wxFAIL_MSG( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
3228 if ( m_table
&& m_table
->AppendRows( numRows
) )
3230 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3232 // if we have just inserted cols into an empty grid the current
3233 // cell will be undefined...
3235 SetCurrentCell( 0, 0 );
3238 // the table will have sent the results of the append row
3239 // operation to this view object as a grid table message
3242 if ( !GetBatchCount() ) Refresh();
3252 bool wxGrid::DeleteRows( int pos
, int numRows
, bool WXUNUSED(updateLabels
) )
3254 // TODO: something with updateLabels flag
3258 wxFAIL_MSG( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
3262 if ( m_table
&& m_table
->DeleteRows( pos
, numRows
) )
3264 // the table will have sent the results of the delete row
3265 // operation to this view object as a grid table message
3267 if ( m_numRows
> 0 )
3268 SetEditControlValue();
3270 HideCellEditControl();
3273 if ( !GetBatchCount() ) Refresh();
3283 bool wxGrid::InsertCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
3285 // TODO: something with updateLabels flag
3289 wxFAIL_MSG( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
3295 HideCellEditControl();
3296 bool ok
= m_table
->InsertCols( pos
, numCols
);
3298 // the table will have sent the results of the insert col
3299 // operation to this view object as a grid table message
3303 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3305 // if we have just inserted cols into an empty grid the current
3306 // cell will be undefined...
3308 SetCurrentCell( 0, 0 );
3312 if ( !GetBatchCount() ) Refresh();
3315 SetEditControlValue();
3325 bool wxGrid::AppendCols( int numCols
, bool WXUNUSED(updateLabels
) )
3327 // TODO: something with updateLabels flag
3331 wxFAIL_MSG( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
3335 if ( m_table
&& m_table
->AppendCols( numCols
) )
3337 // the table will have sent the results of the append col
3338 // operation to this view object as a grid table message
3340 if ( m_currentCellCoords
== wxGridNoCellCoords
)
3342 // if we have just inserted cols into an empty grid the current
3343 // cell will be undefined...
3345 SetCurrentCell( 0, 0 );
3349 if ( !GetBatchCount() ) Refresh();
3359 bool wxGrid::DeleteCols( int pos
, int numCols
, bool WXUNUSED(updateLabels
) )
3361 // TODO: something with updateLabels flag
3365 wxFAIL_MSG( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
3369 if ( m_table
&& m_table
->DeleteCols( pos
, numCols
) )
3371 // the table will have sent the results of the delete col
3372 // operation to this view object as a grid table message
3374 if ( m_numCols
> 0 )
3375 SetEditControlValue();
3377 HideCellEditControl();
3380 if ( !GetBatchCount() ) Refresh();
3392 // ----- event handlers
3395 // Generate a grid event based on a mouse event and
3396 // return the result of ProcessEvent()
3398 bool wxGrid::SendEvent( const wxEventType type
,
3400 wxMouseEvent
& mouseEv
)
3402 if ( type
== EVT_GRID_ROW_SIZE
||
3403 type
== EVT_GRID_COL_SIZE
)
3405 int rowOrCol
= (row
== -1 ? col
: row
);
3407 wxGridSizeEvent
gridEvt( GetId(),
3411 mouseEv
.GetX(), mouseEv
.GetY(),
3412 mouseEv
.ControlDown(),
3413 mouseEv
.ShiftDown(),
3415 mouseEv
.MetaDown() );
3417 return GetEventHandler()->ProcessEvent(gridEvt
);
3419 else if ( type
== EVT_GRID_RANGE_SELECT
)
3421 wxGridRangeSelectEvent
gridEvt( GetId(),
3425 m_selectedBottomRight
,
3426 mouseEv
.ControlDown(),
3427 mouseEv
.ShiftDown(),
3429 mouseEv
.MetaDown() );
3431 return GetEventHandler()->ProcessEvent(gridEvt
);
3435 wxGridEvent
gridEvt( GetId(),
3439 mouseEv
.GetX(), mouseEv
.GetY(),
3440 mouseEv
.ControlDown(),
3441 mouseEv
.ShiftDown(),
3443 mouseEv
.MetaDown() );
3445 return GetEventHandler()->ProcessEvent(gridEvt
);
3450 // Generate a grid event of specified type and return the result
3451 // of ProcessEvent().
3453 bool wxGrid::SendEvent( const wxEventType type
,
3456 if ( type
== EVT_GRID_ROW_SIZE
||
3457 type
== EVT_GRID_COL_SIZE
)
3459 int rowOrCol
= (row
== -1 ? col
: row
);
3461 wxGridSizeEvent
gridEvt( GetId(),
3466 return GetEventHandler()->ProcessEvent(gridEvt
);
3470 wxGridEvent
gridEvt( GetId(),
3475 return GetEventHandler()->ProcessEvent(gridEvt
);
3480 void wxGrid::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
3482 wxPaintDC
dc( this );
3484 if ( m_currentCellCoords
== wxGridNoCellCoords
&&
3485 m_numRows
&& m_numCols
)
3487 m_currentCellCoords
.Set(0, 0);
3488 SetEditControlValue();
3489 ShowCellEditControl();
3496 // This is just here to make sure that CalcDimensions gets called when
3497 // the grid view is resized... then the size event is skipped to allow
3498 // the box sizers to handle everything
3500 void wxGrid::OnSize( wxSizeEvent
& event
)
3507 void wxGrid::OnKeyDown( wxKeyEvent
& event
)
3509 if ( m_inOnKeyDown
)
3511 // shouldn't be here - we are going round in circles...
3513 wxFAIL_MSG( wxT("wxGrid::OnKeyDown called while already active") );
3516 m_inOnKeyDown
= TRUE
;
3518 // propagate the event up and see if it gets processed
3520 wxWindow
*parent
= GetParent();
3521 wxKeyEvent
keyEvt( event
);
3522 keyEvt
.SetEventObject( parent
);
3524 if ( !parent
->GetEventHandler()->ProcessEvent( keyEvt
) )
3526 // try local handlers
3528 switch ( event
.KeyCode() )
3531 if ( event
.ControlDown() )
3533 MoveCursorUpBlock();
3542 if ( event
.ControlDown() )
3544 MoveCursorDownBlock();
3553 if ( event
.ControlDown() )
3555 MoveCursorLeftBlock();
3564 if ( event
.ControlDown() )
3566 MoveCursorRightBlock();
3575 if ( event
.ControlDown() )
3577 event
.Skip(); // to let the edit control have the return
3586 if (event
.ShiftDown())
3593 if ( event
.ControlDown() )
3595 MakeCellVisible( 0, 0 );
3596 SetCurrentCell( 0, 0 );
3605 if ( event
.ControlDown() )
3607 MakeCellVisible( m_numRows
-1, m_numCols
-1 );
3608 SetCurrentCell( m_numRows
-1, m_numCols
-1 );
3624 // We don't want these keys to trigger the edit control, any others?
3633 if ( !IsEditable() )
3638 // Otherwise fall through to default
3641 // now try the cell edit control
3643 if ( !IsCellEditControlEnabled() )
3644 EnableCellEditControl( TRUE
);
3645 if (IsCellEditControlEnabled()) {
3646 wxGridCellAttr
* attr
= GetCellAttr(m_currentCellCoords
);
3647 attr
->GetEditor()->StartingKey(event
);
3654 m_inOnKeyDown
= FALSE
;
3658 void wxGrid::OnEraseBackground(wxEraseEvent
&)
3664 void wxGrid::SetCurrentCell( const wxGridCellCoords
& coords
)
3666 if ( SendEvent( EVT_GRID_SELECT_CELL
, coords
.GetRow(), coords
.GetCol() ) )
3668 // the event has been intercepted - do nothing
3673 m_currentCellCoords
!= wxGridNoCellCoords
)
3675 HideCellEditControl();
3676 SaveEditControlValue();
3677 EnableCellEditControl(FALSE
);
3679 // Clear the old current cell highlight
3680 wxRect r
= BlockToDeviceRect(m_currentCellCoords
, m_currentCellCoords
);
3681 m_currentCellCoords
= coords
; // Otherwise refresh redraws the hilit!
3682 m_gridWin
->Refresh( FALSE
, &r
);
3685 m_currentCellCoords
= coords
;
3687 SetEditControlValue();
3692 ShowCellEditControl();
3694 wxClientDC
dc(m_gridWin
);
3696 DrawCellHighlight(dc
);
3699 if ( IsSelection() )
3701 wxRect
r( SelectionToDeviceRect() );
3703 if ( !GetBatchCount() ) m_gridWin
->Refresh( FALSE
, &r
);
3710 // ------ functions to get/send data (see also public functions)
3713 bool wxGrid::GetModelValues()
3717 // all we need to do is repaint the grid
3719 m_gridWin
->Refresh();
3727 bool wxGrid::SetModelValues()
3733 for ( row
= 0; row
< m_numRows
; row
++ )
3735 for ( col
= 0; col
< m_numCols
; col
++ )
3737 m_table
->SetValue( row
, col
, GetCellValue(row
, col
) );
3749 // Note - this function only draws cells that are in the list of
3750 // exposed cells (usually set from the update region by
3751 // CalcExposedCells)
3753 void wxGrid::DrawGridCellArea( wxDC
& dc
)
3755 if ( !m_numRows
|| !m_numCols
) return;
3758 size_t numCells
= m_cellsExposed
.GetCount();
3760 for ( i
= 0; i
< numCells
; i
++ )
3762 DrawCell( dc
, m_cellsExposed
[i
] );
3767 void wxGrid::DrawCell( wxDC
& dc
, const wxGridCellCoords
& coords
)
3769 int row
= coords
.GetRow();
3770 int col
= coords
.GetCol();
3772 if ( m_colWidths
[col
] <= 0 || m_rowHeights
[row
] <= 0 )
3775 // we draw the cell border ourselves
3776 #if !WXGRID_DRAW_LINES
3777 if ( m_gridLinesEnabled
)
3778 DrawCellBorder( dc
, coords
);
3781 // but all the rest is drawn by the cell renderer and hence may be
3784 rect
.x
= m_colRights
[col
] - m_colWidths
[col
];
3785 rect
.y
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3786 rect
.width
= m_colWidths
[col
];
3787 rect
.height
= m_rowHeights
[row
];
3789 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
3790 attr
->GetRenderer()->Draw(*this, *attr
, dc
, rect
, row
, col
, IsInSelection(coords
));
3793 if (m_currentCellCoords
== coords
)
3794 DrawCellHighlight(dc
);
3798 void wxGrid::DrawCellHighlight( wxDC
& dc
)
3800 int row
= m_currentCellCoords
.GetRow();
3801 int col
= m_currentCellCoords
.GetCol();
3803 if ( m_colWidths
[col
] <= 0 || m_rowHeights
[row
] <= 0 )
3807 rect
.x
= m_colRights
[col
] - m_colWidths
[col
];
3808 rect
.y
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3809 rect
.width
= m_colWidths
[col
] - 1;
3810 rect
.height
= m_rowHeights
[row
] - 1;
3812 dc
.SetPen(wxPen(m_gridLineColour
, 3, wxSOLID
));
3813 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
3814 //dc.SetLogicalFunction(wxINVERT);
3816 dc
.DrawRectangle(rect
);
3819 void wxGrid::DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& coords
)
3821 if ( m_colWidths
[coords
.GetCol()] <=0 ||
3822 m_rowHeights
[coords
.GetRow()] <= 0 ) return;
3824 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
3825 int row
= coords
.GetRow();
3826 int col
= coords
.GetCol();
3828 // right hand border
3830 dc
.DrawLine( m_colRights
[col
], m_rowBottoms
[row
] - m_rowHeights
[row
],
3831 m_colRights
[col
], m_rowBottoms
[row
] );
3835 dc
.DrawLine( m_colRights
[col
] - m_colWidths
[col
], m_rowBottoms
[row
],
3836 m_colRights
[col
], m_rowBottoms
[row
] );
3840 // TODO: remove this ???
3841 // This is used to redraw all grid lines e.g. when the grid line colour
3844 void wxGrid::DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
)
3846 if ( !m_gridLinesEnabled
||
3848 !m_numCols
) return;
3850 int top
, bottom
, left
, right
;
3854 m_gridWin
->GetClientSize(&cw
, &ch
);
3856 // virtual coords of visible area
3858 CalcUnscrolledPosition( 0, 0, &left
, &top
);
3859 CalcUnscrolledPosition( cw
, ch
, &right
, &bottom
);
3863 reg
.GetBox(x
, y
, w
, h
);
3864 CalcUnscrolledPosition( x
, y
, &left
, &top
);
3865 CalcUnscrolledPosition( x
+ w
, y
+ h
, &right
, &bottom
);
3868 // avoid drawing grid lines past the last row and col
3870 right
= wxMin( right
, m_colRights
[m_numCols
-1] );
3871 bottom
= wxMin( bottom
, m_rowBottoms
[m_numRows
-1] );
3873 dc
.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID
) );
3875 // horizontal grid lines
3878 for ( i
= 0; i
< m_numRows
; i
++ )
3880 if ( m_rowBottoms
[i
]-1 > bottom
)
3884 else if ( m_rowBottoms
[i
]-1 >= top
)
3886 dc
.DrawLine( left
, m_rowBottoms
[i
]-1, right
, m_rowBottoms
[i
]-1 );
3891 // vertical grid lines
3893 for ( i
= 0; i
< m_numCols
; i
++ )
3895 if ( m_colRights
[i
]-1 > right
)
3899 else if ( m_colRights
[i
]-1 >= left
)
3901 dc
.DrawLine( m_colRights
[i
]-1, top
, m_colRights
[i
]-1, bottom
);
3907 void wxGrid::DrawRowLabels( wxDC
& dc
)
3909 if ( !m_numRows
|| !m_numCols
) return;
3912 size_t numLabels
= m_rowLabelsExposed
.GetCount();
3914 for ( i
= 0; i
< numLabels
; i
++ )
3916 DrawRowLabel( dc
, m_rowLabelsExposed
[i
] );
3921 void wxGrid::DrawRowLabel( wxDC
& dc
, int row
)
3923 if ( m_rowHeights
[row
] <= 0 ) return;
3925 int rowTop
= m_rowBottoms
[row
] - m_rowHeights
[row
];
3927 dc
.SetPen( *wxBLACK_PEN
);
3928 dc
.DrawLine( m_rowLabelWidth
-1, rowTop
,
3929 m_rowLabelWidth
-1, m_rowBottoms
[row
]-1 );
3931 dc
.DrawLine( 0, m_rowBottoms
[row
]-1,
3932 m_rowLabelWidth
-1, m_rowBottoms
[row
]-1 );
3934 dc
.SetPen( *wxWHITE_PEN
);
3935 dc
.DrawLine( 0, rowTop
, 0, m_rowBottoms
[row
]-1 );
3936 dc
.DrawLine( 0, rowTop
, m_rowLabelWidth
-1, rowTop
);
3938 dc
.SetBackgroundMode( wxTRANSPARENT
);
3939 dc
.SetTextForeground( GetLabelTextColour() );
3940 dc
.SetFont( GetLabelFont() );
3943 GetRowLabelAlignment( &hAlign
, &vAlign
);
3947 rect
.SetY( m_rowBottoms
[row
] - m_rowHeights
[row
] + 2 );
3948 rect
.SetWidth( m_rowLabelWidth
- 4 );
3949 rect
.SetHeight( m_rowHeights
[row
] - 4 );
3950 DrawTextRectangle( dc
, GetRowLabelValue( row
), rect
, hAlign
, vAlign
);
3954 void wxGrid::DrawColLabels( wxDC
& dc
)
3956 if ( !m_numRows
|| !m_numCols
) return;
3959 size_t numLabels
= m_colLabelsExposed
.GetCount();
3961 for ( i
= 0; i
< numLabels
; i
++ )
3963 DrawColLabel( dc
, m_colLabelsExposed
[i
] );
3968 void wxGrid::DrawColLabel( wxDC
& dc
, int col
)
3970 if ( m_colWidths
[col
] <= 0 ) return;
3972 int colLeft
= m_colRights
[col
] - m_colWidths
[col
];
3974 dc
.SetPen( *wxBLACK_PEN
);
3975 dc
.DrawLine( m_colRights
[col
]-1, 0,
3976 m_colRights
[col
]-1, m_colLabelHeight
-1 );
3978 dc
.DrawLine( colLeft
, m_colLabelHeight
-1,
3979 m_colRights
[col
]-1, m_colLabelHeight
-1 );
3981 dc
.SetPen( *wxWHITE_PEN
);
3982 dc
.DrawLine( colLeft
, 0, colLeft
, m_colLabelHeight
-1 );
3983 dc
.DrawLine( colLeft
, 0, m_colRights
[col
]-1, 0 );
3985 dc
.SetBackgroundMode( wxTRANSPARENT
);
3986 dc
.SetTextForeground( GetLabelTextColour() );
3987 dc
.SetFont( GetLabelFont() );
3989 dc
.SetBackgroundMode( wxTRANSPARENT
);
3990 dc
.SetTextForeground( GetLabelTextColour() );
3991 dc
.SetFont( GetLabelFont() );
3994 GetColLabelAlignment( &hAlign
, &vAlign
);
3997 rect
.SetX( m_colRights
[col
] - m_colWidths
[col
] + 2 );
3999 rect
.SetWidth( m_colWidths
[col
] - 4 );
4000 rect
.SetHeight( m_colLabelHeight
- 4 );
4001 DrawTextRectangle( dc
, GetColLabelValue( col
), rect
, hAlign
, vAlign
);
4005 void wxGrid::DrawTextRectangle( wxDC
& dc
,
4006 const wxString
& value
,
4011 long textWidth
, textHeight
;
4012 long lineWidth
, lineHeight
;
4013 wxArrayString lines
;
4015 dc
.SetClippingRegion( rect
);
4016 StringToLines( value
, lines
);
4017 if ( lines
.GetCount() )
4019 GetTextBoxSize( dc
, lines
, &textWidth
, &textHeight
);
4020 dc
.GetTextExtent( lines
[0], &lineWidth
, &lineHeight
);
4023 switch ( horizAlign
)
4026 x
= rect
.x
+ (rect
.width
- textWidth
- 1);
4030 x
= rect
.x
+ ((rect
.width
- textWidth
)/2);
4039 switch ( vertAlign
)
4042 y
= rect
.y
+ (rect
.height
- textHeight
- 1);
4046 y
= rect
.y
+ ((rect
.height
- textHeight
)/2);
4055 for ( size_t i
= 0; i
< lines
.GetCount(); i
++ )
4057 dc
.DrawText( lines
[i
], (long)x
, (long)y
);
4062 dc
.DestroyClippingRegion();
4066 // Split multi line text up into an array of strings. Any existing
4067 // contents of the string array are preserved.
4069 void wxGrid::StringToLines( const wxString
& value
, wxArrayString
& lines
)
4073 wxString eol
= wxTextFile::GetEOL( wxTextFileType_Unix
);
4074 wxString tVal
= wxTextFile::Translate( value
, wxTextFileType_Unix
);
4076 while ( startPos
< (int)tVal
.Length() )
4078 pos
= tVal
.Mid(startPos
).Find( eol
);
4083 else if ( pos
== 0 )
4085 lines
.Add( wxEmptyString
);
4089 lines
.Add( value
.Mid(startPos
, pos
) );
4093 if ( startPos
< (int)value
.Length() )
4095 lines
.Add( value
.Mid( startPos
) );
4100 void wxGrid::GetTextBoxSize( wxDC
& dc
,
4101 wxArrayString
& lines
,
4102 long *width
, long *height
)
4109 for ( i
= 0; i
< lines
.GetCount(); i
++ )
4111 dc
.GetTextExtent( lines
[i
], &lineW
, &lineH
);
4112 w
= wxMax( w
, lineW
);
4122 // ------ Edit control functions
4126 void wxGrid::EnableEditing( bool edit
)
4128 // TODO: improve this ?
4130 if ( edit
!= m_editable
)
4134 EnableCellEditControl(m_editable
);
4139 void wxGrid::EnableCellEditControl( bool enable
)
4144 if ( m_currentCellCoords
== wxGridNoCellCoords
)
4145 SetCurrentCell( 0, 0 );
4147 if ( enable
!= m_cellEditCtrlEnabled
)
4151 m_cellEditCtrlEnabled
= enable
;
4152 SetEditControlValue();
4153 ShowCellEditControl();
4157 HideCellEditControl();
4158 SaveEditControlValue();
4159 m_cellEditCtrlEnabled
= enable
;
4165 void wxGrid::ShowCellEditControl()
4167 if ( IsCellEditControlEnabled() )
4169 if ( !IsVisible( m_currentCellCoords
) )
4175 wxRect rect
= CellToRect( m_currentCellCoords
);
4176 int row
= m_currentCellCoords
.GetRow();
4177 int col
= m_currentCellCoords
.GetCol();
4179 // convert to scrolled coords
4181 int left
, top
, right
, bottom
;
4182 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
4183 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
4184 left
--; top
--; right
--; bottom
--; // cell is shifted by one pixel
4186 m_gridWin
->GetClientSize( &cw
, &ch
);
4188 // Make the edit control large enough to allow for internal margins
4189 // TODO: remove this if the text ctrl sizing is improved esp. for unix
4192 #if defined(__WXMOTIF__)
4193 if ( row
== 0 || col
== 0 )
4202 if ( row
== 0 || col
== 0 )
4212 #if defined(__WXGTK__)
4215 if (left
!= 0) left_diff
++;
4216 if (top
!= 0) top_diff
++;
4217 rect
.SetLeft( left
+ left_diff
);
4218 rect
.SetTop( top
+ top_diff
);
4219 rect
.SetRight( rect
.GetRight() - left_diff
);
4220 rect
.SetBottom( rect
.GetBottom() - top_diff
);
4222 rect
.SetLeft( wxMax(0, left
- extra
) );
4223 rect
.SetTop( wxMax(0, top
- extra
) );
4224 rect
.SetRight( rect
.GetRight() + 2*extra
);
4225 rect
.SetBottom( rect
.GetBottom() + 2*extra
);
4228 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4229 wxGridCellEditor
* editor
= attr
->GetEditor();
4230 if (! editor
->IsCreated()) {
4231 editor
->Create(m_gridWin
, -1,
4232 new wxGridCellEditorEvtHandler(this, editor
));
4235 editor
->SetSize( rect
);
4236 editor
->Show( TRUE
);
4237 editor
->BeginEdit(row
, col
, this, attr
);
4244 void wxGrid::HideCellEditControl()
4246 if ( IsCellEditControlEnabled() )
4248 int row
= m_currentCellCoords
.GetRow();
4249 int col
= m_currentCellCoords
.GetCol();
4251 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4252 attr
->GetEditor()->Show( FALSE
);
4254 m_gridWin
->SetFocus();
4259 void wxGrid::SetEditControlValue( const wxString
& value
)
4264 void wxGrid::SaveEditControlValue()
4266 if (IsCellEditControlEnabled()) {
4267 int row
= m_currentCellCoords
.GetRow();
4268 int col
= m_currentCellCoords
.GetCol();
4270 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
4271 bool changed
= attr
->GetEditor()->EndEdit(row
, col
, TRUE
, this, attr
);
4276 SendEvent( EVT_GRID_CELL_CHANGE
,
4277 m_currentCellCoords
.GetRow(),
4278 m_currentCellCoords
.GetCol() );
4285 // ------ Grid location functions
4286 // Note that all of these functions work with the logical coordinates of
4287 // grid cells and labels so you will need to convert from device
4288 // coordinates for mouse events etc.
4291 void wxGrid::XYToCell( int x
, int y
, wxGridCellCoords
& coords
)
4293 int row
= YToRow(y
);
4294 int col
= XToCol(x
);
4296 if ( row
== -1 || col
== -1 )
4298 coords
= wxGridNoCellCoords
;
4302 coords
.Set( row
, col
);
4307 int wxGrid::YToRow( int y
)
4311 for ( i
= 0; i
< m_numRows
; i
++ )
4313 if ( y
< m_rowBottoms
[i
] ) return i
;
4316 return m_numRows
; //-1;
4320 int wxGrid::XToCol( int x
)
4324 for ( i
= 0; i
< m_numCols
; i
++ )
4326 if ( x
< m_colRights
[i
] ) return i
;
4329 return m_numCols
; //-1;
4333 // return the row number that that the y coord is near the edge of, or
4334 // -1 if not near an edge
4336 int wxGrid::YToEdgeOfRow( int y
)
4340 for ( i
= 0; i
< m_numRows
; i
++ )
4342 if ( m_rowHeights
[i
] > WXGRID_LABEL_EDGE_ZONE
)
4344 d
= abs( y
- m_rowBottoms
[i
] );
4346 if ( d
< WXGRID_LABEL_EDGE_ZONE
) return i
;
4355 // return the col number that that the x coord is near the edge of, or
4356 // -1 if not near an edge
4358 int wxGrid::XToEdgeOfCol( int x
)
4362 for ( i
= 0; i
< m_numCols
; i
++ )
4364 if ( m_colWidths
[i
] > WXGRID_LABEL_EDGE_ZONE
)
4366 d
= abs( x
- m_colRights
[i
] );
4368 if ( d
< WXGRID_LABEL_EDGE_ZONE
) return i
;
4377 wxRect
wxGrid::CellToRect( int row
, int col
)
4379 wxRect
rect( -1, -1, -1, -1 );
4381 if ( row
>= 0 && row
< m_numRows
&&
4382 col
>= 0 && col
< m_numCols
)
4384 rect
.x
= m_colRights
[col
] - m_colWidths
[col
];
4385 rect
.y
= m_rowBottoms
[row
] - m_rowHeights
[row
];
4386 rect
.width
= m_colWidths
[col
];
4387 rect
.height
= m_rowHeights
[ row
];
4394 bool wxGrid::IsVisible( int row
, int col
, bool wholeCellVisible
)
4396 // get the cell rectangle in logical coords
4398 wxRect
r( CellToRect( row
, col
) );
4400 // convert to device coords
4402 int left
, top
, right
, bottom
;
4403 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
4404 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
4406 // check against the client area of the grid window
4409 m_gridWin
->GetClientSize( &cw
, &ch
);
4411 if ( wholeCellVisible
)
4413 // is the cell wholly visible ?
4415 return ( left
>= 0 && right
<= cw
&&
4416 top
>= 0 && bottom
<= ch
);
4420 // is the cell partly visible ?
4422 return ( ((left
>=0 && left
< cw
) || (right
> 0 && right
<= cw
)) &&
4423 ((top
>=0 && top
< ch
) || (bottom
> 0 && bottom
<= ch
)) );
4428 // make the specified cell location visible by doing a minimal amount
4431 void wxGrid::MakeCellVisible( int row
, int col
)
4434 int xpos
= -1, ypos
= -1;
4436 if ( row
>= 0 && row
< m_numRows
&&
4437 col
>= 0 && col
< m_numCols
)
4439 // get the cell rectangle in logical coords
4441 wxRect
r( CellToRect( row
, col
) );
4443 // convert to device coords
4445 int left
, top
, right
, bottom
;
4446 CalcScrolledPosition( r
.GetLeft(), r
.GetTop(), &left
, &top
);
4447 CalcScrolledPosition( r
.GetRight(), r
.GetBottom(), &right
, &bottom
);
4450 m_gridWin
->GetClientSize( &cw
, &ch
);
4456 else if ( bottom
> ch
)
4458 int h
= r
.GetHeight();
4460 for ( i
= row
-1; i
>= 0; i
-- )
4462 if ( h
+ m_rowHeights
[i
] > ch
) break;
4464 h
+= m_rowHeights
[i
];
4465 ypos
-= m_rowHeights
[i
];
4468 // we divide it later by GRID_SCROLL_LINE, make sure that we don't
4469 // have rounding errors (this is important, because if we do, we
4470 // might not scroll at all and some cells won't be redrawn)
4471 ypos
+= GRID_SCROLL_LINE
/ 2;
4478 else if ( right
> cw
)
4480 int w
= r
.GetWidth();
4482 for ( i
= col
-1; i
>= 0; i
-- )
4484 if ( w
+ m_colWidths
[i
] > cw
) break;
4486 w
+= m_colWidths
[i
];
4487 xpos
-= m_colWidths
[i
];
4490 // see comment for ypos above
4491 xpos
+= GRID_SCROLL_LINE
/ 2;
4494 if ( xpos
!= -1 || ypos
!= -1 )
4496 if ( xpos
!= -1 ) xpos
/= GRID_SCROLL_LINE
;
4497 if ( ypos
!= -1 ) ypos
/= GRID_SCROLL_LINE
;
4498 Scroll( xpos
, ypos
);
4506 // ------ Grid cursor movement functions
4509 bool wxGrid::MoveCursorUp()
4511 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
4512 m_currentCellCoords
.GetRow() > 0 )
4514 MakeCellVisible( m_currentCellCoords
.GetRow() - 1,
4515 m_currentCellCoords
.GetCol() );
4517 SetCurrentCell( m_currentCellCoords
.GetRow() - 1,
4518 m_currentCellCoords
.GetCol() );
4527 bool wxGrid::MoveCursorDown()
4529 // TODO: allow for scrolling
4531 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
4532 m_currentCellCoords
.GetRow() < m_numRows
-1 )
4534 MakeCellVisible( m_currentCellCoords
.GetRow() + 1,
4535 m_currentCellCoords
.GetCol() );
4537 SetCurrentCell( m_currentCellCoords
.GetRow() + 1,
4538 m_currentCellCoords
.GetCol() );
4547 bool wxGrid::MoveCursorLeft()
4549 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
4550 m_currentCellCoords
.GetCol() > 0 )
4552 MakeCellVisible( m_currentCellCoords
.GetRow(),
4553 m_currentCellCoords
.GetCol() - 1 );
4555 SetCurrentCell( m_currentCellCoords
.GetRow(),
4556 m_currentCellCoords
.GetCol() - 1 );
4565 bool wxGrid::MoveCursorRight()
4567 if ( m_currentCellCoords
!= wxGridNoCellCoords
&&
4568 m_currentCellCoords
.GetCol() < m_numCols
- 1 )
4570 MakeCellVisible( m_currentCellCoords
.GetRow(),
4571 m_currentCellCoords
.GetCol() + 1 );
4573 SetCurrentCell( m_currentCellCoords
.GetRow(),
4574 m_currentCellCoords
.GetCol() + 1 );
4583 bool wxGrid::MovePageUp()
4585 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
4587 int row
= m_currentCellCoords
.GetRow();
4591 m_gridWin
->GetClientSize( &cw
, &ch
);
4593 int y
= m_rowBottoms
[ row
] - m_rowHeights
[ row
];
4594 int newRow
= YToRow( y
- ch
+ 1 );
4599 else if ( newRow
== row
)
4604 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
4605 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
4613 bool wxGrid::MovePageDown()
4615 if ( m_currentCellCoords
== wxGridNoCellCoords
) return FALSE
;
4617 int row
= m_currentCellCoords
.GetRow();
4618 if ( row
< m_numRows
)
4621 m_gridWin
->GetClientSize( &cw
, &ch
);
4623 int y
= m_rowBottoms
[ row
] - m_rowHeights
[ row
];
4624 int newRow
= YToRow( y
+ ch
);
4627 newRow
= m_numRows
- 1;
4629 else if ( newRow
== row
)
4634 MakeCellVisible( newRow
, m_currentCellCoords
.GetCol() );
4635 SetCurrentCell( newRow
, m_currentCellCoords
.GetCol() );
4643 bool wxGrid::MoveCursorUpBlock()
4646 m_currentCellCoords
!= wxGridNoCellCoords
&&
4647 m_currentCellCoords
.GetRow() > 0 )
4649 int row
= m_currentCellCoords
.GetRow();
4650 int col
= m_currentCellCoords
.GetCol();
4652 if ( m_table
->IsEmptyCell(row
, col
) )
4654 // starting in an empty cell: find the next block of
4660 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4663 else if ( m_table
->IsEmptyCell(row
-1, col
) )
4665 // starting at the top of a block: find the next block
4671 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4676 // starting within a block: find the top of the block
4681 if ( m_table
->IsEmptyCell(row
, col
) )
4689 MakeCellVisible( row
, col
);
4690 SetCurrentCell( row
, col
);
4698 bool wxGrid::MoveCursorDownBlock()
4701 m_currentCellCoords
!= wxGridNoCellCoords
&&
4702 m_currentCellCoords
.GetRow() < m_numRows
-1 )
4704 int row
= m_currentCellCoords
.GetRow();
4705 int col
= m_currentCellCoords
.GetCol();
4707 if ( m_table
->IsEmptyCell(row
, col
) )
4709 // starting in an empty cell: find the next block of
4712 while ( row
< m_numRows
-1 )
4715 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4718 else if ( m_table
->IsEmptyCell(row
+1, col
) )
4720 // starting at the bottom of a block: find the next block
4723 while ( row
< m_numRows
-1 )
4726 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4731 // starting within a block: find the bottom of the block
4733 while ( row
< m_numRows
-1 )
4736 if ( m_table
->IsEmptyCell(row
, col
) )
4744 MakeCellVisible( row
, col
);
4745 SetCurrentCell( row
, col
);
4753 bool wxGrid::MoveCursorLeftBlock()
4756 m_currentCellCoords
!= wxGridNoCellCoords
&&
4757 m_currentCellCoords
.GetCol() > 0 )
4759 int row
= m_currentCellCoords
.GetRow();
4760 int col
= m_currentCellCoords
.GetCol();
4762 if ( m_table
->IsEmptyCell(row
, col
) )
4764 // starting in an empty cell: find the next block of
4770 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4773 else if ( m_table
->IsEmptyCell(row
, col
-1) )
4775 // starting at the left of a block: find the next block
4781 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4786 // starting within a block: find the left of the block
4791 if ( m_table
->IsEmptyCell(row
, col
) )
4799 MakeCellVisible( row
, col
);
4800 SetCurrentCell( row
, col
);
4808 bool wxGrid::MoveCursorRightBlock()
4811 m_currentCellCoords
!= wxGridNoCellCoords
&&
4812 m_currentCellCoords
.GetCol() < m_numCols
-1 )
4814 int row
= m_currentCellCoords
.GetRow();
4815 int col
= m_currentCellCoords
.GetCol();
4817 if ( m_table
->IsEmptyCell(row
, col
) )
4819 // starting in an empty cell: find the next block of
4822 while ( col
< m_numCols
-1 )
4825 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4828 else if ( m_table
->IsEmptyCell(row
, col
+1) )
4830 // starting at the right of a block: find the next block
4833 while ( col
< m_numCols
-1 )
4836 if ( !(m_table
->IsEmptyCell(row
, col
)) ) break;
4841 // starting within a block: find the right of the block
4843 while ( col
< m_numCols
-1 )
4846 if ( m_table
->IsEmptyCell(row
, col
) )
4854 MakeCellVisible( row
, col
);
4855 SetCurrentCell( row
, col
);
4866 // ------ Label values and formatting
4869 void wxGrid::GetRowLabelAlignment( int *horiz
, int *vert
)
4871 *horiz
= m_rowLabelHorizAlign
;
4872 *vert
= m_rowLabelVertAlign
;
4875 void wxGrid::GetColLabelAlignment( int *horiz
, int *vert
)
4877 *horiz
= m_colLabelHorizAlign
;
4878 *vert
= m_colLabelVertAlign
;
4881 wxString
wxGrid::GetRowLabelValue( int row
)
4885 return m_table
->GetRowLabelValue( row
);
4895 wxString
wxGrid::GetColLabelValue( int col
)
4899 return m_table
->GetColLabelValue( col
);
4910 void wxGrid::SetRowLabelSize( int width
)
4912 width
= wxMax( width
, 0 );
4913 if ( width
!= m_rowLabelWidth
)
4917 m_rowLabelWin
->Show( FALSE
);
4918 m_cornerLabelWin
->Show( FALSE
);
4920 else if ( m_rowLabelWidth
== 0 )
4922 m_rowLabelWin
->Show( TRUE
);
4923 if ( m_colLabelHeight
> 0 ) m_cornerLabelWin
->Show( TRUE
);
4926 m_rowLabelWidth
= width
;
4933 void wxGrid::SetColLabelSize( int height
)
4935 height
= wxMax( height
, 0 );
4936 if ( height
!= m_colLabelHeight
)
4940 m_colLabelWin
->Show( FALSE
);
4941 m_cornerLabelWin
->Show( FALSE
);
4943 else if ( m_colLabelHeight
== 0 )
4945 m_colLabelWin
->Show( TRUE
);
4946 if ( m_rowLabelWidth
> 0 ) m_cornerLabelWin
->Show( TRUE
);
4949 m_colLabelHeight
= height
;
4956 void wxGrid::SetLabelBackgroundColour( const wxColour
& colour
)
4958 if ( m_labelBackgroundColour
!= colour
)
4960 m_labelBackgroundColour
= colour
;
4961 m_rowLabelWin
->SetBackgroundColour( colour
);
4962 m_colLabelWin
->SetBackgroundColour( colour
);
4963 m_cornerLabelWin
->SetBackgroundColour( colour
);
4965 if ( !GetBatchCount() )
4967 m_rowLabelWin
->Refresh();
4968 m_colLabelWin
->Refresh();
4969 m_cornerLabelWin
->Refresh();
4974 void wxGrid::SetLabelTextColour( const wxColour
& colour
)
4976 if ( m_labelTextColour
!= colour
)
4978 m_labelTextColour
= colour
;
4979 if ( !GetBatchCount() )
4981 m_rowLabelWin
->Refresh();
4982 m_colLabelWin
->Refresh();
4987 void wxGrid::SetLabelFont( const wxFont
& font
)
4990 if ( !GetBatchCount() )
4992 m_rowLabelWin
->Refresh();
4993 m_colLabelWin
->Refresh();
4997 void wxGrid::SetRowLabelAlignment( int horiz
, int vert
)
4999 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
5001 m_rowLabelHorizAlign
= horiz
;
5004 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
5006 m_rowLabelVertAlign
= vert
;
5009 if ( !GetBatchCount() )
5011 m_rowLabelWin
->Refresh();
5015 void wxGrid::SetColLabelAlignment( int horiz
, int vert
)
5017 if ( horiz
== wxLEFT
|| horiz
== wxCENTRE
|| horiz
== wxRIGHT
)
5019 m_colLabelHorizAlign
= horiz
;
5022 if ( vert
== wxTOP
|| vert
== wxCENTRE
|| vert
== wxBOTTOM
)
5024 m_colLabelVertAlign
= vert
;
5027 if ( !GetBatchCount() )
5029 m_colLabelWin
->Refresh();
5033 void wxGrid::SetRowLabelValue( int row
, const wxString
& s
)
5037 m_table
->SetRowLabelValue( row
, s
);
5038 if ( !GetBatchCount() )
5040 wxRect rect
= CellToRect( row
, 0);
5041 if ( rect
.height
> 0 )
5043 CalcScrolledPosition(0, rect
.y
, &rect
.x
, &rect
.y
);
5045 rect
.width
= m_rowLabelWidth
;
5046 m_rowLabelWin
->Refresh( TRUE
, &rect
);
5052 void wxGrid::SetColLabelValue( int col
, const wxString
& s
)
5056 m_table
->SetColLabelValue( col
, s
);
5057 if ( !GetBatchCount() )
5059 wxRect rect
= CellToRect( 0, col
);
5060 if ( rect
.width
> 0 )
5062 CalcScrolledPosition(rect
.x
, 0, &rect
.x
, &rect
.y
);
5064 rect
.height
= m_colLabelHeight
;
5065 m_colLabelWin
->Refresh( TRUE
, &rect
);
5071 void wxGrid::SetGridLineColour( const wxColour
& colour
)
5073 if ( m_gridLineColour
!= colour
)
5075 m_gridLineColour
= colour
;
5077 wxClientDC
dc( m_gridWin
);
5079 DrawAllGridLines( dc
, wxRegion() );
5083 void wxGrid::EnableGridLines( bool enable
)
5085 if ( enable
!= m_gridLinesEnabled
)
5087 m_gridLinesEnabled
= enable
;
5089 if ( !GetBatchCount() )
5093 wxClientDC
dc( m_gridWin
);
5095 DrawAllGridLines( dc
, wxRegion() );
5099 m_gridWin
->Refresh();
5106 int wxGrid::GetDefaultRowSize()
5108 return m_defaultRowHeight
;
5111 int wxGrid::GetRowSize( int row
)
5113 wxCHECK_MSG( row
>= 0 && row
< m_numRows
, 0, _T("invalid row index") );
5115 return m_rowHeights
[row
];
5118 int wxGrid::GetDefaultColSize()
5120 return m_defaultColWidth
;
5123 int wxGrid::GetColSize( int col
)
5125 wxCHECK_MSG( col
>= 0 && col
< m_numCols
, 0, _T("invalid column index") );
5127 return m_colWidths
[col
];
5130 // ============================================================================
5131 // access to the grid attributes: each of them has a default value in the grid
5132 // itself and may be overidden on a per-cell basis
5133 // ============================================================================
5135 // ----------------------------------------------------------------------------
5136 // setting default attributes
5137 // ----------------------------------------------------------------------------
5139 void wxGrid::SetDefaultCellBackgroundColour( const wxColour
& col
)
5141 m_defaultCellAttr
->SetBackgroundColour(col
);
5144 void wxGrid::SetDefaultCellTextColour( const wxColour
& col
)
5146 m_defaultCellAttr
->SetTextColour(col
);
5149 void wxGrid::SetDefaultCellAlignment( int horiz
, int vert
)
5151 m_defaultCellAttr
->SetAlignment(horiz
, vert
);
5154 void wxGrid::SetDefaultCellFont( const wxFont
& font
)
5156 m_defaultCellAttr
->SetFont(font
);
5159 void wxGrid::SetDefaultRenderer(wxGridCellRenderer
*renderer
)
5161 m_defaultCellAttr
->SetRenderer(renderer
);
5164 // ----------------------------------------------------------------------------
5165 // access to the default attrbiutes
5166 // ----------------------------------------------------------------------------
5168 wxColour
wxGrid::GetDefaultCellBackgroundColour()
5170 return m_defaultCellAttr
->GetBackgroundColour();
5173 wxColour
wxGrid::GetDefaultCellTextColour()
5175 return m_defaultCellAttr
->GetTextColour();
5178 wxFont
wxGrid::GetDefaultCellFont()
5180 return m_defaultCellAttr
->GetFont();
5183 void wxGrid::GetDefaultCellAlignment( int *horiz
, int *vert
)
5185 m_defaultCellAttr
->GetAlignment(horiz
, vert
);
5188 wxGridCellRenderer
*wxGrid::GetDefaultRenderer() const
5190 return m_defaultCellAttr
->GetRenderer();
5193 // ----------------------------------------------------------------------------
5194 // access to cell attributes
5195 // ----------------------------------------------------------------------------
5197 wxColour
wxGrid::GetCellBackgroundColour(int row
, int col
)
5199 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5200 wxColour colour
= attr
->GetBackgroundColour();
5205 wxColour
wxGrid::GetCellTextColour( int row
, int col
)
5207 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5208 wxColour colour
= attr
->GetTextColour();
5213 wxFont
wxGrid::GetCellFont( int row
, int col
)
5215 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5216 wxFont font
= attr
->GetFont();
5221 void wxGrid::GetCellAlignment( int row
, int col
, int *horiz
, int *vert
)
5223 wxGridCellAttr
*attr
= GetCellAttr(row
, col
);
5224 attr
->GetAlignment(horiz
, vert
);
5228 wxGridCellRenderer
* wxGrid::GetCellRenderer(int row
, int col
)
5230 wxGridCellAttr
* attr
= GetCellAttr(row
, col
);
5231 wxGridCellRenderer
* renderer
= attr
->GetRenderer();
5236 // ----------------------------------------------------------------------------
5237 // attribute support: cache, automatic provider creation, ...
5238 // ----------------------------------------------------------------------------
5240 bool wxGrid::CanHaveAttributes()
5247 // RD: Maybe m_table->CanHaveAttributes() would be better in case the
5248 // table is providing the attributes itself??? In which case
5249 // I don't think the grid should create a Provider object for the
5250 // table but the table should be smart enough to do that on its own.
5251 if ( !m_table
->GetAttrProvider() )
5253 // use the default attr provider by default
5254 // (another choice would be to just return FALSE thus forcing the user
5256 m_table
->SetAttrProvider(new wxGridCellAttrProvider
);
5262 void wxGrid::ClearAttrCache()
5264 if ( m_attrCache
.row
!= -1 )
5266 m_attrCache
.attr
->SafeDecRef();
5267 m_attrCache
.row
= -1;
5271 void wxGrid::CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const
5273 wxGrid
*self
= (wxGrid
*)this; // const_cast
5275 self
->ClearAttrCache();
5276 self
->m_attrCache
.row
= row
;
5277 self
->m_attrCache
.col
= col
;
5278 self
->m_attrCache
.attr
= attr
;
5282 bool wxGrid::LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const
5284 if ( row
== m_attrCache
.row
&& col
== m_attrCache
.col
)
5286 *attr
= m_attrCache
.attr
;
5287 (*attr
)->SafeIncRef();
5289 #ifdef DEBUG_ATTR_CACHE
5290 gs_nAttrCacheHits
++;
5297 #ifdef DEBUG_ATTR_CACHE
5298 gs_nAttrCacheMisses
++;
5304 wxGridCellAttr
*wxGrid::GetCellAttr(int row
, int col
) const
5306 wxGridCellAttr
*attr
;
5307 if ( !LookupAttr(row
, col
, &attr
) )
5309 attr
= m_table
? m_table
->GetAttr(row
, col
) : (wxGridCellAttr
*)NULL
;
5310 CacheAttr(row
, col
, attr
);
5313 attr
->SetDefAttr(m_defaultCellAttr
);
5315 attr
= m_defaultCellAttr
;
5322 wxGridCellAttr
*wxGrid::GetOrCreateCellAttr(int row
, int col
) const
5324 wxGridCellAttr
*attr
;
5325 if ( !LookupAttr(row
, col
, &attr
) || !attr
)
5327 wxASSERT_MSG( m_table
,
5328 _T("we may only be called if CanHaveAttributes() "
5329 "returned TRUE and then m_table should be !NULL") );
5331 attr
= m_table
->GetAttr(row
, col
);
5334 attr
= new wxGridCellAttr
;
5336 // artificially inc the ref count to match DecRef() in caller
5339 m_table
->SetAttr(attr
, row
, col
);
5342 CacheAttr(row
, col
, attr
);
5344 attr
->SetDefAttr(m_defaultCellAttr
);
5348 // ----------------------------------------------------------------------------
5349 // setting cell attributes: this is forwarded to the table
5350 // ----------------------------------------------------------------------------
5352 void wxGrid::SetRowAttr(int row
, wxGridCellAttr
*attr
)
5354 if ( CanHaveAttributes() )
5356 m_table
->SetRowAttr(attr
, row
);
5364 void wxGrid::SetColAttr(int col
, wxGridCellAttr
*attr
)
5366 if ( CanHaveAttributes() )
5368 m_table
->SetColAttr(attr
, col
);
5376 void wxGrid::SetCellBackgroundColour( int row
, int col
, const wxColour
& colour
)
5378 if ( CanHaveAttributes() )
5380 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5381 attr
->SetBackgroundColour(colour
);
5386 void wxGrid::SetCellTextColour( int row
, int col
, const wxColour
& colour
)
5388 if ( CanHaveAttributes() )
5390 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5391 attr
->SetTextColour(colour
);
5396 void wxGrid::SetCellFont( int row
, int col
, const wxFont
& font
)
5398 if ( CanHaveAttributes() )
5400 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5401 attr
->SetFont(font
);
5406 void wxGrid::SetCellAlignment( int row
, int col
, int horiz
, int vert
)
5408 if ( CanHaveAttributes() )
5410 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5411 attr
->SetAlignment(horiz
, vert
);
5416 void wxGrid::SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
)
5418 if ( CanHaveAttributes() )
5420 wxGridCellAttr
*attr
= GetOrCreateCellAttr(row
, col
);
5421 attr
->SetRenderer(renderer
);
5426 // ----------------------------------------------------------------------------
5428 // ----------------------------------------------------------------------------
5430 void wxGrid::SetDefaultRowSize( int height
, bool resizeExistingRows
)
5432 m_defaultRowHeight
= wxMax( height
, WXGRID_MIN_ROW_HEIGHT
);
5434 if ( resizeExistingRows
)
5438 for ( row
= 0; row
< m_numRows
; row
++ )
5440 m_rowHeights
[row
] = m_defaultRowHeight
;
5441 bottom
+= m_defaultRowHeight
;
5442 m_rowBottoms
[row
] = bottom
;
5448 void wxGrid::SetRowSize( int row
, int height
)
5450 wxCHECK_RET( row
>= 0 && row
< m_numRows
, _T("invalid row index") );
5454 int h
= wxMax( 0, height
);
5455 int diff
= h
- m_rowHeights
[row
];
5457 m_rowHeights
[row
] = h
;
5458 for ( i
= row
; i
< m_numRows
; i
++ )
5460 m_rowBottoms
[i
] += diff
;
5465 void wxGrid::SetDefaultColSize( int width
, bool resizeExistingCols
)
5467 m_defaultColWidth
= wxMax( width
, WXGRID_MIN_COL_WIDTH
);
5469 if ( resizeExistingCols
)
5473 for ( col
= 0; col
< m_numCols
; col
++ )
5475 m_colWidths
[col
] = m_defaultColWidth
;
5476 right
+= m_defaultColWidth
;
5477 m_colRights
[col
] = right
;
5483 void wxGrid::SetColSize( int col
, int width
)
5485 wxCHECK_RET( col
>= 0 && col
< m_numCols
, _T("invalid column index") );
5489 int w
= wxMax( 0, width
);
5490 int diff
= w
- m_colWidths
[col
];
5491 m_colWidths
[col
] = w
;
5493 for ( i
= col
; i
< m_numCols
; i
++ )
5495 m_colRights
[i
] += diff
;
5502 // ------ cell value accessor functions
5505 void wxGrid::SetCellValue( int row
, int col
, const wxString
& s
)
5509 m_table
->SetValue( row
, col
, s
.c_str() );
5510 if ( !GetBatchCount() )
5512 wxClientDC
dc( m_gridWin
);
5514 DrawCell( dc
, wxGridCellCoords(row
, col
) );
5517 #if 0 // TODO: edit in place
5519 if ( m_currentCellCoords
.GetRow() == row
&&
5520 m_currentCellCoords
.GetCol() == col
)
5522 SetEditControlValue( s
);
5531 // ------ Block, row and col selection
5534 void wxGrid::SelectRow( int row
, bool addToSelected
)
5538 if ( IsSelection() && addToSelected
)
5541 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
5544 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
5545 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
5546 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
5547 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
5551 need_refresh
[0] = TRUE
;
5552 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( row
, 0 ),
5553 wxGridCellCoords ( oldTop
- 1,
5555 m_selectedTopLeft
.SetRow( row
);
5560 need_refresh
[1] = TRUE
;
5561 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
, 0 ),
5562 wxGridCellCoords ( oldBottom
,
5565 m_selectedTopLeft
.SetCol( 0 );
5568 if ( oldBottom
< row
)
5570 need_refresh
[2] = TRUE
;
5571 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1, 0 ),
5572 wxGridCellCoords ( row
,
5574 m_selectedBottomRight
.SetRow( row
);
5577 if ( oldRight
< m_numCols
- 1 )
5579 need_refresh
[3] = TRUE
;
5580 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5582 wxGridCellCoords ( oldBottom
,
5584 m_selectedBottomRight
.SetCol( m_numCols
- 1 );
5587 for (i
= 0; i
< 4; i
++ )
5588 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
5589 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
5593 r
= SelectionToDeviceRect();
5595 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
5597 m_selectedTopLeft
.Set( row
, 0 );
5598 m_selectedBottomRight
.Set( row
, m_numCols
-1 );
5599 r
= SelectionToDeviceRect();
5600 m_gridWin
->Refresh( FALSE
, &r
);
5603 wxGridRangeSelectEvent
gridEvt( GetId(),
5604 EVT_GRID_RANGE_SELECT
,
5607 m_selectedBottomRight
);
5609 GetEventHandler()->ProcessEvent(gridEvt
);
5613 void wxGrid::SelectCol( int col
, bool addToSelected
)
5615 if ( IsSelection() && addToSelected
)
5618 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
5621 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
5622 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
5623 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
5624 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
5626 if ( oldLeft
> col
)
5628 need_refresh
[0] = TRUE
;
5629 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( 0, col
),
5630 wxGridCellCoords ( m_numRows
- 1,
5632 m_selectedTopLeft
.SetCol( col
);
5637 need_refresh
[1] = TRUE
;
5638 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( 0, oldLeft
),
5639 wxGridCellCoords ( oldTop
- 1,
5641 m_selectedTopLeft
.SetRow( 0 );
5644 if ( oldRight
< col
)
5646 need_refresh
[2] = TRUE
;
5647 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( 0, oldRight
+ 1 ),
5648 wxGridCellCoords ( m_numRows
- 1,
5650 m_selectedBottomRight
.SetCol( col
);
5653 if ( oldBottom
< m_numRows
- 1 )
5655 need_refresh
[3] = TRUE
;
5656 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( oldBottom
+ 1,
5658 wxGridCellCoords ( m_numRows
- 1,
5660 m_selectedBottomRight
.SetRow( m_numRows
- 1 );
5663 for (i
= 0; i
< 4; i
++ )
5664 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
5665 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
5671 r
= SelectionToDeviceRect();
5673 if ( r
!= wxGridNoCellRect
) m_gridWin
->Refresh( FALSE
, &r
);
5675 m_selectedTopLeft
.Set( 0, col
);
5676 m_selectedBottomRight
.Set( m_numRows
-1, col
);
5677 r
= SelectionToDeviceRect();
5678 m_gridWin
->Refresh( FALSE
, &r
);
5681 wxGridRangeSelectEvent
gridEvt( GetId(),
5682 EVT_GRID_RANGE_SELECT
,
5685 m_selectedBottomRight
);
5687 GetEventHandler()->ProcessEvent(gridEvt
);
5691 void wxGrid::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
5694 wxGridCellCoords updateTopLeft
, updateBottomRight
;
5696 if ( topRow
> bottomRow
)
5703 if ( leftCol
> rightCol
)
5710 updateTopLeft
= wxGridCellCoords( topRow
, leftCol
);
5711 updateBottomRight
= wxGridCellCoords( bottomRow
, rightCol
);
5713 if ( m_selectedTopLeft
!= updateTopLeft
||
5714 m_selectedBottomRight
!= updateBottomRight
)
5716 // Compute two optimal update rectangles:
5717 // Either one rectangle is a real subset of the
5718 // other, or they are (almost) disjoint!
5720 bool need_refresh
[4] = { FALSE
, FALSE
, FALSE
, FALSE
};
5723 // Store intermediate values
5724 wxCoord oldLeft
= m_selectedTopLeft
.GetCol();
5725 wxCoord oldTop
= m_selectedTopLeft
.GetRow();
5726 wxCoord oldRight
= m_selectedBottomRight
.GetCol();
5727 wxCoord oldBottom
= m_selectedBottomRight
.GetRow();
5729 // Determine the outer/inner coordinates.
5730 if (oldLeft
> leftCol
)
5736 if (oldTop
> topRow
)
5742 if (oldRight
< rightCol
)
5745 oldRight
= rightCol
;
5748 if (oldBottom
< bottomRow
)
5751 oldBottom
= bottomRow
;
5755 // Now, either the stuff marked old is the outer
5756 // rectangle or we don't have a situation where one
5757 // is contained in the other.
5759 if ( oldLeft
< leftCol
)
5761 need_refresh
[0] = TRUE
;
5762 rect
[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5764 wxGridCellCoords ( oldBottom
,
5768 if ( oldTop
< topRow
)
5770 need_refresh
[1] = TRUE
;
5771 rect
[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5773 wxGridCellCoords ( topRow
- 1,
5777 if ( oldRight
> rightCol
)
5779 need_refresh
[2] = TRUE
;
5780 rect
[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop
,
5782 wxGridCellCoords ( oldBottom
,
5786 if ( oldBottom
> bottomRow
)
5788 need_refresh
[3] = TRUE
;
5789 rect
[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow
+ 1,
5791 wxGridCellCoords ( oldBottom
,
5797 m_selectedTopLeft
= updateTopLeft
;
5798 m_selectedBottomRight
= updateBottomRight
;
5800 // various Refresh() calls
5801 for (i
= 0; i
< 4; i
++ )
5802 if ( need_refresh
[i
] && rect
[i
] != wxGridNoCellRect
)
5803 m_gridWin
->Refresh( FALSE
, &(rect
[i
]) );
5806 // only generate an event if the block is not being selected by
5807 // dragging the mouse (in which case the event will be generated in
5808 // the mouse event handler)
5809 if ( !m_isDragging
)
5811 wxGridRangeSelectEvent
gridEvt( GetId(),
5812 EVT_GRID_RANGE_SELECT
,
5815 m_selectedBottomRight
);
5817 GetEventHandler()->ProcessEvent(gridEvt
);
5821 void wxGrid::SelectAll()
5823 m_selectedTopLeft
.Set( 0, 0 );
5824 m_selectedBottomRight
.Set( m_numRows
-1, m_numCols
-1 );
5826 m_gridWin
->Refresh();
5830 void wxGrid::ClearSelection()
5832 m_selectedTopLeft
= wxGridNoCellCoords
;
5833 m_selectedBottomRight
= wxGridNoCellCoords
;
5837 // This function returns the rectangle that encloses the given block
5838 // in device coords clipped to the client size of the grid window.
5840 wxRect
wxGrid::BlockToDeviceRect( const wxGridCellCoords
&topLeft
,
5841 const wxGridCellCoords
&bottomRight
)
5843 wxRect
rect( wxGridNoCellRect
);
5846 cellRect
= CellToRect( topLeft
);
5847 if ( cellRect
!= wxGridNoCellRect
)
5853 rect
= wxRect( 0, 0, 0, 0 );
5856 cellRect
= CellToRect( bottomRight
);
5857 if ( cellRect
!= wxGridNoCellRect
)
5863 return wxGridNoCellRect
;
5866 // convert to scrolled coords
5868 int left
, top
, right
, bottom
;
5869 CalcScrolledPosition( rect
.GetLeft(), rect
.GetTop(), &left
, &top
);
5870 CalcScrolledPosition( rect
.GetRight(), rect
.GetBottom(), &right
, &bottom
);
5873 m_gridWin
->GetClientSize( &cw
, &ch
);
5875 rect
.SetLeft( wxMax(0, left
) );
5876 rect
.SetTop( wxMax(0, top
) );
5877 rect
.SetRight( wxMin(cw
, right
) );
5878 rect
.SetBottom( wxMin(ch
, bottom
) );
5886 // ------ Grid event classes
5889 IMPLEMENT_DYNAMIC_CLASS( wxGridEvent
, wxEvent
)
5891 wxGridEvent::wxGridEvent( int id
, wxEventType type
, wxObject
* obj
,
5892 int row
, int col
, int x
, int y
,
5893 bool control
, bool shift
, bool alt
, bool meta
)
5894 : wxNotifyEvent( type
, id
)
5900 m_control
= control
;
5905 SetEventObject(obj
);
5909 IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent
, wxEvent
)
5911 wxGridSizeEvent::wxGridSizeEvent( int id
, wxEventType type
, wxObject
* obj
,
5912 int rowOrCol
, int x
, int y
,
5913 bool control
, bool shift
, bool alt
, bool meta
)
5914 : wxNotifyEvent( type
, id
)
5916 m_rowOrCol
= rowOrCol
;
5919 m_control
= control
;
5924 SetEventObject(obj
);
5928 IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent
, wxEvent
)
5930 wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
5931 const wxGridCellCoords
& topLeft
,
5932 const wxGridCellCoords
& bottomRight
,
5933 bool control
, bool shift
, bool alt
, bool meta
)
5934 : wxNotifyEvent( type
, id
)
5936 m_topLeft
= topLeft
;
5937 m_bottomRight
= bottomRight
;
5938 m_control
= control
;
5943 SetEventObject(obj
);
5947 #endif // ifndef wxUSE_NEW_GRID