pass ApplyEdit() arguments to EndEdit() too for better backwards compatibility (closes #10544)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59365 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-03-06 10:38:45 +00:00
parent d35146fa5d
commit 78e7881208
5 changed files with 1900 additions and 1866 deletions

View File

@@ -218,8 +218,10 @@ public:
// new value in its string form in the newval output parameter. // new value in its string form in the newval output parameter.
// //
// This should also store the new value in its real type internally so that // This should also store the new value in its real type internally so that
// it could be used by ApplyEdit(). // it could be used by ApplyEdit() but it must not modify the grid as the
virtual bool EndEdit(const wxString& oldval, wxString *newval) = 0; // change could still be vetoed.
virtual bool EndEdit(int row, int col, const wxGrid *grid,
const wxString& oldval, wxString *newval) = 0;
// Complete the editing of the current cell by storing the value saved by // Complete the editing of the current cell by storing the value saved by
// the previous call to EndEdit() in the grid // the previous call to EndEdit() in the grid

View File

@@ -1,328 +1,335 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: wx/generic/grideditors.h // Name: wx/generic/grideditors.h
// Purpose: wxGridCellEditorEvtHandler and wxGrid editors // Purpose: wxGridCellEditorEvtHandler and wxGrid editors
// Author: Michael Bedward (based on code by Julian Smart, Robin Dunn) // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
// Modified by: Santiago Palacios // Modified by: Santiago Palacios
// Created: 1/08/1999 // Created: 1/08/1999
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Michael Bedward // Copyright: (c) Michael Bedward
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GENERIC_GRID_EDITORS_H_ #ifndef _WX_GENERIC_GRID_EDITORS_H_
#define _WX_GENERIC_GRID_EDITORS_H_ #define _WX_GENERIC_GRID_EDITORS_H_
#include "wx/defs.h" #include "wx/defs.h"
#if wxUSE_GRID #if wxUSE_GRID
class wxGridCellEditorEvtHandler : public wxEvtHandler class wxGridCellEditorEvtHandler : public wxEvtHandler
{ {
public: public:
wxGridCellEditorEvtHandler(wxGrid* grid, wxGridCellEditor* editor) wxGridCellEditorEvtHandler(wxGrid* grid, wxGridCellEditor* editor)
: m_grid(grid), : m_grid(grid),
m_editor(editor), m_editor(editor),
m_inSetFocus(false) m_inSetFocus(false)
{ {
} }
void OnKillFocus(wxFocusEvent& event); void OnKillFocus(wxFocusEvent& event);
void OnKeyDown(wxKeyEvent& event); void OnKeyDown(wxKeyEvent& event);
void OnChar(wxKeyEvent& event); void OnChar(wxKeyEvent& event);
void SetInSetFocus(bool inSetFocus) { m_inSetFocus = inSetFocus; } void SetInSetFocus(bool inSetFocus) { m_inSetFocus = inSetFocus; }
private: private:
wxGrid *m_grid; wxGrid *m_grid;
wxGridCellEditor *m_editor; wxGridCellEditor *m_editor;
// Work around the fact that a focus kill event can be sent to // Work around the fact that a focus kill event can be sent to
// a combobox within a set focus event. // a combobox within a set focus event.
bool m_inSetFocus; bool m_inSetFocus;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler) DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler)
wxDECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler); wxDECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler);
}; };
#if wxUSE_TEXTCTRL #if wxUSE_TEXTCTRL
// the editor for string/text data // the editor for string/text data
class WXDLLIMPEXP_ADV wxGridCellTextEditor : public wxGridCellEditor class WXDLLIMPEXP_ADV wxGridCellTextEditor : public wxGridCellEditor
{ {
public: public:
wxGridCellTextEditor(); wxGridCellTextEditor();
virtual void Create(wxWindow* parent, virtual void Create(wxWindow* parent,
wxWindowID id, wxWindowID id,
wxEvtHandler* evtHandler); wxEvtHandler* evtHandler);
virtual void SetSize(const wxRect& rect); virtual void SetSize(const wxRect& rect);
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
virtual bool IsAcceptedKey(wxKeyEvent& event); virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid); virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(const wxString& oldval, wxString *newval); virtual bool EndEdit(int row, int col, const wxGrid* grid,
virtual void ApplyEdit(int row, int col, wxGrid* grid); const wxString& oldval, wxString *newval);
virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual void Reset();
virtual void StartingKey(wxKeyEvent& event); virtual void Reset();
virtual void HandleReturn(wxKeyEvent& event); virtual void StartingKey(wxKeyEvent& event);
virtual void HandleReturn(wxKeyEvent& event);
// parameters string format is "max_width"
virtual void SetParameters(const wxString& params); // parameters string format is "max_width"
virtual void SetParameters(const wxString& params);
virtual wxGridCellEditor *Clone() const
{ return new wxGridCellTextEditor; } virtual wxGridCellEditor *Clone() const
{ return new wxGridCellTextEditor; }
// added GetValue so we can get the value which is in the control
virtual wxString GetValue() const; // added GetValue so we can get the value which is in the control
virtual wxString GetValue() const;
protected:
wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; } protected:
wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
// parts of our virtual functions reused by the derived classes
void DoCreate(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler, // parts of our virtual functions reused by the derived classes
long style = 0); void DoCreate(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler,
void DoBeginEdit(const wxString& startValue); long style = 0);
void DoReset(const wxString& startValue); void DoBeginEdit(const wxString& startValue);
void DoReset(const wxString& startValue);
private:
size_t m_maxChars; // max number of chars allowed private:
wxString m_value; size_t m_maxChars; // max number of chars allowed
wxString m_value;
wxDECLARE_NO_COPY_CLASS(wxGridCellTextEditor);
}; wxDECLARE_NO_COPY_CLASS(wxGridCellTextEditor);
};
// the editor for numeric (long) data
class WXDLLIMPEXP_ADV wxGridCellNumberEditor : public wxGridCellTextEditor // the editor for numeric (long) data
{ class WXDLLIMPEXP_ADV wxGridCellNumberEditor : public wxGridCellTextEditor
public: {
// allows to specify the range - if min == max == -1, no range checking is public:
// done // allows to specify the range - if min == max == -1, no range checking is
wxGridCellNumberEditor(int min = -1, int max = -1); // done
wxGridCellNumberEditor(int min = -1, int max = -1);
virtual void Create(wxWindow* parent,
wxWindowID id, virtual void Create(wxWindow* parent,
wxEvtHandler* evtHandler); wxWindowID id,
wxEvtHandler* evtHandler);
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid); virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual bool EndEdit(const wxString& oldval, wxString *newval); virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual void ApplyEdit(int row, int col, wxGrid* grid); virtual bool EndEdit(int row, int col, const wxGrid* grid,
const wxString& oldval, wxString *newval);
virtual void Reset(); virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual void StartingKey(wxKeyEvent& event);
virtual void Reset();
// parameters string format is "min,max" virtual void StartingKey(wxKeyEvent& event);
virtual void SetParameters(const wxString& params);
// parameters string format is "min,max"
virtual wxGridCellEditor *Clone() const virtual void SetParameters(const wxString& params);
{ return new wxGridCellNumberEditor(m_min, m_max); }
virtual wxGridCellEditor *Clone() const
// added GetValue so we can get the value which is in the control { return new wxGridCellNumberEditor(m_min, m_max); }
virtual wxString GetValue() const;
// added GetValue so we can get the value which is in the control
protected: virtual wxString GetValue() const;
#if wxUSE_SPINCTRL
wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; } protected:
#endif #if wxUSE_SPINCTRL
wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }
// if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl #endif
bool HasRange() const
{ // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
#if wxUSE_SPINCTRL bool HasRange() const
return m_min != m_max; {
#else #if wxUSE_SPINCTRL
return false; return m_min != m_max;
#endif #else
} return false;
#endif
// string representation of our value }
wxString GetString() const
{ return wxString::Format(_T("%ld"), m_value); } // string representation of our value
wxString GetString() const
private: { return wxString::Format(_T("%ld"), m_value); }
int m_min,
m_max; private:
int m_min,
long m_value; m_max;
wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor); long m_value;
};
wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor);
// the editor for floating point numbers (double) data };
class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor
{ // the editor for floating point numbers (double) data
public: class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor
wxGridCellFloatEditor(int width = -1, int precision = -1); {
public:
virtual void Create(wxWindow* parent, wxGridCellFloatEditor(int width = -1, int precision = -1);
wxWindowID id,
wxEvtHandler* evtHandler); virtual void Create(wxWindow* parent,
wxWindowID id,
virtual bool IsAcceptedKey(wxKeyEvent& event); wxEvtHandler* evtHandler);
virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(const wxString& oldval, wxString *newval); virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void ApplyEdit(int row, int col, wxGrid* grid); virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(int row, int col, const wxGrid* grid,
virtual void Reset(); const wxString& oldval, wxString *newval);
virtual void StartingKey(wxKeyEvent& event); virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual wxGridCellEditor *Clone() const virtual void Reset();
{ return new wxGridCellFloatEditor(m_width, m_precision); } virtual void StartingKey(wxKeyEvent& event);
// parameters string format is "width,precision" virtual wxGridCellEditor *Clone() const
virtual void SetParameters(const wxString& params); { return new wxGridCellFloatEditor(m_width, m_precision); }
protected: // parameters string format is "width,precision"
// string representation of our value virtual void SetParameters(const wxString& params);
wxString GetString() const;
protected:
private: // string representation of our value
int m_width, wxString GetString() const;
m_precision;
double m_value; private:
int m_width,
wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor); m_precision;
}; double m_value;
#endif // wxUSE_TEXTCTRL wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor);
};
#if wxUSE_CHECKBOX
#endif // wxUSE_TEXTCTRL
// the editor for boolean data
class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor #if wxUSE_CHECKBOX
{
public: // the editor for boolean data
wxGridCellBoolEditor() { } class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor
{
virtual void Create(wxWindow* parent, public:
wxWindowID id, wxGridCellBoolEditor() { }
wxEvtHandler* evtHandler);
virtual void Create(wxWindow* parent,
virtual void SetSize(const wxRect& rect); wxWindowID id,
virtual void Show(bool show, wxGridCellAttr *attr = NULL); wxEvtHandler* evtHandler);
virtual bool IsAcceptedKey(wxKeyEvent& event); virtual void SetSize(const wxRect& rect);
virtual void BeginEdit(int row, int col, wxGrid* grid); virtual void Show(bool show, wxGridCellAttr *attr = NULL);
virtual bool EndEdit(const wxString& oldval, wxString *newval);
virtual void ApplyEdit(int row, int col, wxGrid* grid); virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual void Reset(); virtual bool EndEdit(int row, int col, const wxGrid* grid,
virtual void StartingClick(); const wxString& oldval, wxString *newval);
virtual void StartingKey(wxKeyEvent& event); virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual wxGridCellEditor *Clone() const virtual void Reset();
{ return new wxGridCellBoolEditor; } virtual void StartingClick();
virtual void StartingKey(wxKeyEvent& event);
// added GetValue so we can get the value which is in the control, see
// also UseStringValues() virtual wxGridCellEditor *Clone() const
virtual wxString GetValue() const; { return new wxGridCellBoolEditor; }
// set the string values returned by GetValue() for the true and false // added GetValue so we can get the value which is in the control, see
// states, respectively // also UseStringValues()
static void UseStringValues(const wxString& valueTrue = _T("1"), virtual wxString GetValue() const;
const wxString& valueFalse = wxEmptyString);
// set the string values returned by GetValue() for the true and false
// return true if the given string is equal to the string representation of // states, respectively
// true value which we currently use static void UseStringValues(const wxString& valueTrue = _T("1"),
static bool IsTrueValue(const wxString& value); const wxString& valueFalse = wxEmptyString);
protected: // return true if the given string is equal to the string representation of
wxCheckBox *CBox() const { return (wxCheckBox *)m_control; } // true value which we currently use
static bool IsTrueValue(const wxString& value);
private:
bool m_value; protected:
wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
static wxString ms_stringValues[2];
private:
wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor); bool m_value;
};
static wxString ms_stringValues[2];
#endif // wxUSE_CHECKBOX
wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor);
#if wxUSE_COMBOBOX };
// the editor for string data allowing to choose from the list of strings #endif // wxUSE_CHECKBOX
class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor
{ #if wxUSE_COMBOBOX
public:
// if !allowOthers, user can't type a string not in choices array // the editor for string data allowing to choose from the list of strings
wxGridCellChoiceEditor(size_t count = 0, class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor
const wxString choices[] = NULL, {
bool allowOthers = false); public:
wxGridCellChoiceEditor(const wxArrayString& choices, // if !allowOthers, user can't type a string not in choices array
bool allowOthers = false); wxGridCellChoiceEditor(size_t count = 0,
const wxString choices[] = NULL,
virtual void Create(wxWindow* parent, bool allowOthers = false);
wxWindowID id, wxGridCellChoiceEditor(const wxArrayString& choices,
wxEvtHandler* evtHandler); bool allowOthers = false);
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); virtual void Create(wxWindow* parent,
wxWindowID id,
virtual void BeginEdit(int row, int col, wxGrid* grid); wxEvtHandler* evtHandler);
virtual bool EndEdit(const wxString& oldval, wxString *newval);
virtual void ApplyEdit(int row, int col, wxGrid* grid); virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
virtual void Reset(); virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(int row, int col, const wxGrid* grid,
// parameters string format is "item1[,item2[...,itemN]]" const wxString& oldval, wxString *newval);
virtual void SetParameters(const wxString& params); virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual wxGridCellEditor *Clone() const; virtual void Reset();
// added GetValue so we can get the value which is in the control // parameters string format is "item1[,item2[...,itemN]]"
virtual wxString GetValue() const; virtual void SetParameters(const wxString& params);
protected: virtual wxGridCellEditor *Clone() const;
wxComboBox *Combo() const { return (wxComboBox *)m_control; }
// added GetValue so we can get the value which is in the control
wxString m_value; virtual wxString GetValue() const;
wxArrayString m_choices;
bool m_allowOthers; protected:
wxComboBox *Combo() const { return (wxComboBox *)m_control; }
wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor);
}; wxString m_value;
wxArrayString m_choices;
#endif // wxUSE_COMBOBOX bool m_allowOthers;
#if wxUSE_COMBOBOX wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor);
};
class WXDLLIMPEXP_ADV wxGridCellEnumEditor : public wxGridCellChoiceEditor
{ #endif // wxUSE_COMBOBOX
public:
wxGridCellEnumEditor( const wxString& choices = wxEmptyString ); #if wxUSE_COMBOBOX
virtual ~wxGridCellEnumEditor() {}
class WXDLLIMPEXP_ADV wxGridCellEnumEditor : public wxGridCellChoiceEditor
virtual wxGridCellEditor* Clone() const; {
public:
virtual void BeginEdit(int row, int col, wxGrid* grid); wxGridCellEnumEditor( const wxString& choices = wxEmptyString );
virtual bool EndEdit(const wxString& oldval, wxString *newval); virtual ~wxGridCellEnumEditor() {}
virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual wxGridCellEditor* Clone() const;
private:
long m_index; virtual void BeginEdit(int row, int col, wxGrid* grid);
virtual bool EndEdit(int row, int col, const wxGrid* grid,
wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor); const wxString& oldval, wxString *newval);
}; virtual void ApplyEdit(int row, int col, wxGrid* grid);
#endif // wxUSE_COMBOBOX private:
long m_index;
class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
{ wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor);
public: };
wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }
virtual void Create(wxWindow* parent, #endif // wxUSE_COMBOBOX
wxWindowID id,
wxEvtHandler* evtHandler); class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
{
virtual wxGridCellEditor *Clone() const public:
{ return new wxGridCellAutoWrapStringEditor; } wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }
virtual void Create(wxWindow* parent,
wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor); wxWindowID id,
}; wxEvtHandler* evtHandler);
#endif // wxUSE_GRID virtual wxGridCellEditor *Clone() const
#endif // _WX_GENERIC_GRID_EDITORS_H_ { return new wxGridCellAutoWrapStringEditor; }
wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor);
};
#endif // wxUSE_GRID
#endif // _WX_GENERIC_GRID_EDITORS_H_

View File

@@ -218,14 +218,21 @@ public:
This function must check if the current value of the editing control is This function must check if the current value of the editing control is
valid and different from the original value (available as @a oldval in valid and different from the original value (available as @a oldval in
its string form and possibly saved internally using its real type by its string form and possibly saved internally using its real type by
BeginEdit()). If it isn't, it just returns @false, otherwise it fills BeginEdit()). If it isn't, it just returns @false, otherwise it must do
@a newval with the representation of the new value in the string form, the following:
if necessary saves it using its real type internally, and returns @true. # Save the new value internally so that ApplyEdit() could apply it.
# Fill @a newval (which is never @NULL) with the string
representation of the new value.
# Return @true
Notice that it must @em not modify the grid as the change could still
be vetoed.
If the user-defined wxEVT_GRID_CELL_CHANGING event handler doesn't veto If the user-defined wxEVT_GRID_CELL_CHANGING event handler doesn't veto
this change, ApplyEdit() will be called next. this change, ApplyEdit() will be called next.
*/ */
virtual bool EndEdit(const wxString& oldval, wxString* newval) = 0; virtual bool EndEdit(int row, int col, const wxGrid* grid,
const wxString& oldval, wxString* newval) = 0;
/** /**
Effectively save the changes in the grid. Effectively save the changes in the grid.

View File

@@ -5976,7 +5976,7 @@ void wxGrid::SaveEditControlValue()
wxGridCellEditor* editor = attr->GetEditor(this, row, col); wxGridCellEditor* editor = attr->GetEditor(this, row, col);
wxString newval; wxString newval;
bool changed = editor->EndEdit(oldval, &newval); bool changed = editor->EndEdit(row, col, this, oldval, &newval);
if ( changed && SendEvent(wxEVT_GRID_CELL_CHANGING, newval) != -1 ) if ( changed && SendEvent(wxEVT_GRID_CELL_CHANGING, newval) != -1 )
{ {

File diff suppressed because it is too large Load Diff