]> 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 5fcffb809e5681f3bd71cf5019027e27fec2ced7..a2994e167915ceb41b0d8827e908f7bc01a8426c 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;
@@ -3736,7 +3767,8 @@ void wxGridRowLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
 
     int x, y;
     m_owner->CalcUnscrolledPosition( 0, 0, &x, &y );
-    dc.SetDeviceOrigin( 0, -y );
+    wxPoint pt = dc.GetDeviceOrigin();
+    dc.SetDeviceOrigin( pt.x, pt.y-y );
 
     wxArrayInt rows = m_owner->CalcRowLabelsExposed( GetUpdateRegion() );
     m_owner->DrawRowLabels( dc, rows );
@@ -3806,7 +3838,11 @@ void wxGridColLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
 
     int x, y;
     m_owner->CalcUnscrolledPosition( 0, 0, &x, &y );
-    dc.SetDeviceOrigin( -x, 0 );
+    wxPoint pt = dc.GetDeviceOrigin();
+    if (GetLayoutDirection() == wxLayout_RightToLeft)
+        dc.SetDeviceOrigin( pt.x+x, pt.y );
+    else
+        dc.SetDeviceOrigin( pt.x-x, pt.y );
 
     wxArrayInt cols = m_owner->CalcColLabelsExposed( GetUpdateRegion() );
     m_owner->DrawColLabels( dc, cols );
@@ -3873,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 );
@@ -6826,6 +6863,14 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
 
     if ( !parent->GetEventHandler()->ProcessEvent( keyEvt ) )
     {
+        if (GetLayoutDirection() == wxLayout_RightToLeft)
+        {
+            if (event.GetKeyCode() == WXK_RIGHT)
+                event.m_keyCode = WXK_LEFT;
+            else if (event.GetKeyCode() == WXK_LEFT)
+                event.m_keyCode = WXK_RIGHT;
+        }
+    
         // try local handlers
         switch ( event.GetKeyCode() )
         {
@@ -7739,7 +7784,12 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) )
     {
         i = GetColAt( colPos );
 
-        int colRight = GetColRight(i) - 1;
+        int colRight = GetColRight(i);
+#ifdef __WXGTK__
+        if (GetLayoutDirection() != wxLayout_RightToLeft)
+#endif
+            colRight--;
+
         if ( colRight > right )
         {
             break;
@@ -7776,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 );
@@ -7838,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 );
@@ -10366,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 )