]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
don't set virtual size of the window to (0, 0) if scrollbars are removed from it
[wxWidgets.git] / src / generic / grid.cpp
index 6c6ba9d2c9bd70052eeae03cfdb4cd540b3b8c1d..47190211460c7e982582c7540dd204315a7c9a30 100644 (file)
@@ -47,6 +47,7 @@
 #include "wx/textfile.h"
 #include "wx/spinctrl.h"
 #include "wx/tokenzr.h"
+#include "wx/renderer.h"
 
 #include "wx/grid.h"
 #include "wx/generic/gridsel.h"
@@ -502,7 +503,7 @@ void wxGridCellEditor::Show(bool show, wxGridCellAttr *attr)
             m_colBgOld = m_control->GetBackgroundColour();
             m_control->SetBackgroundColour(attr->GetBackgroundColour());
 
-            // Workaround for GTK+1 font setting problem on some platforms
+// Workaround for GTK+1 font setting problem on some platforms
 #if !defined(__WXGTK__) || defined(__WXGTK20__)
             m_fontOld = m_control->GetFont();
             m_control->SetFont(attr->GetFont());
@@ -525,8 +526,7 @@ void wxGridCellEditor::Show(bool show, wxGridCellAttr *attr)
             m_control->SetBackgroundColour(m_colBgOld);
             m_colBgOld = wxNullColour;
         }
-
-        // Workaround for GTK+1 font setting problem on some platforms
+// Workaround for GTK+1 font setting problem on some platforms
 #if !defined(__WXGTK__) || defined(__WXGTK20__)
         if ( m_fontOld.Ok() )
         {
@@ -552,7 +552,7 @@ void wxGridCellEditor::HandleReturn(wxKeyEvent& event)
 bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event)
 {
     // accept the simple key presses, not anything with Ctrl/Alt/Meta
-    return !(event.ControlDown() || event.AltDown());
+    return !(event.ControlDown() || event.AltDown() || event.GetKeyCode() == WXK_SHIFT);
 }
 
 void wxGridCellEditor::StartingKey(wxKeyEvent& event)
@@ -729,7 +729,7 @@ bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event)
 
             default:
                 // accept 8 bit chars too if isprint() agrees
-                if ( (keycode < 255) && (wxIsprint((wxChar)keycode)) )
+                if ( (keycode < 255) && (wxIsprint(keycode)) )
                     return true;
         }
     }
@@ -803,6 +803,7 @@ void wxGridCellNumberEditor::Create(wxWindow* parent,
                                     wxWindowID id,
                                     wxEvtHandler* evtHandler)
 {
+#if wxUSE_SPINCTRL
     if ( HasRange() )
     {
         // create a spin ctrl
@@ -814,6 +815,7 @@ void wxGridCellNumberEditor::Create(wxWindow* parent,
         wxGridCellEditor::Create(parent, id, evtHandler);
     }
     else
+#endif
     {
         // just a text control
         wxGridCellTextEditor::Create(parent, id, evtHandler);
@@ -843,12 +845,14 @@ void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid)
         }
     }
 
+#if wxUSE_SPINCTRL
     if ( HasRange() )
     {
         Spin()->SetValue((int)m_valueOld);
         Spin()->SetFocus();
     }
     else
+#endif
     {
         DoBeginEdit(GetString());
     }
@@ -861,6 +865,7 @@ bool wxGridCellNumberEditor::EndEdit(int row, int col,
     long value = 0;
     wxString text;
 
+#if wxUSE_SPINCTRL
     if ( HasRange() )
     {
         value = Spin()->GetValue();
@@ -869,6 +874,7 @@ bool wxGridCellNumberEditor::EndEdit(int row, int col,
             text = wxString::Format(wxT("%ld"), value);
     }
     else
+#endif
     {
         text = Text()->GetValue();
         changed = (text.empty() || text.ToLong(&value)) && (value != m_valueOld);
@@ -887,11 +893,13 @@ bool wxGridCellNumberEditor::EndEdit(int row, int col,
 
 void wxGridCellNumberEditor::Reset()
 {
+#if wxUSE_SPINCTRL
     if ( HasRange() )
     {
         Spin()->SetValue((int)m_valueOld);
     }
     else
+#endif
     {
         DoReset(GetString());
     }
@@ -923,7 +931,7 @@ bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent& event)
                 return true;
 
             default:
-                if ( (keycode < 128) && wxIsdigit((wxChar)keycode) )
+                if ( (keycode < 128) && wxIsdigit(keycode) )
                     return true;
         }
     }
@@ -936,7 +944,7 @@ void wxGridCellNumberEditor::StartingKey(wxKeyEvent& event)
     if ( !HasRange() )
     {
         int keycode = event.GetKeyCode();
-        if ( wxIsdigit((wxChar)keycode) || keycode == '+' || keycode == '-'
+        if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-'
             || keycode ==  WXK_NUMPAD0
             || keycode ==  WXK_NUMPAD1
             || keycode ==  WXK_NUMPAD2
@@ -993,18 +1001,21 @@ void wxGridCellNumberEditor::SetParameters(const wxString& params)
 // return the value in the spin control if it is there (the text control otherwise)
 wxString wxGridCellNumberEditor::GetValue() const
 {
-  wxString s;
+    wxString s;
 
-  if( HasRange() )
-  {
-    long value = Spin()->GetValue();
-    s.Printf(wxT("%ld"), value);
-  }
-  else
-  {
-    s = Text()->GetValue();
-  }
-  return s;
+#if wxUSE_SPINCTRL
+    if( HasRange() )
+    {
+        long value = Spin()->GetValue();
+        s.Printf(wxT("%ld"), value);
+    }
+    else
+#endif
+    {
+        s = Text()->GetValue();
+    }
+
+    return s;
 }
 
 // ----------------------------------------------------------------------------
@@ -1082,7 +1093,7 @@ void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event)
     wxString strbuf(tmpbuf, *wxConvCurrent);
     bool is_decimal_point = ( strbuf ==
       wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER) );
-        if ( wxIsdigit((wxChar)keycode) || keycode == '+' || keycode == '-'
+        if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-'
             || is_decimal_point
             || keycode ==  WXK_NUMPAD0
             || keycode ==  WXK_NUMPAD1
@@ -1193,7 +1204,7 @@ bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event)
                     ( strbuf == wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT,
                                                   wxLOCALE_CAT_NUMBER) );
                 if ( (keycode < 128) &&
-                     (wxIsdigit((wxChar)keycode) || tolower(keycode) == 'e' ||
+                     (wxIsdigit(keycode) || tolower(keycode) == 'e' ||
                       is_decimal_point || keycode == '+' || keycode == '-') )
                     return true;
             }
@@ -1586,18 +1597,18 @@ void wxGridCellRenderer::Draw(wxGrid& grid,
     // grey out fields if the grid is disabled
     if( grid.IsEnabled() )
     {
-      if ( isSelected )
-      {
-          dc.SetBrush( wxBrush(grid.GetSelectionBackground(), wxSOLID) );
-      }
-      else
-      {
-          dc.SetBrush( wxBrush(attr.GetBackgroundColour(), wxSOLID) );
-      }
+        if ( isSelected )
+        {
+            dc.SetBrush( wxBrush(grid.GetSelectionBackground(), wxSOLID) );
+        }
+        else
+        {
+            dc.SetBrush( wxBrush(attr.GetBackgroundColour(), wxSOLID) );
+        }
     }
     else
     {
-      dc.SetBrush(wxBrush(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE), wxSOLID));
+        dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE), wxSOLID));
     }
 
     dc.SetPen( *wxTRANSPARENT_PEN );
@@ -1633,8 +1644,8 @@ void wxGridCellStringRenderer::SetTextColoursAndFont(wxGrid& grid,
     }
     else
     {
-      dc.SetTextBackground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE));
-      dc.SetTextForeground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_GRAYTEXT));
+      dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
+      dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
     }
 
     dc.SetFont( attr.GetFont() );
@@ -1921,7 +1932,7 @@ void wxGridCellFloatRenderer::SetParameters(const wxString& params)
     else
     {
         wxString tmp = params.BeforeFirst(_T(','));
-        if ( !!tmp )
+        if ( !tmp.empty() )
         {
             long width;
             if ( tmp.ToLong(&width) )
@@ -1935,7 +1946,7 @@ void wxGridCellFloatRenderer::SetParameters(const wxString& params)
 
         }
                 tmp = params.AfterFirst(_T(','));
-                if ( !!tmp )
+                if ( !tmp.empty() )
                 {
                     long precision;
             if ( tmp.ToLong(&precision) )
@@ -2420,7 +2431,9 @@ void wxGridCellAttrData::UpdateAttrRows( size_t pos, int numRows )
                 else
                 {
                     // ...or remove the attribute
-                    m_attrs.RemoveAt((size_t)n);
+                    // No need to DecRef the attribute itself since this is
+                    // done be wxGridCellWithAttr's destructor!
+                    m_attrs.RemoveAt(n);
                     n--; count--;
                 }
             }
@@ -2453,7 +2466,9 @@ void wxGridCellAttrData::UpdateAttrCols( size_t pos, int numCols )
                 else
                 {
                     // ...or remove the attribute
-                    m_attrs.RemoveAt((size_t)n);
+                    // No need to DecRef the attribute itself since this is
+                    // done be wxGridCellWithAttr's destructor!
+                    m_attrs.RemoveAt(n);
                     n--; count--;
                 }
             }
@@ -2551,8 +2566,9 @@ void wxGridRowOrColAttrData::UpdateAttrRowsOrCols( size_t pos, int numRowsOrCols
                     rowOrCol += numRowsOrCols;
                 else
                 {
-                    m_rowsOrCols.RemoveAt((size_t)n);
-                    m_attrs.RemoveAt((size_t)n);
+                    m_rowsOrCols.RemoveAt(n);
+                    m_attrs[n]->DecRef();
+                    m_attrs.RemoveAt(n);
                     n--; count--;
                 }
             }
@@ -3636,6 +3652,15 @@ void wxGridCornerLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
     int client_width = 0;
     GetClientSize( &client_width, &client_height );
 
+#if __WXGTK__
+    wxRect rect;
+    rect.SetX( 1 );
+    rect.SetY( 1 );
+    rect.SetWidth( client_width - 2 );
+    rect.SetHeight( client_height - 2 );
+
+    wxRendererNative::Get().DrawHeaderButton( this, dc, rect, 0 );
+#else
     dc.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW),1, wxSOLID) );
     dc.DrawLine( client_width-1, client_height-1, client_width-1, 0 );
     dc.DrawLine( client_width-1, client_height-1, 0, client_height-1 );
@@ -3645,6 +3670,7 @@ void wxGridCornerLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
     dc.SetPen( *wxWHITE_PEN );
     dc.DrawLine( 1, 1, client_width-1, 1 );
     dc.DrawLine( 1, 1, 1, client_height-1 );
+#endif
 }
 
 
@@ -7193,6 +7219,19 @@ void wxGrid::DrawRowLabel( wxDC& dc, int row )
     if ( GetRowHeight(row) <= 0 )
         return;
 
+    wxRect rect;
+#ifdef __WXGTK__
+    rect.SetX( 1 );
+    rect.SetY( GetRowTop(row) + 1 );
+    rect.SetWidth( m_rowLabelWidth - 2 );
+    rect.SetHeight( GetRowHeight(row) - 2 );
+
+    CalcScrolledPosition( 0, rect.y, NULL, &rect.y );
+
+    wxWindowDC *win_dc = (wxWindowDC*) &dc;
+
+    wxRendererNative::Get().DrawHeaderButton( win_dc->m_owner, dc, rect, 0 );
+#else
     int rowTop = GetRowTop(row),
         rowBottom = GetRowBottom(row) - 1;
 
@@ -7207,7 +7246,7 @@ void wxGrid::DrawRowLabel( wxDC& dc, int row )
     dc.SetPen( *wxWHITE_PEN );
     dc.DrawLine( 1, rowTop, 1, rowBottom );
     dc.DrawLine( 1, rowTop, m_rowLabelWidth-1, rowTop );
-
+#endif
     dc.SetBackgroundMode( wxTRANSPARENT );
     dc.SetTextForeground( GetLabelTextColour() );
     dc.SetFont( GetLabelFont() );
@@ -7215,7 +7254,6 @@ void wxGrid::DrawRowLabel( wxDC& dc, int row )
     int hAlign, vAlign;
     GetRowLabelAlignment( &hAlign, &vAlign );
 
-    wxRect rect;
     rect.SetX( 2 );
     rect.SetY( GetRowTop(row) + 2 );
     rect.SetWidth( m_rowLabelWidth - 4 );
@@ -7243,8 +7281,20 @@ void wxGrid::DrawColLabel( wxDC& dc, int col )
     if ( GetColWidth(col) <= 0 )
         return;
 
-    int colLeft = GetColLeft(col),
-        colRight = GetColRight(col) - 1;
+    int colLeft = GetColLeft(col);
+
+    wxRect rect;
+#ifdef __WXGTK__
+    rect.SetX( colLeft + 1 );
+    rect.SetY( 1 );
+    rect.SetWidth( GetColWidth(col) - 2 );
+    rect.SetHeight( m_colLabelHeight - 2 );
+
+    wxWindowDC *win_dc = (wxWindowDC*) &dc;
+
+    wxRendererNative::Get().DrawHeaderButton( win_dc->m_owner, dc, rect, 0 );
+#else
+    int colRight = GetColRight(col) - 1;
 
     dc.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW),1, wxSOLID) );
     dc.DrawLine( colRight, 0,
@@ -7258,7 +7308,7 @@ void wxGrid::DrawColLabel( wxDC& dc, int col )
     dc.SetPen( *wxWHITE_PEN );
     dc.DrawLine( colLeft, 1, colLeft, m_colLabelHeight-1 );
     dc.DrawLine( colLeft, 1, colRight, 1 );
-
+#endif
     dc.SetBackgroundMode( wxTRANSPARENT );
     dc.SetTextForeground( GetLabelTextColour() );
     dc.SetFont( GetLabelFont() );
@@ -7267,7 +7317,6 @@ void wxGrid::DrawColLabel( wxDC& dc, int col )
     GetColLabelAlignment( &hAlign, &vAlign );
     orient = GetColLabelTextOrientation();
 
-    wxRect rect;
     rect.SetX( colLeft + 2 );
     rect.SetY( 2 );
     rect.SetWidth( GetColWidth(col) - 4 );
@@ -7475,6 +7524,16 @@ void wxGrid::ForceRefresh()
     EndBatch();
 }
 
+bool wxGrid::Enable(bool enable)
+{
+    if ( !wxScrolledWindow::Enable(enable) )
+        return false;
+
+    // redraw in the new state
+    m_gridWin->Refresh();
+
+    return true;
+}
 
 //
 // ------ Edit control functions
@@ -10137,7 +10196,7 @@ wxRect wxGrid::BlockToDeviceRect( const wxGridCellCoords &topLeft,
     }
     else
     {
-        rect = wxRect( 0, 0, 0, 0 );
+        rect = wxRect(0,0,0,0);
     }
 
     cellRect = CellToRect( bottomRight );
@@ -10212,7 +10271,7 @@ wxRect wxGrid::BlockToDeviceRect( const wxGridCellCoords &topLeft,
     m_gridWin->GetClientSize( &cw, &ch );
 
     if (right < 0 || bottom < 0 || left > cw || top > ch)
-        return wxRect( 0, 0, 0, 0);
+        return wxRect(0,0,0,0);
 
     rect.SetLeft( wxMax(0, left) );
     rect.SetTop( wxMax(0, top) );