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