X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4797b0145c81236c08cdee4f05e616ef17924a50..40ae960071c5d74e167c7fd596122ed7d9e766b9:/include/wx/generic/grid.h diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index eb0932154c..c9ee2e7143 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -327,13 +327,26 @@ public: // 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; @@ -410,7 +423,8 @@ public: 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); @@ -436,7 +450,7 @@ protected: private: size_t m_maxChars; // max number of chars allowed - wxString m_startValue; + wxString m_value; DECLARE_NO_COPY_CLASS(wxGridCellTextEditor) }; @@ -455,7 +469,8 @@ public: 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); @@ -484,15 +499,15 @@ protected: #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) }; @@ -509,7 +524,8 @@ public: 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); @@ -521,13 +537,13 @@ public: 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) }; @@ -551,7 +567,8 @@ public: 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(); @@ -577,7 +594,7 @@ protected: wxCheckBox *CBox() const { return (wxCheckBox *)m_control; } private: - bool m_startValue; + bool m_value; static wxString ms_stringValues[2]; @@ -606,7 +623,8 @@ public: 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(); @@ -621,10 +639,7 @@ public: 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; @@ -1485,8 +1500,10 @@ public: // int GetDefaultRowSize() const; int GetRowSize( int row ) const; + bool IsRowShown(int row) const { return GetRowSize(row) != 0; } int GetDefaultColSize() const; int GetColSize( int col ) const; + bool IsColShown(int col) const { return GetColSize(col) != 0; } wxColour GetDefaultCellBackgroundColour() const; wxColour GetCellBackgroundColour( int row, int col ) const; wxColour GetDefaultCellTextColour() const; @@ -1530,6 +1547,10 @@ public: // only the display and hit testing code really cares about display // positions at all + // set the positions of all columns at once (this method uses the same + // conventions as wxHeaderCtrl::SetColumnsOrder() for the order array) + void SetColumnsOrder(const wxArrayInt& order); + // return the column index corresponding to the given (valid) position int GetColAt(int pos) const { @@ -1747,6 +1768,17 @@ public: wxWindow* GetGridColLabelWindow() const { return m_colWindow; } wxWindow* GetGridCornerLabelWindow() const { return (wxWindow*)m_cornerLabelWin; } + // This one can only be called if we are using the native header window + wxHeaderCtrl *GetGridColHeader() const + { + wxASSERT_MSG( m_useNativeHeader, "no column header window" ); + + // static_cast<> doesn't work without the full class declaration in + // view and we prefer to avoid adding more compile-time dependencies + // even at the cost of using reinterpret_cast<> + return reinterpret_cast(m_colWindow); + } + // Allow adjustment of scroll increment. The default is (15, 15). void SetScrollLineX(int x) { m_scrollLineX = x; } void SetScrollLineY(int y) { m_scrollLineY = y; } @@ -1970,16 +2002,6 @@ protected: // wxGridColLabelWindow, use accessors below when the real type matters wxWindow *m_colWindow; - wxHeaderCtrl *GetColHeader() const - { - wxASSERT_MSG( m_useNativeHeader, "no column header window" ); - - // static_cast<> doesn't work without the full class declaration in - // view and we prefer to avoid adding more compile-time dependencies - // even at the cost of using reinterpret_cast<> - return reinterpret_cast(m_colWindow); - } - wxGridColLabelWindow *GetColLabelWindow() const { wxASSERT_MSG( !m_useNativeHeader, "no column label window" ); @@ -2226,11 +2248,15 @@ protected: 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& ); @@ -2652,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_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; @@ -2661,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_SORT; - typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&); typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&); typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&); @@ -2704,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_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) @@ -2726,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_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;