]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
using the foreground brush to fill mono bitmaps - gradients are not yet supported
[wxWidgets.git] / src / generic / grid.cpp
index 68c6411e8f8413e3a36b09afe121b22bf17166aa..8f8d30f9756e15f75e659424782d172550c45bb9 100644 (file)
@@ -18,6 +18,8 @@
 
 #if wxUSE_GRID
 
+#include "wx/grid.h"
+
 #ifndef WX_PRECOMP
     #include "wx/utils.h"
     #include "wx/dcclient.h"
 #include "wx/tokenzr.h"
 #include "wx/renderer.h"
 
-#include "wx/grid.h"
 #include "wx/generic/gridsel.h"
 
+const wxChar wxGridNameStr[] = wxT("grid");
+
 #if defined(__WXMOTIF__)
     #define WXUNUSED_MOTIF(identifier)  WXUNUSED(identifier)
 #else
@@ -1230,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)
@@ -1335,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);
@@ -1355,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;
@@ -1413,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
@@ -2214,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 )
@@ -2289,6 +2319,7 @@ wxGridCellAttr *wxGridCellAttr::Clone() const
     if ( IsReadOnly() )
         attr->SetReadOnly();
 
+    attr->SetOverflow( m_overflow == Overflow );
     attr->SetKind( m_attrkind );
 
     return attr;
@@ -3878,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 );
@@ -4131,7 +4163,7 @@ wxGrid::wxGrid( wxWindow *parent,
     m_rowMinHeights(GRID_HASH_SIZE)
 {
     Create();
-    SetBestFittingSize(size);
+    SetInitialSize(size);
 }
 
 bool wxGrid::Create(wxWindow *parent, wxWindowID id,
@@ -4146,7 +4178,7 @@ bool wxGrid::Create(wxWindow *parent, wxWindowID id,
     m_rowMinHeights = wxLongToLongHashMap(GRID_HASH_SIZE);
 
     Create();
-    SetBestFittingSize(size);
+    SetInitialSize(size);
 
     return true;
 }
@@ -7794,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 );
@@ -7856,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 );
@@ -10384,12 +10418,12 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column )
 
     if ( column )
     {
-        dc.GetTextExtent( GetColLabelValue(col), &w, &h );
+        dc.GetMultiLineTextExtent( GetColLabelValue(col), &w, &h );
         if ( GetColLabelTextOrientation() == wxVERTICAL )
             w = h;
     }
     else
-        dc.GetTextExtent( GetRowLabelValue(row), &w, &h );
+        dc.GetMultiLineTextExtent( GetRowLabelValue(row), &w, &h );
 
     extent = column ? w : h;
     if ( extent > extentMax )