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