X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/71b619d7f464dca60f58b603a46c53293d8e3011..6f026b5b63fe7ccb025e84509886f74772b9df13:/src/generic/grid.cpp?ds=inline diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 670f3d5923..38c1b9f92c 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -4,7 +4,6 @@ // 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 ///////////////////////////////////////////////////////////////////////////// @@ -146,6 +145,7 @@ wxDEFINE_EVENT( wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEvent ); 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 ); @@ -2158,6 +2158,7 @@ BEGIN_EVENT_TABLE( wxGrid, wxScrolledWindow ) 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, @@ -2943,8 +2944,6 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) int numCols = msg.GetCommandInt(); int oldNumCols = m_numCols; m_numCols += numCols; - if ( m_useNativeHeader ) - GetGridColHeader()->SetColumnCount(m_numCols); if ( !m_colAt.IsEmpty() ) { @@ -2976,6 +2975,12 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) } } + // 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 @@ -3720,7 +3725,8 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event ) // 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); @@ -4642,7 +4648,7 @@ wxGrid::DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t), // event generation helpers // ---------------------------------------------------------------------------- -void +bool wxGrid::SendGridSizeEvent(wxEventType type, int row, int col, const wxMouseEvent& mouseEv) @@ -4657,7 +4663,7 @@ wxGrid::SendGridSizeEvent(wxEventType type, mouseEv.GetY() + GetColLabelSize(), mouseEv); - GetEventHandler()->ProcessEvent(gridEvt); + return GetEventHandler()->ProcessEvent(gridEvt); } // Generate a grid event based on a mouse event and return: @@ -6551,6 +6557,11 @@ void wxGrid::SaveEditControlValue() } } +void wxGrid::OnHideEditor(wxCommandEvent& WXUNUSED(event)) +{ + DisableCellEditControl(); +} + // // ------ Grid location functions // Note that all of these functions work with the logical coordinates of @@ -6675,17 +6686,28 @@ int wxGrid::PosToEdgeOfLine(int pos, const wxGridOperations& oper) const // Get the bottom or rightmost line that could match. int line = oper.PosToLine(this, pos, true); - // Go backwards until we find a line that is big enough. - while ( oper.GetLineSize(this, line) <= WXGRID_LABEL_EDGE_ZONE ) + if ( oper.GetLineSize(this, line) > WXGRID_LABEL_EDGE_ZONE ) { - line = oper.GetLineBefore(this, line); - if ( line <= 0 ) - break; - } + // We know that we are in this line, test whether we are close enough + // to start or end border, respectively. + if ( abs(oper.GetLineEndPos(this, line) - pos) < WXGRID_LABEL_EDGE_ZONE ) + return line; + else if ( line > 0 && + pos - oper.GetLineStartPos(this, + line) < WXGRID_LABEL_EDGE_ZONE ) + { + // 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 ); - // If the bottom or right touches then we have a match - if ( abs(oper.GetLineEndPos(this, line) - pos) < WXGRID_LABEL_EDGE_ZONE ) - return line; + // It can possibly be -1 here. + return line; + } + } return -1; } @@ -8150,12 +8172,9 @@ void wxGrid::SetRowSize( int row, int height ) 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); @@ -8226,14 +8245,13 @@ void wxGrid::SetColSize( int col, int width ) 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);