33 #include "wx/dcclient.h"
34 #include "wx/settings.h"
36 #include "wx/textctrl.h"
37 #include "wx/checkbox.h"
38 #include "wx/combobox.h"
39 #include "wx/valtext.h"
42 #include "wx/listbox.h"
45#include "wx/textfile.h"
46#include "wx/spinctrl.h"
47#include "wx/tokenzr.h"
48#include "wx/renderer.h"
49#include "wx/headerctrl.h"
50#include "wx/hashset.h"
52#include "wx/generic/gridsel.h"
53#include "wx/generic/gridctrl.h"
54#include "wx/generic/grideditors.h"
55#include "wx/generic/private/grid.h"
57const char wxGridNameStr[] =
"grid";
59#if defined(__WXMOTIF__)
60 #define WXUNUSED_MOTIF(identifier) WXUNUSED(identifier)
62 #define WXUNUSED_MOTIF(identifier) identifier
66 #define WXUNUSED_GTK(identifier) WXUNUSED(identifier)
68 #define WXUNUSED_GTK(identifier) identifier
74WX_DECLARE_HASH_SET_WITH_DECL_PTR(
int, wxIntegerHash, wxIntegerEqual,
75 wxGridFixedIndicesSet,
class WXDLLIMPEXP_ADV);
86#ifdef DEBUG_ATTR_CACHE
87 static size_t gs_nAttrCacheHits = 0;
88 static size_t gs_nAttrCacheMisses = 0;
95struct DefaultHeaderRenderers
97 wxGridColumnHeaderRendererDefault colRenderer;
98 wxGridRowHeaderRendererDefault rowRenderer;
99 wxGridCornerHeaderRendererDefault cornerRenderer;
100} gs_defaultHeaderRenderers;
108wxGridCellCoords wxGridNoCellCoords( -1, -1 );
109wxRect wxGridNoCellRect( -1, -1, -1, -1 );
115const size_t GRID_SCROLL_LINE_X = 15;
116const size_t GRID_SCROLL_LINE_Y = GRID_SCROLL_LINE_X;
120const int GRID_HASH_SIZE = 100;
124const int DRAG_SENSITIVITY = 3;
128#include "wx/arrimpl.cpp"
137wxDEFINE_EVENT( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEvent );
138wxDEFINE_EVENT( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEvent );
139wxDEFINE_EVENT( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEvent );
140wxDEFINE_EVENT( wxEVT_GRID_CELL_RIGHT_DCLICK, wxGridEvent );
141wxDEFINE_EVENT( wxEVT_GRID_CELL_BEGIN_DRAG, wxGridEvent );
142wxDEFINE_EVENT( wxEVT_GRID_LABEL_LEFT_CLICK, wxGridEvent );
143wxDEFINE_EVENT( wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEvent );
144wxDEFINE_EVENT( wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEvent );
145wxDEFINE_EVENT( wxEVT_GRID_LABEL_RIGHT_DCLICK, wxGridEvent );
146wxDEFINE_EVENT( wxEVT_GRID_ROW_SIZE, wxGridSizeEvent );
147wxDEFINE_EVENT( wxEVT_GRID_COL_SIZE, wxGridSizeEvent );
148wxDEFINE_EVENT( wxEVT_GRID_COL_AUTO_SIZE, wxGridSizeEvent );
149wxDEFINE_EVENT( wxEVT_GRID_COL_MOVE, wxGridEvent );
150wxDEFINE_EVENT( wxEVT_GRID_COL_SORT, wxGridEvent );
151wxDEFINE_EVENT( wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEvent );
152wxDEFINE_EVENT( wxEVT_GRID_CELL_CHANGING, wxGridEvent );
153wxDEFINE_EVENT( wxEVT_GRID_CELL_CHANGED, wxGridEvent );
154wxDEFINE_EVENT( wxEVT_GRID_SELECT_CELL, wxGridEvent );
155wxDEFINE_EVENT( wxEVT_GRID_EDITOR_SHOWN, wxGridEvent );
156wxDEFINE_EVENT( wxEVT_GRID_EDITOR_HIDDEN, wxGridEvent );
157wxDEFINE_EVENT( wxEVT_GRID_EDITOR_CREATED, wxGridEditorCreatedEvent );
158wxDEFINE_EVENT( wxEVT_GRID_TABBING, wxGridEvent );
169 void EnsureFirstLessThanSecond(
int& first,
int& second)
171 if ( first > second )
172 wxSwap(first, second);
181IMPLEMENT_ABSTRACT_CLASS(wxGridCellEditorEvtHandler, wxEvtHandler)
183BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler, wxEvtHandler )
184 EVT_KILL_FOCUS( wxGridCellEditorEvtHandler::OnKillFocus )
185 EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown )
186 EVT_CHAR( wxGridCellEditorEvtHandler::OnChar )
189BEGIN_EVENT_TABLE(wxGridHeaderCtrl, wxHeaderCtrl)
190 EVT_HEADER_CLICK(wxID_ANY, wxGridHeaderCtrl::OnClick)
191 EVT_HEADER_DCLICK(wxID_ANY, wxGridHeaderCtrl::OnDoubleClick)
192 EVT_HEADER_RIGHT_CLICK(wxID_ANY, wxGridHeaderCtrl::OnRightClick)
194 EVT_HEADER_BEGIN_RESIZE(wxID_ANY, wxGridHeaderCtrl::OnBeginResize)
195 EVT_HEADER_RESIZING(wxID_ANY, wxGridHeaderCtrl::OnResizing)
196 EVT_HEADER_END_RESIZE(wxID_ANY, wxGridHeaderCtrl::OnEndResize)
198 EVT_HEADER_BEGIN_REORDER(wxID_ANY, wxGridHeaderCtrl::OnBeginReorder)
199 EVT_HEADER_END_REORDER(wxID_ANY, wxGridHeaderCtrl::OnEndReorder)
202wxGridOperations& wxGridRowOperations::Dual()
const
204 static wxGridColumnOperations s_colOper;
209wxGridOperations& wxGridColumnOperations::Dual()
const
211 static wxGridRowOperations s_rowOper;
221void wxGridCellWorker::SetParameters(
const wxString& WXUNUSED(params))
226wxGridCellWorker::~wxGridCellWorker()
234void wxGridHeaderLabelsRenderer::DrawLabel(
const wxGrid& grid,
236 const wxString& value,
240 int textOrientation)
const
242 dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
243 dc.SetTextForeground(grid.GetLabelTextColour());
244 dc.SetFont(grid.GetLabelFont());
245 grid.DrawTextRectangle(dc, value, rect, horizAlign, vertAlign, textOrientation);
249void wxGridRowHeaderRendererDefault::DrawBorder(
const wxGrid& WXUNUSED(grid),
253 dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
254 dc.DrawLine(rect.GetRight(), rect.GetTop(),
255 rect.GetRight(), rect.GetBottom());
256 dc.DrawLine(rect.GetLeft(), rect.GetTop(),
257 rect.GetLeft(), rect.GetBottom());
258 dc.DrawLine(rect.GetLeft(), rect.GetBottom(),
259 rect.GetRight() + 1, rect.GetBottom());
261 dc.SetPen(*wxWHITE_PEN);
262 dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(),
263 rect.GetLeft() + 1, rect.GetBottom());
264 dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(),
265 rect.GetRight(), rect.GetTop());
270void wxGridColumnHeaderRendererDefault::DrawBorder(
const wxGrid& WXUNUSED(grid),
274 dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
275 dc.DrawLine(rect.GetRight(), rect.GetTop(),
276 rect.GetRight(), rect.GetBottom());
277 dc.DrawLine(rect.GetLeft(), rect.GetTop(),
278 rect.GetRight(), rect.GetTop());
279 dc.DrawLine(rect.GetLeft(), rect.GetBottom(),
280 rect.GetRight() + 1, rect.GetBottom());
282 dc.SetPen(*wxWHITE_PEN);
283 dc.DrawLine(rect.GetLeft(), rect.GetTop() + 1,
284 rect.GetLeft(), rect.GetBottom());
285 dc.DrawLine(rect.GetLeft(), rect.GetTop() + 1,
286 rect.GetRight(), rect.GetTop() + 1);
291void wxGridCornerHeaderRendererDefault::DrawBorder(
const wxGrid& WXUNUSED(grid),
295 dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
296 dc.DrawLine(rect.GetRight() - 1, rect.GetBottom() - 1,
297 rect.GetRight() - 1, rect.GetTop());
298 dc.DrawLine(rect.GetRight() - 1, rect.GetBottom() - 1,
299 rect.GetLeft(), rect.GetBottom() - 1);
300 dc.DrawLine(rect.GetLeft(), rect.GetTop(),
301 rect.GetRight(), rect.GetTop());
302 dc.DrawLine(rect.GetLeft(), rect.GetTop(),
303 rect.GetLeft(), rect.GetBottom());
305 dc.SetPen(*wxWHITE_PEN);
306 dc.DrawLine(rect.GetLeft() + 1, rect.GetTop() + 1,
307 rect.GetRight() - 1, rect.GetTop() + 1);
308 dc.DrawLine(rect.GetLeft() + 1, rect.GetTop() + 1,
309 rect.GetLeft() + 1, rect.GetBottom() - 1);
318void wxGridCellAttr::Init(wxGridCellAttr *attrDefault)
320 m_isReadOnly = Unset;
325 m_attrkind = wxGridCellAttr::Cell;
327 m_sizeRows = m_sizeCols = 1;
328 m_overflow = UnsetOverflow;
330 SetDefAttr(attrDefault);
333wxGridCellAttr *wxGridCellAttr::Clone()
const
335 wxGridCellAttr *attr =
new wxGridCellAttr(m_defGridAttr);
337 if ( HasTextColour() )
338 attr->SetTextColour(GetTextColour());
339 if ( HasBackgroundColour() )
340 attr->SetBackgroundColour(GetBackgroundColour());
342 attr->SetFont(GetFont());
343 if ( HasAlignment() )
344 attr->SetAlignment(m_hAlign, m_vAlign);
346 attr->SetSize( m_sizeRows, m_sizeCols );
350 attr->SetRenderer(m_renderer);
351 m_renderer->IncRef();
355 attr->SetEditor(m_editor);
362 attr->SetOverflow( m_overflow == Overflow );
363 attr->SetKind( m_attrkind );
368void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom)
370 if ( !HasTextColour() && mergefrom->HasTextColour() )
371 SetTextColour(mergefrom->GetTextColour());
372 if ( !HasBackgroundColour() && mergefrom->HasBackgroundColour() )
373 SetBackgroundColour(mergefrom->GetBackgroundColour());
374 if ( !HasFont() && mergefrom->HasFont() )
375 SetFont(mergefrom->GetFont());
376 if ( !HasAlignment() && mergefrom->HasAlignment() )
379 mergefrom->GetAlignment( &hAlign, &vAlign);
380 SetAlignment(hAlign, vAlign);
382 if ( !HasSize() && mergefrom->HasSize() )
383 mergefrom->GetSize( &m_sizeRows, &m_sizeCols );
389 if (!HasRenderer() && mergefrom->HasRenderer() )
391 m_renderer = mergefrom->m_renderer;
392 m_renderer->IncRef();
394 if ( !HasEditor() && mergefrom->HasEditor() )
396 m_editor = mergefrom->m_editor;
399 if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() )
400 SetReadOnly(mergefrom->IsReadOnly());
402 if (!HasOverflowMode() && mergefrom->HasOverflowMode() )
403 SetOverflow(mergefrom->GetOverflow());
405 SetDefAttr(mergefrom->m_defGridAttr);
408void wxGridCellAttr::SetSize(
int num_rows,
int num_cols)
420 wxASSERT_MSG( (!((num_rows > 0) && (num_cols <= 0)) ||
421 !((num_rows <= 0) && (num_cols > 0)) ||
422 !((num_rows == 0) && (num_cols == 0))),
423 wxT(
"wxGridCellAttr::SetSize only takes two positive values or negative/zero values"));
425 m_sizeRows = num_rows;
426 m_sizeCols = num_cols;
429const wxColour& wxGridCellAttr::GetTextColour()
const
435 else if (m_defGridAttr && m_defGridAttr !=
this)
437 return m_defGridAttr->GetTextColour();
441 wxFAIL_MSG(wxT(
"Missing default cell attribute"));
446const wxColour& wxGridCellAttr::GetBackgroundColour()
const
448 if (HasBackgroundColour())
452 else if (m_defGridAttr && m_defGridAttr !=
this)
454 return m_defGridAttr->GetBackgroundColour();
458 wxFAIL_MSG(wxT(
"Missing default cell attribute"));
463const wxFont& wxGridCellAttr::GetFont()
const
469 else if (m_defGridAttr && m_defGridAttr !=
this)
471 return m_defGridAttr->GetFont();
475 wxFAIL_MSG(wxT(
"Missing default cell attribute"));
480void wxGridCellAttr::GetAlignment(
int *hAlign,
int *vAlign)
const
489 else if (m_defGridAttr && m_defGridAttr !=
this)
491 m_defGridAttr->GetAlignment(hAlign, vAlign);
495 wxFAIL_MSG(wxT(
"Missing default cell attribute"));
499void wxGridCellAttr::GetNonDefaultAlignment(
int *hAlign,
int *vAlign)
const
501 if ( hAlign && m_hAlign != wxALIGN_INVALID )
504 if ( vAlign && m_vAlign != wxALIGN_INVALID )
508void wxGridCellAttr::GetSize(
int *num_rows,
int *num_cols )
const
511 *num_rows = m_sizeRows;
513 *num_cols = m_sizeCols;
523wxGridCellRenderer* wxGridCellAttr::GetRenderer(
const wxGrid* grid,
int row,
int col)
const
525 wxGridCellRenderer *renderer = NULL;
527 if ( m_renderer &&
this != m_defGridAttr )
530 renderer = m_renderer;
539 renderer = grid->GetDefaultRendererForCell(row, col);
542 if ( renderer == NULL )
544 if ( (m_defGridAttr != NULL) && (m_defGridAttr !=
this) )
548 renderer = m_defGridAttr->GetRenderer(NULL, 0, 0);
553 renderer = m_renderer;
561 wxASSERT_MSG(renderer, wxT(
"Missing default cell renderer"));
567wxGridCellEditor* wxGridCellAttr::GetEditor(
const wxGrid* grid,
int row,
int col)
const
569 wxGridCellEditor *editor = NULL;
571 if ( m_editor &&
this != m_defGridAttr )
583 editor = grid->GetDefaultEditorForCell(row, col);
586 if ( editor == NULL )
588 if ( (m_defGridAttr != NULL) && (m_defGridAttr !=
this) )
592 editor = m_defGridAttr->GetEditor(NULL, 0, 0);
605 wxASSERT_MSG(editor, wxT(
"Missing default cell editor"));
614void wxGridCellAttrData::SetAttr(wxGridCellAttr *attr,
int row,
int col)
619 int n = FindIndex(row, col);
620 if ( n == wxNOT_FOUND )
625 m_attrs.Add(
new wxGridCellWithAttr(row, col, attr));
634 m_attrs[(size_t)n].ChangeAttr(attr);
639 m_attrs.RemoveAt((
size_t)n);
644wxGridCellAttr *wxGridCellAttrData::GetAttr(
int row,
int col)
const
646 wxGridCellAttr *attr = NULL;
648 int n = FindIndex(row, col);
649 if ( n != wxNOT_FOUND )
651 attr = m_attrs[(size_t)n].attr;
658void wxGridCellAttrData::UpdateAttrRows(
size_t pos,
int numRows )
660 size_t count = m_attrs.GetCount();
661 for (
size_t n = 0; n < count; n++ )
663 wxGridCellCoords& coords = m_attrs[n].coords;
664 wxCoord row = coords.GetRow();
665 if ((
size_t)row >= pos)
670 coords.SetRow(row + numRows);
672 else if (numRows < 0)
675 if ((
size_t)row >= pos - numRows)
678 coords.SetRow(row + numRows);
692void wxGridCellAttrData::UpdateAttrCols(
size_t pos,
int numCols )
694 size_t count = m_attrs.GetCount();
695 for (
size_t n = 0; n < count; n++ )
697 wxGridCellCoords& coords = m_attrs[n].coords;
698 wxCoord col = coords.GetCol();
699 if ( (
size_t)col >= pos )
704 coords.SetCol(col + numCols);
706 else if (numCols < 0)
709 if ((
size_t)col >= pos - numCols)
712 coords.SetCol(col + numCols);
727void wxGridCellAttrData::RemoveAttrsFromRow(
int row)
729 size_t count = m_attrs.GetCount();
731 for (
size_t n = 0; n < count; n++)
733 wxGridCellCoords& coords = m_attrs[n].coords;
734 wxCoord cellRow = coords.GetRow();
746void wxGridCellAttrData::RemoveAttrsFromCol(
int col)
748 size_t count = m_attrs.GetCount();
750 for (
size_t n = 0; n < count; n++)
752 wxGridCellCoords& coords = m_attrs[n].coords;
753 wxCoord cellCol = coords.GetCol();
765int wxGridCellAttrData::FindIndex(
int row,
int col)
const
767 size_t count = m_attrs.GetCount();
768 for (
size_t n = 0; n < count; n++ )
770 const wxGridCellCoords& coords = m_attrs[n].coords;
771 if ( (coords.GetRow() == row) && (coords.GetCol() == col) )
784wxGridRowOrColAttrData::~wxGridRowOrColAttrData()
786 size_t count = m_attrs.GetCount();
787 for (
size_t n = 0; n < count; n++ )
789 m_attrs[n]->DecRef();
793wxGridCellAttr *wxGridRowOrColAttrData::GetAttr(
int rowOrCol)
const
795 wxGridCellAttr *attr = NULL;
797 int n = m_rowsOrCols.Index(rowOrCol);
798 if ( n != wxNOT_FOUND )
800 attr = m_attrs[(size_t)n];
807void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr *attr,
int rowOrCol)
809 int i = m_rowsOrCols.Index(rowOrCol);
810 if ( i == wxNOT_FOUND )
815 m_rowsOrCols.Add(rowOrCol);
822 size_t n = (size_t)i;
829 m_attrs[n]->DecRef();
838 m_rowsOrCols.RemoveAt(n);
844void wxGridRowOrColAttrData::UpdateAttrRowsOrCols(
size_t pos,
int numRowsOrCols )
846 size_t count = m_attrs.GetCount();
847 for (
size_t n = 0; n < count; n++ )
849 int & rowOrCol = m_rowsOrCols[n];
850 if ( (
size_t)rowOrCol >= pos )
852 if ( numRowsOrCols > 0 )
855 rowOrCol += numRowsOrCols;
857 else if ( numRowsOrCols < 0)
860 if ((
size_t)rowOrCol >= pos - numRowsOrCols)
861 rowOrCol += numRowsOrCols;
864 m_rowsOrCols.RemoveAt(n);
865 m_attrs[n]->DecRef();
879wxGridCellAttrProvider::wxGridCellAttrProvider()
884wxGridCellAttrProvider::~wxGridCellAttrProvider()
889void wxGridCellAttrProvider::InitData()
891 m_data =
new wxGridCellAttrProviderData;
894wxGridCellAttr *wxGridCellAttrProvider::GetAttr(
int row,
int col,
895 wxGridCellAttr::wxAttrKind kind )
const
897 wxGridCellAttr *attr = NULL;
902 case (wxGridCellAttr::Any):
910 wxGridCellAttr *attrcell = m_data->m_cellAttrs.GetAttr(row, col);
911 wxGridCellAttr *attrrow = m_data->m_rowAttrs.GetAttr(row);
912 wxGridCellAttr *attrcol = m_data->m_colAttrs.GetAttr(col);
914 if ((attrcell != attrrow) && (attrrow != attrcol) && (attrcell != attrcol))
917 attr =
new wxGridCellAttr;
918 attr->SetKind(wxGridCellAttr::Merged);
923 attr->MergeWith(attrcell);
928 attr->MergeWith(attrcol);
933 attr->MergeWith(attrrow);
962 case (wxGridCellAttr::Cell):
963 attr = m_data->m_cellAttrs.GetAttr(row, col);
966 case (wxGridCellAttr::Col):
967 attr = m_data->m_colAttrs.GetAttr(col);
970 case (wxGridCellAttr::Row):
971 attr = m_data->m_rowAttrs.GetAttr(row);
985void wxGridCellAttrProvider::SetAttr(wxGridCellAttr *attr,
991 m_data->m_cellAttrs.SetAttr(attr, row, col);
994void wxGridCellAttrProvider::SetRowAttr(wxGridCellAttr *attr,
int row,
bool clear)
999 m_data->m_rowAttrs.SetAttr(attr, row);
1004 m_data->m_cellAttrs.RemoveAttrsFromRow(row);
1007void wxGridCellAttrProvider::SetColAttr(wxGridCellAttr *attr,
int col,
bool clear)
1012 m_data->m_colAttrs.SetAttr(attr, col);
1017 m_data->m_cellAttrs.RemoveAttrsFromCol(col);
1020void wxGridCellAttrProvider::UpdateAttrRows(
size_t pos,
int numRows )
1024 m_data->m_cellAttrs.UpdateAttrRows( pos, numRows );
1026 m_data->m_rowAttrs.UpdateAttrRowsOrCols( pos, numRows );
1030void wxGridCellAttrProvider::UpdateAttrCols(
size_t pos,
int numCols )
1034 m_data->m_cellAttrs.UpdateAttrCols( pos, numCols );
1036 m_data->m_colAttrs.UpdateAttrRowsOrCols( pos, numCols );
1040const wxGridColumnHeaderRenderer&
1041wxGridCellAttrProvider::GetColumnHeaderRenderer(
int WXUNUSED(col))
1043 return gs_defaultHeaderRenderers.colRenderer;
1046const wxGridRowHeaderRenderer&
1047wxGridCellAttrProvider::GetRowHeaderRenderer(
int WXUNUSED(row))
1049 return gs_defaultHeaderRenderers.rowRenderer;
1052const wxGridCornerHeaderRenderer& wxGridCellAttrProvider::GetCornerRenderer()
1054 return gs_defaultHeaderRenderers.cornerRenderer;
1061IMPLEMENT_ABSTRACT_CLASS( wxGridTableBase, wxObject )
1063wxGridTableBase::wxGridTableBase()
1066 m_attrProvider = NULL;
1069wxGridTableBase::~wxGridTableBase()
1071 delete m_attrProvider;
1074void wxGridTableBase::SetAttrProvider(wxGridCellAttrProvider *attrProvider)
1076 delete m_attrProvider;
1077 m_attrProvider = attrProvider;
1080bool wxGridTableBase::CanHaveAttributes()
1082 if ( ! GetAttrProvider() )
1085 SetAttrProvider(
new wxGridCellAttrProvider);
1091wxGridCellAttr *wxGridTableBase::GetAttr(
int row,
int col, wxGridCellAttr::wxAttrKind kind)
1093 if ( m_attrProvider )
1094 return m_attrProvider->GetAttr(row, col, kind);
1099void wxGridTableBase::SetAttr(wxGridCellAttr* attr,
int row,
int col)
1101 if ( m_attrProvider )
1104 attr->SetKind(wxGridCellAttr::Cell);
1105 m_attrProvider->SetAttr(attr, row, col);
1115void wxGridTableBase::SetRowAttr(wxGridCellAttr *attr,
int row,
bool clear)
1117 if ( m_attrProvider )
1119 attr->SetKind(wxGridCellAttr::Row);
1120 m_attrProvider->SetRowAttr(attr, row, clear);
1130void wxGridTableBase::SetColAttr(wxGridCellAttr *attr,
int col,
bool clear)
1132 if ( m_attrProvider )
1134 attr->SetKind(wxGridCellAttr::Col);
1135 m_attrProvider->SetColAttr(attr, col, clear);
1145bool wxGridTableBase::InsertRows(
size_t WXUNUSED(pos),
1146 size_t WXUNUSED(numRows) )
1148 wxFAIL_MSG( wxT(
"Called grid table class function InsertRows\nbut your derived table class does not override this function") );
1153bool wxGridTableBase::AppendRows(
size_t WXUNUSED(numRows) )
1155 wxFAIL_MSG( wxT(
"Called grid table class function AppendRows\nbut your derived table class does not override this function"));
1160bool wxGridTableBase::DeleteRows(
size_t WXUNUSED(pos),
1161 size_t WXUNUSED(numRows) )
1163 wxFAIL_MSG( wxT(
"Called grid table class function DeleteRows\nbut your derived table class does not override this function"));
1168bool wxGridTableBase::InsertCols(
size_t WXUNUSED(pos),
1169 size_t WXUNUSED(numCols) )
1171 wxFAIL_MSG( wxT(
"Called grid table class function InsertCols\nbut your derived table class does not override this function"));
1176bool wxGridTableBase::AppendCols(
size_t WXUNUSED(numCols) )
1178 wxFAIL_MSG(wxT(
"Called grid table class function AppendCols\nbut your derived table class does not override this function"));
1183bool wxGridTableBase::DeleteCols(
size_t WXUNUSED(pos),
1184 size_t WXUNUSED(numCols) )
1186 wxFAIL_MSG( wxT(
"Called grid table class function DeleteCols\nbut your derived table class does not override this function"));
1191wxString wxGridTableBase::GetRowLabelValue(
int row )
1202wxString wxGridTableBase::GetColLabelValue(
int col )
1211 for ( n = 1; ; n++ )
1213 s += (wxChar) (wxT(
'A') + (wxChar)(col % 26));
1221 for ( i = 0; i < n; i++ )
1229wxString wxGridTableBase::GetTypeName(
int WXUNUSED(row),
int WXUNUSED(col) )
1231 return wxGRID_VALUE_STRING;
1234bool wxGridTableBase::CanGetValueAs(
int WXUNUSED(row),
int WXUNUSED(col),
1235 const wxString& typeName )
1237 return typeName == wxGRID_VALUE_STRING;
1240bool wxGridTableBase::CanSetValueAs(
int row,
int col,
const wxString& typeName )
1242 return CanGetValueAs(row, col, typeName);
1245long wxGridTableBase::GetValueAsLong(
int WXUNUSED(row),
int WXUNUSED(col) )
1250double wxGridTableBase::GetValueAsDouble(
int WXUNUSED(row),
int WXUNUSED(col) )
1255bool wxGridTableBase::GetValueAsBool(
int WXUNUSED(row),
int WXUNUSED(col) )
1260void wxGridTableBase::SetValueAsLong(
int WXUNUSED(row),
int WXUNUSED(col),
1261 long WXUNUSED(value) )
1265void wxGridTableBase::SetValueAsDouble(
int WXUNUSED(row),
int WXUNUSED(col),
1266 double WXUNUSED(value) )
1270void wxGridTableBase::SetValueAsBool(
int WXUNUSED(row),
int WXUNUSED(col),
1271 bool WXUNUSED(value) )
1275void* wxGridTableBase::GetValueAsCustom(
int WXUNUSED(row),
int WXUNUSED(col),
1276 const wxString& WXUNUSED(typeName) )
1281void wxGridTableBase::SetValueAsCustom(
int WXUNUSED(row),
int WXUNUSED(col),
1282 const wxString& WXUNUSED(typeName),
1283 void* WXUNUSED(value) )
1293wxGridTableMessage::wxGridTableMessage()
1301wxGridTableMessage::wxGridTableMessage( wxGridTableBase *table,
int id,
1302 int commandInt1,
int commandInt2 )
1306 m_comInt1 = commandInt1;
1307 m_comInt2 = commandInt2;
1320wxGridStringTable::wxGridStringTable()
1326wxGridStringTable::wxGridStringTable(
int numRows,
int numCols )
1329 m_numCols = numCols;
1331 m_data.Alloc( numRows );
1334 sa.Alloc( numCols );
1335 sa.Add( wxEmptyString, numCols );
1337 m_data.Add( sa, numRows );
1340wxString wxGridStringTable::GetValue(
int row,
int col )
1342 wxCHECK_MSG( (row >= 0 && row < GetNumberRows()) &&
1343 (col >= 0 && col < GetNumberCols()),
1345 wxT(
"invalid row or column index in wxGridStringTable") );
1347 return m_data[row][col];
1350void wxGridStringTable::SetValue(
int row,
int col,
const wxString& value )
1352 wxCHECK_RET( (row >= 0 && row < GetNumberRows()) &&
1353 (col >= 0 && col < GetNumberCols()),
1354 wxT(
"invalid row or column index in wxGridStringTable") );
1356 m_data[row][col] = value;
1359void wxGridStringTable::Clear()
1362 int numRows, numCols;
1364 numRows = m_data.GetCount();
1367 numCols = m_data[0].GetCount();
1369 for ( row = 0; row < numRows; row++ )
1371 for ( col = 0; col < numCols; col++ )
1373 m_data[row][col] = wxEmptyString;
1379bool wxGridStringTable::InsertRows(
size_t pos,
size_t numRows )
1381 if ( pos >= m_data.size() )
1383 return AppendRows( numRows );
1387 sa.Alloc( m_numCols );
1388 sa.Add( wxEmptyString, m_numCols );
1389 m_data.Insert( sa, pos, numRows );
1393 wxGridTableMessage msg(
this,
1394 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1398 GetView()->ProcessTableMessage( msg );
1404bool wxGridStringTable::AppendRows(
size_t numRows )
1407 if ( m_numCols > 0 )
1409 sa.Alloc( m_numCols );
1410 sa.Add( wxEmptyString, m_numCols );
1413 m_data.Add( sa, numRows );
1417 wxGridTableMessage msg(
this,
1418 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1421 GetView()->ProcessTableMessage( msg );
1427bool wxGridStringTable::DeleteRows(
size_t pos,
size_t numRows )
1429 size_t curNumRows = m_data.GetCount();
1431 if ( pos >= curNumRows )
1433 wxFAIL_MSG( wxString::Format
1435 wxT(
"Called wxGridStringTable::DeleteRows(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu rows"),
1437 (
unsigned long)numRows,
1438 (
unsigned long)curNumRows
1444 if ( numRows > curNumRows - pos )
1446 numRows = curNumRows - pos;
1449 if ( numRows >= curNumRows )
1455 m_data.RemoveAt( pos, numRows );
1460 wxGridTableMessage msg(
this,
1461 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1465 GetView()->ProcessTableMessage( msg );
1471bool wxGridStringTable::InsertCols(
size_t pos,
size_t numCols )
1473 if ( pos >=
static_cast<size_t>(m_numCols) )
1475 return AppendCols( numCols );
1478 if ( !m_colLabels.IsEmpty() )
1480 m_colLabels.Insert( wxEmptyString, pos, numCols );
1482 for (
size_t i = pos; i < pos + numCols; i++ )
1483 m_colLabels[i] = wxGridTableBase::GetColLabelValue( i );
1486 for (
size_t row = 0; row < m_data.size(); row++ )
1488 for (
size_t col = pos; col < pos + numCols; col++ )
1490 m_data[row].Insert( wxEmptyString, col );
1494 m_numCols += numCols;
1498 wxGridTableMessage msg(
this,
1499 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1503 GetView()->ProcessTableMessage( msg );
1509bool wxGridStringTable::AppendCols(
size_t numCols )
1511 for (
size_t row = 0; row < m_data.size(); row++ )
1513 m_data[row].Add( wxEmptyString, numCols );
1516 m_numCols += numCols;
1520 wxGridTableMessage msg(
this,
1521 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1524 GetView()->ProcessTableMessage( msg );
1530bool wxGridStringTable::DeleteCols(
size_t pos,
size_t numCols )
1534 size_t curNumRows = m_data.GetCount();
1535 size_t curNumCols = m_numCols;
1537 if ( pos >= curNumCols )
1539 wxFAIL_MSG( wxString::Format
1541 wxT(
"Called wxGridStringTable::DeleteCols(pos=%lu, N=%lu)\nPos value is invalid for present table with %lu cols"),
1543 (
unsigned long)numCols,
1544 (
unsigned long)curNumCols
1551 colID = GetView()->GetColAt( pos );
1555 if ( numCols > curNumCols - colID )
1557 numCols = curNumCols - colID;
1560 if ( !m_colLabels.IsEmpty() )
1565 int numRemaining = m_colLabels.size() - colID;
1566 if (numRemaining > 0)
1567 m_colLabels.RemoveAt( colID, wxMin(numCols, numRemaining) );
1570 if ( numCols >= curNumCols )
1572 for ( row = 0; row < curNumRows; row++ )
1574 m_data[row].Clear();
1581 for ( row = 0; row < curNumRows; row++ )
1583 m_data[row].RemoveAt( colID, numCols );
1586 m_numCols -= numCols;
1591 wxGridTableMessage msg(
this,
1592 wxGRIDTABLE_NOTIFY_COLS_DELETED,
1596 GetView()->ProcessTableMessage( msg );
1602wxString wxGridStringTable::GetRowLabelValue(
int row )
1604 if ( row > (
int)(m_rowLabels.GetCount()) - 1 )
1608 return wxGridTableBase::GetRowLabelValue( row );
1612 return m_rowLabels[row];
1616wxString wxGridStringTable::GetColLabelValue(
int col )
1618 if ( col > (
int)(m_colLabels.GetCount()) - 1 )
1622 return wxGridTableBase::GetColLabelValue( col );
1626 return m_colLabels[col];
1630void wxGridStringTable::SetRowLabelValue(
int row,
const wxString& value )
1632 if ( row > (
int)(m_rowLabels.GetCount()) - 1 )
1634 int n = m_rowLabels.GetCount();
1637 for ( i = n; i <= row; i++ )
1639 m_rowLabels.Add( wxGridTableBase::GetRowLabelValue(i) );
1643 m_rowLabels[row] = value;
1646void wxGridStringTable::SetColLabelValue(
int col,
const wxString& value )
1648 if ( col > (
int)(m_colLabels.GetCount()) - 1 )
1650 int n = m_colLabels.GetCount();
1653 for ( i = n; i <= col; i++ )
1655 m_colLabels.Add( wxGridTableBase::GetColLabelValue(i) );
1659 m_colLabels[col] = value;
1666BEGIN_EVENT_TABLE(wxGridSubwindow, wxWindow)
1667 EVT_MOUSE_CAPTURE_LOST(wxGridSubwindow::OnMouseCaptureLost)
1670void wxGridSubwindow::OnMouseCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event))
1672 m_owner->CancelMouseCapture();
1675BEGIN_EVENT_TABLE( wxGridRowLabelWindow, wxGridSubwindow )
1676 EVT_PAINT( wxGridRowLabelWindow::OnPaint )
1677 EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel )
1678 EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent )
1681void wxGridRowLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
1692 m_owner->CalcUnscrolledPosition( 0, 0, &x, &y );
1693 wxPoint pt = dc.GetDeviceOrigin();
1694 dc.SetDeviceOrigin( pt.x, pt.y-y );
1696 wxArrayInt rows = m_owner->CalcRowLabelsExposed( GetUpdateRegion() );
1697 m_owner->DrawRowLabels( dc, rows );
1700void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent& event )
1702 m_owner->ProcessRowLabelMouseEvent( event );
1705void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent& event )
1707 if (!m_owner->GetEventHandler()->ProcessEvent( event ))
1713BEGIN_EVENT_TABLE( wxGridColLabelWindow, wxGridSubwindow )
1714 EVT_PAINT( wxGridColLabelWindow::OnPaint )
1715 EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel )
1716 EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent )
1719void wxGridColLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
1730 m_owner->CalcUnscrolledPosition( 0, 0, &x, &y );
1731 wxPoint pt = dc.GetDeviceOrigin();
1732 dc.SetDeviceOrigin( pt.x-x, pt.y );
1734 wxArrayInt cols = m_owner->CalcColLabelsExposed( GetUpdateRegion() );
1735 m_owner->DrawColLabels( dc, cols );
1738void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent& event )
1740 m_owner->ProcessColLabelMouseEvent( event );
1743void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent& event )
1745 if (!m_owner->GetEventHandler()->ProcessEvent( event ))
1751BEGIN_EVENT_TABLE( wxGridCornerLabelWindow, wxGridSubwindow )
1752 EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel )
1753 EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent )
1754 EVT_PAINT( wxGridCornerLabelWindow::OnPaint )
1757void wxGridCornerLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
1761 m_owner->DrawCornerLabel(dc);
1764void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent& event )
1766 m_owner->ProcessCornerLabelMouseEvent( event );
1769void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent& event )
1771 if (!m_owner->GetEventHandler()->ProcessEvent(event))
1777BEGIN_EVENT_TABLE( wxGridWindow, wxGridSubwindow )
1778 EVT_PAINT( wxGridWindow::OnPaint )
1779 EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel )
1780 EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent )
1781 EVT_KEY_DOWN( wxGridWindow::OnKeyDown )
1782 EVT_KEY_UP( wxGridWindow::OnKeyUp )
1783 EVT_CHAR( wxGridWindow::OnChar )
1784 EVT_SET_FOCUS( wxGridWindow::OnFocus )
1785 EVT_KILL_FOCUS( wxGridWindow::OnFocus )
1789void wxGridWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1791 wxPaintDC dc(
this );
1792 m_owner->PrepareDC( dc );
1793 wxRegion reg = GetUpdateRegion();
1794 wxGridCellCoordsArray dirtyCells = m_owner->CalcCellsExposed( reg );
1795 m_owner->DrawGridCellArea( dc, dirtyCells );
1797 m_owner->DrawGridSpace( dc );
1799 m_owner->DrawAllGridLines( dc, reg );
1801 m_owner->DrawHighlight( dc, dirtyCells );
1804void wxGrid::Render( wxDC& dc,
1805 const wxPoint& position,
1807 const wxGridCellCoords& topLeft,
1808 const wxGridCellCoords& bottomRight,
1811 wxCHECK_RET( bottomRight.GetCol() < GetNumberCols(),
1812 "Invalid right column" );
1813 wxCHECK_RET( bottomRight.GetRow() < GetNumberRows(),
1814 "Invalid bottom row" );
1821 wxGridCellCoordsArray selectedCells;
1822 bool hasSelection = IsSelection();
1823 if ( hasSelection && !( style & wxGRID_DRAW_SELECTION ) )
1825 selectedCells = GetSelectionBlockTopLeft();
1827 if ( GetSelectionBlockBottomRight().size() )
1828 selectedCells.Add( GetSelectionBlockBottomRight()[ 0 ] );
1834 wxCoord userOriginX, userOriginY;
1835 dc.GetDeviceOrigin( &userOriginX, &userOriginY );
1838 double scaleUserX, scaleUserY;
1839 dc.GetUserScale( &scaleUserX, &scaleUserY );
1842 wxGridCellCoords leftTop( topLeft ), rightBottom( bottomRight );
1843 if ( leftTop.GetCol() < 0 )
1845 if ( leftTop.GetRow() < 0 )
1847 if ( rightBottom.GetCol() < 0 )
1848 rightBottom.SetCol(GetNumberCols() - 1);
1849 if ( rightBottom.GetRow() < 0 )
1850 rightBottom.SetRow(GetNumberRows() - 1);
1853 wxPoint pointOffSet;
1855 wxGridCellCoordsArray renderCells;
1856 wxArrayInt arrayCols;
1857 wxArrayInt arrayRows;
1859 GetRenderSizes( leftTop, rightBottom,
1860 pointOffSet, sizeGrid,
1862 arrayCols, arrayRows );
1865 if ( style & wxGRID_DRAW_ROWS_HEADER )
1866 sizeGrid.x += GetRowLabelSize();
1867 if ( style & wxGRID_DRAW_COLS_HEADER )
1868 sizeGrid.y += GetColLabelSize();
1871 wxPoint positionRender = GetRenderPosition( dc, position );
1873 wxCoord originX = dc.LogicalToDeviceX( positionRender.x );
1874 wxCoord originY = dc.LogicalToDeviceY( positionRender.y );
1876 dc.SetDeviceOrigin( originX, originY );
1878 SetRenderScale( dc, positionRender, size, sizeGrid );
1881 if ( GetRowLabelSize() > 0 && ( style & wxGRID_DRAW_ROWS_HEADER ) )
1883 if ( style & wxGRID_DRAW_COLS_HEADER )
1885 DrawCornerLabel( dc );
1886 originY += dc.LogicalToDeviceYRel( GetColLabelSize() );
1889 originY -= dc.LogicalToDeviceYRel( pointOffSet.y );
1890 dc.SetDeviceOrigin( originX, originY );
1892 DrawRowLabels( dc, arrayRows );
1895 if ( style & wxGRID_DRAW_COLS_HEADER )
1896 originY -= dc.LogicalToDeviceYRel( GetColLabelSize() );
1898 originY += dc.LogicalToDeviceYRel( pointOffSet.y );
1900 originX += dc.LogicalToDeviceXRel( GetRowLabelSize() );
1904 originX -= dc.LogicalToDeviceXRel( pointOffSet.x );
1908 if ( style & wxGRID_DRAW_COLS_HEADER )
1910 dc.SetDeviceOrigin( originX, originY );
1911 DrawColLabels( dc, arrayCols );
1913 originY += dc.LogicalToDeviceYRel( GetColLabelSize() );
1917 originY -= dc.LogicalToDeviceYRel( pointOffSet.y );
1918 dc.SetDeviceOrigin( originX, originY );
1921 dc.SetBrush( GetDefaultCellBackgroundColour() );
1922 dc.SetPen( *wxTRANSPARENT_PEN );
1924 wxSize sizeCells( sizeGrid );
1925 if ( style & wxGRID_DRAW_ROWS_HEADER )
1926 sizeCells.x -= GetRowLabelSize();
1927 if ( style & wxGRID_DRAW_COLS_HEADER )
1928 sizeCells.y -= GetColLabelSize();
1930 dc.DrawRectangle( pointOffSet, sizeCells );
1933 DrawGridCellArea( dc, renderCells );
1936 if ( style & wxGRID_DRAW_CELL_LINES )
1938 wxRegion regionClip( pointOffSet.x, pointOffSet.y,
1939 sizeCells.x, sizeCells.y );
1941 DrawRangeGridLines(dc, regionClip, renderCells[0], renderCells.Last());
1945 DoRenderBox( dc, style,
1946 pointOffSet, sizeCells,
1947 leftTop, rightBottom );
1950 dc.SetDeviceOrigin( userOriginX, userOriginY );
1951 dc.SetUserScale( scaleUserX, scaleUserY );
1953 if ( selectedCells.size() && !( style & wxGRID_DRAW_SELECTION ) )
1955 SelectBlock( selectedCells[ 0 ].GetRow(),
1956 selectedCells[ 0 ].GetCol(),
1957 selectedCells[ selectedCells.size() -1 ].GetRow(),
1958 selectedCells[ selectedCells.size() -1 ].GetCol() );
1963wxGrid::SetRenderScale(wxDC& dc,
1964 const wxPoint& pos,
const wxSize& size,
1965 const wxSize& sizeGrid )
1967 double scaleX, scaleY;
1970 if ( size.GetWidth() != wxDefaultSize.GetWidth() )
1971 sizeTemp.SetWidth( size.GetWidth() );
1973 sizeTemp.SetWidth( dc.DeviceToLogicalXRel( dc.GetSize().GetWidth() )
1976 if ( size.GetHeight() != wxDefaultSize.GetHeight() )
1977 sizeTemp.SetHeight( size.GetHeight() );
1979 sizeTemp.SetHeight( dc.DeviceToLogicalYRel( dc.GetSize().GetHeight() )
1982 scaleX = (double)( (
double) sizeTemp.GetWidth() / (double) sizeGrid.GetWidth() );
1983 scaleY = (double)( (
double) sizeTemp.GetHeight() / (double) sizeGrid.GetHeight() );
1985 dc.SetUserScale( wxMin( scaleX, scaleY), wxMin( scaleX, scaleY ) );
1989void wxGrid::GetRenderSizes(
const wxGridCellCoords& topLeft,
1990 const wxGridCellCoords& bottomRight,
1991 wxPoint& pointOffSet, wxSize& sizeGrid,
1992 wxGridCellCoordsArray& renderCells,
1993 wxArrayInt& arrayCols, wxArrayInt& arrayRows )
1997 sizeGrid.SetWidth( 0 );
1998 sizeGrid.SetHeight( 0 );
2002 wxGridSizesInfo sizeinfo = GetColSizes();
2003 for ( col = 0; col <= bottomRight.GetCol(); col++ )
2005 if ( col < topLeft.GetCol() )
2007 pointOffSet.x += sizeinfo.GetSize( col );
2011 for ( row = topLeft.GetRow(); row <= bottomRight.GetRow(); row++ )
2013 renderCells.Add( wxGridCellCoords( row, col ));
2014 arrayRows.Add( row );
2016 arrayCols.Add( col );
2017 sizeGrid.x += sizeinfo.GetSize( col );
2021 sizeinfo = GetRowSizes();
2022 for ( row = 0; row <= bottomRight.GetRow(); row++ )
2024 if ( row < topLeft.GetRow() )
2025 pointOffSet.y += sizeinfo.GetSize( row );
2027 sizeGrid.y += sizeinfo.GetSize( row );
2033wxPoint wxGrid::GetRenderPosition( wxDC& dc,
const wxPoint& position )
2035 wxPoint positionRender( position );
2037 if ( !positionRender.IsFullySpecified() )
2039 if ( positionRender.x == wxDefaultPosition.x )
2040 positionRender.x = dc.MaxX();
2042 if ( positionRender.y == wxDefaultPosition.y )
2043 positionRender.y = dc.MaxY();
2046 return positionRender;
2051void wxGrid::DoRenderBox( wxDC& dc,
const int& style,
2052 const wxPoint& pointOffSet,
2053 const wxSize& sizeCells,
2054 const wxGridCellCoords& topLeft,
2055 const wxGridCellCoords& bottomRight )
2057 if ( !( style & wxGRID_DRAW_BOX_RECT ) )
2060 int bottom = pointOffSet.y + sizeCells.GetY(),
2061 right = pointOffSet.x + sizeCells.GetX() - 1;
2064 if ( !( style & wxGRID_DRAW_COLS_HEADER ) )
2066 int left = pointOffSet.x;
2067 left += ( style & wxGRID_DRAW_COLS_HEADER )
2068 ? - GetRowLabelSize() : 0;
2069 dc.SetPen( GetRowGridLinePen( topLeft.GetRow() ) );
2077 dc.SetPen( GetRowGridLinePen( bottomRight.GetRow() ) );
2078 dc.DrawLine( pointOffSet.x, bottom - 1, right, bottom - 1 );
2081 if ( !( style & wxGRID_DRAW_ROWS_HEADER ) )
2083 int top = pointOffSet.y;
2084 top += ( style & wxGRID_DRAW_COLS_HEADER )
2085 ? - GetColLabelSize() : 0;
2086 dc.SetPen( GetColGridLinePen( topLeft.GetCol() ) );
2087 dc.DrawLine( pointOffSet.x -1,
2094 dc.SetPen( GetColGridLinePen( bottomRight.GetCol() ) );
2095 dc.DrawLine( right, pointOffSet.y, right, bottom - 1 );
2098void wxGridWindow::ScrollWindow(
int dx,
int dy,
const wxRect *rect )
2100 wxWindow::ScrollWindow( dx, dy, rect );
2101 m_owner->GetGridRowLabelWindow()->ScrollWindow( 0, dy, rect );
2102 m_owner->GetGridColLabelWindow()->ScrollWindow( dx, 0, rect );
2105void wxGridWindow::OnMouseEvent( wxMouseEvent& event )
2107 if (event.ButtonDown(wxMOUSE_BTN_LEFT) && FindFocus() !=
this)
2110 m_owner->ProcessGridCellMouseEvent( event );
2113void wxGridWindow::OnMouseWheel( wxMouseEvent& event )
2115 if (!m_owner->GetEventHandler()->ProcessEvent( event ))
2122void wxGridWindow::OnKeyDown( wxKeyEvent& event )
2124 if ( !m_owner->GetEventHandler()->ProcessEvent( event ) )
2128void wxGridWindow::OnKeyUp( wxKeyEvent& event )
2130 if ( !m_owner->GetEventHandler()->ProcessEvent( event ) )
2134void wxGridWindow::OnChar( wxKeyEvent& event )
2136 if ( !m_owner->GetEventHandler()->ProcessEvent( event ) )
2140void wxGridWindow::OnEraseBackground( wxEraseEvent& WXUNUSED(event) )
2144void wxGridWindow::OnFocus(wxFocusEvent& event)
2148 if ( m_owner->IsSelection() )
2162 const wxGridCellCoords cursorCoords(m_owner->GetGridCursorRow(),
2163 m_owner->GetGridCursorCol());
2164 const wxRect cursor =
2165 m_owner->BlockToDeviceRect(cursorCoords, cursorCoords);
2166 Refresh(
true, &cursor);
2169 if ( !m_owner->GetEventHandler()->ProcessEvent( event ) )
2173#define internalXToCol(x) XToCol(x, true)
2174#define internalYToRow(y) YToRow(y, true)
2178BEGIN_EVENT_TABLE( wxGrid, wxScrolledWindow )
2179 EVT_PAINT( wxGrid::OnPaint )
2180 EVT_SIZE( wxGrid::OnSize )
2181 EVT_KEY_DOWN( wxGrid::OnKeyDown )
2182 EVT_KEY_UP( wxGrid::OnKeyUp )
2183 EVT_CHAR ( wxGrid::OnChar )
2185 EVT_COMMAND(wxID_ANY, wxEVT_GRID_HIDE_EDITOR, wxGrid::OnHideEditor )
2188bool wxGrid::Create(wxWindow *parent, wxWindowID
id,
2189 const wxPoint& pos, const wxSize& size,
2190 long style, const wxString&
name)
2192 if (!wxScrolledWindow::Create(parent,
id, pos, size,
2193 style | wxWANTS_CHARS,
name))
2196 m_colMinWidths = wxLongToLongHashMap(GRID_HASH_SIZE);
2197 m_rowMinHeights = wxLongToLongHashMap(GRID_HASH_SIZE);
2200 SetInitialSize(size);
2209 m_winCapture->ReleaseMouse();
2214 HideCellEditControl();
2217 SetTargetWindow(
this);
2219 wxSafeDecRef(m_defaultCellAttr);
2221#ifdef DEBUG_ATTR_CACHE
2222 size_t total = gs_nAttrCacheHits + gs_nAttrCacheMisses;
2223 wxPrintf(wxT(
"wxGrid attribute cache statistics: "
2224 "total: %u, hits: %u (%u%%)\n"),
2225 total, gs_nAttrCacheHits,
2226 total ? (gs_nAttrCacheHits*100) / total : 0);
2233 else if ( m_table && m_table->GetView() ==
this )
2234 m_table->SetView(NULL);
2236 delete m_typeRegistry;
2239 delete m_setFixedRows;
2240 delete m_setFixedCols;
2249#define _USE_VISATTR 0
2251void wxGrid::Create()
2254 m_typeRegistry =
new wxGridTypeRegistry;
2256 m_cellEditCtrlEnabled =
false;
2258 m_defaultCellAttr =
new wxGridCellAttr();
2261 m_defaultCellAttr->SetDefAttr(m_defaultCellAttr);
2262 m_defaultCellAttr->SetKind(wxGridCellAttr::Default);
2263 m_defaultCellAttr->SetFont(GetFont());
2264 m_defaultCellAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_TOP);
2265 m_defaultCellAttr->SetRenderer(
new wxGridCellStringRenderer);
2266 m_defaultCellAttr->SetEditor(
new wxGridCellTextEditor);
2269 wxVisualAttributes gva = wxListBox::GetClassDefaultAttributes();
2270 wxVisualAttributes lva = wxPanel::GetClassDefaultAttributes();
2272 m_defaultCellAttr->SetTextColour(gva.colFg);
2273 m_defaultCellAttr->SetBackgroundColour(gva.colBg);
2276 m_defaultCellAttr->SetTextColour(
2277 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
2278 m_defaultCellAttr->SetBackgroundColour(
2279 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
2284 m_currentCellCoords = wxGridNoCellCoords;
2287 m_rowLabelWin =
new wxGridRowLabelWindow(
this);
2288 CreateColumnWindow();
2289 m_cornerLabelWin =
new wxGridCornerLabelWindow(
this);
2290 m_gridWin =
new wxGridWindow(
this );
2292 SetTargetWindow( m_gridWin );
2295 wxColour gfg = gva.colFg;
2296 wxColour gbg = gva.colBg;
2297 wxColour lfg = lva.colFg;
2298 wxColour lbg = lva.colBg;
2300 wxColour gfg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
2301 wxColour gbg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
2302 wxColour lfg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
2303 wxColour lbg = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
2306 m_cornerLabelWin->SetOwnForegroundColour(lfg);
2307 m_cornerLabelWin->SetOwnBackgroundColour(lbg);
2308 m_rowLabelWin->SetOwnForegroundColour(lfg);
2309 m_rowLabelWin->SetOwnBackgroundColour(lbg);
2310 m_colWindow->SetOwnForegroundColour(lfg);
2311 m_colWindow->SetOwnBackgroundColour(lbg);
2313 m_gridWin->SetOwnForegroundColour(gfg);
2314 m_gridWin->SetOwnBackgroundColour(gbg);
2316 m_labelBackgroundColour = m_rowLabelWin->GetBackgroundColour();
2317 m_labelTextColour = m_rowLabelWin->GetForegroundColour();
2321 m_defaultRowHeight = m_gridWin->GetCharHeight();
2322#if defined(__WXMOTIF__) || defined(__WXGTK__)
2323 m_defaultRowHeight += 8;
2325 m_defaultRowHeight += 4;
2330void wxGrid::CreateColumnWindow()
2332 if ( m_useNativeHeader )
2334 m_colWindow =
new wxGridHeaderCtrl(
this);
2335 m_colLabelHeight = m_colWindow->GetBestSize().y;
2339 m_colWindow =
new wxGridColLabelWindow(
this);
2340 m_colLabelHeight = WXGRID_DEFAULT_COL_LABEL_HEIGHT;
2344bool wxGrid::CreateGrid(
int numRows,
int numCols,
2345 wxGridSelectionModes selmode )
2347 wxCHECK_MSG( !m_created,
2349 wxT(
"wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
2351 return SetTable(
new wxGridStringTable(numRows, numCols),
true, selmode);
2354void wxGrid::SetSelectionMode(wxGridSelectionModes selmode)
2356 wxCHECK_RET( m_created,
2357 wxT(
"Called wxGrid::SetSelectionMode() before calling CreateGrid()") );
2359 m_selection->SetSelectionMode( selmode );
2362wxGrid::wxGridSelectionModes wxGrid::GetSelectionMode()
const
2364 wxCHECK_MSG( m_created, wxGridSelectCells,
2365 wxT(
"Called wxGrid::GetSelectionMode() before calling CreateGrid()") );
2367 return m_selection->GetSelectionMode();
2371wxGrid::SetTable(wxGridTableBase *table,
2373 wxGrid::wxGridSelectionModes selmode )
2375 bool checkSelection =
false;
2383 m_table->SetView(0);
2389 wxDELETE(m_selection);
2394 checkSelection =
true;
2397 m_colWidths.Empty();
2398 m_colRights.Empty();
2399 m_rowHeights.Empty();
2400 m_rowBottoms.Empty();
2405 m_numRows = table->GetNumberRows();
2406 m_numCols = table->GetNumberCols();
2409 m_table->SetView(
this );
2410 m_ownTable = takeOwnership;
2414 if ( m_useNativeHeader )
2415 GetGridColHeader()->SetColumnCount(m_numCols);
2417 m_selection =
new wxGridSelection(
this, selmode );
2423 m_selectedBlockCorner = wxGridNoCellCoords;
2424 m_currentCellCoords =
2425 wxGridCellCoords(wxMin(m_numRows, m_currentCellCoords.GetRow()),
2426 wxMin(m_numCols, m_currentCellCoords.GetCol()));
2427 if (m_selectedBlockTopLeft.GetRow() >= m_numRows ||
2428 m_selectedBlockTopLeft.GetCol() >= m_numCols)
2430 m_selectedBlockTopLeft = wxGridNoCellCoords;
2431 m_selectedBlockBottomRight = wxGridNoCellCoords;
2434 m_selectedBlockBottomRight =
2435 wxGridCellCoords(wxMin(m_numRows,
2436 m_selectedBlockBottomRight.GetRow()),
2438 m_selectedBlockBottomRight.GetCol()));
2445 InvalidateBestSize();
2454 m_cornerLabelWin = NULL;
2455 m_rowLabelWin = NULL;
2463 m_defaultCellAttr = NULL;
2464 m_typeRegistry = NULL;
2465 m_winCapture = NULL;
2467 m_rowLabelWidth = WXGRID_DEFAULT_ROW_LABEL_WIDTH;
2468 m_colLabelHeight = WXGRID_DEFAULT_COL_LABEL_HEIGHT;
2471 m_setFixedCols = NULL;
2474 m_attrCache.row = -1;
2475 m_attrCache.col = -1;
2476 m_attrCache.attr = NULL;
2478 m_labelFont = GetFont();
2479 m_labelFont.SetWeight( wxBOLD );
2481 m_rowLabelHorizAlign = wxALIGN_CENTRE;
2482 m_rowLabelVertAlign = wxALIGN_CENTRE;
2484 m_colLabelHorizAlign = wxALIGN_CENTRE;
2485 m_colLabelVertAlign = wxALIGN_CENTRE;
2486 m_colLabelTextOrientation = wxHORIZONTAL;
2488 m_defaultColWidth = WXGRID_DEFAULT_COL_WIDTH;
2489 m_defaultRowHeight = 0;
2491 m_minAcceptableColWidth = WXGRID_MIN_COL_WIDTH;
2492 m_minAcceptableRowHeight = WXGRID_MIN_ROW_HEIGHT;
2494 m_gridLineColour = wxColour( 192,192,192 );
2495 m_gridLinesEnabled =
true;
2496 m_gridLinesClipHorz =
2497 m_gridLinesClipVert =
true;
2498 m_cellHighlightColour = *wxBLACK;
2499 m_cellHighlightPenWidth = 2;
2500 m_cellHighlightROPenWidth = 1;
2502 m_canDragColMove =
false;
2504 m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
2505 m_winCapture = NULL;
2506 m_canDragRowSize =
true;
2507 m_canDragColSize =
true;
2508 m_canDragGridSize =
true;
2509 m_canDragCell =
false;
2511 m_dragRowOrCol = -1;
2512 m_isDragging =
false;
2513 m_startDragPos = wxDefaultPosition;
2515 m_sortCol = wxNOT_FOUND;
2516 m_sortIsAscending =
true;
2519 m_nativeColumnLabels =
false;
2521 m_waitForSlowClick =
false;
2523 m_rowResizeCursor = wxCursor( wxCURSOR_SIZENS );
2524 m_colResizeCursor = wxCursor( wxCURSOR_SIZEWE );
2526 m_currentCellCoords = wxGridNoCellCoords;
2528 m_selectedBlockTopLeft =
2529 m_selectedBlockBottomRight =
2530 m_selectedBlockCorner = wxGridNoCellCoords;
2532 m_selectionBackground = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
2533 m_selectionForeground = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
2537 m_inOnKeyDown =
false;
2546 m_xScrollPixelsPerLine = GRID_SCROLL_LINE_X;
2547 m_yScrollPixelsPerLine = GRID_SCROLL_LINE_Y;
2549 m_tabBehaviour = Tab_Stop;
2563void wxGrid::InitRowHeights()
2565 m_rowHeights.Empty();
2566 m_rowBottoms.Empty();
2568 m_rowHeights.Alloc( m_numRows );
2569 m_rowBottoms.Alloc( m_numRows );
2571 m_rowHeights.Add( m_defaultRowHeight, m_numRows );
2574 for (
int i = 0; i < m_numRows; i++ )
2576 rowBottom += m_defaultRowHeight;
2577 m_rowBottoms.Add( rowBottom );
2581void wxGrid::InitColWidths()
2583 m_colWidths.Empty();
2584 m_colRights.Empty();
2586 m_colWidths.Alloc( m_numCols );
2587 m_colRights.Alloc( m_numCols );
2589 m_colWidths.Add( m_defaultColWidth, m_numCols );
2591 for (
int i = 0; i < m_numCols; i++ )
2593 int colRight = ( GetColPos( i ) + 1 ) * m_defaultColWidth;
2594 m_colRights.Add( colRight );
2598int wxGrid::GetColWidth(
int col)
const
2600 if ( m_colWidths.IsEmpty() )
2601 return m_defaultColWidth;
2604 return m_colWidths[col] > 0 ? m_colWidths[col] : 0;
2607int wxGrid::GetColLeft(
int col)
const
2609 if ( m_colRights.IsEmpty() )
2610 return GetColPos( col ) * m_defaultColWidth;
2612 return m_colRights[col] - GetColWidth(col);
2615int wxGrid::GetColRight(
int col)
const
2617 return m_colRights.IsEmpty() ? (GetColPos( col ) + 1) * m_defaultColWidth
2621int wxGrid::GetRowHeight(
int row)
const
2624 if ( m_rowHeights.IsEmpty() )
2625 return m_defaultRowHeight;
2628 return m_rowHeights[row] > 0 ? m_rowHeights[row] : 0;
2631int wxGrid::GetRowTop(
int row)
const
2633 if ( m_rowBottoms.IsEmpty() )
2634 return row * m_defaultRowHeight;
2636 return m_rowBottoms[row] - GetRowHeight(row);
2639int wxGrid::GetRowBottom(
int row)
const
2641 return m_rowBottoms.IsEmpty() ? (row + 1) * m_defaultRowHeight
2642 : m_rowBottoms[row];
2645void wxGrid::CalcDimensions()
2648 int w = m_numCols > 0 ? GetColRight(GetColAt(m_numCols - 1)) : 0;
2649 int h = m_numRows > 0 ? GetRowBottom(m_numRows - 1) : 0;
2655 if ( IsCellEditControlShown() )
2658 int r = m_currentCellCoords.GetRow();
2659 int c = m_currentCellCoords.GetCol();
2660 int x = GetColLeft(c);
2661 int y = GetRowTop(r);
2664 wxGridCellAttr* attr = GetCellAttr(r, c);
2665 wxGridCellEditor* editor = attr->GetEditor(
this, r, c);
2666 editor->GetControl()->GetSize(&w2, &h2);
2679 GetViewStart( &x, &y );
2683 x = wxMax( w - 1, 0 );
2685 y = wxMax( h - 1, 0 );
2688 m_gridWin->SetVirtualSize(w, h);
2697wxSize wxGrid::GetSizeAvailableForScrollTarget(
const wxSize& size)
2699 wxSize sizeGridWin(size);
2700 sizeGridWin.x -= m_rowLabelWidth;
2701 sizeGridWin.y -= m_colLabelHeight;
2706void wxGrid::CalcWindowSizes()
2710 if ( m_cornerLabelWin == NULL )
2714 GetClientSize( &cw, &ch );
2718 int gw = cw - m_rowLabelWidth;
2719 int gh = ch - m_colLabelHeight;
2725 if ( m_cornerLabelWin && m_cornerLabelWin->IsShown() )
2726 m_cornerLabelWin->SetSize( 0, 0, m_rowLabelWidth, m_colLabelHeight );
2728 if ( m_colWindow && m_colWindow->IsShown() )
2729 m_colWindow->SetSize( m_rowLabelWidth, 0, gw, m_colLabelHeight );
2731 if ( m_rowLabelWin && m_rowLabelWin->IsShown() )
2732 m_rowLabelWin->SetSize( 0, m_colLabelHeight, m_rowLabelWidth, gh );
2734 if ( m_gridWin && m_gridWin->IsShown() )
2735 m_gridWin->SetSize( m_rowLabelWidth, m_colLabelHeight, gw, gh );
2741bool wxGrid::Redimension( wxGridTableMessage& msg )
2744 bool result =
false;
2755 HideCellEditControl();
2757 switch ( msg.GetId() )
2759 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED:
2761 size_t pos = msg.GetCommandInt();
2762 int numRows = msg.GetCommandInt2();
2764 m_numRows += numRows;
2766 if ( !m_rowHeights.IsEmpty() )
2768 m_rowHeights.Insert( m_defaultRowHeight, pos, numRows );
2769 m_rowBottoms.Insert( 0, pos, numRows );
2773 bottom = m_rowBottoms[pos - 1];
2775 for ( i = pos; i < m_numRows; i++ )
2777 bottom += m_rowHeights[i];
2778 m_rowBottoms[i] = bottom;
2782 if ( m_currentCellCoords == wxGridNoCellCoords )
2787 SetCurrentCell( 0, 0 );
2791 m_selection->UpdateRows( pos, numRows );
2792 wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider();
2794 attrProvider->UpdateAttrRows( pos, numRows );
2796 if ( !GetBatchCount() )
2799 m_rowLabelWin->Refresh();
2805 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED:
2807 int numRows = msg.GetCommandInt();
2808 int oldNumRows = m_numRows;
2809 m_numRows += numRows;
2811 if ( !m_rowHeights.IsEmpty() )
2813 m_rowHeights.Add( m_defaultRowHeight, numRows );
2814 m_rowBottoms.Add( 0, numRows );
2817 if ( oldNumRows > 0 )
2818 bottom = m_rowBottoms[oldNumRows - 1];
2820 for ( i = oldNumRows; i < m_numRows; i++ )
2822 bottom += m_rowHeights[i];
2823 m_rowBottoms[i] = bottom;
2827 if ( m_currentCellCoords == wxGridNoCellCoords )
2832 SetCurrentCell( 0, 0 );
2835 if ( !GetBatchCount() )
2838 m_rowLabelWin->Refresh();
2844 case wxGRIDTABLE_NOTIFY_ROWS_DELETED:
2846 size_t pos = msg.GetCommandInt();
2847 int numRows = msg.GetCommandInt2();
2848 m_numRows -= numRows;
2850 if ( !m_rowHeights.IsEmpty() )
2852 m_rowHeights.RemoveAt( pos, numRows );
2853 m_rowBottoms.RemoveAt( pos, numRows );
2856 for ( i = 0; i < m_numRows; i++ )
2858 h += m_rowHeights[i];
2859 m_rowBottoms[i] = h;
2865 m_currentCellCoords = wxGridNoCellCoords;
2869 if ( m_currentCellCoords.GetRow() >= m_numRows )
2870 m_currentCellCoords.Set( 0, 0 );
2874 m_selection->UpdateRows( pos, -((
int)numRows) );
2875 wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider();
2878 attrProvider->UpdateAttrRows( pos, -((
int)numRows) );
2887 if ( !GetNumberRows() )
2888 attrProvider->UpdateAttrCols( 0, -GetNumberCols() );
2892 if ( !GetBatchCount() )
2895 m_rowLabelWin->Refresh();
2901 case wxGRIDTABLE_NOTIFY_COLS_INSERTED:
2903 size_t pos = msg.GetCommandInt();
2904 int numCols = msg.GetCommandInt2();
2905 m_numCols += numCols;
2907 if ( m_useNativeHeader )
2908 GetGridColHeader()->SetColumnCount(m_numCols);
2910 if ( !m_colAt.IsEmpty() )
2913 for ( i = 0; i < m_numCols - numCols; i++ )
2915 if ( m_colAt[i] >= (
int)pos )
2916 m_colAt[i] += numCols;
2919 m_colAt.Insert( pos, pos, numCols );
2922 for ( i = pos + 1; i < (int)pos + numCols; i++ )
2928 if ( !m_colWidths.IsEmpty() )
2930 m_colWidths.Insert( m_defaultColWidth, pos, numCols );
2931 m_colRights.Insert( 0, pos, numCols );
2935 right = m_colRights[GetColAt( pos - 1 )];
2938 for ( colPos = pos; colPos < m_numCols; colPos++ )
2940 i = GetColAt( colPos );
2942 right += m_colWidths[i];
2943 m_colRights[i] = right;
2947 if ( m_currentCellCoords == wxGridNoCellCoords )
2952 SetCurrentCell( 0, 0 );
2956 m_selection->UpdateCols( pos, numCols );
2957 wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider();
2959 attrProvider->UpdateAttrCols( pos, numCols );
2960 if ( !GetBatchCount() )
2963 m_colWindow->Refresh();
2969 case wxGRIDTABLE_NOTIFY_COLS_APPENDED:
2971 int numCols = msg.GetCommandInt();
2972 int oldNumCols = m_numCols;
2973 m_numCols += numCols;
2975 if ( !m_colAt.IsEmpty() )
2977 m_colAt.Add( 0, numCols );
2980 for ( i = oldNumCols; i < m_numCols; i++ )
2986 if ( !m_colWidths.IsEmpty() )
2988 m_colWidths.Add( m_defaultColWidth, numCols );
2989 m_colRights.Add( 0, numCols );
2992 if ( oldNumCols > 0 )
2993 right = m_colRights[GetColAt( oldNumCols - 1 )];
2996 for ( colPos = oldNumCols; colPos < m_numCols; colPos++ )
2998 i = GetColAt( colPos );
3000 right += m_colWidths[i];
3001 m_colRights[i] = right;
3008 if ( m_useNativeHeader )
3009 GetGridColHeader()->SetColumnCount(m_numCols);
3011 if ( m_currentCellCoords == wxGridNoCellCoords )
3016 SetCurrentCell( 0, 0 );
3018 if ( !GetBatchCount() )
3021 m_colWindow->Refresh();
3027 case wxGRIDTABLE_NOTIFY_COLS_DELETED:
3029 size_t pos = msg.GetCommandInt();
3030 int numCols = msg.GetCommandInt2();
3031 m_numCols -= numCols;
3032 if ( m_useNativeHeader )
3033 GetGridColHeader()->SetColumnCount(m_numCols);
3035 if ( !m_colAt.IsEmpty() )
3037 int colID = GetColAt( pos );
3039 m_colAt.RemoveAt( pos, numCols );
3043 for ( colPos = 0; colPos < m_numCols; colPos++ )
3045 if ( m_colAt[colPos] > colID )
3046 m_colAt[colPos] -= numCols;
3050 if ( !m_colWidths.IsEmpty() )
3052 m_colWidths.RemoveAt( pos, numCols );
3053 m_colRights.RemoveAt( pos, numCols );
3057 for ( colPos = 0; colPos < m_numCols; colPos++ )
3059 i = GetColAt( colPos );
3061 w += m_colWidths[i];
3068 m_currentCellCoords = wxGridNoCellCoords;
3072 if ( m_currentCellCoords.GetCol() >= m_numCols )
3073 m_currentCellCoords.Set( 0, 0 );
3077 m_selection->UpdateCols( pos, -((
int)numCols) );
3078 wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider();
3081 attrProvider->UpdateAttrCols( pos, -((
int)numCols) );
3090 if ( !GetNumberCols() )
3091 attrProvider->UpdateAttrRows( 0, -GetNumberRows() );
3095 if ( !GetBatchCount() )
3098 m_colWindow->Refresh();
3105 InvalidateBestSize();
3107 if (result && !GetBatchCount() )
3108 m_gridWin->Refresh();
3113wxArrayInt wxGrid::CalcRowLabelsExposed(
const wxRegion& reg )
const
3115 wxRegionIterator iter( reg );
3118 wxArrayInt rowlabels;
3130#if defined(__WXMOTIF__)
3132 m_gridWin->GetClientSize( &cw, &ch );
3133 if ( r.GetTop() > ch )
3135 r.SetBottom( wxMin( r.GetBottom(), ch ) );
3141 CalcUnscrolledPosition( 0, r.GetTop(), &dummy, &top );
3142 CalcUnscrolledPosition( 0, r.GetBottom(), &dummy, &bottom );
3147 for ( row = internalYToRow(top); row < m_numRows; row++ )
3149 if ( GetRowBottom(row) < top )
3152 if ( GetRowTop(row) > bottom )
3155 rowlabels.Add( row );
3164wxArrayInt wxGrid::CalcColLabelsExposed(
const wxRegion& reg )
const
3166 wxRegionIterator iter( reg );
3169 wxArrayInt colLabels;
3181#if defined(__WXMOTIF__)
3183 m_gridWin->GetClientSize( &cw, &ch );
3184 if ( r.GetLeft() > cw )
3186 r.SetRight( wxMin( r.GetRight(), cw ) );
3192 CalcUnscrolledPosition( r.GetLeft(), 0, &left, &dummy );
3193 CalcUnscrolledPosition( r.GetRight(), 0, &right, &dummy );
3199 for ( colPos = GetColPos( internalXToCol(left) ); colPos < m_numCols; colPos++ )
3201 col = GetColAt( colPos );
3203 if ( GetColRight(col) < left )
3206 if ( GetColLeft(col) > right )
3209 colLabels.Add( col );
3218wxGridCellCoordsArray wxGrid::CalcCellsExposed(
const wxRegion& reg )
const
3222 wxGridCellCoordsArray cellsExposed;
3224 int left, top, right, bottom;
3225 for ( wxRegionIterator iter(reg); iter; ++iter )
3231 if ( !r.GetHeight() )
3239#if defined(__WXMOTIF__)
3241 m_gridWin->GetClientSize( &cw, &ch );
3242 if ( r.GetTop() > ch ) r.SetTop( 0 );
3243 if ( r.GetLeft() > cw ) r.SetLeft( 0 );
3244 r.SetRight( wxMin( r.GetRight(), cw ) );
3245 r.SetBottom( wxMin( r.GetBottom(), ch ) );
3250 CalcUnscrolledPosition( r.GetLeft(), r.GetTop(), &left, &top );
3251 CalcUnscrolledPosition( r.GetRight(), r.GetBottom(), &right, &bottom );
3255 for (
int row = internalYToRow(top); row < m_numRows; row++ )
3257 if ( GetRowBottom(row) <= top )
3260 if ( GetRowTop(row) > bottom )
3269 for (
int pos = XToPos(left); pos <= XToPos(right); pos++ )
3270 cols.push_back(GetColAt(pos));
3277 const size_t count = cols.size();
3278 for (
size_t n = 0; n < count; n++ )
3279 cellsExposed.Add(wxGridCellCoords(row, cols[n]));
3283 return cellsExposed;
3287void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
3290 wxPoint pos( event.GetPosition() );
3291 CalcUnscrolledPosition( pos.x, pos.y, &x, &y );
3293 if ( event.Dragging() )
3296 m_isDragging =
true;
3298 if ( event.LeftIsDown() )
3300 switch ( m_cursorMode )
3302 case WXGRID_CURSOR_RESIZE_ROW:
3304 int cw, ch, left, dummy;
3305 m_gridWin->GetClientSize( &cw, &ch );
3306 CalcUnscrolledPosition( 0, 0, &left, &dummy );
3308 wxClientDC dc( m_gridWin );
3311 GetRowTop(m_dragRowOrCol) +
3312 GetRowMinimalHeight(m_dragRowOrCol) );
3313 dc.SetLogicalFunction(wxINVERT);
3314 if ( m_dragLastPos >= 0 )
3316 dc.DrawLine( left, m_dragLastPos, left+cw, m_dragLastPos );
3318 dc.DrawLine( left, y, left+cw, y );
3323 case WXGRID_CURSOR_SELECT_ROW:
3325 if ( (row = YToRow( y )) >= 0 )
3328 m_selection->SelectRow(row, event);
3342 if ( m_isDragging && (event.Entering() || event.Leaving()) )
3346 m_isDragging =
false;
3350 if ( event.Entering() || event.Leaving() )
3352 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin);
3357 else if ( event.LeftDown() )
3359 row = YToEdgeOfRow(y);
3360 if ( row != wxNOT_FOUND && CanDragRowSize(row) )
3362 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, m_rowLabelWin);
3368 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) )
3370 if ( !event.ShiftDown() && !event.CmdDown() )
3374 if ( event.ShiftDown() )
3376 m_selection->SelectBlock
3378 m_currentCellCoords.GetRow(), 0,
3379 row, GetNumberCols() - 1,
3385 m_selection->SelectRow(row, event);
3389 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW, m_rowLabelWin);
3396 else if (event.LeftDClick() )
3398 row = YToEdgeOfRow(y);
3399 if ( row != wxNOT_FOUND && CanDragRowSize(row) )
3404 AutoSizeRowLabelSize( row );
3406 SendGridSizeEvent(wxEVT_GRID_ROW_SIZE, row, -1, event);
3408 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow());
3415 !SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event ) )
3424 else if ( event.LeftUp() )
3426 if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
3427 DoEndDragResizeRow(event);
3429 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin);
3435 else if ( event.RightDown() )
3439 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) )
3447 else if ( event.RightDClick() )
3451 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) )
3459 else if ( event.Moving() )
3461 m_dragRowOrCol = YToEdgeOfRow( y );
3462 if ( m_dragRowOrCol != wxNOT_FOUND )
3464 if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
3466 if ( CanDragRowSize(m_dragRowOrCol) )
3467 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, m_rowLabelWin,
false);
3470 else if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
3472 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin,
false);
3477void wxGrid::UpdateColumnSortingIndicator(
int col)
3479 wxCHECK_RET( col != wxNOT_FOUND,
"invalid column index" );
3481 if ( m_useNativeHeader )
3482 GetGridColHeader()->UpdateColumn(col);
3483 else if ( m_nativeColumnLabels )
3484 m_colWindow->Refresh();
3488void wxGrid::SetSortingColumn(
int col,
bool ascending)
3490 if ( col == m_sortCol )
3494 if ( m_sortCol != wxNOT_FOUND && ascending != m_sortIsAscending )
3496 m_sortIsAscending = ascending;
3498 UpdateColumnSortingIndicator(m_sortCol);
3503 const int sortColOld = m_sortCol;
3509 if ( sortColOld != wxNOT_FOUND )
3510 UpdateColumnSortingIndicator(sortColOld);
3512 if ( m_sortCol != wxNOT_FOUND )
3514 m_sortIsAscending = ascending;
3515 UpdateColumnSortingIndicator(m_sortCol);
3520void wxGrid::DoColHeaderClick(
int col)
3524 if ( SendEvent(wxEVT_GRID_COL_SORT, -1, col) == 1 )
3526 SetSortingColumn(col, IsSortingBy(col) ? !m_sortIsAscending :
true);
3531void wxGrid::DoStartResizeCol(
int col)
3533 m_dragRowOrCol = col;
3535 DoUpdateResizeColWidth(GetColWidth(m_dragRowOrCol));
3538void wxGrid::DoUpdateResizeCol(
int x)
3540 int cw, ch, dummy, top;
3541 m_gridWin->GetClientSize( &cw, &ch );
3542 CalcUnscrolledPosition( 0, 0, &dummy, &top );
3544 wxClientDC dc( m_gridWin );
3547 x = wxMax( x, GetColLeft(m_dragRowOrCol) + GetColMinimalWidth(m_dragRowOrCol));
3548 dc.SetLogicalFunction(wxINVERT);
3549 if ( m_dragLastPos >= 0 )
3551 dc.DrawLine( m_dragLastPos, top, m_dragLastPos, top + ch );
3553 dc.DrawLine( x, top, x, top + ch );
3557void wxGrid::DoUpdateResizeColWidth(
int w)
3559 DoUpdateResizeCol(GetColLeft(m_dragRowOrCol) + w);
3562void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
3565 CalcUnscrolledPosition( event.GetPosition().x, 0, &x, NULL );
3567 int col = XToCol(x);
3568 if ( event.Dragging() )
3572 m_isDragging =
true;
3574 if ( m_cursorMode == WXGRID_CURSOR_MOVE_COL && col != -1 )
3575 DoStartMoveCol(col);
3578 if ( event.LeftIsDown() )
3580 switch ( m_cursorMode )
3582 case WXGRID_CURSOR_RESIZE_COL:
3583 DoUpdateResizeCol(x);
3586 case WXGRID_CURSOR_SELECT_COL:
3591 m_selection->SelectCol(col, event);
3596 case WXGRID_CURSOR_MOVE_COL:
3598 int posNew = XToPos(x);
3599 int colNew = GetColAt(posNew);
3603 if ( x >= GetColLeft(colNew) + (GetColWidth(colNew) / 2) )
3604 markerX = GetColRight(colNew);
3606 markerX = GetColLeft(colNew);
3608 if ( markerX != m_dragLastPos )
3610 wxClientDC dc( GetColLabelWindow() );
3614 GetColLabelWindow()->GetClientSize( &cw, &ch );
3619 if ( m_dragLastPos >= 0 )
3621 wxPen pen( GetColLabelWindow()->GetBackgroundColour(), 2 );
3623 dc.DrawLine( m_dragLastPos + 1, 0, m_dragLastPos + 1, ch );
3624 dc.SetPen(wxNullPen);
3626 if ( XToCol( m_dragLastPos ) != -1 )
3627 DrawColLabel( dc, XToCol( m_dragLastPos ) );
3630 const wxColour *color;
3632 if ( colNew == m_dragRowOrCol )
3633 color = wxLIGHT_GREY;
3638 wxPen pen( *color, 2 );
3641 dc.DrawLine( markerX, 0, markerX, ch );
3643 dc.SetPen(wxNullPen);
3645 m_dragLastPos = markerX - 1;
3659 if ( m_isDragging && (event.Entering() || event.Leaving()) )
3663 m_isDragging =
false;
3667 if ( event.Entering() || event.Leaving() )
3669 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow());
3674 else if ( event.LeftDown() )
3676 int colEdge = XToEdgeOfCol(x);
3677 if ( colEdge != wxNOT_FOUND && CanDragColSize(colEdge) )
3679 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, GetColLabelWindow());
3684 !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) )
3686 if ( m_canDragColMove )
3689 wxClientDC dc( GetColLabelWindow() );
3690 int colLeft = GetColLeft( col );
3691 int colRight = GetColRight( col ) - 1;
3692 dc.SetPen( wxPen( GetColLabelWindow()->GetBackgroundColour(), 1 ) );
3693 dc.DrawLine( colLeft, 1, colLeft, m_colLabelHeight-1 );
3694 dc.DrawLine( colLeft, 1, colRight, 1 );
3696 ChangeCursorMode(WXGRID_CURSOR_MOVE_COL, GetColLabelWindow());
3700 if ( !event.ShiftDown() && !event.CmdDown() )
3704 if ( event.ShiftDown() )
3706 m_selection->SelectBlock
3708 0, m_currentCellCoords.GetCol(),
3709 GetNumberRows() - 1, col,
3715 m_selection->SelectCol(col, event);
3719 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL, GetColLabelWindow());
3727 if ( event.LeftDClick() )
3729 const int colEdge = XToEdgeOfCol(x);
3730 if ( colEdge == -1 )
3733 ! SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event ) )
3743 if ( !SendGridSizeEvent(wxEVT_GRID_COL_AUTO_SIZE, -1, colEdge, event) )
3744 AutoSizeColLabelSize( colEdge );
3746 SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, colEdge, event);
3748 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow());
3755 else if ( event.LeftUp() )
3757 switch ( m_cursorMode )
3759 case WXGRID_CURSOR_RESIZE_COL:
3760 DoEndDragResizeCol(event);
3763 case WXGRID_CURSOR_MOVE_COL:
3764 if ( m_dragLastPos == -1 || col == m_dragRowOrCol )
3768 DoColHeaderClick(col);
3769 m_colWindow->Refresh();
3774 int pos = XToPos(x);
3781 const int colValid = GetColAt(pos);
3785 const int middle = GetColLeft(colValid) +
3786 GetColWidth(colValid)/2;
3787 const bool onNearPart = (x <= middle);
3790 if ( pos < GetColPos(m_dragRowOrCol) )
3802 case WXGRID_CURSOR_SELECT_COL:
3803 case WXGRID_CURSOR_SELECT_CELL:
3804 case WXGRID_CURSOR_RESIZE_ROW:
3805 case WXGRID_CURSOR_SELECT_ROW:
3807 DoColHeaderClick(col);
3811 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow());
3817 else if ( event.RightDown() )
3820 !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) )
3828 else if ( event.RightDClick() )
3831 !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) )
3839 else if ( event.Moving() )
3841 m_dragRowOrCol = XToEdgeOfCol( x );
3842 if ( m_dragRowOrCol >= 0 )
3844 if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
3846 if ( CanDragColSize(m_dragRowOrCol) )
3847 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, GetColLabelWindow(),
false);
3850 else if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
3852 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow(),
false);
3857void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent& event )
3859 if ( event.LeftDown() )
3864 if ( !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, event ) )
3869 else if ( event.LeftDClick() )
3871 SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, event );
3873 else if ( event.RightDown() )
3875 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, event ) )
3880 else if ( event.RightDClick() )
3882 if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, event ) )
3889void wxGrid::CancelMouseCapture()
3894 m_isDragging =
false;
3895 m_startDragPos = wxDefaultPosition;
3897 m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
3898 m_winCapture->SetCursor( *wxSTANDARD_CURSOR );
3899 m_winCapture = NULL;
3906void wxGrid::ChangeCursorMode(CursorMode mode,
3911 static const wxChar *
const cursorModes[] =
3921 wxLogTrace(wxT(
"grid"),
3922 wxT(
"wxGrid cursor mode (mouse capture for %s): %s -> %s"),
3923 win == m_colWindow ? wxT(
"colLabelWin")
3924 : win ? wxT(
"rowLabelWin")
3926 cursorModes[m_cursorMode], cursorModes[mode]);
3929 if ( mode == m_cursorMode &&
3930 win == m_winCapture &&
3931 captureMouse == (m_winCapture != NULL))
3942 m_winCapture->ReleaseMouse();
3943 m_winCapture = NULL;
3946 m_cursorMode = mode;
3948 switch ( m_cursorMode )
3950 case WXGRID_CURSOR_RESIZE_ROW:
3951 win->SetCursor( m_rowResizeCursor );
3954 case WXGRID_CURSOR_RESIZE_COL:
3955 win->SetCursor( m_colResizeCursor );
3958 case WXGRID_CURSOR_MOVE_COL:
3959 win->SetCursor( wxCursor(wxCURSOR_HAND) );
3963 win->SetCursor( *wxSTANDARD_CURSOR );
3968 bool resize = m_cursorMode == WXGRID_CURSOR_RESIZE_ROW ||
3969 m_cursorMode == WXGRID_CURSOR_RESIZE_COL;
3971 if ( captureMouse && resize )
3973 win->CaptureMouse();
3983wxGrid::DoGridCellDrag(wxMouseEvent& event,
3984 const wxGridCellCoords& coords,
3987 bool performDefault = true ;
3989 if ( coords == wxGridNoCellCoords )
3990 return performDefault;
3993 if ( IsCellEditControlShown() )
3995 HideCellEditControl();
3996 SaveEditControlValue();
3999 switch ( event.GetModifiers() )
4002 if ( m_selectedBlockCorner == wxGridNoCellCoords)
4003 m_selectedBlockCorner = coords;
4004 UpdateBlockBeingSelected(m_selectedBlockCorner, coords);
4008 if ( CanDragCell() )
4012 if ( m_selectedBlockCorner == wxGridNoCellCoords)
4013 m_selectedBlockCorner = coords;
4016 if ( SendEvent(wxEVT_GRID_CELL_BEGIN_DRAG, coords, event) != 0 )
4017 performDefault =
false;
4019 return performDefault;
4023 UpdateBlockBeingSelected(m_currentCellCoords, coords);
4031 return performDefault;
4034void wxGrid::DoGridLineDrag(wxMouseEvent& event,
const wxGridOperations& oper)
4036 wxClientDC dc(m_gridWin);
4038 dc.SetLogicalFunction(wxINVERT);
4040 const wxRect rectWin(CalcUnscrolledPosition(wxPoint(0, 0)),
4041 m_gridWin->GetClientSize());
4044 if ( m_dragLastPos >= 0 )
4045 oper.DrawParallelLineInRect(dc, rectWin, m_dragLastPos);
4048 m_dragLastPos = oper.Dual().Select(CalcUnscrolledPosition(event.GetPosition()));
4051 const int posMin = oper.GetLineStartPos(
this, m_dragRowOrCol) +
4052 oper.GetMinimalLineSize(
this, m_dragRowOrCol);
4053 if ( m_dragLastPos < posMin )
4054 m_dragLastPos = posMin;
4057 oper.DrawParallelLineInRect(dc, rectWin, m_dragLastPos);
4060void wxGrid::DoGridDragEvent(wxMouseEvent& event,
const wxGridCellCoords& coords)
4062 if ( !m_isDragging )
4066 const wxPoint& pt =
event.GetPosition();
4067 if ( m_startDragPos == wxDefaultPosition )
4069 m_startDragPos = pt;
4073 if (
abs(m_startDragPos.x - pt.x) <= DRAG_SENSITIVITY &&
4074 abs(m_startDragPos.y - pt.y) <= DRAG_SENSITIVITY )
4078 const bool isFirstDrag = !m_isDragging;
4079 m_isDragging =
true;
4081 switch ( m_cursorMode )
4083 case WXGRID_CURSOR_SELECT_CELL:
4085 if ( DoGridCellDrag(event, coords, isFirstDrag) ==
false )
4089 case WXGRID_CURSOR_RESIZE_ROW:
4090 DoGridLineDrag(event, wxGridRowOperations());
4093 case WXGRID_CURSOR_RESIZE_COL:
4094 DoGridLineDrag(event, wxGridColumnOperations());
4103 wxASSERT_MSG( !m_winCapture,
"shouldn't capture the mouse twice" );
4105 m_winCapture = m_gridWin;
4106 m_winCapture->CaptureMouse();
4111wxGrid::DoGridCellLeftDown(wxMouseEvent& event,
4112 const wxGridCellCoords& coords,
4115 if ( SendEvent(wxEVT_GRID_CELL_LEFT_CLICK, coords, event) )
4121 if ( !event.CmdDown() )
4124 if ( event.ShiftDown() )
4128 m_selection->SelectBlock(m_currentCellCoords, coords, event);
4129 m_selectedBlockCorner = coords;
4132 else if ( XToEdgeOfCol(pos.x) < 0 && YToEdgeOfRow(pos.y) < 0 )
4134 DisableCellEditControl();
4135 MakeCellVisible( coords );
4137 if ( event.CmdDown() )
4141 m_selection->ToggleCellSelection(coords, event);
4144 m_selectedBlockTopLeft = wxGridNoCellCoords;
4145 m_selectedBlockBottomRight = wxGridNoCellCoords;
4146 m_selectedBlockCorner = coords;
4156 switch ( m_selection->GetSelectionMode() )
4158 case wxGridSelectCells:
4159 case wxGridSelectRowsOrColumns:
4163 case wxGridSelectRows:
4164 m_selection->SelectRow(coords.GetRow());
4167 case wxGridSelectColumns:
4168 m_selection->SelectCol(coords.GetCol());
4173 m_waitForSlowClick = m_currentCellCoords == coords &&
4174 coords != wxGridNoCellCoords;
4175 SetCurrentCell( coords );
4181wxGrid::DoGridCellLeftDClick(wxMouseEvent& event,
4182 const wxGridCellCoords& coords,
4185 if ( XToEdgeOfCol(pos.x) < 0 && YToEdgeOfRow(pos.y) < 0 )
4187 if ( !SendEvent(wxEVT_GRID_CELL_LEFT_DCLICK, coords, event) )
4191 m_waitForSlowClick =
true;
4197wxGrid::DoGridCellLeftUp(wxMouseEvent& event,
const wxGridCellCoords& coords)
4199 if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
4203 m_winCapture->ReleaseMouse();
4204 m_winCapture = NULL;
4207 if ( coords == m_currentCellCoords && m_waitForSlowClick && CanEnableCellControl() )
4210 EnableCellEditControl();
4212 wxGridCellAttr *attr = GetCellAttr(coords);
4213 wxGridCellEditor *editor = attr->GetEditor(
this, coords.GetRow(), coords.GetCol());
4214 editor->StartingClick();
4218 m_waitForSlowClick =
false;
4220 else if ( m_selectedBlockTopLeft != wxGridNoCellCoords &&
4221 m_selectedBlockBottomRight != wxGridNoCellCoords )
4225 m_selection->SelectBlock( m_selectedBlockTopLeft,
4226 m_selectedBlockBottomRight,
4230 m_selectedBlockTopLeft = wxGridNoCellCoords;
4231 m_selectedBlockBottomRight = wxGridNoCellCoords;
4235 ShowCellEditControl();
4238 else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
4240 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
4241 DoEndDragResizeRow(event);
4243 else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
4245 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
4246 DoEndDragResizeCol(event);
4253wxGrid::DoGridMouseMoveEvent(wxMouseEvent& WXUNUSED(event),
4254 const wxGridCellCoords& coords,
4257 if ( coords.GetRow() < 0 || coords.GetCol() < 0 )
4260 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
4264 int dragRow = YToEdgeOfRow( pos.y );
4265 int dragCol = XToEdgeOfCol( pos.x );
4270 if ( dragRow >= 0 && dragCol >= 0 )
4272 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
4276 if ( dragRow >= 0 && CanDragGridSize() && CanDragRowSize(dragRow) )
4278 if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
4280 m_dragRowOrCol = dragRow;
4281 ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, NULL,
false);
4287 else if ( dragCol >= 0 && !m_useNativeHeader &&
4288 CanDragGridSize() && CanDragColSize(dragCol) )
4290 if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
4292 m_dragRowOrCol = dragCol;
4293 ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, NULL,
false);
4298 if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
4300 ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
4305void wxGrid::ProcessGridCellMouseEvent(wxMouseEvent& event)
4307 if ( event.Entering() || event.Leaving() )
4315 const wxPoint pos = CalcUnscrolledPosition(event.GetPosition());
4318 wxGridCellCoords coords = XYToCell(pos);
4320 int cell_rows, cell_cols;
4321 GetCellSize( coords.GetRow(), coords.GetCol(), &cell_rows, &cell_cols );
4322 if ( (cell_rows < 0) || (cell_cols < 0) )
4324 coords.SetRow(coords.GetRow() + cell_rows);
4325 coords.SetCol(coords.GetCol() + cell_cols);
4328 if ( event.Dragging() )
4330 if ( event.LeftIsDown() )
4331 DoGridDragEvent(event, coords);
4337 m_isDragging =
false;
4338 m_startDragPos = wxDefaultPosition;
4341 if ( event.IsButton() )
4343 if ( coords != wxGridNoCellCoords )
4345 DisableCellEditControl();
4347 if ( event.LeftDown() )
4348 DoGridCellLeftDown(event, coords, pos);
4349 else if ( event.LeftDClick() )
4350 DoGridCellLeftDClick(event, coords, pos);
4351 else if ( event.RightDown() )
4352 SendEvent(wxEVT_GRID_CELL_RIGHT_CLICK, coords, event);
4353 else if ( event.RightDClick() )
4354 SendEvent(wxEVT_GRID_CELL_RIGHT_DCLICK, coords, event);
4358 if ( event.LeftUp() )
4360 DoGridCellLeftUp(event, coords);
4363 else if ( event.Moving() )
4365 DoGridMouseMoveEvent(event, coords, pos);
4374bool wxGrid::DoEndDragResizeLine(
const wxGridOperations& oper)
4376 if ( m_dragLastPos == -1 )
4379 const wxGridOperations& doper = oper.Dual();
4381 const wxSize size = m_gridWin->GetClientSize();
4383 const wxPoint ptOrigin = CalcUnscrolledPosition(wxPoint(0, 0));
4386 wxClientDC dc(m_gridWin);
4388 dc.SetLogicalFunction(wxINVERT);
4390 const int posLineStart = oper.Select(ptOrigin);
4391 const int posLineEnd = oper.Select(ptOrigin) + oper.Select(size);
4393 oper.DrawParallelLine(dc, posLineStart, posLineEnd, m_dragLastPos);
4396 HideCellEditControl();
4397 SaveEditControlValue();
4400 const int lineStart = oper.GetLineStartPos(
this, m_dragRowOrCol);
4401 const int lineSizeOld = oper.GetLineSize(
this, m_dragRowOrCol);
4402 oper.SetLineSize(
this, m_dragRowOrCol,
4403 wxMax(m_dragLastPos - lineStart,
4404 oper.GetMinimalLineSize(
this, m_dragRowOrCol)));
4406 sizeChanged = oper.GetLineSize(
this, m_dragRowOrCol) != lineSizeOld;
4411 if ( !GetBatchCount() )
4417 wxRect rect(CellToRect(oper.MakeCoords(m_dragRowOrCol, 0)));
4418 rect.SetPosition(CalcScrolledPosition(rect.GetPosition()));
4422 oper.Select(rect) = 0;
4424 wxRect rectHeader(rect.GetPosition(),
4427 oper.GetHeaderWindowSize(
this),
4428 doper.Select(size) - doper.Select(rect)
4431 oper.GetHeaderWindow(
this)->Refresh(
true, &rectHeader);
4437 oper.SelectSize(rect) = oper.Select(size);
4439 int subtractLines = 0;
4440 int line = doper.PosToLine(
this, posLineStart);
4446 const int lineEnd = doper.PosToLine(
this, posLineEnd,
true);
4447 for ( ; line < lineEnd; line++ )
4449 int cellLines = oper.Select(
4450 GetCellSize(oper.MakeCoords(m_dragRowOrCol, line)));
4451 if ( cellLines < subtractLines )
4452 subtractLines = cellLines;
4457 oper.GetLineStartPos(
this, m_dragRowOrCol + subtractLines);
4458 startPos = doper.CalcScrolledPosition(
this, startPos);
4460 doper.Select(rect) = startPos;
4461 doper.SelectSize(rect) = doper.Select(size) - startPos;
4463 m_gridWin->Refresh(
false, &rect);
4468 ShowCellEditControl();
4473void wxGrid::DoEndDragResizeRow(
const wxMouseEvent& event)
4477 if ( DoEndDragResizeLine(wxGridRowOperations()) )
4478 SendGridSizeEvent(wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event);
4481void wxGrid::DoEndDragResizeCol(
const wxMouseEvent& event)
4485 if ( DoEndDragResizeLine(wxGridColumnOperations()) )
4486 SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event);
4489void wxGrid::DoStartMoveCol(
int col)
4491 m_dragRowOrCol = col;
4494void wxGrid::DoEndMoveCol(
int pos)
4496 wxASSERT_MSG( m_dragRowOrCol != -1,
"no matching DoStartMoveCol?" );
4498 if ( SendEvent(wxEVT_GRID_COL_MOVE, -1, m_dragRowOrCol) != -1 )
4499 SetColPos(m_dragRowOrCol, pos);
4502 m_dragRowOrCol = -1;
4505void wxGrid::RefreshAfterColPosChange()
4510 if ( !m_colWidths.empty() )
4513 for (
int colPos = 0; colPos < m_numCols; colPos++ )
4515 int colID = GetColAt( colPos );
4518 const int width = m_colWidths[colID];
4522 m_colRights[colID] = colRight;
4527 if ( m_useNativeHeader )
4529 if ( m_colAt.empty() )
4530 GetGridColHeader()->ResetColumnsOrder();
4532 GetGridColHeader()->SetColumnsOrder(m_colAt);
4536 m_colWindow->Refresh();
4538 m_gridWin->Refresh();
4541void wxGrid::SetColumnsOrder(
const wxArrayInt& order)
4545 RefreshAfterColPosChange();
4548void wxGrid::SetColPos(
int idx,
int pos)
4551 if ( m_colAt.empty() )
4553 m_colAt.reserve(m_numCols);
4554 for (
int i = 0; i < m_numCols; i++ )
4555 m_colAt.push_back(i);
4558 wxHeaderCtrl::MoveColumnInOrderArray(m_colAt, idx, pos);
4560 RefreshAfterColPosChange();
4563void wxGrid::ResetColPos()
4567 RefreshAfterColPosChange();
4570void wxGrid::EnableDragColMove(
bool enable )
4572 if ( m_canDragColMove == enable )
4575 if ( m_useNativeHeader )
4578 GetGridColHeader()->SetColumnCount(m_numCols);
4581 m_canDragColMove = enable;
4593bool wxGrid::ProcessTableMessage( wxGridTableMessage& msg )
4595 switch ( msg.GetId() )
4597 case wxGRIDTABLE_REQUEST_VIEW_GET_VALUES:
4598 return GetModelValues();
4600 case wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES:
4601 return SetModelValues();
4603 case wxGRIDTABLE_NOTIFY_ROWS_INSERTED:
4604 case wxGRIDTABLE_NOTIFY_ROWS_APPENDED:
4605 case wxGRIDTABLE_NOTIFY_ROWS_DELETED:
4606 case wxGRIDTABLE_NOTIFY_COLS_INSERTED:
4607 case wxGRIDTABLE_NOTIFY_COLS_APPENDED:
4608 case wxGRIDTABLE_NOTIFY_COLS_DELETED:
4609 return Redimension( msg );
4621void wxGrid::ClearGrid()
4625 if (IsCellEditControlEnabled())
4626 DisableCellEditControl();
4629 if (!GetBatchCount())
4630 m_gridWin->Refresh();
4635wxGrid::DoModifyLines(
bool (wxGridTableBase::*funcModify)(
size_t,
size_t),
4636 int pos,
int num,
bool WXUNUSED(updateLabels) )
4638 wxCHECK_MSG( m_created,
false,
"must finish creating the grid first" );
4643 if ( IsCellEditControlEnabled() )
4644 DisableCellEditControl();
4646 return (m_table->*funcModify)(pos, num);
4653wxGrid::DoAppendLines(
bool (wxGridTableBase::*funcAppend)(
size_t),
4654 int num,
bool WXUNUSED(updateLabels))
4656 wxCHECK_MSG( m_created,
false,
"must finish creating the grid first" );
4661 return (m_table->*funcAppend)(num);
4669wxGrid::SendGridSizeEvent(wxEventType type,
4671 const wxMouseEvent& mouseEv)
4673 int rowOrCol = row == -1 ? col : row;
4675 wxGridSizeEvent gridEvt( GetId(),
4679 mouseEv.GetX() + GetRowLabelSize(),
4680 mouseEv.GetY() + GetColLabelSize(),
4683 return GetEventHandler()->ProcessEvent(gridEvt);
4691wxGrid::SendEvent(
const wxEventType type,
4693 const wxMouseEvent& mouseEv)
4695 bool claimed, vetoed;
4697 if ( type == wxEVT_GRID_RANGE_SELECT )
4700 wxGridRangeSelectEvent gridEvt( GetId(),
4703 m_selectedBlockTopLeft,
4704 m_selectedBlockBottomRight,
4708 claimed = GetEventHandler()->ProcessEvent(gridEvt);
4709 vetoed = !gridEvt.IsAllowed();
4711 else if ( type == wxEVT_GRID_LABEL_LEFT_CLICK ||
4712 type == wxEVT_GRID_LABEL_LEFT_DCLICK ||
4713 type == wxEVT_GRID_LABEL_RIGHT_CLICK ||
4714 type == wxEVT_GRID_LABEL_RIGHT_DCLICK )
4716 wxPoint pos = mouseEv.GetPosition();
4718 if ( mouseEv.GetEventObject() == GetGridRowLabelWindow() )
4719 pos.y += GetColLabelSize();
4720 if ( mouseEv.GetEventObject() == GetGridColLabelWindow() )
4721 pos.x += GetRowLabelSize();
4723 wxGridEvent gridEvt( GetId(),
4731 claimed = GetEventHandler()->ProcessEvent(gridEvt);
4732 vetoed = !gridEvt.IsAllowed();
4736 wxGridEvent gridEvt( GetId(),
4740 mouseEv.GetX() + GetRowLabelSize(),
4741 mouseEv.GetY() + GetColLabelSize(),
4745 if ( type == wxEVT_GRID_CELL_BEGIN_DRAG )
4752 claimed = GetEventHandler()->ProcessEvent(gridEvt);
4753 vetoed = !gridEvt.IsAllowed();
4760 return claimed ? 1 : 0;
4766wxGrid::SendEvent(
const wxEventType type,
int row,
int col,
const wxString& s)
4768 wxGridEvent gridEvt( GetId(), type,
this, row, col );
4769 gridEvt.SetString(s);
4771 const bool claimed = GetEventHandler()->ProcessEvent(gridEvt);
4774 if ( !gridEvt.IsAllowed() )
4777 return claimed ? 1 : 0;
4780void wxGrid::OnPaint( wxPaintEvent& WXUNUSED(event) )
4786void wxGrid::Refresh(
bool eraseb,
const wxRect* rect)
4790 if ( m_created && !GetBatchCount() )
4793 wxScrolledWindow::Refresh(eraseb, rect);
4797 int rect_x, rect_y, rectWidth, rectHeight;
4798 int width_label, width_cell, height_label, height_cell;
4802 rect_x = rect->GetX();
4803 rect_y = rect->GetY();
4804 rectWidth = rect->GetWidth();
4805 rectHeight = rect->GetHeight();
4807 width_label = m_rowLabelWidth - rect_x;
4808 if (width_label > rectWidth)
4809 width_label = rectWidth;
4811 height_label = m_colLabelHeight - rect_y;
4812 if (height_label > rectHeight)
4813 height_label = rectHeight;
4815 if (rect_x > m_rowLabelWidth)
4817 x = rect_x - m_rowLabelWidth;
4818 width_cell = rectWidth;
4823 width_cell = rectWidth - (m_rowLabelWidth - rect_x);
4826 if (rect_y > m_colLabelHeight)
4828 y = rect_y - m_colLabelHeight;
4829 height_cell = rectHeight;
4834 height_cell = rectHeight - (m_colLabelHeight - rect_y);
4838 if ( width_label > 0 && height_label > 0 )
4840 wxRect anotherrect(rect_x, rect_y, width_label, height_label);
4841 m_cornerLabelWin->Refresh(eraseb, &anotherrect);
4845 if ( width_cell > 0 && height_label > 0 )
4847 wxRect anotherrect(x, rect_y, width_cell, height_label);
4848 m_colWindow->Refresh(eraseb, &anotherrect);
4852 if ( width_label > 0 && height_cell > 0 )
4854 wxRect anotherrect(rect_x, y, width_label, height_cell);
4855 m_rowLabelWin->Refresh(eraseb, &anotherrect);
4859 if ( width_cell > 0 && height_cell > 0 )
4861 wxRect anotherrect(x, y, width_cell, height_cell);
4862 m_gridWin->Refresh(eraseb, &anotherrect);
4867 m_cornerLabelWin->Refresh(eraseb, NULL);
4868 m_colWindow->Refresh(eraseb, NULL);
4869 m_rowLabelWin->Refresh(eraseb, NULL);
4870 m_gridWin->Refresh(eraseb, NULL);
4875void wxGrid::OnSize(wxSizeEvent& WXUNUSED(event))
4877 if (m_targetWindow !=
this)
4884void wxGrid::OnKeyDown( wxKeyEvent& event )
4886 if ( m_inOnKeyDown )
4890 wxFAIL_MSG( wxT(
"wxGrid::OnKeyDown called while already active") );
4893 m_inOnKeyDown =
true;
4896 wxWindow *parent = GetParent();
4897 wxKeyEvent keyEvt( event );
4898 keyEvt.SetEventObject( parent );
4900 if ( !parent->GetEventHandler()->ProcessEvent( keyEvt ) )
4902 if (GetLayoutDirection() == wxLayout_RightToLeft)
4904 if (event.GetKeyCode() == WXK_RIGHT)
4905 event.m_keyCode = WXK_LEFT;
4906 else if (event.GetKeyCode() == WXK_LEFT)
4907 event.m_keyCode = WXK_RIGHT;
4911 switch ( event.GetKeyCode() )
4914 if ( event.ControlDown() )
4915 MoveCursorUpBlock( event.ShiftDown() );
4917 MoveCursorUp( event.ShiftDown() );
4921 if ( event.ControlDown() )
4922 MoveCursorDownBlock( event.ShiftDown() );
4924 MoveCursorDown( event.ShiftDown() );
4928 if ( event.ControlDown() )
4929 MoveCursorLeftBlock( event.ShiftDown() );
4931 MoveCursorLeft( event.ShiftDown() );
4935 if ( event.ControlDown() )
4936 MoveCursorRightBlock( event.ShiftDown() );
4938 MoveCursorRight( event.ShiftDown() );
4942 case WXK_NUMPAD_ENTER:
4943 if ( event.ControlDown() )
4949 if ( GetGridCursorRow() < GetNumberRows()-1 )
4951 MoveCursorDown( event.ShiftDown() );
4956 DisableCellEditControl();
4968 wxGridEvent gridEvt(GetId(), wxEVT_GRID_TABBING,
this,
4969 GetGridCursorRow(), GetGridCursorCol(),
4970 -1, -1,
false, event);
4971 if ( ProcessWindowEvent(gridEvt) )
4977 DoGridProcessTab( event );
4981 GoToCell(event.ControlDown() ? 0
4982 : m_currentCellCoords.GetRow(),
4987 GoToCell(event.ControlDown() ? m_numRows - 1
4988 : m_currentCellCoords.GetRow(),
5003 switch ( m_selection ? event.GetModifiers() : wxMOD_NONE )
5006 m_selection->SelectCol(m_currentCellCoords.GetCol());
5010 m_selection->SelectRow(m_currentCellCoords.GetRow());
5013 case wxMOD_CONTROL | wxMOD_SHIFT:
5014 m_selection->SelectBlock(0, 0,
5015 m_numRows - 1, m_numCols - 1);
5019 if ( !IsEditable() )
5021 MoveCursorRight(
false);
5037 m_inOnKeyDown =
false;
5040void wxGrid::OnKeyUp( wxKeyEvent& event )
5044 if ( event.GetKeyCode() == WXK_SHIFT )
5046 if ( m_selectedBlockTopLeft != wxGridNoCellCoords &&
5047 m_selectedBlockBottomRight != wxGridNoCellCoords )
5051 m_selection->SelectBlock(
5052 m_selectedBlockTopLeft,
5053 m_selectedBlockBottomRight,
5058 m_selectedBlockTopLeft = wxGridNoCellCoords;
5059 m_selectedBlockBottomRight = wxGridNoCellCoords;
5060 m_selectedBlockCorner = wxGridNoCellCoords;
5064void wxGrid::OnChar( wxKeyEvent& event )
5067 if ( !IsCellEditControlEnabled() && CanEnableCellControl() )
5070 int row = m_currentCellCoords.GetRow();
5071 int col = m_currentCellCoords.GetCol();
5072 wxGridCellAttr *attr = GetCellAttr(row, col);
5073 wxGridCellEditor *editor = attr->GetEditor(
this, row, col);
5077 if ( (event.GetKeyCode() == WXK_F2 && !event.HasModifiers())
5078 || editor->IsAcceptedKey(event) )
5081 MakeCellVisible(row, col);
5082 EnableCellEditControl();
5088 if ( event.GetKeyCode() != WXK_F2 && editor->IsCreated() && m_cellEditCtrlEnabled )
5089 editor->StartingKey(event);
5105void wxGrid::OnEraseBackground(wxEraseEvent&)
5109void wxGrid::DoGridProcessTab(wxKeyboardState& kbdState)
5111 const bool isForwardTab = !kbdState.ShiftDown();
5117 if ( GetGridCursorCol() < GetNumberCols() - 1 )
5119 MoveCursorRight(
false );
5125 if ( GetGridCursorCol() )
5127 MoveCursorLeft(
false );
5135 switch ( m_tabBehaviour )
5145 if ( GetGridCursorRow() < GetNumberRows() - 1 )
5147 GoToCell( GetGridCursorRow() + 1, 0 );
5153 if ( GetGridCursorRow() > 0 )
5155 GoToCell( GetGridCursorRow() - 1, GetNumberCols() - 1 );
5162 if ( Navigate( isForwardTab ? wxNavigationKeyEvent::IsForward
5163 : wxNavigationKeyEvent::IsBackward ) )
5169 DisableCellEditControl();
5172bool wxGrid::SetCurrentCell(
const wxGridCellCoords& coords )
5174 if ( SendEvent(wxEVT_GRID_SELECT_CELL, coords) == -1 )
5180#if !defined(__WXMAC__)
5181 wxClientDC dc( m_gridWin );
5185 if ( m_currentCellCoords != wxGridNoCellCoords )
5187 DisableCellEditControl();
5189 if ( IsVisible( m_currentCellCoords,
false ) )
5192 r = BlockToDeviceRect( m_currentCellCoords, m_currentCellCoords );
5193 if ( !m_gridLinesEnabled )
5201 wxGridCellCoordsArray cells = CalcCellsExposed( r );
5204 m_currentCellCoords = coords;
5206#if defined(__WXMAC__)
5207 m_gridWin->Refresh(
true );
5209 DrawGridCellArea( dc, cells );
5210 DrawAllGridLines( dc, r );
5215 m_currentCellCoords = coords;
5217 wxGridCellAttr *attr = GetCellAttr( coords );
5218#if !defined(__WXMAC__)
5219 DrawCellHighlight( dc, attr );
5227wxGrid::UpdateBlockBeingSelected(
int topRow,
int leftCol,
5228 int bottomRow,
int rightCol)
5230 MakeCellVisible(m_selectedBlockCorner);
5231 m_selectedBlockCorner = wxGridCellCoords(bottomRow, rightCol);
5235 switch ( m_selection->GetSelectionMode() )
5238 wxFAIL_MSG(
"unknown selection mode" );
5241 case wxGridSelectCells:
5246 case wxGridSelectRows:
5250 rightCol = GetNumberCols() - 1;
5253 case wxGridSelectColumns:
5256 bottomRow = GetNumberRows() - 1;
5259 case wxGridSelectRowsOrColumns:
5269 EnsureFirstLessThanSecond(topRow, bottomRow);
5270 EnsureFirstLessThanSecond(leftCol, rightCol);
5272 wxGridCellCoords updateTopLeft = wxGridCellCoords(topRow, leftCol),
5273 updateBottomRight = wxGridCellCoords(bottomRow, rightCol);
5276 if ( m_selectedBlockTopLeft == wxGridNoCellCoords ||
5277 m_selectedBlockBottomRight == wxGridNoCellCoords )
5280 rect = BlockToDeviceRect( wxGridCellCoords ( topRow, leftCol ),
5281 wxGridCellCoords ( bottomRow, rightCol ) );
5282 m_gridWin->Refresh(
false, &rect );
5286 else if ( m_selectedBlockTopLeft != updateTopLeft ||
5287 m_selectedBlockBottomRight != updateBottomRight )
5293 bool need_refresh[4];
5297 need_refresh[3] =
false;
5301 wxCoord oldLeft = m_selectedBlockTopLeft.GetCol();
5302 wxCoord oldTop = m_selectedBlockTopLeft.GetRow();
5303 wxCoord oldRight = m_selectedBlockBottomRight.GetCol();
5304 wxCoord oldBottom = m_selectedBlockBottomRight.GetRow();
5307 EnsureFirstLessThanSecond(oldLeft, leftCol);
5308 EnsureFirstLessThanSecond(oldTop, topRow);
5309 EnsureFirstLessThanSecond(rightCol, oldRight);
5310 EnsureFirstLessThanSecond(bottomRow, oldBottom);
5316 if ( oldLeft < leftCol )
5320 need_refresh[0] =
true;
5321 rect[0] = BlockToDeviceRect(
5322 wxGridCellCoords( oldTop, oldLeft ),
5323 wxGridCellCoords( oldBottom, leftCol - 1 ) );
5326 if ( oldTop < topRow )
5330 need_refresh[1] =
true;
5331 rect[1] = BlockToDeviceRect(
5332 wxGridCellCoords( oldTop, leftCol ),
5333 wxGridCellCoords( topRow - 1, rightCol ) );
5336 if ( oldRight > rightCol )
5340 need_refresh[2] =
true;
5341 rect[2] = BlockToDeviceRect(
5342 wxGridCellCoords( oldTop, rightCol + 1 ),
5343 wxGridCellCoords( oldBottom, oldRight ) );
5346 if ( oldBottom > bottomRow )
5350 need_refresh[3] =
true;
5351 rect[3] = BlockToDeviceRect(
5352 wxGridCellCoords( bottomRow + 1, leftCol ),
5353 wxGridCellCoords( oldBottom, rightCol ) );
5357 for (i = 0; i < 4; i++ )
5358 if ( need_refresh[i] && rect[i] != wxGridNoCellRect )
5359 m_gridWin->Refresh(
false, &(rect[i]) );
5363 m_selectedBlockTopLeft = updateTopLeft;
5364 m_selectedBlockBottomRight = updateBottomRight;
5371bool wxGrid::GetModelValues()
5374 HideCellEditControl();
5380 m_gridWin->Refresh();
5387bool wxGrid::SetModelValues()
5394 DisableCellEditControl();
5398 for ( row = 0; row < m_numRows; row++ )
5400 for ( col = 0; col < m_numCols; col++ )
5402 m_table->SetValue( row, col, GetCellValue(row, col) );
5416void wxGrid::DrawGridCellArea( wxDC& dc,
const wxGridCellCoordsArray& cells )
5418 if ( !m_numRows || !m_numCols )
5421 int i, numCells = cells.GetCount();
5422 int row, col, cell_rows, cell_cols;
5423 wxGridCellCoordsArray redrawCells;
5425 for ( i = numCells - 1; i >= 0; i-- )
5427 row = cells[i].GetRow();
5428 col = cells[i].GetCol();
5429 GetCellSize( row, col, &cell_rows, &cell_cols );
5432 if ( cell_rows <= 0 || cell_cols <= 0 )
5434 wxGridCellCoords cell( row + cell_rows, col + cell_cols );
5435 bool marked =
false;
5436 for (
int j = 0; j < numCells; j++ )
5438 if ( cell == cells[j] )
5447 int count = redrawCells.GetCount();
5448 for (
int j = 0; j < count; j++)
5450 if ( cell == redrawCells[j] )
5458 redrawCells.Add( cell );
5466 if (m_table && m_table->IsEmptyCell(row, col))
5468 for (
int l = 0; l < cell_rows; l++ )
5472 for (
int k = 0; k < int(redrawCells.GetCount()); k++)
5473 if ((redrawCells[k].GetCol() < left) &&
5474 (redrawCells[k].GetRow() == row))
5476 left = redrawCells[k].GetCol();
5482 for (
int j = col - 1; j >= left; j--)
5484 if (!m_table->IsEmptyCell(row + l, j))
5486 if (GetCellOverflow(row + l, j))
5488 wxGridCellCoords cell(row + l, j);
5489 bool marked =
false;
5491 for (
int k = 0; k < numCells; k++)
5493 if ( cell == cells[k] )
5502 int count = redrawCells.GetCount();
5503 for (
int k = 0; k < count; k++)
5505 if ( cell == redrawCells[k] )
5512 redrawCells.Add( cell );
5521 DrawCell( dc, cells[i] );
5524 numCells = redrawCells.GetCount();
5526 for ( i = numCells - 1; i >= 0; i-- )
5528 DrawCell( dc, redrawCells[i] );
5532void wxGrid::DrawGridSpace( wxDC& dc )
5535 m_gridWin->GetClientSize( &cw, &ch );
5538 CalcUnscrolledPosition( cw, ch, &right, &bottom );
5540 int rightCol = m_numCols > 0 ? GetColRight(GetColAt( m_numCols - 1 )) : 0;
5541 int bottomRow = m_numRows > 0 ? GetRowBottom(m_numRows - 1) : 0;
5543 if ( right > rightCol || bottom > bottomRow )
5546 CalcUnscrolledPosition( 0, 0, &left, &top );
5548 dc.SetBrush(GetDefaultCellBackgroundColour());
5549 dc.SetPen( *wxTRANSPARENT_PEN );
5551 if ( right > rightCol )
5553 dc.DrawRectangle( rightCol, top, right - rightCol, ch );
5556 if ( bottom > bottomRow )
5558 dc.DrawRectangle( left, bottomRow, cw, bottom - bottomRow );
5563void wxGrid::DrawCell( wxDC& dc,
const wxGridCellCoords& coords )
5565 int row = coords.GetRow();
5566 int col = coords.GetCol();
5568 if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 )
5572 wxGridCellAttr* attr = GetCellAttr(row, col);
5574 bool isCurrent = coords == m_currentCellCoords;
5576 wxRect rect = CellToRect( row, col );
5580 if ( isCurrent && IsCellEditControlShown() )
5586#if !defined(__WXMAC__)
5587 wxGridCellEditor *editor = attr->GetEditor(
this, row, col);
5588 editor->PaintBackground(dc, rect, *attr);
5595 wxGridCellRenderer *renderer = attr->GetRenderer(
this, row, col);
5596 renderer->Draw(*
this, *attr, dc, rect, row, col, IsInSelection(coords));
5603void wxGrid::DrawCellHighlight( wxDC& dc,
const wxGridCellAttr *attr )
5609 int row = m_currentCellCoords.GetRow();
5610 int col = m_currentCellCoords.GetCol();
5612 if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 )
5615 wxRect rect = CellToRect(row, col);
5621 int penWidth = attr->IsReadOnly() ? m_cellHighlightROPenWidth : m_cellHighlightPenWidth;
5630 rect.x += penWidth / 2;
5631 rect.y += penWidth / 2;
5632 rect.width -= penWidth - 1;
5633 rect.height -= penWidth - 1;
5638 dc.SetPen(wxPen(IsInSelection(row,col) ? m_selectionForeground
5639 : m_cellHighlightColour,
5641 dc.SetBrush(*wxTRANSPARENT_BRUSH);
5642 dc.DrawRectangle(rect);
5646wxPen wxGrid::GetDefaultGridLinePen()
5648 return wxPen(GetGridLineColour());
5651wxPen wxGrid::GetRowGridLinePen(
int WXUNUSED(row))
5653 return GetDefaultGridLinePen();
5656wxPen wxGrid::GetColGridLinePen(
int WXUNUSED(col))
5658 return GetDefaultGridLinePen();
5661void wxGrid::DrawCellBorder( wxDC& dc,
const wxGridCellCoords& coords )
5663 int row = coords.GetRow();
5664 int col = coords.GetCol();
5665 if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 )
5669 wxRect rect = CellToRect( row, col );
5672 dc.SetPen( GetColGridLinePen(col) );
5673 dc.DrawLine( rect.x + rect.width, rect.y,
5674 rect.x + rect.width, rect.y + rect.height + 1 );
5677 dc.SetPen( GetRowGridLinePen(row) );
5678 dc.DrawLine( rect.x, rect.y + rect.height,
5679 rect.x + rect.width, rect.y + rect.height);
5682void wxGrid::DrawHighlight(wxDC& dc,
const wxGridCellCoordsArray& cells)
5687 if ( m_currentCellCoords == wxGridNoCellCoords &&
5688 m_numRows && m_numCols )
5690 m_currentCellCoords.Set(0, 0);
5693 if ( IsCellEditControlShown() )
5701 size_t count = cells.GetCount();
5702 for (
size_t n = 0; n < count; n++ )
5704 wxGridCellCoords cell = cells[n];
5711 if ( CanHaveAttributes() )
5715 GetCellSize(cell.GetRow(), cell.GetCol(), &rows, &cols);
5718 cell.SetRow(cell.GetRow() + rows);
5721 cell.SetCol(cell.GetCol() + cols);
5724 if ( cell == m_currentCellCoords )
5726 wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords);
5727 DrawCellHighlight(dc, attr);
5738wxGrid::DrawRangeGridLines(wxDC& dc,
5739 const wxRegion& reg,
5740 const wxGridCellCoords& topLeft,
5741 const wxGridCellCoords& bottomRight)
5743 if ( !m_gridLinesEnabled )
5746 int top, left, width, height;
5747 reg.GetBox( left, top, width, height );
5750 wxRegion clippedcells( dc.LogicalToDeviceX( left ),
5751 dc.LogicalToDeviceY( top ),
5752 dc.LogicalToDeviceXRel( width ),
5753 dc.LogicalToDeviceYRel( height ) );
5757 for (
int row = topLeft.GetRow(); row <= bottomRight.GetRow(); row++ )
5759 for (
int col = topLeft.GetCol(); col <= bottomRight.GetCol(); col++ )
5761 int cell_rows, cell_cols;
5762 GetCellSize( row, col, &cell_rows, &cell_cols );
5763 if ( cell_rows > 1 || cell_cols > 1 )
5765 rect = CellToRect( row, col );
5768 rect.x = dc.LogicalToDeviceX( rect.x );
5769 rect.y = dc.LogicalToDeviceY( rect.y );
5770 rect.width = dc.LogicalToDeviceXRel( rect.width );
5771 rect.height = dc.LogicalToDeviceYRel( rect.height ) - 1;
5772 clippedcells.Subtract( rect );
5774 else if ( cell_rows < 0 || cell_cols < 0 )
5776 rect = CellToRect( row + cell_rows, col + cell_cols );
5777 rect.x = dc.LogicalToDeviceX( rect.x );
5778 rect.y = dc.LogicalToDeviceY( rect.y );
5779 rect.width = dc.LogicalToDeviceXRel( rect.width );
5780 rect.height = dc.LogicalToDeviceYRel( rect.height ) - 1;
5781 clippedcells.Subtract( rect );
5786 dc.SetDeviceClippingRegion( clippedcells );
5789 top, left, top + height, left + width,
5790 topLeft.GetRow(), topLeft.GetCol(),
5791 bottomRight.GetRow(), bottomRight.GetCol());
5793 dc.DestroyClippingRegion();
5799void wxGrid::DrawAllGridLines( wxDC& dc,
const wxRegion & WXUNUSED(reg) )
5801 if ( !m_gridLinesEnabled )
5804 int top, bottom, left, right;
5807 m_gridWin->GetClientSize(&cw, &ch);
5808 CalcUnscrolledPosition( 0, 0, &left, &top );
5809 CalcUnscrolledPosition( cw, ch, &right, &bottom );
5812 if ( m_gridLinesClipHorz )
5817 const int lastColRight = GetColRight(GetColAt(m_numCols - 1));
5818 if ( right > lastColRight )
5819 right = lastColRight;
5822 if ( m_gridLinesClipVert )
5827 const int lastRowBottom = GetRowBottom(m_numRows - 1);
5828 if ( bottom > lastRowBottom )
5829 bottom = lastRowBottom;
5833 int leftCol = GetColPos( internalXToCol(left) );
5834 int topRow = internalYToRow(top);
5835 int rightCol = GetColPos( internalXToCol(right) );
5836 int bottomRow = internalYToRow(bottom);
5838 wxRegion clippedcells(0, 0, cw, ch);
5840 int cell_rows, cell_cols;
5843 for (
int j = topRow; j <= bottomRow; j++ )
5845 for (
int colPos = leftCol; colPos <= rightCol; colPos++ )
5847 int i = GetColAt( colPos );
5849 GetCellSize( j, i, &cell_rows, &cell_cols );
5850 if ((cell_rows > 1) || (cell_cols > 1))
5852 rect = CellToRect(j,i);
5853 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
5854 clippedcells.Subtract(rect);
5856 else if ((cell_rows < 0) || (cell_cols < 0))
5858 rect = CellToRect(j + cell_rows, i + cell_cols);
5859 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
5860 clippedcells.Subtract(rect);
5865 dc.SetDeviceClippingRegion( clippedcells );
5868 top, left, bottom, right,
5869 topRow, leftCol, m_numRows, m_numCols);
5871 dc.DestroyClippingRegion();
5875wxGrid::DoDrawGridLines(wxDC& dc,
5877 int bottom,
int right,
5878 int topRow,
int leftCol,
5879 int bottomRow,
int rightCol)
5882 for (
int i = topRow; i < bottomRow; i++ )
5884 int bot = GetRowBottom(i) - 1;
5891 dc.SetPen( GetRowGridLinePen(i) );
5892 dc.DrawLine( left, bot, right, bot );
5897 for (
int colPos = leftCol; colPos < rightCol; colPos++ )
5899 int i = GetColAt( colPos );
5901 int colRight = GetColRight(i);
5903 if (GetLayoutDirection() != wxLayout_RightToLeft)
5907 if ( colRight > right )
5910 if ( colRight >= left )
5912 dc.SetPen( GetColGridLinePen(i) );
5913 dc.DrawLine( colRight, top, colRight, bottom );
5918void wxGrid::DrawRowLabels( wxDC& dc,
const wxArrayInt& rows)
5923 const size_t numLabels = rows.GetCount();
5924 for (
size_t i = 0; i < numLabels; i++ )
5926 DrawRowLabel( dc, rows[i] );
5930void wxGrid::DrawRowLabel( wxDC& dc,
int row )
5932 if ( GetRowHeight(row) <= 0 || m_rowLabelWidth <= 0 )
5935 wxGridCellAttrProvider *
const
5936 attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
5941 const wxGridRowHeaderRenderer&
5942 rend = attrProvider ? attrProvider->GetRowHeaderRenderer(row)
5943 :
static_cast<const wxGridRowHeaderRenderer&
>
5944 (gs_defaultHeaderRenderers.rowRenderer);
5946 wxRect rect(0, GetRowTop(row), m_rowLabelWidth, GetRowHeight(row));
5947 rend.DrawBorder(*
this, dc, rect);
5950 GetRowLabelAlignment(&hAlign, &vAlign);
5952 rend.DrawLabel(*
this, dc, GetRowLabelValue(row),
5953 rect, hAlign, vAlign, wxHORIZONTAL);
5956void wxGrid::UseNativeColHeader(
bool native)
5958 if ( native == m_useNativeHeader )
5962 m_useNativeHeader = native;
5964 CreateColumnWindow();
5966 if ( m_useNativeHeader )
5967 GetGridColHeader()->SetColumnCount(m_numCols);
5971void wxGrid::SetUseNativeColLabels(
bool native )
5973 wxASSERT_MSG( !m_useNativeHeader,
5974 "doesn't make sense when using native header" );
5976 m_nativeColumnLabels = native;
5979 int height = wxRendererNative::Get().GetHeaderButtonHeight(
this );
5980 SetColLabelSize( height );
5983 GetColLabelWindow()->Refresh();
5984 m_cornerLabelWin->Refresh();
5987void wxGrid::DrawColLabels( wxDC& dc,
const wxArrayInt& cols )
5992 const size_t numLabels = cols.GetCount();
5993 for (
size_t i = 0; i < numLabels; i++ )
5995 DrawColLabel( dc, cols[i] );
5999void wxGrid::DrawCornerLabel(wxDC& dc)
6001 wxRect rect(wxSize(m_rowLabelWidth, m_colLabelHeight));
6003 if ( m_nativeColumnLabels )
6007 wxRendererNative::Get().DrawHeaderButton(m_cornerLabelWin, dc, rect, 0);
6014 wxGridCellAttrProvider *
const
6015 attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
6016 const wxGridCornerHeaderRenderer&
6017 rend = attrProvider ? attrProvider->GetCornerRenderer()
6018 :
static_cast<wxGridCornerHeaderRenderer&
>
6019 (gs_defaultHeaderRenderers.cornerRenderer);
6021 rend.DrawBorder(*
this, dc, rect);
6025void wxGrid::DrawColLabel(wxDC& dc,
int col)
6027 if ( GetColWidth(col) <= 0 || m_colLabelHeight <= 0 )
6030 int colLeft = GetColLeft(col);
6032 wxRect rect(colLeft, 0, GetColWidth(col), m_colLabelHeight);
6033 wxGridCellAttrProvider *
const
6034 attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
6035 const wxGridColumnHeaderRenderer&
6036 rend = attrProvider ? attrProvider->GetColumnHeaderRenderer(col)
6037 :
static_cast<wxGridColumnHeaderRenderer&
>
6038 (gs_defaultHeaderRenderers.colRenderer);
6040 if ( m_nativeColumnLabels )
6042 wxRendererNative::Get().DrawHeaderButton
6044 GetColLabelWindow(),
6049 ? IsSortOrderAscending()
6050 ? wxHDR_SORT_ICON_UP
6051 : wxHDR_SORT_ICON_DOWN
6052 : wxHDR_SORT_ICON_NONE
6060 wxDCBrushChanger setBrush(dc, m_colWindow->GetBackgroundColour());
6061 dc.DrawRectangle(rect);
6063 rend.DrawBorder(*
this, dc, rect);
6067 GetColLabelAlignment(&hAlign, &vAlign);
6068 const int orient = GetColLabelTextOrientation();
6070 rend.DrawLabel(*
this, dc, GetColLabelValue(col), rect, hAlign, vAlign, orient);
6075void wxGrid::DrawTextRectangle( wxDC& dc,
6076 const wxString& value,
6080 int textOrientation )
const
6082 wxArrayString lines;
6084 StringToLines( value, lines );
6086 DrawTextRectangle(dc, lines, rect, horizAlign, vertAlign, textOrientation);
6089void wxGrid::DrawTextRectangle(wxDC& dc,
6090 const wxArrayString& lines,
6094 int textOrientation)
const
6096 if ( lines.empty() )
6099 wxDCClipper clip(dc, rect);
6104 if ( textOrientation == wxHORIZONTAL )
6105 GetTextBoxSize( dc, lines, &textWidth, &textHeight );
6107 GetTextBoxSize( dc, lines, &textHeight, &textWidth );
6111 switch ( vertAlign )
6113 case wxALIGN_BOTTOM:
6114 if ( textOrientation == wxHORIZONTAL )
6115 y = rect.y + (rect.height - textHeight - 1);
6117 x = rect.x + rect.width - textWidth;
6120 case wxALIGN_CENTRE:
6121 if ( textOrientation == wxHORIZONTAL )
6122 y = rect.y + ((rect.height - textHeight) / 2);
6124 x = rect.x + ((rect.width - textWidth) / 2);
6129 if ( textOrientation == wxHORIZONTAL )
6137 size_t nLines = lines.GetCount();
6138 for (
size_t l = 0; l < nLines; l++ )
6140 const wxString& line = lines[l];
6144 *(textOrientation == wxHORIZONTAL ? &y : &x) += dc.GetCharHeight();
6148 wxCoord lineWidth = 0,
6150 dc.GetTextExtent(line, &lineWidth, &lineHeight);
6152 switch ( horizAlign )
6155 if ( textOrientation == wxHORIZONTAL )
6156 x = rect.x + (rect.width - lineWidth - 1);
6158 y = rect.y + lineWidth + 1;
6161 case wxALIGN_CENTRE:
6162 if ( textOrientation == wxHORIZONTAL )
6163 x = rect.x + ((rect.width - lineWidth) / 2);
6165 y = rect.y + rect.height - ((rect.height - lineWidth) / 2);
6170 if ( textOrientation == wxHORIZONTAL )
6173 y = rect.y + rect.height - 1;
6177 if ( textOrientation == wxHORIZONTAL )
6179 dc.DrawText( line, x, y );
6184 dc.DrawRotatedText( line, x, y, 90.0 );
6194void wxGrid::StringToLines(
const wxString& value, wxArrayString& lines )
const
6198 wxString eol = wxTextFile::GetEOL( wxTextFileType_Unix );
6199 wxString tVal = wxTextFile::Translate( value, wxTextFileType_Unix );
6201 while ( startPos < (
int)tVal.length() )
6203 pos = tVal.Mid(startPos).Find( eol );
6208 else if ( pos == 0 )
6210 lines.Add( wxEmptyString );
6214 lines.Add( tVal.Mid(startPos, pos) );
6217 startPos += pos + 1;
6220 if ( startPos < (
int)tVal.length() )
6222 lines.Add( tVal.Mid( startPos ) );
6226void wxGrid::GetTextBoxSize(
const wxDC& dc,
6227 const wxArrayString& lines,
6228 long *width,
long *height )
const
6232 wxCoord lineW = 0, lineH = 0;
6235 for ( i = 0; i < lines.GetCount(); i++ )
6237 dc.GetTextExtent( lines[i], &lineW, &lineH );
6238 w = wxMax( w, lineW );
6249void wxGrid::EndBatch()
6251 if ( m_batchCount > 0 )
6254 if ( !m_batchCount )
6257 m_rowLabelWin->Refresh();
6258 m_colWindow->Refresh();
6259 m_cornerLabelWin->Refresh();
6260 m_gridWin->Refresh();
6269void wxGrid::ForceRefresh()
6275bool wxGrid::Enable(
bool enable)
6277 if ( !wxScrolledWindow::Enable(enable) )
6281 m_gridWin->Refresh();
6290void wxGrid::EnableEditing(
bool edit )
6292 if ( edit != m_editable )
6295 EnableCellEditControl(edit);
6300void wxGrid::EnableCellEditControl(
bool enable )
6305 if ( enable != m_cellEditCtrlEnabled )
6309 if ( SendEvent(wxEVT_GRID_EDITOR_SHOWN) == -1 )
6313 wxASSERT_MSG( CanEnableCellControl(), wxT(
"can't enable editing for this cell!") );
6316 m_cellEditCtrlEnabled = enable;
6318 ShowCellEditControl();
6322 SendEvent(wxEVT_GRID_EDITOR_HIDDEN);
6324 HideCellEditControl();
6325 SaveEditControlValue();
6328 m_cellEditCtrlEnabled = enable;
6333bool wxGrid::IsCurrentCellReadOnly()
const
6336 attr =
const_cast<wxGrid *
>(
this)->GetCellAttr(m_currentCellCoords);
6337 bool readonly = attr->IsReadOnly();
6343bool wxGrid::CanEnableCellControl()
const
6345 return m_editable && (m_currentCellCoords != wxGridNoCellCoords) &&
6346 !IsCurrentCellReadOnly();
6349bool wxGrid::IsCellEditControlEnabled()
const
6353 return m_cellEditCtrlEnabled ? !IsCurrentCellReadOnly() : false;
6356bool wxGrid::IsCellEditControlShown()
const
6358 bool isShown =
false;
6360 if ( m_cellEditCtrlEnabled )
6362 int row = m_currentCellCoords.GetRow();
6363 int col = m_currentCellCoords.GetCol();
6364 wxGridCellAttr* attr = GetCellAttr(row, col);
6365 wxGridCellEditor* editor = attr->GetEditor((wxGrid*)
this, row, col);
6370 if ( editor->IsCreated() )
6372 isShown = editor->GetControl()->IsShown();
6382void wxGrid::ShowCellEditControl()
6384 if ( IsCellEditControlEnabled() )
6386 if ( !IsVisible( m_currentCellCoords,
false ) )
6388 m_cellEditCtrlEnabled =
false;
6393 wxRect rect = CellToRect( m_currentCellCoords );
6394 int row = m_currentCellCoords.GetRow();
6395 int col = m_currentCellCoords.GetCol();
6398 int cell_rows, cell_cols;
6399 GetCellSize( row, col, &cell_rows, &cell_cols );
6400 if ( cell_rows <= 0 || cell_cols <= 0 )
6404 m_currentCellCoords.SetRow( row );
6405 m_currentCellCoords.SetCol( col );
6410 wxClientDC dc( m_gridWin );
6412 wxGridCellAttr* attr = GetCellAttr(row, col);
6413 dc.SetBrush(wxBrush(attr->GetBackgroundColour()));
6414 dc.SetPen(*wxTRANSPARENT_PEN);
6415 dc.DrawRectangle(rect);
6418 CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
6433 wxGridCellEditor* editor = attr->GetEditor(
this, row, col);
6434 if ( !editor->IsCreated() )
6436 editor->Create(m_gridWin, wxID_ANY,
6437 new wxGridCellEditorEvtHandler(
this, editor));
6439 wxGridEditorCreatedEvent evt(GetId(),
6440 wxEVT_GRID_EDITOR_CREATED,
6444 editor->GetControl());
6445 GetEventHandler()->ProcessEvent(evt);
6449 int maxWidth = rect.width;
6450 wxString value = GetCellValue(row, col);
6451 if ( (value != wxEmptyString) && (attr->GetOverflow()) )
6454 GetTextExtent(value, &maxWidth, &y, NULL, NULL, &attr->GetFont());
6455 if (maxWidth < rect.width)
6456 maxWidth = rect.width;
6459 int client_right = m_gridWin->GetClientSize().GetWidth();
6460 if (rect.x + maxWidth > client_right)
6461 maxWidth = client_right - rect.x;
6463 if ((maxWidth > rect.width) && (col < m_numCols) && m_table)
6465 GetCellSize( row, col, &cell_rows, &cell_cols );
6467 for (
int i = col + cell_cols; i < m_numCols; i++)
6470 GetCellSize( row, i, &c_rows, &c_cols );
6473 if (m_table->IsEmptyCell( row, i ) &&
6474 (rect.width < maxWidth) && (c_rows == 1))
6476 rect.width += GetColWidth( i );
6482 if (rect.GetRight() > client_right)
6483 rect.SetRight( client_right - 1 );
6486 editor->SetCellAttr( attr );
6487 editor->SetSize( rect );
6489 editor->GetControl()->Move(
6490 editor->GetControl()->GetPosition().x + nXMove,
6491 editor->GetControl()->GetPosition().y );
6492 editor->Show(
true, attr );
6498 editor->BeginEdit(row, col,
this);
6499 editor->SetCellAttr(NULL);
6507void wxGrid::HideCellEditControl()
6509 if ( IsCellEditControlEnabled() )
6511 int row = m_currentCellCoords.GetRow();
6512 int col = m_currentCellCoords.GetCol();
6514 wxGridCellAttr *attr = GetCellAttr(row, col);
6515 wxGridCellEditor *editor = attr->GetEditor(
this, row, col);
6516 const bool editorHadFocus = editor->GetControl()->HasFocus();
6517 editor->Show(
false );
6526 if ( editorHadFocus )
6527 m_gridWin->SetFocus();
6530 wxRect rect( CellToRect(row, col) );
6531 CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y );
6532 rect.width = m_gridWin->GetClientSize().GetWidth() - rect.x;
6536 rect.Inflate(10, 10);
6539 m_gridWin->Refresh(
false, &rect );
6543void wxGrid::SaveEditControlValue()
6545 if ( IsCellEditControlEnabled() )
6547 int row = m_currentCellCoords.GetRow();
6548 int col = m_currentCellCoords.GetCol();
6550 wxString oldval = GetCellValue(row, col);
6552 wxGridCellAttr* attr = GetCellAttr(row, col);
6553 wxGridCellEditor* editor = attr->GetEditor(
this, row, col);
6556 bool changed = editor->EndEdit(row, col,
this, oldval, &newval);
6558 if ( changed && SendEvent(wxEVT_GRID_CELL_CHANGING, newval) != -1 )
6560 editor->ApplyEdit(row, col,
this);
6565 if ( SendEvent(wxEVT_GRID_CELL_CHANGED, oldval) == -1 )
6568 SetCellValue(row, col, oldval);
6577void wxGrid::OnHideEditor(wxCommandEvent& WXUNUSED(event))
6579 DisableCellEditControl();
6589wxGridCellCoords wxGrid::XYToCell(
int x,
int y)
const
6591 int row = YToRow(y);
6592 int col = XToCol(x);
6594 return row == -1 || col == -1 ? wxGridNoCellCoords
6595 : wxGridCellCoords(row, col);
6602int wxGrid::PosToLinePos(
int coord,
6604 const wxGridOperations& oper)
const
6606 const int numLines = oper.GetNumberOfLines(
this);
6609 return clipToMinMax && numLines > 0 ? 0 : wxNOT_FOUND;
6611 const int defaultLineSize = oper.GetDefaultLineSize(
this);
6612 wxCHECK_MSG( defaultLineSize, -1,
"can't have 0 default line size" );
6614 int maxPos = coord / defaultLineSize,
6619 const wxArrayInt& lineEnds = oper.GetLineEnds(
this);
6620 if ( lineEnds.empty() )
6622 if ( maxPos < numLines )
6625 return clipToMinMax ? numLines - 1 : -1;
6633 maxPos = numLines - 1;
6636 const int lineAtMaxPos = oper.GetLineAt(
this, maxPos);
6637 if ( coord >= lineEnds[lineAtMaxPos] )
6638 return clipToMinMax ? maxPos : -1;
6641 const int lineAt0 = oper.GetLineAt(
this, 0);
6642 if ( coord < lineEnds[lineAt0] )
6647 while ( minPos < maxPos )
6649 wxCHECK_MSG( lineEnds[oper.GetLineAt(
this, minPos)] <= coord &&
6650 coord < lineEnds[oper.GetLineAt(
this, maxPos)],
6652 "wxGrid: internal error in PosToLinePos()" );
6654 if ( coord >= lineEnds[oper.GetLineAt(
this, maxPos - 1)] )
6659 const int median = minPos + (maxPos - minPos + 1) / 2;
6660 if ( coord < lineEnds[oper.GetLineAt(
this, median)] )
6670wxGrid::PosToLine(
int coord,
6672 const wxGridOperations& oper)
const
6674 int pos = PosToLinePos(coord, clipToMinMax, oper);
6676 return pos == wxNOT_FOUND ? wxNOT_FOUND : oper.GetLineAt(
this, pos);
6679int wxGrid::YToRow(
int y,
bool clipToMinMax)
const
6681 return PosToLine(y, clipToMinMax, wxGridRowOperations());
6684int wxGrid::XToCol(
int x,
bool clipToMinMax)
const
6686 return PosToLine(x, clipToMinMax, wxGridColumnOperations());
6689int wxGrid::XToPos(
int x)
const
6691 return PosToLinePos(x,
true , wxGridColumnOperations());
6701int wxGrid::PosToEdgeOfLine(
int pos,
const wxGridOperations& oper)
const
6704 int line = oper.PosToLine(
this, pos,
true);
6706 if ( oper.GetLineSize(
this, line) > WXGRID_LABEL_EDGE_ZONE )
6710 if (
abs(oper.GetLineEndPos(
this, line) - pos) < WXGRID_LABEL_EDGE_ZONE )
6712 else if ( line > 0 &&
6713 pos - oper.GetLineStartPos(
this,
6714 line) < WXGRID_LABEL_EDGE_ZONE )
6720 line = oper.GetLineBefore(
this, line);
6722 while ( line >= 0 && oper.GetLineSize(
this, line) == 0 );
6732int wxGrid::YToEdgeOfRow(
int y)
const
6734 return PosToEdgeOfLine(y, wxGridRowOperations());
6737int wxGrid::XToEdgeOfCol(
int x)
const
6739 return PosToEdgeOfLine(x, wxGridColumnOperations());
6742wxRect wxGrid::CellToRect(
int row,
int col )
const
6744 wxRect rect( -1, -1, -1, -1 );
6746 if ( row >= 0 && row < m_numRows &&
6747 col >= 0 && col < m_numCols )
6749 int i, cell_rows, cell_cols;
6750 rect.width = rect.height = 0;
6751 GetCellSize( row, col, &cell_rows, &cell_cols );
6757 GetCellSize( row, col, &cell_rows, &cell_cols );
6759 rect.x = GetColLeft(col);
6760 rect.y = GetRowTop(row);
6761 for (i=col; i < col + cell_cols; i++)
6762 rect.width += GetColWidth(i);
6763 for (i=row; i < row + cell_rows; i++)
6764 rect.height += GetRowHeight(i);
6767 if (m_gridLinesEnabled)
6777bool wxGrid::IsVisible(
int row,
int col,
bool wholeCellVisible )
const
6781 wxRect r( CellToRect( row, col ) );
6785 int left, top, right, bottom;
6786 CalcScrolledPosition( r.GetLeft(), r.GetTop(), &left, &top );
6787 CalcScrolledPosition( r.GetRight(), r.GetBottom(), &right, &bottom );
6791 m_gridWin->GetClientSize( &cw, &ch );
6793 if ( wholeCellVisible )
6796 return ( left >= 0 && right <= cw &&
6797 top >= 0 && bottom <= ch );
6803 return ( ((left >= 0 && left < cw) || (right > 0 && right <= cw)) &&
6804 ((top >= 0 && top < ch) || (bottom > 0 && bottom <= ch)) );
6811void wxGrid::MakeCellVisible(
int row,
int col )
6814 int xpos = -1, ypos = -1;
6816 if ( row >= 0 && row < m_numRows &&
6817 col >= 0 && col < m_numCols )
6820 wxRect r( CellToRect( row, col ) );
6823 int left, top, right, bottom;
6824 CalcScrolledPosition( r.GetLeft(), r.GetTop(), &left, &top );
6825 CalcScrolledPosition( r.GetRight(), r.GetBottom(), &right, &bottom );
6828 m_gridWin->GetClientSize( &cw, &ch );
6834 else if ( bottom > ch )
6836 int h = r.GetHeight();
6838 for ( i = row - 1; i >= 0; i-- )
6840 int rowHeight = GetRowHeight(i);
6841 if ( h + rowHeight > ch )
6854 ypos += m_yScrollPixelsPerLine;
6861 if ( left < 0 || (right - left) >= cw )
6865 else if ( right > cw )
6869 CalcUnscrolledPosition(0, 0, &x0, &y0);
6870 xpos = x0 + (right - cw);
6873 xpos += m_xScrollPixelsPerLine;
6876 if ( xpos != -1 || ypos != -1 )
6879 xpos /= m_xScrollPixelsPerLine;
6881 ypos /= m_yScrollPixelsPerLine;
6882 Scroll( xpos, ypos );
6893wxGrid::DoMoveCursor(
bool expandSelection,
6894 const wxGridDirectionOperations& diroper)
6896 if ( m_currentCellCoords == wxGridNoCellCoords )
6899 if ( expandSelection )
6901 wxGridCellCoords coords = m_selectedBlockCorner;
6902 if ( coords == wxGridNoCellCoords )
6903 coords = m_currentCellCoords;
6905 if ( diroper.IsAtBoundary(coords) )
6908 diroper.Advance(coords);
6910 UpdateBlockBeingSelected(m_currentCellCoords, coords);
6916 if ( diroper.IsAtBoundary(m_currentCellCoords) )
6919 wxGridCellCoords coords = m_currentCellCoords;
6920 diroper.Advance(coords);
6928bool wxGrid::MoveCursorUp(
bool expandSelection)
6930 return DoMoveCursor(expandSelection,
6931 wxGridBackwardOperations(
this, wxGridRowOperations()));
6934bool wxGrid::MoveCursorDown(
bool expandSelection)
6936 return DoMoveCursor(expandSelection,
6937 wxGridForwardOperations(
this, wxGridRowOperations()));
6940bool wxGrid::MoveCursorLeft(
bool expandSelection)
6942 return DoMoveCursor(expandSelection,
6943 wxGridBackwardOperations(
this, wxGridColumnOperations()));
6946bool wxGrid::MoveCursorRight(
bool expandSelection)
6948 return DoMoveCursor(expandSelection,
6949 wxGridForwardOperations(
this, wxGridColumnOperations()));
6952bool wxGrid::DoMoveCursorByPage(
const wxGridDirectionOperations& diroper)
6954 if ( m_currentCellCoords == wxGridNoCellCoords )
6957 if ( diroper.IsAtBoundary(m_currentCellCoords) )
6960 const int oldRow = m_currentCellCoords.GetRow();
6961 int newRow = diroper.MoveByPixelDistance(oldRow, m_gridWin->GetClientSize().y);
6962 if ( newRow == oldRow )
6964 wxGridCellCoords coords(m_currentCellCoords);
6965 diroper.Advance(coords);
6966 newRow = coords.GetRow();
6969 GoToCell(newRow, m_currentCellCoords.GetCol());
6974bool wxGrid::MovePageUp()
6976 return DoMoveCursorByPage(
6977 wxGridBackwardOperations(
this, wxGridRowOperations()));
6980bool wxGrid::MovePageDown()
6982 return DoMoveCursorByPage(
6983 wxGridForwardOperations(
this, wxGridRowOperations()));
6989wxGrid::AdvanceToNextNonEmpty(wxGridCellCoords& coords,
6990 const wxGridDirectionOperations& diroper)
6992 while ( !diroper.IsAtBoundary(coords) )
6994 diroper.Advance(coords);
6995 if ( !m_table->IsEmpty(coords) )
7001wxGrid::DoMoveCursorByBlock(
bool expandSelection,
7002 const wxGridDirectionOperations& diroper)
7004 if ( !m_table || m_currentCellCoords == wxGridNoCellCoords )
7007 if ( diroper.IsAtBoundary(m_currentCellCoords) )
7010 wxGridCellCoords coords(m_currentCellCoords);
7011 if ( m_table->IsEmpty(coords) )
7014 AdvanceToNextNonEmpty(coords, diroper);
7018 diroper.Advance(coords);
7019 if ( m_table->IsEmpty(coords) )
7022 AdvanceToNextNonEmpty(coords, diroper);
7028 while ( !diroper.IsAtBoundary(coords) )
7030 wxGridCellCoords coordsNext(coords);
7031 diroper.Advance(coordsNext);
7032 if ( m_table->IsEmpty(coordsNext) )
7035 coords = coordsNext;
7040 if ( expandSelection )
7042 UpdateBlockBeingSelected(m_currentCellCoords, coords);
7053bool wxGrid::MoveCursorUpBlock(
bool expandSelection)
7055 return DoMoveCursorByBlock(
7057 wxGridBackwardOperations(
this, wxGridRowOperations())
7061bool wxGrid::MoveCursorDownBlock(
bool expandSelection )
7063 return DoMoveCursorByBlock(
7065 wxGridForwardOperations(
this, wxGridRowOperations())
7069bool wxGrid::MoveCursorLeftBlock(
bool expandSelection )
7071 return DoMoveCursorByBlock(
7073 wxGridBackwardOperations(
this, wxGridColumnOperations())
7077bool wxGrid::MoveCursorRightBlock(
bool expandSelection )
7079 return DoMoveCursorByBlock(
7081 wxGridForwardOperations(
this, wxGridColumnOperations())
7089void wxGrid::GetRowLabelAlignment(
int *horiz,
int *vert )
const
7092 *horiz = m_rowLabelHorizAlign;
7094 *vert = m_rowLabelVertAlign;
7097void wxGrid::GetColLabelAlignment(
int *horiz,
int *vert )
const
7100 *horiz = m_colLabelHorizAlign;
7102 *vert = m_colLabelVertAlign;
7105int wxGrid::GetColLabelTextOrientation()
const
7107 return m_colLabelTextOrientation;
7110wxString wxGrid::GetRowLabelValue(
int row )
const
7114 return m_table->GetRowLabelValue( row );
7124wxString wxGrid::GetColLabelValue(
int col )
const
7128 return m_table->GetColLabelValue( col );
7138void wxGrid::SetRowLabelSize(
int width )
7140 wxASSERT( width >= 0 || width == wxGRID_AUTOSIZE );
7142 if ( width == wxGRID_AUTOSIZE )
7144 width = CalcColOrRowLabelAreaMinSize(wxGRID_ROW);
7147 if ( width != m_rowLabelWidth )
7151 m_rowLabelWin->Show(
false );
7152 m_cornerLabelWin->Show(
false );
7154 else if ( m_rowLabelWidth == 0 )
7156 m_rowLabelWin->Show(
true );
7157 if ( m_colLabelHeight > 0 )
7158 m_cornerLabelWin->Show(
true );
7161 m_rowLabelWidth = width;
7162 InvalidateBestSize();
7164 wxScrolledWindow::Refresh(
true );
7168void wxGrid::SetColLabelSize(
int height )
7170 wxASSERT( height >=0 || height == wxGRID_AUTOSIZE );
7172 if ( height == wxGRID_AUTOSIZE )
7174 height = CalcColOrRowLabelAreaMinSize(wxGRID_COLUMN);
7177 if ( height != m_colLabelHeight )
7181 m_colWindow->Show(
false );
7182 m_cornerLabelWin->Show(
false );
7184 else if ( m_colLabelHeight == 0 )
7186 m_colWindow->Show(
true );
7187 if ( m_rowLabelWidth > 0 )
7188 m_cornerLabelWin->Show(
true );
7191 m_colLabelHeight = height;
7192 InvalidateBestSize();
7194 wxScrolledWindow::Refresh(
true );
7198void wxGrid::SetLabelBackgroundColour(
const wxColour& colour )
7200 if ( m_labelBackgroundColour != colour )
7202 m_labelBackgroundColour = colour;
7203 m_rowLabelWin->SetBackgroundColour( colour );
7204 m_colWindow->SetBackgroundColour( colour );
7205 m_cornerLabelWin->SetBackgroundColour( colour );
7207 if ( !GetBatchCount() )
7209 m_rowLabelWin->Refresh();
7210 m_colWindow->Refresh();
7211 m_cornerLabelWin->Refresh();
7216void wxGrid::SetLabelTextColour(
const wxColour& colour )
7218 if ( m_labelTextColour != colour )
7220 m_labelTextColour = colour;
7221 if ( !GetBatchCount() )
7223 m_rowLabelWin->Refresh();
7224 m_colWindow->Refresh();
7229void wxGrid::SetLabelFont(
const wxFont& font )
7232 if ( !GetBatchCount() )
7234 m_rowLabelWin->Refresh();
7235 m_colWindow->Refresh();
7239void wxGrid::SetRowLabelAlignment(
int horiz,
int vert )
7244 case wxLEFT: horiz = wxALIGN_LEFT;
break;
7245 case wxRIGHT: horiz = wxALIGN_RIGHT;
break;
7246 case wxCENTRE: horiz = wxALIGN_CENTRE;
break;
7251 case wxTOP: vert = wxALIGN_TOP;
break;
7252 case wxBOTTOM: vert = wxALIGN_BOTTOM;
break;
7253 case wxCENTRE: vert = wxALIGN_CENTRE;
break;
7256 if ( horiz == wxALIGN_LEFT || horiz == wxALIGN_CENTRE || horiz == wxALIGN_RIGHT )
7258 m_rowLabelHorizAlign = horiz;
7261 if ( vert == wxALIGN_TOP || vert == wxALIGN_CENTRE || vert == wxALIGN_BOTTOM )
7263 m_rowLabelVertAlign = vert;
7266 if ( !GetBatchCount() )
7268 m_rowLabelWin->Refresh();
7272void wxGrid::SetColLabelAlignment(
int horiz,
int vert )
7277 case wxLEFT: horiz = wxALIGN_LEFT;
break;
7278 case wxRIGHT: horiz = wxALIGN_RIGHT;
break;
7279 case wxCENTRE: horiz = wxALIGN_CENTRE;
break;
7284 case wxTOP: vert = wxALIGN_TOP;
break;
7285 case wxBOTTOM: vert = wxALIGN_BOTTOM;
break;
7286 case wxCENTRE: vert = wxALIGN_CENTRE;
break;
7289 if ( horiz == wxALIGN_LEFT || horiz == wxALIGN_CENTRE || horiz == wxALIGN_RIGHT )
7291 m_colLabelHorizAlign = horiz;
7294 if ( vert == wxALIGN_TOP || vert == wxALIGN_CENTRE || vert == wxALIGN_BOTTOM )
7296 m_colLabelVertAlign = vert;
7299 if ( !GetBatchCount() )
7301 m_colWindow->Refresh();
7312void wxGrid::SetColLabelTextOrientation(
int textOrientation )
7314 if ( textOrientation == wxHORIZONTAL || textOrientation == wxVERTICAL )
7315 m_colLabelTextOrientation = textOrientation;
7317 if ( !GetBatchCount() )
7318 m_colWindow->Refresh();
7321void wxGrid::SetRowLabelValue(
int row,
const wxString& s )
7325 m_table->SetRowLabelValue( row, s );
7326 if ( !GetBatchCount() )
7328 wxRect rect = CellToRect( row, 0 );
7329 if ( rect.height > 0 )
7331 CalcScrolledPosition(0, rect.y, &rect.x, &rect.y);
7333 rect.width = m_rowLabelWidth;
7334 m_rowLabelWin->Refresh(
true, &rect );
7340void wxGrid::SetColLabelValue(
int col,
const wxString& s )
7344 m_table->SetColLabelValue( col, s );
7345 if ( !GetBatchCount() )
7347 if ( m_useNativeHeader )
7349 GetGridColHeader()->UpdateColumn(col);
7353 wxRect rect = CellToRect( 0, col );
7354 if ( rect.width > 0 )
7356 CalcScrolledPosition(rect.x, 0, &rect.x, &rect.y);
7358 rect.height = m_colLabelHeight;
7359 GetColLabelWindow()->Refresh(
true, &rect );
7366void wxGrid::SetGridLineColour(
const wxColour& colour )
7368 if ( m_gridLineColour != colour )
7370 m_gridLineColour = colour;
7372 if ( GridLinesEnabled() )
7377void wxGrid::SetCellHighlightColour(
const wxColour& colour )
7379 if ( m_cellHighlightColour != colour )
7381 m_cellHighlightColour = colour;
7383 wxClientDC dc( m_gridWin );
7385 wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords);
7386 DrawCellHighlight(dc, attr);
7391void wxGrid::SetCellHighlightPenWidth(
int width)
7393 if (m_cellHighlightPenWidth != width)
7395 m_cellHighlightPenWidth = width;
7399 int row = m_currentCellCoords.GetRow();
7400 int col = m_currentCellCoords.GetCol();
7401 if ( row == -1 || col == -1 || GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 )
7404 wxRect rect = CellToRect(row, col);
7405 m_gridWin->Refresh(
true, &rect);
7409void wxGrid::SetCellHighlightROPenWidth(
int width)
7411 if (m_cellHighlightROPenWidth != width)
7413 m_cellHighlightROPenWidth = width;
7417 int row = m_currentCellCoords.GetRow();
7418 int col = m_currentCellCoords.GetCol();
7419 if ( row == -1 || col == -1 ||
7420 GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 )
7423 wxRect rect = CellToRect(row, col);
7424 m_gridWin->Refresh(
true, &rect);
7428void wxGrid::RedrawGridLines()
7431 if ( GetBatchCount() )
7434 if ( GridLinesEnabled() )
7436 wxClientDC dc( m_gridWin );
7438 DrawAllGridLines( dc, wxRegion() );
7442 m_gridWin->Refresh();
7446void wxGrid::EnableGridLines(
bool enable )
7448 if ( enable != m_gridLinesEnabled )
7450 m_gridLinesEnabled = enable;
7456void wxGrid::DoClipGridLines(
bool& var,
bool clip)
7462 if ( GridLinesEnabled() )
7467int wxGrid::GetDefaultRowSize()
const
7469 return m_defaultRowHeight;
7472int wxGrid::GetRowSize(
int row )
const
7474 wxCHECK_MSG( row >= 0 && row < m_numRows, 0, wxT(
"invalid row index") );
7476 return GetRowHeight(row);
7479int wxGrid::GetDefaultColSize()
const
7481 return m_defaultColWidth;
7484int wxGrid::GetColSize(
int col )
const
7486 wxCHECK_MSG( col >= 0 && col < m_numCols, 0, wxT(
"invalid column index") );
7488 return GetColWidth(col);
7500void wxGrid::SetDefaultCellBackgroundColour(
const wxColour& col )
7502 m_defaultCellAttr->SetBackgroundColour(col);
7504 m_gridWin->SetBackgroundColour(col);
7508void wxGrid::SetDefaultCellTextColour(
const wxColour& col )
7510 m_defaultCellAttr->SetTextColour(col);
7513void wxGrid::SetDefaultCellAlignment(
int horiz,
int vert )
7515 m_defaultCellAttr->SetAlignment(horiz, vert);
7518void wxGrid::SetDefaultCellOverflow(
bool allow )
7520 m_defaultCellAttr->SetOverflow(allow);
7523void wxGrid::SetDefaultCellFont(
const wxFont& font )
7525 m_defaultCellAttr->SetFont(font);
7533void wxGrid::SetDefaultRenderer(wxGridCellRenderer *renderer)
7535 RegisterDataType(wxGRID_VALUE_STRING,
7537 GetDefaultEditorForType(wxGRID_VALUE_STRING));
7540void wxGrid::SetDefaultEditor(wxGridCellEditor *editor)
7542 RegisterDataType(wxGRID_VALUE_STRING,
7543 GetDefaultRendererForType(wxGRID_VALUE_STRING),
7551wxColour wxGrid::GetDefaultCellBackgroundColour()
const
7553 return m_defaultCellAttr->GetBackgroundColour();
7556wxColour wxGrid::GetDefaultCellTextColour()
const
7558 return m_defaultCellAttr->GetTextColour();
7561wxFont wxGrid::GetDefaultCellFont()
const
7563 return m_defaultCellAttr->GetFont();
7566void wxGrid::GetDefaultCellAlignment(
int *horiz,
int *vert )
const
7568 m_defaultCellAttr->GetAlignment(horiz, vert);
7571bool wxGrid::GetDefaultCellOverflow()
const
7573 return m_defaultCellAttr->GetOverflow();
7576wxGridCellRenderer *wxGrid::GetDefaultRenderer()
const
7578 return m_defaultCellAttr->GetRenderer(NULL, 0, 0);
7581wxGridCellEditor *wxGrid::GetDefaultEditor()
const
7583 return m_defaultCellAttr->GetEditor(NULL, 0, 0);
7590wxColour wxGrid::GetCellBackgroundColour(
int row,
int col)
const
7592 wxGridCellAttr *attr = GetCellAttr(row, col);
7593 wxColour colour = attr->GetBackgroundColour();
7599wxColour wxGrid::GetCellTextColour(
int row,
int col )
const
7601 wxGridCellAttr *attr = GetCellAttr(row, col);
7602 wxColour colour = attr->GetTextColour();
7608wxFont wxGrid::GetCellFont(
int row,
int col )
const
7610 wxGridCellAttr *attr = GetCellAttr(row, col);
7611 wxFont font = attr->GetFont();
7617void wxGrid::GetCellAlignment(
int row,
int col,
int *horiz,
int *vert )
const
7619 wxGridCellAttr *attr = GetCellAttr(row, col);
7620 attr->GetAlignment(horiz, vert);
7624bool wxGrid::GetCellOverflow(
int row,
int col )
const
7626 wxGridCellAttr *attr = GetCellAttr(row, col);
7627 bool allow = attr->GetOverflow();
7634wxGrid::GetCellSize(
int row,
int col,
int *num_rows,
int *num_cols )
const
7636 wxGridCellAttr *attr = GetCellAttr(row, col);
7637 attr->GetSize( num_rows, num_cols );
7640 if ( *num_rows == 1 && *num_cols == 1 )
7641 return CellSpan_None;
7643 if ( *num_rows < 0 || *num_cols < 0 )
7644 return CellSpan_Inside;
7647 return CellSpan_Main;
7650wxGridCellRenderer* wxGrid::GetCellRenderer(
int row,
int col)
const
7652 wxGridCellAttr* attr = GetCellAttr(row, col);
7653 wxGridCellRenderer* renderer = attr->GetRenderer(
this, row, col);
7659wxGridCellEditor* wxGrid::GetCellEditor(
int row,
int col)
const
7661 wxGridCellAttr* attr = GetCellAttr(row, col);
7662 wxGridCellEditor* editor = attr->GetEditor(
this, row, col);
7668bool wxGrid::IsReadOnly(
int row,
int col)
const
7670 wxGridCellAttr* attr = GetCellAttr(row, col);
7671 bool isReadOnly = attr->IsReadOnly();
7681bool wxGrid::CanHaveAttributes()
const
7688 return m_table->CanHaveAttributes();
7691void wxGrid::ClearAttrCache()
7693 if ( m_attrCache.row != -1 )
7695 wxGridCellAttr *oldAttr = m_attrCache.attr;
7696 m_attrCache.attr = NULL;
7697 m_attrCache.row = -1;
7702 wxSafeDecRef(oldAttr);
7706void wxGrid::RefreshAttr(
int row,
int col)
7708 if ( m_attrCache.row == row && m_attrCache.col == col )
7713void wxGrid::CacheAttr(
int row,
int col, wxGridCellAttr *attr)
const
7717 wxGrid *
const self =
const_cast<wxGrid *
>(
this);
7719 self->ClearAttrCache();
7720 self->m_attrCache.row = row;
7721 self->m_attrCache.col = col;
7722 self->m_attrCache.attr = attr;
7727bool wxGrid::LookupAttr(
int row,
int col, wxGridCellAttr **attr)
const
7729 if ( row == m_attrCache.row && col == m_attrCache.col )
7731 *attr = m_attrCache.attr;
7732 wxSafeIncRef(m_attrCache.attr);
7734#ifdef DEBUG_ATTR_CACHE
7735 gs_nAttrCacheHits++;
7742#ifdef DEBUG_ATTR_CACHE
7743 gs_nAttrCacheMisses++;
7750wxGridCellAttr *wxGrid::GetCellAttr(
int row,
int col)
const
7752 wxGridCellAttr *attr = NULL;
7757 if ( !LookupAttr(row, col, &attr) )
7759 attr = m_table ? m_table->GetAttr(row, col, wxGridCellAttr::Any)
7761 CacheAttr(row, col, attr);
7767 attr->SetDefAttr(m_defaultCellAttr);
7771 attr = m_defaultCellAttr;
7778wxGridCellAttr *wxGrid::GetOrCreateCellAttr(
int row,
int col)
const
7780 wxGridCellAttr *attr = NULL;
7781 bool canHave = ((wxGrid*)
this)->CanHaveAttributes();
7783 wxCHECK_MSG( canHave, attr, wxT(
"Cell attributes not allowed"));
7784 wxCHECK_MSG( m_table, attr, wxT(
"must have a table") );
7786 attr = m_table->GetAttr(row, col, wxGridCellAttr::Cell);
7789 attr =
new wxGridCellAttr(m_defaultCellAttr);
7793 m_table->SetAttr(attr, row, col);
7803void wxGrid::SetColFormatBool(
int col)
7805 SetColFormatCustom(col, wxGRID_VALUE_BOOL);
7808void wxGrid::SetColFormatNumber(
int col)
7810 SetColFormatCustom(col, wxGRID_VALUE_NUMBER);
7813void wxGrid::SetColFormatFloat(
int col,
int width,
int precision)
7815 wxString typeName = wxGRID_VALUE_FLOAT;
7816 if ( (width != -1) || (precision != -1) )
7818 typeName << wxT(
':') << width << wxT(
',') << precision;
7821 SetColFormatCustom(col, typeName);
7824void wxGrid::SetColFormatCustom(
int col,
const wxString& typeName)
7826 wxGridCellAttr *attr = m_table->GetAttr(-1, col, wxGridCellAttr::Col );
7828 attr =
new wxGridCellAttr;
7829 wxGridCellRenderer *renderer = GetDefaultRendererForType(typeName);
7830 attr->SetRenderer(renderer);
7831 wxGridCellEditor *editor = GetDefaultEditorForType(typeName);
7832 attr->SetEditor(editor);
7834 SetColAttr(col, attr);
7842void wxGrid::SetAttr(
int row,
int col, wxGridCellAttr *attr)
7844 if ( CanHaveAttributes() )
7846 m_table->SetAttr(attr, row, col);
7855void wxGrid::SetRowAttr(
int row, wxGridCellAttr *attr,
bool clear)
7857 if ( CanHaveAttributes() )
7859 m_table->SetRowAttr(attr, row, clear);
7868void wxGrid::SetColAttr(
int col, wxGridCellAttr *attr,
bool clear)
7870 if ( CanHaveAttributes() )
7872 m_table->SetColAttr(attr, col, clear);
7881void wxGrid::SetCellBackgroundColour(
int row,
int col,
const wxColour& colour )
7883 if ( CanHaveAttributes() )
7885 wxGridCellAttr *attr = GetOrCreateCellAttr(row, col);
7886 attr->SetBackgroundColour(colour);
7891void wxGrid::SetCellTextColour(
int row,
int col,
const wxColour& colour )
7893 if ( CanHaveAttributes() )
7895 wxGridCellAttr *attr = GetOrCreateCellAttr(row, col);
7896 attr->SetTextColour(colour);
7901void wxGrid::SetCellFont(
int row,
int col,
const wxFont& font )
7903 if ( CanHaveAttributes() )
7905 wxGridCellAttr *attr = GetOrCreateCellAttr(row, col);
7906 attr->SetFont(font);
7911void wxGrid::SetCellAlignment(
int row,
int col,
int horiz,
int vert )
7913 if ( CanHaveAttributes() )
7915 wxGridCellAttr *attr = GetOrCreateCellAttr(row, col);
7916 attr->SetAlignment(horiz, vert);
7921void wxGrid::SetCellOverflow(
int row,
int col,
bool allow )
7923 if ( CanHaveAttributes() )
7925 wxGridCellAttr *attr = GetOrCreateCellAttr(row, col);
7926 attr->SetOverflow(allow);
7931void wxGrid::SetCellSize(
int row,
int col,
int num_rows,
int num_cols )
7933 if ( CanHaveAttributes() )
7935 int cell_rows, cell_cols;
7937 wxGridCellAttr *attr = GetOrCreateCellAttr(row, col);
7938 attr->GetSize(&cell_rows, &cell_cols);
7939 attr->SetSize(num_rows, num_cols);
7946 wxASSERT_MSG( !((cell_rows < 1) || (cell_cols < 1)),
7947 wxT(
"wxGrid::SetCellSize setting cell size that is already part of another cell"));
7948 wxASSERT_MSG( !((num_rows < 1) || (num_cols < 1)),
7949 wxT(
"wxGrid::SetCellSize setting cell size to < 1"));
7952 if ((cell_rows > 1) || (cell_cols > 1))
7955 for (j=row; j < row + cell_rows; j++)
7957 for (i=col; i < col + cell_cols; i++)
7959 if ((i != col) || (j != row))
7961 wxGridCellAttr *attr_stub = GetOrCreateCellAttr(j, i);
7962 attr_stub->SetSize( 1, 1 );
7963 attr_stub->DecRef();
7971 if (((num_rows > 1) || (num_cols > 1)) && (num_rows >= 1) && (num_cols >= 1))
7974 for (j=row; j < row + num_rows; j++)
7976 for (i=col; i < col + num_cols; i++)
7978 if ((i != col) || (j != row))
7980 wxGridCellAttr *attr_stub = GetOrCreateCellAttr(j, i);
7981 attr_stub->SetSize( row - j, col - i );
7982 attr_stub->DecRef();
7990void wxGrid::SetCellRenderer(
int row,
int col, wxGridCellRenderer *renderer)
7992 if ( CanHaveAttributes() )
7994 wxGridCellAttr *attr = GetOrCreateCellAttr(row, col);
7995 attr->SetRenderer(renderer);
8000void wxGrid::SetCellEditor(
int row,
int col, wxGridCellEditor* editor)
8002 if ( CanHaveAttributes() )
8004 wxGridCellAttr *attr = GetOrCreateCellAttr(row, col);
8005 attr->SetEditor(editor);
8010void wxGrid::SetReadOnly(
int row,
int col,
bool isReadOnly)
8012 if ( CanHaveAttributes() )
8014 wxGridCellAttr *attr = GetOrCreateCellAttr(row, col);
8015 attr->SetReadOnly(isReadOnly);
8024void wxGrid::RegisterDataType(
const wxString& typeName,
8025 wxGridCellRenderer* renderer,
8026 wxGridCellEditor* editor)
8028 m_typeRegistry->RegisterDataType(typeName, renderer, editor);
8032wxGridCellEditor * wxGrid::GetDefaultEditorForCell(
int row,
int col)
const
8034 wxString typeName = m_table->GetTypeName(row, col);
8035 return GetDefaultEditorForType(typeName);
8038wxGridCellRenderer * wxGrid::GetDefaultRendererForCell(
int row,
int col)
const
8040 wxString typeName = m_table->GetTypeName(row, col);
8041 return GetDefaultRendererForType(typeName);
8044wxGridCellEditor * wxGrid::GetDefaultEditorForType(
const wxString& typeName)
const
8046 int index = m_typeRegistry->FindOrCloneDataType(typeName);
8047 if ( index == wxNOT_FOUND )
8049 wxFAIL_MSG(wxString::Format(wxT(
"Unknown data type name [%s]"), typeName.c_str()));
8054 return m_typeRegistry->GetEditor(index);
8057wxGridCellRenderer * wxGrid::GetDefaultRendererForType(
const wxString& typeName)
const
8059 int index = m_typeRegistry->FindOrCloneDataType(typeName);
8060 if ( index == wxNOT_FOUND )
8062 wxFAIL_MSG(wxString::Format(wxT(
"Unknown data type name [%s]"), typeName.c_str()));
8067 return m_typeRegistry->GetRenderer(index);
8074void wxGrid::DoDisableLineResize(
int line, wxGridFixedIndicesSet *& setFixed)
8078 setFixed =
new wxGridFixedIndicesSet;
8081 setFixed->insert(line);
8085wxGrid::DoCanResizeLine(
int line,
const wxGridFixedIndicesSet *setFixed)
const
8087 return !setFixed || !setFixed->count(line);
8090void wxGrid::EnableDragRowSize(
bool enable )
8092 m_canDragRowSize = enable;
8095void wxGrid::EnableDragColSize(
bool enable )
8097 m_canDragColSize = enable;
8100void wxGrid::EnableDragGridSize(
bool enable )
8102 m_canDragGridSize = enable;
8105void wxGrid::EnableDragCell(
bool enable )
8107 m_canDragCell = enable;
8110void wxGrid::SetDefaultRowSize(
int height,
bool resizeExistingRows )
8112 m_defaultRowHeight = wxMax( height, m_minAcceptableRowHeight );
8114 if ( resizeExistingRows )
8120 m_rowHeights.Empty();
8121 m_rowBottoms.Empty();
8122 if ( !GetBatchCount() )
8135int UpdateRowOrColSize(
int& sizeCurrent,
int sizeNew)
8145 wxASSERT_MSG( sizeNew == -1, wxS(
"New size must be positive or -1.") );
8148 if ( sizeCurrent >= 0 )
8152 sizeCurrent = -sizeCurrent;
8157 else if ( sizeNew == 0 )
8162 if ( sizeCurrent <= 0 )
8167 sizeCurrent = -sizeCurrent;
8175 const int sizeOld = sizeCurrent < 0 ? 0 : sizeCurrent;
8177 sizeCurrent = sizeNew;
8179 return sizeCurrent - sizeOld;
8185void wxGrid::SetRowSize(
int row,
int height )
8188 if ( height > 0 && height < GetRowMinimalAcceptableHeight())
8193 if ( height == -1 && GetRowHeight(row) != 0 )
8196 wxArrayString lines;
8197 wxClientDC dc(m_rowLabelWin);
8198 dc.SetFont(GetLabelFont());
8199 StringToLines(GetRowLabelValue( row ), lines);
8200 GetTextBoxSize( dc, lines, &w, &h );
8203 height = wxMax(h, GetRowMinimalHeight(row));
8206 DoSetRowSize(row, height);
8209void wxGrid::DoSetRowSize(
int row,
int height )
8211 wxCHECK_RET( row >= 0 && row < m_numRows, wxT(
"invalid row index") );
8213 if ( m_rowHeights.IsEmpty() )
8219 const int diff = UpdateRowOrColSize(m_rowHeights[row], height);
8223 for (
int i = row; i < m_numRows; i++ )
8225 m_rowBottoms[i] += diff;
8228 InvalidateBestSize();
8230 if ( !GetBatchCount() )
8237void wxGrid::SetDefaultColSize(
int width,
bool resizeExistingCols )
8240 m_defaultColWidth = wxMax( wxMax( width, m_minAcceptableColWidth ), 1 );
8242 if ( resizeExistingCols )
8248 m_colWidths.Empty();
8249 m_colRights.Empty();
8250 if ( !GetBatchCount() )
8255void wxGrid::SetColSize(
int col,
int width )
8262 if ( width > 0 && width < GetColMinimalAcceptableWidth() )
8271 if ( width == -1 && GetColWidth(col) != 0 )
8274 wxArrayString lines;
8275 wxClientDC dc(m_colWindow);
8276 dc.SetFont(GetLabelFont());
8277 StringToLines(GetColLabelValue(col), lines);
8278 if ( GetColLabelTextOrientation() == wxHORIZONTAL )
8279 GetTextBoxSize( dc, lines, &w, &h );
8281 GetTextBoxSize( dc, lines, &h, &w );
8290 width = wxMax(width, GetColMinimalWidth(col));
8293 DoSetColSize(col, width);
8296void wxGrid::DoSetColSize(
int col,
int width )
8298 wxCHECK_RET( col >= 0 && col < m_numCols, wxT(
"invalid column index") );
8300 if ( m_colWidths.IsEmpty() )
8306 const int diff = UpdateRowOrColSize(m_colWidths[col], width);
8310 if ( m_useNativeHeader )
8311 GetGridColHeader()->UpdateColumn(col);
8314 for (
int colPos = GetColPos(col); colPos < m_numCols; colPos++ )
8316 m_colRights[GetColAt(colPos)] += diff;
8319 InvalidateBestSize();
8321 if ( !GetBatchCount() )
8328void wxGrid::SetColMinimalWidth(
int col,
int width )
8330 if (width > GetColMinimalAcceptableWidth())
8332 wxLongToLongHashMap::key_type key = (wxLongToLongHashMap::key_type)col;
8333 m_colMinWidths[key] = width;
8337void wxGrid::SetRowMinimalHeight(
int row,
int width )
8339 if (width > GetRowMinimalAcceptableHeight())
8341 wxLongToLongHashMap::key_type key = (wxLongToLongHashMap::key_type)row;
8342 m_rowMinHeights[key] = width;
8346int wxGrid::GetColMinimalWidth(
int col)
const
8348 wxLongToLongHashMap::key_type key = (wxLongToLongHashMap::key_type)col;
8349 wxLongToLongHashMap::const_iterator it = m_colMinWidths.find(key);
8351 return it != m_colMinWidths.end() ? (int)it->second : m_minAcceptableColWidth;
8354int wxGrid::GetRowMinimalHeight(
int row)
const
8356 wxLongToLongHashMap::key_type key = (wxLongToLongHashMap::key_type)row;
8357 wxLongToLongHashMap::const_iterator it = m_rowMinHeights.find(key);
8359 return it != m_rowMinHeights.end() ? (int)it->second : m_minAcceptableRowHeight;
8362void wxGrid::SetColMinimalAcceptableWidth(
int width )
8367 m_minAcceptableColWidth = width;
8370void wxGrid::SetRowMinimalAcceptableHeight(
int height )
8375 m_minAcceptableRowHeight = height;
8378int wxGrid::GetColMinimalAcceptableWidth()
const
8380 return m_minAcceptableColWidth;
8383int wxGrid::GetRowMinimalAcceptableHeight()
const
8385 return m_minAcceptableRowHeight;
8393wxGrid::AutoSizeColOrRow(
int colOrRow,
bool setAsMin, wxGridDirection direction)
8395 const bool column = direction == wxGRID_COLUMN;
8401 if ( GetColWidth(colOrRow) == 0 )
8406 if ( GetRowHeight(colOrRow) == 0 )
8410 wxClientDC dc(m_gridWin);
8413 HideCellEditControl();
8414 SaveEditControlValue();
8431 wxCoord
extent, extentMax = 0;
8432 int max = column ? m_numRows : m_numCols;
8433 for (
int rowOrCol = 0; rowOrCol <
max; rowOrCol++ )
8437 if ( !IsRowShown(rowOrCol) )
8445 if ( !IsColShown(rowOrCol) )
8455 int numRows, numCols;
8456 const CellSpan span = GetCellSize(row, col, &numRows, &numCols);
8457 if ( span == CellSpan_Inside )
8465 GetCellSize(row, col, &numRows, &numCols);
8469 wxGridCellAttr *attr = GetCellAttr(row, col);
8470 wxGridCellRenderer *renderer = attr->GetRenderer(
this, row, col);
8473 wxSize size = renderer->GetBestSize(*
this, *attr, dc, row, col);
8474 extent = column ? size.x : size.y;
8476 if ( span != CellSpan_None )
8485 extent /= column ? numCols : numRows;
8488 if (
extent > extentMax )
8499 dc.SetFont( GetLabelFont() );
8503 dc.GetMultiLineTextExtent( GetColLabelValue(colOrRow), &w, &h );
8504 if ( GetColLabelTextOrientation() == wxVERTICAL )
8508 dc.GetMultiLineTextExtent( GetRowLabelValue(colOrRow), &w, &h );
8511 if (
extent > extentMax )
8518 extentMax = column ? m_defaultColWidth : m_defaultRowHeight;
8535 extentMax = wxMax(extentMax, GetColMinimalWidth(colOrRow));
8537 SetColSize( colOrRow, extentMax );
8538 if ( !GetBatchCount() )
8540 if ( m_useNativeHeader )
8542 GetGridColHeader()->UpdateColumn(colOrRow);
8547 m_gridWin->GetClientSize( &cw, &ch );
8548 wxRect rect ( CellToRect( 0, colOrRow ) );
8550 CalcScrolledPosition(rect.x, 0, &rect.x, &dummy);
8551 rect.width = cw - rect.x;
8552 rect.height = m_colLabelHeight;
8553 GetColLabelWindow()->Refresh(
true, &rect );
8563 extentMax = wxMax(extentMax, GetRowMinimalHeight(colOrRow));
8565 SetRowSize(colOrRow, extentMax);
8566 if ( !GetBatchCount() )
8569 m_gridWin->GetClientSize( &cw, &ch );
8570 wxRect rect( CellToRect( colOrRow, 0 ) );
8572 CalcScrolledPosition(0, rect.y, &dummy, &rect.y);
8573 rect.width = m_rowLabelWidth;
8574 rect.height = ch - rect.y;
8575 m_rowLabelWin->Refresh(
true, &rect );
8582 SetColMinimalWidth(colOrRow, extentMax);
8584 SetRowMinimalHeight(colOrRow, extentMax);
8588wxCoord wxGrid::CalcColOrRowLabelAreaMinSize(wxGridDirection direction)
8591 const bool calcRows = direction == wxGRID_ROW;
8593 wxClientDC dc(calcRows ? GetGridRowLabelWindow()
8594 : GetGridColLabelWindow());
8595 dc.SetFont(GetLabelFont());
8602 useWidth = calcRows || (GetColLabelTextOrientation() == wxVERTICAL);
8604 wxArrayString lines;
8605 wxCoord extentMax = 0;
8607 const int numRowsOrCols = calcRows ? m_numRows : m_numCols;
8608 for (
int rowOrCol = 0; rowOrCol < numRowsOrCols; rowOrCol++ )
8612 wxString label = calcRows ? GetRowLabelValue(rowOrCol)
8613 : GetColLabelValue(rowOrCol);
8614 StringToLines(label, lines);
8617 GetTextBoxSize(dc, lines, &w, &h);
8619 const wxCoord
extent = useWidth ? w : h;
8620 if (
extent > extentMax )
8628 extentMax = calcRows ? GetDefaultRowLabelSize()
8629 : GetDefaultColLabelSize();
8641int wxGrid::SetOrCalcColumnSizes(
bool calcOnly,
bool setAsMin)
8643 int width = m_rowLabelWidth;
8645 wxGridUpdateLocker locker;
8647 locker.Create(
this);
8649 for (
int col = 0; col < m_numCols; col++ )
8652 AutoSizeColumn(col, setAsMin);
8654 width += GetColWidth(col);
8660int wxGrid::SetOrCalcRowSizes(
bool calcOnly,
bool setAsMin)
8662 int height = m_colLabelHeight;
8664 wxGridUpdateLocker locker;
8666 locker.Create(
this);
8668 for (
int row = 0; row < m_numRows; row++ )
8671 AutoSizeRow(row, setAsMin);
8673 height += GetRowHeight(row);
8679void wxGrid::AutoSize()
8681 wxGridUpdateLocker locker(
this);
8683 wxSize size(SetOrCalcColumnSizes(
false) - m_rowLabelWidth + m_extraWidth,
8684 SetOrCalcRowSizes(
false) - m_colLabelHeight + m_extraHeight);
8689 SetScrollbars(m_xScrollPixelsPerLine, m_yScrollPixelsPerLine,
8692 SetClientSize(size.x + m_rowLabelWidth, size.y + m_colLabelHeight);
8695void wxGrid::AutoSizeRowLabelSize(
int row )
8699 if ( IsCellEditControlShown() )
8701 HideCellEditControl();
8702 SaveEditControlValue();
8706 SetRowSize(row, -1);
8711void wxGrid::AutoSizeColLabelSize(
int col )
8715 if ( IsCellEditControlShown() )
8717 HideCellEditControl();
8718 SaveEditControlValue();
8722 SetColSize(col, -1);
8727wxSize wxGrid::DoGetBestSize()
const
8729 wxGrid *
const self =
const_cast<wxGrid *
>(
this);
8733 wxSize size(self->SetOrCalcColumnSizes(
true) - m_rowLabelWidth + m_extraWidth,
8734 self->SetOrCalcRowSizes(
true) - m_colLabelHeight + m_extraHeight);
8736 return wxSize(size.x + m_rowLabelWidth, size.y + m_colLabelHeight)
8737 + GetWindowBorderSize();
8745#if WXWIN_COMPATIBILITY_2_8
8746wxPen& wxGrid::GetDividerPen()
const
8756void wxGrid::SetCellValue(
int row,
int col,
const wxString& s )
8760 m_table->SetValue( row, col, s );
8761 if ( !GetBatchCount() )
8764 wxRect rect( CellToRect( row, col ) );
8766 rect.width = m_gridWin->GetClientSize().GetWidth();
8767 CalcScrolledPosition(0, rect.y, &dummy, &rect.y);
8768 m_gridWin->Refresh(
false, &rect );
8771 if ( m_currentCellCoords.GetRow() == row &&
8772 m_currentCellCoords.GetCol() == col &&
8773 IsCellEditControlShown())
8778 HideCellEditControl();
8779 ShowCellEditControl();
8788void wxGrid::SelectRow(
int row,
bool addToSelected )
8793 if ( !addToSelected )
8796 m_selection->SelectRow(row);
8799void wxGrid::SelectCol(
int col,
bool addToSelected )
8804 if ( !addToSelected )
8807 m_selection->SelectCol(col);
8810void wxGrid::SelectBlock(
int topRow,
int leftCol,
int bottomRow,
int rightCol,
8816 if ( !addToSelected )
8819 m_selection->SelectBlock(topRow, leftCol, bottomRow, rightCol);
8822void wxGrid::SelectAll()
8824 if ( m_numRows > 0 && m_numCols > 0 )
8827 m_selection->SelectBlock( 0, 0, m_numRows - 1, m_numCols - 1 );
8835void wxGrid::DeselectLine(
int line,
const wxGridOperations& oper)
8840 const wxGridSelectionModes mode = m_selection->GetSelectionMode();
8841 if ( mode == oper.GetSelectionMode() ||
8842 mode == wxGrid::wxGridSelectRowsOrColumns )
8844 const wxGridCellCoords c(oper.MakeCoords(line, 0));
8845 if ( m_selection->IsInSelection(c) )
8846 m_selection->ToggleCellSelection(c);
8848 else if ( mode != oper.Dual().GetSelectionMode() )
8850 const int nOther = oper.Dual().GetNumberOfLines(
this);
8851 for (
int i = 0; i < nOther; i++ )
8853 const wxGridCellCoords c(oper.MakeCoords(line, i));
8854 if ( m_selection->IsInSelection(c) )
8855 m_selection->ToggleCellSelection(c);
8862void wxGrid::DeselectRow(
int row)
8864 DeselectLine(row, wxGridRowOperations());
8867void wxGrid::DeselectCol(
int col)
8869 DeselectLine(col, wxGridColumnOperations());
8872void wxGrid::DeselectCell(
int row,
int col )
8874 if ( m_selection && m_selection->IsInSelection(row, col) )
8875 m_selection->ToggleCellSelection(row, col);
8878bool wxGrid::IsSelection()
const
8880 return ( m_selection && (m_selection->IsSelection() ||
8881 ( m_selectedBlockTopLeft != wxGridNoCellCoords &&
8882 m_selectedBlockBottomRight != wxGridNoCellCoords) ) );
8885bool wxGrid::IsInSelection(
int row,
int col )
const
8887 return ( m_selection && (m_selection->IsInSelection( row, col ) ||
8888 ( row >= m_selectedBlockTopLeft.GetRow() &&
8889 col >= m_selectedBlockTopLeft.GetCol() &&
8890 row <= m_selectedBlockBottomRight.GetRow() &&
8891 col <= m_selectedBlockBottomRight.GetCol() )) );
8894wxGridCellCoordsArray wxGrid::GetSelectedCells()
const
8898 wxGridCellCoordsArray a;
8902 return m_selection->m_cellSelection;
8905wxGridCellCoordsArray wxGrid::GetSelectionBlockTopLeft()
const
8909 wxGridCellCoordsArray a;
8913 return m_selection->m_blockSelectionTopLeft;
8916wxGridCellCoordsArray wxGrid::GetSelectionBlockBottomRight()
const
8920 wxGridCellCoordsArray a;
8924 return m_selection->m_blockSelectionBottomRight;
8927wxArrayInt wxGrid::GetSelectedRows()
const
8935 return m_selection->m_rowSelection;
8938wxArrayInt wxGrid::GetSelectedCols()
const
8946 return m_selection->m_colSelection;
8949void wxGrid::ClearSelection()
8951 wxRect r1 = BlockToDeviceRect(m_selectedBlockTopLeft,
8952 m_selectedBlockBottomRight);
8953 wxRect r2 = BlockToDeviceRect(m_currentCellCoords,
8954 m_selectedBlockCorner);
8956 m_selectedBlockTopLeft =
8957 m_selectedBlockBottomRight =
8958 m_selectedBlockCorner = wxGridNoCellCoords;
8960 if ( !r1.IsEmpty() )
8961 RefreshRect(r1,
false);
8962 if ( !r2.IsEmpty() )
8963 RefreshRect(r2,
false);
8966 m_selection->ClearSelection();
8972wxRect wxGrid::BlockToDeviceRect(
const wxGridCellCoords& topLeft,
8973 const wxGridCellCoords& bottomRight )
const
8976 wxRect tempCellRect = CellToRect(topLeft);
8977 if ( tempCellRect != wxGridNoCellRect )
8979 resultRect = tempCellRect;
8983 resultRect = wxRect(0, 0, 0, 0);
8986 tempCellRect = CellToRect(bottomRight);
8987 if ( tempCellRect != wxGridNoCellRect )
8989 resultRect += tempCellRect;
8994 return wxGridNoCellRect;
8998 int left = resultRect.GetLeft();
8999 int top = resultRect.GetTop();
9000 int right = resultRect.GetRight();
9001 int bottom = resultRect.GetBottom();
9003 int leftCol = topLeft.GetCol();
9004 int topRow = topLeft.GetRow();
9005 int rightCol = bottomRight.GetCol();
9006 int bottomRow = bottomRight.GetRow();
9032 m_gridWin->GetClientSize( &cw, &ch );
9036 int gridOriginX = 0;
9037 int gridOriginY = 0;
9038 CalcScrolledPosition(gridOriginX, gridOriginY, &gridOriginX, &gridOriginY);
9040 int onScreenLeftmostCol = internalXToCol(-gridOriginX);
9041 int onScreenUppermostRow = internalYToRow(-gridOriginY);
9043 int onScreenRightmostCol = internalXToCol(-gridOriginX + cw);
9044 int onScreenBottommostRow = internalYToRow(-gridOriginY + ch);
9050 const int visibleTopRow = wxMax(topRow, onScreenUppermostRow);
9051 const int visibleBottomRow = wxMin(bottomRow, onScreenBottommostRow);
9052 const int visibleLeftCol = wxMax(leftCol, onScreenLeftmostCol);
9053 const int visibleRightCol = wxMin(rightCol, onScreenRightmostCol);
9055 for (
int j = visibleTopRow; j <= visibleBottomRow; j++ )
9057 for (
int i = visibleLeftCol; i <= visibleRightCol; i++ )
9059 if ( (j == visibleTopRow) || (j == visibleBottomRow) ||
9060 (i == visibleLeftCol) || (i == visibleRightCol) )
9062 tempCellRect = CellToRect( j, i );
9064 if (tempCellRect.x < left)
9065 left = tempCellRect.x;
9066 if (tempCellRect.y < top)
9067 top = tempCellRect.y;
9068 if (tempCellRect.x + tempCellRect.width > right)
9069 right = tempCellRect.x + tempCellRect.width;
9070 if (tempCellRect.y + tempCellRect.height > bottom)
9071 bottom = tempCellRect.y + tempCellRect.height;
9075 i = visibleRightCol;
9081 CalcScrolledPosition( left, top, &left, &top );
9082 CalcScrolledPosition( right, bottom, &right, &bottom );
9084 if (right < 0 || bottom < 0 || left > cw || top > ch)
9085 return wxRect(0,0,0,0);
9087 resultRect.SetLeft( wxMax(0, left) );
9088 resultRect.SetTop( wxMax(0, top) );
9089 resultRect.SetRight( wxMin(cw, right) );
9090 resultRect.SetBottom( wxMin(ch, bottom) );
9095void wxGrid::DoSetSizes(
const wxGridSizesInfo& sizeInfo,
9096 const wxGridOperations& oper)
9099 oper.SetDefaultLineSize(
this, sizeInfo.m_sizeDefault,
true);
9100 const int numLines = oper.GetNumberOfLines(
this);
9101 for (
int i = 0; i < numLines; i++ )
9103 int size = sizeInfo.GetSize(i);
9104 if ( size != sizeInfo.m_sizeDefault)
9105 oper.SetLineSize(
this, i, size);
9110void wxGrid::SetColSizes(
const wxGridSizesInfo& sizeInfo)
9112 DoSetSizes(sizeInfo, wxGridColumnOperations());
9115void wxGrid::SetRowSizes(
const wxGridSizesInfo& sizeInfo)
9117 DoSetSizes(sizeInfo, wxGridRowOperations());
9120wxGridSizesInfo::wxGridSizesInfo(
int defSize,
const wxArrayInt& allSizes)
9122 m_sizeDefault = defSize;
9123 for (
size_t i = 0; i < allSizes.size(); i++ )
9125 if ( allSizes[i] != defSize )
9126 m_customSizes[i] = allSizes[i];
9130int wxGridSizesInfo::GetSize(
unsigned pos)
const
9132 wxUnsignedToIntHashMap::const_iterator it = m_customSizes.find(pos);
9135 if ( it == m_customSizes.end() )
9136 return m_sizeDefault;
9140 if ( it->second < 0 )
9150#if wxUSE_DRAG_AND_DROP
9153void wxGrid::SetDropTarget(wxDropTarget *dropTarget)
9155 GetGridWindow()->SetDropTarget(dropTarget);
9166wxGridEvent::wxGridEvent(
int id, wxEventType type, wxObject* obj,
9167 int row,
int col,
int x,
int y,
bool sel,
9168 bool control,
bool shift,
bool alt,
bool meta )
9169 : wxNotifyEvent( type, id ),
9170 wxKeyboardState(control, shift, alt, meta)
9172 Init(row, col, x, y, sel);
9174 SetEventObject(obj);
9179wxGridSizeEvent::wxGridSizeEvent(
int id, wxEventType type, wxObject* obj,
9180 int rowOrCol,
int x,
int y,
9181 bool control,
bool shift,
bool alt,
bool meta )
9182 : wxNotifyEvent( type, id ),
9183 wxKeyboardState(control, shift, alt, meta)
9185 Init(rowOrCol, x, y);
9187 SetEventObject(obj);
9193wxGridRangeSelectEvent::wxGridRangeSelectEvent(
int id, wxEventType type, wxObject* obj,
9194 const wxGridCellCoords& topLeft,
9195 const wxGridCellCoords& bottomRight,
9196 bool sel,
bool control,
9197 bool shift,
bool alt,
bool meta )
9198 : wxNotifyEvent( type, id ),
9199 wxKeyboardState(control, shift, alt, meta)
9201 Init(topLeft, bottomRight, sel);
9203 SetEventObject(obj);
9209wxGridEditorCreatedEvent::wxGridEditorCreatedEvent(
int id, wxEventType type,
9210 wxObject* obj,
int row,
9211 int col, wxControl* ctrl)
9212 : wxCommandEvent(type, id)
9214 SetEventObject(obj);
9225wxGridTypeRegistry::~wxGridTypeRegistry()
9227 size_t count = m_typeinfo.GetCount();
9228 for (
size_t i = 0; i < count; i++ )
9229 delete m_typeinfo[i];
9232void wxGridTypeRegistry::RegisterDataType(
const wxString& typeName,
9233 wxGridCellRenderer* renderer,
9234 wxGridCellEditor* editor)
9236 wxGridDataTypeInfo* info =
new wxGridDataTypeInfo(typeName, renderer, editor);
9239 int loc = FindRegisteredDataType(typeName);
9240 if ( loc != wxNOT_FOUND )
9242 delete m_typeinfo[loc];
9243 m_typeinfo[loc] = info;
9247 m_typeinfo.Add(info);
9251int wxGridTypeRegistry::FindRegisteredDataType(
const wxString& typeName)
9253 size_t count = m_typeinfo.GetCount();
9254 for (
size_t i = 0; i < count; i++ )
9256 if ( typeName == m_typeinfo[i]->m_typeName )
9265int wxGridTypeRegistry::FindDataType(
const wxString& typeName)
9267 int index = FindRegisteredDataType(typeName);
9268 if ( index == wxNOT_FOUND )
9273 if ( typeName == wxGRID_VALUE_STRING )
9275 RegisterDataType(wxGRID_VALUE_STRING,
9276 new wxGridCellStringRenderer,
9277 new wxGridCellTextEditor);
9282 if ( typeName == wxGRID_VALUE_BOOL )
9284 RegisterDataType(wxGRID_VALUE_BOOL,
9285 new wxGridCellBoolRenderer,
9286 new wxGridCellBoolEditor);
9291 if ( typeName == wxGRID_VALUE_NUMBER )
9293 RegisterDataType(wxGRID_VALUE_NUMBER,
9294 new wxGridCellNumberRenderer,
9295 new wxGridCellNumberEditor);
9297 else if ( typeName == wxGRID_VALUE_FLOAT )
9299 RegisterDataType(wxGRID_VALUE_FLOAT,
9300 new wxGridCellFloatRenderer,
9301 new wxGridCellFloatEditor);
9306 if ( typeName == wxGRID_VALUE_CHOICE )
9308 RegisterDataType(wxGRID_VALUE_CHOICE,
9309 new wxGridCellStringRenderer,
9310 new wxGridCellChoiceEditor);
9320 index = m_typeinfo.GetCount() - 1;
9326int wxGridTypeRegistry::FindOrCloneDataType(
const wxString& typeName)
9328 int index = FindDataType(typeName);
9329 if ( index == wxNOT_FOUND )
9333 index = FindDataType(typeName.BeforeFirst(wxT(
':')));
9334 if ( index == wxNOT_FOUND )
9339 wxGridCellRenderer *renderer = GetRenderer(index);
9340 wxGridCellRenderer *rendererOld = renderer;
9341 renderer = renderer->Clone();
9342 rendererOld->DecRef();
9344 wxGridCellEditor *editor = GetEditor(index);
9345 wxGridCellEditor *editorOld = editor;
9346 editor = editor->Clone();
9347 editorOld->DecRef();
9350 wxString params = typeName.AfterFirst(wxT(
':'));
9351 renderer->SetParameters(params);
9352 editor->SetParameters(params);
9355 RegisterDataType(typeName, renderer, editor);
9358 index = m_typeinfo.GetCount() - 1;
9364wxGridCellRenderer* wxGridTypeRegistry::GetRenderer(
int index)
9366 wxGridCellRenderer* renderer = m_typeinfo[index]->m_renderer;
9373wxGridCellEditor* wxGridTypeRegistry::GetEditor(
int index)
9375 wxGridCellEditor* editor = m_typeinfo[index]->m_editor;
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
EVT_ERASE_BACKGROUND(wxTreeListHeaderWindow::OnEraseBackground) void wxTreeListHeaderWindow
WX_DEFINE_OBJARRAY(wxArrayTreeListColumnInfo)
IMPLEMENT_DYNAMIC_CLASS(wxTreeListHeaderWindow, wxWindow)