X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a6b40a9aa23c66aee8b9bada956d15fb3c81299c..07aaf32633ecf18ec3edfbb41793a112914792d0:/src/generic/grid.cpp diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 3aef6989b0..6bd231ea0b 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -146,6 +146,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 ); @@ -2414,6 +2415,8 @@ wxGrid::SetTable(wxGridTableBase *table, m_created = true; } + InvalidateBestSize(); + return m_created; } @@ -3718,7 +3721,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); @@ -4640,7 +4644,7 @@ wxGrid::DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t), // event generation helpers // ---------------------------------------------------------------------------- -void +bool wxGrid::SendGridSizeEvent(wxEventType type, int row, int col, const wxMouseEvent& mouseEv) @@ -4655,7 +4659,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: @@ -6661,7 +6665,7 @@ int wxGrid::XToPos(int x) const 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 @@ -6670,7 +6674,8 @@ int wxGrid::XToPos(int x) const // _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 ) { @@ -6682,7 +6687,16 @@ int wxGrid::PosToEdgeOfLine(int pos, const wxGridOperations& oper) const 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; } } @@ -8104,8 +8118,11 @@ int UpdateRowOrColSize(int& sizeCurrent, int sizeNew) // 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. @@ -8114,8 +8131,13 @@ int UpdateRowOrColSize(int& sizeCurrent, int sizeNew) 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.