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