]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
Code cleaning.
[wxWidgets.git] / src / generic / grid.cpp
index 6e36f1d0fdf88f8f6e7d504607601b1a19a9256f..8947c56632c19ea533d9ac212af55022c0f17ad9 100644 (file)
@@ -41,6 +41,7 @@
     #include "wx/checkbox.h"
     #include "wx/combobox.h"
     #include "wx/valtext.h"
+    #include "wx/intl.h"
 #endif
 
 #include "wx/textfile.h"
@@ -668,7 +669,8 @@ bool wxGridCellTextEditor::EndEdit(int row, int col,
         grid->GetTable()->SetValue(row, col, value);
 
     m_startValue = wxEmptyString;
-    Text()->SetValue(m_startValue);
+    // No point in setting the text of the hidden control
+    //Text()->SetValue(m_startValue);
 
     return changed;
 }
@@ -1066,7 +1068,13 @@ void wxGridCellFloatEditor::Reset()
 void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event)
 {
     int keycode = event.GetKeyCode();
-        if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-' || keycode == '.'
+    char tmpbuf[2];
+    tmpbuf[0] = (char) keycode;
+    tmpbuf[1] = '\0';
+    bool is_decimal_point = ( wxString(tmpbuf, *wxConvCurrent) == 
+      wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER) );
+        if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-'
+            || is_decimal_point
             || keycode ==  WXK_NUMPAD0
             || keycode ==  WXK_NUMPAD1
             || keycode ==  WXK_NUMPAD2
@@ -1165,11 +1173,21 @@ bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event)
             case WXK_NUMPAD_DECIMAL:
                 return TRUE;
 
-            default:
-                // additionally accept 'e' as in '1e+6'
+            default: 
+            {
+               // additionally accept 'e' as in '1e+6', also '-', '+', and '.'
+                char tmpbuf[2];
+                tmpbuf[0] = (char) keycode;
+                tmpbuf[1] = '\0';
+                bool is_decimal_point =
+                  ( wxString(tmpbuf, *wxConvCurrent) == 
+                    wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT,
+                                      wxLOCALE_CAT_NUMBER) );
                 if ( (keycode < 128) &&
-                     (wxIsdigit(keycode) || tolower(keycode) == 'e') )
+                     (wxIsdigit(keycode) || tolower(keycode) == 'e' ||
+                      is_decimal_point || keycode == '+' || keycode == '-') )
                     return TRUE;
+            }
         }
     }
 
@@ -1397,20 +1415,11 @@ void wxGridCellChoiceEditor::Create(wxWindow* parent,
                                     wxWindowID id,
                                     wxEvtHandler* evtHandler)
 {
-    size_t count = m_choices.GetCount();
-    wxString *choices = new wxString[count];
-    for ( size_t n = 0; n < count; n++ )
-    {
-        choices[n] = m_choices[n];
-    }
-
     m_control = new wxComboBox(parent, id, wxEmptyString,
                                wxDefaultPosition, wxDefaultSize,
-                               count, choices,
+                               m_choices,
                                m_allowOthers ? 0 : wxCB_READONLY);
 
-    delete [] choices;
-
     wxGridCellEditor::Create(parent, id, evtHandler);
 }
 
@@ -2991,7 +3000,7 @@ wxString wxGridTableBase::GetColLabelValue( int col )
     unsigned int i, n;
     for ( n = 1; ; n++ )
     {
-        s += (_T('A') + (wxChar)( col%26 ));
+        s += (wxChar) (_T('A') + (wxChar)( col%26 ));
         col = col/26 - 1;
         if ( col < 0 ) break;
     }
@@ -3470,7 +3479,7 @@ END_EVENT_TABLE()
 wxGridRowLabelWindow::wxGridRowLabelWindow( wxGrid *parent,
                                             wxWindowID id,
                                             const wxPoint &pos, const wxSize &size )
-  : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE )
+  : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE )
 {
     m_owner = parent;
 }
@@ -3536,7 +3545,7 @@ END_EVENT_TABLE()
 wxGridColLabelWindow::wxGridColLabelWindow( wxGrid *parent,
                                             wxWindowID id,
                                             const wxPoint &pos, const wxSize &size )
-  : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE )
+  : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE )
 {
     m_owner = parent;
 }
@@ -3601,7 +3610,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 )
+  : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE )
 {
     m_owner = parent;
 }
@@ -3673,14 +3682,13 @@ wxGridWindow::wxGridWindow( wxGrid *parent,
                             wxWindowID id,
                             const wxPoint &pos,
                             const wxSize &size )
-            : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxBORDER_NONE | wxCLIP_CHILDREN,
+            : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxBORDER_NONE | wxCLIP_CHILDREN|wxFULL_REPAINT_ON_RESIZE,
                         wxT("grid window") )
 
 {
     m_owner = parent;
     m_rowLabelWin = rowLblWin;
     m_colLabelWin = colLblWin;
-    SetBackgroundColour(_T("WHITE"));
 }
 
 
@@ -3803,7 +3811,7 @@ IMPLEMENT_DYNAMIC_CLASS_XTI(wxGrid, wxScrolledWindow,"wx/grid.h")
 
 wxBEGIN_PROPERTIES_TABLE(wxGrid)
     wxHIDE_PROPERTY( Children )
-    wxPROPERTY_FLAGS( WindowStyle , wxGridStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
+    wxPROPERTY_FLAGS( WindowStyle , wxGridStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
 wxEND_PROPERTIES_TABLE()
 
 wxBEGIN_HANDLERS_TABLE(wxGrid)
@@ -3894,6 +3902,14 @@ wxGrid::~wxGrid()
 // ----- internal init and update functions
 //
 
+// NOTE: If using the default visual attributes works everywhere then this can
+// be removed as well as the #else cases below.
+#define _USE_VISATTR 0
+
+#if _USE_VISATTR
+#include "wx/listbox.h"
+#endif
+
 void wxGrid::Create()
 {
     m_created = FALSE;    // set to TRUE by CreateGrid
@@ -3910,13 +3926,22 @@ void wxGrid::Create()
     m_defaultCellAttr->SetKind(wxGridCellAttr::Default);
     m_defaultCellAttr->SetFont(GetFont());
     m_defaultCellAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_TOP);
+    m_defaultCellAttr->SetRenderer(new wxGridCellStringRenderer);
+    m_defaultCellAttr->SetEditor(new wxGridCellTextEditor);
+
+#if _USE_VISATTR
+    wxVisualAttributes gva = wxListBox::GetClassDefaultAttributes();
+    wxVisualAttributes lva = wxPanel::GetClassDefaultAttributes();
+
+    m_defaultCellAttr->SetTextColour(gva.colFg);
+    m_defaultCellAttr->SetBackgroundColour(gva.colBg);
+    
+#else
     m_defaultCellAttr->SetTextColour(
         wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
     m_defaultCellAttr->SetBackgroundColour(
         wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
-    m_defaultCellAttr->SetRenderer(new wxGridCellStringRenderer);
-    m_defaultCellAttr->SetEditor(new wxGridCellTextEditor);
-
+#endif
 
     m_numRows = 0;
     m_numCols = 0;
@@ -3954,6 +3979,27 @@ void wxGrid::Create()
 
     SetTargetWindow( m_gridWin );
 
+#if _USE_VISATTR
+    wxColour gfg = gva.colFg;
+    wxColour gbg = gva.colBg;
+    wxColour lfg = lva.colFg;
+    wxColour lbg = lva.colBg;
+#else
+    wxColour gfg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
+    wxColour gbg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
+    wxColour lfg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
+    wxColour lbg = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
+#endif
+    m_cornerLabelWin->SetDefaultForegroundColour(lfg);
+    m_cornerLabelWin->SetDefaultBackgroundColour(lbg);
+    m_rowLabelWin->SetDefaultForegroundColour(lfg);
+    m_rowLabelWin->SetDefaultBackgroundColour(lbg);
+    m_colLabelWin->SetDefaultForegroundColour(lfg);
+    m_colLabelWin->SetDefaultBackgroundColour(lbg);
+
+    m_gridWin->SetDefaultForegroundColour(gfg);
+    m_gridWin->SetDefaultBackgroundColour(gbg);
+    
     Init();
 }
 
@@ -4240,9 +4286,9 @@ void wxGrid::CalcDimensions()
     GetViewStart( &x, &y );
 
     // ensure the position is valid for the new scroll ranges
-        if ( x >= w )
+    if ( x >= w )
         x = wxMax( w - 1, 0 );
-        if ( y >= h )
+    if ( y >= h )
         y = wxMax( h - 1, 0 );
 
     // do set scrollbar parameters
@@ -6271,8 +6317,7 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
                     else
                     {
                         // at the bottom of a column
-                        HideCellEditControl();
-                        SaveEditControlValue();
+                        DisableCellEditControl();
                     }
                 }
                 break;
@@ -6291,8 +6336,7 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
                     else
                     {
                         // at left of grid
-                        HideCellEditControl();
-                        SaveEditControlValue();
+                        DisableCellEditControl();
                     }
                 }
                 else
@@ -6304,8 +6348,7 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
                     else
                     {
                         // at right of grid
-                        HideCellEditControl();
-                        SaveEditControlValue();
+                        DisableCellEditControl();
                     }
                 }
                 break;
@@ -6454,7 +6497,6 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords )
 
     if ( m_currentCellCoords != wxGridNoCellCoords )
     {
-        HideCellEditControl();
         DisableCellEditControl();
 
         if ( IsVisible( m_currentCellCoords, FALSE ) )
@@ -9515,6 +9557,10 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column )
 {
     wxClientDC dc(m_gridWin);
 
+    //Cancel editting of cell
+    HideCellEditControl();
+    SaveEditControlValue();
+
     // init both of them to avoid compiler warnings, even if weo nly need one
     int row = -1,
         col = -1;