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