#include "wx/panel.h"
#include "wx/string.h"
#include "wx/scrolbar.h"
+#include "wx/event.h"
#define wxGRID_DEFAULT_EDIT_WIDTH 300
#define wxGRID_DEFAULT_EDIT_HEIGHT 27
-#define wxGRID_DEFAULT_EDIT_X 5
+#define wxGRID_DEFAULT_EDIT_X 2
#define wxGRID_DEFAULT_EDIT_Y 1
#define wxGRID_DEFAULT_SHEET_TOP 31
#define wxGRID_DEFAULT_SHEET_LEFT 0
#define wxRIGHT 0x0800
#endif
-#define WXGENERIC_GRID_VERSION 0.4
+#define WXGENERIC_GRID_VERSION 0.5
+class WXDLLEXPORT wxGridEvent;
class WXDLLEXPORT wxGridCell;
class WXDLLEXPORT wxGenericGrid: public wxPanel
{
public:
wxGenericGrid(void);
- inline wxGenericGrid(wxWindow *parent, int x, int y, int width, int height, const long style = 0, char *name = "grid")
+ inline wxGenericGrid(wxWindow *parent, int x, int y, int width, int height, long style = 0, char *name = "grid")
{
Create(parent, -1, wxPoint(x, y), wxSize(width, height), style, name);
}
bool Create(wxWindow *parent, wxWindowID, const wxPoint& pos, const wxSize& size, long style = 0, const wxString& name = "grid");
- bool CreateGrid(int nRows, int nCols, wxString **cellValues = NULL, short *widths = NULL,
+ bool CreateGrid(int nRows, int nCols, wxString **cellValues = (wxString **) NULL, short *widths = (short *) NULL,
short defaultWidth = wxGRID_DEFAULT_CELL_WIDTH, short defaultHeight = wxGRID_DEFAULT_CELL_HEIGHT);
void PaintGrid(wxDC& dc);
void ClearGrid(void);
void SetCellTextFont(wxFont *fnt, int row, int col);
wxBitmap *GetCellBitmap(int row, int col);
void SetCellBitmap(wxBitmap *bitmap, int row, int col);
-
+
// Size accessors
void SetColumnWidth(int col, int width);
int GetColumnWidth(int col);
void SetRowHeight(int row, int height);
int GetRowHeight(int row);
-
+
// Label accessors
void SetLabelSize(int orientation, int sz);
int GetLabelSize(int orientation);
virtual void OnSelectCellImplementation(wxDC *dc, int row, int col);
virtual void OnSelectCell(int WXUNUSED(row), int WXUNUSED(col)) {};
+ void _OnSelectCell(wxGridEvent& event);
// Override to create your own class of grid cell
virtual wxGridCell *OnCreateCell(void);
-
+ void _OnCreateCell(wxGridEvent& event);
+
// Override to change labels e.g. creation of grid, inserting/deleting a row/col.
// By default, auto-labels the grid.
virtual void OnChangeLabels(void);
+ void _OnChangeLabels(wxGridEvent& event);
// Override to change the label of the edit field when selecting a cell
// By default, sets it to e.g. A12
virtual void OnChangeSelectionLabel(void);
-
+ void _OnChangeSelectionLabel(wxGridEvent& event);
+
// Override for event processing
virtual void OnCellChange(int WXUNUSED(row), int WXUNUSED(col)) {};
virtual void OnCellLeftClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
virtual void OnLabelLeftClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
virtual void OnLabelRightClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
+ void _OnCellChange(wxGridEvent& event);
+ void _OnCellLeftClick(wxGridEvent& event);
+ void _OnCellRightClick(wxGridEvent& event);
+ void _OnLabelLeftClick(wxGridEvent& event);
+ void _OnLabelRightClick(wxGridEvent& event);
+
// Activation: call from wxFrame::OnActivate
void OnActivate(bool active);
int m_totalRows;
int m_totalCols;
-
+
// Row and column we're currently looking at
int m_scrollPosX;
int m_scrollPosY;
short* m_colWidths; // Dynamically allocated
short* m_rowHeights; // Dynamically allocated
int m_scrollWidth; // Vert. scroll width, horiz. scroll height
-
+
// Colours
wxColour m_cellTextColour;
wxColour m_cellBackgroundColour;
// Position of Edit control
wxRectangle m_editControlPosition;
-
+
// Drag status
int m_dragStatus;
int m_dragRowOrCol;
wxBitmap *cellBitmap;
int alignment;
- wxGridCell(wxGenericGrid *window = NULL);
+ wxGridCell(wxGenericGrid *window = (wxGenericGrid *) NULL);
~wxGridCell(void);
-
+
virtual wxString& GetTextValue(void) { return textValue; }
virtual void SetTextValue(const wxString& str) { textValue = str; }
inline wxFont *GetFont(void) { return font; }
inline wxColour& GetBackgroundColour(void) { return backgroundColour; }
void SetBackgroundColour(const wxColour& colour);
inline wxBrush *GetBackgroundBrush(void) { return backgroundBrush; }
+ inline void SetBackgroundBrush(wxBrush *brush) { backgroundBrush = brush; }
inline int GetAlignment(void) { return alignment; }
inline void SetAlignment(int align) { alignment = align; }
inline wxBitmap *GetCellBitmap(void) { return cellBitmap; }
}
};
+
+
+
+class WXDLLEXPORT wxGridEvent : public wxCommandEvent {
+ DECLARE_DYNAMIC_CLASS(wxGridEvent)
+public:
+ wxGridEvent()
+ : wxCommandEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
+ m_control(0), m_shift(0), m_cell(0)
+ {}
+
+ wxGridEvent(int id, wxEventType type, wxObject* obj,
+ int row=-1, int col=-1, int x=-1, int y=-1,
+ bool control=FALSE, bool shift=FALSE)
+ : wxCommandEvent(type, id), m_row(row), m_col(col), m_x(x), m_y(y),
+ m_control(control), m_shift(shift), m_cell(0)
+ {
+ SetEventObject(obj);
+ }
+
+
+ int m_row;
+ int m_col;
+ int m_x;
+ int m_y;
+ bool m_control;
+ bool m_shift;
+ wxGridCell* m_cell;
+};
+
+const wxEventType wxEVT_GRID_SELECT_CELL = wxEVT_FIRST + 1575;
+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;
+const wxEventType wxEVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1579;
+const wxEventType wxEVT_GRID_CELL_LCLICK = wxEVT_FIRST + 1580;
+const wxEventType wxEVT_GRID_CELL_RCLICK = wxEVT_FIRST + 1581;
+const wxEventType wxEVT_GRID_LABEL_LCLICK = wxEVT_FIRST + 1582;
+const wxEventType wxEVT_GRID_LABEL_RCLICK = wxEVT_FIRST + 1583;
+
+
+typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
+
+#define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -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 },
+#define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CELL_LCLICK(fn) { wxEVT_GRID_CELL_LCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_CELL_RCLICK(fn) { wxEVT_GRID_CELL_RCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_LABEL_LCLICK(fn) { wxEVT_GRID_LABEL_LCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+#define EVT_GRID_LABEL_RCLICK(fn) { wxEVT_GRID_LABEL_RCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
+
#endif