]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/gridg.h
Reduced flicker by a combination of less background erasing, and double-buffering.
[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"
23
24#define wxGRID_DEFAULT_EDIT_WIDTH 300
25#define wxGRID_DEFAULT_EDIT_HEIGHT 27
26#define wxGRID_DEFAULT_EDIT_X 5
27#define wxGRID_DEFAULT_EDIT_Y 1
28#define wxGRID_DEFAULT_SHEET_TOP 31
29#define wxGRID_DEFAULT_SHEET_LEFT 0
30#define wxGRID_DEFAULT_CELL_HEIGHT 20
31#define wxGRID_DEFAULT_CELL_WIDTH 80
32#define wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH 40
33#define wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT 20
34
35#ifndef wxLEFT
36#define wxLEFT 0x0400
37#endif
38
39#ifndef wxRIGHT
40#define wxRIGHT 0x0800
41#endif
42
43#define WXGENERIC_GRID_VERSION 0.4
44
45class WXDLLEXPORT wxGridCell;
46class WXDLLEXPORT wxGenericGrid: public wxPanel
47{
48 DECLARE_DYNAMIC_CLASS(wxGenericGrid)
49 protected:
50 wxTextCtrl *textItem;
51 wxScrollBar *hScrollBar;
52 wxScrollBar *vScrollBar;
53 int wCursorRow;
54 int wCursorColumn;
55 wxRectangle CurrentRect;
56 bool currentRectVisible;
57 wxGridCell ***gridCells;
58 wxGridCell **rowLabelCells;
59 wxGridCell **colLabelCells;
60 bool bEditCreated;
61 bool editable;
62
63 int totalRows;
64 int totalCols;
65
66 // Row and column we're currently looking at
67 int scrollPosX;
68 int scrollPosY;
69
70 // Dimensions
71 int leftOfSheet;
72 int topOfSheet;
73 int rightOfSheet; // Calculated from colWidths
74 int bottomOfSheet; // Calculated from rowHeights
75 int totalGridWidth; // Total 'virtual' size
76 int totalGridHeight;
77 int cellHeight; // For now, a default
78 int verticalLabelWidth;
79 int horizontalLabelHeight;
80 int verticalLabelAlignment;
81 int horizontalLabelAlignment;
82 int cellAlignment;
83 short *colWidths; // Dynamically allocated
84 short *rowHeights; // Dynamically allocated
85 int scrollWidth; // Vert. scroll width, horiz. scroll height
86
87 // Colours
88 wxColour cellTextColour;
89 wxColour cellBackgroundColour;
90 wxFont *cellTextFont;
91 wxColour labelTextColour;
92 wxColour labelBackgroundColour;
93 wxBrush *labelBackgroundBrush;
94 wxFont *labelTextFont;
95 wxPen *divisionPen;
96
97 // Position of Edit control
98 wxRectangle editControlPosition;
99
100 // Drag status
101 int dragStatus;
102 int dragRowOrCol;
103 int dragStartPosition;
104 int dragLastPosition;
105 static wxCursor *horizontalSashCursor;
106 static wxCursor *verticalSashCursor;
107
108 // Don't refresh whilst this is > 0
109 int batchCount;
110
111 public:
112 wxGenericGrid(void);
113
114 inline wxGenericGrid(wxWindow *parent, int x, int y, int width, int height, const long style = 0, char *name = "grid")
115 {
116 Create(parent, -1, wxPoint(x, y), wxSize(width, height), style, name);
117 }
118 inline wxGenericGrid(wxWindow *parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, const long style = 0, const wxString& name = "grid")
119 {
120 Create(parent, id, pos, size, style, name);
121 }
122 ~wxGenericGrid(void);
123
124 void OnPaint(wxPaintEvent& event);
125 void OnMouseEvent(wxMouseEvent& event);
126 void OnSize(wxSizeEvent& event);
127
128 bool Create(wxWindow *parent, const wxWindowID, const wxPoint& pos, const wxSize& size, const long style = 0, const wxString& name = "grid");
129
130 bool CreateGrid(int nRows, int nCols, wxString **cellValues = NULL, short *widths = NULL,
131 short defaultWidth = wxGRID_DEFAULT_CELL_WIDTH, short defaultHeight = wxGRID_DEFAULT_CELL_HEIGHT);
132 void ClearGrid(void);
133 virtual wxGridCell *GetCell(int row, int col);
134 inline wxGridCell ***GetCells(void) { return gridCells; }
135 bool InsertCols(int pos = 0, int n = 1, bool updateLabels = TRUE);
136 bool InsertRows(int pos = 0, int n = 1, bool updateLabels = TRUE);
137 bool AppendCols(int n = 1, bool updateLabels = TRUE);
138 bool AppendRows(int n = 1, bool updateLabels = TRUE);
139 bool DeleteCols(int pos = 0, int n = 1, bool updateLabels = TRUE);
140 bool DeleteRows(int pos = 0, int n = 1, bool updateLabels = TRUE);
141
142 // Cell accessors
143 void SetCellValue(const wxString& val, int row, int col);
144 wxString& GetCellValue(int row, int col);
145 void SetCellAlignment(int flag, int row, int col);
146 void SetCellAlignment(int flag);
147 int GetCellAlignment(int row, int col);
148 int GetCellAlignment(void);
149 void SetCellTextColour(const wxColour& val, int row, int col);
150 void SetCellTextColour(const wxColour& col);
151 wxColour& GetCellTextColour(int row, int col);
152 inline wxColour& GetCellTextColour(void) { return cellTextColour; }
153 void SetCellBackgroundColour(const wxColour& col);
154 void SetCellBackgroundColour(const wxColour& colour, int row, int col);
155 inline wxColour& GetCellBackgroundColour(void) { return cellBackgroundColour; }
156 wxColour& GetCellBackgroundColour(int row, int col);
157 inline wxFont *GetCellTextFont(void) { return cellTextFont; }
158 wxFont *GetCellTextFont(int row, int col);
159 void SetCellTextFont(wxFont *fnt);
160 void SetCellTextFont(wxFont *fnt, int row, int col);
161 wxBitmap *GetCellBitmap(int row, int col);
162 void SetCellBitmap(wxBitmap *bitmap, int row, int col);
163
164 // Size accessors
165 void SetColumnWidth(int col, int width);
166 int GetColumnWidth(int col);
167 void SetRowHeight(int row, int height);
168 int GetRowHeight(int row);
169
170 // Label accessors
171 void SetLabelSize(int orientation, int sz);
172 int GetLabelSize(int orientation);
173 void SetLabelAlignment(int orientation, int alignment);
174 int GetLabelAlignment(int orientation);
175 wxGridCell *GetLabelCell(int orientation, int pos);
176 void SetLabelValue(int orientation, const wxString& val, int pos);
177 wxString& GetLabelValue(int orientation, int pos);
178 void SetLabelTextColour(const wxColour& colour);
179 void SetLabelBackgroundColour(const wxColour& colour);
180 inline wxColour& GetLabelTextColour(void) { return labelTextColour; }
181 inline wxColour& GetLabelBackgroundColour(void) { return labelBackgroundColour; }
182 inline wxFont *GetLabelTextFont(void) { return labelTextFont; }
183 inline void SetLabelTextFont(wxFont *fnt) { labelTextFont = fnt; }
184
185 // Miscellaneous accessors
186 inline int GetCursorRow(void) { return wCursorRow; }
187 inline int GetCursorColumn(void) { return wCursorColumn; }
188 void SetGridCursor(int row, int col);
189 inline int GetRows(void) { return totalRows; }
190 inline int GetCols(void) { return totalCols; }
191 inline int GetScrollPosX(void) { return scrollPosX; }
192 inline int GetScrollPosY(void) { return scrollPosY; }
193 inline void SetScrollPosX(int pos) { scrollPosX = pos; }
194 inline void SetScrollPosY(int pos) { scrollPosY = pos; }
195 inline wxTextCtrl *GetTextItem(void) { return textItem; }
196 inline wxScrollBar *GetHorizScrollBar(void) { return hScrollBar; }
197 inline wxScrollBar *GetVertScrollBar(void) { return vScrollBar; }
198 inline bool GetEditable(void) { return editable; }
199 void SetEditable(bool edit);
200 inline wxRectangle& GetCurrentRect(void) { return CurrentRect; }
201 inline bool CurrentCellVisible(void) { return currentRectVisible; }
202 inline void SetDividerPen(wxPen *pen) { divisionPen = pen; }
203 inline wxPen *GetDividerPen(void) { return divisionPen; }
204
205 // High-level event handling
206 // Override e.g. to check value of current cell; but call
207 // base member for default processing.
208 virtual void OnSelectCellImplementation(wxDC *dc, int row, int col);
209
210 virtual void OnSelectCell(int WXUNUSED(row), int WXUNUSED(col)) {};
211
212 // Override to create your own class of grid cell
213 virtual wxGridCell *OnCreateCell(void);
214
215 // Override to change labels e.g. creation of grid, inserting/deleting a row/col.
216 // By default, auto-labels the grid.
217 virtual void OnChangeLabels(void);
218
219 // Override to change the label of the edit field when selecting a cell
220 // By default, sets it to e.g. A12
221 virtual void OnChangeSelectionLabel(void);
222
223 // Override for event processing
224 virtual void OnCellChange(int WXUNUSED(row), int WXUNUSED(col)) {};
225 virtual void OnCellLeftClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
226 virtual void OnCellRightClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
227 virtual void OnLabelLeftClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
228 virtual void OnLabelRightClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
229
230 // Activation: call from wxFrame::OnActivate
231 void OnActivate(bool active);
232
233 // Miscellaneous
234 void AdjustScrollbars(void);
235 void UpdateDimensions(void);
236
237 /* INTERNAL
238 */
239 void SetCurrentRect (int Row, int Column, int canvasW = -1, int canvasH = -1);
240 void HighlightCell (wxDC *dc);
241 void DrawCellText(void);
242 void SetGridClippingRegion(wxDC *dc);
243 virtual bool CellHitTest(int x, int y, int *row, int *col);
244 virtual bool LabelSashHitTest(int x, int y, int *orientation, int *rowOrCol, int *startPos);
245 virtual bool LabelHitTest(int x, int y, int *row, int *col);
246 // Painting
247 virtual void DrawLabelAreas(wxDC *dc);
248 virtual void DrawEditableArea(wxDC *dc);
249 virtual void DrawGridLines(wxDC *dc);
250 virtual void DrawColumnLabels(wxDC *dc);
251 virtual void DrawColumnLabel(wxDC *dc, wxRectangle *rect, int col);
252 virtual void DrawRowLabels(wxDC *dc);
253 virtual void DrawRowLabel(wxDC *dc, wxRectangle *rect, int row);
254 virtual void DrawCells(wxDC *dc);
255 virtual void DrawCellValue(wxDC *dc, wxRectangle *rect, int row, int col);
256 virtual void DrawCellBackground(wxDC *dc, wxRectangle *rect, int row, int col);
257 virtual void DrawTextRect(wxDC *dc, const wxString& text, wxRectangle *rect, int flag);
258 virtual void DrawBitmapRect(wxDC *dc, wxBitmap *bitmap, wxRectangle *rect, int flag);
259
260 // Refresh cell and optionally set the text field
261 void RefreshCell(int row, int col, bool setText = FALSE);
262
263 // Don't refresh within the outer pair of these.
264 inline void BeginBatch(void) { batchCount ++; }
265 inline void EndBatch(void) { batchCount --; }
266 inline int GetBatchCount(void) { return batchCount; }
267
268 void OnText(wxCommandEvent& ev);
269 void OnGridScroll(wxScrollEvent& ev);
270
271DECLARE_EVENT_TABLE()
272};
273
274#define wxGRID_TEXT_CTRL 2000
275#define wxGRID_HSCROLL 2001
276#define wxGRID_VSCROLL 2002
277
278class WXDLLEXPORT wxGridCell: public wxObject
279{
280 public:
281 wxString textValue;
282 wxFont *font;
283 wxColour textColour;
284 wxColour backgroundColour;
285 wxBrush *backgroundBrush;
286 wxBitmap *cellBitmap;
287 int alignment;
288
289 wxGridCell(wxGenericGrid *window = NULL);
290 ~wxGridCell(void);
291
292 virtual wxString& GetTextValue(void) { return textValue; }
293 virtual void SetTextValue(const wxString& str) { textValue = str; }
294 inline wxFont *GetFont(void) { return font; }
295 inline void SetFont(wxFont *f) { font = f; }
296 inline wxColour& GetTextColour(void) { return textColour; }
297 inline void SetTextColour(const wxColour& colour) { textColour = colour; }
298 inline wxColour& GetBackgroundColour(void) { return backgroundColour; }
299 void SetBackgroundColour(const wxColour& colour);
300 inline wxBrush *GetBackgroundBrush(void) { return backgroundBrush; }
301 inline int GetAlignment(void) { return alignment; }
302 inline void SetAlignment(int align) { alignment = align; }
303 inline wxBitmap *GetCellBitmap(void) { return cellBitmap; }
304 inline void SetCellBitmap(wxBitmap *bitmap) { cellBitmap = bitmap; }
305};
306
307class WXDLLEXPORT wxGrid: public wxGenericGrid
308{
309 public:
310 wxGrid(void):wxGenericGrid() {}
311 wxGrid(wxWindow *parent, int x=-1, int y=-1, int width=-1, int height=-1,
312 long style=0, char *name = "gridWindow"):
313 wxGenericGrid(parent, x, y, width, height, style, name)
314 {
315 }
316};
317
318#endif
319