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