split wxEVT_GRID_CELL_CHANGE into wxEVT_GRID_CELL_CHANGING/ED pair for consistency with all the other controls; provide access to new/old value of the cell in the event object
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57505 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -199,6 +199,15 @@ Changes in behaviour which may result in compilation errors
|
|||||||
have been changed to accept "wxBitmapType bitmaptype", please use enum
|
have been changed to accept "wxBitmapType bitmaptype", please use enum
|
||||||
wxBitmapType in your code.
|
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
|
Deprecated methods and their replacements
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
@@ -416,6 +425,7 @@ All (GUI):
|
|||||||
- Improved drawing of the hint during column move in wxGrid (Santo Pfingsten).
|
- Improved drawing of the hint during column move in wxGrid (Santo Pfingsten).
|
||||||
- Add wxGridSelectRowsOrColumns selection mode to wxGrid.
|
- Add wxGridSelectRowsOrColumns selection mode to wxGrid.
|
||||||
- Get/HasModifiers() of wxKeyEvent are now also available in wxMouseEvent.
|
- Get/HasModifiers() of wxKeyEvent are now also available in wxMouseEvent.
|
||||||
|
- Provide new/old cell value in wxEVT_GRID_CELL_CHANGING/CHANGED events.
|
||||||
|
|
||||||
wxGTK:
|
wxGTK:
|
||||||
|
|
||||||
|
@@ -327,13 +327,26 @@ public:
|
|||||||
// version just fills it with background colour from the attribute
|
// version just fills it with background colour from the attribute
|
||||||
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
|
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
|
// Fetch the value from the table and prepare the edit control
|
||||||
// to begin editing. Set the focus to the edit control.
|
// to begin editing. Set the focus to the edit control.
|
||||||
virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
|
virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
|
||||||
|
|
||||||
// Complete the editing of the current cell. Returns true if the value has
|
// Returns false if nothing changed, otherwise returns true and return the
|
||||||
// changed. If necessary, the control may be destroyed.
|
// new value in its string form in the newval output parameter.
|
||||||
virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
|
//
|
||||||
|
// 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
|
// Reset the value in the control back to its starting value
|
||||||
virtual void Reset() = 0;
|
virtual void Reset() = 0;
|
||||||
@@ -410,7 +423,8 @@ public:
|
|||||||
|
|
||||||
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(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 Reset();
|
||||||
virtual void StartingKey(wxKeyEvent& event);
|
virtual void StartingKey(wxKeyEvent& event);
|
||||||
@@ -436,7 +450,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
size_t m_maxChars; // max number of chars allowed
|
size_t m_maxChars; // max number of chars allowed
|
||||||
wxString m_startValue;
|
wxString m_value;
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(wxGridCellTextEditor)
|
DECLARE_NO_COPY_CLASS(wxGridCellTextEditor)
|
||||||
};
|
};
|
||||||
@@ -455,7 +469,8 @@ public:
|
|||||||
|
|
||||||
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(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 Reset();
|
||||||
virtual void StartingKey(wxKeyEvent& event);
|
virtual void StartingKey(wxKeyEvent& event);
|
||||||
@@ -484,15 +499,15 @@ protected:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// string representation of m_valueOld
|
// string representation of our value
|
||||||
wxString GetString() const
|
wxString GetString() const
|
||||||
{ return wxString::Format(_T("%ld"), m_valueOld); }
|
{ return wxString::Format(_T("%ld"), m_value); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_min,
|
int m_min,
|
||||||
m_max;
|
m_max;
|
||||||
|
|
||||||
long m_valueOld;
|
long m_value;
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(wxGridCellNumberEditor)
|
DECLARE_NO_COPY_CLASS(wxGridCellNumberEditor)
|
||||||
};
|
};
|
||||||
@@ -509,7 +524,8 @@ public:
|
|||||||
|
|
||||||
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(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 Reset();
|
||||||
virtual void StartingKey(wxKeyEvent& event);
|
virtual void StartingKey(wxKeyEvent& event);
|
||||||
@@ -521,13 +537,13 @@ public:
|
|||||||
virtual void SetParameters(const wxString& params);
|
virtual void SetParameters(const wxString& params);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// string representation of m_valueOld
|
// string representation of our value
|
||||||
wxString GetString() const;
|
wxString GetString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_width,
|
int m_width,
|
||||||
m_precision;
|
m_precision;
|
||||||
double m_valueOld;
|
double m_value;
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(wxGridCellFloatEditor)
|
DECLARE_NO_COPY_CLASS(wxGridCellFloatEditor)
|
||||||
};
|
};
|
||||||
@@ -551,7 +567,8 @@ public:
|
|||||||
|
|
||||||
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(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 Reset();
|
||||||
virtual void StartingClick();
|
virtual void StartingClick();
|
||||||
@@ -577,7 +594,7 @@ protected:
|
|||||||
wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
|
wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_startValue;
|
bool m_value;
|
||||||
|
|
||||||
static wxString ms_stringValues[2];
|
static wxString ms_stringValues[2];
|
||||||
|
|
||||||
@@ -606,7 +623,8 @@ public:
|
|||||||
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
|
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
|
||||||
|
|
||||||
virtual void BeginEdit(int row, int col, wxGrid* grid);
|
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 Reset();
|
||||||
|
|
||||||
@@ -621,10 +639,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
wxComboBox *Combo() const { return (wxComboBox *)m_control; }
|
wxComboBox *Combo() const { return (wxComboBox *)m_control; }
|
||||||
|
|
||||||
// DJC - (MAPTEK) you at least need access to m_choices if you
|
wxString m_value;
|
||||||
// wish to override this class
|
|
||||||
protected:
|
|
||||||
wxString m_startValue;
|
|
||||||
wxArrayString m_choices;
|
wxArrayString m_choices;
|
||||||
bool m_allowOthers;
|
bool m_allowOthers;
|
||||||
|
|
||||||
@@ -2233,11 +2248,15 @@ protected:
|
|||||||
const wxGridCellCoords& coords,
|
const wxGridCellCoords& coords,
|
||||||
wxMouseEvent& e)
|
wxMouseEvent& e)
|
||||||
{ return SendEvent(evtType, coords.GetRow(), coords.GetCol(), e); }
|
{ return SendEvent(evtType, coords.GetRow(), coords.GetCol(), e); }
|
||||||
int SendEvent(const wxEventType evtType, int row, int col);
|
int SendEvent(const wxEventType evtType,
|
||||||
int SendEvent(const wxEventType evtType, const wxGridCellCoords& coords)
|
int row, int col,
|
||||||
{ return SendEvent(evtType, coords.GetRow(), coords.GetCol()); }
|
const wxString& s = wxString());
|
||||||
int SendEvent(const wxEventType evtType)
|
int SendEvent(const wxEventType evtType,
|
||||||
{ return SendEvent(evtType, m_currentCellCoords); }
|
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 OnPaint( wxPaintEvent& );
|
||||||
void OnSize( wxSizeEvent& );
|
void OnSize( wxSizeEvent& );
|
||||||
@@ -2659,7 +2678,8 @@ extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
|
|||||||
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_ROW_SIZE;
|
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_COL_SIZE;
|
||||||
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_RANGE_SELECT;
|
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_SELECT_CELL;
|
||||||
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_EDITOR_SHOWN;
|
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_EDITOR_HIDDEN;
|
||||||
@@ -2668,7 +2688,6 @@ extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_BEGIN_DRAG;
|
|||||||
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_MOVE;
|
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_MOVE;
|
||||||
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_SORT;
|
extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_SORT;
|
||||||
|
|
||||||
|
|
||||||
typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
|
typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
|
||||||
typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
|
typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
|
||||||
typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
|
typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
|
||||||
@@ -2711,7 +2730,8 @@ typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreat
|
|||||||
#define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn)
|
#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_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_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_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_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_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn)
|
||||||
@@ -2733,13 +2753,25 @@ typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreat
|
|||||||
#define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, 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_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_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_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_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_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_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)
|
#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 ?
|
#if 0 // TODO: implement these ? others ?
|
||||||
|
|
||||||
extern const int wxEVT_GRID_CREATE_CELL;
|
extern const int wxEVT_GRID_CREATE_CELL;
|
||||||
|
@@ -100,11 +100,12 @@ public:
|
|||||||
|
|
||||||
virtual wxGridCellEditor* Clone() const;
|
virtual wxGridCellEditor* Clone() const;
|
||||||
|
|
||||||
virtual bool EndEdit(int row, int col, wxGrid* grid);
|
|
||||||
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 void ApplyEdit(int row, int col, wxGrid* grid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long int m_startint;
|
long m_index;
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(wxGridCellEnumEditor)
|
DECLARE_NO_COPY_CLASS(wxGridCellEnumEditor)
|
||||||
};
|
};
|
||||||
|
@@ -186,7 +186,13 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Fetch the value from the table and prepare the edit control to begin
|
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 BeginEdit(int row, int col, wxGrid* grid) = 0;
|
||||||
|
|
||||||
@@ -207,13 +213,28 @@ public:
|
|||||||
virtual void Destroy();
|
virtual void Destroy();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Complete the editing of the current cell. If necessary, the control may
|
End editing the cell.
|
||||||
be destroyed.
|
|
||||||
|
|
||||||
@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;
|
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
|
Some types of controls on some platforms may need some help with the
|
||||||
Return key.
|
Return key.
|
||||||
@@ -3330,9 +3351,17 @@ public:
|
|||||||
documented below for brevity.
|
documented below for brevity.
|
||||||
|
|
||||||
@beginEventTable{wxGridEvent}
|
@beginEventTable{wxGridEvent}
|
||||||
@event{EVT_GRID_CELL_CHANGE(func)}
|
@event{EVT_GRID_CELL_CHANGING(func)}
|
||||||
The user changed the data in a cell. Processes a
|
The user is about to change the data in a cell. The new cell value as
|
||||||
@c wxEVT_GRID_CELL_CHANGE event type.
|
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)}
|
@event{EVT_GRID_CELL_LEFT_CLICK(func)}
|
||||||
The user clicked a cell with the left mouse button. Processes a
|
The user clicked a cell with the left mouse button. Processes a
|
||||||
@c wxEVT_GRID_CELL_LEFT_CLICK event type.
|
@c wxEVT_GRID_CELL_LEFT_CLICK event type.
|
||||||
|
@@ -133,6 +133,7 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
|
|||||||
EVT_GRID_COL_SIZE( GridFrame::OnColSize )
|
EVT_GRID_COL_SIZE( GridFrame::OnColSize )
|
||||||
EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell )
|
EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell )
|
||||||
EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected )
|
EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected )
|
||||||
|
EVT_GRID_CELL_CHANGING( GridFrame::OnCellValueChanging )
|
||||||
EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged )
|
EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged )
|
||||||
EVT_GRID_CELL_BEGIN_DRAG( GridFrame::OnCellBeginDrag )
|
EVT_GRID_CELL_BEGIN_DRAG( GridFrame::OnCellBeginDrag )
|
||||||
|
|
||||||
@@ -1059,13 +1060,36 @@ void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev )
|
|||||||
ev.Skip();
|
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 )
|
void GridFrame::OnCellValueChanged( wxGridEvent& ev )
|
||||||
{
|
{
|
||||||
int row = ev.GetRow(),
|
int row = ev.GetRow(),
|
||||||
col = ev.GetCol();
|
col = ev.GetCol();
|
||||||
|
|
||||||
wxLogMessage(_T("Value changed for cell at row %d, col %d: now \"%s\""),
|
wxLogMessage("Value of cell at (%d, %d) changed and is now \"%s\" "
|
||||||
row, col, grid->GetCellValue(row, col).c_str());
|
"(was \"%s\")",
|
||||||
|
row, col,
|
||||||
|
grid->GetCellValue(row, col), ev.GetString());
|
||||||
|
|
||||||
ev.Skip();
|
ev.Skip();
|
||||||
}
|
}
|
||||||
@@ -1969,4 +1993,3 @@ void GridFrame::OnTabularTable(wxCommandEvent&)
|
|||||||
{
|
{
|
||||||
new TabularGridFrame;
|
new TabularGridFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -91,6 +91,7 @@ class GridFrame : public wxFrame
|
|||||||
void OnColSize( wxGridSizeEvent& );
|
void OnColSize( wxGridSizeEvent& );
|
||||||
void OnSelectCell( wxGridEvent& );
|
void OnSelectCell( wxGridEvent& );
|
||||||
void OnRangeSelected( wxGridRangeSelectEvent& );
|
void OnRangeSelected( wxGridRangeSelectEvent& );
|
||||||
|
void OnCellValueChanging( wxGridEvent& );
|
||||||
void OnCellValueChanged( wxGridEvent& );
|
void OnCellValueChanged( wxGridEvent& );
|
||||||
void OnCellBeginDrag( wxGridEvent& );
|
void OnCellBeginDrag( wxGridEvent& );
|
||||||
|
|
||||||
|
@@ -99,6 +99,7 @@ enum
|
|||||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
|
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
|
||||||
EVT_MENU(Minimal_About, MyFrame::OnAbout)
|
EVT_MENU(Minimal_About, MyFrame::OnAbout)
|
||||||
|
EVT_BUTTON(Minimal_About, MyFrame::OnAbout)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
// Create a new application object: this macro will allow wxWidgets to create
|
// Create a new application object: this macro will allow wxWidgets to create
|
||||||
@@ -167,6 +168,11 @@ MyFrame::MyFrame(const wxString& title)
|
|||||||
SetMenuBar(menuBar);
|
SetMenuBar(menuBar);
|
||||||
#endif // wxUSE_MENUS
|
#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
|
#if wxUSE_STATUSBAR
|
||||||
// create a status bar just for fun (by default with 1 pane only)
|
// create a status bar just for fun (by default with 1 pane only)
|
||||||
CreateStatusBar(2);
|
CreateStatusBar(2);
|
||||||
@@ -185,6 +191,9 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
|
wxGetTextFromUser("Your text?");
|
||||||
|
|
||||||
|
#if 0
|
||||||
wxMessageBox(wxString::Format
|
wxMessageBox(wxString::Format
|
||||||
(
|
(
|
||||||
"Welcome to %s!\n"
|
"Welcome to %s!\n"
|
||||||
@@ -197,4 +206,5 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|||||||
"About wxWidgets minimal sample",
|
"About wxWidgets minimal sample",
|
||||||
wxOK | wxICON_INFORMATION,
|
wxOK | wxICON_INFORMATION,
|
||||||
this);
|
this);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -148,7 +148,8 @@ DEFINE_EVENT_TYPE(wxEVT_GRID_COL_SIZE)
|
|||||||
DEFINE_EVENT_TYPE(wxEVT_GRID_COL_MOVE)
|
DEFINE_EVENT_TYPE(wxEVT_GRID_COL_MOVE)
|
||||||
DEFINE_EVENT_TYPE(wxEVT_GRID_COL_SORT)
|
DEFINE_EVENT_TYPE(wxEVT_GRID_COL_SORT)
|
||||||
DEFINE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT)
|
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_SELECT_CELL)
|
||||||
DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN)
|
DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN)
|
||||||
DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN)
|
DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN)
|
||||||
@@ -1259,9 +1260,9 @@ void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
{
|
{
|
||||||
wxASSERT_MSG(m_control, wxT("The wxGridCellEditor must be created first!"));
|
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)
|
void wxGridCellTextEditor::DoBeginEdit(const wxString& startValue)
|
||||||
@@ -1272,31 +1273,35 @@ void wxGridCellTextEditor::DoBeginEdit(const wxString& startValue)
|
|||||||
Text()->SetFocus();
|
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;
|
const wxString value = Text()->GetValue();
|
||||||
wxString value = Text()->GetValue();
|
if ( value == m_value )
|
||||||
if (value != m_startValue)
|
return false;
|
||||||
changed = true;
|
|
||||||
|
|
||||||
if (changed)
|
m_value = value;
|
||||||
grid->GetTable()->SetValue(row, col, value);
|
|
||||||
|
|
||||||
m_startValue = wxEmptyString;
|
if ( newval )
|
||||||
|
*newval = m_value;
|
||||||
|
|
||||||
// No point in setting the text of the hidden control
|
return true;
|
||||||
//Text()->SetValue(m_startValue);
|
}
|
||||||
|
|
||||||
return changed;
|
void wxGridCellTextEditor::ApplyEdit(int row, int col, wxGrid* grid)
|
||||||
|
{
|
||||||
|
grid->GetTable()->SetValue(row, col, m_value);
|
||||||
|
m_value.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGridCellTextEditor::Reset()
|
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)
|
void wxGridCellTextEditor::DoReset(const wxString& startValue)
|
||||||
@@ -1438,13 +1443,13 @@ void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
wxGridTableBase *table = grid->GetTable();
|
wxGridTableBase *table = grid->GetTable();
|
||||||
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
|
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
|
||||||
{
|
{
|
||||||
m_valueOld = table->GetValueAsLong(row, col);
|
m_value = table->GetValueAsLong(row, col);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_valueOld = 0;
|
m_value = 0;
|
||||||
wxString sValue = table->GetValue(row, col);
|
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") );
|
wxFAIL_MSG( _T("this cell doesn't have numeric value") );
|
||||||
return;
|
return;
|
||||||
@@ -1454,7 +1459,7 @@ void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
#if wxUSE_SPINCTRL
|
#if wxUSE_SPINCTRL
|
||||||
if ( HasRange() )
|
if ( HasRange() )
|
||||||
{
|
{
|
||||||
Spin()->SetValue((int)m_valueOld);
|
Spin()->SetValue((int)m_value);
|
||||||
Spin()->SetFocus();
|
Spin()->SetFocus();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1464,8 +1469,7 @@ void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxGridCellNumberEditor::EndEdit(int row, int col,
|
bool wxGridCellNumberEditor::EndEdit(const wxString& oldval, wxString *newval)
|
||||||
wxGrid* grid)
|
|
||||||
{
|
{
|
||||||
long value = 0;
|
long value = 0;
|
||||||
wxString text;
|
wxString text;
|
||||||
@@ -1474,7 +1478,7 @@ bool wxGridCellNumberEditor::EndEdit(int row, int col,
|
|||||||
if ( HasRange() )
|
if ( HasRange() )
|
||||||
{
|
{
|
||||||
value = Spin()->GetValue();
|
value = Spin()->GetValue();
|
||||||
if ( value == m_valueOld )
|
if ( value == m_value )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
text.Printf(wxT("%ld"), value);
|
text.Printf(wxT("%ld"), value);
|
||||||
@@ -1482,11 +1486,10 @@ bool wxGridCellNumberEditor::EndEdit(int row, int col,
|
|||||||
else // using unconstrained input
|
else // using unconstrained input
|
||||||
#endif // wxUSE_SPINCTRL
|
#endif // wxUSE_SPINCTRL
|
||||||
{
|
{
|
||||||
const wxString textOld(grid->GetCellValue(row, col));
|
|
||||||
text = Text()->GetValue();
|
text = Text()->GetValue();
|
||||||
if ( text.empty() )
|
if ( text.empty() )
|
||||||
{
|
{
|
||||||
if ( textOld.empty() )
|
if ( oldval.empty() )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else // non-empty text now (maybe 0)
|
else // non-empty text now (maybe 0)
|
||||||
@@ -1494,28 +1497,36 @@ bool wxGridCellNumberEditor::EndEdit(int row, int col,
|
|||||||
if ( !text.ToLong(&value) )
|
if ( !text.ToLong(&value) )
|
||||||
return false;
|
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
|
// "0" something still did change
|
||||||
if ( value == m_valueOld && (value || !textOld.empty()) )
|
if ( value == m_value && (value || !oldval.empty()) )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGridTableBase * const table = grid->GetTable();
|
m_value = value;
|
||||||
if ( table->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER) )
|
|
||||||
table->SetValueAsLong(row, col, value);
|
if ( newval )
|
||||||
else
|
*newval = text;
|
||||||
table->SetValue(row, col, text);
|
|
||||||
|
|
||||||
return true;
|
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, m_value);
|
||||||
|
else
|
||||||
|
table->SetValue(row, col, wxString::Format("%ld", m_value));
|
||||||
|
}
|
||||||
|
|
||||||
void wxGridCellNumberEditor::Reset()
|
void wxGridCellNumberEditor::Reset()
|
||||||
{
|
{
|
||||||
#if wxUSE_SPINCTRL
|
#if wxUSE_SPINCTRL
|
||||||
if ( HasRange() )
|
if ( HasRange() )
|
||||||
{
|
{
|
||||||
Spin()->SetValue((int)m_valueOld);
|
Spin()->SetValue((int)m_value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
@@ -1643,16 +1654,16 @@ void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
wxGridTableBase * const table = grid->GetTable();
|
wxGridTableBase * const table = grid->GetTable();
|
||||||
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) )
|
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) )
|
||||||
{
|
{
|
||||||
m_valueOld = table->GetValueAsDouble(row, col);
|
m_value = table->GetValueAsDouble(row, col);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_valueOld = 0.0;
|
m_value = 0.0;
|
||||||
|
|
||||||
const wxString value = table->GetValue(row, col);
|
const wxString value = table->GetValue(row, col);
|
||||||
if ( !value.empty() )
|
if ( !value.empty() )
|
||||||
{
|
{
|
||||||
if ( !value.ToDouble(&m_valueOld) )
|
if ( !value.ToDouble(&m_value) )
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( _T("this cell doesn't have float value") );
|
wxFAIL_MSG( _T("this cell doesn't have float value") );
|
||||||
return;
|
return;
|
||||||
@@ -1663,10 +1674,9 @@ void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
DoBeginEdit(GetString());
|
DoBeginEdit(GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxGridCellFloatEditor::EndEdit(int row, int col, wxGrid* grid)
|
bool wxGridCellFloatEditor::EndEdit(const wxString& oldval, wxString *newval)
|
||||||
{
|
{
|
||||||
const wxString text(Text()->GetValue()),
|
const wxString text(Text()->GetValue());
|
||||||
textOld(grid->GetCellValue(row, col));
|
|
||||||
|
|
||||||
double value;
|
double value;
|
||||||
if ( !text.empty() )
|
if ( !text.empty() )
|
||||||
@@ -1676,7 +1686,7 @@ bool wxGridCellFloatEditor::EndEdit(int row, int col, wxGrid* grid)
|
|||||||
}
|
}
|
||||||
else // new value is empty string
|
else // new value is empty string
|
||||||
{
|
{
|
||||||
if ( textOld.empty() )
|
if ( oldval.empty() )
|
||||||
return false; // nothing changed
|
return false; // nothing changed
|
||||||
|
|
||||||
value = 0.;
|
value = 0.;
|
||||||
@@ -1684,17 +1694,25 @@ bool wxGridCellFloatEditor::EndEdit(int row, int col, wxGrid* grid)
|
|||||||
|
|
||||||
// the test for empty strings ensures that we don't skip the value setting
|
// 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.
|
// 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
|
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();
|
wxGridTableBase * const table = grid->GetTable();
|
||||||
|
|
||||||
if ( table->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT) )
|
if ( table->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT) )
|
||||||
table->SetValueAsDouble(row, col, value);
|
table->SetValueAsDouble(row, col, m_value);
|
||||||
else
|
else
|
||||||
table->SetValue(row, col, text);
|
table->SetValue(row, col, Text()->GetValue());
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGridCellFloatEditor::Reset()
|
void wxGridCellFloatEditor::Reset()
|
||||||
@@ -1780,7 +1798,7 @@ wxString wxGridCellFloatEditor::GetString() const
|
|||||||
fmt = _T("%f");
|
fmt = _T("%f");
|
||||||
}
|
}
|
||||||
|
|
||||||
return wxString::Format(fmt, m_valueOld);
|
return wxString::Format(fmt, m_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event)
|
bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event)
|
||||||
@@ -1928,16 +1946,16 @@ void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
|
|
||||||
if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL))
|
if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL))
|
||||||
{
|
{
|
||||||
m_startValue = grid->GetTable()->GetValueAsBool(row, col);
|
m_value = grid->GetTable()->GetValueAsBool(row, col);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxString cellval( grid->GetTable()->GetValue(row, col) );
|
wxString cellval( grid->GetTable()->GetValue(row, col) );
|
||||||
|
|
||||||
if ( cellval == ms_stringValues[false] )
|
if ( cellval == ms_stringValues[false] )
|
||||||
m_startValue = false;
|
m_value = false;
|
||||||
else if ( cellval == ms_stringValues[true] )
|
else if ( cellval == ms_stringValues[true] )
|
||||||
m_startValue = true;
|
m_value = true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// do not try to be smart here and convert it to true or false
|
// do not try to be smart here and convert it to true or false
|
||||||
@@ -1948,39 +1966,40 @@ void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CBox()->SetValue(m_startValue);
|
CBox()->SetValue(m_value);
|
||||||
CBox()->SetFocus();
|
CBox()->SetFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxGridCellBoolEditor::EndEdit(int row, int col,
|
bool wxGridCellBoolEditor::EndEdit(const wxString& WXUNUSED(oldval),
|
||||||
wxGrid* grid)
|
wxString *newval)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG(m_control,
|
|
||||||
wxT("The wxGridCellEditor must be created first!"));
|
|
||||||
|
|
||||||
bool changed = false;
|
|
||||||
bool value = CBox()->GetValue();
|
bool value = CBox()->GetValue();
|
||||||
if ( value != m_startValue )
|
if ( value == m_value )
|
||||||
changed = true;
|
return false;
|
||||||
|
|
||||||
if ( changed )
|
m_value = value;
|
||||||
|
|
||||||
|
if ( newval )
|
||||||
|
*newval = GetValue();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGridCellBoolEditor::ApplyEdit(int row, int col, wxGrid* grid)
|
||||||
{
|
{
|
||||||
wxGridTableBase * const table = grid->GetTable();
|
wxGridTableBase * const table = grid->GetTable();
|
||||||
if ( table->CanSetValueAs(row, col, wxGRID_VALUE_BOOL) )
|
if ( table->CanSetValueAs(row, col, wxGRID_VALUE_BOOL) )
|
||||||
table->SetValueAsBool(row, col, value);
|
table->SetValueAsBool(row, col, m_value);
|
||||||
else
|
else
|
||||||
table->SetValue(row, col, GetValue());
|
table->SetValue(row, col, GetValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxGridCellBoolEditor::Reset()
|
void wxGridCellBoolEditor::Reset()
|
||||||
{
|
{
|
||||||
wxASSERT_MSG(m_control,
|
wxASSERT_MSG(m_control,
|
||||||
wxT("The wxGridCellEditor must be created first!"));
|
wxT("The wxGridCellEditor must be created first!"));
|
||||||
|
|
||||||
CBox()->SetValue(m_startValue);
|
CBox()->SetValue(m_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGridCellBoolEditor::StartingClick()
|
void wxGridCellBoolEditor::StartingClick()
|
||||||
@@ -2123,9 +2142,9 @@ void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
if (evtHandler)
|
if (evtHandler)
|
||||||
evtHandler->SetInSetFocus(true);
|
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();
|
Combo()->SetFocus();
|
||||||
|
|
||||||
@@ -2139,29 +2158,37 @@ void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxGridCellChoiceEditor::EndEdit(int row, int col,
|
bool wxGridCellChoiceEditor::EndEdit(const wxString& WXUNUSED(oldval),
|
||||||
wxGrid* grid)
|
wxString *newval)
|
||||||
{
|
{
|
||||||
wxString value = Combo()->GetValue();
|
const wxString value = Combo()->GetValue();
|
||||||
if ( value == m_startValue )
|
if ( value == m_value )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
grid->GetTable()->SetValue(row, col, value);
|
m_value = value;
|
||||||
|
|
||||||
|
if ( newval )
|
||||||
|
*newval = value;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxGridCellChoiceEditor::ApplyEdit(int row, int col, wxGrid* grid)
|
||||||
|
{
|
||||||
|
grid->GetTable()->SetValue(row, col, m_value);
|
||||||
|
}
|
||||||
|
|
||||||
void wxGridCellChoiceEditor::Reset()
|
void wxGridCellChoiceEditor::Reset()
|
||||||
{
|
{
|
||||||
if (m_allowOthers)
|
if (m_allowOthers)
|
||||||
{
|
{
|
||||||
Combo()->SetValue(m_startValue);
|
Combo()->SetValue(m_value);
|
||||||
Combo()->SetInsertionPointEnd();
|
Combo()->SetInsertionPointEnd();
|
||||||
}
|
}
|
||||||
else // the combobox is read-only
|
else // the combobox is read-only
|
||||||
{
|
{
|
||||||
// find the right position, or default to the first if not found
|
// 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)
|
if (pos == wxNOT_FOUND)
|
||||||
pos = 0;
|
pos = 0;
|
||||||
Combo()->SetSelection(pos);
|
Combo()->SetSelection(pos);
|
||||||
@@ -7105,7 +7132,8 @@ wxGrid::SendEvent(const wxEventType type,
|
|||||||
|
|
||||||
// Generate a grid event of specified type, return value same as above
|
// 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;
|
bool claimed, vetoed;
|
||||||
|
|
||||||
@@ -7121,6 +7149,7 @@ int wxGrid::SendEvent(const wxEventType type, int row, int col)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxGridEvent gridEvt( GetId(), type, this, row, col );
|
wxGridEvent gridEvt( GetId(), type, this, row, col );
|
||||||
|
gridEvt.SetString(s);
|
||||||
|
|
||||||
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
||||||
vetoed = !gridEvt.IsAllowed();
|
vetoed = !gridEvt.IsAllowed();
|
||||||
@@ -8573,7 +8602,6 @@ void wxGrid::EnableCellEditControl( bool enable )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//FIXME:add veto support
|
|
||||||
SendEvent(wxEVT_GRID_EDITOR_HIDDEN);
|
SendEvent(wxEVT_GRID_EDITOR_HIDDEN);
|
||||||
|
|
||||||
HideCellEditControl();
|
HideCellEditControl();
|
||||||
@@ -8806,19 +8834,26 @@ void wxGrid::SaveEditControlValue()
|
|||||||
|
|
||||||
wxGridCellAttr* attr = GetCellAttr(row, col);
|
wxGridCellAttr* attr = GetCellAttr(row, col);
|
||||||
wxGridCellEditor* editor = attr->GetEditor(this, row, col);
|
wxGridCellEditor* editor = attr->GetEditor(this, row, col);
|
||||||
bool changed = editor->EndEdit(row, col, this);
|
|
||||||
|
|
||||||
editor->DecRef();
|
wxString newval;
|
||||||
attr->DecRef();
|
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.
|
// Event has been vetoed, set the data back.
|
||||||
SetCellValue(row, col, oldval);
|
SetCellValue(row, col, oldval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editor->DecRef();
|
||||||
|
attr->DecRef();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -225,7 +225,7 @@ void wxGridCellEnumRenderer::SetParameters(const wxString& params)
|
|||||||
wxGridCellEnumEditor::wxGridCellEnumEditor(const wxString& choices)
|
wxGridCellEnumEditor::wxGridCellEnumEditor(const wxString& choices)
|
||||||
:wxGridCellChoiceEditor()
|
:wxGridCellChoiceEditor()
|
||||||
{
|
{
|
||||||
m_startint = -1;
|
m_index = -1;
|
||||||
|
|
||||||
if (!choices.empty())
|
if (!choices.empty())
|
||||||
SetParameters(choices);
|
SetParameters(choices);
|
||||||
@@ -234,7 +234,7 @@ wxGridCellEnumEditor::wxGridCellEnumEditor(const wxString& choices)
|
|||||||
wxGridCellEditor *wxGridCellEnumEditor::Clone() const
|
wxGridCellEditor *wxGridCellEnumEditor::Clone() const
|
||||||
{
|
{
|
||||||
wxGridCellEnumEditor *editor = new wxGridCellEnumEditor();
|
wxGridCellEnumEditor *editor = new wxGridCellEnumEditor();
|
||||||
editor->m_startint = m_startint;
|
editor->m_index = m_index;
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,40 +247,49 @@ void wxGridCellEnumEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
|
|
||||||
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
|
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
|
||||||
{
|
{
|
||||||
m_startint = table->GetValueAsLong(row, col);
|
m_index = table->GetValueAsLong(row, col);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxString startValue = table->GetValue(row, col);
|
wxString startValue = table->GetValue(row, col);
|
||||||
if (startValue.IsNumber() && !startValue.empty())
|
if (startValue.IsNumber() && !startValue.empty())
|
||||||
{
|
{
|
||||||
startValue.ToLong(&m_startint);
|
startValue.ToLong(&m_index);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_startint=-1;
|
m_index = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Combo()->SetSelection(m_startint);
|
Combo()->SetSelection(m_index);
|
||||||
Combo()->SetInsertionPointEnd();
|
Combo()->SetInsertionPointEnd();
|
||||||
Combo()->SetFocus();
|
Combo()->SetFocus();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxGridCellEnumEditor::EndEdit(int row, int col, wxGrid* grid)
|
bool wxGridCellEnumEditor::EndEdit(const wxString& WXUNUSED(oldval),
|
||||||
|
wxString *newval)
|
||||||
{
|
{
|
||||||
int pos = Combo()->GetSelection();
|
long idx = Combo()->GetSelection();
|
||||||
bool changed = (pos != m_startint);
|
if ( idx == m_index )
|
||||||
if (changed)
|
return false;
|
||||||
{
|
|
||||||
if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER))
|
m_index = idx;
|
||||||
grid->GetTable()->SetValueAsLong(row, col, pos);
|
|
||||||
else
|
if ( newval )
|
||||||
grid->GetTable()->SetValue(row, col,wxString::Format(wxT("%i"),pos));
|
newval->Printf("%ld", m_index);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
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
|
#endif // wxUSE_COMBOBOX
|
||||||
|
Reference in New Issue
Block a user