// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-
#include "wx/defs.h"
#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
#include "wx/string.h"
#include "wx/scrolbar.h"
#include "wx/event.h"
-#include "wx/textctrl.h"
#include "wx/combobox.h"
#include "wx/dynarray.h"
#include "wx/timer.h"
class WXDLLEXPORT wxGridTableBase;
class WXDLLEXPORT wxGridWindow;
+class WXDLLEXPORT wxCheckBox;
+class WXDLLEXPORT wxTextCtrl;
+
// ----------------------------------------------------------------------------
// wxGridCellRenderer: this class is responsible for actually drawing the cell
// in the grid. You may pass it to the wxGridCellAttr (below) to change the
bool isSelected);
};
+// renderer for boolean fields
+class WXDLLEXPORT wxGridCellBoolRenderer : public wxGridCellRenderer
+{
+public:
+
+ // draw a check mark or nothing
+ virtual void Draw(wxGrid& grid,
+ wxGridCellAttr& attr,
+ wxDC& dc,
+ const wxRect& rect,
+ int row, int col,
+ bool isSelected);
+};
// ----------------------------------------------------------------------------
// wxGridCellEditor: This class is responsible for providing and manipulating
// Size and position the edit control
virtual void SetSize(const wxRect& rect);
- // Show or hide the edit control
- virtual void Show(bool show);
+ // Show or hide the edit control, use the specified attributes to set
+ // colours/fonts for it
+ virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
+
+ // Draws the part of the cell not occupied by the control: the base class
+ // version just fills it with background colour from the attribute
+ virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
// 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,
- wxGridCellAttr* attr) = 0;
+ virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
// Complete the editing of the current cell. If saveValue is
// true then send the new value back to the table. Returns true
// if the value has changed. If necessary, the control may be
// destroyed.
- virtual bool EndEdit(int row, int col, bool saveValue,
- wxGrid* grid, wxGridCellAttr* attr) = 0;
+ virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid) = 0;
// Reset the value in the control back to its starting value
virtual void Reset() = 0;
// that first key if desired.
virtual void StartingKey(wxKeyEvent& event);
+ // if the editor is enabled by clicking on the cell, this method will be
+ // called
+ virtual void StartingClick();
+
// Some types of controls on some platforms may need some help
// with the Return key.
virtual void HandleReturn(wxKeyEvent& event);
virtual void Destroy();
protected:
+ // the control we show on screen
wxControl* m_control;
-};
+ // if we change the colours/font of the control from the default ones, we
+ // must restore the default later and we save them here between calls to
+ // Show(TRUE) and Show(FALSE)
+ wxColour m_colFgOld,
+ m_colBgOld;
+ wxFont m_fontOld;
+};
+// the editor for string/text data
class WXDLLEXPORT wxGridCellTextEditor : public wxGridCellEditor
{
public:
wxWindowID id,
wxEvtHandler* evtHandler);
- virtual void BeginEdit(int row, int col, wxGrid* grid,
- wxGridCellAttr* attr);
+ virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
- virtual bool EndEdit(int row, int col, bool saveValue,
- wxGrid* grid, wxGridCellAttr* attr);
+ virtual void BeginEdit(int row, int col, wxGrid* grid);
+ virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid);
virtual void Reset();
virtual void StartingKey(wxKeyEvent& event);
virtual void HandleReturn(wxKeyEvent& event);
+protected:
+ wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
private:
wxString m_startValue;
};
+// the editor for boolean data
+class WXDLLEXPORT wxGridCellBoolEditor : public wxGridCellEditor
+{
+public:
+ virtual void Create(wxWindow* parent,
+ wxWindowID id,
+ wxEvtHandler* evtHandler);
+
+ virtual void SetSize(const wxRect& rect);
+ virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
+
+ virtual void BeginEdit(int row, int col, wxGrid* grid);
+ virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid);
+
+ virtual void Reset();
+ virtual void StartingClick();
+
+protected:
+ wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
+
+private:
+ bool m_startValue;
+};
+
// ----------------------------------------------------------------------------
// wxGridCellAttr: this class can be used to alter the cells appearance in
// the grid by changing their colour/font/... from default. An object of this
SetAlignment(0, 0);
}
+ // VZ: considering the number of members wxGridCellAttr has now, this ctor
+ // seems to be pretty useless... may be we should just remove it?
wxGridCellAttr(const wxColour& colText,
const wxColour& colBack,
const wxFont& font,
m_hAlign = hAlign;
m_vAlign = vAlign;
}
+ void SetReadOnly(bool isReadOnly = TRUE) { m_isReadOnly = isReadOnly; }
// takes ownership of the pointer
void SetRenderer(wxGridCellRenderer *renderer)
wxGridCellRenderer *GetRenderer() const;
wxGridCellEditor *GetEditor() const;
+ bool IsReadOnly() const { return m_isReadOnly; }
+
void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; }
private:
// the common part of all ctors
- void Init() {
+ void Init()
+ {
m_nRef = 1;
+
+ m_isReadOnly = FALSE;
+
m_renderer = NULL;
m_editor = NULL;
}
wxGridCellEditor* m_editor;
wxGridCellAttr* m_defGridAttr;
+ bool m_isReadOnly;
+
// suppress the stupid gcc warning about the class having private dtor and
// no friends
friend class wxGridCellAttrDummyFriend;
virtual void SetAttr(wxGridCellAttr *attr, int row, int col);
virtual void SetRowAttr(wxGridCellAttr *attr, int row);
virtual void SetColAttr(wxGridCellAttr *attr, int col);
+
+ // these functions must be called whenever some rows/cols are deleted
+ // because the internal data must be updated then
void UpdateAttrRows( size_t pos, int numRows );
void UpdateAttrCols( size_t pos, int numCols );
return *this;
}
- bool operator==( const wxGridCellCoords& other )
+ bool operator==( const wxGridCellCoords& other ) const
{
return (m_row == other.m_row && m_col == other.m_col);
}
- bool operator!=( const wxGridCellCoords& other )
+ bool operator!=( const wxGridCellCoords& other ) const
{
return (m_row != other.m_row || m_col != other.m_col);
}
- bool operator!()
+ bool operator!() const
{
return (m_row == -1 && m_col == -1 );
}
void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
void DrawCell( wxDC& dc, const wxGridCellCoords& );
- void DrawCellHighlight( wxDC& dc );
+ void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
void DrawRowLabels( wxDC& dc );
void DrawRowLabel( wxDC& dc, int row );
bool IsEditable() { return m_editable; }
void EnableEditing( bool edit );
- void EnableCellEditControl( bool enable );
+ void EnableCellEditControl( bool enable = TRUE );
+ void DisableCellEditControl() { EnableCellEditControl(FALSE); }
+ bool CanEnableCellControl() const;
+ bool IsCellEditControlEnabled() const;
- bool IsCellEditControlEnabled()
- { return m_cellEditCtrlEnabled; }
+ bool IsCurrentCellReadOnly() const;
void ShowCellEditControl();
void HideCellEditControl();
wxGridCellRenderer *GetDefaultRenderer() const;
wxGridCellRenderer* GetCellRenderer(int row, int col);
- // takes ownership of the pointer
+ // takes ownership of the pointer
void SetDefaultEditor(wxGridCellEditor *editor);
void SetCellEditor(int row, int col, wxGridCellEditor *editor);
wxGridCellEditor *GetDefaultEditor() const;
void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
{ SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
+ // returns TRUE if the cell can't be edited
+ bool IsReadOnly(int row, int col) const;
+ // make the cell editable/readonly
+ void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
// ------ selections of blocks of cells
//
wxGRID_CHOICE,
wxGRID_COMBOBOX };
+ // for wxGridCellBoolEditor
+ wxWindow *GetGridWindow() const;
+
protected:
bool m_created;
bool m_displayed;
wxCursor m_rowResizeCursor;
wxCursor m_colResizeCursor;
- bool m_editable; // applies to whole grid
- bool m_cellEditCtrlEnabled;
+ bool m_editable; // applies to whole grid
+ bool m_cellEditCtrlEnabled; // is in-place edit currently shown?
void Create();
bool Redimension( wxGridTableMessage& );
- bool SendEvent( const wxEventType,
- int row, int col,
- wxMouseEvent& );
-
- bool SendEvent( const wxEventType,
- int row, int col );
-
+ bool SendEvent( const wxEventType, int row, int col, wxMouseEvent& );
+ bool SendEvent( const wxEventType, int row, int col );
+ bool SendEvent( const wxEventType type)
+ {
+ return SendEvent(type,
+ m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol());
+ }
void OnPaint( wxPaintEvent& );
void OnSize( wxSizeEvent& );
DECLARE_DYNAMIC_CLASS(wxGridEvent)
};
-
class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent
{
public:
DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent)
};
-
-const wxEventType EVT_GRID_CELL_LEFT_CLICK = wxEVT_FIRST + 1580;
-const wxEventType EVT_GRID_CELL_RIGHT_CLICK = wxEVT_FIRST + 1581;
-const wxEventType EVT_GRID_CELL_LEFT_DCLICK = wxEVT_FIRST + 1582;
-const wxEventType EVT_GRID_CELL_RIGHT_DCLICK = wxEVT_FIRST + 1583;
-const wxEventType EVT_GRID_LABEL_LEFT_CLICK = wxEVT_FIRST + 1584;
-const wxEventType EVT_GRID_LABEL_RIGHT_CLICK = wxEVT_FIRST + 1585;
-const wxEventType EVT_GRID_LABEL_LEFT_DCLICK = wxEVT_FIRST + 1586;
-const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK = wxEVT_FIRST + 1587;
-const wxEventType EVT_GRID_ROW_SIZE = wxEVT_FIRST + 1588;
-const wxEventType EVT_GRID_COL_SIZE = wxEVT_FIRST + 1589;
-const wxEventType EVT_GRID_RANGE_SELECT = wxEVT_FIRST + 1590;
-const wxEventType EVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1591;
-const wxEventType EVT_GRID_SELECT_CELL = wxEVT_FIRST + 1592;
+// TODO move to wx/event.h
+const wxEventType wxEVT_GRID_CELL_LEFT_CLICK = wxEVT_FIRST + 1580;
+const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK = wxEVT_FIRST + 1581;
+const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK = wxEVT_FIRST + 1582;
+const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK = wxEVT_FIRST + 1583;
+const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK = wxEVT_FIRST + 1584;
+const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK = wxEVT_FIRST + 1585;
+const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK = wxEVT_FIRST + 1586;
+const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK = wxEVT_FIRST + 1587;
+const wxEventType wxEVT_GRID_ROW_SIZE = wxEVT_FIRST + 1588;
+const wxEventType wxEVT_GRID_COL_SIZE = wxEVT_FIRST + 1589;
+const wxEventType wxEVT_GRID_RANGE_SELECT = wxEVT_FIRST + 1590;
+const wxEventType wxEVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1591;
+const wxEventType wxEVT_GRID_SELECT_CELL = wxEVT_FIRST + 1592;
+const wxEventType wxEVT_GRID_EDITOR_SHOWN = wxEVT_FIRST + 1593;
+const wxEventType wxEVT_GRID_EDITOR_HIDDEN = wxEVT_FIRST + 1594;
typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
-#define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
-#define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
-#define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
-#define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CELL_LEFT_CLICK(fn) { wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CELL_RIGHT_CLICK(fn) { wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CELL_LEFT_DCLICK(fn) { wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CELL_RIGHT_DCLICK(fn) { wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_LABEL_LEFT_CLICK(fn) { wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_LABEL_RIGHT_CLICK(fn) { wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_LABEL_LEFT_DCLICK(fn) { wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_ROW_SIZE(fn) { wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
+#define EVT_GRID_COL_SIZE(fn) { wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
+#define EVT_GRID_RANGE_SELECT(fn) { wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
+#define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_EDITOR_SHOWN(fn) { wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_EDITOR_HIDDEN(fn) { wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
#if 0 // TODO: implement these ? others ?
-const wxEventType EVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576;
-const wxEventType EVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577;
-const wxEventType EVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578;
+const wxEventType wxEVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576;
+const wxEventType wxEVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577;
+const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578;
-#define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
-#define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
#endif