have been changed to accept "wxBitmapType bitmaptype", please use enum
wxBitmapType in your code.
+- wxGridCellEditor::EndEdit() signature has changed and it was split in two
+ functions, one still called EndEdit() and ApplyEdit(). See the documentation
+ of the new functions for more details about how grid editors should be
+ written now.
+
+- wxEVT_GRID_CELL_CHANGE event renamed to wxEVT_GRID_CELL_CHANGED and shouldn't
+ be vetoed any more, use the new wxEVT_GRID_CELL_CHANGING event to do it.
+
+
Deprecated methods and their replacements
-----------------------------------------
- Improved drawing of the hint during column move in wxGrid (Santo Pfingsten).
- Add wxGridSelectRowsOrColumns selection mode to wxGrid.
- Get/HasModifiers() of wxKeyEvent are now also available in wxMouseEvent.
+- Provide new/old cell value in wxEVT_GRID_CELL_CHANGING/CHANGED events.
wxGTK:
// version just fills it with background colour from the attribute
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
+
+ // The methods called by wxGrid when a cell is edited: first BeginEdit() is
+ // called, then EndEdit() is and if it returns true and if the change is
+ // not vetoed by a user-defined event handler, finally ApplyEdit() is called
+
// Fetch the value from the table and prepare the edit control
// to begin editing. Set the focus to the edit control.
virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
- // Complete the editing of the current cell. Returns true if the value has
- // changed. If necessary, the control may be destroyed.
- virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
+ // Returns false if nothing changed, otherwise returns true and return the
+ // 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
+ // it could be used by ApplyEdit().
+ virtual bool EndEdit(const wxString& oldval, wxString *newval) = 0;
+
+ // Complete the editing of the current cell by storing the value saved by
+ // the previous call to EndEdit() in the grid
+ virtual void ApplyEdit(int row, int col, wxGrid* grid) = 0;
+
// Reset the value in the control back to its starting value
virtual void Reset() = 0;
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid);
- virtual bool EndEdit(int row, int col, wxGrid* grid);
+ virtual bool EndEdit(const wxString& oldval, wxString *newval);
+ virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual void Reset();
virtual void StartingKey(wxKeyEvent& event);
private:
size_t m_maxChars; // max number of chars allowed
- wxString m_startValue;
+ wxString m_value;
DECLARE_NO_COPY_CLASS(wxGridCellTextEditor)
};
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid);
- virtual bool EndEdit(int row, int col, wxGrid* grid);
+ virtual bool EndEdit(const wxString& oldval, wxString *newval);
+ virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual void Reset();
virtual void StartingKey(wxKeyEvent& event);
#endif
}
- // string representation of m_valueOld
+ // string representation of our value
wxString GetString() const
- { return wxString::Format(_T("%ld"), m_valueOld); }
+ { return wxString::Format(_T("%ld"), m_value); }
private:
int m_min,
m_max;
- long m_valueOld;
+ long m_value;
DECLARE_NO_COPY_CLASS(wxGridCellNumberEditor)
};
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid);
- virtual bool EndEdit(int row, int col, wxGrid* grid);
+ virtual bool EndEdit(const wxString& oldval, wxString *newval);
+ virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual void Reset();
virtual void StartingKey(wxKeyEvent& event);
virtual void SetParameters(const wxString& params);
protected:
- // string representation of m_valueOld
+ // string representation of our value
wxString GetString() const;
private:
int m_width,
m_precision;
- double m_valueOld;
+ double m_value;
DECLARE_NO_COPY_CLASS(wxGridCellFloatEditor)
};
virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid);
- virtual bool EndEdit(int row, int col, wxGrid* grid);
+ virtual bool EndEdit(const wxString& oldval, wxString *newval);
+ virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual void Reset();
virtual void StartingClick();
wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
private:
- bool m_startValue;
+ bool m_value;
static wxString ms_stringValues[2];
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
virtual void BeginEdit(int row, int col, wxGrid* grid);
- virtual bool EndEdit(int row, int col, wxGrid* grid);
+ virtual bool EndEdit(const wxString& oldval, wxString *newval);
+ virtual void ApplyEdit(int row, int col, wxGrid* grid);
virtual void Reset();
protected:
wxComboBox *Combo() const { return (wxComboBox *)m_control; }
-// DJC - (MAPTEK) you at least need access to m_choices if you
-// wish to override this class
-protected:
- wxString m_startValue;
+ wxString m_value;
wxArrayString m_choices;
bool m_allowOthers;
const wxGridCellCoords& coords,
wxMouseEvent& e)
{ return SendEvent(evtType, coords.GetRow(), coords.GetCol(), e); }
- int SendEvent(const wxEventType evtType, int row, int col);
- int SendEvent(const wxEventType evtType, const wxGridCellCoords& coords)
- { return SendEvent(evtType, coords.GetRow(), coords.GetCol()); }
- int SendEvent(const wxEventType evtType)
- { return SendEvent(evtType, m_currentCellCoords); }
+ int SendEvent(const wxEventType evtType,
+ int row, int col,
+ const wxString& s = wxString());
+ int SendEvent(const wxEventType evtType,
+ const wxGridCellCoords& coords,
+ const wxString& s = wxString())
+ { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), s); }
+ int SendEvent(const wxEventType evtType, const wxString& s = wxString())
+ { return SendEvent(evtType, m_currentCellCoords, s); }
void OnPaint( wxPaintEvent& );
void OnSize( wxSizeEvent& );
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_ROW_SIZE;
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_SIZE;
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_RANGE_SELECT;
-extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_CHANGE;
+extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_CHANGING;
+extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_CHANGED;
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_SELECT_CELL;
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_EDITOR_SHOWN;
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_EDITOR_HIDDEN;
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_MOVE;
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_SORT;
-
typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
#define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn)
#define EVT_GRID_CMD_COL_SORT(id, fn) wx__DECLARE_GRIDEVT(COL_SORT, id, fn)
#define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn)
-#define EVT_GRID_CMD_CELL_CHANGE(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGE, id, fn)
+#define EVT_GRID_CMD_CELL_CHANGING(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGING, id, fn)
+#define EVT_GRID_CMD_CELL_CHANGED(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGED, id, fn)
#define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn)
#define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn)
#define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn)
#define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn)
#define EVT_GRID_COL_SORT(fn) EVT_GRID_CMD_COL_SORT(wxID_ANY, fn)
#define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn)
-#define EVT_GRID_CELL_CHANGE(fn) EVT_GRID_CMD_CELL_CHANGE(wxID_ANY, fn)
+#define EVT_GRID_CELL_CHANGING(fn) EVT_GRID_CMD_CELL_CHANGING(wxID_ANY, fn)
+#define EVT_GRID_CELL_CHANGED(fn) EVT_GRID_CMD_CELL_CHANGED(wxID_ANY, fn)
#define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn)
#define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn)
#define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn)
#define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn)
#define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn)
+// we used to have a single wxEVT_GRID_CELL_CHANGE event but it was split into
+// wxEVT_GRID_CELL_CHANGING and CHANGED ones in wx 2.9.0, however the CHANGED
+// is basically the same as the old CHANGE event so we keep the name for
+// compatibility
+#if WXWIN_COMPATIBILITY_2_8
+ #define wxEVT_GRID_CELL_CHANGE wxEVT_GRID_CELL_CHANGED
+
+ #define EVT_GRID_CMD_CELL_CHANGE EVT_GRID_CMD_CELL_CHANGED
+ #define EVT_GRID_CELL_CHANGE EVT_GRID_CELL_CHANGED
+#endif // WXWIN_COMPATIBILITY_2_8
+
#if 0 // TODO: implement these ? others ?
extern const int wxEVT_GRID_CREATE_CELL;
virtual wxGridCellEditor* Clone() const;
- virtual bool EndEdit(int row, int col, wxGrid* grid);
virtual void BeginEdit(int row, int col, wxGrid* grid);
+ virtual bool EndEdit(const wxString& oldval, wxString *newval);
+ virtual void ApplyEdit(int row, int col, wxGrid* grid);
private:
- long int m_startint;
+ long m_index;
DECLARE_NO_COPY_CLASS(wxGridCellEnumEditor)
};
/**
Fetch the value from the table and prepare the edit control to begin
- editing. Sets the focus to the edit control.
+ editing.
+
+ This function should save the original value of the grid cell at the
+ given @a row and @a col and show the control allowing the user to
+ change it.
+
+ @see EndEdit()
*/
virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
virtual void Destroy();
/**
- Complete the editing of the current cell. If necessary, the control may
- be destroyed.
+ End editing the cell.
- @return @true if the value has changed.
+ 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
+ its string form and possibly saved internally using its real type by
+ BeginEdit()). If it isn't, it just returns @false, otherwise it fills
+ @a newval with the representation of the new value in the string form,
+ if necessary saves it using its real type internally, and returns @true.
+
+ If the user-defined wxEVT_GRID_CELL_CHANGING event handler doesn't veto
+ this change, ApplyEdit() will be called next.
*/
virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
+ /**
+ Effectively save the changes in the grid.
+
+ This function should save the value of the control in the grid. It is
+ called only after EndEdit() returns @true.
+ */
+ virtual void ApplyEdit(int row, int col, wxGrid* grid) = 0;
+
/**
Some types of controls on some platforms may need some help with the
Return key.
documented below for brevity.
@beginEventTable{wxGridEvent}
- @event{EVT_GRID_CELL_CHANGE(func)}
- The user changed the data in a cell. Processes a
- @c wxEVT_GRID_CELL_CHANGE event type.
+ @event{EVT_GRID_CELL_CHANGING(func)}
+ The user is about to change the data in a cell. The new cell value as
+ string is available from GetString() event object method. This event
+ can be vetoed if the change is not allowed. Processes a @c
+ wxEVT_GRID_CELL_CHANGING event type.
+ @event{EVT_GRID_CELL_CHANGED(func)}
+ The user changed the data in a cell. The old cell value as string is
+ available from GetString() event object method. Notice that vetoing
+ this event still works for backwards compatibility reasons but any new
+ code should only veto EVT_GRID_CELL_CHANGING event and not this one.
+ Processes a @c wxEVT_GRID_CELL_CHANGED event type.
@event{EVT_GRID_CELL_LEFT_CLICK(func)}
The user clicked a cell with the left mouse button. Processes a
@c wxEVT_GRID_CELL_LEFT_CLICK event type.
EVT_GRID_COL_SIZE( GridFrame::OnColSize )
EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell )
EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected )
+ EVT_GRID_CELL_CHANGING( GridFrame::OnCellValueChanging )
EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged )
EVT_GRID_CELL_BEGIN_DRAG( GridFrame::OnCellBeginDrag )
ev.Skip();
}
+void GridFrame::OnCellValueChanging( wxGridEvent& ev )
+{
+ int row = ev.GetRow(),
+ col = ev.GetCol();
+
+ wxLogMessage("Value of cell at (%d, %d): about to change "
+ "from \"%s\" to \"%s\"",
+ row, col,
+ grid->GetCellValue(row, col), ev.GetString());
+
+ // test how vetoing works
+ if ( ev.GetString() == "42" )
+ {
+ wxLogMessage("Vetoing the change.");
+ ev.Veto();
+ return;
+ }
+
+ ev.Skip();
+}
+
void GridFrame::OnCellValueChanged( wxGridEvent& ev )
{
int row = ev.GetRow(),
col = ev.GetCol();
- wxLogMessage(_T("Value changed for cell at row %d, col %d: now \"%s\""),
- row, col, grid->GetCellValue(row, col).c_str());
+ wxLogMessage("Value of cell at (%d, %d) changed and is now \"%s\" "
+ "(was \"%s\")",
+ row, col,
+ grid->GetCellValue(row, col), ev.GetString());
ev.Skip();
}
{
new TabularGridFrame;
}
-
void OnColSize( wxGridSizeEvent& );
void OnSelectCell( wxGridEvent& );
void OnRangeSelected( wxGridRangeSelectEvent& );
+ void OnCellValueChanging( wxGridEvent& );
void OnCellValueChanged( wxGridEvent& );
void OnCellBeginDrag( wxGridEvent& );
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
EVT_MENU(Minimal_About, MyFrame::OnAbout)
+ EVT_BUTTON(Minimal_About, MyFrame::OnAbout)
END_EVENT_TABLE()
// Create a new application object: this macro will allow wxWidgets to create
SetMenuBar(menuBar);
#endif // wxUSE_MENUS
+ wxSizer * const sizer = new wxBoxSizer(wxVERTICAL);
+ sizer->Add(new wxButton(this, wxID_ABOUT));
+ sizer->Add(new wxButton(this, wxID_OPEN));
+ SetSizer(sizer);
+
#if wxUSE_STATUSBAR
// create a status bar just for fun (by default with 1 pane only)
CreateStatusBar(2);
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
+ wxGetTextFromUser("Your text?");
+
+#if 0
wxMessageBox(wxString::Format
(
"Welcome to %s!\n"
"About wxWidgets minimal sample",
wxOK | wxICON_INFORMATION,
this);
+#endif
}
DEFINE_EVENT_TYPE(wxEVT_GRID_COL_MOVE)
DEFINE_EVENT_TYPE(wxEVT_GRID_COL_SORT)
DEFINE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT)
-DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGE)
+DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGING)
+DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGED)
DEFINE_EVENT_TYPE(wxEVT_GRID_SELECT_CELL)
DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN)
DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN)
{
wxASSERT_MSG(m_control, wxT("The wxGridCellEditor must be created first!"));
- m_startValue = grid->GetTable()->GetValue(row, col);
+ m_value = grid->GetTable()->GetValue(row, col);
- DoBeginEdit(m_startValue);
+ DoBeginEdit(m_value);
}
void wxGridCellTextEditor::DoBeginEdit(const wxString& startValue)
Text()->SetFocus();
}
-bool wxGridCellTextEditor::EndEdit(int row, int col, wxGrid* grid)
+bool wxGridCellTextEditor::EndEdit(const wxString& WXUNUSED(oldval),
+ wxString *newval)
{
- wxASSERT_MSG(m_control, wxT("The wxGridCellEditor must be created first!"));
+ wxCHECK_MSG( m_control, false,
+ "wxGridCellTextEditor must be created first!" );
- bool changed = false;
- wxString value = Text()->GetValue();
- if (value != m_startValue)
- changed = true;
+ const wxString value = Text()->GetValue();
+ if ( value == m_value )
+ return false;
- if (changed)
- grid->GetTable()->SetValue(row, col, value);
+ m_value = value;
- m_startValue = wxEmptyString;
+ if ( newval )
+ *newval = m_value;
- // No point in setting the text of the hidden control
- //Text()->SetValue(m_startValue);
+ return true;
+}
- return changed;
+void wxGridCellTextEditor::ApplyEdit(int row, int col, wxGrid* grid)
+{
+ grid->GetTable()->SetValue(row, col, m_value);
+ m_value.clear();
}
void wxGridCellTextEditor::Reset()
{
- wxASSERT_MSG(m_control, wxT("The wxGridCellEditor must be created first!"));
+ wxASSERT_MSG( m_control, "wxGridCellTextEditor must be created first!" );
- DoReset(m_startValue);
+ DoReset(m_value);
}
void wxGridCellTextEditor::DoReset(const wxString& startValue)
wxGridTableBase *table = grid->GetTable();
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
{
- m_valueOld = table->GetValueAsLong(row, col);
+ m_value = table->GetValueAsLong(row, col);
}
else
{
- m_valueOld = 0;
+ m_value = 0;
wxString sValue = table->GetValue(row, col);
- if (! sValue.ToLong(&m_valueOld) && ! sValue.empty())
+ if (! sValue.ToLong(&m_value) && ! sValue.empty())
{
wxFAIL_MSG( _T("this cell doesn't have numeric value") );
return;
#if wxUSE_SPINCTRL
if ( HasRange() )
{
- Spin()->SetValue((int)m_valueOld);
+ Spin()->SetValue((int)m_value);
Spin()->SetFocus();
}
else
}
}
-bool wxGridCellNumberEditor::EndEdit(int row, int col,
- wxGrid* grid)
+bool wxGridCellNumberEditor::EndEdit(const wxString& oldval, wxString *newval)
{
long value = 0;
wxString text;
if ( HasRange() )
{
value = Spin()->GetValue();
- if ( value == m_valueOld )
+ if ( value == m_value )
return false;
text.Printf(wxT("%ld"), value);
else // using unconstrained input
#endif // wxUSE_SPINCTRL
{
- const wxString textOld(grid->GetCellValue(row, col));
text = Text()->GetValue();
if ( text.empty() )
{
- if ( textOld.empty() )
+ if ( oldval.empty() )
return false;
}
else // non-empty text now (maybe 0)
if ( !text.ToLong(&value) )
return false;
- // if value == m_valueOld == 0 but old text was "" and new one is
+ // if value == m_value == 0 but old text was "" and new one is
// "0" something still did change
- if ( value == m_valueOld && (value || !textOld.empty()) )
+ if ( value == m_value && (value || !oldval.empty()) )
return false;
}
}
+ m_value = value;
+
+ if ( newval )
+ *newval = text;
+
+ return true;
+}
+
+void wxGridCellNumberEditor::ApplyEdit(int row, int col, wxGrid* grid)
+{
wxGridTableBase * const table = grid->GetTable();
if ( table->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER) )
- table->SetValueAsLong(row, col, value);
+ table->SetValueAsLong(row, col, m_value);
else
- table->SetValue(row, col, text);
-
- return true;
+ table->SetValue(row, col, wxString::Format("%ld", m_value));
}
void wxGridCellNumberEditor::Reset()
#if wxUSE_SPINCTRL
if ( HasRange() )
{
- Spin()->SetValue((int)m_valueOld);
+ Spin()->SetValue((int)m_value);
}
else
#endif
wxGridTableBase * const table = grid->GetTable();
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) )
{
- m_valueOld = table->GetValueAsDouble(row, col);
+ m_value = table->GetValueAsDouble(row, col);
}
else
{
- m_valueOld = 0.0;
+ m_value = 0.0;
const wxString value = table->GetValue(row, col);
if ( !value.empty() )
{
- if ( !value.ToDouble(&m_valueOld) )
+ if ( !value.ToDouble(&m_value) )
{
wxFAIL_MSG( _T("this cell doesn't have float value") );
return;
DoBeginEdit(GetString());
}
-bool wxGridCellFloatEditor::EndEdit(int row, int col, wxGrid* grid)
+bool wxGridCellFloatEditor::EndEdit(const wxString& oldval, wxString *newval)
{
- const wxString text(Text()->GetValue()),
- textOld(grid->GetCellValue(row, col));
+ const wxString text(Text()->GetValue());
double value;
if ( !text.empty() )
}
else // new value is empty string
{
- if ( textOld.empty() )
+ if ( oldval.empty() )
return false; // nothing changed
value = 0.;
// the test for empty strings ensures that we don't skip the value setting
// when "" is replaced by "0" or vice versa as "" numeric value is also 0.
- if ( wxIsSameDouble(value, m_valueOld) && !text.empty() && !textOld.empty() )
+ if ( wxIsSameDouble(value, m_value) && !text.empty() && !oldval.empty() )
return false; // nothing changed
+ m_value = value;
+
+ if ( newval )
+ *newval = text;
+
+ return true;
+}
+
+void wxGridCellFloatEditor::ApplyEdit(int row, int col, wxGrid* grid)
+{
wxGridTableBase * const table = grid->GetTable();
if ( table->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT) )
- table->SetValueAsDouble(row, col, value);
+ table->SetValueAsDouble(row, col, m_value);
else
- table->SetValue(row, col, text);
-
- return true;
+ table->SetValue(row, col, Text()->GetValue());
}
void wxGridCellFloatEditor::Reset()
fmt = _T("%f");
}
- return wxString::Format(fmt, m_valueOld);
+ return wxString::Format(fmt, m_value);
}
bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event)
if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL))
{
- m_startValue = grid->GetTable()->GetValueAsBool(row, col);
+ m_value = grid->GetTable()->GetValueAsBool(row, col);
}
else
{
wxString cellval( grid->GetTable()->GetValue(row, col) );
if ( cellval == ms_stringValues[false] )
- m_startValue = false;
+ m_value = false;
else if ( cellval == ms_stringValues[true] )
- m_startValue = true;
+ m_value = true;
else
{
// do not try to be smart here and convert it to true or false
}
}
- CBox()->SetValue(m_startValue);
+ CBox()->SetValue(m_value);
CBox()->SetFocus();
}
-bool wxGridCellBoolEditor::EndEdit(int row, int col,
- wxGrid* grid)
+bool wxGridCellBoolEditor::EndEdit(const wxString& WXUNUSED(oldval),
+ wxString *newval)
{
- 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 ( value == m_value )
+ return false;
- if ( changed )
- {
- wxGridTableBase * const table = grid->GetTable();
- if ( table->CanSetValueAs(row, col, wxGRID_VALUE_BOOL) )
- table->SetValueAsBool(row, col, value);
- else
- table->SetValue(row, col, GetValue());
- }
+ m_value = value;
+
+ if ( newval )
+ *newval = GetValue();
- return changed;
+ return true;
+}
+
+void wxGridCellBoolEditor::ApplyEdit(int row, int col, wxGrid* grid)
+{
+ wxGridTableBase * const table = grid->GetTable();
+ if ( table->CanSetValueAs(row, col, wxGRID_VALUE_BOOL) )
+ table->SetValueAsBool(row, col, m_value);
+ else
+ table->SetValue(row, col, GetValue());
}
void wxGridCellBoolEditor::Reset()
wxASSERT_MSG(m_control,
wxT("The wxGridCellEditor must be created first!"));
- CBox()->SetValue(m_startValue);
+ CBox()->SetValue(m_value);
}
void wxGridCellBoolEditor::StartingClick()
if (evtHandler)
evtHandler->SetInSetFocus(true);
- m_startValue = grid->GetTable()->GetValue(row, col);
+ m_value = grid->GetTable()->GetValue(row, col);
- Reset(); // this updates combo box to correspond to m_startValue
+ Reset(); // this updates combo box to correspond to m_value
Combo()->SetFocus();
}
}
-bool wxGridCellChoiceEditor::EndEdit(int row, int col,
- wxGrid* grid)
+bool wxGridCellChoiceEditor::EndEdit(const wxString& WXUNUSED(oldval),
+ wxString *newval)
{
- wxString value = Combo()->GetValue();
- if ( value == m_startValue )
+ const wxString value = Combo()->GetValue();
+ if ( value == m_value )
return false;
- grid->GetTable()->SetValue(row, col, value);
+ m_value = value;
+
+ if ( newval )
+ *newval = value;
return true;
}
+void wxGridCellChoiceEditor::ApplyEdit(int row, int col, wxGrid* grid)
+{
+ grid->GetTable()->SetValue(row, col, m_value);
+}
+
void wxGridCellChoiceEditor::Reset()
{
if (m_allowOthers)
{
- Combo()->SetValue(m_startValue);
+ Combo()->SetValue(m_value);
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);
+ int pos = Combo()->FindString(m_value);
if (pos == wxNOT_FOUND)
pos = 0;
Combo()->SetSelection(pos);
// Generate a grid event of specified type, return value same as above
//
-int wxGrid::SendEvent(const wxEventType type, int row, int col)
+int
+wxGrid::SendEvent(const wxEventType type, int row, int col, const wxString& s)
{
bool claimed, vetoed;
else
{
wxGridEvent gridEvt( GetId(), type, this, row, col );
+ gridEvt.SetString(s);
claimed = GetEventHandler()->ProcessEvent(gridEvt);
vetoed = !gridEvt.IsAllowed();
}
else
{
- //FIXME:add veto support
SendEvent(wxEVT_GRID_EDITOR_HIDDEN);
HideCellEditControl();
wxGridCellAttr* attr = GetCellAttr(row, col);
wxGridCellEditor* editor = attr->GetEditor(this, row, col);
- bool changed = editor->EndEdit(row, col, this);
- editor->DecRef();
- attr->DecRef();
+ wxString newval;
+ bool changed = editor->EndEdit(oldval, &newval);
- if (changed)
+ if ( changed && SendEvent(wxEVT_GRID_CELL_CHANGING, newval) != -1 )
{
- if ( SendEvent(wxEVT_GRID_CELL_CHANGE) == -1 )
+ editor->ApplyEdit(row, col, this);
+
+ // for compatibility reasons dating back to wx 2.8 when this event
+ // was called wxEVT_GRID_CELL_CHANGE and wxEVT_GRID_CELL_CHANGING
+ // didn't exist we allow vetoing this one too
+ if ( SendEvent(wxEVT_GRID_CELL_CHANGED, oldval) == -1 )
{
// Event has been vetoed, set the data back.
SetCellValue(row, col, oldval);
}
}
+
+ editor->DecRef();
+ attr->DecRef();
}
}
wxGridCellEnumEditor::wxGridCellEnumEditor(const wxString& choices)
:wxGridCellChoiceEditor()
{
- m_startint = -1;
+ m_index = -1;
if (!choices.empty())
SetParameters(choices);
wxGridCellEditor *wxGridCellEnumEditor::Clone() const
{
wxGridCellEnumEditor *editor = new wxGridCellEnumEditor();
- editor->m_startint = m_startint;
+ editor->m_index = m_index;
return editor;
}
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
{
- m_startint = table->GetValueAsLong(row, col);
+ m_index = table->GetValueAsLong(row, col);
}
else
{
wxString startValue = table->GetValue(row, col);
if (startValue.IsNumber() && !startValue.empty())
{
- startValue.ToLong(&m_startint);
+ startValue.ToLong(&m_index);
}
else
{
- m_startint=-1;
+ m_index = -1;
}
}
- Combo()->SetSelection(m_startint);
+ Combo()->SetSelection(m_index);
Combo()->SetInsertionPointEnd();
Combo()->SetFocus();
}
-bool wxGridCellEnumEditor::EndEdit(int row, int col, wxGrid* grid)
+bool wxGridCellEnumEditor::EndEdit(const wxString& WXUNUSED(oldval),
+ wxString *newval)
{
- int pos = Combo()->GetSelection();
- bool changed = (pos != m_startint);
- if (changed)
- {
- if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER))
- grid->GetTable()->SetValueAsLong(row, col, pos);
- else
- grid->GetTable()->SetValue(row, col,wxString::Format(wxT("%i"),pos));
- }
+ long idx = Combo()->GetSelection();
+ if ( idx == m_index )
+ return false;
+
+ m_index = idx;
+
+ if ( newval )
+ newval->Printf("%ld", m_index);
- return changed;
+ return true;
+}
+
+void wxGridCellEnumEditor::ApplyEdit(int row, int col, wxGrid* grid)
+{
+ wxGridTableBase * const table = grid->GetTable();
+ if ( table->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER) )
+ table->SetValueAsLong(row, col, m_index);
+ else
+ table->SetValue(row, col, wxString::Format("%ld", m_index));
}
#endif // wxUSE_COMBOBOX