]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/gridg.h
new makefiles (part I)
[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 #include "wx/event.h"
24
25 #define wxGRID_DEFAULT_EDIT_WIDTH 300
26 #define wxGRID_DEFAULT_EDIT_HEIGHT 27
27 #define wxGRID_DEFAULT_EDIT_X 2
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
44 #define WXGENERIC_GRID_VERSION 0.5
45
46 class WXDLLEXPORT wxGridEvent;
47 class WXDLLEXPORT wxGridCell;
48 class WXDLLEXPORT wxGenericGrid: public wxPanel
49 {
50 DECLARE_DYNAMIC_CLASS(wxGenericGrid)
51 public:
52 wxGenericGrid(void);
53
54 inline wxGenericGrid(wxWindow *parent, int x, int y, int width, int height, long style = 0, char *name = "grid")
55 {
56 Create(parent, -1, wxPoint(x, y), wxSize(width, height), style, name);
57 }
58 inline wxGenericGrid(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style = 0, const wxString& name = "grid")
59 {
60 Create(parent, id, pos, size, style, name);
61 }
62 ~wxGenericGrid(void);
63
64 void OnPaint(wxPaintEvent& event);
65 void OnEraseBackground(wxEraseEvent& event);
66 void OnMouseEvent(wxMouseEvent& event);
67 void OnSize(wxSizeEvent& event);
68
69 bool Create(wxWindow *parent, wxWindowID, const wxPoint& pos, const wxSize& size, long style = 0, const wxString& name = "grid");
70
71 bool CreateGrid(int nRows, int nCols, wxString **cellValues = (wxString **) NULL, short *widths = (short *) NULL,
72 short defaultWidth = wxGRID_DEFAULT_CELL_WIDTH, short defaultHeight = wxGRID_DEFAULT_CELL_HEIGHT);
73 void PaintGrid(wxDC& dc);
74 void ClearGrid(void);
75 virtual wxGridCell *GetCell(int row, int col) const;
76 inline wxGridCell ***GetCells(void) const { return m_gridCells; }
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);
86 wxString& GetCellValue(int row, int col) const;
87 void SetCellAlignment(int flag, int row, int col);
88 void SetCellAlignment(int flag);
89 int GetCellAlignment(int row, int col) const;
90 int GetCellAlignment(void) const;
91 void SetCellTextColour(const wxColour& val, int row, int col);
92 void SetCellTextColour(const wxColour& col);
93 wxColour& GetCellTextColour(int row, int col) const;
94 inline wxColour& GetCellTextColour(void) const { return (wxColour&) m_cellTextColour; }
95 void SetCellBackgroundColour(const wxColour& col);
96 void SetCellBackgroundColour(const wxColour& colour, int row, int col);
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;
104 void SetCellBitmap(wxBitmap *bitmap, int row, int col);
105
106 // Size accessors
107 void SetColumnWidth(int col, int width);
108 int GetColumnWidth(int col) const;
109 void SetRowHeight(int row, int height);
110 int GetRowHeight(int row) const;
111
112 // Label accessors
113 void SetLabelSize(int orientation, int sz);
114 int GetLabelSize(int orientation) const;
115 void SetLabelAlignment(int orientation, int alignment);
116 int GetLabelAlignment(int orientation) const;
117 wxGridCell *GetLabelCell(int orientation, int pos) const;
118 void SetLabelValue(int orientation, const wxString& val, int pos);
119 wxString& GetLabelValue(int orientation, int pos) const;
120 void SetLabelTextColour(const wxColour& colour);
121 void SetLabelBackgroundColour(const wxColour& colour);
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; }
126
127 // Miscellaneous accessors
128 inline int GetCursorRow(void) const { return m_wCursorRow; }
129 inline int GetCursorColumn(void) const { return m_wCursorColumn; }
130 void SetGridCursor(int row, int col);
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; }
135 inline void SetScrollPosX(int pos) { m_scrollPosX = pos; }
136 inline void SetScrollPosY(int pos) { m_scrollPosY = pos; }
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; }
141 void SetEditable(bool edit);
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; }
146
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)) {};
153 void _OnSelectCell(wxGridEvent& event);
154
155 // Override to create your own class of grid cell
156 virtual wxGridCell *OnCreateCell(void);
157 void _OnCreateCell(wxGridEvent& event);
158
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);
162 void _OnChangeLabels(wxGridEvent& event);
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);
167 void _OnChangeSelectionLabel(wxGridEvent& event);
168
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
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);
181
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);
203 virtual void DrawColumnLabel(wxDC *dc, wxRect *rect, int col);
204 virtual void DrawRowLabels(wxDC *dc);
205 virtual void DrawRowLabel(wxDC *dc, wxRect *rect, int row);
206 virtual void DrawCells(wxDC *dc);
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);
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.
216 inline void BeginBatch(void) { m_batchCount ++; }
217 inline void EndBatch(void) { m_batchCount --; }
218 inline int GetBatchCount(void) { return m_batchCount; }
219
220 void OnText(wxCommandEvent& ev);
221 void OnGridScroll(wxScrollEvent& ev);
222
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;
230 wxRect m_currentRect;
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;
240
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
261
262 // Colours
263 wxColour m_cellTextColour;
264 wxColour m_cellBackgroundColour;
265 wxFont m_cellTextFont;
266 wxColour m_labelTextColour;
267 wxColour m_labelBackgroundColour;
268 wxBrush m_labelBackgroundBrush;
269 wxFont m_labelTextFont;
270 wxPen m_divisionPen;
271 wxBitmap* m_doubleBufferingBitmap;
272
273 // Position of Edit control
274 wxRect m_editControlPosition;
275
276 // Drag status
277 int m_dragStatus;
278 int m_dragRowOrCol;
279 int m_dragStartPosition;
280 int m_dragLastPosition;
281 wxCursor m_horizontalSashCursor;
282 wxCursor m_verticalSashCursor;
283
284 // To avoid multiple refreshes, use Begin/EndBatch
285 int m_batchCount;
286
287 DECLARE_EVENT_TABLE()
288 };
289
290 #define wxGRID_TEXT_CTRL 2000
291 #define wxGRID_HSCROLL 2001
292 #define wxGRID_VSCROLL 2002
293
294 class WXDLLEXPORT wxGridCell: public wxObject
295 {
296 public:
297 wxString textValue;
298 wxFont font;
299 wxColour textColour;
300 wxColour backgroundColour;
301 wxBrush backgroundBrush;
302 wxBitmap* cellBitmap;
303 int alignment;
304
305 wxGridCell(wxGenericGrid *window = (wxGenericGrid *) NULL);
306 ~wxGridCell(void);
307
308 virtual wxString& GetTextValue(void) const { return (wxString&) textValue; }
309 virtual void SetTextValue(const wxString& str) { textValue = str; }
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; }
313 inline void SetTextColour(const wxColour& colour) { textColour = colour; }
314 inline wxColour& GetBackgroundColour(void) const { return (wxColour&) backgroundColour; }
315 void SetBackgroundColour(const wxColour& colour);
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; }
319 inline void SetAlignment(int align) { alignment = align; }
320 inline wxBitmap *GetCellBitmap(void) const { return cellBitmap; }
321 inline void SetCellBitmap(wxBitmap *bitmap) { cellBitmap = bitmap; }
322 };
323
324 class 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
335 class WXDLLEXPORT wxGridEvent : public wxCommandEvent {
336 DECLARE_DYNAMIC_CLASS(wxGridEvent)
337 public:
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
362 const wxEventType wxEVT_GRID_SELECT_CELL = wxEVT_FIRST + 1575;
363 const wxEventType wxEVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576;
364 const wxEventType wxEVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577;
365 const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578;
366 const wxEventType wxEVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1579;
367 const wxEventType wxEVT_GRID_CELL_LCLICK = wxEVT_FIRST + 1580;
368 const wxEventType wxEVT_GRID_CELL_RCLICK = wxEVT_FIRST + 1581;
369 const wxEventType wxEVT_GRID_LABEL_LCLICK = wxEVT_FIRST + 1582;
370 const wxEventType wxEVT_GRID_LABEL_RCLICK = wxEVT_FIRST + 1583;
371
372
373 typedef 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
385 #endif
386