]>
Commit | Line | Data |
---|---|---|
f85afd4e | 1 | ///////////////////////////////////////////////////////////////////////////// |
43947979 | 2 | // Name: wx/generic/grid.h |
f85afd4e MB |
3 | // Purpose: wxGrid and related classes |
4 | // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn) | |
d4175745 | 5 | // Modified by: Santiago Palacios |
f85afd4e MB |
6 | // Created: 1/08/1999 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Michael Bedward | |
65571936 | 9 | // Licence: wxWindows licence |
f85afd4e MB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
df9fac6d PC |
12 | #ifndef _WX_GENERIC_GRID_H_ |
13 | #define _WX_GENERIC_GRID_H_ | |
14 | ||
15 | #include "wx/defs.h" | |
16 | ||
17 | #if wxUSE_GRID | |
f85afd4e | 18 | |
2d66e025 | 19 | #include "wx/scrolwin.h" |
f85afd4e | 20 | |
816be743 VZ |
21 | // ---------------------------------------------------------------------------- |
22 | // constants | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
4c44eb66 | 25 | extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxGridNameStr[]; |
61961a3c | 26 | |
f85afd4e MB |
27 | // Default parameters for wxGrid |
28 | // | |
29 | #define WXGRID_DEFAULT_NUMBER_ROWS 10 | |
30 | #define WXGRID_DEFAULT_NUMBER_COLS 10 | |
e6002250 | 31 | #if defined(__WXMSW__) || defined(__WXGTK20__) |
f85afd4e MB |
32 | #define WXGRID_DEFAULT_ROW_HEIGHT 25 |
33 | #else | |
34 | #define WXGRID_DEFAULT_ROW_HEIGHT 30 | |
35 | #endif // __WXMSW__ | |
36 | #define WXGRID_DEFAULT_COL_WIDTH 80 | |
37 | #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32 | |
38 | #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82 | |
f1567cdd | 39 | #define WXGRID_LABEL_EDGE_ZONE 2 |
f85afd4e MB |
40 | #define WXGRID_MIN_ROW_HEIGHT 15 |
41 | #define WXGRID_MIN_COL_WIDTH 15 | |
42 | #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16 | |
f85afd4e | 43 | |
816be743 VZ |
44 | // type names for grid table values |
45 | #define wxGRID_VALUE_STRING _T("string") | |
46 | #define wxGRID_VALUE_BOOL _T("bool") | |
47 | #define wxGRID_VALUE_NUMBER _T("long") | |
48 | #define wxGRID_VALUE_FLOAT _T("double") | |
c4608a8a | 49 | #define wxGRID_VALUE_CHOICE _T("choice") |
816be743 VZ |
50 | |
51 | #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING | |
52 | #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER | |
53 | ||
733f486a VZ |
54 | // magic constant which tells (to some functions) to automatically calculate |
55 | // the appropriate size | |
56 | #define wxGRID_AUTOSIZE (-1) | |
57 | ||
58 | // many wxGrid methods work either with columns or rows, this enum is used for | |
59 | // the parameter indicating which one should it be | |
60 | enum wxGridDirection | |
61 | { | |
62 | wxGRID_COLUMN, | |
05cc594a | 63 | wxGRID_ROW |
733f486a VZ |
64 | }; |
65 | ||
b99be8fb VZ |
66 | // ---------------------------------------------------------------------------- |
67 | // forward declarations | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
b5dbe15d VS |
70 | class WXDLLIMPEXP_FWD_ADV wxGrid; |
71 | class WXDLLIMPEXP_FWD_ADV wxGridCellAttr; | |
72 | class WXDLLIMPEXP_FWD_ADV wxGridCellAttrProviderData; | |
73 | class WXDLLIMPEXP_FWD_ADV wxGridColLabelWindow; | |
74 | class WXDLLIMPEXP_FWD_ADV wxGridCornerLabelWindow; | |
75 | class WXDLLIMPEXP_FWD_ADV wxGridRowLabelWindow; | |
76 | class WXDLLIMPEXP_FWD_ADV wxGridWindow; | |
77 | class WXDLLIMPEXP_FWD_ADV wxGridTypeRegistry; | |
78 | class WXDLLIMPEXP_FWD_ADV wxGridSelection; | |
79 | ||
80 | class WXDLLIMPEXP_FWD_CORE wxCheckBox; | |
81 | class WXDLLIMPEXP_FWD_CORE wxComboBox; | |
82 | class WXDLLIMPEXP_FWD_CORE wxTextCtrl; | |
0e871ad0 | 83 | #if wxUSE_SPINCTRL |
b5dbe15d | 84 | class WXDLLIMPEXP_FWD_CORE wxSpinCtrl; |
0e871ad0 | 85 | #endif |
508011ce | 86 | |
bec70262 VZ |
87 | class wxGridOperations; |
88 | class wxGridRowOperations; | |
89 | class wxGridColumnOperations; | |
10a4531d | 90 | class wxGridDirectionOperations; |
bec70262 | 91 | |
39bcce60 VZ |
92 | // ---------------------------------------------------------------------------- |
93 | // macros | |
94 | // ---------------------------------------------------------------------------- | |
95 | ||
96 | #define wxSafeIncRef(p) if ( p ) (p)->IncRef() | |
97 | #define wxSafeDecRef(p) if ( p ) (p)->DecRef() | |
98 | ||
ab79958a | 99 | // ---------------------------------------------------------------------------- |
c4608a8a VZ |
100 | // wxGridCellWorker: common base class for wxGridCellRenderer and |
101 | // wxGridCellEditor | |
102 | // | |
103 | // NB: this is more an implementation convenience than a design issue, so this | |
104 | // class is not documented and is not public at all | |
ab79958a VZ |
105 | // ---------------------------------------------------------------------------- |
106 | ||
12f190b0 | 107 | class WXDLLIMPEXP_ADV wxGridCellWorker : public wxClientDataContainer |
ab79958a VZ |
108 | { |
109 | public: | |
c4608a8a | 110 | wxGridCellWorker() { m_nRef = 1; } |
39bcce60 VZ |
111 | |
112 | // this class is ref counted: it is created with ref count of 1, so | |
113 | // calling DecRef() once will delete it. Calling IncRef() allows to lock | |
114 | // it until the matching DecRef() is called | |
115 | void IncRef() { m_nRef++; } | |
8d7eaf91 | 116 | void DecRef() { if ( --m_nRef == 0 ) delete this; } |
39bcce60 | 117 | |
c4608a8a VZ |
118 | // interpret renderer parameters: arbitrary string whose interpretatin is |
119 | // left to the derived classes | |
120 | virtual void SetParameters(const wxString& params); | |
121 | ||
122 | protected: | |
123 | // virtual dtor for any base class - private because only DecRef() can | |
124 | // delete us | |
125 | virtual ~wxGridCellWorker(); | |
126 | ||
127 | private: | |
128 | size_t m_nRef; | |
129 | ||
130 | // suppress the stupid gcc warning about the class having private dtor and | |
131 | // no friends | |
132 | friend class wxGridCellWorkerDummyFriend; | |
133 | }; | |
134 | ||
135 | // ---------------------------------------------------------------------------- | |
136 | // wxGridCellRenderer: this class is responsible for actually drawing the cell | |
137 | // in the grid. You may pass it to the wxGridCellAttr (below) to change the | |
138 | // format of one given cell or to wxGrid::SetDefaultRenderer() to change the | |
139 | // view of all cells. This is an ABC, you will normally use one of the | |
140 | // predefined derived classes or derive your own class from it. | |
141 | // ---------------------------------------------------------------------------- | |
142 | ||
12f190b0 | 143 | class WXDLLIMPEXP_ADV wxGridCellRenderer : public wxGridCellWorker |
c4608a8a VZ |
144 | { |
145 | public: | |
ab79958a VZ |
146 | // draw the given cell on the provided DC inside the given rectangle |
147 | // using the style specified by the attribute and the default or selected | |
148 | // state corresponding to the isSelected value. | |
149 | // | |
150 | // this pure virtual function has a default implementation which will | |
151 | // prepare the DC using the given attribute: it will draw the rectangle | |
152 | // with the bg colour from attr and set the text colour and font | |
153 | virtual void Draw(wxGrid& grid, | |
2796cce3 | 154 | wxGridCellAttr& attr, |
ab79958a VZ |
155 | wxDC& dc, |
156 | const wxRect& rect, | |
157 | int row, int col, | |
158 | bool isSelected) = 0; | |
816be743 | 159 | |
65e4e78e VZ |
160 | // get the preferred size of the cell for its contents |
161 | virtual wxSize GetBestSize(wxGrid& grid, | |
162 | wxGridCellAttr& attr, | |
163 | wxDC& dc, | |
164 | int row, int col) = 0; | |
165 | ||
e72b4213 VZ |
166 | // create a new object which is the copy of this one |
167 | virtual wxGridCellRenderer *Clone() const = 0; | |
ab79958a VZ |
168 | }; |
169 | ||
170 | // the default renderer for the cells containing string data | |
12f190b0 | 171 | class WXDLLIMPEXP_ADV wxGridCellStringRenderer : public wxGridCellRenderer |
ab79958a VZ |
172 | { |
173 | public: | |
174 | // draw the string | |
175 | virtual void Draw(wxGrid& grid, | |
2796cce3 | 176 | wxGridCellAttr& attr, |
ab79958a VZ |
177 | wxDC& dc, |
178 | const wxRect& rect, | |
179 | int row, int col, | |
180 | bool isSelected); | |
816be743 | 181 | |
65e4e78e VZ |
182 | // return the string extent |
183 | virtual wxSize GetBestSize(wxGrid& grid, | |
184 | wxGridCellAttr& attr, | |
185 | wxDC& dc, | |
186 | int row, int col); | |
187 | ||
e72b4213 VZ |
188 | virtual wxGridCellRenderer *Clone() const |
189 | { return new wxGridCellStringRenderer; } | |
190 | ||
816be743 VZ |
191 | protected: |
192 | // set the text colours before drawing | |
fbfb8bcc VZ |
193 | void SetTextColoursAndFont(const wxGrid& grid, |
194 | const wxGridCellAttr& attr, | |
816be743 VZ |
195 | wxDC& dc, |
196 | bool isSelected); | |
65e4e78e VZ |
197 | |
198 | // calc the string extent for given string/font | |
fbfb8bcc | 199 | wxSize DoGetBestSize(const wxGridCellAttr& attr, |
65e4e78e VZ |
200 | wxDC& dc, |
201 | const wxString& text); | |
816be743 VZ |
202 | }; |
203 | ||
204 | // the default renderer for the cells containing numeric (long) data | |
12f190b0 | 205 | class WXDLLIMPEXP_ADV wxGridCellNumberRenderer : public wxGridCellStringRenderer |
816be743 VZ |
206 | { |
207 | public: | |
208 | // draw the string right aligned | |
209 | virtual void Draw(wxGrid& grid, | |
210 | wxGridCellAttr& attr, | |
211 | wxDC& dc, | |
212 | const wxRect& rect, | |
213 | int row, int col, | |
214 | bool isSelected); | |
65e4e78e VZ |
215 | |
216 | virtual wxSize GetBestSize(wxGrid& grid, | |
217 | wxGridCellAttr& attr, | |
218 | wxDC& dc, | |
219 | int row, int col); | |
220 | ||
e72b4213 VZ |
221 | virtual wxGridCellRenderer *Clone() const |
222 | { return new wxGridCellNumberRenderer; } | |
223 | ||
65e4e78e | 224 | protected: |
fbfb8bcc | 225 | wxString GetString(const wxGrid& grid, int row, int col); |
816be743 VZ |
226 | }; |
227 | ||
12f190b0 | 228 | class WXDLLIMPEXP_ADV wxGridCellFloatRenderer : public wxGridCellStringRenderer |
816be743 VZ |
229 | { |
230 | public: | |
0b190b0f | 231 | wxGridCellFloatRenderer(int width = -1, int precision = -1); |
816be743 VZ |
232 | |
233 | // get/change formatting parameters | |
234 | int GetWidth() const { return m_width; } | |
0b190b0f | 235 | void SetWidth(int width) { m_width = width; m_format.clear(); } |
816be743 | 236 | int GetPrecision() const { return m_precision; } |
0b190b0f | 237 | void SetPrecision(int precision) { m_precision = precision; m_format.clear(); } |
816be743 VZ |
238 | |
239 | // draw the string right aligned with given width/precision | |
240 | virtual void Draw(wxGrid& grid, | |
241 | wxGridCellAttr& attr, | |
242 | wxDC& dc, | |
243 | const wxRect& rect, | |
244 | int row, int col, | |
245 | bool isSelected); | |
246 | ||
65e4e78e VZ |
247 | virtual wxSize GetBestSize(wxGrid& grid, |
248 | wxGridCellAttr& attr, | |
249 | wxDC& dc, | |
250 | int row, int col); | |
0b190b0f VZ |
251 | |
252 | // parameters string format is "width[,precision]" | |
253 | virtual void SetParameters(const wxString& params); | |
254 | ||
e72b4213 VZ |
255 | virtual wxGridCellRenderer *Clone() const; |
256 | ||
65e4e78e | 257 | protected: |
fbfb8bcc | 258 | wxString GetString(const wxGrid& grid, int row, int col); |
65e4e78e | 259 | |
816be743 VZ |
260 | private: |
261 | // formatting parameters | |
262 | int m_width, | |
0b190b0f | 263 | m_precision; |
816be743 VZ |
264 | |
265 | wxString m_format; | |
ab79958a | 266 | }; |
f85afd4e | 267 | |
508011ce | 268 | // renderer for boolean fields |
12f190b0 | 269 | class WXDLLIMPEXP_ADV wxGridCellBoolRenderer : public wxGridCellRenderer |
508011ce VZ |
270 | { |
271 | public: | |
508011ce VZ |
272 | // draw a check mark or nothing |
273 | virtual void Draw(wxGrid& grid, | |
274 | wxGridCellAttr& attr, | |
275 | wxDC& dc, | |
276 | const wxRect& rect, | |
277 | int row, int col, | |
278 | bool isSelected); | |
65e4e78e VZ |
279 | |
280 | // return the checkmark size | |
281 | virtual wxSize GetBestSize(wxGrid& grid, | |
282 | wxGridCellAttr& attr, | |
283 | wxDC& dc, | |
284 | int row, int col); | |
285 | ||
e72b4213 VZ |
286 | virtual wxGridCellRenderer *Clone() const |
287 | { return new wxGridCellBoolRenderer; } | |
288 | ||
65e4e78e VZ |
289 | private: |
290 | static wxSize ms_sizeCheckMark; | |
508011ce | 291 | }; |
2796cce3 RD |
292 | |
293 | // ---------------------------------------------------------------------------- | |
294 | // wxGridCellEditor: This class is responsible for providing and manipulating | |
295 | // the in-place edit controls for the grid. Instances of wxGridCellEditor | |
296 | // (actually, instances of derived classes since it is an ABC) can be | |
297 | // associated with the cell attributes for individual cells, rows, columns, or | |
298 | // even for the entire grid. | |
299 | // ---------------------------------------------------------------------------- | |
300 | ||
12f190b0 | 301 | class WXDLLIMPEXP_ADV wxGridCellEditor : public wxGridCellWorker |
2796cce3 RD |
302 | { |
303 | public: | |
304 | wxGridCellEditor(); | |
39bcce60 | 305 | |
2796cce3 | 306 | bool IsCreated() { return m_control != NULL; } |
f6bcfd97 BP |
307 | wxControl* GetControl() { return m_control; } |
308 | void SetControl(wxControl* control) { m_control = control; } | |
2796cce3 | 309 | |
1bd71df9 JS |
310 | wxGridCellAttr* GetCellAttr() { return m_attr; } |
311 | void SetCellAttr(wxGridCellAttr* attr) { m_attr = attr; } | |
312 | ||
2796cce3 RD |
313 | // Creates the actual edit control |
314 | virtual void Create(wxWindow* parent, | |
315 | wxWindowID id, | |
2796cce3 RD |
316 | wxEvtHandler* evtHandler) = 0; |
317 | ||
318 | // Size and position the edit control | |
319 | virtual void SetSize(const wxRect& rect); | |
320 | ||
3da93aae VZ |
321 | // Show or hide the edit control, use the specified attributes to set |
322 | // colours/fonts for it | |
323 | virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL); | |
2796cce3 | 324 | |
189d0213 VZ |
325 | // Draws the part of the cell not occupied by the control: the base class |
326 | // version just fills it with background colour from the attribute | |
327 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); | |
328 | ||
2796cce3 RD |
329 | // Fetch the value from the table and prepare the edit control |
330 | // to begin editing. Set the focus to the edit control. | |
3da93aae | 331 | virtual void BeginEdit(int row, int col, wxGrid* grid) = 0; |
2796cce3 | 332 | |
3324d5f5 VZ |
333 | // Complete the editing of the current cell. Returns true if the value has |
334 | // changed. If necessary, the control may be destroyed. | |
335 | virtual bool EndEdit(int row, int col, wxGrid* grid) = 0; | |
2796cce3 RD |
336 | |
337 | // Reset the value in the control back to its starting value | |
338 | virtual void Reset() = 0; | |
339 | ||
ca65c044 | 340 | // return true to allow the given key to start editing: the base class |
f6bcfd97 BP |
341 | // version only checks that the event has no modifiers. The derived |
342 | // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in | |
343 | // their IsAcceptedKey() implementation, although, of course, it is not a | |
344 | // mandatory requirment. | |
345 | // | |
346 | // NB: if the key is F2 (special), editing will always start and this | |
347 | // method will not be called at all (but StartingKey() will) | |
348 | virtual bool IsAcceptedKey(wxKeyEvent& event); | |
349 | ||
350 | // If the editor is enabled by pressing keys on the grid, this will be | |
351 | // called to let the editor do something about that first key if desired | |
2c9a89e0 RD |
352 | virtual void StartingKey(wxKeyEvent& event); |
353 | ||
e195a54c VZ |
354 | // if the editor is enabled by clicking on the cell, this method will be |
355 | // called | |
356 | virtual void StartingClick(); | |
357 | ||
2796cce3 RD |
358 | // Some types of controls on some platforms may need some help |
359 | // with the Return key. | |
360 | virtual void HandleReturn(wxKeyEvent& event); | |
361 | ||
362 | // Final cleanup | |
363 | virtual void Destroy(); | |
364 | ||
c4608a8a VZ |
365 | // create a new object which is the copy of this one |
366 | virtual wxGridCellEditor *Clone() const = 0; | |
367 | ||
73145b0e JS |
368 | // added GetValue so we can get the value which is in the control |
369 | virtual wxString GetValue() const = 0; | |
370 | ||
2796cce3 | 371 | protected: |
39bcce60 VZ |
372 | // the dtor is private because only DecRef() can delete us |
373 | virtual ~wxGridCellEditor(); | |
374 | ||
3da93aae | 375 | // the control we show on screen |
2796cce3 | 376 | wxControl* m_control; |
3da93aae | 377 | |
1bd71df9 JS |
378 | // a temporary pointer to the attribute being edited |
379 | wxGridCellAttr* m_attr; | |
380 | ||
3da93aae VZ |
381 | // if we change the colours/font of the control from the default ones, we |
382 | // must restore the default later and we save them here between calls to | |
ca65c044 | 383 | // Show(true) and Show(false) |
3da93aae VZ |
384 | wxColour m_colFgOld, |
385 | m_colBgOld; | |
386 | wxFont m_fontOld; | |
39bcce60 VZ |
387 | |
388 | // suppress the stupid gcc warning about the class having private dtor and | |
389 | // no friends | |
390 | friend class wxGridCellEditorDummyFriend; | |
22f3361e VZ |
391 | |
392 | DECLARE_NO_COPY_CLASS(wxGridCellEditor) | |
2796cce3 RD |
393 | }; |
394 | ||
3379ed37 VZ |
395 | #if wxUSE_TEXTCTRL |
396 | ||
508011ce | 397 | // the editor for string/text data |
12f190b0 | 398 | class WXDLLIMPEXP_ADV wxGridCellTextEditor : public wxGridCellEditor |
2796cce3 RD |
399 | { |
400 | public: | |
401 | wxGridCellTextEditor(); | |
402 | ||
403 | virtual void Create(wxWindow* parent, | |
404 | wxWindowID id, | |
2796cce3 | 405 | wxEvtHandler* evtHandler); |
99306db2 | 406 | virtual void SetSize(const wxRect& rect); |
2796cce3 | 407 | |
189d0213 VZ |
408 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); |
409 | ||
f6bcfd97 | 410 | virtual bool IsAcceptedKey(wxKeyEvent& event); |
3da93aae | 411 | virtual void BeginEdit(int row, int col, wxGrid* grid); |
3324d5f5 | 412 | virtual bool EndEdit(int row, int col, wxGrid* grid); |
2796cce3 RD |
413 | |
414 | virtual void Reset(); | |
2c9a89e0 | 415 | virtual void StartingKey(wxKeyEvent& event); |
2796cce3 RD |
416 | virtual void HandleReturn(wxKeyEvent& event); |
417 | ||
c4608a8a VZ |
418 | // parameters string format is "max_width" |
419 | virtual void SetParameters(const wxString& params); | |
420 | ||
421 | virtual wxGridCellEditor *Clone() const | |
422 | { return new wxGridCellTextEditor; } | |
423 | ||
73145b0e JS |
424 | // added GetValue so we can get the value which is in the control |
425 | virtual wxString GetValue() const; | |
9c71a138 | 426 | |
b54ba671 VZ |
427 | protected: |
428 | wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; } | |
2796cce3 | 429 | |
816be743 | 430 | // parts of our virtual functions reused by the derived classes |
1d5fda5d VZ |
431 | void DoCreate(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler, |
432 | long style = 0); | |
816be743 VZ |
433 | void DoBeginEdit(const wxString& startValue); |
434 | void DoReset(const wxString& startValue); | |
435 | ||
2796cce3 | 436 | private: |
c4608a8a | 437 | size_t m_maxChars; // max number of chars allowed |
2796cce3 | 438 | wxString m_startValue; |
fc7a2a60 VZ |
439 | |
440 | DECLARE_NO_COPY_CLASS(wxGridCellTextEditor) | |
2796cce3 RD |
441 | }; |
442 | ||
816be743 | 443 | // the editor for numeric (long) data |
12f190b0 | 444 | class WXDLLIMPEXP_ADV wxGridCellNumberEditor : public wxGridCellTextEditor |
816be743 VZ |
445 | { |
446 | public: | |
447 | // allows to specify the range - if min == max == -1, no range checking is | |
448 | // done | |
449 | wxGridCellNumberEditor(int min = -1, int max = -1); | |
450 | ||
451 | virtual void Create(wxWindow* parent, | |
452 | wxWindowID id, | |
453 | wxEvtHandler* evtHandler); | |
454 | ||
f6bcfd97 | 455 | virtual bool IsAcceptedKey(wxKeyEvent& event); |
816be743 | 456 | virtual void BeginEdit(int row, int col, wxGrid* grid); |
3324d5f5 | 457 | virtual bool EndEdit(int row, int col, wxGrid* grid); |
816be743 VZ |
458 | |
459 | virtual void Reset(); | |
460 | virtual void StartingKey(wxKeyEvent& event); | |
461 | ||
c4608a8a VZ |
462 | // parameters string format is "min,max" |
463 | virtual void SetParameters(const wxString& params); | |
464 | ||
465 | virtual wxGridCellEditor *Clone() const | |
466 | { return new wxGridCellNumberEditor(m_min, m_max); } | |
9c71a138 | 467 | |
73145b0e JS |
468 | // added GetValue so we can get the value which is in the control |
469 | virtual wxString GetValue() const; | |
c4608a8a | 470 | |
816be743 | 471 | protected: |
0e871ad0 | 472 | #if wxUSE_SPINCTRL |
816be743 | 473 | wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; } |
0e871ad0 | 474 | #endif |
816be743 VZ |
475 | |
476 | // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl | |
0e871ad0 WS |
477 | bool HasRange() const |
478 | { | |
479 | #if wxUSE_SPINCTRL | |
480 | return m_min != m_max; | |
481 | #else | |
482 | return false; | |
483 | #endif | |
484 | } | |
816be743 VZ |
485 | |
486 | // string representation of m_valueOld | |
487 | wxString GetString() const | |
488 | { return wxString::Format(_T("%ld"), m_valueOld); } | |
489 | ||
490 | private: | |
491 | int m_min, | |
492 | m_max; | |
493 | ||
494 | long m_valueOld; | |
fc7a2a60 VZ |
495 | |
496 | DECLARE_NO_COPY_CLASS(wxGridCellNumberEditor) | |
816be743 VZ |
497 | }; |
498 | ||
499 | // the editor for floating point numbers (double) data | |
12f190b0 | 500 | class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor |
816be743 VZ |
501 | { |
502 | public: | |
f6bcfd97 BP |
503 | wxGridCellFloatEditor(int width = -1, int precision = -1); |
504 | ||
816be743 VZ |
505 | virtual void Create(wxWindow* parent, |
506 | wxWindowID id, | |
507 | wxEvtHandler* evtHandler); | |
508 | ||
f6bcfd97 | 509 | virtual bool IsAcceptedKey(wxKeyEvent& event); |
816be743 | 510 | virtual void BeginEdit(int row, int col, wxGrid* grid); |
3324d5f5 | 511 | virtual bool EndEdit(int row, int col, wxGrid* grid); |
816be743 VZ |
512 | |
513 | virtual void Reset(); | |
514 | virtual void StartingKey(wxKeyEvent& event); | |
515 | ||
c4608a8a | 516 | virtual wxGridCellEditor *Clone() const |
ec53826c | 517 | { return new wxGridCellFloatEditor(m_width, m_precision); } |
c4608a8a | 518 | |
f6bcfd97 BP |
519 | // parameters string format is "width,precision" |
520 | virtual void SetParameters(const wxString& params); | |
521 | ||
816be743 VZ |
522 | protected: |
523 | // string representation of m_valueOld | |
f6bcfd97 | 524 | wxString GetString() const; |
816be743 VZ |
525 | |
526 | private: | |
f6bcfd97 BP |
527 | int m_width, |
528 | m_precision; | |
816be743 | 529 | double m_valueOld; |
fc7a2a60 VZ |
530 | |
531 | DECLARE_NO_COPY_CLASS(wxGridCellFloatEditor) | |
816be743 VZ |
532 | }; |
533 | ||
3379ed37 VZ |
534 | #endif // wxUSE_TEXTCTRL |
535 | ||
536 | #if wxUSE_CHECKBOX | |
537 | ||
508011ce | 538 | // the editor for boolean data |
12f190b0 | 539 | class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor |
508011ce VZ |
540 | { |
541 | public: | |
fc7a2a60 VZ |
542 | wxGridCellBoolEditor() { } |
543 | ||
508011ce VZ |
544 | virtual void Create(wxWindow* parent, |
545 | wxWindowID id, | |
546 | wxEvtHandler* evtHandler); | |
547 | ||
548 | virtual void SetSize(const wxRect& rect); | |
9c71a138 | 549 | virtual void Show(bool show, wxGridCellAttr *attr = NULL); |
508011ce | 550 | |
f6bcfd97 | 551 | virtual bool IsAcceptedKey(wxKeyEvent& event); |
508011ce | 552 | virtual void BeginEdit(int row, int col, wxGrid* grid); |
3324d5f5 | 553 | virtual bool EndEdit(int row, int col, wxGrid* grid); |
508011ce VZ |
554 | |
555 | virtual void Reset(); | |
e195a54c | 556 | virtual void StartingClick(); |
63e2147c | 557 | virtual void StartingKey(wxKeyEvent& event); |
508011ce | 558 | |
c4608a8a VZ |
559 | virtual wxGridCellEditor *Clone() const |
560 | { return new wxGridCellBoolEditor; } | |
9c71a138 VZ |
561 | |
562 | // added GetValue so we can get the value which is in the control, see | |
563 | // also UseStringValues() | |
73145b0e | 564 | virtual wxString GetValue() const; |
c4608a8a | 565 | |
9c71a138 VZ |
566 | // set the string values returned by GetValue() for the true and false |
567 | // states, respectively | |
568 | static void UseStringValues(const wxString& valueTrue = _T("1"), | |
569 | const wxString& valueFalse = wxEmptyString); | |
570 | ||
571 | // return true if the given string is equal to the string representation of | |
572 | // true value which we currently use | |
573 | static bool IsTrueValue(const wxString& value); | |
574 | ||
508011ce VZ |
575 | protected: |
576 | wxCheckBox *CBox() const { return (wxCheckBox *)m_control; } | |
577 | ||
578 | private: | |
579 | bool m_startValue; | |
fc7a2a60 | 580 | |
9c71a138 VZ |
581 | static wxString ms_stringValues[2]; |
582 | ||
fc7a2a60 | 583 | DECLARE_NO_COPY_CLASS(wxGridCellBoolEditor) |
508011ce VZ |
584 | }; |
585 | ||
3379ed37 VZ |
586 | #endif // wxUSE_CHECKBOX |
587 | ||
588 | #if wxUSE_COMBOBOX | |
589 | ||
4ee5fc9c | 590 | // the editor for string data allowing to choose from the list of strings |
12f190b0 | 591 | class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor |
4ee5fc9c VZ |
592 | { |
593 | public: | |
594 | // if !allowOthers, user can't type a string not in choices array | |
c4608a8a | 595 | wxGridCellChoiceEditor(size_t count = 0, |
f6bcfd97 | 596 | const wxString choices[] = NULL, |
ca65c044 | 597 | bool allowOthers = false); |
7db33cc3 | 598 | wxGridCellChoiceEditor(const wxArrayString& choices, |
ca65c044 | 599 | bool allowOthers = false); |
4ee5fc9c VZ |
600 | |
601 | virtual void Create(wxWindow* parent, | |
602 | wxWindowID id, | |
603 | wxEvtHandler* evtHandler); | |
604 | ||
605 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); | |
606 | ||
607 | virtual void BeginEdit(int row, int col, wxGrid* grid); | |
3324d5f5 | 608 | virtual bool EndEdit(int row, int col, wxGrid* grid); |
4ee5fc9c VZ |
609 | |
610 | virtual void Reset(); | |
611 | ||
c4608a8a VZ |
612 | // parameters string format is "item1[,item2[...,itemN]]" |
613 | virtual void SetParameters(const wxString& params); | |
614 | ||
615 | virtual wxGridCellEditor *Clone() const; | |
9c71a138 | 616 | |
73145b0e JS |
617 | // added GetValue so we can get the value which is in the control |
618 | virtual wxString GetValue() const; | |
c4608a8a | 619 | |
4ee5fc9c VZ |
620 | protected: |
621 | wxComboBox *Combo() const { return (wxComboBox *)m_control; } | |
622 | ||
73145b0e JS |
623 | // DJC - (MAPTEK) you at least need access to m_choices if you |
624 | // wish to override this class | |
625 | protected: | |
4ee5fc9c VZ |
626 | wxString m_startValue; |
627 | wxArrayString m_choices; | |
628 | bool m_allowOthers; | |
fc7a2a60 VZ |
629 | |
630 | DECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor) | |
4ee5fc9c | 631 | }; |
a68c1246 | 632 | |
3379ed37 VZ |
633 | #endif // wxUSE_COMBOBOX |
634 | ||
b99be8fb VZ |
635 | // ---------------------------------------------------------------------------- |
636 | // wxGridCellAttr: this class can be used to alter the cells appearance in | |
637 | // the grid by changing their colour/font/... from default. An object of this | |
638 | // class may be returned by wxGridTable::GetAttr(). | |
639 | // ---------------------------------------------------------------------------- | |
640 | ||
12f190b0 | 641 | class WXDLLIMPEXP_ADV wxGridCellAttr : public wxClientDataContainer |
b99be8fb VZ |
642 | { |
643 | public: | |
19d7140e VZ |
644 | enum wxAttrKind |
645 | { | |
646 | Any, | |
647 | Default, | |
648 | Cell, | |
649 | Row, | |
650 | Col, | |
651 | Merged | |
652 | }; | |
653 | ||
b99be8fb | 654 | // ctors |
1df4050d | 655 | wxGridCellAttr(wxGridCellAttr *attrDefault = NULL) |
b99be8fb | 656 | { |
1df4050d VZ |
657 | Init(attrDefault); |
658 | ||
0767cb6f MB |
659 | // MB: args used to be 0,0 here but wxALIGN_LEFT is 0 |
660 | SetAlignment(-1, -1); | |
b99be8fb VZ |
661 | } |
662 | ||
283b7808 VZ |
663 | // VZ: considering the number of members wxGridCellAttr has now, this ctor |
664 | // seems to be pretty useless... may be we should just remove it? | |
b99be8fb VZ |
665 | wxGridCellAttr(const wxColour& colText, |
666 | const wxColour& colBack, | |
667 | const wxFont& font, | |
668 | int hAlign, | |
669 | int vAlign) | |
670 | : m_colText(colText), m_colBack(colBack), m_font(font) | |
671 | { | |
2e9a6788 | 672 | Init(); |
b99be8fb VZ |
673 | SetAlignment(hAlign, vAlign); |
674 | } | |
675 | ||
39bcce60 VZ |
676 | // creates a new copy of this object |
677 | wxGridCellAttr *Clone() const; | |
19d7140e | 678 | void MergeWith(wxGridCellAttr *mergefrom); |
b99be8fb | 679 | |
2e9a6788 VZ |
680 | // this class is ref counted: it is created with ref count of 1, so |
681 | // calling DecRef() once will delete it. Calling IncRef() allows to lock | |
682 | // it until the matching DecRef() is called | |
683 | void IncRef() { m_nRef++; } | |
8d7eaf91 | 684 | void DecRef() { if ( --m_nRef == 0 ) delete this; } |
2e9a6788 | 685 | |
b99be8fb VZ |
686 | // setters |
687 | void SetTextColour(const wxColour& colText) { m_colText = colText; } | |
688 | void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } | |
689 | void SetFont(const wxFont& font) { m_font = font; } | |
690 | void SetAlignment(int hAlign, int vAlign) | |
691 | { | |
692 | m_hAlign = hAlign; | |
693 | m_vAlign = vAlign; | |
694 | } | |
27f35b66 | 695 | void SetSize(int num_rows, int num_cols); |
ca65c044 | 696 | void SetOverflow(bool allow = true) |
ef5df12b | 697 | { m_overflow = allow ? Overflow : SingleCell; } |
ca65c044 | 698 | void SetReadOnly(bool isReadOnly = true) |
19d7140e | 699 | { m_isReadOnly = isReadOnly ? ReadOnly : ReadWrite; } |
b99be8fb | 700 | |
ab79958a VZ |
701 | // takes ownership of the pointer |
702 | void SetRenderer(wxGridCellRenderer *renderer) | |
39bcce60 | 703 | { wxSafeDecRef(m_renderer); m_renderer = renderer; } |
07296f0b | 704 | void SetEditor(wxGridCellEditor* editor) |
39bcce60 | 705 | { wxSafeDecRef(m_editor); m_editor = editor; } |
ab79958a | 706 | |
19d7140e VZ |
707 | void SetKind(wxAttrKind kind) { m_attrkind = kind; } |
708 | ||
b99be8fb VZ |
709 | // accessors |
710 | bool HasTextColour() const { return m_colText.Ok(); } | |
711 | bool HasBackgroundColour() const { return m_colBack.Ok(); } | |
712 | bool HasFont() const { return m_font.Ok(); } | |
0767cb6f | 713 | bool HasAlignment() const { return (m_hAlign != -1 || m_vAlign != -1); } |
2796cce3 | 714 | bool HasRenderer() const { return m_renderer != NULL; } |
07296f0b | 715 | bool HasEditor() const { return m_editor != NULL; } |
19d7140e | 716 | bool HasReadWriteMode() const { return m_isReadOnly != Unset; } |
b63fce94 | 717 | bool HasOverflowMode() const { return m_overflow != UnsetOverflow; } |
3100c3db | 718 | bool HasSize() const { return m_sizeRows != 1 || m_sizeCols != 1; } |
b99be8fb | 719 | |
2796cce3 RD |
720 | const wxColour& GetTextColour() const; |
721 | const wxColour& GetBackgroundColour() const; | |
722 | const wxFont& GetFont() const; | |
723 | void GetAlignment(int *hAlign, int *vAlign) const; | |
27f35b66 | 724 | void GetSize(int *num_rows, int *num_cols) const; |
ef5df12b | 725 | bool GetOverflow() const |
b63fce94 | 726 | { return m_overflow != SingleCell; } |
ef316e23 VZ |
727 | wxGridCellRenderer *GetRenderer(const wxGrid* grid, int row, int col) const; |
728 | wxGridCellEditor *GetEditor(const wxGrid* grid, int row, int col) const; | |
b99be8fb | 729 | |
19d7140e VZ |
730 | bool IsReadOnly() const { return m_isReadOnly == wxGridCellAttr::ReadOnly; } |
731 | ||
732 | wxAttrKind GetKind() { return m_attrkind; } | |
283b7808 | 733 | |
2796cce3 | 734 | void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; } |
ab79958a | 735 | |
338d1deb VZ |
736 | protected: |
737 | // the dtor is private because only DecRef() can delete us | |
738 | virtual ~wxGridCellAttr() | |
739 | { | |
740 | wxSafeDecRef(m_renderer); | |
741 | wxSafeDecRef(m_editor); | |
742 | } | |
743 | ||
b99be8fb | 744 | private: |
19d7140e VZ |
745 | enum wxAttrReadMode |
746 | { | |
747 | Unset = -1, | |
748 | ReadWrite, | |
749 | ReadOnly | |
30bc4a8f | 750 | }; |
19d7140e | 751 | |
b63fce94 RD |
752 | enum wxAttrOverflowMode |
753 | { | |
754 | UnsetOverflow = -1, | |
755 | Overflow, | |
756 | SingleCell | |
757 | }; | |
758 | ||
2e9a6788 | 759 | // the common part of all ctors |
1df4050d | 760 | void Init(wxGridCellAttr *attrDefault = NULL); |
2e9a6788 | 761 | |
2e9a6788 VZ |
762 | |
763 | // the ref count - when it goes to 0, we die | |
764 | size_t m_nRef; | |
765 | ||
b99be8fb VZ |
766 | wxColour m_colText, |
767 | m_colBack; | |
768 | wxFont m_font; | |
769 | int m_hAlign, | |
770 | m_vAlign; | |
27f35b66 SN |
771 | int m_sizeRows, |
772 | m_sizeCols; | |
ef5df12b RD |
773 | |
774 | wxAttrOverflowMode m_overflow; | |
2e9a6788 | 775 | |
07296f0b RD |
776 | wxGridCellRenderer* m_renderer; |
777 | wxGridCellEditor* m_editor; | |
778 | wxGridCellAttr* m_defGridAttr; | |
ab79958a | 779 | |
19d7140e VZ |
780 | wxAttrReadMode m_isReadOnly; |
781 | ||
782 | wxAttrKind m_attrkind; | |
283b7808 | 783 | |
a68c1246 | 784 | // use Clone() instead |
7ef4c90b | 785 | DECLARE_NO_COPY_CLASS(wxGridCellAttr) |
a68c1246 | 786 | |
2e9a6788 VZ |
787 | // suppress the stupid gcc warning about the class having private dtor and |
788 | // no friends | |
789 | friend class wxGridCellAttrDummyFriend; | |
b99be8fb VZ |
790 | }; |
791 | ||
792 | // ---------------------------------------------------------------------------- | |
793 | // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the | |
794 | // cell attributes. | |
795 | // ---------------------------------------------------------------------------- | |
796 | ||
797 | // implementation note: we separate it from wxGridTableBase because we wish to | |
798 | // avoid deriving a new table class if possible, and sometimes it will be | |
799 | // enough to just derive another wxGridCellAttrProvider instead | |
758cbedf VZ |
800 | // |
801 | // the default implementation is reasonably efficient for the generic case, | |
802 | // but you might still wish to implement your own for some specific situations | |
803 | // if you have performance problems with the stock one | |
12f190b0 | 804 | class WXDLLIMPEXP_ADV wxGridCellAttrProvider : public wxClientDataContainer |
b99be8fb VZ |
805 | { |
806 | public: | |
807 | wxGridCellAttrProvider(); | |
808 | virtual ~wxGridCellAttrProvider(); | |
809 | ||
2e9a6788 | 810 | // DecRef() must be called on the returned pointer |
19d7140e VZ |
811 | virtual wxGridCellAttr *GetAttr(int row, int col, |
812 | wxGridCellAttr::wxAttrKind kind ) const; | |
2e9a6788 | 813 | |
758cbedf VZ |
814 | // all these functions take ownership of the pointer, don't call DecRef() |
815 | // on it | |
2e9a6788 | 816 | virtual void SetAttr(wxGridCellAttr *attr, int row, int col); |
758cbedf VZ |
817 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); |
818 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
d1c0b4f9 VZ |
819 | |
820 | // these functions must be called whenever some rows/cols are deleted | |
821 | // because the internal data must be updated then | |
4d60017a SN |
822 | void UpdateAttrRows( size_t pos, int numRows ); |
823 | void UpdateAttrCols( size_t pos, int numCols ); | |
b99be8fb VZ |
824 | |
825 | private: | |
826 | void InitData(); | |
827 | ||
828 | wxGridCellAttrProviderData *m_data; | |
22f3361e VZ |
829 | |
830 | DECLARE_NO_COPY_CLASS(wxGridCellAttrProvider) | |
b99be8fb | 831 | }; |
f85afd4e | 832 | |
10a4531d VZ |
833 | // ---------------------------------------------------------------------------- |
834 | // wxGridCellCoords: location of a cell in the grid | |
835 | // ---------------------------------------------------------------------------- | |
836 | ||
837 | class WXDLLIMPEXP_ADV wxGridCellCoords | |
838 | { | |
839 | public: | |
840 | wxGridCellCoords() { m_row = m_col = -1; } | |
841 | wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; } | |
842 | ||
843 | // default copy ctor is ok | |
844 | ||
845 | int GetRow() const { return m_row; } | |
846 | void SetRow( int n ) { m_row = n; } | |
847 | int GetCol() const { return m_col; } | |
848 | void SetCol( int n ) { m_col = n; } | |
849 | void Set( int row, int col ) { m_row = row; m_col = col; } | |
850 | ||
851 | wxGridCellCoords& operator=( const wxGridCellCoords& other ) | |
852 | { | |
853 | if ( &other != this ) | |
854 | { | |
855 | m_row=other.m_row; | |
856 | m_col=other.m_col; | |
857 | } | |
858 | return *this; | |
859 | } | |
860 | ||
861 | bool operator==( const wxGridCellCoords& other ) const | |
862 | { | |
863 | return (m_row == other.m_row && m_col == other.m_col); | |
864 | } | |
865 | ||
866 | bool operator!=( const wxGridCellCoords& other ) const | |
867 | { | |
868 | return (m_row != other.m_row || m_col != other.m_col); | |
869 | } | |
870 | ||
871 | bool operator!() const | |
872 | { | |
873 | return (m_row == -1 && m_col == -1 ); | |
874 | } | |
875 | ||
876 | private: | |
877 | int m_row; | |
878 | int m_col; | |
879 | }; | |
880 | ||
881 | ||
882 | // For comparisons... | |
f85afd4e | 883 | // |
10a4531d VZ |
884 | extern WXDLLIMPEXP_ADV wxGridCellCoords wxGridNoCellCoords; |
885 | extern WXDLLIMPEXP_ADV wxRect wxGridNoCellRect; | |
886 | ||
887 | // An array of cell coords... | |
f85afd4e | 888 | // |
10a4531d VZ |
889 | WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords, wxGridCellCoordsArray, |
890 | class WXDLLIMPEXP_ADV); | |
f85afd4e | 891 | |
10a4531d VZ |
892 | // ---------------------------------------------------------------------------- |
893 | // Grid table classes | |
894 | // ---------------------------------------------------------------------------- | |
f85afd4e | 895 | |
10a4531d VZ |
896 | // the abstract base class |
897 | class WXDLLIMPEXP_ADV wxGridTableBase : public wxObject, | |
898 | public wxClientDataContainer | |
f85afd4e | 899 | { |
60ff3b99 | 900 | public: |
f85afd4e MB |
901 | wxGridTableBase(); |
902 | virtual ~wxGridTableBase(); | |
903 | ||
904 | // You must override these functions in a derived table class | |
905 | // | |
e32352cf SN |
906 | virtual int GetNumberRows() = 0; |
907 | virtual int GetNumberCols() = 0; | |
f85afd4e | 908 | virtual bool IsEmptyCell( int row, int col ) = 0; |
10a4531d VZ |
909 | |
910 | bool IsEmpty(const wxGridCellCoords& coord) | |
911 | { | |
912 | return IsEmptyCell(coord.GetRow(), coord.GetCol()); | |
913 | } | |
914 | ||
f2d76237 RD |
915 | virtual wxString GetValue( int row, int col ) = 0; |
916 | virtual void SetValue( int row, int col, const wxString& value ) = 0; | |
917 | ||
918 | // Data type determination and value access | |
919 | virtual wxString GetTypeName( int row, int col ); | |
920 | virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); | |
921 | virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); | |
922 | ||
923 | virtual long GetValueAsLong( int row, int col ); | |
924 | virtual double GetValueAsDouble( int row, int col ); | |
925 | virtual bool GetValueAsBool( int row, int col ); | |
926 | ||
927 | virtual void SetValueAsLong( int row, int col, long value ); | |
928 | virtual void SetValueAsDouble( int row, int col, double value ); | |
929 | virtual void SetValueAsBool( int row, int col, bool value ); | |
930 | ||
931 | // For user defined types | |
932 | virtual void* GetValueAsCustom( int row, int col, const wxString& typeName ); | |
933 | virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value ); | |
934 | ||
60ff3b99 | 935 | |
f85afd4e MB |
936 | // Overriding these is optional |
937 | // | |
938 | virtual void SetView( wxGrid *grid ) { m_view = grid; } | |
939 | virtual wxGrid * GetView() const { return m_view; } | |
940 | ||
941 | virtual void Clear() {} | |
942 | virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 ); | |
943 | virtual bool AppendRows( size_t numRows = 1 ); | |
944 | virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); | |
945 | virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 ); | |
946 | virtual bool AppendCols( size_t numCols = 1 ); | |
947 | virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); | |
948 | ||
949 | virtual wxString GetRowLabelValue( int row ); | |
950 | virtual wxString GetColLabelValue( int col ); | |
af111fc3 JS |
951 | virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {} |
952 | virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {} | |
60ff3b99 | 953 | |
b99be8fb VZ |
954 | // Attribute handling |
955 | // | |
956 | ||
957 | // give us the attr provider to use - we take ownership of the pointer | |
958 | void SetAttrProvider(wxGridCellAttrProvider *attrProvider); | |
959 | ||
960 | // get the currently used attr provider (may be NULL) | |
961 | wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; } | |
962 | ||
f2d76237 RD |
963 | // Does this table allow attributes? Default implementation creates |
964 | // a wxGridCellAttrProvider if necessary. | |
965 | virtual bool CanHaveAttributes(); | |
966 | ||
b99be8fb | 967 | // by default forwarded to wxGridCellAttrProvider if any. May be |
f2d76237 | 968 | // overridden to handle attributes directly in the table. |
19d7140e VZ |
969 | virtual wxGridCellAttr *GetAttr( int row, int col, |
970 | wxGridCellAttr::wxAttrKind kind ); | |
971 | ||
b99be8fb | 972 | |
758cbedf VZ |
973 | // these functions take ownership of the pointer |
974 | virtual void SetAttr(wxGridCellAttr* attr, int row, int col); | |
975 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); | |
976 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
b99be8fb | 977 | |
60ff3b99 VZ |
978 | private: |
979 | wxGrid * m_view; | |
b99be8fb | 980 | wxGridCellAttrProvider *m_attrProvider; |
60ff3b99 | 981 | |
3839f37e | 982 | DECLARE_ABSTRACT_CLASS(wxGridTableBase) |
22f3361e | 983 | DECLARE_NO_COPY_CLASS(wxGridTableBase) |
f85afd4e MB |
984 | }; |
985 | ||
986 | ||
b99be8fb VZ |
987 | // ---------------------------------------------------------------------------- |
988 | // wxGridTableMessage | |
989 | // ---------------------------------------------------------------------------- | |
f85afd4e MB |
990 | |
991 | // IDs for messages sent from grid table to view | |
992 | // | |
60ff3b99 VZ |
993 | enum wxGridTableRequest |
994 | { | |
f85afd4e MB |
995 | wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000, |
996 | wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES, | |
997 | wxGRIDTABLE_NOTIFY_ROWS_INSERTED, | |
998 | wxGRIDTABLE_NOTIFY_ROWS_APPENDED, | |
999 | wxGRIDTABLE_NOTIFY_ROWS_DELETED, | |
1000 | wxGRIDTABLE_NOTIFY_COLS_INSERTED, | |
1001 | wxGRIDTABLE_NOTIFY_COLS_APPENDED, | |
1002 | wxGRIDTABLE_NOTIFY_COLS_DELETED | |
1003 | }; | |
1004 | ||
12f190b0 | 1005 | class WXDLLIMPEXP_ADV wxGridTableMessage |
f85afd4e | 1006 | { |
60ff3b99 | 1007 | public: |
f85afd4e MB |
1008 | wxGridTableMessage(); |
1009 | wxGridTableMessage( wxGridTableBase *table, int id, | |
1010 | int comInt1 = -1, | |
1011 | int comInt2 = -1 ); | |
1012 | ||
1013 | void SetTableObject( wxGridTableBase *table ) { m_table = table; } | |
1014 | wxGridTableBase * GetTableObject() const { return m_table; } | |
1015 | void SetId( int id ) { m_id = id; } | |
1016 | int GetId() { return m_id; } | |
1017 | void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; } | |
1018 | int GetCommandInt() { return m_comInt1; } | |
1019 | void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; } | |
60ff3b99 VZ |
1020 | int GetCommandInt2() { return m_comInt2; } |
1021 | ||
1022 | private: | |
1023 | wxGridTableBase *m_table; | |
1024 | int m_id; | |
1025 | int m_comInt1; | |
1026 | int m_comInt2; | |
22f3361e VZ |
1027 | |
1028 | DECLARE_NO_COPY_CLASS(wxGridTableMessage) | |
f85afd4e MB |
1029 | }; |
1030 | ||
1031 | ||
1032 | ||
1033 | // ------ wxGridStringArray | |
1034 | // A 2-dimensional array of strings for data values | |
1035 | // | |
1036 | ||
160ba750 VS |
1037 | WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString, wxGridStringArray, |
1038 | class WXDLLIMPEXP_ADV); | |
2d66e025 | 1039 | |
f85afd4e MB |
1040 | |
1041 | ||
1042 | // ------ wxGridStringTable | |
1043 | // | |
1044 | // Simplest type of data table for a grid for small tables of strings | |
1045 | // that are stored in memory | |
1046 | // | |
1047 | ||
12f190b0 | 1048 | class WXDLLIMPEXP_ADV wxGridStringTable : public wxGridTableBase |
f85afd4e | 1049 | { |
60ff3b99 | 1050 | public: |
f85afd4e MB |
1051 | wxGridStringTable(); |
1052 | wxGridStringTable( int numRows, int numCols ); | |
e669d97a | 1053 | virtual ~wxGridStringTable(); |
f85afd4e MB |
1054 | |
1055 | // these are pure virtual in wxGridTableBase | |
1056 | // | |
e32352cf SN |
1057 | int GetNumberRows(); |
1058 | int GetNumberCols(); | |
f85afd4e MB |
1059 | wxString GetValue( int row, int col ); |
1060 | void SetValue( int row, int col, const wxString& s ); | |
1061 | bool IsEmptyCell( int row, int col ); | |
60ff3b99 | 1062 | |
f85afd4e MB |
1063 | // overridden functions from wxGridTableBase |
1064 | // | |
1065 | void Clear(); | |
1066 | bool InsertRows( size_t pos = 0, size_t numRows = 1 ); | |
1067 | bool AppendRows( size_t numRows = 1 ); | |
1068 | bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); | |
1069 | bool InsertCols( size_t pos = 0, size_t numCols = 1 ); | |
1070 | bool AppendCols( size_t numCols = 1 ); | |
1071 | bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); | |
1072 | ||
1073 | void SetRowLabelValue( int row, const wxString& ); | |
1074 | void SetColLabelValue( int col, const wxString& ); | |
1075 | wxString GetRowLabelValue( int row ); | |
1076 | wxString GetColLabelValue( int col ); | |
60ff3b99 VZ |
1077 | |
1078 | private: | |
1079 | wxGridStringArray m_data; | |
1080 | ||
1081 | // These only get used if you set your own labels, otherwise the | |
1082 | // GetRow/ColLabelValue functions return wxGridTableBase defaults | |
1083 | // | |
1084 | wxArrayString m_rowLabels; | |
1085 | wxArrayString m_colLabels; | |
1086 | ||
fc7a2a60 | 1087 | DECLARE_DYNAMIC_CLASS_NO_COPY( wxGridStringTable ) |
f85afd4e MB |
1088 | }; |
1089 | ||
1090 | ||
1091 | ||
43947979 | 1092 | // ============================================================================ |
f85afd4e | 1093 | // Grid view classes |
43947979 VZ |
1094 | // ============================================================================ |
1095 | ||
b99be8fb VZ |
1096 | // ---------------------------------------------------------------------------- |
1097 | // wxGrid | |
1098 | // ---------------------------------------------------------------------------- | |
f85afd4e | 1099 | |
12f190b0 | 1100 | class WXDLLIMPEXP_ADV wxGrid : public wxScrolledWindow |
60ff3b99 VZ |
1101 | { |
1102 | public: | |
bf2c8b31 VZ |
1103 | // possible selection modes |
1104 | enum wxGridSelectionModes | |
1105 | { | |
1106 | wxGridSelectCells = 0, // allow selecting anything | |
1107 | wxGridSelectRows = 1, // allow selecting only entire rows | |
1108 | wxGridSelectColumns = 2, // allow selecting only entire columns | |
1109 | wxGridSelectRowsOrColumns = wxGridSelectRows | wxGridSelectColumns | |
1110 | }; | |
1111 | ||
1112 | // creation and destruction | |
1113 | // ------------------------ | |
1114 | ||
1115 | // ctor and Create() create the grid window, as with the other controls | |
f9549841 | 1116 | wxGrid(); |
986a98c6 | 1117 | |
bf2c8b31 | 1118 | wxGrid(wxWindow *parent, |
986a98c6 SC |
1119 | wxWindowID id, |
1120 | const wxPoint& pos = wxDefaultPosition, | |
1121 | const wxSize& size = wxDefaultSize, | |
1122 | long style = wxWANTS_CHARS, | |
bf2c8b31 | 1123 | const wxString& name = wxGridNameStr); |
60ff3b99 | 1124 | |
bf2c8b31 VZ |
1125 | bool Create(wxWindow *parent, |
1126 | wxWindowID id, | |
1127 | const wxPoint& pos = wxDefaultPosition, | |
1128 | const wxSize& size = wxDefaultSize, | |
1129 | long style = wxWANTS_CHARS, | |
1130 | const wxString& name = wxGridNameStr); | |
2d66e025 | 1131 | |
e669d97a | 1132 | virtual ~wxGrid(); |
f85afd4e | 1133 | |
bf2c8b31 VZ |
1134 | // however to initialize grid data either CreateGrid() or SetTable() must |
1135 | // be also called | |
b5808881 | 1136 | |
bf2c8b31 VZ |
1137 | // this is basically equivalent to |
1138 | // | |
1139 | // SetTable(new wxGridStringTable(numRows, numCols), true, selmode) | |
1140 | // | |
b5808881 | 1141 | bool CreateGrid( int numRows, int numCols, |
801a9641 | 1142 | wxGridSelectionModes selmode = wxGridSelectCells ); |
2d66e025 | 1143 | |
bf2c8b31 VZ |
1144 | bool SetTable( wxGridTableBase *table, |
1145 | bool takeOwnership = false, | |
1146 | wxGridSelectionModes selmode = wxGridSelectCells ); | |
1147 | ||
1148 | ||
801a9641 VZ |
1149 | void SetSelectionMode(wxGridSelectionModes selmode); |
1150 | wxGridSelectionModes GetSelectionMode() const; | |
60ff3b99 | 1151 | |
2d66e025 MB |
1152 | // ------ grid dimensions |
1153 | // | |
ef316e23 VZ |
1154 | int GetNumberRows() const { return m_numRows; } |
1155 | int GetNumberCols() const { return m_numCols; } | |
2d66e025 | 1156 | |
60ff3b99 | 1157 | |
2d66e025 MB |
1158 | // ------ display update functions |
1159 | // | |
ef316e23 | 1160 | wxArrayInt CalcRowLabelsExposed( const wxRegion& reg ) const; |
8fb66724 | 1161 | |
ef316e23 VZ |
1162 | wxArrayInt CalcColLabelsExposed( const wxRegion& reg ) const; |
1163 | wxGridCellCoordsArray CalcCellsExposed( const wxRegion& reg ) const; | |
60ff3b99 | 1164 | |
2d66e025 | 1165 | |
2d66e025 MB |
1166 | // ------ event handlers |
1167 | // | |
1168 | void ProcessRowLabelMouseEvent( wxMouseEvent& event ); | |
1169 | void ProcessColLabelMouseEvent( wxMouseEvent& event ); | |
1170 | void ProcessCornerLabelMouseEvent( wxMouseEvent& event ); | |
60ff3b99 | 1171 | void ProcessGridCellMouseEvent( wxMouseEvent& event ); |
2d66e025 | 1172 | bool ProcessTableMessage( wxGridTableMessage& ); |
f85afd4e | 1173 | |
6d004f67 MB |
1174 | void DoEndDragResizeRow(); |
1175 | void DoEndDragResizeCol(); | |
d4175745 | 1176 | void DoEndDragMoveCol(); |
60ff3b99 | 1177 | |
f85afd4e | 1178 | wxGridTableBase * GetTable() const { return m_table; } |
f85afd4e MB |
1179 | |
1180 | void ClearGrid(); | |
10a4531d VZ |
1181 | bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true) |
1182 | { | |
1183 | return DoModifyLines(&wxGridTableBase::InsertRows, | |
1184 | pos, numRows, updateLabels); | |
1185 | } | |
1186 | bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true) | |
1187 | { | |
1188 | return DoModifyLines(&wxGridTableBase::InsertCols, | |
1189 | pos, numCols, updateLabels); | |
1190 | } | |
1191 | ||
1192 | bool AppendRows(int numRows = 1, bool updateLabels = true) | |
1193 | { | |
1194 | return DoAppendLines(&wxGridTableBase::AppendRows, numRows, updateLabels); | |
1195 | } | |
1196 | bool AppendCols(int numCols = 1, bool updateLabels = true) | |
1197 | { | |
1198 | return DoAppendLines(&wxGridTableBase::AppendCols, numCols, updateLabels); | |
1199 | } | |
1200 | ||
1201 | bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true) | |
1202 | { | |
1203 | return DoModifyLines(&wxGridTableBase::DeleteRows, | |
1204 | pos, numRows, updateLabels); | |
1205 | } | |
1206 | bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true) | |
1207 | { | |
1208 | return DoModifyLines(&wxGridTableBase::DeleteCols, | |
1209 | pos, numCols, updateLabels); | |
1210 | } | |
f85afd4e | 1211 | |
d10f4bf9 | 1212 | void DrawGridCellArea( wxDC& dc , const wxGridCellCoordsArray& cells ); |
7c8a8ad5 | 1213 | void DrawGridSpace( wxDC& dc ); |
2d66e025 | 1214 | void DrawCellBorder( wxDC& dc, const wxGridCellCoords& ); |
4634a5d6 | 1215 | void DrawAllGridLines( wxDC& dc, const wxRegion & reg ); |
2d66e025 | 1216 | void DrawCell( wxDC& dc, const wxGridCellCoords& ); |
d10f4bf9 | 1217 | void DrawHighlight(wxDC& dc, const wxGridCellCoordsArray& cells); |
d16c04bb VZ |
1218 | |
1219 | // this function is called when the current cell highlight must be redrawn | |
1220 | // and may be overridden by the user | |
1221 | virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ); | |
1f1ce288 | 1222 | |
6914b57a JS |
1223 | virtual void DrawRowLabels( wxDC& dc, const wxArrayInt& rows ); |
1224 | virtual void DrawRowLabel( wxDC& dc, int row ); | |
8fb66724 | 1225 | |
6914b57a JS |
1226 | virtual void DrawColLabels( wxDC& dc, const wxArrayInt& cols ); |
1227 | virtual void DrawColLabel( wxDC& dc, int col ); | |
60ff3b99 | 1228 | |
ff72f628 | 1229 | virtual void DrawCornerLabel(wxDC& dc); |
f85afd4e | 1230 | |
2d66e025 | 1231 | // ------ Cell text drawing functions |
f85afd4e | 1232 | // |
2d66e025 | 1233 | void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&, |
4c7277db | 1234 | int horizontalAlignment = wxALIGN_LEFT, |
d43851f7 JS |
1235 | int verticalAlignment = wxALIGN_TOP, |
1236 | int textOrientation = wxHORIZONTAL ); | |
30bc4a8f | 1237 | |
d10f4bf9 VZ |
1238 | void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&, |
1239 | int horizontalAlignment = wxALIGN_LEFT, | |
d43851f7 JS |
1240 | int verticalAlignment = wxALIGN_TOP, |
1241 | int textOrientation = wxHORIZONTAL ); | |
d10f4bf9 | 1242 | |
f85afd4e | 1243 | |
ef316e23 | 1244 | // Split a string containing newline characters into an array of |
2d66e025 MB |
1245 | // strings and return the number of lines |
1246 | // | |
ef316e23 | 1247 | void StringToLines( const wxString& value, wxArrayString& lines ) const; |
60ff3b99 | 1248 | |
fbfb8bcc | 1249 | void GetTextBoxSize( const wxDC& dc, |
d10f4bf9 | 1250 | const wxArrayString& lines, |
ef316e23 | 1251 | long *width, long *height ) const; |
60ff3b99 | 1252 | |
2d66e025 | 1253 | |
f85afd4e MB |
1254 | // ------ |
1255 | // Code that does a lot of grid modification can be enclosed | |
1256 | // between BeginBatch() and EndBatch() calls to avoid screen | |
1257 | // flicker | |
1258 | // | |
1259 | void BeginBatch() { m_batchCount++; } | |
f6bcfd97 BP |
1260 | void EndBatch(); |
1261 | ||
f85afd4e MB |
1262 | int GetBatchCount() { return m_batchCount; } |
1263 | ||
ca65c044 | 1264 | virtual void Refresh(bool eraseb = true, |
b7282ad2 | 1265 | const wxRect* rect = (const wxRect *) NULL); |
27f35b66 | 1266 | |
d8232393 MB |
1267 | // Use this, rather than wxWindow::Refresh(), to force an |
1268 | // immediate repainting of the grid. Has no effect if you are | |
1269 | // already inside a BeginBatch / EndBatch block. | |
1270 | // | |
1271 | // This function is necessary because wxGrid has a minimal OnPaint() | |
1272 | // handler to reduce screen flicker. | |
1273 | // | |
1274 | void ForceRefresh(); | |
d2520c85 | 1275 | |
2d66e025 MB |
1276 | |
1277 | // ------ edit control functions | |
1278 | // | |
84035150 | 1279 | bool IsEditable() const { return m_editable; } |
2d66e025 MB |
1280 | void EnableEditing( bool edit ); |
1281 | ||
ca65c044 WS |
1282 | void EnableCellEditControl( bool enable = true ); |
1283 | void DisableCellEditControl() { EnableCellEditControl(false); } | |
b54ba671 VZ |
1284 | bool CanEnableCellControl() const; |
1285 | bool IsCellEditControlEnabled() const; | |
f6bcfd97 | 1286 | bool IsCellEditControlShown() const; |
2d66e025 | 1287 | |
b54ba671 | 1288 | bool IsCurrentCellReadOnly() const; |
2d66e025 | 1289 | |
2d66e025 MB |
1290 | void ShowCellEditControl(); |
1291 | void HideCellEditControl(); | |
2d66e025 MB |
1292 | void SaveEditControlValue(); |
1293 | ||
60ff3b99 | 1294 | |
2d66e025 | 1295 | // ------ grid location functions |
60ff3b99 | 1296 | // Note that all of these functions work with the logical coordinates of |
2d66e025 MB |
1297 | // grid cells and labels so you will need to convert from device |
1298 | // coordinates for mouse events etc. | |
1299 | // | |
ef316e23 | 1300 | void XYToCell( int x, int y, wxGridCellCoords& ) const; |
bec70262 | 1301 | int YToRow( int y, bool clipToMinMax = false ) const; |
ef316e23 | 1302 | int XToCol( int x, bool clipToMinMax = false ) const; |
2d66e025 | 1303 | |
ef316e23 VZ |
1304 | int YToEdgeOfRow( int y ) const; |
1305 | int XToEdgeOfCol( int x ) const; | |
2d66e025 | 1306 | |
ef316e23 VZ |
1307 | wxRect CellToRect( int row, int col ) const; |
1308 | wxRect CellToRect( const wxGridCellCoords& coords ) const | |
2d66e025 MB |
1309 | { return CellToRect( coords.GetRow(), coords.GetCol() ); } |
1310 | ||
ef316e23 VZ |
1311 | int GetGridCursorRow() const { return m_currentCellCoords.GetRow(); } |
1312 | int GetGridCursorCol() const { return m_currentCellCoords.GetCol(); } | |
60ff3b99 | 1313 | |
2d66e025 MB |
1314 | // check to see if a cell is either wholly visible (the default arg) or |
1315 | // at least partially visible in the grid window | |
1316 | // | |
ef316e23 VZ |
1317 | bool IsVisible( int row, int col, bool wholeCellVisible = true ) const; |
1318 | bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = true ) const | |
2d66e025 MB |
1319 | { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); } |
1320 | void MakeCellVisible( int row, int col ); | |
1321 | void MakeCellVisible( const wxGridCellCoords& coords ) | |
1322 | { MakeCellVisible( coords.GetRow(), coords.GetCol() ); } | |
1323 | ||
60ff3b99 | 1324 | |
2d66e025 MB |
1325 | // ------ grid cursor movement functions |
1326 | // | |
dfaf42d2 | 1327 | void SetGridCursor( int row, int col ) |
b27f2615 | 1328 | { SetCurrentCell( wxGridCellCoords(row, col) ); } |
dfaf42d2 | 1329 | |
5c8fc7c1 SN |
1330 | bool MoveCursorUp( bool expandSelection ); |
1331 | bool MoveCursorDown( bool expandSelection ); | |
1332 | bool MoveCursorLeft( bool expandSelection ); | |
1333 | bool MoveCursorRight( bool expandSelection ); | |
2d66e025 MB |
1334 | bool MovePageDown(); |
1335 | bool MovePageUp(); | |
5c8fc7c1 SN |
1336 | bool MoveCursorUpBlock( bool expandSelection ); |
1337 | bool MoveCursorDownBlock( bool expandSelection ); | |
1338 | bool MoveCursorLeftBlock( bool expandSelection ); | |
1339 | bool MoveCursorRightBlock( bool expandSelection ); | |
2d66e025 | 1340 | |
60ff3b99 | 1341 | |
f85afd4e MB |
1342 | // ------ label and gridline formatting |
1343 | // | |
ef316e23 VZ |
1344 | int GetDefaultRowLabelSize() const { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; } |
1345 | int GetRowLabelSize() const { return m_rowLabelWidth; } | |
1346 | int GetDefaultColLabelSize() const { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; } | |
1347 | int GetColLabelSize() const { return m_colLabelHeight; } | |
1348 | wxColour GetLabelBackgroundColour() const { return m_labelBackgroundColour; } | |
1349 | wxColour GetLabelTextColour() const { return m_labelTextColour; } | |
1350 | wxFont GetLabelFont() const { return m_labelFont; } | |
1351 | void GetRowLabelAlignment( int *horiz, int *vert ) const; | |
1352 | void GetColLabelAlignment( int *horiz, int *vert ) const; | |
1353 | int GetColLabelTextOrientation() const; | |
1354 | wxString GetRowLabelValue( int row ) const; | |
1355 | wxString GetColLabelValue( int col ) const; | |
1356 | wxColour GetGridLineColour() const { return m_gridLineColour; } | |
3d3f3e37 VZ |
1357 | |
1358 | // these methods may be overridden to customize individual grid lines | |
1359 | // appearance | |
1360 | virtual wxPen GetDefaultGridLinePen(); | |
1361 | virtual wxPen GetRowGridLinePen(int row); | |
1362 | virtual wxPen GetColGridLinePen(int col); | |
ef316e23 VZ |
1363 | wxColour GetCellHighlightColour() const { return m_cellHighlightColour; } |
1364 | int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; } | |
1365 | int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth; } | |
f85afd4e | 1366 | |
71cf399f | 1367 | void SetUseNativeColLabels( bool native = true ); |
ab79958a | 1368 | void SetRowLabelSize( int width ); |
f85afd4e | 1369 | void SetColLabelSize( int height ); |
0a9ca9c4 RR |
1370 | void HideRowLabels() { SetRowLabelSize( 0 ); } |
1371 | void HideColLabels() { SetColLabelSize( 0 ); } | |
f85afd4e MB |
1372 | void SetLabelBackgroundColour( const wxColour& ); |
1373 | void SetLabelTextColour( const wxColour& ); | |
1374 | void SetLabelFont( const wxFont& ); | |
1375 | void SetRowLabelAlignment( int horiz, int vert ); | |
1376 | void SetColLabelAlignment( int horiz, int vert ); | |
d43851f7 | 1377 | void SetColLabelTextOrientation( int textOrientation ); |
f85afd4e MB |
1378 | void SetRowLabelValue( int row, const wxString& ); |
1379 | void SetColLabelValue( int col, const wxString& ); | |
1380 | void SetGridLineColour( const wxColour& ); | |
f6bcfd97 | 1381 | void SetCellHighlightColour( const wxColour& ); |
d2520c85 RD |
1382 | void SetCellHighlightPenWidth(int width); |
1383 | void SetCellHighlightROPenWidth(int width); | |
28a77bc4 | 1384 | |
ca65c044 WS |
1385 | void EnableDragRowSize( bool enable = true ); |
1386 | void DisableDragRowSize() { EnableDragRowSize( false ); } | |
ef316e23 | 1387 | bool CanDragRowSize() const { return m_canDragRowSize; } |
ca65c044 WS |
1388 | void EnableDragColSize( bool enable = true ); |
1389 | void DisableDragColSize() { EnableDragColSize( false ); } | |
ef316e23 | 1390 | bool CanDragColSize() const { return m_canDragColSize; } |
d4175745 VZ |
1391 | void EnableDragColMove( bool enable = true ); |
1392 | void DisableDragColMove() { EnableDragColMove( false ); } | |
ef316e23 | 1393 | bool CanDragColMove() const { return m_canDragColMove; } |
ca65c044 WS |
1394 | void EnableDragGridSize(bool enable = true); |
1395 | void DisableDragGridSize() { EnableDragGridSize(false); } | |
ef316e23 | 1396 | bool CanDragGridSize() const { return m_canDragGridSize; } |
4cfa5de6 | 1397 | |
79dbea21 RD |
1398 | void EnableDragCell( bool enable = true ); |
1399 | void DisableDragCell() { EnableDragCell( false ); } | |
ef316e23 | 1400 | bool CanDragCell() const { return m_canDragCell; } |
79dbea21 | 1401 | |
27f35b66 SN |
1402 | // this sets the specified attribute for this cell or in this row/col |
1403 | void SetAttr(int row, int col, wxGridCellAttr *attr); | |
758cbedf VZ |
1404 | void SetRowAttr(int row, wxGridCellAttr *attr); |
1405 | void SetColAttr(int col, wxGridCellAttr *attr); | |
1406 | ||
71e60f70 RD |
1407 | // returns the attribute we may modify in place: a new one if this cell |
1408 | // doesn't have any yet or the existing one if it does | |
1409 | // | |
1410 | // DecRef() must be called on the returned pointer, as usual | |
1411 | wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const; | |
1412 | ||
d94c09cd | 1413 | |
0b190b0f VZ |
1414 | // shortcuts for setting the column parameters |
1415 | ||
1416 | // set the format for the data in the column: default is string | |
1417 | void SetColFormatBool(int col); | |
1418 | void SetColFormatNumber(int col); | |
1419 | void SetColFormatFloat(int col, int width = -1, int precision = -1); | |
1420 | void SetColFormatCustom(int col, const wxString& typeName); | |
1421 | ||
ca65c044 | 1422 | void EnableGridLines( bool enable = true ); |
ef316e23 | 1423 | bool GridLinesEnabled() const { return m_gridLinesEnabled; } |
f85afd4e | 1424 | |
f85afd4e MB |
1425 | // ------ row and col formatting |
1426 | // | |
ef316e23 VZ |
1427 | int GetDefaultRowSize() const; |
1428 | int GetRowSize( int row ) const; | |
1429 | int GetDefaultColSize() const; | |
1430 | int GetColSize( int col ) const; | |
1431 | wxColour GetDefaultCellBackgroundColour() const; | |
1432 | wxColour GetCellBackgroundColour( int row, int col ) const; | |
1433 | wxColour GetDefaultCellTextColour() const; | |
1434 | wxColour GetCellTextColour( int row, int col ) const; | |
1435 | wxFont GetDefaultCellFont() const; | |
1436 | wxFont GetCellFont( int row, int col ) const; | |
1437 | void GetDefaultCellAlignment( int *horiz, int *vert ) const; | |
1438 | void GetCellAlignment( int row, int col, int *horiz, int *vert ) const; | |
1439 | bool GetDefaultCellOverflow() const; | |
1440 | bool GetCellOverflow( int row, int col ) const; | |
1441 | void GetCellSize( int row, int col, int *num_rows, int *num_cols ) const; | |
bec70262 VZ |
1442 | wxSize GetCellSize(const wxGridCellCoords& coords) |
1443 | { | |
1444 | wxSize s; | |
1445 | GetCellSize(coords.GetRow(), coords.GetCol(), &s.x, &s.y); | |
1446 | return s; | |
1447 | } | |
60ff3b99 | 1448 | |
ca65c044 | 1449 | void SetDefaultRowSize( int height, bool resizeExistingRows = false ); |
f85afd4e | 1450 | void SetRowSize( int row, int height ); |
ca65c044 | 1451 | void SetDefaultColSize( int width, bool resizeExistingCols = false ); |
8fb66724 | 1452 | |
f85afd4e | 1453 | void SetColSize( int col, int width ); |
43947979 | 1454 | |
d4175745 VZ |
1455 | //Column positions |
1456 | int GetColAt( int colPos ) const | |
1457 | { | |
1458 | if ( m_colAt.IsEmpty() ) | |
1459 | return colPos; | |
1460 | else | |
1461 | return m_colAt[colPos]; | |
1462 | } | |
1463 | ||
1464 | void SetColPos( int colID, int newPos ); | |
1465 | ||
1466 | int GetColPos( int colID ) const | |
1467 | { | |
1468 | if ( m_colAt.IsEmpty() ) | |
1469 | return colID; | |
1470 | else | |
1471 | { | |
1472 | for ( int i = 0; i < m_numCols; i++ ) | |
1473 | { | |
1474 | if ( m_colAt[i] == colID ) | |
1475 | return i; | |
1476 | } | |
1477 | } | |
1478 | ||
1479 | return -1; | |
1480 | } | |
1481 | ||
af547d51 | 1482 | // automatically size the column or row to fit to its contents, if |
ca65c044 | 1483 | // setAsMin is true, this optimal width will also be set as minimal width |
af547d51 | 1484 | // for this column |
ca65c044 | 1485 | void AutoSizeColumn( int col, bool setAsMin = true ) |
733f486a | 1486 | { AutoSizeColOrRow(col, setAsMin, wxGRID_COLUMN); } |
ca65c044 | 1487 | void AutoSizeRow( int row, bool setAsMin = true ) |
733f486a | 1488 | { AutoSizeColOrRow(row, setAsMin, wxGRID_ROW); } |
65e4e78e VZ |
1489 | |
1490 | // auto size all columns (very ineffective for big grids!) | |
ca65c044 WS |
1491 | void AutoSizeColumns( bool setAsMin = true ) |
1492 | { (void)SetOrCalcColumnSizes(false, setAsMin); } | |
65e4e78e | 1493 | |
ca65c044 WS |
1494 | void AutoSizeRows( bool setAsMin = true ) |
1495 | { (void)SetOrCalcRowSizes(false, setAsMin); } | |
57c086ef VZ |
1496 | |
1497 | // auto size the grid, that is make the columns/rows of the "right" size | |
1498 | // and also set the grid size to just fit its contents | |
1499 | void AutoSize(); | |
1500 | ||
733f486a VZ |
1501 | // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize: |
1502 | // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column | |
1503 | // instead of data column. Note that this operation may be slow for large | |
1504 | // tables. | |
d43851f7 JS |
1505 | // autosize row height depending on label text |
1506 | void AutoSizeRowLabelSize( int row ); | |
1507 | ||
1508 | // autosize column width depending on label text | |
1509 | void AutoSizeColLabelSize( int col ); | |
1510 | ||
43947979 VZ |
1511 | // column won't be resized to be lesser width - this must be called during |
1512 | // the grid creation because it won't resize the column if it's already | |
1513 | // narrower than the minimal width | |
1514 | void SetColMinimalWidth( int col, int width ); | |
af547d51 | 1515 | void SetRowMinimalHeight( int row, int width ); |
43947979 | 1516 | |
b8d24d4e RG |
1517 | /* These members can be used to query and modify the minimal |
1518 | * acceptable size of grid rows and columns. Call this function in | |
1519 | * your code which creates the grid if you want to display cells | |
1520 | * with a size smaller than the default acceptable minimum size. | |
1521 | * Like the members SetColMinimalWidth and SetRowMinimalWidth, | |
1522 | * the existing rows or columns will not be checked/resized. | |
1523 | */ | |
1524 | void SetColMinimalAcceptableWidth( int width ); | |
1525 | void SetRowMinimalAcceptableHeight( int width ); | |
1526 | int GetColMinimalAcceptableWidth() const; | |
1527 | int GetRowMinimalAcceptableHeight() const; | |
1528 | ||
f85afd4e MB |
1529 | void SetDefaultCellBackgroundColour( const wxColour& ); |
1530 | void SetCellBackgroundColour( int row, int col, const wxColour& ); | |
1531 | void SetDefaultCellTextColour( const wxColour& ); | |
8fb66724 | 1532 | |
f85afd4e | 1533 | void SetCellTextColour( int row, int col, const wxColour& ); |
f85afd4e MB |
1534 | void SetDefaultCellFont( const wxFont& ); |
1535 | void SetCellFont( int row, int col, const wxFont& ); | |
1536 | void SetDefaultCellAlignment( int horiz, int vert ); | |
1537 | void SetCellAlignment( int row, int col, int horiz, int vert ); | |
27f35b66 SN |
1538 | void SetDefaultCellOverflow( bool allow ); |
1539 | void SetCellOverflow( int row, int col, bool allow ); | |
1540 | void SetCellSize( int row, int col, int num_rows, int num_cols ); | |
f85afd4e | 1541 | |
ab79958a | 1542 | // takes ownership of the pointer |
2796cce3 | 1543 | void SetDefaultRenderer(wxGridCellRenderer *renderer); |
ab79958a | 1544 | void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer); |
2796cce3 | 1545 | wxGridCellRenderer *GetDefaultRenderer() const; |
ef316e23 | 1546 | wxGridCellRenderer* GetCellRenderer(int row, int col) const; |
2796cce3 | 1547 | |
283b7808 | 1548 | // takes ownership of the pointer |
0ba143c9 | 1549 | void SetDefaultEditor(wxGridCellEditor *editor); |
9b4aede2 | 1550 | void SetCellEditor(int row, int col, wxGridCellEditor *editor); |
0ba143c9 | 1551 | wxGridCellEditor *GetDefaultEditor() const; |
ef316e23 | 1552 | wxGridCellEditor* GetCellEditor(int row, int col) const; |
9b4aede2 | 1553 | |
60a67569 | 1554 | |
f2d76237 | 1555 | |
f85afd4e MB |
1556 | // ------ cell value accessors |
1557 | // | |
ef316e23 | 1558 | wxString GetCellValue( int row, int col ) const |
f85afd4e MB |
1559 | { |
1560 | if ( m_table ) | |
1561 | { | |
1562 | return m_table->GetValue( row, col ); | |
1563 | } | |
1564 | else | |
1565 | { | |
1566 | return wxEmptyString; | |
1567 | } | |
1568 | } | |
1569 | ||
ef316e23 | 1570 | wxString GetCellValue( const wxGridCellCoords& coords ) const |
f85afd4e | 1571 | { return GetCellValue( coords.GetRow(), coords.GetCol() ); } |
60ff3b99 | 1572 | |
f85afd4e MB |
1573 | void SetCellValue( int row, int col, const wxString& s ); |
1574 | void SetCellValue( const wxGridCellCoords& coords, const wxString& s ) | |
1575 | { SetCellValue( coords.GetRow(), coords.GetCol(), s ); } | |
f85afd4e | 1576 | |
ca65c044 | 1577 | // returns true if the cell can't be edited |
283b7808 | 1578 | bool IsReadOnly(int row, int col) const; |
60ff3b99 | 1579 | |
283b7808 | 1580 | // make the cell editable/readonly |
ca65c044 | 1581 | void SetReadOnly(int row, int col, bool isReadOnly = true); |
f85afd4e | 1582 | |
aa5b8857 | 1583 | // ------ select blocks of cells |
f85afd4e | 1584 | // |
ca65c044 WS |
1585 | void SelectRow( int row, bool addToSelected = false ); |
1586 | void SelectCol( int col, bool addToSelected = false ); | |
60ff3b99 | 1587 | |
c9097836 | 1588 | void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol, |
ca65c044 | 1589 | bool addToSelected = false ); |
f85afd4e MB |
1590 | |
1591 | void SelectBlock( const wxGridCellCoords& topLeft, | |
c9097836 | 1592 | const wxGridCellCoords& bottomRight, |
ca65c044 | 1593 | bool addToSelected = false ) |
f85afd4e | 1594 | { SelectBlock( topLeft.GetRow(), topLeft.GetCol(), |
c9097836 MB |
1595 | bottomRight.GetRow(), bottomRight.GetCol(), |
1596 | addToSelected ); } | |
f85afd4e MB |
1597 | |
1598 | void SelectAll(); | |
60ff3b99 | 1599 | |
ef316e23 | 1600 | bool IsSelection() const; |
f85afd4e | 1601 | |
aa5b8857 | 1602 | // ------ deselect blocks or cells |
f7b4b343 VZ |
1603 | // |
1604 | void DeselectRow( int row ); | |
1605 | void DeselectCol( int col ); | |
1606 | void DeselectCell( int row, int col ); | |
1607 | ||
f85afd4e MB |
1608 | void ClearSelection(); |
1609 | ||
84035150 | 1610 | bool IsInSelection( int row, int col ) const; |
f85afd4e | 1611 | |
84035150 | 1612 | bool IsInSelection( const wxGridCellCoords& coords ) const |
f85afd4e MB |
1613 | { return IsInSelection( coords.GetRow(), coords.GetCol() ); } |
1614 | ||
aa5b8857 SN |
1615 | wxGridCellCoordsArray GetSelectedCells() const; |
1616 | wxGridCellCoordsArray GetSelectionBlockTopLeft() const; | |
1617 | wxGridCellCoordsArray GetSelectionBlockBottomRight() const; | |
1618 | wxArrayInt GetSelectedRows() const; | |
1619 | wxArrayInt GetSelectedCols() const; | |
c3baf426 SN |
1620 | |
1621 | // This function returns the rectangle that encloses the block of cells | |
1622 | // limited by TopLeft and BottomRight cell in device coords and clipped | |
1623 | // to the client size of the grid window. | |
1624 | // | |
58dd5b3b | 1625 | wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft, |
ef316e23 | 1626 | const wxGridCellCoords & bottomRight ) const; |
c3baf426 | 1627 | |
2796cce3 RD |
1628 | // Access or update the selection fore/back colours |
1629 | wxColour GetSelectionBackground() const | |
1630 | { return m_selectionBackground; } | |
1631 | wxColour GetSelectionForeground() const | |
1632 | { return m_selectionForeground; } | |
1633 | ||
1634 | void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; } | |
1635 | void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; } | |
1636 | ||
1637 | ||
f2d76237 RD |
1638 | // Methods for a registry for mapping data types to Renderers/Editors |
1639 | void RegisterDataType(const wxString& typeName, | |
1640 | wxGridCellRenderer* renderer, | |
1641 | wxGridCellEditor* editor); | |
73145b0e JS |
1642 | // DJC MAPTEK |
1643 | virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const; | |
99306db2 VZ |
1644 | wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const |
1645 | { return GetDefaultEditorForCell(c.GetRow(), c.GetCol()); } | |
73145b0e JS |
1646 | virtual wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const; |
1647 | virtual wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const; | |
1648 | virtual wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const; | |
f2d76237 | 1649 | |
266e8367 VZ |
1650 | // grid may occupy more space than needed for its rows/columns, this |
1651 | // function allows to set how big this extra space is | |
1652 | void SetMargins(int extraWidth, int extraHeight) | |
1653 | { | |
1654 | m_extraWidth = extraWidth; | |
1655 | m_extraHeight = extraHeight; | |
b8125adf VZ |
1656 | |
1657 | CalcDimensions(); | |
266e8367 | 1658 | } |
f85afd4e | 1659 | |
d2520c85 | 1660 | // Accessors for component windows |
ef316e23 VZ |
1661 | wxWindow* GetGridWindow() const { return (wxWindow*)m_gridWin; } |
1662 | wxWindow* GetGridRowLabelWindow() const { return (wxWindow*)m_rowLabelWin; } | |
1663 | wxWindow* GetGridColLabelWindow() const { return (wxWindow*)m_colLabelWin; } | |
1664 | wxWindow* GetGridCornerLabelWindow() const { return (wxWindow*)m_cornerLabelWin; } | |
d2520c85 | 1665 | |
608754c4 JS |
1666 | // Allow adjustment of scroll increment. The default is (15, 15). |
1667 | void SetScrollLineX(int x) { m_scrollLineX = x; } | |
1668 | void SetScrollLineY(int y) { m_scrollLineY = y; } | |
1669 | int GetScrollLineX() const { return m_scrollLineX; } | |
1670 | int GetScrollLineY() const { return m_scrollLineY; } | |
1671 | ||
1edce33f VZ |
1672 | // ------- drag and drop |
1673 | #if wxUSE_DRAG_AND_DROP | |
1674 | virtual void SetDropTarget(wxDropTarget *dropTarget); | |
1675 | #endif // wxUSE_DRAG_AND_DROP | |
bf646121 | 1676 | |
bf2c8b31 VZ |
1677 | |
1678 | #ifdef WXWIN_COMPATIBILITY_2_8 | |
f85afd4e MB |
1679 | // ------ For compatibility with previous wxGrid only... |
1680 | // | |
1681 | // ************************************************ | |
1682 | // ** Don't use these in new code because they ** | |
1683 | // ** are liable to disappear in a future ** | |
1684 | // ** revision ** | |
1685 | // ************************************************ | |
1686 | // | |
1687 | ||
1688 | wxGrid( wxWindow *parent, | |
422d0ff0 | 1689 | int x, int y, int w = wxDefaultCoord, int h = wxDefaultCoord, |
ebd773c6 | 1690 | long style = wxWANTS_CHARS, |
f85afd4e | 1691 | const wxString& name = wxPanelNameStr ) |
ca65c044 | 1692 | : wxScrolledWindow( parent, wxID_ANY, wxPoint(x,y), wxSize(w,h), |
ebd773c6 | 1693 | (style|wxWANTS_CHARS), name ) |
60ff3b99 | 1694 | { |
f9549841 | 1695 | InitVars(); |
f85afd4e | 1696 | Create(); |
60ff3b99 | 1697 | } |
f85afd4e MB |
1698 | |
1699 | void SetCellValue( const wxString& val, int row, int col ) | |
1700 | { SetCellValue( row, col, val ); } | |
60ff3b99 | 1701 | |
f85afd4e MB |
1702 | void UpdateDimensions() |
1703 | { CalcDimensions(); } | |
1704 | ||
ef316e23 VZ |
1705 | int GetRows() const { return GetNumberRows(); } |
1706 | int GetCols() const { return GetNumberCols(); } | |
1707 | int GetCursorRow() const { return GetGridCursorRow(); } | |
1708 | int GetCursorColumn() const { return GetGridCursorCol(); } | |
60ff3b99 | 1709 | |
ef316e23 VZ |
1710 | int GetScrollPosX() const { return 0; } |
1711 | int GetScrollPosY() const { return 0; } | |
60ff3b99 | 1712 | |
aa5e1f75 SN |
1713 | void SetScrollX( int WXUNUSED(x) ) { } |
1714 | void SetScrollY( int WXUNUSED(y) ) { } | |
f85afd4e MB |
1715 | |
1716 | void SetColumnWidth( int col, int width ) | |
1717 | { SetColSize( col, width ); } | |
60ff3b99 | 1718 | |
ef316e23 | 1719 | int GetColumnWidth( int col ) const |
f85afd4e | 1720 | { return GetColSize( col ); } |
60ff3b99 | 1721 | |
f85afd4e MB |
1722 | void SetRowHeight( int row, int height ) |
1723 | { SetRowSize( row, height ); } | |
60ff3b99 | 1724 | |
7c1cb261 | 1725 | // GetRowHeight() is below |
60ff3b99 | 1726 | |
ef316e23 | 1727 | int GetViewHeight() const // returned num whole rows visible |
2d66e025 | 1728 | { return 0; } |
60ff3b99 | 1729 | |
ef316e23 | 1730 | int GetViewWidth() const // returned num whole cols visible |
2d66e025 | 1731 | { return 0; } |
f85afd4e MB |
1732 | |
1733 | void SetLabelSize( int orientation, int sz ) | |
1734 | { | |
1735 | if ( orientation == wxHORIZONTAL ) | |
1736 | SetColLabelSize( sz ); | |
1737 | else | |
1738 | SetRowLabelSize( sz ); | |
1739 | } | |
1740 | ||
ef316e23 | 1741 | int GetLabelSize( int orientation ) const |
f85afd4e MB |
1742 | { |
1743 | if ( orientation == wxHORIZONTAL ) | |
1744 | return GetColLabelSize(); | |
1745 | else | |
1746 | return GetRowLabelSize(); | |
1747 | } | |
1748 | ||
1749 | void SetLabelAlignment( int orientation, int align ) | |
1750 | { | |
1751 | if ( orientation == wxHORIZONTAL ) | |
1752 | SetColLabelAlignment( align, -1 ); | |
1753 | else | |
1754 | SetRowLabelAlignment( align, -1 ); | |
1755 | } | |
1756 | ||
ef316e23 | 1757 | int GetLabelAlignment( int orientation, int WXUNUSED(align) ) const |
f85afd4e MB |
1758 | { |
1759 | int h, v; | |
1760 | if ( orientation == wxHORIZONTAL ) | |
1761 | { | |
1762 | GetColLabelAlignment( &h, &v ); | |
1763 | return h; | |
1764 | } | |
1765 | else | |
1766 | { | |
1767 | GetRowLabelAlignment( &h, &v ); | |
1768 | return h; | |
1769 | } | |
1770 | } | |
1771 | ||
1772 | void SetLabelValue( int orientation, const wxString& val, int pos ) | |
1773 | { | |
1774 | if ( orientation == wxHORIZONTAL ) | |
1775 | SetColLabelValue( pos, val ); | |
1776 | else | |
1777 | SetRowLabelValue( pos, val ); | |
1778 | } | |
60ff3b99 | 1779 | |
ef316e23 | 1780 | wxString GetLabelValue( int orientation, int pos) const |
f85afd4e MB |
1781 | { |
1782 | if ( orientation == wxHORIZONTAL ) | |
1783 | return GetColLabelValue( pos ); | |
1784 | else | |
1785 | return GetRowLabelValue( pos ); | |
1786 | } | |
1787 | ||
60ff3b99 | 1788 | wxFont GetCellTextFont() const |
2796cce3 | 1789 | { return m_defaultCellAttr->GetFont(); } |
60ff3b99 | 1790 | |
af111fc3 | 1791 | wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const |
2796cce3 | 1792 | { return m_defaultCellAttr->GetFont(); } |
60ff3b99 | 1793 | |
f85afd4e MB |
1794 | void SetCellTextFont(const wxFont& fnt) |
1795 | { SetDefaultCellFont( fnt ); } | |
60ff3b99 | 1796 | |
f85afd4e MB |
1797 | void SetCellTextFont(const wxFont& fnt, int row, int col) |
1798 | { SetCellFont( row, col, fnt ); } | |
60ff3b99 | 1799 | |
f85afd4e MB |
1800 | void SetCellTextColour(const wxColour& val, int row, int col) |
1801 | { SetCellTextColour( row, col, val ); } | |
60ff3b99 | 1802 | |
f85afd4e MB |
1803 | void SetCellTextColour(const wxColour& col) |
1804 | { SetDefaultCellTextColour( col ); } | |
60ff3b99 | 1805 | |
f85afd4e MB |
1806 | void SetCellBackgroundColour(const wxColour& col) |
1807 | { SetDefaultCellBackgroundColour( col ); } | |
60ff3b99 | 1808 | |
f85afd4e MB |
1809 | void SetCellBackgroundColour(const wxColour& colour, int row, int col) |
1810 | { SetCellBackgroundColour( row, col, colour ); } | |
60ff3b99 | 1811 | |
ef316e23 | 1812 | bool GetEditable() const { return IsEditable(); } |
ca65c044 | 1813 | void SetEditable( bool edit = true ) { EnableEditing( edit ); } |
ef316e23 | 1814 | bool GetEditInPlace() const { return IsCellEditControlEnabled(); } |
8fb66724 | 1815 | |
ca65c044 | 1816 | void SetEditInPlace(bool WXUNUSED(edit) = true) { } |
f85afd4e | 1817 | |
60a67569 | 1818 | void SetCellAlignment( int align, int row, int col) |
4c7277db | 1819 | { SetCellAlignment(row, col, align, wxALIGN_CENTER); } |
60a67569 JS |
1820 | void SetCellAlignment( int WXUNUSED(align) ) {} |
1821 | void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col)) | |
1822 | { } | |
1823 | void SetDividerPen(const wxPen& WXUNUSED(pen)) { } | |
6fc0f38f | 1824 | wxPen& GetDividerPen() const; |
60a67569 | 1825 | void OnActivate(bool WXUNUSED(active)) {} |
60ff3b99 | 1826 | |
f85afd4e MB |
1827 | // ******** End of compatibility functions ********** |
1828 | ||
2d66e025 MB |
1829 | |
1830 | ||
f85afd4e | 1831 | // ------ control IDs |
2d66e025 | 1832 | enum { wxGRID_CELLCTRL = 2000, |
f85afd4e MB |
1833 | wxGRID_TOPCTRL }; |
1834 | ||
1835 | // ------ control types | |
2d66e025 | 1836 | enum { wxGRID_TEXTCTRL = 2100, |
f85afd4e MB |
1837 | wxGRID_CHECKBOX, |
1838 | wxGRID_CHOICE, | |
1839 | wxGRID_COMBOBOX }; | |
bf2c8b31 VZ |
1840 | #endif // WXWIN_COMPATIBILITY_2_8 |
1841 | ||
f85afd4e | 1842 | |
bf2c8b31 VZ |
1843 | // override some base class functions |
1844 | virtual bool Enable(bool enable = true); | |
1845 | virtual wxWindow *GetMainWindowOfCompositeControl() | |
1846 | { return (wxWindow*)m_gridWin; } | |
266e8367 VZ |
1847 | virtual void Fit(); |
1848 | ||
86033c4b VZ |
1849 | // implementation only |
1850 | void CancelMouseCapture(); | |
1851 | ||
60ff3b99 | 1852 | protected: |
266e8367 VZ |
1853 | virtual wxSize DoGetBestSize() const; |
1854 | ||
60ff3b99 VZ |
1855 | bool m_created; |
1856 | ||
1857 | wxGridWindow *m_gridWin; | |
1858 | wxGridRowLabelWindow *m_rowLabelWin; | |
1859 | wxGridColLabelWindow *m_colLabelWin; | |
1860 | wxGridCornerLabelWindow *m_cornerLabelWin; | |
1861 | ||
60ff3b99 | 1862 | wxGridTableBase *m_table; |
2796cce3 | 1863 | bool m_ownTable; |
60ff3b99 | 1864 | |
60ff3b99 VZ |
1865 | int m_numRows; |
1866 | int m_numCols; | |
1867 | ||
1868 | wxGridCellCoords m_currentCellCoords; | |
1869 | ||
b5808881 SN |
1870 | wxGridCellCoords m_selectingTopLeft; |
1871 | wxGridCellCoords m_selectingBottomRight; | |
d95b0c2b | 1872 | wxGridCellCoords m_selectingKeyboard; |
b5808881 | 1873 | wxGridSelection *m_selection; |
2796cce3 RD |
1874 | wxColour m_selectionBackground; |
1875 | wxColour m_selectionForeground; | |
60ff3b99 | 1876 | |
7c1cb261 VZ |
1877 | // NB: *never* access m_row/col arrays directly because they are created |
1878 | // on demand, *always* use accessor functions instead! | |
1879 | ||
1880 | // init the m_rowHeights/Bottoms arrays with default values | |
1881 | void InitRowHeights(); | |
1882 | ||
60ff3b99 | 1883 | int m_defaultRowHeight; |
b8d24d4e | 1884 | int m_minAcceptableRowHeight; |
60ff3b99 VZ |
1885 | wxArrayInt m_rowHeights; |
1886 | wxArrayInt m_rowBottoms; | |
1887 | ||
7c1cb261 VZ |
1888 | // init the m_colWidths/Rights arrays |
1889 | void InitColWidths(); | |
1890 | ||
60ff3b99 | 1891 | int m_defaultColWidth; |
b8d24d4e | 1892 | int m_minAcceptableColWidth; |
60ff3b99 VZ |
1893 | wxArrayInt m_colWidths; |
1894 | wxArrayInt m_colRights; | |
bf2c8b31 | 1895 | |
71cf399f | 1896 | bool m_nativeColumnLabels; |
7c1cb261 VZ |
1897 | |
1898 | // get the col/row coords | |
1899 | int GetColWidth(int col) const; | |
1900 | int GetColLeft(int col) const; | |
1901 | int GetColRight(int col) const; | |
1902 | ||
1903 | // this function must be public for compatibility... | |
1904 | public: | |
1905 | int GetRowHeight(int row) const; | |
1906 | protected: | |
1907 | ||
1908 | int GetRowTop(int row) const; | |
1909 | int GetRowBottom(int row) const; | |
1910 | ||
60ff3b99 VZ |
1911 | int m_rowLabelWidth; |
1912 | int m_colLabelHeight; | |
1913 | ||
266e8367 VZ |
1914 | // the size of the margin left to the right and bottom of the cell area |
1915 | int m_extraWidth, | |
1916 | m_extraHeight; | |
1917 | ||
60ff3b99 VZ |
1918 | wxColour m_labelBackgroundColour; |
1919 | wxColour m_labelTextColour; | |
1920 | wxFont m_labelFont; | |
1921 | ||
1922 | int m_rowLabelHorizAlign; | |
1923 | int m_rowLabelVertAlign; | |
1924 | int m_colLabelHorizAlign; | |
1925 | int m_colLabelVertAlign; | |
d43851f7 | 1926 | int m_colLabelTextOrientation; |
60ff3b99 VZ |
1927 | |
1928 | bool m_defaultRowLabelValues; | |
1929 | bool m_defaultColLabelValues; | |
1930 | ||
1931 | wxColour m_gridLineColour; | |
1932 | bool m_gridLinesEnabled; | |
f6bcfd97 | 1933 | wxColour m_cellHighlightColour; |
d2520c85 RD |
1934 | int m_cellHighlightPenWidth; |
1935 | int m_cellHighlightROPenWidth; | |
1936 | ||
60ff3b99 | 1937 | |
266e8367 | 1938 | // common part of AutoSizeColumn/Row() and GetBestSize() |
ca65c044 WS |
1939 | int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = true); |
1940 | int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = true); | |
266e8367 | 1941 | |
af547d51 | 1942 | // common part of AutoSizeColumn/Row() |
733f486a VZ |
1943 | void AutoSizeColOrRow(int n, bool setAsMin, wxGridDirection direction); |
1944 | ||
1945 | // Calculate the minimum acceptable size for labels area | |
1946 | wxCoord CalcColOrRowLabelAreaMinSize(wxGridDirection direction); | |
af547d51 | 1947 | |
43947979 VZ |
1948 | // if a column has a minimal width, it will be the value for it in this |
1949 | // hash table | |
ba8c1601 MB |
1950 | wxLongToLongHashMap m_colMinWidths, |
1951 | m_rowMinHeights; | |
43947979 | 1952 | |
af547d51 VZ |
1953 | // get the minimal width of the given column/row |
1954 | int GetColMinimalWidth(int col) const; | |
1955 | int GetRowMinimalHeight(int col) const; | |
b99be8fb VZ |
1956 | |
1957 | // do we have some place to store attributes in? | |
ef316e23 | 1958 | bool CanHaveAttributes() const; |
60ff3b99 | 1959 | |
0a976765 VZ |
1960 | // cell attribute cache (currently we only cache 1, may be will do |
1961 | // more/better later) | |
1962 | struct CachedAttr | |
1963 | { | |
1964 | int row, col; | |
1965 | wxGridCellAttr *attr; | |
1966 | } m_attrCache; | |
1967 | ||
1968 | // invalidates the attribute cache | |
1969 | void ClearAttrCache(); | |
1970 | ||
1971 | // adds an attribute to cache | |
1972 | void CacheAttr(int row, int col, wxGridCellAttr *attr) const; | |
1973 | ||
ca65c044 | 1974 | // looks for an attr in cache, returns true if found |
0a976765 VZ |
1975 | bool LookupAttr(int row, int col, wxGridCellAttr **attr) const; |
1976 | ||
1977 | // looks for the attr in cache, if not found asks the table and caches the | |
1978 | // result | |
2e9a6788 | 1979 | wxGridCellAttr *GetCellAttr(int row, int col) const; |
ef316e23 | 1980 | wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords ) const |
2c9a89e0 | 1981 | { return GetCellAttr( coords.GetRow(), coords.GetCol() ); } |
2e9a6788 | 1982 | |
2796cce3 RD |
1983 | // the default cell attr object for cells that don't have their own |
1984 | wxGridCellAttr* m_defaultCellAttr; | |
1985 | ||
1986 | ||
60ff3b99 VZ |
1987 | bool m_inOnKeyDown; |
1988 | int m_batchCount; | |
1989 | ||
f2d76237 RD |
1990 | |
1991 | wxGridTypeRegistry* m_typeRegistry; | |
1992 | ||
e2b42eeb VZ |
1993 | enum CursorMode |
1994 | { | |
1995 | WXGRID_CURSOR_SELECT_CELL, | |
1996 | WXGRID_CURSOR_RESIZE_ROW, | |
1997 | WXGRID_CURSOR_RESIZE_COL, | |
1998 | WXGRID_CURSOR_SELECT_ROW, | |
d4175745 VZ |
1999 | WXGRID_CURSOR_SELECT_COL, |
2000 | WXGRID_CURSOR_MOVE_COL | |
60ff3b99 VZ |
2001 | }; |
2002 | ||
e2b42eeb | 2003 | // this method not only sets m_cursorMode but also sets the correct cursor |
ca65c044 | 2004 | // for the given mode and, if captureMouse is not false releases the mouse |
e2b42eeb VZ |
2005 | // if it was captured and captures it if it must be captured |
2006 | // | |
2007 | // for this to work, you should always use it and not set m_cursorMode | |
2008 | // directly! | |
2009 | void ChangeCursorMode(CursorMode mode, | |
2010 | wxWindow *win = (wxWindow *)NULL, | |
ca65c044 | 2011 | bool captureMouse = true); |
e2b42eeb VZ |
2012 | |
2013 | wxWindow *m_winCapture; // the window which captured the mouse | |
2014 | CursorMode m_cursorMode; | |
2015 | ||
d4175745 VZ |
2016 | //Column positions |
2017 | wxArrayInt m_colAt; | |
2018 | int m_moveToCol; | |
2019 | ||
6e8524b1 MB |
2020 | bool m_canDragRowSize; |
2021 | bool m_canDragColSize; | |
d4175745 | 2022 | bool m_canDragColMove; |
4cfa5de6 | 2023 | bool m_canDragGridSize; |
79dbea21 | 2024 | bool m_canDragCell; |
bec70262 VZ |
2025 | |
2026 | // the last position (horizontal or vertical depending on whether the user | |
2027 | // is resizing a column or a row) where a row or column separator line was | |
2028 | // dragged by the user or -1 of there is no drag operation in progress | |
07296f0b RD |
2029 | int m_dragLastPos; |
2030 | int m_dragRowOrCol; | |
bec70262 | 2031 | |
07296f0b RD |
2032 | bool m_isDragging; |
2033 | wxPoint m_startDragPos; | |
60ff3b99 | 2034 | |
75ecbe45 | 2035 | bool m_waitForSlowClick; |
025562fe | 2036 | |
60ff3b99 VZ |
2037 | wxGridCellCoords m_selectionStart; |
2038 | ||
2039 | wxCursor m_rowResizeCursor; | |
2040 | wxCursor m_colResizeCursor; | |
2041 | ||
b54ba671 VZ |
2042 | bool m_editable; // applies to whole grid |
2043 | bool m_cellEditCtrlEnabled; // is in-place edit currently shown? | |
60ff3b99 | 2044 | |
608754c4 JS |
2045 | int m_scrollLineX; // X scroll increment |
2046 | int m_scrollLineY; // Y scroll increment | |
60ff3b99 VZ |
2047 | |
2048 | void Create(); | |
2049 | void Init(); | |
f9549841 | 2050 | void InitVars(); |
60ff3b99 | 2051 | void CalcDimensions(); |
7807d81c | 2052 | void CalcWindowSizes(); |
60ff3b99 VZ |
2053 | bool Redimension( wxGridTableMessage& ); |
2054 | ||
2055 | ||
fe7b9ed6 VZ |
2056 | int SendEvent( const wxEventType, int row, int col, wxMouseEvent& ); |
2057 | int SendEvent( const wxEventType, int row, int col ); | |
2058 | int SendEvent( const wxEventType type) | |
b54ba671 VZ |
2059 | { |
2060 | return SendEvent(type, | |
2061 | m_currentCellCoords.GetRow(), | |
2062 | m_currentCellCoords.GetCol()); | |
2063 | } | |
60ff3b99 VZ |
2064 | |
2065 | void OnPaint( wxPaintEvent& ); | |
2066 | void OnSize( wxSizeEvent& ); | |
2067 | void OnKeyDown( wxKeyEvent& ); | |
f6bcfd97 | 2068 | void OnKeyUp( wxKeyEvent& ); |
63e2147c | 2069 | void OnChar( wxKeyEvent& ); |
2796cce3 | 2070 | void OnEraseBackground( wxEraseEvent& ); |
60ff3b99 VZ |
2071 | |
2072 | ||
2073 | void SetCurrentCell( const wxGridCellCoords& coords ); | |
2074 | void SetCurrentCell( int row, int col ) | |
2075 | { SetCurrentCell( wxGridCellCoords(row, col) ); } | |
2076 | ||
c9097836 MB |
2077 | void HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCol ); |
2078 | ||
2079 | void HighlightBlock( const wxGridCellCoords& topLeft, | |
d2520c85 | 2080 | const wxGridCellCoords& bottomRight ) |
c9097836 MB |
2081 | { HighlightBlock( topLeft.GetRow(), topLeft.GetCol(), |
2082 | bottomRight.GetRow(), bottomRight.GetCol() ); } | |
60ff3b99 VZ |
2083 | |
2084 | // ------ functions to get/send data (see also public functions) | |
2085 | // | |
2086 | bool GetModelValues(); | |
2087 | bool SetModelValues(); | |
2088 | ||
b5dbe15d | 2089 | friend class WXDLLIMPEXP_FWD_ADV wxGridSelection; |
bec70262 VZ |
2090 | friend class wxGridRowOperations; |
2091 | friend class wxGridColumnOperations; | |
60ff3b99 | 2092 | |
69367c56 VZ |
2093 | private: |
2094 | // implement wxScrolledWindow method to return m_gridWin size | |
2095 | virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size); | |
2096 | ||
bec70262 VZ |
2097 | |
2098 | // common implementations of methods defined for both rows and columns | |
2099 | void DeselectLine(int line, const wxGridOperations& oper); | |
2100 | void DoEndDragResizeLine(const wxGridOperations& oper); | |
2101 | int PosToLine(int pos, bool clipToMinMax, | |
2102 | const wxGridOperations& oper) const; | |
10a4531d VZ |
2103 | int PosToEdgeOfLine(int pos, const wxGridOperations& oper) const; |
2104 | ||
2105 | bool DoMoveCursor(bool expandSelection, | |
2106 | const wxGridDirectionOperations& diroper); | |
2107 | bool DoMoveCursorByPage(const wxGridDirectionOperations& diroper); | |
2108 | bool DoMoveCursorByBlock(bool expandSelection, | |
2109 | const wxGridDirectionOperations& diroper); | |
2110 | void AdvanceToNextNonEmpty(wxGridCellCoords& coords, | |
2111 | const wxGridDirectionOperations& diroper); | |
2112 | ||
2113 | // common part of {Insert,Delete}{Rows,Cols} | |
2114 | bool DoModifyLines(bool (wxGridTableBase::*funcModify)(size_t, size_t), | |
2115 | int pos, int num, bool updateLabels); | |
2116 | // Append{Rows,Cols} is a bit different because of one less parameter | |
2117 | bool DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t), | |
2118 | int num, bool updateLabels); | |
bec70262 | 2119 | |
2d66e025 | 2120 | DECLARE_DYNAMIC_CLASS( wxGrid ) |
f85afd4e | 2121 | DECLARE_EVENT_TABLE() |
22f3361e | 2122 | DECLARE_NO_COPY_CLASS(wxGrid) |
f85afd4e MB |
2123 | }; |
2124 | ||
b62f94ff VZ |
2125 | // ---------------------------------------------------------------------------- |
2126 | // wxGridUpdateLocker prevents updates to a grid during its lifetime | |
2127 | // ---------------------------------------------------------------------------- | |
2128 | ||
2129 | class WXDLLIMPEXP_ADV wxGridUpdateLocker | |
2130 | { | |
2131 | public: | |
2132 | // if the pointer is NULL, Create() can be called later | |
2133 | wxGridUpdateLocker(wxGrid *grid = NULL) | |
2134 | { | |
2135 | Init(grid); | |
2136 | } | |
2137 | ||
2138 | // can be called if ctor was used with a NULL pointer, must not be called | |
2139 | // more than once | |
2140 | void Create(wxGrid *grid) | |
2141 | { | |
2142 | wxASSERT_MSG( !m_grid, _T("shouldn't be called more than once") ); | |
2143 | ||
2144 | Init(grid); | |
2145 | } | |
2146 | ||
2147 | ~wxGridUpdateLocker() | |
2148 | { | |
2149 | if ( m_grid ) | |
2150 | m_grid->EndBatch(); | |
2151 | } | |
2152 | ||
2153 | private: | |
2154 | void Init(wxGrid *grid) | |
2155 | { | |
2156 | m_grid = grid; | |
2157 | if ( m_grid ) | |
2158 | m_grid->BeginBatch(); | |
2159 | } | |
2160 | ||
2161 | wxGrid *m_grid; | |
2162 | ||
2163 | DECLARE_NO_COPY_CLASS(wxGridUpdateLocker) | |
2164 | }; | |
2165 | ||
43947979 VZ |
2166 | // ---------------------------------------------------------------------------- |
2167 | // Grid event class and event types | |
2168 | // ---------------------------------------------------------------------------- | |
f85afd4e | 2169 | |
12f190b0 | 2170 | class WXDLLIMPEXP_ADV wxGridEvent : public wxNotifyEvent |
f85afd4e | 2171 | { |
60ff3b99 | 2172 | public: |
f85afd4e MB |
2173 | wxGridEvent() |
2174 | : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1), | |
5c8fc7c1 | 2175 | m_selecting(0), m_control(0), m_meta(0), m_shift(0), m_alt(0) |
f85afd4e MB |
2176 | { |
2177 | } | |
2178 | ||
2179 | wxGridEvent(int id, wxEventType type, wxObject* obj, | |
ca65c044 WS |
2180 | int row=-1, int col=-1, int x=-1, int y=-1, bool sel = true, |
2181 | bool control = false, bool shift = false, bool alt = false, bool meta = false); | |
f85afd4e MB |
2182 | |
2183 | virtual int GetRow() { return m_row; } | |
2184 | virtual int GetCol() { return m_col; } | |
2185 | wxPoint GetPosition() { return wxPoint( m_x, m_y ); } | |
5c8fc7c1 | 2186 | bool Selecting() { return m_selecting; } |
f85afd4e MB |
2187 | bool ControlDown() { return m_control; } |
2188 | bool MetaDown() { return m_meta; } | |
2189 | bool ShiftDown() { return m_shift; } | |
2190 | bool AltDown() { return m_alt; } | |
d4175745 | 2191 | bool CmdDown() |
2b01fd49 RD |
2192 | { |
2193 | #if defined(__WXMAC__) || defined(__WXCOCOA__) | |
2194 | return MetaDown(); | |
2195 | #else | |
2196 | return ControlDown(); | |
2197 | #endif | |
2198 | } | |
2d66e025 | 2199 | |
e1f8ec29 RD |
2200 | virtual wxEvent *Clone() const { return new wxGridEvent(*this); } |
2201 | ||
60ff3b99 VZ |
2202 | protected: |
2203 | int m_row; | |
2204 | int m_col; | |
f85afd4e MB |
2205 | int m_x; |
2206 | int m_y; | |
5c8fc7c1 | 2207 | bool m_selecting; |
f85afd4e MB |
2208 | bool m_control; |
2209 | bool m_meta; | |
2210 | bool m_shift; | |
2211 | bool m_alt; | |
60ff3b99 | 2212 | |
e1f8ec29 | 2213 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent) |
60ff3b99 VZ |
2214 | }; |
2215 | ||
12f190b0 | 2216 | class WXDLLIMPEXP_ADV wxGridSizeEvent : public wxNotifyEvent |
60ff3b99 VZ |
2217 | { |
2218 | public: | |
f85afd4e MB |
2219 | wxGridSizeEvent() |
2220 | : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1), | |
2221 | m_control(0), m_meta(0), m_shift(0), m_alt(0) | |
2222 | { | |
2223 | } | |
2224 | ||
2225 | wxGridSizeEvent(int id, wxEventType type, wxObject* obj, | |
2226 | int rowOrCol=-1, int x=-1, int y=-1, | |
ca65c044 | 2227 | bool control = false, bool shift = false, bool alt = false, bool meta = false); |
f85afd4e MB |
2228 | |
2229 | int GetRowOrCol() { return m_rowOrCol; } | |
2230 | wxPoint GetPosition() { return wxPoint( m_x, m_y ); } | |
2231 | bool ControlDown() { return m_control; } | |
2232 | bool MetaDown() { return m_meta; } | |
2233 | bool ShiftDown() { return m_shift; } | |
2234 | bool AltDown() { return m_alt; } | |
d4175745 | 2235 | bool CmdDown() |
2b01fd49 RD |
2236 | { |
2237 | #if defined(__WXMAC__) || defined(__WXCOCOA__) | |
2238 | return MetaDown(); | |
2239 | #else | |
2240 | return ControlDown(); | |
2241 | #endif | |
2242 | } | |
733f486a | 2243 | |
e1f8ec29 | 2244 | virtual wxEvent *Clone() const { return new wxGridSizeEvent(*this); } |
2d66e025 | 2245 | |
60ff3b99 VZ |
2246 | protected: |
2247 | int m_rowOrCol; | |
2248 | int m_x; | |
2249 | int m_y; | |
2250 | bool m_control; | |
2251 | bool m_meta; | |
2252 | bool m_shift; | |
2253 | bool m_alt; | |
2254 | ||
e1f8ec29 | 2255 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent) |
f85afd4e MB |
2256 | }; |
2257 | ||
2258 | ||
12f190b0 | 2259 | class WXDLLIMPEXP_ADV wxGridRangeSelectEvent : public wxNotifyEvent |
f85afd4e | 2260 | { |
60ff3b99 | 2261 | public: |
f85afd4e | 2262 | wxGridRangeSelectEvent() |
60ff3b99 VZ |
2263 | : wxNotifyEvent() |
2264 | { | |
2265 | m_topLeft = wxGridNoCellCoords; | |
2266 | m_bottomRight = wxGridNoCellCoords; | |
ca65c044 WS |
2267 | m_selecting = false; |
2268 | m_control = false; | |
2269 | m_meta = false; | |
2270 | m_shift = false; | |
2271 | m_alt = false; | |
60ff3b99 | 2272 | } |
f85afd4e MB |
2273 | |
2274 | wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj, | |
60ff3b99 VZ |
2275 | const wxGridCellCoords& topLeft, |
2276 | const wxGridCellCoords& bottomRight, | |
ca65c044 WS |
2277 | bool sel = true, |
2278 | bool control = false, bool shift = false, | |
2279 | bool alt = false, bool meta = false); | |
f85afd4e MB |
2280 | |
2281 | wxGridCellCoords GetTopLeftCoords() { return m_topLeft; } | |
2282 | wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; } | |
2283 | int GetTopRow() { return m_topLeft.GetRow(); } | |
2284 | int GetBottomRow() { return m_bottomRight.GetRow(); } | |
2285 | int GetLeftCol() { return m_topLeft.GetCol(); } | |
2286 | int GetRightCol() { return m_bottomRight.GetCol(); } | |
5c8fc7c1 | 2287 | bool Selecting() { return m_selecting; } |
f85afd4e MB |
2288 | bool ControlDown() { return m_control; } |
2289 | bool MetaDown() { return m_meta; } | |
2290 | bool ShiftDown() { return m_shift; } | |
2291 | bool AltDown() { return m_alt; } | |
d4175745 | 2292 | bool CmdDown() |
2b01fd49 RD |
2293 | { |
2294 | #if defined(__WXMAC__) || defined(__WXCOCOA__) | |
2295 | return MetaDown(); | |
2296 | #else | |
2297 | return ControlDown(); | |
2298 | #endif | |
2299 | } | |
733f486a | 2300 | |
e1f8ec29 | 2301 | virtual wxEvent *Clone() const { return new wxGridRangeSelectEvent(*this); } |
2d66e025 | 2302 | |
60ff3b99 VZ |
2303 | protected: |
2304 | wxGridCellCoords m_topLeft; | |
2305 | wxGridCellCoords m_bottomRight; | |
5c8fc7c1 | 2306 | bool m_selecting; |
60ff3b99 VZ |
2307 | bool m_control; |
2308 | bool m_meta; | |
2309 | bool m_shift; | |
2310 | bool m_alt; | |
2311 | ||
e1f8ec29 | 2312 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent) |
f85afd4e MB |
2313 | }; |
2314 | ||
bf7945ce | 2315 | |
12f190b0 | 2316 | class WXDLLIMPEXP_ADV wxGridEditorCreatedEvent : public wxCommandEvent { |
bf7945ce RD |
2317 | public: |
2318 | wxGridEditorCreatedEvent() | |
2319 | : wxCommandEvent() | |
2320 | { | |
2321 | m_row = 0; | |
2322 | m_col = 0; | |
2323 | m_ctrl = NULL; | |
2324 | } | |
2325 | ||
2326 | wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj, | |
2327 | int row, int col, wxControl* ctrl); | |
2328 | ||
2329 | int GetRow() { return m_row; } | |
2330 | int GetCol() { return m_col; } | |
2331 | wxControl* GetControl() { return m_ctrl; } | |
2332 | void SetRow(int row) { m_row = row; } | |
2333 | void SetCol(int col) { m_col = col; } | |
2334 | void SetControl(wxControl* ctrl) { m_ctrl = ctrl; } | |
733f486a | 2335 | |
e1f8ec29 | 2336 | virtual wxEvent *Clone() const { return new wxGridEditorCreatedEvent(*this); } |
bf7945ce RD |
2337 | |
2338 | private: | |
2339 | int m_row; | |
2340 | int m_col; | |
2341 | wxControl* m_ctrl; | |
2342 | ||
e1f8ec29 | 2343 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent) |
bf7945ce RD |
2344 | }; |
2345 | ||
2346 | ||
c058cafa VZ |
2347 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_LEFT_CLICK; |
2348 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK; | |
2349 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK; | |
2350 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK; | |
2351 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK; | |
2352 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK; | |
2353 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK; | |
2354 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK; | |
2355 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_ROW_SIZE; | |
2356 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_SIZE; | |
2357 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_RANGE_SELECT; | |
2358 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_CHANGE; | |
2359 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_SELECT_CELL; | |
2360 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_EDITOR_SHOWN; | |
2361 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_EDITOR_HIDDEN; | |
2362 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_EDITOR_CREATED; | |
2363 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_BEGIN_DRAG; | |
2364 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_MOVE; | |
749692cc | 2365 | |
f85afd4e MB |
2366 | |
2367 | typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&); | |
2368 | typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&); | |
2369 | typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&); | |
bf7945ce | 2370 | typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreatedEvent&); |
f85afd4e | 2371 | |
7fa03f04 | 2372 | #define wxGridEventHandler(func) \ |
d94c09cd | 2373 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridEventFunction, &func) |
7fa03f04 VZ |
2374 | |
2375 | #define wxGridSizeEventHandler(func) \ | |
d94c09cd | 2376 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridSizeEventFunction, &func) |
7fa03f04 VZ |
2377 | |
2378 | #define wxGridRangeSelectEventHandler(func) \ | |
d94c09cd | 2379 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridRangeSelectEventFunction, &func) |
7fa03f04 VZ |
2380 | |
2381 | #define wxGridEditorCreatedEventHandler(func) \ | |
d94c09cd | 2382 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridEditorCreatedEventFunction, &func) |
7fa03f04 VZ |
2383 | |
2384 | #define wx__DECLARE_GRIDEVT(evt, id, fn) \ | |
2385 | wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn)) | |
2386 | ||
2387 | #define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \ | |
2388 | wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn)) | |
2389 | ||
2390 | #define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \ | |
2391 | wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn)) | |
2392 | ||
2393 | #define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \ | |
2394 | wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn)) | |
2395 | ||
2396 | #define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn) | |
2397 | #define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn) | |
2398 | #define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn) | |
2399 | #define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn) | |
2400 | #define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn) | |
2401 | #define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn) | |
2402 | #define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn) | |
2403 | #define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn) | |
2404 | #define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn) | |
2405 | #define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn) | |
5d984f5d | 2406 | #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn) |
7fa03f04 VZ |
2407 | #define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn) |
2408 | #define EVT_GRID_CMD_CELL_CHANGE(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGE, id, fn) | |
2409 | #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn) | |
2410 | #define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn) | |
2411 | #define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn) | |
2412 | #define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn) | |
2413 | #define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn) | |
2414 | ||
2415 | // same as above but for any id (exists mainly for backwards compatibility but | |
2416 | // then it's also true that you rarely have multiple grid in the same window) | |
2417 | #define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn) | |
2418 | #define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn) | |
2419 | #define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn) | |
2420 | #define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn) | |
2421 | #define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn) | |
2422 | #define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn) | |
2423 | #define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn) | |
2424 | #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn) | |
2425 | #define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn) | |
2426 | #define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn) | |
4d5a1b0a | 2427 | #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn) |
7fa03f04 VZ |
2428 | #define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn) |
2429 | #define EVT_GRID_CELL_CHANGE(fn) EVT_GRID_CMD_CELL_CHANGE(wxID_ANY, fn) | |
2430 | #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn) | |
2431 | #define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn) | |
2432 | #define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn) | |
2433 | #define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn) | |
2434 | #define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn) | |
f85afd4e MB |
2435 | |
2436 | #if 0 // TODO: implement these ? others ? | |
2437 | ||
77d4384e RR |
2438 | extern const int wxEVT_GRID_CREATE_CELL; |
2439 | extern const int wxEVT_GRID_CHANGE_LABELS; | |
2440 | extern const int wxEVT_GRID_CHANGE_SEL_LABEL; | |
f85afd4e | 2441 | |
ca65c044 WS |
2442 | #define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ), |
2443 | #define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ), | |
2444 | #define EVT_GRID_CHANGE_SEL_LABEL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ), | |
f85afd4e MB |
2445 | |
2446 | #endif | |
2447 | ||
df9fac6d PC |
2448 | #endif // wxUSE_GRID |
2449 | #endif // _WX_GENERIC_GRID_H_ |