// Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
// Modified by: Robin Dunn, Vadim Zeitlin, Santiago Palacios
// Created: 1/08/1999
-// RCS-ID: $Id$
// Copyright: (c) Michael Bedward (mbedward@ozemail.com.au)
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
wxDEFINE_EVENT( wxEVT_GRID_LABEL_RIGHT_DCLICK, wxGridEvent );
wxDEFINE_EVENT( wxEVT_GRID_ROW_SIZE, wxGridSizeEvent );
wxDEFINE_EVENT( wxEVT_GRID_COL_SIZE, wxGridSizeEvent );
+wxDEFINE_EVENT( wxEVT_GRID_COL_AUTO_SIZE, wxGridSizeEvent );
wxDEFINE_EVENT( wxEVT_GRID_COL_MOVE, wxGridEvent );
wxDEFINE_EVENT( wxEVT_GRID_COL_SORT, wxGridEvent );
wxDEFINE_EVENT( wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEvent );
EVT_KEY_UP( wxGrid::OnKeyUp )
EVT_CHAR ( wxGrid::OnChar )
EVT_ERASE_BACKGROUND( wxGrid::OnEraseBackground )
+ EVT_COMMAND(wxID_ANY, wxEVT_GRID_HIDE_EDITOR, wxGrid::OnHideEditor )
END_EVENT_TABLE()
bool wxGrid::Create(wxWindow *parent, wxWindowID id,
m_created = true;
}
+ InvalidateBestSize();
+
return m_created;
}
int numCols = msg.GetCommandInt();
int oldNumCols = m_numCols;
m_numCols += numCols;
- if ( m_useNativeHeader )
- GetGridColHeader()->SetColumnCount(m_numCols);
if ( !m_colAt.IsEmpty() )
{
}
}
+ // Notice that this must be called after updating m_colWidths above
+ // as the native grid control will check whether the new columns
+ // are shown which results in accessing m_colWidths array.
+ if ( m_useNativeHeader )
+ GetGridColHeader()->SetColumnCount(m_numCols);
+
if ( m_currentCellCoords == wxGridNoCellCoords )
{
// if we have just inserted cols into an empty grid the current
break;
}
+ InvalidateBestSize();
+
if (result && !GetBatchCount() )
m_gridWin->Refresh();
// adjust column width depending on label text
//
// TODO: generate RESIZING event, see #10754
- AutoSizeColLabelSize( colEdge );
+ if ( !SendGridSizeEvent(wxEVT_GRID_COL_AUTO_SIZE, -1, colEdge, event) )
+ AutoSizeColLabelSize( colEdge );
SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, colEdge, event);
// event generation helpers
// ----------------------------------------------------------------------------
-void
+bool
wxGrid::SendGridSizeEvent(wxEventType type,
int row, int col,
const wxMouseEvent& mouseEv)
mouseEv.GetY() + GetColLabelSize(),
mouseEv);
- GetEventHandler()->ProcessEvent(gridEvt);
+ return GetEventHandler()->ProcessEvent(gridEvt);
}
// Generate a grid event based on a mouse event and return:
}
}
+void wxGrid::OnHideEditor(wxCommandEvent& WXUNUSED(event))
+{
+ DisableCellEditControl();
+}
+
//
// ------ Grid location functions
// Note that all of these functions work with the logical coordinates of
return PosToLinePos(x, true /* clip */, wxGridColumnOperations());
}
-// return the row number such that the y coord is near the edge of, or -1 if
+// return the row/col number such that the pos is near the edge of, or -1 if
// not near an edge.
//
// notice that position can only possibly be near an edge if the row/column is
// _never_ be considered to be near the edge).
int wxGrid::PosToEdgeOfLine(int pos, const wxGridOperations& oper) const
{
- const int line = oper.PosToLine(this, pos, true);
+ // Get the bottom or rightmost line that could match.
+ int line = oper.PosToLine(this, pos, true);
if ( oper.GetLineSize(this, line) > WXGRID_LABEL_EDGE_ZONE )
{
pos - oper.GetLineStartPos(this,
line) < WXGRID_LABEL_EDGE_ZONE )
{
- return oper.GetLineBefore(this, line);
+ // We need to find the previous visible line, so skip all the
+ // hidden (of size 0) ones.
+ do
+ {
+ line = oper.GetLineBefore(this, line);
+ }
+ while ( line >= 0 && oper.GetLineSize(this, line) == 0 );
+
+ // It can possibly be -1 here.
+ return line;
}
}
}
m_rowLabelWidth = width;
+ InvalidateBestSize();
CalcWindowSizes();
wxScrolledWindow::Refresh( true );
}
}
m_colLabelHeight = height;
+ InvalidateBestSize();
CalcWindowSizes();
wxScrolledWindow::Refresh( true );
}
// We're showing back a previously hidden row/column.
wxASSERT_MSG( sizeNew == -1, wxS("New size must be positive or -1.") );
- wxASSERT_MSG( sizeCurrent < 0, wxS("May only show back if hidden.") );
+ // If it's already visible, simply do nothing.
+ if ( sizeCurrent >= 0 )
+ return 0;
+ // Otherwise show it by restoring its old size.
sizeCurrent = -sizeCurrent;
// This is positive which is correct.
else if ( sizeNew == 0 )
{
// We're hiding a row/column.
- wxASSERT_MSG( sizeCurrent > 0, wxS("Can't hide if already hidden.") );
+ // If it's already hidden, simply do nothing.
+ if ( sizeCurrent <= 0 )
+ return 0;
+
+ // Otherwise hide it and also remember the shown size to be able to
+ // restore it later.
sizeCurrent = -sizeCurrent;
// This is negative which is correct.
return;
// The value of -1 is special and means to fit the height to the row label.
- if ( height == -1 )
+ // As with the columns, ignore attempts to auto-size the hidden rows.
+ if ( height == -1 && GetRowHeight(row) != 0 )
{
- // As with the columns, ignore attempts to auto-size the hidden rows.
- if ( GetRowHeight(row) == 0 )
- return;
-
long w, h;
wxArrayString lines;
wxClientDC dc(m_rowLabelWin);
m_rowBottoms[i] += diff;
}
+ InvalidateBestSize();
+
if ( !GetBatchCount() )
{
CalcDimensions();
return;
// The value of -1 is special and means to fit the width to the column label.
- if ( width == -1 )
+ //
+ // Notice that we currently don't support auto-sizing hidden columns (we
+ // could, but it's not clear whether this is really needed and it would
+ // make the code more complex), and for them passing -1 simply means to
+ // show the column back using its old size.
+ if ( width == -1 && GetColWidth(col) != 0 )
{
- // We currently don't support auto-sizing hidden columns. We could, but
- // it's not clear whether this is really needed and it would make the
- // code more complex.
- if ( GetColWidth(col) == 0 )
- return;
-
long w, h;
wxArrayString lines;
wxClientDC dc(m_colWindow);
m_colRights[GetColAt(colPos)] += diff;
}
+ InvalidateBestSize();
+
if ( !GetBatchCount() )
{
CalcDimensions();
wxSize size(self->SetOrCalcColumnSizes(true) - m_rowLabelWidth + m_extraWidth,
self->SetOrCalcRowSizes(true) - m_colLabelHeight + m_extraHeight);
- // NOTE: This size should be cached, but first we need to add calls to
- // InvalidateBestSize everywhere that could change the results of this
- // calculation.
- // CacheBestSize(size);
-
return wxSize(size.x + m_rowLabelWidth, size.y + m_colLabelHeight)
+ GetWindowBorderSize();
}