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