]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
use wxChar correctly in wxString docs; mark wx1 compatibility functions
[wxWidgets.git] / src / generic / grid.cpp
index bf62e90e3ec22783bd19963b08af336ec726e428..a2994e167915ceb41b0d8827e908f7bc01a8426c 100644 (file)
@@ -1233,6 +1233,9 @@ bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event)
 // wxGridCellBoolEditor
 // ----------------------------------------------------------------------------
 
+// the default values for GetValue()
+wxString wxGridCellBoolEditor::ms_stringValues[2] = { _T("1"), _T("") };
+
 void wxGridCellBoolEditor::Create(wxWindow* parent,
                                   wxWindowID id,
                                   wxEvtHandler* evtHandler)
@@ -1338,7 +1341,19 @@ void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid)
     else
     {
         wxString cellval( grid->GetTable()->GetValue(row, col) );
-        m_startValue = !( !cellval || (cellval == wxT("0")) );
+
+        if ( cellval == ms_stringValues[false] )
+            m_startValue = false;
+        else if ( cellval == ms_stringValues[true] )
+            m_startValue = true;
+        else
+        {
+            // do not try to be smart here and convert it to true or false
+            // because we'll still overwrite it with something different and
+            // this risks to be very surprising for the user code, let them
+            // know about it
+            wxFAIL_MSG( _T("invalid value for a cell with bool editor!") );
+        }
     }
 
     CBox()->SetValue(m_startValue);
@@ -1358,10 +1373,11 @@ bool wxGridCellBoolEditor::EndEdit(int row, int col,
 
     if ( changed )
     {
-        if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL))
-            grid->GetTable()->SetValueAsBool(row, col, value);
+        wxGridTableBase * const table = grid->GetTable();
+        if ( table->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) )
+            table->SetValueAsBool(row, col, value);
         else
-            grid->GetTable()->SetValue(row, col, value ? _T("1") : wxEmptyString);
+            table->SetValue(row, col, GetValue());
     }
 
     return changed;
@@ -1416,12 +1432,23 @@ void wxGridCellBoolEditor::StartingKey(wxKeyEvent& event)
     }
 }
 
-
-// return the value as "1" for true and the empty string for false
 wxString wxGridCellBoolEditor::GetValue() const
 {
-  bool bSet = CBox()->GetValue();
-  return bSet ? _T("1") : wxEmptyString;
+  return ms_stringValues[CBox()->GetValue()];
+}
+
+/* static */ void
+wxGridCellBoolEditor::UseStringValues(const wxString& valueTrue,
+                                      const wxString& valueFalse)
+{
+    ms_stringValues[false] = valueFalse;
+    ms_stringValues[true] = valueTrue;
+}
+
+/* static */ bool
+wxGridCellBoolEditor::IsTrueValue(const wxString& value)
+{
+    return value == ms_stringValues[true];
 }
 
 #endif // wxUSE_CHECKBOX
@@ -2217,7 +2244,7 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid,
     else
     {
         wxString cellval( grid.GetTable()->GetValue(row, col) );
-        value = !( !cellval || (cellval == wxT("0")) );
+        value = wxGridCellBoolEditor::IsTrueValue(cellval);
     }
 
     if ( value )
@@ -3882,7 +3909,8 @@ void wxGridCornerLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
     GetClientSize( &client_width, &client_height );
 
     // VZ: any reason for this ifdef? (FIXME)
-#ifdef __WXGTK__
+#if 0
+def __WXGTK__
     wxRect rect;
     rect.SetX( 1 );
     rect.SetY( 1 );
@@ -7798,7 +7826,8 @@ void wxGrid::DrawRowLabel( wxDC& dc, int row )
 
     wxRect rect;
 
-#ifdef __WXGTK20__
+#if 0
+def __WXGTK20__
     rect.SetX( 1 );
     rect.SetY( GetRowTop(row) + 1 );
     rect.SetWidth( m_rowLabelWidth - 2 );
@@ -7860,7 +7889,8 @@ void wxGrid::DrawColLabel( wxDC& dc, int col )
 
     wxRect rect;
 
-#ifdef __WXGTK20__
+#if 0
+def __WXGTK20__
     rect.SetX( colLeft + 1 );
     rect.SetY( 1 );
     rect.SetWidth( GetColWidth(col) - 2 );