]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/gridg.h
wxWindow::IsShown() made 'const'
[wxWidgets.git] / include / wx / generic / gridg.h
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
45 class WXDLLEXPORT wxGridCell;
46 class WXDLLEXPORT wxGenericGrid: public wxPanel
47 {
48 DECLARE_DYNAMIC_CLASS(wxGenericGrid)
49 public:
50 wxGenericGrid(void);
51
52 inline wxGenericGrid(wxWindow *parent, int x, int y, int width, int height, long style = 0, char *name = "grid")
53 {
54 Create(parent, -1, wxPoint(x, y), wxSize(width, height), style, name);
55 }
56 inline wxGenericGrid(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style = 0, const wxString& name = "grid")
57 {
58 Create(parent, id, pos, size, style, name);
59 }
60 ~wxGenericGrid(void);
61
62 void OnPaint(wxPaintEvent& event);
63 void OnEraseBackground(wxEraseEvent& event);
64 void OnMouseEvent(wxMouseEvent& event);
65 void OnSize(wxSizeEvent& event);
66
67 bool Create(wxWindow *parent, wxWindowID, const wxPoint& pos, const wxSize& size, long style = 0, const wxString& name = "grid");
68
69 bool CreateGrid(int nRows, int nCols, wxString **cellValues = NULL, short *widths = NULL,
70 short defaultWidth = wxGRID_DEFAULT_CELL_WIDTH, short defaultHeight = wxGRID_DEFAULT_CELL_HEIGHT);
71 void PaintGrid(wxDC& dc);
72 void ClearGrid(void);
73 virtual wxGridCell *GetCell(int row, int col);
74 inline wxGridCell ***GetCells(void) { return m_gridCells; }
75 bool InsertCols(int pos = 0, int n = 1, bool updateLabels = TRUE);
76 bool InsertRows(int pos = 0, int n = 1, bool updateLabels = TRUE);
77 bool AppendCols(int n = 1, bool updateLabels = TRUE);
78 bool AppendRows(int n = 1, bool updateLabels = TRUE);
79 bool DeleteCols(int pos = 0, int n = 1, bool updateLabels = TRUE);
80 bool DeleteRows(int pos = 0, int n = 1, bool updateLabels = TRUE);
81
82 // Cell accessors
83 void SetCellValue(const wxString& val, int row, int col);
84 wxString& GetCellValue(int row, int col);
85 void SetCellAlignment(int flag, int row, int col);
86 void SetCellAlignment(int flag);
87 int GetCellAlignment(int row, int col);
88 int GetCellAlignment(void);
89 void SetCellTextColour(const wxColour& val, int row, int col);
90 void SetCellTextColour(const wxColour& col);
91 wxColour& GetCellTextColour(int row, int col);
92 inline wxColour& GetCellTextColour(void) { return m_cellTextColour; }
93 void SetCellBackgroundColour(const wxColour& col);
94 void SetCellBackgroundColour(const wxColour& colour, int row, int col);
95 inline wxColour& GetCellBackgroundColour(void) { return m_cellBackgroundColour; }
96 wxColour& GetCellBackgroundColour(int row, int col);
97 inline wxFont *GetCellTextFont(void) { return m_cellTextFont; }
98 wxFont *GetCellTextFont(int row, int col);
99 void SetCellTextFont(wxFont *fnt);
100 void SetCellTextFont(wxFont *fnt, int row, int col);
101 wxBitmap *GetCellBitmap(int row, int col);
102 void SetCellBitmap(wxBitmap *bitmap, int row, int col);
103
104 // Size accessors
105 void SetColumnWidth(int col, int width);
106 int GetColumnWidth(int col);
107 void SetRowHeight(int row, int height);
108 int GetRowHeight(int row);
109
110 // Label accessors
111 void SetLabelSize(int orientation, int sz);
112 int GetLabelSize(int orientation);
113 void SetLabelAlignment(int orientation, int alignment);
114 int GetLabelAlignment(int orientation);
115 wxGridCell *GetLabelCell(int orientation, int pos);
116 void SetLabelValue(int orientation, const wxString& val, int pos);
117 wxString& GetLabelValue(int orientation, int pos);
118 void SetLabelTextColour(const wxColour& colour);
119 void SetLabelBackgroundColour(const wxColour& colour);
120 inline wxColour& GetLabelTextColour(void) { return m_labelTextColour; }
121 inline wxColour& GetLabelBackgroundColour(void) { return m_labelBackgroundColour; }
122 inline wxFont *GetLabelTextFont(void) { return m_labelTextFont; }
123 inline void SetLabelTextFont(wxFont *fnt) { m_labelTextFont = fnt; }
124
125 // Miscellaneous accessors
126 inline int GetCursorRow(void) { return m_wCursorRow; }
127 inline int GetCursorColumn(void) { return m_wCursorColumn; }
128 void SetGridCursor(int row, int col);
129 inline int GetRows(void) { return m_totalRows; }
130 inline int GetCols(void) { return m_totalCols; }
131 inline int GetScrollPosX(void) { return m_scrollPosX; }
132 inline int GetScrollPosY(void) { return m_scrollPosY; }
133 inline void SetScrollPosX(int pos) { m_scrollPosX = pos; }
134 inline void SetScrollPosY(int pos) { m_scrollPosY = pos; }
135 inline wxTextCtrl *GetTextItem(void) { return m_textItem; }
136 inline wxScrollBar *GetHorizScrollBar(void) { return m_hScrollBar; }
137 inline wxScrollBar *GetVertScrollBar(void) { return m_vScrollBar; }
138 inline bool GetEditable(void) { return m_editable; }
139 void SetEditable(bool edit);
140 inline wxRectangle& GetCurrentRect(void) { return m_currentRect; }
141 inline bool CurrentCellVisible(void) { return m_currentRectVisible; }
142 inline void SetDividerPen(wxPen *pen) { m_divisionPen = pen; }
143 inline wxPen *GetDividerPen(void) { return m_divisionPen; }
144
145 // High-level event handling
146 // Override e.g. to check value of current cell; but call
147 // base member for default processing.
148 virtual void OnSelectCellImplementation(wxDC *dc, int row, int col);
149
150 virtual void OnSelectCell(int WXUNUSED(row), int WXUNUSED(col)) {};
151
152 // Override to create your own class of grid cell
153 virtual wxGridCell *OnCreateCell(void);
154
155 // Override to change labels e.g. creation of grid, inserting/deleting a row/col.
156 // By default, auto-labels the grid.
157 virtual void OnChangeLabels(void);
158
159 // Override to change the label of the edit field when selecting a cell
160 // By default, sets it to e.g. A12
161 virtual void OnChangeSelectionLabel(void);
162
163 // Override for event processing
164 virtual void OnCellChange(int WXUNUSED(row), int WXUNUSED(col)) {};
165 virtual void OnCellLeftClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
166 virtual void OnCellRightClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
167 virtual void OnLabelLeftClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
168 virtual void OnLabelRightClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {};
169
170 // Activation: call from wxFrame::OnActivate
171 void OnActivate(bool active);
172
173 // Miscellaneous
174 void AdjustScrollbars(void);
175 void UpdateDimensions(void);
176
177 /* INTERNAL
178 */
179 void SetCurrentRect (int Row, int Column, int canvasW = -1, int canvasH = -1);
180 void HighlightCell (wxDC *dc);
181 void DrawCellText(void);
182 void SetGridClippingRegion(wxDC *dc);
183 virtual bool CellHitTest(int x, int y, int *row, int *col);
184 virtual bool LabelSashHitTest(int x, int y, int *orientation, int *rowOrCol, int *startPos);
185 virtual bool LabelHitTest(int x, int y, int *row, int *col);
186 // Painting
187 virtual void DrawLabelAreas(wxDC *dc);
188 virtual void DrawEditableArea(wxDC *dc);
189 virtual void DrawGridLines(wxDC *dc);
190 virtual void DrawColumnLabels(wxDC *dc);
191 virtual void DrawColumnLabel(wxDC *dc, wxRectangle *rect, int col);
192 virtual void DrawRowLabels(wxDC *dc);
193 virtual void DrawRowLabel(wxDC *dc, wxRectangle *rect, int row);
194 virtual void DrawCells(wxDC *dc);
195 virtual void DrawCellValue(wxDC *dc, wxRectangle *rect, int row, int col);
196 virtual void DrawCellBackground(wxDC *dc, wxRectangle *rect, int row, int col);
197 virtual void DrawTextRect(wxDC *dc, const wxString& text, wxRectangle *rect, int flag);
198 virtual void DrawBitmapRect(wxDC *dc, wxBitmap *bitmap, wxRectangle *rect, int flag);
199
200 // Refresh cell and optionally set the text field
201 void RefreshCell(int row, int col, bool setText = FALSE);
202
203 // Don't refresh within the outer pair of these.
204 inline void BeginBatch(void) { m_batchCount ++; }
205 inline void EndBatch(void) { m_batchCount --; }
206 inline int GetBatchCount(void) { return m_batchCount; }
207
208 void OnText(wxCommandEvent& ev);
209 void OnGridScroll(wxScrollEvent& ev);
210
211 protected:
212 wxPanel* m_editingPanel; // Contains the text control
213 wxTextCtrl* m_textItem;
214 wxScrollBar* m_hScrollBar;
215 wxScrollBar* m_vScrollBar;
216 int m_wCursorRow;
217 int m_wCursorColumn;
218 wxRectangle m_currentRect;
219 bool m_currentRectVisible;
220 wxGridCell*** m_gridCells;
221 wxGridCell** m_rowLabelCells;
222 wxGridCell** m_colLabelCells;
223 bool m_editCreated;
224 bool m_editable;
225
226 int m_totalRows;
227 int m_totalCols;
228
229 // Row and column we're currently looking at
230 int m_scrollPosX;
231 int m_scrollPosY;
232
233 // Dimensions
234 int m_leftOfSheet;
235 int m_topOfSheet;
236 int m_rightOfSheet; // Calculated from m_colWidths
237 int m_bottomOfSheet; // Calculated from m_rowHeights
238 int m_totalGridWidth; // Total 'virtual' size
239 int m_totalGridHeight;
240 int m_cellHeight; // For now, a default
241 int m_verticalLabelWidth;
242 int m_horizontalLabelHeight;
243 int m_verticalLabelAlignment;
244 int m_horizontalLabelAlignment;
245 int m_cellAlignment;
246 short* m_colWidths; // Dynamically allocated
247 short* m_rowHeights; // Dynamically allocated
248 int m_scrollWidth; // Vert. scroll width, horiz. scroll height
249
250 // Colours
251 wxColour m_cellTextColour;
252 wxColour m_cellBackgroundColour;
253 wxFont* m_cellTextFont;
254 wxColour m_labelTextColour;
255 wxColour m_labelBackgroundColour;
256 wxBrush* m_labelBackgroundBrush;
257 wxFont* m_labelTextFont;
258 wxPen* m_divisionPen;
259 wxBitmap* m_doubleBufferingBitmap;
260
261 // Position of Edit control
262 wxRectangle m_editControlPosition;
263
264 // Drag status
265 int m_dragStatus;
266 int m_dragRowOrCol;
267 int m_dragStartPosition;
268 int m_dragLastPosition;
269 wxCursor* m_horizontalSashCursor;
270 wxCursor* m_verticalSashCursor;
271
272 // To avoid multiple refreshes, use Begin/EndBatch
273 int m_batchCount;
274
275 DECLARE_EVENT_TABLE()
276 };
277
278 #define wxGRID_TEXT_CTRL 2000
279 #define wxGRID_HSCROLL 2001
280 #define wxGRID_VSCROLL 2002
281
282 class WXDLLEXPORT wxGridCell: public wxObject
283 {
284 public:
285 wxString textValue;
286 wxFont *font;
287 wxColour textColour;
288 wxColour backgroundColour;
289 wxBrush *backgroundBrush;
290 wxBitmap *cellBitmap;
291 int alignment;
292
293 wxGridCell(wxGenericGrid *window = NULL);
294 ~wxGridCell(void);
295
296 virtual wxString& GetTextValue(void) { return textValue; }
297 virtual void SetTextValue(const wxString& str) { textValue = str; }
298 inline wxFont *GetFont(void) { return font; }
299 inline void SetFont(wxFont *f) { font = f; }
300 inline wxColour& GetTextColour(void) { return textColour; }
301 inline void SetTextColour(const wxColour& colour) { textColour = colour; }
302 inline wxColour& GetBackgroundColour(void) { return backgroundColour; }
303 void SetBackgroundColour(const wxColour& colour);
304 inline wxBrush *GetBackgroundBrush(void) { return backgroundBrush; }
305 inline int GetAlignment(void) { return alignment; }
306 inline void SetAlignment(int align) { alignment = align; }
307 inline wxBitmap *GetCellBitmap(void) { return cellBitmap; }
308 inline void SetCellBitmap(wxBitmap *bitmap) { cellBitmap = bitmap; }
309 };
310
311 class WXDLLEXPORT wxGrid: public wxGenericGrid
312 {
313 public:
314 wxGrid(void):wxGenericGrid() {}
315 wxGrid(wxWindow *parent, int x=-1, int y=-1, int width=-1, int height=-1,
316 long style=0, char *name = "gridWindow"):
317 wxGenericGrid(parent, x, y, width, height, style, name)
318 {
319 }
320 };
321
322 #endif
323