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