- else
- {
- // restore the standard colours fonts
- if ( m_colFgOld.Ok() )
- {
- m_control->SetForegroundColour(m_colFgOld);
- m_colFgOld = wxNullColour;
- }
-
- if ( m_colBgOld.Ok() )
- {
- m_control->SetBackgroundColour(m_colBgOld);
- m_colBgOld = wxNullColour;
- }
-
-// Workaround for GTK+1 font setting problem on some platforms
-#if !defined(__WXGTK__) || defined(__WXGTK20__)
- if ( m_fontOld.Ok() )
- {
- m_control->SetFont(m_fontOld);
- m_fontOld = wxNullFont;
- }
-#endif
- }
-}
-
-void wxGridCellEditor::SetSize(const wxRect& rect)
-{
- wxASSERT_MSG(m_control, wxT("The wxGridCellEditor must be created first!"));
-
- m_control->SetSize(rect, wxSIZE_ALLOW_MINUS_ONE);
-}
-
-void wxGridCellEditor::HandleReturn(wxKeyEvent& event)
-{
- event.Skip();
-}
-
-bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event)
-{
- bool ctrl = event.ControlDown();
- bool alt = event.AltDown();
-
-#ifdef __WXMAC__
- // On the Mac the Alt key is more like shift and is used for entry of
- // valid characters, so check for Ctrl and Meta instead.
- alt = event.MetaDown();
-#endif
-
- // Assume it's not a valid char if ctrl or alt is down, but if both are
- // down then it may be because of an AltGr key combination, so let them
- // through in that case.
- if ((ctrl || alt) && !(ctrl && alt))
- return false;
-
- int key = 0;
- bool keyOk = true;
-
-#ifdef __WXGTK20__
- // If it's a F-Key or other special key then it shouldn't start the
- // editor.
- if (event.GetKeyCode() >= WXK_START)
- return false;
-#endif
-#if wxUSE_UNICODE
- // if the unicode key code is not really a unicode character (it may
- // be a function key or etc., the platforms appear to always give us a
- // small value in this case) then fallback to the ASCII key code but
- // don't do anything for function keys or etc.
- key = event.GetUnicodeKey();
- if (key <= 127)
- {
- key = event.GetKeyCode();
- keyOk = (key <= 127);
- }
-#else
- key = event.GetKeyCode();
- keyOk = (key <= 255);
-#endif
-
- return keyOk;
-}
-
-void wxGridCellEditor::StartingKey(wxKeyEvent& event)
-{
- event.Skip();
-}
-
-void wxGridCellEditor::StartingClick()
-{
-}
-
-#if wxUSE_TEXTCTRL
-
-// ----------------------------------------------------------------------------
-// wxGridCellTextEditor
-// ----------------------------------------------------------------------------
-
-wxGridCellTextEditor::wxGridCellTextEditor()
-{
- m_maxChars = 0;
-}
-
-void wxGridCellTextEditor::Create(wxWindow* parent,
- wxWindowID id,
- wxEvtHandler* evtHandler)
-{
- DoCreate(parent, id, evtHandler);
-}
-
-void wxGridCellTextEditor::DoCreate(wxWindow* parent,
- wxWindowID id,
- wxEvtHandler* evtHandler,
- long style)
-{
- style |= wxTE_PROCESS_ENTER |
- wxTE_PROCESS_TAB |
- wxTE_AUTO_SCROLL |
- wxNO_BORDER;
-
- m_control = new wxTextCtrl(parent, id, wxEmptyString,
- wxDefaultPosition, wxDefaultSize,
- style);
-
- // set max length allowed in the textctrl, if the parameter was set
- if ( m_maxChars != 0 )
- {
- Text()->SetMaxLength(m_maxChars);
- }
-
- wxGridCellEditor::Create(parent, id, evtHandler);
-}
-
-void wxGridCellTextEditor::PaintBackground(const wxRect& WXUNUSED(rectCell),
- wxGridCellAttr * WXUNUSED(attr))
-{
- // as we fill the entire client area,
- // don't do anything here to minimize flicker
-}
-
-void wxGridCellTextEditor::SetSize(const wxRect& rectOrig)
-{
- wxRect rect(rectOrig);
-
- // Make the edit control large enough to allow for internal margins
- //
- // TODO: remove this if the text ctrl sizing is improved esp. for unix
- //
-#if defined(__WXGTK__)
- if (rect.x != 0)
- {
- rect.x += 1;
- rect.y += 1;
- rect.width -= 1;
- rect.height -= 1;
- }
-#elif defined(__WXMSW__)
- if ( rect.x == 0 )
- rect.x += 2;
- else
- rect.x += 3;
-
- if ( rect.y == 0 )
- rect.y += 2;
- else
- rect.y += 3;
-
- rect.width -= 2;
- rect.height -= 2;
-#else
- int extra_x = ( rect.x > 2 ) ? 2 : 1;
- int extra_y = ( rect.y > 2 ) ? 2 : 1;
-
- #if defined(__WXMOTIF__)
- extra_x *= 2;
- extra_y *= 2;
- #endif
-
- rect.SetLeft( wxMax(0, rect.x - extra_x) );
- rect.SetTop( wxMax(0, rect.y - extra_y) );
- rect.SetRight( rect.GetRight() + 2 * extra_x );
- rect.SetBottom( rect.GetBottom() + 2 * extra_y );
-#endif
-
- wxGridCellEditor::SetSize(rect);
-}
-
-void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid)
-{
- wxASSERT_MSG(m_control, wxT("The wxGridCellEditor must be created first!"));
-
- m_startValue = grid->GetTable()->GetValue(row, col);
-
- DoBeginEdit(m_startValue);
-}
-
-void wxGridCellTextEditor::DoBeginEdit(const wxString& startValue)
-{
- Text()->SetValue(startValue);
- Text()->SetInsertionPointEnd();
- Text()->SetSelection(-1, -1);
- Text()->SetFocus();
-}
-
-bool wxGridCellTextEditor::EndEdit(int row, int col, wxGrid* grid)
-{
- wxASSERT_MSG(m_control, wxT("The wxGridCellEditor must be created first!"));
-
- bool changed = false;
- wxString value = Text()->GetValue();
- if (value != m_startValue)
- changed = true;
-
- if (changed)
- grid->GetTable()->SetValue(row, col, value);
-
- m_startValue = wxEmptyString;
-
- // No point in setting the text of the hidden control
- //Text()->SetValue(m_startValue);
-
- return changed;
-}
-
-void wxGridCellTextEditor::Reset()
-{
- wxASSERT_MSG(m_control, wxT("The wxGridCellEditor must be created first!"));
-
- DoReset(m_startValue);
-}
-
-void wxGridCellTextEditor::DoReset(const wxString& startValue)
-{
- Text()->SetValue(startValue);
- Text()->SetInsertionPointEnd();
-}
-
-bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event)
-{
- return wxGridCellEditor::IsAcceptedKey(event);
-}
-
-void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
-{
- // Since this is now happening in the EVT_CHAR event EmulateKeyPress is no
- // longer an appropriate way to get the character into the text control.
- // Do it ourselves instead. We know that if we get this far that we have
- // a valid character, so not a whole lot of testing needs to be done.
-
- wxTextCtrl* tc = Text();
- wxChar ch;
- long pos;
-
-#if wxUSE_UNICODE
- ch = event.GetUnicodeKey();
- if (ch <= 127)
- ch = (wxChar)event.GetKeyCode();
-#else
- ch = (wxChar)event.GetKeyCode();
-#endif
-
- switch (ch)
- {
- case WXK_DELETE:
- // delete the character at the cursor
- pos = tc->GetInsertionPoint();
- if (pos < tc->GetLastPosition())
- tc->Remove(pos, pos + 1);
- break;
-
- case WXK_BACK:
- // delete the character before the cursor
- pos = tc->GetInsertionPoint();
- if (pos > 0)
- tc->Remove(pos - 1, pos);
- break;
-
- default:
- tc->WriteText(ch);
- break;
- }
-}
-
-void wxGridCellTextEditor::HandleReturn( wxKeyEvent&
- WXUNUSED_GTK(WXUNUSED_MOTIF(event)) )
-{
-#if defined(__WXMOTIF__) || defined(__WXGTK__)
- // wxMotif needs a little extra help...
- size_t pos = (size_t)( Text()->GetInsertionPoint() );
- wxString s( Text()->GetValue() );
- s = s.Left(pos) + wxT("\n") + s.Mid(pos);
- Text()->SetValue(s);
- Text()->SetInsertionPoint( pos );
-#else
- // the other ports can handle a Return key press
- //
- event.Skip();
-#endif
-}
-
-void wxGridCellTextEditor::SetParameters(const wxString& params)
-{
- if ( !params )
- {
- // reset to default
- m_maxChars = 0;
- }
- else
- {
- long tmp;
- if ( params.ToLong(&tmp) )
- {
- m_maxChars = (size_t)tmp;
- }
- else
- {
- wxLogDebug( _T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params.c_str() );
- }
- }
-}
-
-// return the value in the text control
-wxString wxGridCellTextEditor::GetValue() const
-{
- return Text()->GetValue();
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellNumberEditor
-// ----------------------------------------------------------------------------
-
-wxGridCellNumberEditor::wxGridCellNumberEditor(int min, int max)
-{
- m_min = min;
- m_max = max;
-}
-
-void wxGridCellNumberEditor::Create(wxWindow* parent,
- wxWindowID id,
- wxEvtHandler* evtHandler)
-{
-#if wxUSE_SPINCTRL
- if ( HasRange() )
- {
- // create a spin ctrl
- m_control = new wxSpinCtrl(parent, wxID_ANY, wxEmptyString,
- wxDefaultPosition, wxDefaultSize,
- wxSP_ARROW_KEYS,
- m_min, m_max);
-
- wxGridCellEditor::Create(parent, id, evtHandler);
- }
- else
-#endif
- {
- // just a text control
- wxGridCellTextEditor::Create(parent, id, evtHandler);
-
-#if wxUSE_VALIDATORS
- Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
-#endif
- }
-}
-
-void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid)
-{
- // first get the value
- wxGridTableBase *table = grid->GetTable();
- if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
- {
- m_valueOld = table->GetValueAsLong(row, col);
- }
- else
- {
- m_valueOld = 0;
- wxString sValue = table->GetValue(row, col);
- if (! sValue.ToLong(&m_valueOld) && ! sValue.empty())
- {
- wxFAIL_MSG( _T("this cell doesn't have numeric value") );
- return;
- }
- }
-
-#if wxUSE_SPINCTRL
- if ( HasRange() )
- {
- Spin()->SetValue((int)m_valueOld);
- Spin()->SetFocus();
- }
- else
-#endif
- {
- DoBeginEdit(GetString());
- }
-}
-
-bool wxGridCellNumberEditor::EndEdit(int row, int col,
- wxGrid* grid)
-{
- bool changed;
- long value = 0;
- wxString text;
-
-#if wxUSE_SPINCTRL
- if ( HasRange() )
- {
- value = Spin()->GetValue();
- changed = value != m_valueOld;
- if (changed)
- text = wxString::Format(wxT("%ld"), value);
- }
- else
-#endif
- {
- text = Text()->GetValue();
- changed = (text.empty() || text.ToLong(&value)) && (value != m_valueOld);
- }
-
- if ( changed )
- {
- if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER))
- grid->GetTable()->SetValueAsLong(row, col, value);
- else
- grid->GetTable()->SetValue(row, col, text);
- }
-
- return changed;
-}
-
-void wxGridCellNumberEditor::Reset()
-{
-#if wxUSE_SPINCTRL
- if ( HasRange() )
- {
- Spin()->SetValue((int)m_valueOld);
- }
- else
-#endif
- {
- DoReset(GetString());
- }
-}
-
-bool wxGridCellNumberEditor::IsAcceptedKey(wxKeyEvent& event)
-{
- if ( wxGridCellEditor::IsAcceptedKey(event) )
- {
- int keycode = event.GetKeyCode();
- if ( (keycode < 128) &&
- (wxIsdigit(keycode) || keycode == '+' || keycode == '-'))
- {
- return true;
- }
- }
-
- return false;
-}
-
-void wxGridCellNumberEditor::StartingKey(wxKeyEvent& event)
-{
- int keycode = event.GetKeyCode();
- if ( !HasRange() )
- {
- if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-')
- {
- wxGridCellTextEditor::StartingKey(event);
-
- // skip Skip() below
- return;
- }
- }
-#if wxUSE_SPINCTRL
- else
- {
- if ( wxIsdigit(keycode) )
- {
- wxSpinCtrl* spin = (wxSpinCtrl*)m_control;
- spin->SetValue(keycode - '0');
- spin->SetSelection(1,1);
- return;
- }
- }
-#endif
-
- event.Skip();
-}
-
-void wxGridCellNumberEditor::SetParameters(const wxString& params)
-{
- if ( !params )
- {
- // reset to default
- m_min =
- m_max = -1;
- }
- else
- {
- long tmp;
- if ( params.BeforeFirst(_T(',')).ToLong(&tmp) )
- {
- m_min = (int)tmp;
-
- if ( params.AfterFirst(_T(',')).ToLong(&tmp) )
- {
- m_max = (int)tmp;
-
- // skip the error message below
- return;
- }
- }
-
- wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string '%s' ignored"), params.c_str());
- }
-}
-
-// return the value in the spin control if it is there (the text control otherwise)
-wxString wxGridCellNumberEditor::GetValue() const
-{
- wxString s;
-
-#if wxUSE_SPINCTRL
- if ( HasRange() )
- {
- long value = Spin()->GetValue();
- s.Printf(wxT("%ld"), value);
- }
- else
-#endif
- {
- s = Text()->GetValue();
- }
-
- return s;
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellFloatEditor
-// ----------------------------------------------------------------------------
-
-wxGridCellFloatEditor::wxGridCellFloatEditor(int width, int precision)
-{
- m_width = width;
- m_precision = precision;
-}
-
-void wxGridCellFloatEditor::Create(wxWindow* parent,
- wxWindowID id,
- wxEvtHandler* evtHandler)
-{
- wxGridCellTextEditor::Create(parent, id, evtHandler);
-
-#if wxUSE_VALIDATORS
- Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
-#endif
-}
-
-void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid)
-{
- // first get the value
- wxGridTableBase *table = grid->GetTable();
- if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) )
- {
- m_valueOld = table->GetValueAsDouble(row, col);
- }
- else
- {
- m_valueOld = 0.0;
- wxString sValue = table->GetValue(row, col);
- if (! sValue.ToDouble(&m_valueOld) && ! sValue.empty())
- {
- wxFAIL_MSG( _T("this cell doesn't have float value") );
- return;
- }
- }
-
- DoBeginEdit(GetString());
-}
-
-bool wxGridCellFloatEditor::EndEdit(int row, int col,
- wxGrid* grid)
-{
- double value = 0.0;
- wxString text(Text()->GetValue());
-
- if ( (text.empty() || text.ToDouble(&value)) &&
- !wxIsSameDouble(value, m_valueOld) )
- {
- if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT))
- grid->GetTable()->SetValueAsDouble(row, col, value);
- else
- grid->GetTable()->SetValue(row, col, text);
-
- return true;
- }
-
- return false;
-}
-
-void wxGridCellFloatEditor::Reset()
-{
- DoReset(GetString());
-}
-
-void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event)
-{
- int keycode = event.GetKeyCode();
- char tmpbuf[2];
- tmpbuf[0] = (char) keycode;
- tmpbuf[1] = '\0';
- wxString strbuf(tmpbuf, *wxConvCurrent);
-
-#if wxUSE_INTL
- bool is_decimal_point = ( strbuf ==
- wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER) );
-#else
- bool is_decimal_point = ( strbuf == _T(".") );
-#endif
-
- if ( wxIsdigit(keycode) || keycode == '+' || keycode == '-'
- || is_decimal_point )
- {
- wxGridCellTextEditor::StartingKey(event);
-
- // skip Skip() below
- return;
- }
-
- event.Skip();
-}
-
-void wxGridCellFloatEditor::SetParameters(const wxString& params)
-{
- if ( !params )
- {
- // reset to default
- m_width =
- m_precision = -1;
- }
- else
- {
- long tmp;
- if ( params.BeforeFirst(_T(',')).ToLong(&tmp) )
- {
- m_width = (int)tmp;
-
- if ( params.AfterFirst(_T(',')).ToLong(&tmp) )
- {
- m_precision = (int)tmp;
-
- // skip the error message below
- return;
- }
- }
-
- wxLogDebug(_T("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params.c_str());
- }
-}
-
-wxString wxGridCellFloatEditor::GetString() const
-{
- wxString fmt;
- if ( m_precision == -1 && m_width != -1)
- {
- // default precision
- fmt.Printf(_T("%%%d.f"), m_width);
- }
- else if ( m_precision != -1 && m_width == -1)
- {
- // default width
- fmt.Printf(_T("%%.%df"), m_precision);
- }
- else if ( m_precision != -1 && m_width != -1 )
- {
- fmt.Printf(_T("%%%d.%df"), m_width, m_precision);
- }
- else
- {
- // default width/precision
- fmt = _T("%f");
- }
-
- return wxString::Format(fmt, m_valueOld);
-}
-
-bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event)
-{
- if ( wxGridCellEditor::IsAcceptedKey(event) )
- {
- const int keycode = event.GetKeyCode();
- if ( isascii(keycode) )
- {
- char tmpbuf[2];
- tmpbuf[0] = (char) keycode;
- tmpbuf[1] = '\0';
- wxString strbuf(tmpbuf, *wxConvCurrent);
-
-#if wxUSE_INTL
- const wxString decimalPoint =
- wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER);
-#else
- const wxString decimalPoint(_T('.'));
-#endif
-
- // accept digits, 'e' as in '1e+6', also '-', '+', and '.'
- if ( wxIsdigit(keycode) ||
- tolower(keycode) == 'e' ||
- keycode == decimalPoint ||
- keycode == '+' ||
- keycode == '-' )
- {
- return true;
- }
- }
- }
-
- return false;
-}
-
-#endif // wxUSE_TEXTCTRL
-
-#if wxUSE_CHECKBOX
-
-// ----------------------------------------------------------------------------
-// wxGridCellBoolEditor
-// ----------------------------------------------------------------------------
-
-// the default values for GetValue()
-wxString wxGridCellBoolEditor::ms_stringValues[2] = { _T(""), _T("1") };
-
-void wxGridCellBoolEditor::Create(wxWindow* parent,
- wxWindowID id,
- wxEvtHandler* evtHandler)
-{
- m_control = new wxCheckBox(parent, id, wxEmptyString,
- wxDefaultPosition, wxDefaultSize,
- wxNO_BORDER);
-
- wxGridCellEditor::Create(parent, id, evtHandler);
-}
-
-void wxGridCellBoolEditor::SetSize(const wxRect& r)
-{
- bool resize = false;
- wxSize size = m_control->GetSize();
- wxCoord minSize = wxMin(r.width, r.height);
-
- // check if the checkbox is not too big/small for this cell
- wxSize sizeBest = m_control->GetBestSize();
- if ( !(size == sizeBest) )
- {
- // reset to default size if it had been made smaller
- size = sizeBest;
-
- resize = true;
- }
-
- if ( size.x >= minSize || size.y >= minSize )
- {
- // leave 1 pixel margin
- size.x = size.y = minSize - 2;
-
- resize = true;
- }
-
- if ( resize )
- {
- m_control->SetSize(size);
- }
-
- // position it in the centre of the rectangle (TODO: support alignment?)
-
-#if defined(__WXGTK__) || defined (__WXMOTIF__)
- // the checkbox without label still has some space to the right in wxGTK,
- // so shift it to the right
- size.x -= 8;
-#elif defined(__WXMSW__)
- // here too, but in other way
- size.x += 1;
- size.y -= 2;
-#endif
-
- int hAlign = wxALIGN_CENTRE;
- int vAlign = wxALIGN_CENTRE;
- if (GetCellAttr())
- GetCellAttr()->GetAlignment(& hAlign, & vAlign);
-
- int x = 0, y = 0;
- if (hAlign == wxALIGN_LEFT)
- {
- x = r.x + 2;
-
-#ifdef __WXMSW__
- x += 2;
-#endif
-
- y = r.y + r.height / 2 - size.y / 2;
- }
- else if (hAlign == wxALIGN_RIGHT)
- {
- x = r.x + r.width - size.x - 2;
- y = r.y + r.height / 2 - size.y / 2;
- }
- else if (hAlign == wxALIGN_CENTRE)
- {
- x = r.x + r.width / 2 - size.x / 2;
- y = r.y + r.height / 2 - size.y / 2;
- }
-
- m_control->Move(x, y);
-}
-
-void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr)
-{
- m_control->Show(show);
-
- if ( show )
- {
- wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY;
- CBox()->SetBackgroundColour(colBg);
- }
-}
-
-void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid)
-{
- wxASSERT_MSG(m_control,
- wxT("The wxGridCellEditor must be created first!"));
-
- if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL))
- {
- m_startValue = grid->GetTable()->GetValueAsBool(row, col);
- }
- else
- {
- wxString cellval( grid->GetTable()->GetValue(row, col) );
-
- 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);
- CBox()->SetFocus();
-}
-
-bool wxGridCellBoolEditor::EndEdit(int row, int col,
- wxGrid* grid)
-{
- wxASSERT_MSG(m_control,
- wxT("The wxGridCellEditor must be created first!"));
-
- bool changed = false;
- bool value = CBox()->GetValue();
- if ( value != m_startValue )
- changed = true;
-
- if ( changed )
- {
- wxGridTableBase * const table = grid->GetTable();
- if ( table->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) )
- table->SetValueAsBool(row, col, value);
- else
- table->SetValue(row, col, GetValue());
- }
-
- return changed;
-}
-
-void wxGridCellBoolEditor::Reset()
-{
- wxASSERT_MSG(m_control,
- wxT("The wxGridCellEditor must be created first!"));
-
- CBox()->SetValue(m_startValue);
-}
-
-void wxGridCellBoolEditor::StartingClick()
-{
- CBox()->SetValue(!CBox()->GetValue());
-}
-
-bool wxGridCellBoolEditor::IsAcceptedKey(wxKeyEvent& event)
-{
- if ( wxGridCellEditor::IsAcceptedKey(event) )
- {
- int keycode = event.GetKeyCode();
- switch ( keycode )
- {
- case WXK_SPACE:
- case '+':
- case '-':
- return true;
- }
- }
-
- return false;
-}
-
-void wxGridCellBoolEditor::StartingKey(wxKeyEvent& event)
-{
- int keycode = event.GetKeyCode();
- switch ( keycode )
- {
- case WXK_SPACE:
- CBox()->SetValue(!CBox()->GetValue());
- break;
-
- case '+':
- CBox()->SetValue(true);
- break;
-
- case '-':
- CBox()->SetValue(false);
- break;
- }
-}
-
-wxString wxGridCellBoolEditor::GetValue() const
-{
- 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
-
-#if wxUSE_COMBOBOX
-
-// ----------------------------------------------------------------------------
-// wxGridCellChoiceEditor
-// ----------------------------------------------------------------------------
-
-wxGridCellChoiceEditor::wxGridCellChoiceEditor(const wxArrayString& choices,
- bool allowOthers)
- : m_choices(choices),
- m_allowOthers(allowOthers) { }
-
-wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count,
- const wxString choices[],
- bool allowOthers)
- : m_allowOthers(allowOthers)
-{
- if ( count )
- {
- m_choices.Alloc(count);
- for ( size_t n = 0; n < count; n++ )
- {
- m_choices.Add(choices[n]);
- }
- }
-}
-
-wxGridCellEditor *wxGridCellChoiceEditor::Clone() const
-{
- wxGridCellChoiceEditor *editor = new wxGridCellChoiceEditor;
- editor->m_allowOthers = m_allowOthers;
- editor->m_choices = m_choices;
-
- return editor;
-}
-
-void wxGridCellChoiceEditor::Create(wxWindow* parent,
- wxWindowID id,
- wxEvtHandler* evtHandler)
-{
- int style = wxTE_PROCESS_ENTER |
- wxTE_PROCESS_TAB |
- wxBORDER_NONE;
-
- if ( !m_allowOthers )
- style |= wxCB_READONLY;
- m_control = new wxComboBox(parent, id, wxEmptyString,
- wxDefaultPosition, wxDefaultSize,
- m_choices,
- style);
-
- wxGridCellEditor::Create(parent, id, evtHandler);
-}
-
-void wxGridCellChoiceEditor::PaintBackground(const wxRect& rectCell,
- wxGridCellAttr * attr)
-{
- // as we fill the entire client area, don't do anything here to minimize
- // flicker
-
- // TODO: It doesn't actually fill the client area since the height of a
- // combo always defaults to the standard. Until someone has time to
- // figure out the right rectangle to paint, just do it the normal way.
- wxGridCellEditor::PaintBackground(rectCell, attr);
-}
-
-void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
-{
- wxASSERT_MSG(m_control,
- wxT("The wxGridCellEditor must be created first!"));
-
- wxGridCellEditorEvtHandler* evtHandler = NULL;
- if (m_control)
- evtHandler = wxDynamicCast(m_control->GetEventHandler(), wxGridCellEditorEvtHandler);
-
- // Don't immediately end if we get a kill focus event within BeginEdit
- if (evtHandler)
- evtHandler->SetInSetFocus(true);
-
- m_startValue = grid->GetTable()->GetValue(row, col);
-
- if (m_allowOthers)
- {
- Combo()->SetValue(m_startValue);
- Combo()->SetInsertionPointEnd();
- }
- else // the combobox is read-only
- {
- // find the right position, or default to the first if not found
- int pos = Combo()->FindString(m_startValue);
- if (pos == wxNOT_FOUND)
- pos = 0;
- Combo()->SetSelection(pos);
- }
-
- Combo()->SetFocus();
-
- if (evtHandler)
- {
- // When dropping down the menu, a kill focus event
- // happens after this point, so we can't reset the flag yet.
-#if !defined(__WXGTK20__)
- evtHandler->SetInSetFocus(false);
-#endif
- }
-}
-
-bool wxGridCellChoiceEditor::EndEdit(int row, int col,
- wxGrid* grid)
-{
- wxString value = Combo()->GetValue();
- if ( value == m_startValue )
- return false;
-
- grid->GetTable()->SetValue(row, col, value);
-
- return true;
-}
-
-void wxGridCellChoiceEditor::Reset()
-{
- Combo()->SetValue(m_startValue);
- Combo()->SetInsertionPointEnd();
-}
-
-void wxGridCellChoiceEditor::SetParameters(const wxString& params)
-{
- if ( !params )
- {
- // what can we do?
- return;
- }
-
- m_choices.Empty();
-
- wxStringTokenizer tk(params, _T(','));
- while ( tk.HasMoreTokens() )
- {
- m_choices.Add(tk.GetNextToken());
- }
-}
-
-// return the value in the text control
-wxString wxGridCellChoiceEditor::GetValue() const
-{
- return Combo()->GetValue();
-}
-
-#endif // wxUSE_COMBOBOX
-
-// ----------------------------------------------------------------------------
-// wxGridCellEditorEvtHandler
-// ----------------------------------------------------------------------------
-
-void wxGridCellEditorEvtHandler::OnKillFocus(wxFocusEvent& event)
-{
- // Don't disable the cell if we're just starting to edit it
- if (m_inSetFocus)
- return;
-
- // accept changes
- m_grid->DisableCellEditControl();
-
- event.Skip();
-}
-
-void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event)
-{
- switch ( event.GetKeyCode() )
- {
- case WXK_ESCAPE:
- m_editor->Reset();
- m_grid->DisableCellEditControl();
- break;
-
- case WXK_TAB:
- m_grid->GetEventHandler()->ProcessEvent( event );
- break;
-
- case WXK_RETURN:
- case WXK_NUMPAD_ENTER:
- if (!m_grid->GetEventHandler()->ProcessEvent(event))
- m_editor->HandleReturn(event);
- break;
-
- default:
- event.Skip();
- break;
- }
-}
-
-void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event)
-{
- int row = m_grid->GetGridCursorRow();
- int col = m_grid->GetGridCursorCol();
- wxRect rect = m_grid->CellToRect( row, col );
- int cw, ch;
- m_grid->GetGridWindow()->GetClientSize( &cw, &ch );
-
- // if cell width is smaller than grid client area, cell is wholly visible
- bool wholeCellVisible = (rect.GetWidth() < cw);
-
- switch ( event.GetKeyCode() )
- {
- case WXK_ESCAPE:
- case WXK_TAB:
- case WXK_RETURN:
- case WXK_NUMPAD_ENTER:
- break;
-
- case WXK_HOME:
- {
- if ( wholeCellVisible )
- {
- // no special processing needed...
- event.Skip();
- break;
- }
-
- // do special processing for partly visible cell...
-
- // get the widths of all cells previous to this one
- int colXPos = 0;
- for ( int i = 0; i < col; i++ )
- {
- colXPos += m_grid->GetColSize(i);
- }
-
- int xUnit = 1, yUnit = 1;
- m_grid->GetScrollPixelsPerUnit(&xUnit, &yUnit);
- if (col != 0)
- {
- m_grid->Scroll(colXPos / xUnit - 1, m_grid->GetScrollPos(wxVERTICAL));
- }
- else
- {
- m_grid->Scroll(colXPos / xUnit, m_grid->GetScrollPos(wxVERTICAL));
- }
- event.Skip();
- break;
- }
-
- case WXK_END:
- {
- if ( wholeCellVisible )
- {
- // no special processing needed...
- event.Skip();
- break;
- }
-
- // do special processing for partly visible cell...
-
- int textWidth = 0;
- wxString value = m_grid->GetCellValue(row, col);
- if ( wxEmptyString != value )
- {
- // get width of cell CONTENTS (text)
- int y;
- wxFont font = m_grid->GetCellFont(row, col);
- m_grid->GetTextExtent(value, &textWidth, &y, NULL, NULL, &font);
-
- // try to RIGHT align the text by scrolling
- int client_right = m_grid->GetGridWindow()->GetClientSize().GetWidth();
-
- // (m_grid->GetScrollLineX()*2) is a factor for not scrolling to far,
- // otherwise the last part of the cell content might be hidden below the scroll bar
- // FIXME: maybe there is a more suitable correction?
- textWidth -= (client_right - (m_grid->GetScrollLineX() * 2));
- if ( textWidth < 0 )
- {
- textWidth = 0;
- }
- }
-
- // get the widths of all cells previous to this one
- int colXPos = 0;
- for ( int i = 0; i < col; i++ )
- {
- colXPos += m_grid->GetColSize(i);
- }
-
- // and add the (modified) text width of the cell contents
- // as we'd like to see the last part of the cell contents
- colXPos += textWidth;
-
- int xUnit = 1, yUnit = 1;
- m_grid->GetScrollPixelsPerUnit(&xUnit, &yUnit);
- m_grid->Scroll(colXPos / xUnit - 1, m_grid->GetScrollPos(wxVERTICAL));
- event.Skip();
- break;
- }
-
- default:
- event.Skip();
- break;
- }
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellWorker is an (almost) empty common base class for
-// wxGridCellRenderer and wxGridCellEditor managing ref counting
-// ----------------------------------------------------------------------------
-
-void wxGridCellWorker::SetParameters(const wxString& WXUNUSED(params))
-{
- // nothing to do
-}
-
-wxGridCellWorker::~wxGridCellWorker()
-{
-}
-
-// ============================================================================
-// renderer classes
-// ============================================================================
-
-// ----------------------------------------------------------------------------
-// wxGridCellRenderer
-// ----------------------------------------------------------------------------
-
-void wxGridCellRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rect,
- int WXUNUSED(row), int WXUNUSED(col),
- bool isSelected)
-{
- dc.SetBackgroundMode( wxBRUSHSTYLE_SOLID );
-
- // grey out fields if the grid is disabled
- if ( grid.IsEnabled() )
- {
- if ( isSelected )
- {
- wxColour clr;
- if ( grid.HasFocus() )
- clr = grid.GetSelectionBackground();
- else
- clr = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW);
- dc.SetBrush( wxBrush(clr, wxBRUSHSTYLE_SOLID) );
- }
- else
- {
- dc.SetBrush( wxBrush(attr.GetBackgroundColour(), wxBRUSHSTYLE_SOLID) );
- }
- }
- else
- {
- dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE), wxBRUSHSTYLE_SOLID));
- }
-
- dc.SetPen( *wxTRANSPARENT_PEN );
- dc.DrawRectangle(rect);
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellStringRenderer
-// ----------------------------------------------------------------------------
-
-void wxGridCellStringRenderer::SetTextColoursAndFont(const wxGrid& grid,
- const wxGridCellAttr& attr,
- wxDC& dc,
- bool isSelected)
-{
- dc.SetBackgroundMode( wxBRUSHSTYLE_TRANSPARENT );
-
- // TODO some special colours for attr.IsReadOnly() case?
-
- // different coloured text when the grid is disabled
- if ( grid.IsEnabled() )
- {
- if ( isSelected )
- {
- wxColour clr;
- if ( grid.HasFocus() )
- clr = grid.GetSelectionBackground();
- else
- clr = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW);
- dc.SetTextBackground( clr );
- dc.SetTextForeground( grid.GetSelectionForeground() );
- }
- else
- {
- dc.SetTextBackground( attr.GetBackgroundColour() );
- dc.SetTextForeground( attr.GetTextColour() );
- }
- }
- else
- {
- dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
- dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
- }
-
- dc.SetFont( attr.GetFont() );
-}
-
-wxSize wxGridCellStringRenderer::DoGetBestSize(const wxGridCellAttr& attr,
- wxDC& dc,
- const wxString& text)
-{
- wxCoord x = 0, y = 0, max_x = 0;
- dc.SetFont(attr.GetFont());
- wxStringTokenizer tk(text, _T('\n'));
- while ( tk.HasMoreTokens() )
- {
- dc.GetTextExtent(tk.GetNextToken(), &x, &y);
- max_x = wxMax(max_x, x);
- }
-
- y *= 1 + text.Freq(wxT('\n')); // multiply by the number of lines.
-
- return wxSize(max_x, y);
-}
-
-wxSize wxGridCellStringRenderer::GetBestSize(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- int row, int col)
-{
- return DoGetBestSize(attr, dc, grid.GetCellValue(row, col));
-}
-
-void wxGridCellStringRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rectCell,
- int row, int col,
- bool isSelected)
-{
- wxRect rect = rectCell;
- rect.Inflate(-1);
-
- // erase only this cells background, overflow cells should have been erased
- wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
-
- int hAlign, vAlign;
- attr.GetAlignment(&hAlign, &vAlign);
-
- int overflowCols = 0;
-
- if (attr.GetOverflow())
- {
- int cols = grid.GetNumberCols();
- int best_width = GetBestSize(grid,attr,dc,row,col).GetWidth();
- int cell_rows, cell_cols;
- attr.GetSize( &cell_rows, &cell_cols ); // shouldn't get here if <= 0
- if ((best_width > rectCell.width) && (col < cols) && grid.GetTable())
- {
- int i, c_cols, c_rows;
- for (i = col+cell_cols; i < cols; i++)
- {
- bool is_empty = true;
- for (int j=row; j < row + cell_rows; j++)
- {
- // check w/ anchor cell for multicell block
- grid.GetCellSize(j, i, &c_rows, &c_cols);
- if (c_rows > 0)
- c_rows = 0;
- if (!grid.GetTable()->IsEmptyCell(j + c_rows, i))
- {
- is_empty = false;
- break;
- }
- }
-
- if (is_empty)
- {
- rect.width += grid.GetColSize(i);
- }
- else
- {
- i--;
- break;
- }
-
- if (rect.width >= best_width)
- break;
- }
-
- overflowCols = i - col - cell_cols + 1;
- if (overflowCols >= cols)
- overflowCols = cols - 1;
- }
-
- if (overflowCols > 0) // redraw overflow cells w/ proper hilight
- {
- hAlign = wxALIGN_LEFT; // if oveflowed then it's left aligned
- wxRect clip = rect;
- clip.x += rectCell.width;
- // draw each overflow cell individually
- int col_end = col + cell_cols + overflowCols;
- if (col_end >= grid.GetNumberCols())
- col_end = grid.GetNumberCols() - 1;
- for (int i = col + cell_cols; i <= col_end; i++)
- {
- clip.width = grid.GetColSize(i) - 1;
- dc.DestroyClippingRegion();
- dc.SetClippingRegion(clip);
-
- SetTextColoursAndFont(grid, attr, dc,
- grid.IsInSelection(row,i));
-
- grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
- rect, hAlign, vAlign);
- clip.x += grid.GetColSize(i) - 1;
- }
-
- rect = rectCell;
- rect.Inflate(-1);
- rect.width++;
- dc.DestroyClippingRegion();
- }
- }
-
- // now we only have to draw the text
- SetTextColoursAndFont(grid, attr, dc, isSelected);
-
- grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
- rect, hAlign, vAlign);
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellNumberRenderer
-// ----------------------------------------------------------------------------
-
-wxString wxGridCellNumberRenderer::GetString(const wxGrid& grid, int row, int col)
-{
- wxGridTableBase *table = grid.GetTable();
- wxString text;
- if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
- {
- text.Printf(_T("%ld"), table->GetValueAsLong(row, col));
- }
- else
- {
- text = table->GetValue(row, col);
- }
-
- return text;
-}
-
-void wxGridCellNumberRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rectCell,
- int row, int col,
- bool isSelected)
-{
- wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
-
- SetTextColoursAndFont(grid, attr, dc, isSelected);
-
- // draw the text right aligned by default
- int hAlign, vAlign;
- attr.GetAlignment(&hAlign, &vAlign);
- hAlign = wxALIGN_RIGHT;
-
- wxRect rect = rectCell;
- rect.Inflate(-1);
-
- grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign);
-}
-
-wxSize wxGridCellNumberRenderer::GetBestSize(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- int row, int col)
-{
- return DoGetBestSize(attr, dc, GetString(grid, row, col));
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellFloatRenderer
-// ----------------------------------------------------------------------------
-
-wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width, int precision)
-{
- SetWidth(width);
- SetPrecision(precision);
-}
-
-wxGridCellRenderer *wxGridCellFloatRenderer::Clone() const
-{
- wxGridCellFloatRenderer *renderer = new wxGridCellFloatRenderer;
- renderer->m_width = m_width;
- renderer->m_precision = m_precision;
- renderer->m_format = m_format;
-
- return renderer;
-}
-
-wxString wxGridCellFloatRenderer::GetString(const wxGrid& grid, int row, int col)
-{
- wxGridTableBase *table = grid.GetTable();
-
- bool hasDouble;
- double val;
- wxString text;
- if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) )
- {
- val = table->GetValueAsDouble(row, col);
- hasDouble = true;
- }
- else
- {
- text = table->GetValue(row, col);
- hasDouble = text.ToDouble(&val);
- }
-
- if ( hasDouble )
- {
- if ( !m_format )
- {
- if ( m_width == -1 )
- {
- if ( m_precision == -1 )
- {
- // default width/precision
- m_format = _T("%f");
- }
- else
- {
- m_format.Printf(_T("%%.%df"), m_precision);
- }
- }
- else if ( m_precision == -1 )
- {
- // default precision
- m_format.Printf(_T("%%%d.f"), m_width);
- }
- else
- {
- m_format.Printf(_T("%%%d.%df"), m_width, m_precision);
- }
- }
-
- text.Printf(m_format, val);
-
- }
- //else: text already contains the string
-
- return text;
-}
-
-void wxGridCellFloatRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rectCell,
- int row, int col,
- bool isSelected)
-{
- wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
-
- SetTextColoursAndFont(grid, attr, dc, isSelected);
-
- // draw the text right aligned by default
- int hAlign, vAlign;
- attr.GetAlignment(&hAlign, &vAlign);
- hAlign = wxALIGN_RIGHT;
-
- wxRect rect = rectCell;
- rect.Inflate(-1);
-
- grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign);
-}
-
-wxSize wxGridCellFloatRenderer::GetBestSize(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- int row, int col)
-{
- return DoGetBestSize(attr, dc, GetString(grid, row, col));
-}
-
-void wxGridCellFloatRenderer::SetParameters(const wxString& params)
-{
- if ( !params )
- {
- // reset to defaults
- SetWidth(-1);
- SetPrecision(-1);
- }
- else
- {
- wxString tmp = params.BeforeFirst(_T(','));
- if ( !tmp.empty() )
- {
- long width;
- if ( tmp.ToLong(&width) )
- {
- SetWidth((int)width);
- }
- else
- {
- wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params.c_str());
- }
- }
-
- tmp = params.AfterFirst(_T(','));
- if ( !tmp.empty() )
- {
- long precision;
- if ( tmp.ToLong(&precision) )
- {
- SetPrecision((int)precision);
- }
- else
- {
- wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params.c_str());
- }
- }
- }
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellBoolRenderer
-// ----------------------------------------------------------------------------
-
-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),
- int WXUNUSED(row),
- int WXUNUSED(col))
-{
- // 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;
- }
-
- return ms_sizeCheckMark;
-}
-
-void wxGridCellBoolRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rect,
- int row, int col,
- bool isSelected)
-{
- wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
-
- // draw a check mark in the centre (ignoring alignment - TODO)
- wxSize size = GetBestSize(grid, attr, dc, row, col);
-
- // don't draw outside the cell
- wxCoord minSize = wxMin(rect.width, rect.height);
- if ( size.x >= minSize || size.y >= minSize )
- {
- // and even leave (at least) 1 pixel margin
- size.x = size.y = minSize;
- }
-
- // draw a border around checkmark
- int vAlign, hAlign;
- attr.GetAlignment(&hAlign, &vAlign);
-
- wxRect rectBorder;
- if (hAlign == wxALIGN_CENTRE)
- {
- rectBorder.x = rect.x + rect.width / 2 - size.x / 2;
- rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
- rectBorder.width = size.x;
- rectBorder.height = size.y;
- }
- else if (hAlign == wxALIGN_LEFT)
- {
- rectBorder.x = rect.x + 2;
- rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
- rectBorder.width = size.x;
- rectBorder.height = size.y;
- }
- else if (hAlign == wxALIGN_RIGHT)
- {
- rectBorder.x = rect.x + rect.width - size.x - 2;
- rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
- rectBorder.width = size.x;
- rectBorder.height = size.y;
- }
-
- bool value;
- if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) )
- {
- value = grid.GetTable()->GetValueAsBool(row, col);
- }
- else
- {
- wxString cellval( grid.GetTable()->GetValue(row, col) );
- value = wxGridCellBoolEditor::IsTrueValue(cellval);
- }
-
- int flags = 0;
- if (value)
- flags |= wxCONTROL_CHECKED;
-
- wxRendererNative::Get().DrawCheckBox( &grid, dc, rectBorder, flags );
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellAttr
-// ----------------------------------------------------------------------------
-
-void wxGridCellAttr::Init(wxGridCellAttr *attrDefault)
-{
- m_nRef = 1;
-
- m_isReadOnly = Unset;
-
- m_renderer = NULL;
- m_editor = NULL;
-
- m_attrkind = wxGridCellAttr::Cell;
-
- m_sizeRows = m_sizeCols = 1;
- m_overflow = UnsetOverflow;
-
- SetDefAttr(attrDefault);
-}
-
-wxGridCellAttr *wxGridCellAttr::Clone() const
-{
- wxGridCellAttr *attr = new wxGridCellAttr(m_defGridAttr);
-
- if ( HasTextColour() )
- attr->SetTextColour(GetTextColour());
- if ( HasBackgroundColour() )
- attr->SetBackgroundColour(GetBackgroundColour());
- if ( HasFont() )
- attr->SetFont(GetFont());
- if ( HasAlignment() )
- attr->SetAlignment(m_hAlign, m_vAlign);
-
- attr->SetSize( m_sizeRows, m_sizeCols );
-
- if ( m_renderer )
- {
- attr->SetRenderer(m_renderer);
- m_renderer->IncRef();
- }
- if ( m_editor )
- {
- attr->SetEditor(m_editor);
- m_editor->IncRef();
- }
-
- if ( IsReadOnly() )
- attr->SetReadOnly();
-
- attr->SetOverflow( m_overflow == Overflow );
- attr->SetKind( m_attrkind );
-
- return attr;
-}
-
-void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom)
-{
- if ( !HasTextColour() && mergefrom->HasTextColour() )
- SetTextColour(mergefrom->GetTextColour());
- if ( !HasBackgroundColour() && mergefrom->HasBackgroundColour() )
- SetBackgroundColour(mergefrom->GetBackgroundColour());
- if ( !HasFont() && mergefrom->HasFont() )
- SetFont(mergefrom->GetFont());
- if ( !HasAlignment() && mergefrom->HasAlignment() )
- {
- int hAlign, vAlign;
- mergefrom->GetAlignment( &hAlign, &vAlign);
- SetAlignment(hAlign, vAlign);
- }
- if ( !HasSize() && mergefrom->HasSize() )
- mergefrom->GetSize( &m_sizeRows, &m_sizeCols );
-
- // Directly access member functions as GetRender/Editor don't just return
- // m_renderer/m_editor
- //
- // Maybe add support for merge of Render and Editor?
- if (!HasRenderer() && mergefrom->HasRenderer() )
- {
- m_renderer = mergefrom->m_renderer;
- m_renderer->IncRef();
- }
- if ( !HasEditor() && mergefrom->HasEditor() )
- {
- m_editor = mergefrom->m_editor;
- m_editor->IncRef();
- }
- if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() )
- SetReadOnly(mergefrom->IsReadOnly());
-
- if (!HasOverflowMode() && mergefrom->HasOverflowMode() )
- SetOverflow(mergefrom->GetOverflow());
-
- SetDefAttr(mergefrom->m_defGridAttr);
-}
-
-void wxGridCellAttr::SetSize(int num_rows, int num_cols)
-{
- // The size of a cell is normally 1,1
-
- // If this cell is larger (2,2) then this is the top left cell
- // the other cells that will be covered (lower right cells) must be
- // set to negative or zero values such that
- // row + num_rows of the covered cell points to the larger cell (this cell)
- // same goes for the col + num_cols.
-
- // Size of 0,0 is NOT valid, neither is <=0 and any positive value
-
- wxASSERT_MSG( (!((num_rows > 0) && (num_cols <= 0)) ||
- !((num_rows <= 0) && (num_cols > 0)) ||
- !((num_rows == 0) && (num_cols == 0))),
- wxT("wxGridCellAttr::SetSize only takes two postive values or negative/zero values"));
-
- m_sizeRows = num_rows;
- m_sizeCols = num_cols;
-}
-
-const wxColour& wxGridCellAttr::GetTextColour() const
-{
- if (HasTextColour())
- {
- return m_colText;
- }
- else if (m_defGridAttr && m_defGridAttr != this)
- {
- return m_defGridAttr->GetTextColour();
- }
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- return wxNullColour;
- }
-}
-
-const wxColour& wxGridCellAttr::GetBackgroundColour() const
-{
- if (HasBackgroundColour())
- {
- return m_colBack;
- }
- else if (m_defGridAttr && m_defGridAttr != this)