Renamed DrawCheckButton due to conflict with existing and public api of wxUniversal...
[wxWidgets.git] / src / generic / grid.cpp
index 285cfeda4f0adb39e26309ceb011e056a7f732d8..78ab72525061c3986e98a12f966c511784cf611d 100644 (file)
@@ -3206,7 +3206,7 @@ wxString wxGridTableBase::GetColLabelValue( int col )
 
     // reverse the string...
     wxString s2;
-    for ( i = 0;  i < n;  i++ )
+    for ( i = 0; i < n; i++ )
     {
         s2 += s[n - i - 1];
     }
@@ -3375,9 +3375,9 @@ void wxGridStringTable::Clear()
     {
         numCols = m_data[0].GetCount();
 
-        for ( row = 0;  row < numRows;  row++ )
+        for ( row = 0; row < numRows; row++ )
         {
-            for ( col = 0;  col < numCols;  col++ )
+            for ( col = 0; col < numCols; col++ )
             {
                 m_data[row][col] = wxEmptyString;
             }
@@ -3500,9 +3500,9 @@ bool wxGridStringTable::InsertCols( size_t pos, size_t numCols )
         return AppendCols( numCols );
     }
 
-    for ( row = 0;  row < curNumRows;  row++ )
+    for ( row = 0; row < curNumRows; row++ )
     {
-        for ( col = pos;  col < pos + numCols;  col++ )
+        for ( col = pos; col < pos + numCols; col++ )
         {
             m_data[row].Insert( wxEmptyString, col );
         }
@@ -3537,7 +3537,7 @@ bool wxGridStringTable::AppendCols( size_t numCols )
     }
 #endif
 
-    for ( row = 0;  row < curNumRows;  row++ )
+    for ( row = 0; row < curNumRows; row++ )
     {
         m_data[row].Add( wxEmptyString, numCols );
     }
@@ -3579,7 +3579,7 @@ bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols )
         numCols = curNumCols - pos;
     }
 
-    for ( row = 0;  row < curNumRows;  row++ )
+    for ( row = 0; row < curNumRows; row++ )
     {
         if ( numCols >= curNumCols )
         {
@@ -3639,7 +3639,7 @@ void wxGridStringTable::SetRowLabelValue( int row, const wxString& value )
         int n = m_rowLabels.GetCount();
         int i;
 
-        for ( i = n;  i <= row;  i++ )
+        for ( i = n; i <= row; i++ )
         {
             m_rowLabels.Add( wxGridTableBase::GetRowLabelValue(i) );
         }
@@ -3655,7 +3655,7 @@ void wxGridStringTable::SetColLabelValue( int col, const wxString& value )
         int n = m_colLabels.GetCount();
         int i;
 
-        for ( i = n;  i <= col;  i++ )
+        for ( i = n; i <= col; i++ )
         {
             m_colLabels.Add( wxGridTableBase::GetColLabelValue(i) );
         }
@@ -3822,7 +3822,7 @@ END_EVENT_TABLE()
 wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid *parent,
                                                   wxWindowID id,
                                                   const wxPoint &pos, const wxSize &size )
-  : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE )
+  : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxBORDER_NONE | wxFULL_REPAINT_ON_RESIZE )
 {
     m_owner = parent;
 }
@@ -4147,10 +4147,15 @@ wxGrid::~wxGrid()
 
 void wxGrid::Create()
 {
-    m_created = false;    // set to true by CreateGrid
+    // set to true by CreateGrid
+    m_created = false;
+
+    // create the type registry
+    m_typeRegistry = new wxGridTypeRegistry;
+    m_selection = NULL;
 
-    m_table        = (wxGridTableBase *) NULL;
-    m_ownTable     = false;
+    m_table = (wxGridTableBase *) NULL;
+    m_ownTable = false;
 
     m_cellEditCtrlEnabled = false;
 
@@ -4185,16 +4190,7 @@ void wxGrid::Create()
     m_rowLabelWidth = WXGRID_DEFAULT_ROW_LABEL_WIDTH;
     m_colLabelHeight = WXGRID_DEFAULT_COL_LABEL_HEIGHT;
 
-    // create the type registry
-    m_typeRegistry = new wxGridTypeRegistry;
-    m_selection = NULL;
-
     // subwindow components that make up the wxGrid
-    m_cornerLabelWin = new wxGridCornerLabelWindow( this,
-                                                    wxID_ANY,
-                                                    wxDefaultPosition,
-                                                    wxDefaultSize );
-
     m_rowLabelWin = new wxGridRowLabelWindow( this,
                                               wxID_ANY,
                                               wxDefaultPosition,
@@ -4205,6 +4201,11 @@ void wxGrid::Create()
                                               wxDefaultPosition,
                                               wxDefaultSize );
 
+    m_cornerLabelWin = new wxGridCornerLabelWindow( this,
+                                                    wxID_ANY,
+                                                    wxDefaultPosition,
+                                                    wxDefaultSize );
+
     m_gridWin = new wxGridWindow( this,
                                   m_rowLabelWin,
                                   m_colLabelWin,
@@ -4329,10 +4330,10 @@ void wxGrid::Init()
     }
     else
     {
-        m_labelBackgroundColour = wxColour( wxT("WHITE") );
+        m_labelBackgroundColour = *wxWHITE;
     }
 
-    m_labelTextColour = wxColour( wxT("BLACK") );
+    m_labelTextColour = *wxBLACK;
 
     // init attr cache
     m_attrCache.row = -1;
@@ -4426,7 +4427,7 @@ void wxGrid::InitRowHeights()
 
     m_rowHeights.Add( m_defaultRowHeight, m_numRows );
 
-    for ( int i = 0;  i < m_numRows;  i++ )
+    for ( int i = 0; i < m_numRows; i++ )
     {
         rowBottom += m_defaultRowHeight;
         m_rowBottoms.Add( rowBottom );
@@ -4444,7 +4445,7 @@ void wxGrid::InitColWidths()
 
     m_colWidths.Add( m_defaultColWidth, m_numCols );
 
-    for ( int i = 0;  i < m_numCols;  i++ )
+    for ( int i = 0; i < m_numCols; i++ )
     {
         colRight += m_defaultColWidth;
         m_colRights.Add( colRight );
@@ -4502,24 +4503,24 @@ void wxGrid::CalcDimensions()
     // take into account editor if shown
     if ( IsCellEditControlShown() )
     {
-      int w2, h2;
-      int r = m_currentCellCoords.GetRow();
-      int c = m_currentCellCoords.GetCol();
-      int x = GetColLeft(c);
-      int y = GetRowTop(r);
-
-      // how big is the editor
-      wxGridCellAttr* attr = GetCellAttr(r, c);
-      wxGridCellEditor* editor = attr->GetEditor(this, r, c);
-      editor->GetControl()->GetSize(&w2, &h2);
-      w2 += x;
-      h2 += y;
-      if ( w2 > w )
-          w = w2;
-      if ( h2 > h )
-          h = h2;
-      editor->DecRef();
-      attr->DecRef();
+        int w2, h2;
+        int r = m_currentCellCoords.GetRow();
+        int c = m_currentCellCoords.GetCol();
+        int x = GetColLeft(c);
+        int y = GetRowTop(r);
+
+        // how big is the editor
+        wxGridCellAttr* attr = GetCellAttr(r, c);
+        wxGridCellEditor* editor = attr->GetEditor(this, r, c);
+        editor->GetControl()->GetSize(&w2, &h2);
+        w2 += x;
+        h2 += y;
+        if ( w2 > w )
+            w = w2;
+        if ( h2 > h )
+            h = h2;
+        editor->DecRef();
+        attr->DecRef();
     }
 
     // preserve (more or less) the previous position
@@ -4542,7 +4543,6 @@ void wxGrid::CalcDimensions()
     CalcWindowSizes();
 }
 
-
 void wxGrid::CalcWindowSizes()
 {
     // escape if the window is has not been fully created yet
@@ -4566,9 +4566,8 @@ void wxGrid::CalcWindowSizes()
         m_gridWin->SetSize( m_rowLabelWidth, m_colLabelHeight, cw - m_rowLabelWidth, ch - m_colLabelHeight);
 }
 
-
-// this is called when the grid table sends a message to say that it
-// has been redimensioned
+// this is called when the grid table sends a message
+// to indicate that it has been redimensioned
 //
 bool wxGrid::Redimension( wxGridTableMessage& msg )
 {
@@ -4618,7 +4617,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
                 if ( pos > 0 )
                     bottom = m_rowBottoms[pos - 1];
 
-                for ( i = pos;  i < m_numRows;  i++ )
+                for ( i = pos; i < m_numRows; i++ )
                 {
                     bottom += m_rowHeights[i];
                     m_rowBottoms[i] = bottom;
@@ -4663,7 +4662,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
                 if ( oldNumRows > 0 )
                     bottom = m_rowBottoms[oldNumRows - 1];
 
-                for ( i = oldNumRows;  i < m_numRows;  i++ )
+                for ( i = oldNumRows; i < m_numRows; i++ )
                 {
                     bottom += m_rowHeights[i];
                     m_rowBottoms[i] = bottom;
@@ -4699,12 +4698,13 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
                 m_rowBottoms.RemoveAt( pos, numRows );
 
                 int h = 0;
-                for ( i = 0;  i < m_numRows;  i++ )
+                for ( i = 0; i < m_numRows; i++ )
                 {
                     h += m_rowHeights[i];
                     m_rowBottoms[i] = h;
                 }
             }
+
             if ( !m_numRows )
             {
                 m_currentCellCoords = wxGridNoCellCoords;
@@ -4721,6 +4721,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
             if (attrProvider)
             {
                 attrProvider->UpdateAttrRows( pos, -((int)numRows) );
+
 // ifdef'd out following patch from Paul Gammans
 #if 0
                 // No need to touch column attributes, unless we
@@ -4757,7 +4758,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
                 if ( pos > 0 )
                     right = m_colRights[pos - 1];
 
-                for ( i = pos;  i < m_numCols;  i++ )
+                for ( i = pos; i < m_numCols; i++ )
                 {
                     right += m_colWidths[i];
                     m_colRights[i] = right;
@@ -4801,7 +4802,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
                 if ( oldNumCols > 0 )
                     right = m_colRights[oldNumCols - 1];
 
-                for ( i = oldNumCols;  i < m_numCols;  i++ )
+                for ( i = oldNumCols; i < m_numCols; i++ )
                 {
                     right += m_colWidths[i];
                     m_colRights[i] = right;
@@ -4836,7 +4837,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
                 m_colRights.RemoveAt( pos, numCols );
 
                 int w = 0;
-                for ( i = 0;  i < m_numCols;  i++ )
+                for ( i = 0; i < m_numCols; i++ )
                 {
                     w += m_colWidths[i];
                     m_colRights[i] = w;
@@ -4908,7 +4909,8 @@ wxArrayInt wxGrid::CalcRowLabelsExposed( const wxRegion& reg )
 #if defined(__WXMOTIF__)
         int cw, ch;
         m_gridWin->GetClientSize( &cw, &ch );
-        if ( r.GetTop() > ch ) r.SetTop( 0 );
+        if ( r.GetTop() > ch )
+            r.SetTop( 0 );
         r.SetBottom( wxMin( r.GetBottom(), ch ) );
 #endif
 
@@ -4921,7 +4923,7 @@ wxArrayInt wxGrid::CalcRowLabelsExposed( const wxRegion& reg )
         // find the row labels within these bounds
         //
         int row;
-        for ( row = internalYToRow(top);  row < m_numRows;  row++ )
+        for ( row = internalYToRow(top); row < m_numRows; row++ )
         {
             if ( GetRowBottom(row) < top )
                 continue;
@@ -4958,7 +4960,8 @@ wxArrayInt wxGrid::CalcColLabelsExposed( const wxRegion& reg )
 #if defined(__WXMOTIF__)
         int cw, ch;
         m_gridWin->GetClientSize( &cw, &ch );
-        if ( r.GetLeft() > cw ) r.SetLeft( 0 );
+        if ( r.GetLeft() > cw )
+            r.SetLeft( 0 );
         r.SetRight( wxMin( r.GetRight(), cw ) );
 #endif
 
@@ -4971,7 +4974,7 @@ wxArrayInt wxGrid::CalcColLabelsExposed( const wxRegion& reg )
         // find the cells within these bounds
         //
         int col;
-        for ( col = internalXToCol(left);  col < m_numCols;  col++ )
+        for ( col = internalXToCol(left); col < m_numCols; col++ )
         {
             if ( GetColRight(col) < left )
                 continue;
@@ -5022,7 +5025,7 @@ wxGridCellCoordsArray wxGrid::CalcCellsExposed( const wxRegion& reg )
         // find the cells within these bounds
         //
         int row, col;
-        for ( row = internalYToRow(top);  row < m_numRows;  row++ )
+        for ( row = internalYToRow(top); row < m_numRows; row++ )
         {
             if ( GetRowBottom(row) <= top )
                 continue;
@@ -5030,7 +5033,7 @@ wxGridCellCoordsArray wxGrid::CalcCellsExposed( const wxRegion& reg )
             if ( GetRowTop(row) > bottom )
                 break;
 
-            for ( col = internalXToCol(left);  col < m_numCols;  col++ )
+            for ( col = internalXToCol(left); col < m_numCols; col++ )
             {
                 if ( GetColRight(col) <= left )
                     continue;
@@ -6381,7 +6384,8 @@ int wxGrid::SendEvent( const wxEventType type,
 
 void wxGrid::OnPaint( wxPaintEvent& WXUNUSED(event) )
 {
-    wxPaintDC dc(this);  // needed to prevent zillions of paint events on MSW
+    // needed to prevent zillions of paint events on MSW
+    wxPaintDC dc(this);
 }
 
 void wxGrid::Refresh(bool eraseb, const wxRect* rect)
@@ -6943,9 +6947,9 @@ bool wxGrid::SetModelValues()
 
     if ( m_table )
     {
-        for ( row = 0;  row < m_numRows;  row++ )
+        for ( row = 0; row < m_numRows; row++ )
         {
-            for ( col = 0;  col < m_numCols;  col++ )
+            for ( col = 0; col < m_numCols; col++ )
             {
                 m_table->SetValue( row, col, GetCellValue(row, col) );
             }
@@ -6981,7 +6985,7 @@ void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells )
         {
             wxGridCellCoords cell( row + cell_rows, col + cell_cols );
             bool marked = false;
-            for ( int j = 0;  j < numCells; j++ )
+            for ( int j = 0; j < numCells; j++ )
             {
                 if ( cell == cells[j] )
                 {
@@ -7015,7 +7019,7 @@ void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells )
         {
             for ( int l = 0; l < cell_rows; l++ )
             {
-                // find a cell in this row to left alreay marked for repaint
+                // find a cell in this row to leave already marked for repaint
                 int left = col;
                 for (int k = 0; k < int(redrawCells.GetCount()); k++)
                     if ((redrawCells[k].GetCol() < left) &&
@@ -7071,7 +7075,7 @@ void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells )
 
     numCells = redrawCells.GetCount();
 
-    for ( i = numCells - 1; i >= 0;  i-- )
+    for ( i = numCells - 1; i >= 0; i-- )
     {
         DrawCell( dc, redrawCells[i] );
     }
@@ -7171,10 +7175,10 @@ void wxGrid::DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr )
 
     if (penWidth > 0)
     {
-        // The center of th drawn line is where the position/width/height of
-        // the rectangle is actually at, (on wxMSW at least,) so we will
-        // reduce the size of the rectangle to compensate for the thickness of
-        // the line. If this is too strange on non wxMSW platforms then
+        // The center of the drawn line is where the position/width/height of
+        // the rectangle is actually at (on wxMSW at least), so the
+        // size of the rectangle is reduced to compensate for the thickness of
+        // the line. If this is too strange on non-wxMSW platforms then
         // please #ifdef this appropriately.
         rect.x += penWidth / 2;
         rect.y += penWidth / 2;
@@ -7475,7 +7479,7 @@ void wxGrid::DrawColLabels( wxDC& dc,const wxArrayInt& cols )
     size_t i;
     size_t numLabels = cols.GetCount();
 
-    for ( i = 0;  i < numLabels;  i++ )
+    for ( i = 0; i < numLabels; i++ )
     {
         DrawColLabel( dc, cols[i] );
     }
@@ -7687,7 +7691,7 @@ void wxGrid::GetTextBoxSize( const wxDC& dc,
     long lineW = 0, lineH = 0;
 
     size_t i;
-    for ( i = 0;  i < lines.GetCount();  i++ )
+    for ( i = 0; i < lines.GetCount(); i++ )
     {
         dc.GetTextExtent( lines[i], &lineW, &lineH );
         w = wxMax( w, lineW );
@@ -8274,7 +8278,7 @@ void wxGrid::MakeCellVisible( int row, int col )
         {
             int h = r.GetHeight();
             ypos = r.GetTop();
-            for ( i = row - 1;  i >= 0;  i-- )
+            for ( i = row - 1; i >= 0; i-- )
             {
                 int rowHeight = GetRowHeight(i);
                 if ( h + rowHeight > ch )
@@ -8285,11 +8289,11 @@ void wxGrid::MakeCellVisible( int row, int col )
             }
 
             // we divide it later by GRID_SCROLL_LINE, make sure that we don't
-            // have rounding errors (this is important, because if we do, we
-            // might not scroll at all and some cells won't be redrawn)
+            // have rounding errors (this is important, because if we do,
+            // we might not scroll at all and some cells won't be redrawn)
             //
-            // Sometimes GRID_SCROLL_LINE/2 is not enough, so just add a full
-            // scroll unit...
+            // Sometimes GRID_SCROLL_LINE / 2 is not enough,
+            // so just add a full scroll unit...
             ypos += m_scrollLineY;
         }
 
@@ -9774,7 +9778,7 @@ void wxGrid::SetRowSize( int row, int height )
 
     m_rowHeights[row] = h;
     int i;
-    for ( i = row;  i < m_numRows;  i++ )
+    for ( i = row; i < m_numRows; i++ )
     {
         m_rowBottoms[i] += diff;
     }
@@ -9821,16 +9825,16 @@ void wxGrid::SetColSize( int col, int width )
         InitColWidths();
     }
 
-    // if < 0 calc new width from label
+    // if < 0 then calculate new width from label
     if ( width < 0 )
     {
-      long w, h;
-      wxArrayString lines;
-      wxClientDC dc(m_colLabelWin);
-      dc.SetFont(GetLabelFont());
-      StringToLines(GetColLabelValue(col), lines);
-      GetTextBoxSize(dc, lines, &w, &h);
-      width = w + 6;
+        long w, h;
+        wxArrayString lines;
+        wxClientDC dc(m_colLabelWin);
+        dc.SetFont(GetLabelFont());
+        StringToLines(GetColLabelValue(col), lines);
+        GetTextBoxSize(dc, lines, &w, &h);
+        width = w + 6;
     }
 
     int w = wxMax( 0, width );
@@ -9838,7 +9842,7 @@ void wxGrid::SetColSize( int col, int width )
     m_colWidths[col] = w;
 
     int i;
-    for ( i = col;  i < m_numCols;  i++ )
+    for ( i = col; i < m_numCols; i++ )
     {
         m_colRights[i] += diff;
     }
@@ -9943,9 +9947,7 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column )
             wxSize size = renderer->GetBestSize(*this, *attr, dc, row, col);
             extent = column ? size.x : size.y;
             if ( extent > extentMax )
-            {
                 extentMax = extent;
-            }
 
             renderer->DecRef();
         }
@@ -9968,9 +9970,7 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column )
 
     extent = column ? w : h;
     if ( extent > extentMax )
-    {
         extentMax = extent;
-    }
 
     if ( !extentMax )
     {
@@ -10037,9 +10037,7 @@ int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin)
     for ( int col = 0; col < m_numCols; col++ )
     {
         if ( !calcOnly )
-        {
             AutoSizeColumn(col, setAsMin);
-        }
 
         width += GetColWidth(col);
     }