#include "wx/tokenzr.h"
#include "wx/renderer.h"
#include "wx/headerctrl.h"
+#include "wx/hashset.h"
#include "wx/generic/gridsel.h"
#include "wx/generic/gridctrl.h"
// Required for wxIs... functions
#include <ctype.h>
+WX_DECLARE_HASH_SET_WITH_DECL(int, wxIntegerHash, wxIntegerEqual,
+ wxGridFixedIndicesSet, class WXDLLIMPEXP_ADV);
+
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------
+namespace
+{
+
//#define DEBUG_ATTR_CACHE
#ifdef DEBUG_ATTR_CACHE
static size_t gs_nAttrCacheHits = 0;
static size_t gs_nAttrCacheMisses = 0;
#endif
+// this struct simply combines together the default header renderers
+//
+// as the renderers ctors are trivial, there is no problem with making them
+// globals
+struct DefaultHeaderRenderers
+{
+ wxGridColumnHeaderRendererDefault colRenderer;
+ wxGridRowHeaderRendererDefault rowRenderer;
+ wxGridCornerHeaderRendererDefault cornerRenderer;
+} gs_defaultHeaderRenderers;
+
+} // anonymous namespace
+
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxGridHeaderCtrl, wxHeaderCtrl)
EVT_HEADER_CLICK(wxID_ANY, wxGridHeaderCtrl::OnClick)
+ EVT_HEADER_DCLICK(wxID_ANY, wxGridHeaderCtrl::OnDoubleClick)
+ EVT_HEADER_RIGHT_CLICK(wxID_ANY, wxGridHeaderCtrl::OnRightClick)
EVT_HEADER_BEGIN_RESIZE(wxID_ANY, wxGridHeaderCtrl::OnBeginResize)
EVT_HEADER_RESIZING(wxID_ANY, wxGridHeaderCtrl::OnResizing)
{
}
+// ----------------------------------------------------------------------------
+// wxGridHeaderLabelsRenderer and related classes
+// ----------------------------------------------------------------------------
+
+void wxGridHeaderLabelsRenderer::DrawLabel(const wxGrid& grid,
+ wxDC& dc,
+ const wxString& value,
+ const wxRect& rect,
+ int horizAlign,
+ int vertAlign,
+ int textOrientation) const
+{
+ dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
+ dc.SetTextForeground(grid.GetLabelTextColour());
+ dc.SetFont(grid.GetLabelFont());
+ grid.DrawTextRectangle(dc, value, rect, horizAlign, vertAlign, textOrientation);
+}
+
+
+void wxGridRowHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid),
+ wxDC& dc,
+ wxRect& rect) const
+{
+ dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
+ dc.DrawLine(rect.GetRight(), rect.GetTop(),
+ rect.GetRight(), rect.GetBottom());
+ dc.DrawLine(rect.GetLeft(), rect.GetTop(),
+ rect.GetLeft(), rect.GetBottom());
+ dc.DrawLine(rect.GetLeft(), rect.GetBottom(),
+ rect.GetRight() + 1, rect.GetBottom());
+
+ dc.SetPen(*wxWHITE_PEN);
+ dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(),
+ rect.GetLeft() + 1, rect.GetBottom());
+ dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(),
+ rect.GetRight(), rect.GetTop());
+
+ rect.Deflate(2);
+}
+
+void wxGridColumnHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid),
+ wxDC& dc,
+ wxRect& rect) const
+{
+ dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
+ dc.DrawLine(rect.GetRight(), rect.GetTop(),
+ rect.GetRight(), rect.GetBottom());
+ dc.DrawLine(rect.GetLeft(), rect.GetTop(),
+ rect.GetRight(), rect.GetTop());
+ dc.DrawLine(rect.GetLeft(), rect.GetBottom(),
+ rect.GetRight() + 1, rect.GetBottom());
+
+ dc.SetPen(*wxWHITE_PEN);
+ dc.DrawLine(rect.GetLeft(), rect.GetTop() + 1,
+ rect.GetLeft(), rect.GetBottom());
+ dc.DrawLine(rect.GetLeft(), rect.GetTop() + 1,
+ rect.GetRight(), rect.GetTop() + 1);
+
+ rect.Deflate(2);
+}
+
+void wxGridCornerHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid),
+ wxDC& dc,
+ wxRect& rect) const
+{
+ dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
+ dc.DrawLine(rect.GetRight() - 1, rect.GetBottom() - 1,
+ rect.GetRight() - 1, rect.GetTop());
+ dc.DrawLine(rect.GetRight() - 1, rect.GetBottom() - 1,
+ rect.GetLeft(), rect.GetBottom() - 1);
+ dc.DrawLine(rect.GetLeft(), rect.GetTop(),
+ rect.GetRight(), rect.GetTop());
+ dc.DrawLine(rect.GetLeft(), rect.GetTop(),
+ rect.GetLeft(), rect.GetBottom());
+
+ dc.SetPen(*wxWHITE_PEN);
+ dc.DrawLine(rect.GetLeft() + 1, rect.GetTop() + 1,
+ rect.GetRight() - 1, rect.GetTop() + 1);
+ dc.DrawLine(rect.GetLeft() + 1, rect.GetTop() + 1,
+ rect.GetLeft() + 1, rect.GetBottom() - 1);
+
+ rect.Deflate(2);
+}
+
// ----------------------------------------------------------------------------
// wxGridCellAttr
// ----------------------------------------------------------------------------
void wxGridCellAttr::Init(wxGridCellAttr *attrDefault)
{
- m_nRef = 1;
-
m_isReadOnly = Unset;
m_renderer = NULL;
}
}
+void wxGridCellAttr::GetNonDefaultAlignment(int *hAlign, int *vAlign) const
+{
+ if ( hAlign && m_hAlign != wxALIGN_INVALID )
+ *hAlign = m_hAlign;
+
+ if ( vAlign && m_vAlign != wxALIGN_INVALID )
+ *vAlign = m_vAlign;
+}
+
void wxGridCellAttr::GetSize( int *num_rows, int *num_cols ) const
{
if ( num_rows )
{
if ( attr )
{
- // add the attribute - no need to do anything to reference count
- // since we take ownership of the attribute.
+ // store the new attribute, taking its ownership
m_rowsOrCols.Add(rowOrCol);
m_attrs.Add(attr);
}
// nothing to remove
}
- else
+ else // we have an attribute for this row or column
{
size_t n = (size_t)i;
- if ( m_attrs[n] == attr )
- // nothing to do
- return;
+
+ // notice that this code works correctly even when the old attribute is
+ // the same as the new one: as we own of it, we must call DecRef() on
+ // it in any case and this won't result in destruction of the new
+ // attribute if it's the same as old one because it must have ref count
+ // of at least 2 to be passed to us while we keep a reference to it too
+ m_attrs[n]->DecRef();
+
if ( attr )
{
- // change the attribute, handling reference count manually,
- // taking ownership of the new attribute.
- m_attrs[n]->DecRef();
+ // replace the attribute with the new one
m_attrs[n] = attr;
}
- else
+ else // remove the attribute
{
- // remove this attribute, handling reference count manually
- m_attrs[n]->DecRef();
m_rowsOrCols.RemoveAt(n);
m_attrs.RemoveAt(n);
}
}
}
+const wxGridColumnHeaderRenderer&
+wxGridCellAttrProvider::GetColumnHeaderRenderer(int WXUNUSED(col))
+{
+ return gs_defaultHeaderRenderers.colRenderer;
+}
+
+const wxGridRowHeaderRenderer&
+wxGridCellAttrProvider::GetRowHeaderRenderer(int WXUNUSED(row))
+{
+ return gs_defaultHeaderRenderers.rowRenderer;
+}
+
+const wxGridCornerHeaderRenderer& wxGridCellAttrProvider::GetCornerRenderer()
+{
+ return gs_defaultHeaderRenderers.cornerRenderer;
+}
+
// ----------------------------------------------------------------------------
// wxGridTableBase
// ----------------------------------------------------------------------------
unsigned int i, n;
for ( n = 1; ; n++ )
{
- s += (wxChar) (_T('A') + (wxChar)(col % 26));
+ s += (wxChar) (wxT('A') + (wxChar)(col % 26));
col = col / 26 - 1;
if ( col < 0 )
break;
wxGridStringTable::wxGridStringTable()
: wxGridTableBase()
{
+ m_numCols = 0;
}
wxGridStringTable::wxGridStringTable( int numRows, int numCols )
: wxGridTableBase()
{
+ m_numCols = numCols;
+
m_data.Alloc( numRows );
wxArrayString sa;
m_data.Add( sa, numRows );
}
-wxGridStringTable::~wxGridStringTable()
-{
-}
-
-int wxGridStringTable::GetNumberRows()
-{
- return m_data.GetCount();
-}
-
-int wxGridStringTable::GetNumberCols()
-{
- if ( m_data.GetCount() > 0 )
- return m_data[0].GetCount();
- else
- return 0;
-}
-
wxString wxGridStringTable::GetValue( int row, int col )
{
- wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()),
+ wxCHECK_MSG( (row >= 0 && row < GetNumberRows()) &&
+ (col >= 0 && col < GetNumberCols()),
wxEmptyString,
- _T("invalid row or column index in wxGridStringTable") );
+ wxT("invalid row or column index in wxGridStringTable") );
return m_data[row][col];
}
void wxGridStringTable::SetValue( int row, int col, const wxString& value )
{
- wxCHECK_RET( (row < GetNumberRows()) && (col < GetNumberCols()),
- _T("invalid row or column index in wxGridStringTable") );
+ wxCHECK_RET( (row >= 0 && row < GetNumberRows()) &&
+ (col >= 0 && col < GetNumberCols()),
+ wxT("invalid row or column index in wxGridStringTable") );
m_data[row][col] = value;
}
}
}
+ m_numCols += numCols;
+
if ( GetView() )
{
wxGridTableMessage msg( this,
m_data[row].Add( wxEmptyString, numCols );
}
+ m_numCols += numCols;
+
if ( GetView() )
{
wxGridTableMessage msg( this,
m_colLabels.RemoveAt( colID, nToRm );
}
- for ( row = 0; row < curNumRows; row++ )
+ if ( numCols >= curNumCols )
{
- if ( numCols >= curNumCols )
+ for ( row = 0; row < curNumRows; row++ )
{
m_data[row].Clear();
}
- else
+
+ m_numCols = 0;
+ }
+ else // something will be left
+ {
+ for ( row = 0; row < curNumRows; row++ )
{
m_data[row].RemoveAt( colID, numCols );
}
+
+ m_numCols -= numCols;
}
if ( GetView() )
Create();
SetInitialSize(size);
- SetScrollRate(m_scrollLineX, m_scrollLineY);
CalcDimensions();
return true;
#ifdef DEBUG_ATTR_CACHE
size_t total = gs_nAttrCacheHits + gs_nAttrCacheMisses;
- wxPrintf(_T("wxGrid attribute cache statistics: "
+ wxPrintf(wxT("wxGrid attribute cache statistics: "
"total: %u, hits: %u (%u%%)\n"),
total, gs_nAttrCacheHits,
total ? (gs_nAttrCacheHits*100) / total : 0);
delete m_typeRegistry;
delete m_selection;
+
+ delete m_setFixedRows;
+ delete m_setFixedCols;
}
//
m_table = NULL;
}
- delete m_selection;
- m_selection = NULL;
+ wxDELETE(m_selection);
m_ownTable = false;
m_numRows = 0;
m_rowLabelWidth = WXGRID_DEFAULT_ROW_LABEL_WIDTH;
m_colLabelHeight = WXGRID_DEFAULT_COL_LABEL_HEIGHT;
+ m_setFixedRows =
+ m_setFixedCols = NULL;
+
// init attr cache
m_attrCache.row = -1;
m_attrCache.col = -1;
m_extraWidth =
m_extraHeight = 0;
- m_scrollLineX = GRID_SCROLL_LINE_X;
- m_scrollLineY = GRID_SCROLL_LINE_Y;
+ // we can't call SetScrollRate() as the window isn't created yet but OTOH
+ // we don't need to call it neither as the scroll position is (0, 0) right
+ // now anyhow, so just set the parameters directly
+ m_xScrollPixelsPerLine = GRID_SCROLL_LINE_X;
+ m_yScrollPixelsPerLine = GRID_SCROLL_LINE_Y;
}
// ----------------------------------------------------------------------------
//
else if ( event.LeftDown() )
{
- // don't send a label click event for a hit on the
- // edge of the row label - this is probably the user
- // wanting to resize the row
- //
- if ( YToEdgeOfRow(y) < 0 )
+ row = YToEdgeOfRow(y);
+ if ( row != wxNOT_FOUND && CanDragRowSize(row) )
+ {
+ ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, m_rowLabelWin);
+ }
+ else // not a request to start resizing
{
row = YToRow(y);
if ( row >= 0 &&
ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW, m_rowLabelWin);
}
}
- else
- {
- // starting to drag-resize a row
- if ( CanDragRowSize() )
- ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, m_rowLabelWin);
- }
}
// ------------ Left double click
else if (event.LeftDClick() )
{
row = YToEdgeOfRow(y);
- if ( row < 0 )
+ if ( row != wxNOT_FOUND && CanDragRowSize(row) )
+ {
+ // adjust row height depending on label text
+ //
+ // TODO: generate RESIZING event, see #10754
+ AutoSizeRowLabelSize( row );
+
+ SendGridSizeEvent(wxEVT_GRID_ROW_SIZE, row, -1, event);
+
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow());
+ m_dragLastPos = -1;
+ }
+ else // not on row separator or it's not resizeable
{
row = YToRow(y);
if ( row >=0 &&
// no default action at the moment
}
}
- else
- {
- // adjust row height depending on label text
- AutoSizeRowLabelSize( row );
-
- ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow());
- m_dragLastPos = -1;
- }
}
// ------------ Left button released
else if ( event.LeftUp() )
{
if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
- {
- DoEndDragResizeRow();
-
- // Note: we are ending the event *after* doing
- // default processing in this case
- //
- SendEvent( wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
- }
+ DoEndDragResizeRow(event);
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin);
m_dragLastPos = -1;
else if ( event.Moving() )
{
m_dragRowOrCol = YToEdgeOfRow( y );
- if ( m_dragRowOrCol >= 0 )
+ if ( m_dragRowOrCol != wxNOT_FOUND )
{
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
- // don't capture the mouse yet
- if ( CanDragRowSize() )
+ if ( CanDragRowSize(m_dragRowOrCol) )
ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, m_rowLabelWin, false);
}
}
//
else if ( event.LeftDown() )
{
- // don't send a label click event for a hit on the
- // edge of the col label - this is probably the user
- // wanting to resize the col
- //
- if ( XToEdgeOfCol(x) < 0 )
+ int col = XToEdgeOfCol(x);
+ if ( col != wxNOT_FOUND && CanDragColSize(col) )
+ {
+ ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, GetColLabelWindow());
+ }
+ else // not a request to start resizing
{
+ col = XToCol(x);
if ( col >= 0 &&
!SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) )
{
}
}
}
- else
- {
- // starting to drag-resize a col
- //
- if ( CanDragColSize() )
- ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, GetColLabelWindow());
- }
}
// ------------ Left double click
else
{
// adjust column width depending on label text
+ //
+ // TODO: generate RESIZING event, see #10754
AutoSizeColLabelSize( colEdge );
+ SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, colEdge, event);
+
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, GetColLabelWindow());
m_dragLastPos = -1;
}
switch ( m_cursorMode )
{
case WXGRID_CURSOR_RESIZE_COL:
- DoEndDragResizeCol();
+ DoEndDragResizeCol(event);
break;
case WXGRID_CURSOR_MOVE_COL:
}
else
{
- DoEndMoveCol(XToPos(x));
+ // get the position of the column we're over
+ int pos = XToPos(x);
+
+ // we may need to adjust the drop position but don't bother
+ // checking for it if we can't anyhow
+ if ( pos > 1 )
+ {
+ // also find the index of the column we're over: notice
+ // that the existing "col" variable may be invalid but
+ // we need a valid one here
+ const int colValid = GetColAt(pos);
+
+ // if we're on the "near" (usually left but right in
+ // RTL case) part of the column, the actual position we
+ // should be placed in is actually the one before it
+ bool onNearPart;
+ const int middle = GetColLeft(colValid) +
+ GetColWidth(colValid)/2;
+ if ( GetLayoutDirection() == wxLayout_LeftToRight )
+ onNearPart = (x <= middle);
+ else // wxLayout_RightToLeft
+ onNearPart = (x > middle);
+
+ if ( onNearPart )
+ pos--;
+ }
+
+ DoEndMoveCol(pos);
}
break;
{
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
- // don't capture the cursor yet
- if ( CanDragColSize() )
+ if ( CanDragColSize(m_dragRowOrCol) )
ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, GetColLabelWindow(), false);
}
}
wxWindow *win,
bool captureMouse)
{
-#ifdef __WXDEBUG__
- static const wxChar *cursorModes[] =
+#if wxUSE_LOG_TRACE
+ static const wxChar *const cursorModes[] =
{
- _T("SELECT_CELL"),
- _T("RESIZE_ROW"),
- _T("RESIZE_COL"),
- _T("SELECT_ROW"),
- _T("SELECT_COL"),
- _T("MOVE_COL"),
+ wxT("SELECT_CELL"),
+ wxT("RESIZE_ROW"),
+ wxT("RESIZE_COL"),
+ wxT("SELECT_ROW"),
+ wxT("SELECT_COL"),
+ wxT("MOVE_COL"),
};
- wxLogTrace(_T("grid"),
- _T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
- win == m_colWindow ? _T("colLabelWin")
- : win ? _T("rowLabelWin")
- : _T("gridWin"),
+ wxLogTrace(wxT("grid"),
+ wxT("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
+ win == m_colWindow ? wxT("colLabelWin")
+ : win ? wxT("rowLabelWin")
+ : wxT("gridWin"),
cursorModes[m_cursorMode], cursorModes[mode]);
-#endif
+#endif // wxUSE_LOG_TRACE
if ( mode == m_cursorMode &&
win == m_winCapture &&
if ( isFirstDrag )
{
+ wxASSERT_MSG( !m_winCapture, "shouldn't capture the mouse twice" );
+
m_winCapture = m_gridWin;
m_winCapture->CaptureMouse();
}
}
else
{
+ if ( m_selection )
+ {
+ // In row or column selection mode just clicking on the cell
+ // should select the row or column containing it: this is more
+ // convenient for the kinds of controls that use such selection
+ // mode and is compatible with 2.8 behaviour (see #12062).
+ switch ( m_selection->GetSelectionMode() )
+ {
+ case wxGridSelectCells:
+ case wxGridSelectRowsOrColumns:
+ // nothing to do in these cases
+ break;
+
+ case wxGridSelectRows:
+ m_selection->SelectRow(coords.GetRow());
+ break;
+
+ case wxGridSelectColumns:
+ m_selection->SelectCol(coords.GetCol());
+ break;
+ }
+ }
+
m_waitForSlowClick = m_currentCellCoords == coords &&
coords != wxGridNoCellCoords;
SetCurrentCell( coords );
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
{
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
- DoEndDragResizeRow();
-
- // Note: we are ending the event *after* doing
- // default processing in this case
- //
- SendEvent( wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
+ DoEndDragResizeRow(event);
}
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
{
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
- DoEndDragResizeCol();
+ DoEndDragResizeCol(event);
}
m_dragLastPos = -1;
return;
}
- if ( dragRow >= 0 )
+ if ( dragRow >= 0 && CanDragGridSize() && CanDragRowSize(dragRow) )
{
- m_dragRowOrCol = dragRow;
-
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
- if ( CanDragRowSize() && CanDragGridSize() )
- ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, NULL, false);
+ m_dragRowOrCol = dragRow;
+ ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, NULL, false);
}
}
// When using the native header window we can only resize the columns by
// dragging the dividers in it because we can't make it enter into the
// column resizing mode programmatically
- else if ( dragCol >= 0 && !m_useNativeHeader )
+ else if ( dragCol >= 0 && !m_useNativeHeader &&
+ CanDragGridSize() && CanDragColSize(dragCol) )
{
- m_dragRowOrCol = dragCol;
-
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
- if ( CanDragColSize() && CanDragGridSize() )
- ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, NULL, false);
+ m_dragRowOrCol = dragCol;
+ ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, NULL, false);
}
}
else // Neither on a row or col edge
void wxGrid::ProcessGridCellMouseEvent(wxMouseEvent& event)
{
+ if ( event.Entering() || event.Leaving() )
+ {
+ // we don't care about these events but we must not reset m_isDragging
+ // if they happen so return before anything else is done
+ event.Skip();
+ return;
+ }
+
const wxPoint pos = CalcUnscrolledPosition(event.GetPosition());
// coordinates of the cell under mouse
m_isDragging = false;
m_startDragPos = wxDefaultPosition;
- // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
- // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
- // wxGTK
-#if 0
- if ( event.Entering() || event.Leaving() )
- {
- ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
- m_gridWin->SetCursor( *wxSTANDARD_CURSOR );
- }
-#endif // 0
-
// deal with various button presses
if ( event.IsButton() )
{
}
}
-void wxGrid::DoEndDragResizeLine(const wxGridOperations& oper)
+// this function returns true only if the size really changed
+bool wxGrid::DoEndDragResizeLine(const wxGridOperations& oper)
{
if ( m_dragLastPos == -1 )
- return;
+ return false;
const wxGridOperations& doper = oper.Dual();
// do resize the line
const int lineStart = oper.GetLineStartPos(this, m_dragRowOrCol);
+ const int lineSizeOld = oper.GetLineSize(this, m_dragRowOrCol);
oper.SetLineSize(this, m_dragRowOrCol,
wxMax(m_dragLastPos - lineStart,
oper.GetMinimalLineSize(this, m_dragRowOrCol)));
+ const bool
+ sizeChanged = oper.GetLineSize(this, m_dragRowOrCol) != lineSizeOld;
m_dragLastPos = -1;
oper.SelectSize(rect) = oper.Select(size);
int subtractLines = 0;
- const int lineStart = oper.PosToLine(this, posLineStart);
+ const int lineStart = doper.PosToLine(this, posLineStart);
if ( lineStart >= 0 )
{
// ensure that if we have a multi-cell block we redraw all of
// it by increasing the refresh area to cover it entirely if a
// part of it is affected
- const int lineEnd = oper.PosToLine(this, posLineEnd, true);
+ const int lineEnd = doper.PosToLine(this, posLineEnd, true);
for ( int line = lineStart; line < lineEnd; line++ )
{
int cellLines = oper.Select(
// show the edit control back again
ShowCellEditControl();
+
+ return sizeChanged;
}
-void wxGrid::DoEndDragResizeRow()
+void wxGrid::DoEndDragResizeRow(const wxMouseEvent& event)
{
- DoEndDragResizeLine(wxGridRowOperations());
+ // TODO: generate RESIZING event, see #10754
+
+ if ( DoEndDragResizeLine(wxGridRowOperations()) )
+ SendGridSizeEvent(wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event);
}
-void wxGrid::DoEndDragResizeCol(wxMouseEvent *event)
+void wxGrid::DoEndDragResizeCol(const wxMouseEvent& event)
{
- DoEndDragResizeLine(wxGridColumnOperations());
+ // TODO: generate RESIZING event, see #10754
- // Note: we are ending the event *after* doing
- // default processing in this case
- //
- if ( event )
- SendEvent( wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, *event );
- else
- SendEvent( wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol );
+ if ( DoEndDragResizeLine(wxGridColumnOperations()) )
+ SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event);
}
void wxGrid::DoStartMoveCol(int col)
return (m_table->*funcAppend)(num);
}
-//
-// ----- event handlers
-//
+// ----------------------------------------------------------------------------
+// event generation helpers
+// ----------------------------------------------------------------------------
+
+void
+wxGrid::SendGridSizeEvent(wxEventType type,
+ int row, int col,
+ const wxMouseEvent& mouseEv)
+{
+ int rowOrCol = row == -1 ? col : row;
+
+ wxGridSizeEvent gridEvt( GetId(),
+ type,
+ this,
+ rowOrCol,
+ mouseEv.GetX() + GetRowLabelSize(),
+ mouseEv.GetY() + GetColLabelSize(),
+ mouseEv);
+
+ GetEventHandler()->ProcessEvent(gridEvt);
+}
// Generate a grid event based on a mouse event and return:
// -1 if the event was vetoed
int
wxGrid::SendEvent(const wxEventType type,
int row, int col,
- wxMouseEvent& mouseEv)
+ const wxMouseEvent& mouseEv)
{
bool claimed, vetoed;
- if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
- {
- int rowOrCol = (row == -1 ? col : row);
-
- wxGridSizeEvent gridEvt( GetId(),
- type,
- this,
- rowOrCol,
- mouseEv.GetX() + GetRowLabelSize(),
- mouseEv.GetY() + GetColLabelSize(),
- mouseEv);
-
- claimed = GetEventHandler()->ProcessEvent(gridEvt);
- vetoed = !gridEvt.IsAllowed();
- }
- else if ( type == wxEVT_GRID_RANGE_SELECT )
+ if ( type == wxEVT_GRID_RANGE_SELECT )
{
// Right now, it should _never_ end up here!
wxGridRangeSelectEvent gridEvt( GetId(),
int
wxGrid::SendEvent(const wxEventType type, int row, int col, const wxString& s)
{
- bool claimed, vetoed;
-
- if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
- {
- int rowOrCol = (row == -1 ? col : row);
-
- wxGridSizeEvent gridEvt( GetId(), type, this, rowOrCol );
-
- claimed = GetEventHandler()->ProcessEvent(gridEvt);
- vetoed = !gridEvt.IsAllowed();
- }
- else
- {
- wxGridEvent gridEvt( GetId(), type, this, row, col );
- gridEvt.SetString(s);
+ wxGridEvent gridEvt( GetId(), type, this, row, col );
+ gridEvt.SetString(s);
- claimed = GetEventHandler()->ProcessEvent(gridEvt);
- vetoed = !gridEvt.IsAllowed();
- }
+ const bool claimed = GetEventHandler()->ProcessEvent(gridEvt);
// A Veto'd event may not be `claimed' so test this first
- if (vetoed)
+ if ( !gridEvt.IsAllowed() )
return -1;
return claimed ? 1 : 0;
break;
case WXK_HOME:
- if ( event.ControlDown() )
- {
- GoToCell(0, 0);
- }
- else
- {
- event.Skip();
- }
+ GoToCell(event.ControlDown() ? 0
+ : m_currentCellCoords.GetRow(),
+ 0);
break;
case WXK_END:
- if ( event.ControlDown() )
- {
- GoToCell(m_numRows - 1, m_numCols - 1);
- }
- else
- {
- event.Skip();
- }
+ GoToCell(event.ControlDown() ? m_numRows - 1
+ : m_currentCellCoords.GetRow(),
+ m_numCols - 1);
break;
case WXK_PAGEUP:
wxGrid::UpdateBlockBeingSelected(int topRow, int leftCol,
int bottomRow, int rightCol)
{
+ MakeCellVisible(m_selectedBlockCorner);
+ m_selectedBlockCorner = wxGridCellCoords(bottomRow, rightCol);
+
if ( m_selection )
{
switch ( m_selection->GetSelectionMode() )
}
}
- m_selectedBlockCorner = wxGridCellCoords(bottomRow, rightCol);
- MakeCellVisible(m_selectedBlockCorner);
-
EnsureFirstLessThanSecond(topRow, bottomRow);
EnsureFirstLessThanSecond(leftCol, rightCol);
if ( GetRowHeight(row) <= 0 || m_rowLabelWidth <= 0 )
return;
- wxRect rect;
-
- int rowTop = GetRowTop(row),
- rowBottom = GetRowBottom(row) - 1;
-
- dc.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
- dc.DrawLine( m_rowLabelWidth - 1, rowTop, m_rowLabelWidth - 1, rowBottom );
- dc.DrawLine( 0, rowTop, 0, rowBottom );
- dc.DrawLine( 0, rowBottom, m_rowLabelWidth, rowBottom );
+ wxGridCellAttrProvider * const
+ attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
- dc.SetPen( *wxWHITE_PEN );
- dc.DrawLine( 1, rowTop, 1, rowBottom );
- dc.DrawLine( 1, rowTop, m_rowLabelWidth - 1, rowTop );
+ // notice that an explicit static_cast is needed to avoid a compilation
+ // error with VC7.1 which, for some reason, tries to instantiate (abstract)
+ // wxGridRowHeaderRenderer class without it
+ const wxGridRowHeaderRenderer&
+ rend = attrProvider ? attrProvider->GetRowHeaderRenderer(row)
+ : static_cast<const wxGridRowHeaderRenderer&>
+ (gs_defaultHeaderRenderers.rowRenderer);
- dc.SetBackgroundMode( wxBRUSHSTYLE_TRANSPARENT );
- dc.SetTextForeground( GetLabelTextColour() );
- dc.SetFont( GetLabelFont() );
+ wxRect rect(0, GetRowTop(row), m_rowLabelWidth, GetRowHeight(row));
+ rend.DrawBorder(*this, dc, rect);
int hAlign, vAlign;
- GetRowLabelAlignment( &hAlign, &vAlign );
+ GetRowLabelAlignment(&hAlign, &vAlign);
- rect.SetX( 2 );
- rect.SetY( GetRowTop(row) + 2 );
- rect.SetWidth( m_rowLabelWidth - 4 );
- rect.SetHeight( GetRowHeight(row) - 4 );
- DrawTextRectangle( dc, GetRowLabelValue( row ), rect, hAlign, vAlign );
+ rend.DrawLabel(*this, dc, GetRowLabelValue(row),
+ rect, hAlign, vAlign, wxHORIZONTAL);
}
void wxGrid::UseNativeColHeader(bool native)
void wxGrid::DrawCornerLabel(wxDC& dc)
{
+ wxRect rect(wxSize(m_rowLabelWidth, m_colLabelHeight));
+
if ( m_nativeColumnLabels )
{
- wxRect rect(wxSize(m_rowLabelWidth, m_colLabelHeight));
rect.Deflate(1);
wxRendererNative::Get().DrawHeaderButton(m_cornerLabelWin, dc, rect, 0);
}
else
{
- dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
- dc.DrawLine( m_rowLabelWidth - 1, m_colLabelHeight - 1,
- m_rowLabelWidth - 1, 0 );
- dc.DrawLine( m_rowLabelWidth - 1, m_colLabelHeight - 1,
- 0, m_colLabelHeight - 1 );
- dc.DrawLine( 0, 0, m_rowLabelWidth, 0 );
- dc.DrawLine( 0, 0, 0, m_colLabelHeight );
+ rect.width++;
+ rect.height++;
- dc.SetPen( *wxWHITE_PEN );
- dc.DrawLine( 1, 1, m_rowLabelWidth - 1, 1 );
- dc.DrawLine( 1, 1, 1, m_colLabelHeight - 1 );
+ wxGridCellAttrProvider * const
+ attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
+ const wxGridCornerHeaderRenderer&
+ rend = attrProvider ? attrProvider->GetCornerRenderer()
+ : static_cast<wxGridCornerHeaderRenderer&>
+ (gs_defaultHeaderRenderers.cornerRenderer);
+
+ rend.DrawBorder(*this, dc, rect);
}
}
int colLeft = GetColLeft(col);
wxRect rect(colLeft, 0, GetColWidth(col), m_colLabelHeight);
+ wxGridCellAttrProvider * const
+ attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
+ const wxGridColumnHeaderRenderer&
+ rend = attrProvider ? attrProvider->GetColumnHeaderRenderer(col)
+ : static_cast<wxGridColumnHeaderRenderer&>
+ (gs_defaultHeaderRenderers.colRenderer);
if ( m_nativeColumnLabels )
{
: wxHDR_SORT_ICON_DOWN
: wxHDR_SORT_ICON_NONE
);
+ rect.Deflate(2);
}
else
{
- int colRight = GetColRight(col) - 1;
-
- dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
- dc.DrawLine( colRight, 0,
- colRight, m_colLabelHeight - 1 );
- dc.DrawLine( colLeft, 0,
- colRight, 0 );
- dc.DrawLine( colLeft, m_colLabelHeight - 1,
- colRight + 1, m_colLabelHeight - 1 );
+ // It is reported that we need to erase the background to avoid display
+ // artefacts, see #12055.
+ wxDCBrushChanger setBrush(dc, m_colWindow->GetBackgroundColour());
+ dc.DrawRectangle(rect);
- dc.SetPen( *wxWHITE_PEN );
- dc.DrawLine( colLeft, 1, colLeft, m_colLabelHeight - 1 );
- dc.DrawLine( colLeft, 1, colRight, 1 );
+ rend.DrawBorder(*this, dc, rect);
}
- dc.SetBackgroundMode( wxBRUSHSTYLE_TRANSPARENT );
- dc.SetTextForeground( GetLabelTextColour() );
- dc.SetFont( GetLabelFont() );
-
int hAlign, vAlign;
- GetColLabelAlignment( &hAlign, &vAlign );
+ GetColLabelAlignment(&hAlign, &vAlign);
const int orient = GetColLabelTextOrientation();
- rect.Deflate(2);
- DrawTextRectangle(dc, GetColLabelValue(col), rect, hAlign, vAlign, orient);
+ rend.DrawLabel(*this, dc, GetColLabelValue(col), rect, hAlign, vAlign, orient);
}
// TODO: these 2 functions should be replaced with wxDC::DrawLabel() to which
const wxRect& rect,
int horizAlign,
int vertAlign,
- int textOrientation )
+ int textOrientation ) const
{
wxArrayString lines;
const wxRect& rect,
int horizAlign,
int vertAlign,
- int textOrientation)
+ int textOrientation) const
{
if ( lines.empty() )
return;
return;
// this should be checked by the caller!
- wxASSERT_MSG( CanEnableCellControl(), _T("can't enable editing for this cell!") );
+ wxASSERT_MSG( CanEnableCellControl(), wxT("can't enable editing for this cell!") );
// do it before ShowCellEditControl()
m_cellEditCtrlEnabled = enable;
bool wxGrid::IsCurrentCellReadOnly() const
{
- // const_cast
- wxGridCellAttr* attr = ((wxGrid *)this)->GetCellAttr(m_currentCellCoords);
+ wxGridCellAttr*
+ attr = const_cast<wxGrid *>(this)->GetCellAttr(m_currentCellCoords);
bool readonly = attr->IsReadOnly();
attr->DecRef();
return PosToLinePos(x, true /* clip */, wxGridColumnOperations());
}
-// return the row number that that the y coord is near the edge of, or -1 if
+// return the row number such that the y coord is near the edge of, or -1 if
// not near an edge.
//
-// coords can only possibly be near an edge if
-// (a) the row/column is large enough to still allow for an "inner" area
-// that is _not_ near the edge (i.e., if the height/width is smaller
-// than WXGRID_LABEL_EDGE_ZONE, coords are _never_ considered to be
-// near the edge).
-// and
-// (b) resizing rows/columns (the thing for which edge detection is
-// relevant at all) is enabled.
-//
+// notice that position can only possibly be near an edge if the row/column is
+// large enough to still allow for an "inner" area that is _not_ near the edge
+// (i.e., if the height/width is smaller than WXGRID_LABEL_EDGE_ZONE, pos will
+// _never_ be considered to be near the edge).
int wxGrid::PosToEdgeOfLine(int pos, const wxGridOperations& oper) const
{
- if ( !oper.CanResizeLines(this) )
- return -1;
-
const int line = oper.PosToLine(this, pos, true);
if ( oper.GetLineSize(this, line) > WXGRID_LABEL_EDGE_ZONE )
else if ( line > 0 &&
pos - oper.GetLineStartPos(this,
line) < WXGRID_LABEL_EDGE_ZONE )
- return line - 1;
+ {
+ return oper.GetLineBefore(this, line);
+ }
}
return -1;
//
// Sometimes GRID_SCROLL_LINE / 2 is not enough,
// so just add a full scroll unit...
- ypos += m_scrollLineY;
+ ypos += m_yScrollPixelsPerLine;
}
// special handling for wide cells - show always left part of the cell!
xpos = x0 + (right - cw);
// see comment for ypos above
- xpos += m_scrollLineX;
+ xpos += m_xScrollPixelsPerLine;
}
if ( xpos != -1 || ypos != -1 )
{
if ( xpos != -1 )
- xpos /= m_scrollLineX;
+ xpos /= m_xScrollPixelsPerLine;
if ( ypos != -1 )
- ypos /= m_scrollLineY;
+ ypos /= m_yScrollPixelsPerLine;
Scroll( xpos, ypos );
AdjustScrollbars();
}
int wxGrid::GetRowSize( int row ) const
{
- wxCHECK_MSG( row >= 0 && row < m_numRows, 0, _T("invalid row index") );
+ wxCHECK_MSG( row >= 0 && row < m_numRows, 0, wxT("invalid row index") );
return GetRowHeight(row);
}
int wxGrid::GetColSize( int col ) const
{
- wxCHECK_MSG( col >= 0 && col < m_numCols, 0, _T("invalid column index") );
+ wxCHECK_MSG( col >= 0 && col < m_numCols, 0, wxT("invalid column index") );
return GetColWidth(col);
}
return allow;
}
-void wxGrid::GetCellSize( int row, int col, int *num_rows, int *num_cols ) const
+wxGrid::CellSpan
+wxGrid::GetCellSize( int row, int col, int *num_rows, int *num_cols ) const
{
wxGridCellAttr *attr = GetCellAttr(row, col);
attr->GetSize( num_rows, num_cols );
attr->DecRef();
+
+ if ( *num_rows == 1 && *num_cols == 1 )
+ return CellSpan_None; // just a normal cell
+
+ if ( *num_rows < 0 || *num_cols < 0 )
+ return CellSpan_Inside; // covered by a multi-span cell
+
+ // this cell spans multiple cells to its right/bottom
+ return CellSpan_Main;
}
wxGridCellRenderer* wxGrid::GetCellRenderer(int row, int col) const
}
}
+void wxGrid::RefreshAttr(int row, int col)
+{
+ if ( m_attrCache.row == row && m_attrCache.col == col )
+ ClearAttrCache();
+}
+
+
void wxGrid::CacheAttr(int row, int col, wxGridCellAttr *attr) const
{
if ( attr != NULL )
{
- wxGrid *self = (wxGrid *)this; // const_cast
+ wxGrid * const self = const_cast<wxGrid *>(this);
self->ClearAttrCache();
self->m_attrCache.row = row;
wxGridCellAttr *attr = NULL;
bool canHave = ((wxGrid*)this)->CanHaveAttributes();
- wxCHECK_MSG( canHave, attr, _T("Cell attributes not allowed"));
- wxCHECK_MSG( m_table, attr, _T("must have a table") );
+ wxCHECK_MSG( canHave, attr, wxT("Cell attributes not allowed"));
+ wxCHECK_MSG( m_table, attr, wxT("must have a table") );
attr = m_table->GetAttr(row, col, wxGridCellAttr::Cell);
if ( !attr )
wxString typeName = wxGRID_VALUE_FLOAT;
if ( (width != -1) || (precision != -1) )
{
- typeName << _T(':') << width << _T(',') << precision;
+ typeName << wxT(':') << width << wxT(',') << precision;
}
SetColFormatCustom(col, typeName);
// row/col size
// ----------------------------------------------------------------------------
+void wxGrid::DoDisableLineResize(int line, wxGridFixedIndicesSet *& setFixed)
+{
+ if ( !setFixed )
+ {
+ setFixed = new wxGridFixedIndicesSet;
+ }
+
+ setFixed->insert(line);
+}
+
+bool
+wxGrid::DoCanResizeLine(int line, const wxGridFixedIndicesSet *setFixed) const
+{
+ return !setFixed || !setFixed->count(line);
+}
+
void wxGrid::EnableDragRowSize( bool enable )
{
m_canDragRowSize = enable;
void wxGrid::SetRowSize( int row, int height )
{
- wxCHECK_RET( row >= 0 && row < m_numRows, _T("invalid row index") );
+ wxCHECK_RET( row >= 0 && row < m_numRows, wxT("invalid row index") );
// if < 0 then calculate new height from label
if ( height < 0 )
void wxGrid::SetColSize( int col, int width )
{
- wxCHECK_RET( col >= 0 && col < m_numCols, _T("invalid column index") );
+ wxCHECK_RET( col >= 0 && col < m_numCols, wxT("invalid column index") );
// if < 0 then calculate new width from label
if ( width < 0 )
HideCellEditControl();
SaveEditControlValue();
- // init both of them to avoid compiler warnings, even if we only need one
- int row = -1,
- col = -1;
+ // initialize both of them just to avoid compiler warnings even if only
+ // really needs to be initialized here
+ int row,
+ col;
if ( column )
+ {
+ row = -1;
col = colOrRow;
+ }
else
+ {
row = colOrRow;
+ col = -1;
+ }
wxCoord extent, extentMax = 0;
int max = column ? m_numRows : m_numCols;
else
col = rowOrCol;
+ // we need to account for the cells spanning multiple columns/rows:
+ // while they may need a lot of space, they don't need all of it in
+ // this column/row
+ int numRows, numCols;
+ const CellSpan span = GetCellSize(row, col, &numRows, &numCols);
+ if ( span == CellSpan_Inside )
+ {
+ // we need to get the size of the main cell, not of a cell hidden
+ // by it
+ row += numRows;
+ col += numCols;
+
+ // get the size of the main cell too
+ GetCellSize(row, col, &numRows, &numCols);
+ }
+
wxGridCellAttr *attr = GetCellAttr(row, col);
wxGridCellRenderer *renderer = attr->GetRenderer(this, row, col);
if ( renderer )
{
wxSize size = renderer->GetBestSize(*this, *attr, dc, row, col);
extent = column ? size.x : size.y;
+
+ if ( span != CellSpan_None )
+ {
+ // we spread the size of a spanning cell over all the cells it
+ // covers evenly -- this is probably not ideal but we can't
+ // really do much better here
+ //
+ // notice that numCols and numRows are never 0 as they
+ // correspond to the size of the main cell of the span and not
+ // of the cell inside it
+ extent /= column ? numCols : numRows;
+ }
+
if ( extent > extentMax )
extentMax = extent;
// we know that we're not going to have scrollbars so disable them now to
// avoid trouble in SetClientSize() which can otherwise set the correct
// client size but also leave space for (not needed any more) scrollbars
- SetScrollbars(0, 0, 0, 0, 0, 0, true);
-
- // restore the scroll rate parameters overwritten by SetScrollbars()
- SetScrollRate(m_scrollLineX, m_scrollLineY);
+ SetScrollbars(m_xScrollPixelsPerLine, m_yScrollPixelsPerLine,
+ 0, 0, 0, 0, true);
SetClientSize(size.x + m_rowLabelWidth, size.y + m_colLabelHeight);
}
wxSize wxGrid::DoGetBestSize() const
{
- wxGrid *self = (wxGrid *)this; // const_cast
+ wxGrid * const self = const_cast<wxGrid *>(this);
// we do the same as in AutoSize() here with the exception that we don't
// change the column/row sizes, only calculate them
return;
const wxGridSelectionModes mode = m_selection->GetSelectionMode();
- if ( mode == oper.GetSelectionMode() )
+ if ( mode == oper.GetSelectionMode() ||
+ mode == wxGrid::wxGridSelectRowsOrColumns )
{
const wxGridCellCoords c(oper.MakeCoords(line, 0));
if ( m_selection->IsInSelection(c) )
{
// the first part of the typename is the "real" type, anything after ':'
// are the parameters for the renderer
- index = FindDataType(typeName.BeforeFirst(_T(':')));
+ index = FindDataType(typeName.BeforeFirst(wxT(':')));
if ( index == wxNOT_FOUND )
{
return wxNOT_FOUND;
editorOld->DecRef();
// do it even if there are no parameters to reset them to defaults
- wxString params = typeName.AfterFirst(_T(':'));
+ wxString params = typeName.AfterFirst(wxT(':'));
renderer->SetParameters(params);
editor->SetParameters(params);