]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
mention wxTreeCtrl::SelectItem() fix of r60921
[wxWidgets.git] / src / generic / grid.cpp
index 231630ea0223e243db7fc1ebdf732001a639bdbd..7b99052966399db1c43bf307e30dac955321d8ea 100644 (file)
@@ -1127,11 +1127,14 @@ IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable, wxGridTableBase )
 wxGridStringTable::wxGridStringTable()
         : wxGridTableBase()
 {
+    m_numCols = 0;
 }
 
 wxGridStringTable::wxGridStringTable( int numRows, int numCols )
         : wxGridTableBase()
 {
+    m_numCols = numCols;
+
     m_data.Alloc( numRows );
 
     wxArrayString sa;
@@ -1141,23 +1144,6 @@ wxGridStringTable::wxGridStringTable( int numRows, int numCols )
     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()),
@@ -1327,6 +1313,8 @@ bool wxGridStringTable::InsertCols( size_t pos, size_t numCols )
         }
     }
 
+    m_numCols += numCols;
+
     if ( GetView() )
     {
         wxGridTableMessage msg( this,
@@ -1351,6 +1339,8 @@ bool wxGridStringTable::AppendCols( size_t numCols )
         m_data[row].Add( wxEmptyString, numCols );
     }
 
+    m_numCols += numCols;
+
     if ( GetView() )
     {
         wxGridTableMessage msg( this,
@@ -1404,16 +1394,23 @@ bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols )
             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() )
@@ -2969,8 +2966,12 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
         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;
         }
@@ -2990,14 +2991,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
     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;
@@ -3318,8 +3312,12 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
         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;
         }
@@ -3332,7 +3330,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
         switch ( m_cursorMode )
         {
             case WXGRID_CURSOR_RESIZE_COL:
-                DoEndDragResizeCol();
+                DoEndDragResizeCol(event);
                 break;
 
             case WXGRID_CURSOR_MOVE_COL:
@@ -3754,17 +3752,12 @@ wxGrid::DoGridCellLeftUp(wxMouseEvent& event, const wxGridCellCoords& 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;
@@ -3894,10 +3887,11 @@ void wxGrid::ProcessGridCellMouseEvent(wxMouseEvent& event)
     }
 }
 
-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();
 
@@ -3921,9 +3915,12 @@ void wxGrid::DoEndDragResizeLine(const wxGridOperations& oper)
 
     // 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;
 
@@ -3986,24 +3983,24 @@ void wxGrid::DoEndDragResizeLine(const wxGridOperations& oper)
 
     // 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)
@@ -4177,9 +4174,27 @@ wxGrid::DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t),
     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
@@ -4188,26 +4203,11 @@ wxGrid::DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t),
 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(),
@@ -4270,28 +4270,13 @@ wxGrid::SendEvent(const wxEventType type,
 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;