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