]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/gridctrl.cpp
Fix for scroll position being changed when partial layout is done
[wxWidgets.git] / src / generic / gridctrl.cpp
index 955c652ce868a95e45ec841400b96053fd51e775..65b7edd192acfe8b92a5f9b895ec99daabc1201a 100644 (file)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////
-// Name:        generic/gridctrl.cpp
+// Name:        src/generic/gridctrl.cpp
 // Purpose:     wxGrid controls
 // Author:      Paul Gammans, Roger Gammans
 // Modified by:
 // Purpose:     wxGrid controls
 // Author:      Paul Gammans, Roger Gammans
 // Modified by:
@@ -24,7 +24,7 @@
     #include "wx/textctrl.h"
     #include "wx/dc.h"
     #include "wx/combobox.h"
     #include "wx/textctrl.h"
     #include "wx/dc.h"
     #include "wx/combobox.h"
-       #include "wx/settings.h"
+    #include "wx/settings.h"
     #include "wx/log.h"
     #include "wx/checkbox.h"
 #endif // WX_PRECOMP
     #include "wx/log.h"
     #include "wx/checkbox.h"
 #endif // WX_PRECOMP
@@ -47,7 +47,7 @@ void wxGridCellRenderer::Draw(wxGrid& grid,
     dc.SetBackgroundMode( wxBRUSHSTYLE_SOLID );
 
     wxColour clr;
     dc.SetBackgroundMode( wxBRUSHSTYLE_SOLID );
 
     wxColour clr;
-    if ( grid.IsEnabled() )
+    if ( grid.IsThisEnabled() )
     {
         if ( isSelected )
         {
     {
         if ( isSelected )
         {
@@ -145,9 +145,9 @@ void wxGridCellDateTimeRenderer::Draw(wxGrid& grid,
     SetTextColoursAndFont(grid, attr, dc, isSelected);
 
     // draw the text right aligned by default
     SetTextColoursAndFont(grid, attr, dc, isSelected);
 
     // draw the text right aligned by default
-    int hAlign, vAlign;
-    attr.GetAlignment(&hAlign, &vAlign);
-    hAlign = wxRIGHT;
+    int hAlign = wxALIGN_RIGHT,
+        vAlign = wxALIGN_INVALID;
+    attr.GetNonDefaultAlignment(&hAlign, &vAlign);
 
     wxRect rect = rectCell;
     rect.Inflate(-1);
 
     wxRect rect = rectCell;
     rect.Inflate(-1);
@@ -172,7 +172,7 @@ void wxGridCellDateTimeRenderer::SetParameters(const wxString& params)
 #endif // wxUSE_DATETIME
 
 // ----------------------------------------------------------------------------
 #endif // wxUSE_DATETIME
 
 // ----------------------------------------------------------------------------
-// wxGridCellChoiceNumberRenderer
+// wxGridCellEnumRenderer
 // ----------------------------------------------------------------------------
 // Renders a number as a textual equivalent.
 // eg data in cell is 0,1,2 ... n the cell could be rendered as "John","Fred"..."Bob"
 // ----------------------------------------------------------------------------
 // Renders a number as a textual equivalent.
 // eg data in cell is 0,1,2 ... n the cell could be rendered as "John","Fred"..."Bob"
@@ -198,7 +198,7 @@ wxString wxGridCellEnumRenderer::GetString(const wxGrid& grid, int row, int col)
     if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
     {
         int choiceno = table->GetValueAsLong(row, col);
     if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
     {
         int choiceno = table->GetValueAsLong(row, col);
-        text.Printf(_T("%s"), m_choices[ choiceno ].c_str() );
+        text.Printf(wxT("%s"), m_choices[ choiceno ].c_str() );
     }
     else
     {
     }
     else
     {
@@ -222,9 +222,9 @@ void wxGridCellEnumRenderer::Draw(wxGrid& grid,
     SetTextColoursAndFont(grid, attr, dc, isSelected);
 
     // draw the text right aligned by default
     SetTextColoursAndFont(grid, attr, dc, isSelected);
 
     // draw the text right aligned by default
-    int hAlign, vAlign;
-    attr.GetAlignment(&hAlign, &vAlign);
-    hAlign = wxRIGHT;
+    int hAlign = wxALIGN_RIGHT,
+        vAlign = wxALIGN_INVALID;
+    attr.GetNonDefaultAlignment(&hAlign, &vAlign);
 
     wxRect rect = rectCell;
     rect.Inflate(-1);
 
     wxRect rect = rectCell;
     rect.Inflate(-1);
@@ -250,7 +250,7 @@ void wxGridCellEnumRenderer::SetParameters(const wxString& params)
 
     m_choices.Empty();
 
 
     m_choices.Empty();
 
-    wxStringTokenizer tk(params, _T(','));
+    wxStringTokenizer tk(params, wxT(','));
     while ( tk.HasMoreTokens() )
     {
         m_choices.Add(tk.GetNextToken());
     while ( tk.HasMoreTokens() )
     {
         m_choices.Add(tk.GetNextToken());
@@ -305,17 +305,17 @@ wxGridCellAutoWrapStringRenderer::GetTextLines(wxGrid& grid,
     wxCoord max_x = rect.GetWidth();
 
     dc.SetFont(attr.GetFont());
     wxCoord max_x = rect.GetWidth();
 
     dc.SetFont(attr.GetFont());
-    wxStringTokenizer tk(data , _T(" \n\t\r"));
+    wxStringTokenizer tk(data , wxT(" \n\t\r"));
     wxString thisline = wxEmptyString;
 
     while ( tk.HasMoreTokens() )
     {
         wxString tok = tk.GetNextToken();
     wxString thisline = wxEmptyString;
 
     while ( tk.HasMoreTokens() )
     {
         wxString tok = tk.GetNextToken();
-        //FIXME: this causes us to print an extra unnecesary
+        //FIXME: this causes us to print an extra unnecessary
         //       space at the end of the line. But it
         //       is invisible , simplifies the size calculation
         //       and ensures tokens are separated in the display
         //       space at the end of the line. But it
         //       is invisible , simplifies the size calculation
         //       and ensures tokens are separated in the display
-        tok += _T(" ");
+        tok += wxT(" ");
 
         dc.GetTextExtent(tok, &x, &y);
         if ( curr_x + x > max_x)
 
         dc.GetTextExtent(tok, &x, &y);
         if ( curr_x + x > max_x)
@@ -392,7 +392,7 @@ void wxGridCellStringRenderer::SetTextColoursAndFont(const wxGrid& grid,
     // TODO some special colours for attr.IsReadOnly() case?
 
     // different coloured text when the grid is disabled
     // TODO some special colours for attr.IsReadOnly() case?
 
     // different coloured text when the grid is disabled
-    if ( grid.IsEnabled() )
+    if ( grid.IsThisEnabled() )
     {
         if ( isSelected )
         {
     {
         if ( isSelected )
         {
@@ -425,7 +425,7 @@ wxSize wxGridCellStringRenderer::DoGetBestSize(const wxGridCellAttr& attr,
 {
     wxCoord x = 0, y = 0, max_x = 0;
     dc.SetFont(attr.GetFont());
 {
     wxCoord x = 0, y = 0, max_x = 0;
     dc.SetFont(attr.GetFont());
-    wxStringTokenizer tk(text, _T('\n'));
+    wxStringTokenizer tk(text, wxT('\n'));
     while ( tk.HasMoreTokens() )
     {
         dc.GetTextExtent(tk.GetNextToken(), &x, &y);
     while ( tk.HasMoreTokens() )
     {
         dc.GetTextExtent(tk.GetNextToken(), &x, &y);
@@ -554,7 +554,7 @@ wxString wxGridCellNumberRenderer::GetString(const wxGrid& grid, int row, int co
     wxString text;
     if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
     {
     wxString text;
     if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
     {
-        text.Printf(_T("%ld"), table->GetValueAsLong(row, col));
+        text.Printf(wxT("%ld"), table->GetValueAsLong(row, col));
     }
     else
     {
     }
     else
     {
@@ -576,9 +576,9 @@ void wxGridCellNumberRenderer::Draw(wxGrid& grid,
     SetTextColoursAndFont(grid, attr, dc, isSelected);
 
     // draw the text right aligned by default
     SetTextColoursAndFont(grid, attr, dc, isSelected);
 
     // draw the text right aligned by default
-    int hAlign, vAlign;
-    attr.GetAlignment(&hAlign, &vAlign);
-    hAlign = wxALIGN_RIGHT;
+    int hAlign = wxALIGN_RIGHT,
+        vAlign = wxALIGN_INVALID;
+    attr.GetNonDefaultAlignment(&hAlign, &vAlign);
 
     wxRect rect = rectCell;
     rect.Inflate(-1);
 
     wxRect rect = rectCell;
     rect.Inflate(-1);
@@ -598,10 +598,13 @@ wxSize wxGridCellNumberRenderer::GetBestSize(wxGrid& grid,
 // wxGridCellFloatRenderer
 // ----------------------------------------------------------------------------
 
 // wxGridCellFloatRenderer
 // ----------------------------------------------------------------------------
 
-wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width, int precision)
+wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width,
+                                                 int precision,
+                                                 int format)
 {
     SetWidth(width);
     SetPrecision(precision);
 {
     SetWidth(width);
     SetPrecision(precision);
+    SetFormat(format);
 }
 
 wxGridCellRenderer *wxGridCellFloatRenderer::Clone() const
 }
 
 wxGridCellRenderer *wxGridCellFloatRenderer::Clone() const
@@ -609,6 +612,7 @@ wxGridCellRenderer *wxGridCellFloatRenderer::Clone() const
     wxGridCellFloatRenderer *renderer = new wxGridCellFloatRenderer;
     renderer->m_width = m_width;
     renderer->m_precision = m_precision;
     wxGridCellFloatRenderer *renderer = new wxGridCellFloatRenderer;
     renderer->m_width = m_width;
     renderer->m_precision = m_precision;
+    renderer->m_style = m_style;
     renderer->m_format = m_format;
 
     return renderer;
     renderer->m_format = m_format;
 
     return renderer;
@@ -641,22 +645,30 @@ wxString wxGridCellFloatRenderer::GetString(const wxGrid& grid, int row, int col
                 if ( m_precision == -1 )
                 {
                     // default width/precision
                 if ( m_precision == -1 )
                 {
                     // default width/precision
-                    m_format = _T("%f");
+                    m_format = wxT("%");
                 }
                 else
                 {
                 }
                 else
                 {
-                    m_format.Printf(_T("%%.%df"), m_precision);
+                    m_format.Printf(wxT("%%.%d"), m_precision);
                 }
             }
             else if ( m_precision == -1 )
             {
                 // default precision
                 }
             }
             else if ( m_precision == -1 )
             {
                 // default precision
-                m_format.Printf(_T("%%%d.f"), m_width);
+                m_format.Printf(wxT("%%%d."), m_width);
             }
             else
             {
             }
             else
             {
-                m_format.Printf(_T("%%%d.%df"), m_width, m_precision);
+                m_format.Printf(wxT("%%%d.%d"), m_width, m_precision);
             }
             }
+
+            bool isUpper = ( ( m_style & wxGRID_FLOAT_FORMAT_UPPER ) == wxGRID_FLOAT_FORMAT_UPPER);
+            if ( ( m_style & wxGRID_FLOAT_FORMAT_SCIENTIFIC ) == wxGRID_FLOAT_FORMAT_SCIENTIFIC)
+                m_format += isUpper ? wxT('E') : wxT('e');
+            else if ( ( m_style & wxGRID_FLOAT_FORMAT_COMPACT ) == wxGRID_FLOAT_FORMAT_COMPACT)
+                m_format += isUpper ? wxT('G') : wxT('g');
+            else
+                m_format += wxT('f');
         }
 
         text.Printf(m_format, val);
         }
 
         text.Printf(m_format, val);
@@ -679,9 +691,9 @@ void wxGridCellFloatRenderer::Draw(wxGrid& grid,
     SetTextColoursAndFont(grid, attr, dc, isSelected);
 
     // draw the text right aligned by default
     SetTextColoursAndFont(grid, attr, dc, isSelected);
 
     // draw the text right aligned by default
-    int hAlign, vAlign;
-    attr.GetAlignment(&hAlign, &vAlign);
-    hAlign = wxALIGN_RIGHT;
+    int hAlign = wxALIGN_RIGHT,
+        vAlign = wxALIGN_INVALID;
+    attr.GetNonDefaultAlignment(&hAlign, &vAlign);
 
     wxRect rect = rectCell;
     rect.Inflate(-1);
 
     wxRect rect = rectCell;
     rect.Inflate(-1);
@@ -704,10 +716,12 @@ void wxGridCellFloatRenderer::SetParameters(const wxString& params)
         // reset to defaults
         SetWidth(-1);
         SetPrecision(-1);
         // reset to defaults
         SetWidth(-1);
         SetPrecision(-1);
+        SetFormat(wxGRID_FLOAT_FORMAT_DEFAULT);
     }
     else
     {
     }
     else
     {
-        wxString tmp = params.BeforeFirst(_T(','));
+        wxString rest;
+        wxString tmp = params.BeforeFirst(wxT(','), &rest);
         if ( !tmp.empty() )
         {
             long width;
         if ( !tmp.empty() )
         {
             long width;
@@ -717,11 +731,11 @@ void wxGridCellFloatRenderer::SetParameters(const wxString& params)
             }
             else
             {
             }
             else
             {
-                wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params.c_str());
+                wxLogDebug(wxT("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params.c_str());
             }
         }
 
             }
         }
 
-        tmp = params.AfterFirst(_T(','));
+        tmp = rest.BeforeFirst(wxT(','));
         if ( !tmp.empty() )
         {
             long precision;
         if ( !tmp.empty() )
         {
             long precision;
@@ -731,7 +745,44 @@ void wxGridCellFloatRenderer::SetParameters(const wxString& params)
             }
             else
             {
             }
             else
             {
-                wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params.c_str());
+                wxLogDebug(wxT("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params.c_str());
+            }
+        }
+
+        tmp = rest.AfterFirst(wxT(','));
+        if ( !tmp.empty() )
+        {
+            if ( tmp[0] == wxT('f') )
+            {
+                SetFormat(wxGRID_FLOAT_FORMAT_FIXED);
+            }
+            else if ( tmp[0] == wxT('e') )
+            {
+                SetFormat(wxGRID_FLOAT_FORMAT_SCIENTIFIC);
+            }
+            else if ( tmp[0] == wxT('g') )
+            {
+                SetFormat(wxGRID_FLOAT_FORMAT_COMPACT);
+            }
+            else if ( tmp[0] == wxT('E') )
+            {
+                SetFormat(wxGRID_FLOAT_FORMAT_SCIENTIFIC |
+                          wxGRID_FLOAT_FORMAT_UPPER);
+            }
+            else if ( tmp[0] == wxT('F') )
+            {
+                SetFormat(wxGRID_FLOAT_FORMAT_FIXED |
+                          wxGRID_FLOAT_FORMAT_UPPER);
+            }
+            else if ( tmp[0] == wxT('G') )
+            {
+                SetFormat(wxGRID_FLOAT_FORMAT_COMPACT |
+                          wxGRID_FLOAT_FORMAT_UPPER);
+            }
+            else
+            {
+                wxLogDebug("Invalid wxGridCellFloatRenderer format "
+                           "parameter string '%s ignored", params);
             }
         }
     }
             }
         }
     }
@@ -743,11 +794,6 @@ void wxGridCellFloatRenderer::SetParameters(const wxString& params)
 
 wxSize wxGridCellBoolRenderer::ms_sizeCheckMark;
 
 
 wxSize wxGridCellBoolRenderer::ms_sizeCheckMark;
 
-// FIXME these checkbox size calculations are really ugly...
-
-// between checkmark and box
-static const wxCoord wxGRID_CHECKMARK_MARGIN = 2;
-
 wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid,
                                            wxGridCellAttr& WXUNUSED(attr),
                                            wxDC& WXUNUSED(dc),
 wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid,
                                            wxGridCellAttr& WXUNUSED(attr),
                                            wxDC& WXUNUSED(dc),
@@ -757,18 +803,7 @@ wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid,
     // compute it only once (no locks for MT safeness in GUI thread...)
     if ( !ms_sizeCheckMark.x )
     {
     // compute it only once (no locks for MT safeness in GUI thread...)
     if ( !ms_sizeCheckMark.x )
     {
-        // get checkbox size
-        wxCheckBox *checkbox = new wxCheckBox(&grid, wxID_ANY, wxEmptyString);
-        wxSize size = checkbox->GetBestSize();
-        wxCoord checkSize = size.y + 2 * wxGRID_CHECKMARK_MARGIN;
-
-#if defined(__WXMOTIF__)
-        checkSize -= size.y / 2;
-#endif
-
-        delete checkbox;
-
-        ms_sizeCheckMark.x = ms_sizeCheckMark.y = checkSize;
+        ms_sizeCheckMark = wxRendererNative::Get().GetCheckBoxSize(&grid);
     }
 
     return ms_sizeCheckMark;
     }
 
     return ms_sizeCheckMark;