#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
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()),
}
}
+ 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() )
delete m_typeRegistry;
delete m_selection;
+
+ delete m_setFixedRows;
+ delete m_setFixedCols;
}
//
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;
//
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:
{
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__
+#if wxUSE_LOG_TRACE
static const wxChar *cursorModes[] =
{
_T("SELECT_CELL"),
: win ? _T("rowLabelWin")
: _T("gridWin"),
cursorModes[m_cursorMode], cursorModes[mode]);
-#endif
+#endif // wxUSE_LOG_TRACE
if ( mode == m_cursorMode &&
win == m_winCapture &&
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::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;
// 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 );
+ wxGridEvent gridEvt( GetId(), type, this, row, col );
+ gridEvt.SetString(s);
- claimed = GetEventHandler()->ProcessEvent(gridEvt);
- vetoed = !gridEvt.IsAllowed();
- }
- else
- {
- 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;
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 )
// 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;
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) )