]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/gridg.h
headers are now installed by automake too
[wxWidgets.git] / include / wx / generic / gridg.h
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: gridg.h
3// Purpose: wxGenericGrid
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c)
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef __GRIDH_G__
13#define __GRIDH_G__
14
15#ifdef __GNUG__
16#pragma interface "gridg.h"
17#endif
18
19#include "wx/defs.h"
20#include "wx/panel.h"
21#include "wx/string.h"
22#include "wx/scrolbar.h"
1f481e6a 23#include "wx/event.h"
c801d85f
KB
24
25#define wxGRID_DEFAULT_EDIT_WIDTH 300
26#define wxGRID_DEFAULT_EDIT_HEIGHT 27
903f689b 27#define wxGRID_DEFAULT_EDIT_X 2
c801d85f
KB
28#define wxGRID_DEFAULT_EDIT_Y 1
29#define wxGRID_DEFAULT_SHEET_TOP 31
30#define wxGRID_DEFAULT_SHEET_LEFT 0
31#define wxGRID_DEFAULT_CELL_HEIGHT 20
32#define wxGRID_DEFAULT_CELL_WIDTH 80
33#define wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH 40
34#define wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT 20
35
36#ifndef wxLEFT
37#define wxLEFT 0x0400
38#endif
39
40#ifndef wxRIGHT
41#define wxRIGHT 0x0800
42#endif
43
1f481e6a 44#define WXGENERIC_GRID_VERSION 0.5
c801d85f 45
1f481e6a 46class WXDLLEXPORT wxGridEvent;
c801d85f
KB
47class WXDLLEXPORT wxGridCell;
48class WXDLLEXPORT wxGenericGrid: public wxPanel
49{
50 DECLARE_DYNAMIC_CLASS(wxGenericGrid)
c801d85f
KB
51 public:
52 wxGenericGrid(void);
53
debe6624 54 inline wxGenericGrid(wxWindow *parent, int x, int y, int width, int height, long style = 0, char *name = "grid")
c801d85f
KB
55 {
56 Create(parent, -1, wxPoint(x, y), wxSize(width, height), style, name);
57 }
ad95e0f6 58 inline wxGenericGrid(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style = 0, const wxString& name = "grid")
c801d85f
KB
59 {
60 Create(parent, id, pos, size, style, name);
61 }
62 ~wxGenericGrid(void);
63
64 void OnPaint(wxPaintEvent& event);
ad95e0f6 65 void OnEraseBackground(wxEraseEvent& event);
c801d85f
KB
66 void OnMouseEvent(wxMouseEvent& event);
67 void OnSize(wxSizeEvent& event);
68
ad95e0f6 69 bool Create(wxWindow *parent, wxWindowID, const wxPoint& pos, const wxSize& size, long style = 0, const wxString& name = "grid");
c801d85f 70
c67daf87 71 bool CreateGrid(int nRows, int nCols, wxString **cellValues = (wxString **) NULL, short *widths = (short *) NULL,
c801d85f 72 short defaultWidth = wxGRID_DEFAULT_CELL_WIDTH, short defaultHeight = wxGRID_DEFAULT_CELL_HEIGHT);
ad95e0f6 73 void PaintGrid(wxDC& dc);
c801d85f 74 void ClearGrid(void);
c0ed460c
JS
75 virtual wxGridCell *GetCell(int row, int col) const;
76 inline wxGridCell ***GetCells(void) const { return m_gridCells; }
c801d85f
KB
77 bool InsertCols(int pos = 0, int n = 1, bool updateLabels = TRUE);
78 bool InsertRows(int pos = 0, int n = 1, bool updateLabels = TRUE);
79 bool AppendCols(int n = 1, bool updateLabels = TRUE);
80 bool AppendRows(int n = 1, bool updateLabels = TRUE);
81 bool DeleteCols(int pos = 0, int n = 1, bool updateLabels = TRUE);
82 bool DeleteRows(int pos = 0, int n = 1, bool updateLabels = TRUE);
83
84 // Cell accessors
85 void SetCellValue(const wxString& val, int row, int col);
c0ed460c 86 wxString& GetCellValue(int row, int col) const;
c801d85f
KB
87 void SetCellAlignment(int flag, int row, int col);
88 void SetCellAlignment(int flag);
c0ed460c
JS
89 int GetCellAlignment(int row, int col) const;
90 int GetCellAlignment(void) const;
c801d85f
KB
91 void SetCellTextColour(const wxColour& val, int row, int col);
92 void SetCellTextColour(const wxColour& col);
c0ed460c
JS
93 wxColour& GetCellTextColour(int row, int col) const;
94 inline wxColour& GetCellTextColour(void) const { return (wxColour&) m_cellTextColour; }
c801d85f
KB
95 void SetCellBackgroundColour(const wxColour& col);
96 void SetCellBackgroundColour(const wxColour& colour, int row, int col);
c0ed460c
JS
97 inline wxColour& GetCellBackgroundColour(void) const { return (wxColour&) m_cellBackgroundColour; }
98 wxColour& GetCellBackgroundColour(int row, int col) const;
99 inline wxFont& GetCellTextFont(void) const { return (wxFont&) m_cellTextFont; }
100 wxFont& GetCellTextFont(int row, int col) const;
101 void SetCellTextFont(const wxFont& fnt);
102 void SetCellTextFont(const wxFont& fnt, int row, int col);
103 wxBitmap *GetCellBitmap(int row, int col) const;
c801d85f 104 void SetCellBitmap(wxBitmap *bitmap, int row, int col);
1f481e6a 105
c801d85f
KB
106 // Size accessors
107 void SetColumnWidth(int col, int width);
c0ed460c 108 int GetColumnWidth(int col) const;
c801d85f 109 void SetRowHeight(int row, int height);
c0ed460c 110 int GetRowHeight(int row) const;
1f481e6a 111
c801d85f
KB
112 // Label accessors
113 void SetLabelSize(int orientation, int sz);
c0ed460c 114 int GetLabelSize(int orientation) const;
c801d85f 115 void SetLabelAlignment(int orientation, int alignment);
c0ed460c
JS
116 int GetLabelAlignment(int orientation) const;
117 wxGridCell *GetLabelCell(int orientation, int pos) const;
c801d85f 118 void SetLabelValue(int orientation, const wxString& val, int pos);
c0ed460c 119 wxString& GetLabelValue(int orientation, int pos) const;
c801d85f
KB
120 void SetLabelTextColour(const wxColour& colour);
121 void SetLabelBackgroundColour(const wxColour& colour);
c0ed460c
JS
122 inline wxColour& GetLabelTextColour(void) const { return (wxColour&) m_labelTextColour; }
123 inline wxColour& GetLabelBackgroundColour(void) { return (wxColour&) m_labelBackgroundColour; }
124 inline wxFont& GetLabelTextFont(void) { return (wxFont&) m_labelTextFont; }
125 inline void SetLabelTextFont(const wxFont& fnt) { m_labelTextFont = fnt; }
c801d85f
KB
126
127 // Miscellaneous accessors
c0ed460c
JS
128 inline int GetCursorRow(void) const { return m_wCursorRow; }
129 inline int GetCursorColumn(void) const { return m_wCursorColumn; }
c801d85f 130 void SetGridCursor(int row, int col);
c0ed460c
JS
131 inline int GetRows(void) const { return m_totalRows; }
132 inline int GetCols(void) const { return m_totalCols; }
133 inline int GetScrollPosX(void) const { return m_scrollPosX; }
134 inline int GetScrollPosY(void) const { return m_scrollPosY; }
ad95e0f6
JS
135 inline void SetScrollPosX(int pos) { m_scrollPosX = pos; }
136 inline void SetScrollPosY(int pos) { m_scrollPosY = pos; }
c0ed460c
JS
137 inline wxTextCtrl *GetTextItem(void) const { return m_textItem; }
138 inline wxScrollBar *GetHorizScrollBar(void) const { return m_hScrollBar; }
139 inline wxScrollBar *GetVertScrollBar(void) const { return m_vScrollBar; }
140 inline bool GetEditable(void) const { return m_editable; }
c801d85f 141 void SetEditable(bool edit);
c0ed460c
JS
142 inline wxRect& GetCurrentRect(void) const { return (wxRect&) m_currentRect; }
143 inline bool CurrentCellVisible(void) const { return m_currentRectVisible; }
144 inline void SetDividerPen(const wxPen& pen) { m_divisionPen = pen; }
145 inline wxPen& GetDividerPen(void) const { return (wxPen&) m_divisionPen; }
ad95e0f6 146
c801d85f
KB
147 // High-level event handling
148 // Override e.g. to check value of current cell; but call
149 // base member for default processing.
150 virtual void OnSelectCellImplementation(wxDC *dc, int row, int col);
151
152 virtual void OnSelectCell(int WXUNUSED(row), int WXUNUSED(col)) {};
031b2a7b 153 void _OnSelectCell(wxGridEvent& event);
c801d85f
KB
154
155 // Override to create your own class of grid cell
156 virtual wxGridCell *OnCreateCell(void);
031b2a7b 157 void _OnCreateCell(wxGridEvent& event);
1f481e6a 158
c801d85f
KB
159 // Override to change labels e.g. creation of grid, inserting/deleting a row/col.
160 // By default, auto-labels the grid.
161 virtual void OnChangeLabels(void);
031b2a7b 162 void _OnChangeLabels(wxGridEvent& event);
c801d85f
KB
163
164 // Override to change the label of the edit field when selecting a cell
165 // By default, sets it to e.g. A12
166 virtual void OnChangeSelectionLabel(void);
031b2a7b 167 void _OnChangeSelectionLabel(wxGridEvent& event);
1f481e6a 168
c801d85f
KB
169 // Override for event processing
170 virtual void OnCellChange(int WXUNUSED(row), int WXUNUSED(col)) {};
171 virtual void OnCellLeftClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
172 virtual void OnCellRightClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
173 virtual void OnLabelLeftClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
174 virtual void OnLabelRightClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
175
031b2a7b
RR
176 void _OnCellChange(wxGridEvent& event);
177 void _OnCellLeftClick(wxGridEvent& event);
178 void _OnCellRightClick(wxGridEvent& event);
179 void _OnLabelLeftClick(wxGridEvent& event);
180 void _OnLabelRightClick(wxGridEvent& event);
1f481e6a 181
c801d85f
KB
182 // Activation: call from wxFrame::OnActivate
183 void OnActivate(bool active);
184
185 // Miscellaneous
186 void AdjustScrollbars(void);
187 void UpdateDimensions(void);
188
189 /* INTERNAL
190 */
191 void SetCurrentRect (int Row, int Column, int canvasW = -1, int canvasH = -1);
192 void HighlightCell (wxDC *dc);
193 void DrawCellText(void);
194 void SetGridClippingRegion(wxDC *dc);
195 virtual bool CellHitTest(int x, int y, int *row, int *col);
196 virtual bool LabelSashHitTest(int x, int y, int *orientation, int *rowOrCol, int *startPos);
197 virtual bool LabelHitTest(int x, int y, int *row, int *col);
198 // Painting
199 virtual void DrawLabelAreas(wxDC *dc);
200 virtual void DrawEditableArea(wxDC *dc);
201 virtual void DrawGridLines(wxDC *dc);
202 virtual void DrawColumnLabels(wxDC *dc);
16e93305 203 virtual void DrawColumnLabel(wxDC *dc, wxRect *rect, int col);
c801d85f 204 virtual void DrawRowLabels(wxDC *dc);
16e93305 205 virtual void DrawRowLabel(wxDC *dc, wxRect *rect, int row);
c801d85f 206 virtual void DrawCells(wxDC *dc);
16e93305
JS
207 virtual void DrawCellValue(wxDC *dc, wxRect *rect, int row, int col);
208 virtual void DrawCellBackground(wxDC *dc, wxRect *rect, int row, int col);
209 virtual void DrawTextRect(wxDC *dc, const wxString& text, wxRect *rect, int flag);
210 virtual void DrawBitmapRect(wxDC *dc, wxBitmap *bitmap, wxRect *rect, int flag);
c801d85f
KB
211
212 // Refresh cell and optionally set the text field
213 void RefreshCell(int row, int col, bool setText = FALSE);
214
215 // Don't refresh within the outer pair of these.
ad95e0f6
JS
216 inline void BeginBatch(void) { m_batchCount ++; }
217 inline void EndBatch(void) { m_batchCount --; }
218 inline int GetBatchCount(void) { return m_batchCount; }
c801d85f
KB
219
220 void OnText(wxCommandEvent& ev);
221 void OnGridScroll(wxScrollEvent& ev);
222
ad95e0f6
JS
223 protected:
224 wxPanel* m_editingPanel; // Contains the text control
225 wxTextCtrl* m_textItem;
226 wxScrollBar* m_hScrollBar;
227 wxScrollBar* m_vScrollBar;
228 int m_wCursorRow;
229 int m_wCursorColumn;
c0ed460c 230 wxRect m_currentRect;
ad95e0f6
JS
231 bool m_currentRectVisible;
232 wxGridCell*** m_gridCells;
233 wxGridCell** m_rowLabelCells;
234 wxGridCell** m_colLabelCells;
235 bool m_editCreated;
236 bool m_editable;
237
238 int m_totalRows;
239 int m_totalCols;
1f481e6a 240
ad95e0f6
JS
241 // Row and column we're currently looking at
242 int m_scrollPosX;
243 int m_scrollPosY;
244
245 // Dimensions
246 int m_leftOfSheet;
247 int m_topOfSheet;
248 int m_rightOfSheet; // Calculated from m_colWidths
249 int m_bottomOfSheet; // Calculated from m_rowHeights
250 int m_totalGridWidth; // Total 'virtual' size
251 int m_totalGridHeight;
252 int m_cellHeight; // For now, a default
253 int m_verticalLabelWidth;
254 int m_horizontalLabelHeight;
255 int m_verticalLabelAlignment;
256 int m_horizontalLabelAlignment;
257 int m_cellAlignment;
258 short* m_colWidths; // Dynamically allocated
259 short* m_rowHeights; // Dynamically allocated
260 int m_scrollWidth; // Vert. scroll width, horiz. scroll height
1f481e6a 261
ad95e0f6
JS
262 // Colours
263 wxColour m_cellTextColour;
264 wxColour m_cellBackgroundColour;
c0ed460c 265 wxFont m_cellTextFont;
ad95e0f6
JS
266 wxColour m_labelTextColour;
267 wxColour m_labelBackgroundColour;
c0ed460c
JS
268 wxBrush m_labelBackgroundBrush;
269 wxFont m_labelTextFont;
270 wxPen m_divisionPen;
ad95e0f6
JS
271 wxBitmap* m_doubleBufferingBitmap;
272
273 // Position of Edit control
c0ed460c 274 wxRect m_editControlPosition;
1f481e6a 275
ad95e0f6
JS
276 // Drag status
277 int m_dragStatus;
278 int m_dragRowOrCol;
279 int m_dragStartPosition;
280 int m_dragLastPosition;
c0ed460c
JS
281 wxCursor m_horizontalSashCursor;
282 wxCursor m_verticalSashCursor;
ad95e0f6
JS
283
284 // To avoid multiple refreshes, use Begin/EndBatch
285 int m_batchCount;
286
c801d85f
KB
287DECLARE_EVENT_TABLE()
288};
289
290#define wxGRID_TEXT_CTRL 2000
291#define wxGRID_HSCROLL 2001
292#define wxGRID_VSCROLL 2002
293
294class WXDLLEXPORT wxGridCell: public wxObject
295{
296 public:
c0ed460c
JS
297 wxString textValue;
298 wxFont font;
299 wxColour textColour;
300 wxColour backgroundColour;
301 wxBrush backgroundBrush;
302 wxBitmap* cellBitmap;
c801d85f
KB
303 int alignment;
304
c67daf87 305 wxGridCell(wxGenericGrid *window = (wxGenericGrid *) NULL);
c801d85f 306 ~wxGridCell(void);
1f481e6a 307
c0ed460c 308 virtual wxString& GetTextValue(void) const { return (wxString&) textValue; }
c801d85f 309 virtual void SetTextValue(const wxString& str) { textValue = str; }
c0ed460c
JS
310 inline wxFont& GetFont(void) const { return (wxFont&) font; }
311 inline void SetFont(const wxFont& f) { font = f; }
312 inline wxColour& GetTextColour(void) const { return (wxColour&) textColour; }
c801d85f 313 inline void SetTextColour(const wxColour& colour) { textColour = colour; }
c0ed460c 314 inline wxColour& GetBackgroundColour(void) const { return (wxColour&) backgroundColour; }
c801d85f 315 void SetBackgroundColour(const wxColour& colour);
c0ed460c
JS
316 inline wxBrush& GetBackgroundBrush(void) const { return (wxBrush&) backgroundBrush; }
317 inline void SetBackgroundBrush(const wxBrush& brush) { backgroundBrush = brush; }
318 inline int GetAlignment(void) const { return alignment; }
c801d85f 319 inline void SetAlignment(int align) { alignment = align; }
c0ed460c 320 inline wxBitmap *GetCellBitmap(void) const { return cellBitmap; }
c801d85f
KB
321 inline void SetCellBitmap(wxBitmap *bitmap) { cellBitmap = bitmap; }
322};
323
324class WXDLLEXPORT wxGrid: public wxGenericGrid
325{
326 public:
327 wxGrid(void):wxGenericGrid() {}
328 wxGrid(wxWindow *parent, int x=-1, int y=-1, int width=-1, int height=-1,
329 long style=0, char *name = "gridWindow"):
330 wxGenericGrid(parent, x, y, width, height, style, name)
331 {
332 }
333};
334
1f481e6a
RD
335class WXDLLEXPORT wxGridEvent : public wxCommandEvent {
336 DECLARE_DYNAMIC_CLASS(wxGridEvent)
337public:
338 wxGridEvent()
339 : wxCommandEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
340 m_control(0), m_shift(0), m_cell(0)
341 {}
342
343 wxGridEvent(int id, wxEventType type, wxObject* obj,
344 int row=-1, int col=-1, int x=-1, int y=-1,
345 bool control=FALSE, bool shift=FALSE)
346 : wxCommandEvent(type, id), m_row(row), m_col(col), m_x(x), m_y(y),
347 m_control(control), m_shift(shift), m_cell(0)
348 {
349 SetEventObject(obj);
350 }
351
352
353 int m_row;
354 int m_col;
355 int m_x;
356 int m_y;
357 bool m_control;
358 bool m_shift;
359 wxGridCell* m_cell;
360};
361
362const wxEventType wxEVT_GRID_SELECT_CELL = wxEVT_FIRST + 1575;
363const wxEventType wxEVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576;
364const wxEventType wxEVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577;
365const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578;
366const wxEventType wxEVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1579;
367const wxEventType wxEVT_GRID_CELL_LCLICK = wxEVT_FIRST + 1580;
368const wxEventType wxEVT_GRID_CELL_RCLICK = wxEVT_FIRST + 1581;
369const wxEventType wxEVT_GRID_LABEL_LCLICK = wxEVT_FIRST + 1582;
370const wxEventType wxEVT_GRID_LABEL_RCLICK = wxEVT_FIRST + 1583;
371
372
373typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
374
375#define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
376#define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
377#define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
378#define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
379#define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
380#define EVT_GRID_CELL_LCLICK(fn) { wxEVT_GRID_CELL_LCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
381#define EVT_GRID_CELL_RCLICK(fn) { wxEVT_GRID_CELL_RCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
382#define EVT_GRID_LABEL_LCLICK(fn) { wxEVT_GRID_LABEL_LCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
383#define EVT_GRID_LABEL_RCLICK(fn) { wxEVT_GRID_LABEL_RCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
384
c801d85f
KB
385#endif
386