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