1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/grid.h
3 // Purpose: wxGrid and related classes
4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
5 // Modified by: Santiago Palacios
8 // Copyright: (c) Michael Bedward
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_GRID_H_
13 #define _WX_GENERIC_GRID_H_
19 #include "wx/hashmap.h"
21 #include "wx/scrolwin.h"
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 extern WXDLLIMPEXP_DATA_ADV(const char) wxGridNameStr
[];
29 // Default parameters for wxGrid
31 #define WXGRID_DEFAULT_NUMBER_ROWS 10
32 #define WXGRID_DEFAULT_NUMBER_COLS 10
33 #if defined(__WXMSW__) || defined(__WXGTK20__)
34 #define WXGRID_DEFAULT_ROW_HEIGHT 25
36 #define WXGRID_DEFAULT_ROW_HEIGHT 30
38 #define WXGRID_DEFAULT_COL_WIDTH 80
39 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
40 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
41 #define WXGRID_LABEL_EDGE_ZONE 2
42 #define WXGRID_MIN_ROW_HEIGHT 15
43 #define WXGRID_MIN_COL_WIDTH 15
44 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
46 // type names for grid table values
47 #define wxGRID_VALUE_STRING wxT("string")
48 #define wxGRID_VALUE_BOOL wxT("bool")
49 #define wxGRID_VALUE_NUMBER wxT("long")
50 #define wxGRID_VALUE_FLOAT wxT("double")
51 #define wxGRID_VALUE_CHOICE wxT("choice")
53 #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
54 #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
56 // magic constant which tells (to some functions) to automatically calculate
57 // the appropriate size
58 #define wxGRID_AUTOSIZE (-1)
60 // many wxGrid methods work either with columns or rows, this enum is used for
61 // the parameter indicating which one should it be
68 // Flags used with wxGrid::Render() to select parts of the grid to draw.
69 enum wxGridRenderStyle
71 wxGRID_DRAW_ROWS_HEADER
= 0x001,
72 wxGRID_DRAW_COLS_HEADER
= 0x002,
73 wxGRID_DRAW_CELL_LINES
= 0x004,
74 wxGRID_DRAW_BOX_RECT
= 0x008,
75 wxGRID_DRAW_SELECTION
= 0x010,
76 wxGRID_DRAW_DEFAULT
= wxGRID_DRAW_ROWS_HEADER
|
77 wxGRID_DRAW_COLS_HEADER
|
78 wxGRID_DRAW_CELL_LINES
|
82 // ----------------------------------------------------------------------------
83 // forward declarations
84 // ----------------------------------------------------------------------------
86 class WXDLLIMPEXP_FWD_ADV wxGrid
;
87 class WXDLLIMPEXP_FWD_ADV wxGridCellAttr
;
88 class WXDLLIMPEXP_FWD_ADV wxGridCellAttrProviderData
;
89 class WXDLLIMPEXP_FWD_ADV wxGridColLabelWindow
;
90 class WXDLLIMPEXP_FWD_ADV wxGridCornerLabelWindow
;
91 class WXDLLIMPEXP_FWD_ADV wxGridRowLabelWindow
;
92 class WXDLLIMPEXP_FWD_ADV wxGridWindow
;
93 class WXDLLIMPEXP_FWD_ADV wxGridTypeRegistry
;
94 class WXDLLIMPEXP_FWD_ADV wxGridSelection
;
96 class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl
;
97 class WXDLLIMPEXP_FWD_CORE wxCheckBox
;
98 class WXDLLIMPEXP_FWD_CORE wxComboBox
;
99 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
101 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl
;
104 class wxGridFixedIndicesSet
;
106 class wxGridOperations
;
107 class wxGridRowOperations
;
108 class wxGridColumnOperations
;
109 class wxGridDirectionOperations
;
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
116 #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
117 #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
119 // ----------------------------------------------------------------------------
120 // wxGridCellWorker: common base class for wxGridCellRenderer and
123 // NB: this is more an implementation convenience than a design issue, so this
124 // class is not documented and is not public at all
125 // ----------------------------------------------------------------------------
127 class WXDLLIMPEXP_ADV wxGridCellWorker
: public wxClientDataContainer
, public wxRefCounter
130 wxGridCellWorker() { }
132 // interpret renderer parameters: arbitrary string whose interpretatin is
133 // left to the derived classes
134 virtual void SetParameters(const wxString
& params
);
137 // virtual dtor for any base class - private because only DecRef() can
139 virtual ~wxGridCellWorker();
142 // suppress the stupid gcc warning about the class having private dtor and
144 friend class wxGridCellWorkerDummyFriend
;
147 // ----------------------------------------------------------------------------
148 // wxGridCellRenderer: this class is responsible for actually drawing the cell
149 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
150 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
151 // view of all cells. This is an ABC, you will normally use one of the
152 // predefined derived classes or derive your own class from it.
153 // ----------------------------------------------------------------------------
155 class WXDLLIMPEXP_ADV wxGridCellRenderer
: public wxGridCellWorker
158 // draw the given cell on the provided DC inside the given rectangle
159 // using the style specified by the attribute and the default or selected
160 // state corresponding to the isSelected value.
162 // this pure virtual function has a default implementation which will
163 // prepare the DC using the given attribute: it will draw the rectangle
164 // with the bg colour from attr and set the text colour and font
165 virtual void Draw(wxGrid
& grid
,
166 wxGridCellAttr
& attr
,
170 bool isSelected
) = 0;
172 // get the preferred size of the cell for its contents
173 virtual wxSize
GetBestSize(wxGrid
& grid
,
174 wxGridCellAttr
& attr
,
176 int row
, int col
) = 0;
178 // create a new object which is the copy of this one
179 virtual wxGridCellRenderer
*Clone() const = 0;
182 // ----------------------------------------------------------------------------
183 // wxGridCellEditor: This class is responsible for providing and manipulating
184 // the in-place edit controls for the grid. Instances of wxGridCellEditor
185 // (actually, instances of derived classes since it is an ABC) can be
186 // associated with the cell attributes for individual cells, rows, columns, or
187 // even for the entire grid.
188 // ----------------------------------------------------------------------------
190 class WXDLLIMPEXP_ADV wxGridCellEditor
: public wxGridCellWorker
195 bool IsCreated() { return m_control
!= NULL
; }
196 wxControl
* GetControl() { return m_control
; }
197 void SetControl(wxControl
* control
) { m_control
= control
; }
199 wxGridCellAttr
* GetCellAttr() { return m_attr
; }
200 void SetCellAttr(wxGridCellAttr
* attr
) { m_attr
= attr
; }
202 // Creates the actual edit control
203 virtual void Create(wxWindow
* parent
,
205 wxEvtHandler
* evtHandler
) = 0;
207 // Size and position the edit control
208 virtual void SetSize(const wxRect
& rect
);
210 // Show or hide the edit control, use the specified attributes to set
211 // colours/fonts for it
212 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
214 // Draws the part of the cell not occupied by the control: the base class
215 // version just fills it with background colour from the attribute
216 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
219 // The methods called by wxGrid when a cell is edited: first BeginEdit() is
220 // called, then EndEdit() is and if it returns true and if the change is
221 // not vetoed by a user-defined event handler, finally ApplyEdit() is called
223 // Fetch the value from the table and prepare the edit control
224 // to begin editing. Set the focus to the edit control.
225 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
227 // Returns false if nothing changed, otherwise returns true and return the
228 // new value in its string form in the newval output parameter.
230 // This should also store the new value in its real type internally so that
231 // it could be used by ApplyEdit() but it must not modify the grid as the
232 // change could still be vetoed.
233 virtual bool EndEdit(int row
, int col
, const wxGrid
*grid
,
234 const wxString
& oldval
, wxString
*newval
) = 0;
236 // Complete the editing of the current cell by storing the value saved by
237 // the previous call to EndEdit() in the grid
238 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
) = 0;
241 // Reset the value in the control back to its starting value
242 virtual void Reset() = 0;
244 // return true to allow the given key to start editing: the base class
245 // version only checks that the event has no modifiers. The derived
246 // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
247 // their IsAcceptedKey() implementation, although, of course, it is not a
248 // mandatory requirment.
250 // NB: if the key is F2 (special), editing will always start and this
251 // method will not be called at all (but StartingKey() will)
252 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
254 // If the editor is enabled by pressing keys on the grid, this will be
255 // called to let the editor do something about that first key if desired
256 virtual void StartingKey(wxKeyEvent
& event
);
258 // if the editor is enabled by clicking on the cell, this method will be
260 virtual void StartingClick();
262 // Some types of controls on some platforms may need some help
263 // with the Return key.
264 virtual void HandleReturn(wxKeyEvent
& event
);
267 virtual void Destroy();
269 // create a new object which is the copy of this one
270 virtual wxGridCellEditor
*Clone() const = 0;
272 // added GetValue so we can get the value which is in the control
273 virtual wxString
GetValue() const = 0;
276 // the dtor is private because only DecRef() can delete us
277 virtual ~wxGridCellEditor();
279 // the control we show on screen
280 wxControl
* m_control
;
282 // a temporary pointer to the attribute being edited
283 wxGridCellAttr
* m_attr
;
285 // if we change the colours/font of the control from the default ones, we
286 // must restore the default later and we save them here between calls to
287 // Show(true) and Show(false)
292 // suppress the stupid gcc warning about the class having private dtor and
294 friend class wxGridCellEditorDummyFriend
;
296 wxDECLARE_NO_COPY_CLASS(wxGridCellEditor
);
299 // ----------------------------------------------------------------------------
300 // wxGridHeaderRenderer and company: like wxGridCellRenderer but for headers
301 // ----------------------------------------------------------------------------
303 // Base class for corner window renderer: it is the simplest of all renderers
304 // and only has a single function
305 class WXDLLIMPEXP_ADV wxGridCornerHeaderRenderer
308 // Draw the border around the corner window.
309 virtual void DrawBorder(const wxGrid
& grid
,
311 wxRect
& rect
) const = 0;
313 // make the dtor of a class with virtual functions virtual to avoid g++
314 // warnings, even though this class is not supposed to be used
316 virtual ~wxGridCornerHeaderRenderer() { }
320 // Base class for the row/column header cells renderers
321 class WXDLLIMPEXP_ADV wxGridHeaderLabelsRenderer
322 : public wxGridCornerHeaderRenderer
325 // Draw header cell label
326 virtual void DrawLabel(const wxGrid
& grid
,
328 const wxString
& value
,
332 int textOrientation
) const;
335 // Currently the row/column/corner renders don't need any methods other than
336 // those already in wxGridHeaderLabelsRenderer but still define separate classes
337 // for them for future extensions and also for better type safety (i.e. to
338 // avoid inadvertently using a column header renderer for the row headers)
339 class WXDLLIMPEXP_ADV wxGridRowHeaderRenderer
340 : public wxGridHeaderLabelsRenderer
344 class WXDLLIMPEXP_ADV wxGridColumnHeaderRenderer
345 : public wxGridHeaderLabelsRenderer
349 // Also define the default renderers which are used by wxGridCellAttrProvider
351 class WXDLLIMPEXP_ADV wxGridRowHeaderRendererDefault
352 : public wxGridRowHeaderRenderer
355 virtual void DrawBorder(const wxGrid
& grid
,
360 // Column header cells renderers
361 class WXDLLIMPEXP_ADV wxGridColumnHeaderRendererDefault
362 : public wxGridColumnHeaderRenderer
365 virtual void DrawBorder(const wxGrid
& grid
,
370 // Header corner renderer
371 class WXDLLIMPEXP_ADV wxGridCornerHeaderRendererDefault
372 : public wxGridCornerHeaderRenderer
375 virtual void DrawBorder(const wxGrid
& grid
,
381 // ----------------------------------------------------------------------------
382 // wxGridCellAttr: this class can be used to alter the cells appearance in
383 // the grid by changing their colour/font/... from default. An object of this
384 // class may be returned by wxGridTable::GetAttr().
385 // ----------------------------------------------------------------------------
387 class WXDLLIMPEXP_ADV wxGridCellAttr
: public wxClientDataContainer
, public wxRefCounter
401 wxGridCellAttr(wxGridCellAttr
*attrDefault
= NULL
)
405 SetAlignment(wxALIGN_INVALID
, wxALIGN_INVALID
);
408 // VZ: considering the number of members wxGridCellAttr has now, this ctor
409 // seems to be pretty useless... may be we should just remove it?
410 wxGridCellAttr(const wxColour
& colText
,
411 const wxColour
& colBack
,
415 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
418 SetAlignment(hAlign
, vAlign
);
421 // creates a new copy of this object
422 wxGridCellAttr
*Clone() const;
423 void MergeWith(wxGridCellAttr
*mergefrom
);
426 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
427 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
428 void SetFont(const wxFont
& font
) { m_font
= font
; }
429 void SetAlignment(int hAlign
, int vAlign
)
434 void SetSize(int num_rows
, int num_cols
);
435 void SetOverflow(bool allow
= true)
436 { m_overflow
= allow
? Overflow
: SingleCell
; }
437 void SetReadOnly(bool isReadOnly
= true)
438 { m_isReadOnly
= isReadOnly
? ReadOnly
: ReadWrite
; }
440 // takes ownership of the pointer
441 void SetRenderer(wxGridCellRenderer
*renderer
)
442 { wxSafeDecRef(m_renderer
); m_renderer
= renderer
; }
443 void SetEditor(wxGridCellEditor
* editor
)
444 { wxSafeDecRef(m_editor
); m_editor
= editor
; }
446 void SetKind(wxAttrKind kind
) { m_attrkind
= kind
; }
449 bool HasTextColour() const { return m_colText
.IsOk(); }
450 bool HasBackgroundColour() const { return m_colBack
.IsOk(); }
451 bool HasFont() const { return m_font
.IsOk(); }
452 bool HasAlignment() const
454 return m_hAlign
!= wxALIGN_INVALID
|| m_vAlign
!= wxALIGN_INVALID
;
456 bool HasRenderer() const { return m_renderer
!= NULL
; }
457 bool HasEditor() const { return m_editor
!= NULL
; }
458 bool HasReadWriteMode() const { return m_isReadOnly
!= Unset
; }
459 bool HasOverflowMode() const { return m_overflow
!= UnsetOverflow
; }
460 bool HasSize() const { return m_sizeRows
!= 1 || m_sizeCols
!= 1; }
462 const wxColour
& GetTextColour() const;
463 const wxColour
& GetBackgroundColour() const;
464 const wxFont
& GetFont() const;
465 void GetAlignment(int *hAlign
, int *vAlign
) const;
467 // unlike GetAlignment() which always overwrites its output arguments with
468 // the alignment values to use, falling back on default alignment if this
469 // attribute doesn't have any, this function will preserve the values of
470 // parameters on entry if the corresponding alignment is not set in this
471 // attribute meaning that they can be initialized to default alignment (and
472 // also that they must be initialized, unlike with GetAlignment())
473 void GetNonDefaultAlignment(int *hAlign
, int *vAlign
) const;
475 void GetSize(int *num_rows
, int *num_cols
) const;
476 bool GetOverflow() const
477 { return m_overflow
!= SingleCell
; }
478 wxGridCellRenderer
*GetRenderer(const wxGrid
* grid
, int row
, int col
) const;
479 wxGridCellEditor
*GetEditor(const wxGrid
* grid
, int row
, int col
) const;
481 bool IsReadOnly() const { return m_isReadOnly
== wxGridCellAttr::ReadOnly
; }
483 wxAttrKind
GetKind() { return m_attrkind
; }
485 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
488 // the dtor is private because only DecRef() can delete us
489 virtual ~wxGridCellAttr()
491 wxSafeDecRef(m_renderer
);
492 wxSafeDecRef(m_editor
);
503 enum wxAttrOverflowMode
510 // the common part of all ctors
511 void Init(wxGridCellAttr
*attrDefault
= NULL
);
522 wxAttrOverflowMode m_overflow
;
524 wxGridCellRenderer
* m_renderer
;
525 wxGridCellEditor
* m_editor
;
526 wxGridCellAttr
* m_defGridAttr
;
528 wxAttrReadMode m_isReadOnly
;
530 wxAttrKind m_attrkind
;
532 // use Clone() instead
533 wxDECLARE_NO_COPY_CLASS(wxGridCellAttr
);
535 // suppress the stupid gcc warning about the class having private dtor and
537 friend class wxGridCellAttrDummyFriend
;
540 // ----------------------------------------------------------------------------
541 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
543 // ----------------------------------------------------------------------------
545 // implementation note: we separate it from wxGridTableBase because we wish to
546 // avoid deriving a new table class if possible, and sometimes it will be
547 // enough to just derive another wxGridCellAttrProvider instead
549 // the default implementation is reasonably efficient for the generic case,
550 // but you might still wish to implement your own for some specific situations
551 // if you have performance problems with the stock one
552 class WXDLLIMPEXP_ADV wxGridCellAttrProvider
: public wxClientDataContainer
555 wxGridCellAttrProvider();
556 virtual ~wxGridCellAttrProvider();
558 // DecRef() must be called on the returned pointer
559 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
560 wxGridCellAttr::wxAttrKind kind
) const;
562 // all these functions take ownership of the pointer, don't call DecRef()
564 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
565 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
566 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
568 // these functions must be called whenever some rows/cols are deleted
569 // because the internal data must be updated then
570 void UpdateAttrRows( size_t pos
, int numRows
);
571 void UpdateAttrCols( size_t pos
, int numCols
);
574 // get renderers for the given row/column header label and the corner
575 // window: unlike cell renderers, these objects are not reference counted
576 // and are never NULL so they are returned by reference
577 virtual const wxGridColumnHeaderRenderer
& GetColumnHeaderRenderer(int col
);
578 virtual const wxGridRowHeaderRenderer
& GetRowHeaderRenderer(int row
);
579 virtual const wxGridCornerHeaderRenderer
& GetCornerRenderer();
584 wxGridCellAttrProviderData
*m_data
;
586 wxDECLARE_NO_COPY_CLASS(wxGridCellAttrProvider
);
589 // ----------------------------------------------------------------------------
590 // wxGridCellCoords: location of a cell in the grid
591 // ----------------------------------------------------------------------------
593 class WXDLLIMPEXP_ADV wxGridCellCoords
596 wxGridCellCoords() { m_row
= m_col
= -1; }
597 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
599 // default copy ctor is ok
601 int GetRow() const { return m_row
; }
602 void SetRow( int n
) { m_row
= n
; }
603 int GetCol() const { return m_col
; }
604 void SetCol( int n
) { m_col
= n
; }
605 void Set( int row
, int col
) { m_row
= row
; m_col
= col
; }
607 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
609 if ( &other
!= this )
617 bool operator==( const wxGridCellCoords
& other
) const
619 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
622 bool operator!=( const wxGridCellCoords
& other
) const
624 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
627 bool operator!() const
629 return (m_row
== -1 && m_col
== -1 );
638 // For comparisons...
640 extern WXDLLIMPEXP_ADV wxGridCellCoords wxGridNoCellCoords
;
641 extern WXDLLIMPEXP_ADV wxRect wxGridNoCellRect
;
643 // An array of cell coords...
645 WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords
, wxGridCellCoordsArray
,
646 class WXDLLIMPEXP_ADV
);
648 // ----------------------------------------------------------------------------
649 // Grid table classes
650 // ----------------------------------------------------------------------------
652 // the abstract base class
653 class WXDLLIMPEXP_ADV wxGridTableBase
: public wxObject
,
654 public wxClientDataContainer
658 virtual ~wxGridTableBase();
660 // You must override these functions in a derived table class
663 // return the number of rows and columns in this table
664 virtual int GetNumberRows() = 0;
665 virtual int GetNumberCols() = 0;
667 // the methods above are unfortunately non-const even though they should
668 // have been const -- but changing it now is not possible any longer as it
669 // would break the existing code overriding them, so instead we provide
670 // these const synonyms which can be used from const-correct code
671 int GetRowsCount() const
672 { return const_cast<wxGridTableBase
*>(this)->GetNumberRows(); }
673 int GetColsCount() const
674 { return const_cast<wxGridTableBase
*>(this)->GetNumberCols(); }
677 virtual bool IsEmptyCell( int row
, int col
)
679 return GetValue(row
, col
).empty();
682 bool IsEmpty(const wxGridCellCoords
& coord
)
684 return IsEmptyCell(coord
.GetRow(), coord
.GetCol());
687 virtual wxString
GetValue( int row
, int col
) = 0;
688 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
690 // Data type determination and value access
691 virtual wxString
GetTypeName( int row
, int col
);
692 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
693 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
695 virtual long GetValueAsLong( int row
, int col
);
696 virtual double GetValueAsDouble( int row
, int col
);
697 virtual bool GetValueAsBool( int row
, int col
);
699 virtual void SetValueAsLong( int row
, int col
, long value
);
700 virtual void SetValueAsDouble( int row
, int col
, double value
);
701 virtual void SetValueAsBool( int row
, int col
, bool value
);
703 // For user defined types
704 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
705 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
708 // Overriding these is optional
710 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
711 virtual wxGrid
* GetView() const { return m_view
; }
713 virtual void Clear() {}
714 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
715 virtual bool AppendRows( size_t numRows
= 1 );
716 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
717 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
718 virtual bool AppendCols( size_t numCols
= 1 );
719 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
721 virtual wxString
GetRowLabelValue( int row
);
722 virtual wxString
GetColLabelValue( int col
);
723 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
724 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
726 // Attribute handling
729 // give us the attr provider to use - we take ownership of the pointer
730 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
732 // get the currently used attr provider (may be NULL)
733 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
735 // Does this table allow attributes? Default implementation creates
736 // a wxGridCellAttrProvider if necessary.
737 virtual bool CanHaveAttributes();
739 // by default forwarded to wxGridCellAttrProvider if any. May be
740 // overridden to handle attributes directly in the table.
741 virtual wxGridCellAttr
*GetAttr( int row
, int col
,
742 wxGridCellAttr::wxAttrKind kind
);
745 // these functions take ownership of the pointer
746 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
747 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
748 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
752 wxGridCellAttrProvider
*m_attrProvider
;
754 DECLARE_ABSTRACT_CLASS(wxGridTableBase
)
755 wxDECLARE_NO_COPY_CLASS(wxGridTableBase
);
759 // ----------------------------------------------------------------------------
760 // wxGridTableMessage
761 // ----------------------------------------------------------------------------
763 // IDs for messages sent from grid table to view
765 enum wxGridTableRequest
767 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
768 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
769 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
770 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
771 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
772 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
773 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
774 wxGRIDTABLE_NOTIFY_COLS_DELETED
777 class WXDLLIMPEXP_ADV wxGridTableMessage
780 wxGridTableMessage();
781 wxGridTableMessage( wxGridTableBase
*table
, int id
,
785 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
786 wxGridTableBase
* GetTableObject() const { return m_table
; }
787 void SetId( int id
) { m_id
= id
; }
788 int GetId() { return m_id
; }
789 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
790 int GetCommandInt() { return m_comInt1
; }
791 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
792 int GetCommandInt2() { return m_comInt2
; }
795 wxGridTableBase
*m_table
;
800 wxDECLARE_NO_COPY_CLASS(wxGridTableMessage
);
805 // ------ wxGridStringArray
806 // A 2-dimensional array of strings for data values
809 WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString
, wxGridStringArray
,
810 class WXDLLIMPEXP_ADV
);
814 // ------ wxGridStringTable
816 // Simplest type of data table for a grid for small tables of strings
817 // that are stored in memory
820 class WXDLLIMPEXP_ADV wxGridStringTable
: public wxGridTableBase
824 wxGridStringTable( int numRows
, int numCols
);
826 // these are pure virtual in wxGridTableBase
828 virtual int GetNumberRows() { return static_cast<int>(m_data
.size()); }
829 virtual int GetNumberCols() { return m_numCols
; }
830 virtual wxString
GetValue( int row
, int col
);
831 virtual void SetValue( int row
, int col
, const wxString
& s
);
833 // overridden functions from wxGridTableBase
836 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
837 bool AppendRows( size_t numRows
= 1 );
838 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
839 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
840 bool AppendCols( size_t numCols
= 1 );
841 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
843 void SetRowLabelValue( int row
, const wxString
& );
844 void SetColLabelValue( int col
, const wxString
& );
845 wxString
GetRowLabelValue( int row
);
846 wxString
GetColLabelValue( int col
);
849 wxGridStringArray m_data
;
851 // notice that while we don't need to store the number of our rows as it's
852 // always equal to the size of m_data array, we do need to store the number
853 // of our columns as we can't retrieve it from m_data when the number of
854 // rows is 0 (see #10818)
857 // These only get used if you set your own labels, otherwise the
858 // GetRow/ColLabelValue functions return wxGridTableBase defaults
860 wxArrayString m_rowLabels
;
861 wxArrayString m_colLabels
;
863 DECLARE_DYNAMIC_CLASS_NO_COPY( wxGridStringTable
)
868 // ============================================================================
870 // ============================================================================
872 // ----------------------------------------------------------------------------
873 // wxGridSizesInfo stores information about sizes of the rows or columns.
875 // It assumes that most of the columns or rows have default size and so stores
876 // the default size separately and uses a hash to map column or row numbers to
877 // their non default size for those which don't have the default size.
878 // ----------------------------------------------------------------------------
880 // hash map to store positions as the keys and sizes as the values
881 WX_DECLARE_HASH_MAP_WITH_DECL( unsigned, int, wxIntegerHash
, wxIntegerEqual
,
882 wxUnsignedToIntHashMap
, class WXDLLIMPEXP_ADV
);
884 struct WXDLLIMPEXP_ADV wxGridSizesInfo
886 // default ctor, initialize m_sizeDefault and m_customSizes later
887 wxGridSizesInfo() { }
889 // ctor used by wxGrid::Get{Col,Row}Sizes()
890 wxGridSizesInfo(int defSize
, const wxArrayInt
& allSizes
);
892 // default copy ctor, assignment operator and dtor are ok
894 // Get the size of the element with the given index
895 int GetSize(unsigned pos
) const;
901 // position -> size map containing all elements with non-default size
902 wxUnsignedToIntHashMap m_customSizes
;
905 // ----------------------------------------------------------------------------
907 // ----------------------------------------------------------------------------
909 class WXDLLIMPEXP_ADV wxGrid
: public wxScrolledWindow
912 // possible selection modes
913 enum wxGridSelectionModes
915 wxGridSelectCells
= 0, // allow selecting anything
916 wxGridSelectRows
= 1, // allow selecting only entire rows
917 wxGridSelectColumns
= 2, // allow selecting only entire columns
918 wxGridSelectRowsOrColumns
= wxGridSelectRows
| wxGridSelectColumns
921 // Different behaviour of the TAB key when the end (or the beginning, for
922 // Shift-TAB) of the current row is reached:
925 Tab_Stop
, // Do nothing, this is default.
926 Tab_Wrap
, // Move to the next (or previous) row.
927 Tab_Leave
// Move to the next (or previous) control.
930 // creation and destruction
931 // ------------------------
933 // ctor and Create() create the grid window, as with the other controls
936 wxGrid(wxWindow
*parent
,
938 const wxPoint
& pos
= wxDefaultPosition
,
939 const wxSize
& size
= wxDefaultSize
,
940 long style
= wxWANTS_CHARS
,
941 const wxString
& name
= wxGridNameStr
)
945 Create(parent
, id
, pos
, size
, style
, name
);
948 bool Create(wxWindow
*parent
,
950 const wxPoint
& pos
= wxDefaultPosition
,
951 const wxSize
& size
= wxDefaultSize
,
952 long style
= wxWANTS_CHARS
,
953 const wxString
& name
= wxGridNameStr
);
957 // however to initialize grid data either CreateGrid() or SetTable() must
960 // this is basically equivalent to
962 // SetTable(new wxGridStringTable(numRows, numCols), true, selmode)
964 bool CreateGrid( int numRows
, int numCols
,
965 wxGridSelectionModes selmode
= wxGridSelectCells
);
967 bool SetTable( wxGridTableBase
*table
,
968 bool takeOwnership
= false,
969 wxGridSelectionModes selmode
= wxGridSelectCells
);
971 bool ProcessTableMessage(wxGridTableMessage
&);
973 wxGridTableBase
*GetTable() const { return m_table
; }
976 void SetSelectionMode(wxGridSelectionModes selmode
);
977 wxGridSelectionModes
GetSelectionMode() const;
979 // ------ grid dimensions
981 int GetNumberRows() const { return m_numRows
; }
982 int GetNumberCols() const { return m_numCols
; }
985 // ------ display update functions
987 wxArrayInt
CalcRowLabelsExposed( const wxRegion
& reg
) const;
989 wxArrayInt
CalcColLabelsExposed( const wxRegion
& reg
) const;
990 wxGridCellCoordsArray
CalcCellsExposed( const wxRegion
& reg
) const;
994 bool InsertRows(int pos
= 0, int numRows
= 1, bool updateLabels
= true)
996 return DoModifyLines(&wxGridTableBase::InsertRows
,
997 pos
, numRows
, updateLabels
);
999 bool InsertCols(int pos
= 0, int numCols
= 1, bool updateLabels
= true)
1001 return DoModifyLines(&wxGridTableBase::InsertCols
,
1002 pos
, numCols
, updateLabels
);
1005 bool AppendRows(int numRows
= 1, bool updateLabels
= true)
1007 return DoAppendLines(&wxGridTableBase::AppendRows
, numRows
, updateLabels
);
1009 bool AppendCols(int numCols
= 1, bool updateLabels
= true)
1011 return DoAppendLines(&wxGridTableBase::AppendCols
, numCols
, updateLabels
);
1014 bool DeleteRows(int pos
= 0, int numRows
= 1, bool updateLabels
= true)
1016 return DoModifyLines(&wxGridTableBase::DeleteRows
,
1017 pos
, numRows
, updateLabels
);
1019 bool DeleteCols(int pos
= 0, int numCols
= 1, bool updateLabels
= true)
1021 return DoModifyLines(&wxGridTableBase::DeleteCols
,
1022 pos
, numCols
, updateLabels
);
1025 void DrawGridCellArea( wxDC
& dc
, const wxGridCellCoordsArray
& cells
);
1026 void DrawGridSpace( wxDC
& dc
);
1027 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
1028 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
1029 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
1030 void DrawHighlight(wxDC
& dc
, const wxGridCellCoordsArray
& cells
);
1032 // this function is called when the current cell highlight must be redrawn
1033 // and may be overridden by the user
1034 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
1036 virtual void DrawRowLabels( wxDC
& dc
, const wxArrayInt
& rows
);
1037 virtual void DrawRowLabel( wxDC
& dc
, int row
);
1039 virtual void DrawColLabels( wxDC
& dc
, const wxArrayInt
& cols
);
1040 virtual void DrawColLabel( wxDC
& dc
, int col
);
1042 virtual void DrawCornerLabel(wxDC
& dc
);
1044 // ------ Cell text drawing functions
1046 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
1047 int horizontalAlignment
= wxALIGN_LEFT
,
1048 int verticalAlignment
= wxALIGN_TOP
,
1049 int textOrientation
= wxHORIZONTAL
) const;
1051 void DrawTextRectangle( wxDC
& dc
, const wxArrayString
& lines
, const wxRect
&,
1052 int horizontalAlignment
= wxALIGN_LEFT
,
1053 int verticalAlignment
= wxALIGN_TOP
,
1054 int textOrientation
= wxHORIZONTAL
) const;
1056 // ------ grid render function for printing
1058 void Render( wxDC
& dc
,
1059 const wxPoint
& pos
= wxDefaultPosition
,
1060 const wxSize
& size
= wxDefaultSize
,
1061 const wxGridCellCoords
& topLeft
= wxGridCellCoords(-1, -1),
1062 const wxGridCellCoords
& bottomRight
= wxGridCellCoords(-1, -1),
1063 int style
= wxGRID_DRAW_DEFAULT
);
1065 // Split a string containing newline characters into an array of
1066 // strings and return the number of lines
1068 void StringToLines( const wxString
& value
, wxArrayString
& lines
) const;
1070 void GetTextBoxSize( const wxDC
& dc
,
1071 const wxArrayString
& lines
,
1072 long *width
, long *height
) const;
1076 // Code that does a lot of grid modification can be enclosed
1077 // between BeginBatch() and EndBatch() calls to avoid screen
1080 void BeginBatch() { m_batchCount
++; }
1083 int GetBatchCount() { return m_batchCount
; }
1085 virtual void Refresh(bool eraseb
= true, const wxRect
* rect
= NULL
);
1087 // Use this, rather than wxWindow::Refresh(), to force an
1088 // immediate repainting of the grid. Has no effect if you are
1089 // already inside a BeginBatch / EndBatch block.
1091 // This function is necessary because wxGrid has a minimal OnPaint()
1092 // handler to reduce screen flicker.
1094 void ForceRefresh();
1097 // ------ edit control functions
1099 bool IsEditable() const { return m_editable
; }
1100 void EnableEditing( bool edit
);
1102 void EnableCellEditControl( bool enable
= true );
1103 void DisableCellEditControl() { EnableCellEditControl(false); }
1104 bool CanEnableCellControl() const;
1105 bool IsCellEditControlEnabled() const;
1106 bool IsCellEditControlShown() const;
1108 bool IsCurrentCellReadOnly() const;
1110 void ShowCellEditControl();
1111 void HideCellEditControl();
1112 void SaveEditControlValue();
1115 // ------ grid location functions
1116 // Note that all of these functions work with the logical coordinates of
1117 // grid cells and labels so you will need to convert from device
1118 // coordinates for mouse events etc.
1120 wxGridCellCoords
XYToCell(int x
, int y
) const;
1121 void XYToCell(int x
, int y
, wxGridCellCoords
& coords
) const
1122 { coords
= XYToCell(x
, y
); }
1123 wxGridCellCoords
XYToCell(const wxPoint
& pos
) const
1124 { return XYToCell(pos
.x
, pos
.y
); }
1126 // these functions return the index of the row/columns corresponding to the
1127 // given logical position in pixels
1129 // if clipToMinMax is false (default, wxNOT_FOUND is returned if the
1130 // position is outside any row/column, otherwise the first/last element is
1131 // returned in this case
1132 int YToRow( int y
, bool clipToMinMax
= false ) const;
1133 int XToCol( int x
, bool clipToMinMax
= false ) const;
1135 int YToEdgeOfRow( int y
) const;
1136 int XToEdgeOfCol( int x
) const;
1138 wxRect
CellToRect( int row
, int col
) const;
1139 wxRect
CellToRect( const wxGridCellCoords
& coords
) const
1140 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
1142 int GetGridCursorRow() const { return m_currentCellCoords
.GetRow(); }
1143 int GetGridCursorCol() const { return m_currentCellCoords
.GetCol(); }
1145 // check to see if a cell is either wholly visible (the default arg) or
1146 // at least partially visible in the grid window
1148 bool IsVisible( int row
, int col
, bool wholeCellVisible
= true ) const;
1149 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= true ) const
1150 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
1151 void MakeCellVisible( int row
, int col
);
1152 void MakeCellVisible( const wxGridCellCoords
& coords
)
1153 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
1156 // ------ grid cursor movement functions
1158 void SetGridCursor(int row
, int col
) { SetCurrentCell(row
, col
); }
1159 void SetGridCursor(const wxGridCellCoords
& c
) { SetCurrentCell(c
); }
1161 void GoToCell(int row
, int col
)
1163 if ( SetCurrentCell(row
, col
) )
1164 MakeCellVisible(row
, col
);
1167 void GoToCell(const wxGridCellCoords
& coords
)
1169 if ( SetCurrentCell(coords
) )
1170 MakeCellVisible(coords
);
1173 bool MoveCursorUp( bool expandSelection
);
1174 bool MoveCursorDown( bool expandSelection
);
1175 bool MoveCursorLeft( bool expandSelection
);
1176 bool MoveCursorRight( bool expandSelection
);
1177 bool MovePageDown();
1179 bool MoveCursorUpBlock( bool expandSelection
);
1180 bool MoveCursorDownBlock( bool expandSelection
);
1181 bool MoveCursorLeftBlock( bool expandSelection
);
1182 bool MoveCursorRightBlock( bool expandSelection
);
1184 void SetTabBehaviour(TabBehaviour behaviour
) { m_tabBehaviour
= behaviour
; }
1187 // ------ label and gridline formatting
1189 int GetDefaultRowLabelSize() const { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
1190 int GetRowLabelSize() const { return m_rowLabelWidth
; }
1191 int GetDefaultColLabelSize() const { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
1192 int GetColLabelSize() const { return m_colLabelHeight
; }
1193 wxColour
GetLabelBackgroundColour() const { return m_labelBackgroundColour
; }
1194 wxColour
GetLabelTextColour() const { return m_labelTextColour
; }
1195 wxFont
GetLabelFont() const { return m_labelFont
; }
1196 void GetRowLabelAlignment( int *horiz
, int *vert
) const;
1197 void GetColLabelAlignment( int *horiz
, int *vert
) const;
1198 int GetColLabelTextOrientation() const;
1199 wxString
GetRowLabelValue( int row
) const;
1200 wxString
GetColLabelValue( int col
) const;
1202 wxColour
GetCellHighlightColour() const { return m_cellHighlightColour
; }
1203 int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth
; }
1204 int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth
; }
1206 // this one will use wxHeaderCtrl for the column labels
1207 void UseNativeColHeader(bool native
= true);
1209 // this one will still draw them manually but using the native renderer
1210 // instead of using the same appearance as for the row labels
1211 void SetUseNativeColLabels( bool native
= true );
1213 void SetRowLabelSize( int width
);
1214 void SetColLabelSize( int height
);
1215 void HideRowLabels() { SetRowLabelSize( 0 ); }
1216 void HideColLabels() { SetColLabelSize( 0 ); }
1217 void SetLabelBackgroundColour( const wxColour
& );
1218 void SetLabelTextColour( const wxColour
& );
1219 void SetLabelFont( const wxFont
& );
1220 void SetRowLabelAlignment( int horiz
, int vert
);
1221 void SetColLabelAlignment( int horiz
, int vert
);
1222 void SetColLabelTextOrientation( int textOrientation
);
1223 void SetRowLabelValue( int row
, const wxString
& );
1224 void SetColLabelValue( int col
, const wxString
& );
1225 void SetCellHighlightColour( const wxColour
& );
1226 void SetCellHighlightPenWidth(int width
);
1227 void SetCellHighlightROPenWidth(int width
);
1230 // interactive grid mouse operations control
1231 // -----------------------------------------
1233 // functions globally enabling row/column interactive resizing (enabled by
1235 void EnableDragRowSize( bool enable
= true );
1236 void DisableDragRowSize() { EnableDragRowSize( false ); }
1238 void EnableDragColSize( bool enable
= true );
1239 void DisableDragColSize() { EnableDragColSize( false ); }
1241 // if interactive resizing is enabled, some rows/columns can still have
1243 void DisableRowResize(int row
) { DoDisableLineResize(row
, m_setFixedRows
); }
1244 void DisableColResize(int col
) { DoDisableLineResize(col
, m_setFixedCols
); }
1246 // these functions return whether the given row/column can be
1247 // effectively resized: for this interactive resizing must be enabled
1248 // and this index must not have been passed to DisableRow/ColResize()
1249 bool CanDragRowSize(int row
) const
1250 { return m_canDragRowSize
&& DoCanResizeLine(row
, m_setFixedRows
); }
1251 bool CanDragColSize(int col
) const
1252 { return m_canDragColSize
&& DoCanResizeLine(col
, m_setFixedCols
); }
1254 // interactive column reordering (disabled by default)
1255 void EnableDragColMove( bool enable
= true );
1256 void DisableDragColMove() { EnableDragColMove( false ); }
1257 bool CanDragColMove() const { return m_canDragColMove
; }
1259 // interactive resizing of grid cells (enabled by default)
1260 void EnableDragGridSize(bool enable
= true);
1261 void DisableDragGridSize() { EnableDragGridSize(false); }
1262 bool CanDragGridSize() const { return m_canDragGridSize
; }
1264 // interactive dragging of cells (disabled by default)
1265 void EnableDragCell( bool enable
= true );
1266 void DisableDragCell() { EnableDragCell( false ); }
1267 bool CanDragCell() const { return m_canDragCell
; }
1273 // enable or disable drawing of the lines
1274 void EnableGridLines(bool enable
= true);
1275 bool GridLinesEnabled() const { return m_gridLinesEnabled
; }
1277 // by default grid lines stop at last column/row, but this may be changed
1278 void ClipHorzGridLines(bool clip
)
1279 { DoClipGridLines(m_gridLinesClipHorz
, clip
); }
1280 void ClipVertGridLines(bool clip
)
1281 { DoClipGridLines(m_gridLinesClipVert
, clip
); }
1282 bool AreHorzGridLinesClipped() const { return m_gridLinesClipHorz
; }
1283 bool AreVertGridLinesClipped() const { return m_gridLinesClipVert
; }
1285 // this can be used to change the global grid lines colour
1286 void SetGridLineColour(const wxColour
& col
);
1287 wxColour
GetGridLineColour() const { return m_gridLineColour
; }
1289 // these methods may be overridden to customize individual grid lines
1291 virtual wxPen
GetDefaultGridLinePen();
1292 virtual wxPen
GetRowGridLinePen(int row
);
1293 virtual wxPen
GetColGridLinePen(int col
);
1299 // this sets the specified attribute for this cell or in this row/col
1300 void SetAttr(int row
, int col
, wxGridCellAttr
*attr
);
1301 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
1302 void SetColAttr(int col
, wxGridCellAttr
*attr
);
1304 // the grid can cache attributes for the recently used cells (currently it
1305 // only caches one attribute for the most recently used one) and might
1306 // notice that its value in the attribute provider has changed -- if this
1307 // happens, call this function to force it
1308 void RefreshAttr(int row
, int col
);
1310 // returns the attribute we may modify in place: a new one if this cell
1311 // doesn't have any yet or the existing one if it does
1313 // DecRef() must be called on the returned pointer, as usual
1314 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1317 // shortcuts for setting the column parameters
1319 // set the format for the data in the column: default is string
1320 void SetColFormatBool(int col
);
1321 void SetColFormatNumber(int col
);
1322 void SetColFormatFloat(int col
, int width
= -1, int precision
= -1);
1323 void SetColFormatCustom(int col
, const wxString
& typeName
);
1325 // ------ row and col formatting
1327 int GetDefaultRowSize() const;
1328 int GetRowSize( int row
) const;
1329 bool IsRowShown(int row
) const { return GetRowSize(row
) != 0; }
1330 int GetDefaultColSize() const;
1331 int GetColSize( int col
) const;
1332 bool IsColShown(int col
) const { return GetColSize(col
) != 0; }
1333 wxColour
GetDefaultCellBackgroundColour() const;
1334 wxColour
GetCellBackgroundColour( int row
, int col
) const;
1335 wxColour
GetDefaultCellTextColour() const;
1336 wxColour
GetCellTextColour( int row
, int col
) const;
1337 wxFont
GetDefaultCellFont() const;
1338 wxFont
GetCellFont( int row
, int col
) const;
1339 void GetDefaultCellAlignment( int *horiz
, int *vert
) const;
1340 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
) const;
1341 bool GetDefaultCellOverflow() const;
1342 bool GetCellOverflow( int row
, int col
) const;
1344 // this function returns 1 in num_rows and num_cols for normal cells,
1345 // positive numbers for a cell spanning multiple columns/rows (as set with
1346 // SetCellSize()) and _negative_ numbers corresponding to the offset of the
1347 // top left cell of the span from this one for the other cells covered by
1350 // the return value is CellSpan_None, CellSpan_Main or CellSpan_Inside for
1351 // each of these cases respectively
1354 CellSpan_Inside
= -1,
1359 CellSpan
GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
) const;
1361 wxSize
GetCellSize(const wxGridCellCoords
& coords
)
1364 GetCellSize(coords
.GetRow(), coords
.GetCol(), &s
.x
, &s
.y
);
1368 // ------ row and col sizes
1369 void SetDefaultRowSize( int height
, bool resizeExistingRows
= false );
1370 void SetRowSize( int row
, int height
);
1371 void HideRow(int row
) { DoSetRowSize(row
, 0); }
1372 void ShowRow(int row
) { DoSetRowSize(row
, -1); }
1374 void SetDefaultColSize( int width
, bool resizeExistingCols
= false );
1375 void SetColSize( int col
, int width
);
1376 void HideCol(int col
) { DoSetColSize(col
, 0); }
1377 void ShowCol(int col
) { DoSetColSize(col
, -1); }
1379 // the row and column sizes can be also set all at once using
1380 // wxGridSizesInfo which holds all of them at once
1382 wxGridSizesInfo
GetColSizes() const
1383 { return wxGridSizesInfo(GetDefaultColSize(), m_colWidths
); }
1384 wxGridSizesInfo
GetRowSizes() const
1385 { return wxGridSizesInfo(GetDefaultRowSize(), m_rowHeights
); }
1387 void SetColSizes(const wxGridSizesInfo
& sizeInfo
);
1388 void SetRowSizes(const wxGridSizesInfo
& sizeInfo
);
1391 // ------- columns (only, for now) reordering
1393 // columns index <-> positions mapping: by default, the position of the
1394 // column is the same as its index, but the columns can also be reordered
1395 // (either by calling SetColPos() explicitly or by the user dragging the
1396 // columns around) in which case their indices don't correspond to their
1397 // positions on display any longer
1399 // internally we always work with indices except for the functions which
1400 // have "Pos" in their names (and which work with columns, not pixels) and
1401 // only the display and hit testing code really cares about display
1404 // set the positions of all columns at once (this method uses the same
1405 // conventions as wxHeaderCtrl::SetColumnsOrder() for the order array)
1406 void SetColumnsOrder(const wxArrayInt
& order
);
1408 // return the column index corresponding to the given (valid) position
1409 int GetColAt(int pos
) const
1411 return m_colAt
.empty() ? pos
: m_colAt
[pos
];
1414 // reorder the columns so that the column with the given index is now shown
1415 // as the position pos
1416 void SetColPos(int idx
, int pos
);
1418 // return the position at which the column with the given index is
1419 // displayed: notice that this is a slow operation as we don't maintain the
1420 // reverse mapping currently
1421 int GetColPos(int idx
) const
1423 if ( m_colAt
.IsEmpty() )
1426 for ( int i
= 0; i
< m_numCols
; i
++ )
1428 if ( m_colAt
[i
] == idx
)
1432 wxFAIL_MSG( "invalid column index" );
1437 // reset the columns positions to the default order
1441 // automatically size the column or row to fit to its contents, if
1442 // setAsMin is true, this optimal width will also be set as minimal width
1444 void AutoSizeColumn( int col
, bool setAsMin
= true )
1445 { AutoSizeColOrRow(col
, setAsMin
, wxGRID_COLUMN
); }
1446 void AutoSizeRow( int row
, bool setAsMin
= true )
1447 { AutoSizeColOrRow(row
, setAsMin
, wxGRID_ROW
); }
1449 // auto size all columns (very ineffective for big grids!)
1450 void AutoSizeColumns( bool setAsMin
= true )
1451 { (void)SetOrCalcColumnSizes(false, setAsMin
); }
1453 void AutoSizeRows( bool setAsMin
= true )
1454 { (void)SetOrCalcRowSizes(false, setAsMin
); }
1456 // auto size the grid, that is make the columns/rows of the "right" size
1457 // and also set the grid size to just fit its contents
1460 // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize:
1461 // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column
1462 // instead of data column. Note that this operation may be slow for large
1464 // autosize row height depending on label text
1465 void AutoSizeRowLabelSize( int row
);
1467 // autosize column width depending on label text
1468 void AutoSizeColLabelSize( int col
);
1470 // column won't be resized to be lesser width - this must be called during
1471 // the grid creation because it won't resize the column if it's already
1472 // narrower than the minimal width
1473 void SetColMinimalWidth( int col
, int width
);
1474 void SetRowMinimalHeight( int row
, int width
);
1476 /* These members can be used to query and modify the minimal
1477 * acceptable size of grid rows and columns. Call this function in
1478 * your code which creates the grid if you want to display cells
1479 * with a size smaller than the default acceptable minimum size.
1480 * Like the members SetColMinimalWidth and SetRowMinimalWidth,
1481 * the existing rows or columns will not be checked/resized.
1483 void SetColMinimalAcceptableWidth( int width
);
1484 void SetRowMinimalAcceptableHeight( int width
);
1485 int GetColMinimalAcceptableWidth() const;
1486 int GetRowMinimalAcceptableHeight() const;
1488 void SetDefaultCellBackgroundColour( const wxColour
& );
1489 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1490 void SetDefaultCellTextColour( const wxColour
& );
1492 void SetCellTextColour( int row
, int col
, const wxColour
& );
1493 void SetDefaultCellFont( const wxFont
& );
1494 void SetCellFont( int row
, int col
, const wxFont
& );
1495 void SetDefaultCellAlignment( int horiz
, int vert
);
1496 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1497 void SetDefaultCellOverflow( bool allow
);
1498 void SetCellOverflow( int row
, int col
, bool allow
);
1499 void SetCellSize( int row
, int col
, int num_rows
, int num_cols
);
1501 // takes ownership of the pointer
1502 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1503 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1504 wxGridCellRenderer
*GetDefaultRenderer() const;
1505 wxGridCellRenderer
* GetCellRenderer(int row
, int col
) const;
1507 // takes ownership of the pointer
1508 void SetDefaultEditor(wxGridCellEditor
*editor
);
1509 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1510 wxGridCellEditor
*GetDefaultEditor() const;
1511 wxGridCellEditor
* GetCellEditor(int row
, int col
) const;
1515 // ------ cell value accessors
1517 wxString
GetCellValue( int row
, int col
) const
1521 return m_table
->GetValue( row
, col
);
1525 return wxEmptyString
;
1529 wxString
GetCellValue( const wxGridCellCoords
& coords
) const
1530 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1532 void SetCellValue( int row
, int col
, const wxString
& s
);
1533 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1534 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1536 // returns true if the cell can't be edited
1537 bool IsReadOnly(int row
, int col
) const;
1539 // make the cell editable/readonly
1540 void SetReadOnly(int row
, int col
, bool isReadOnly
= true);
1542 // ------ select blocks of cells
1544 void SelectRow( int row
, bool addToSelected
= false );
1545 void SelectCol( int col
, bool addToSelected
= false );
1547 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
1548 bool addToSelected
= false );
1550 void SelectBlock( const wxGridCellCoords
& topLeft
,
1551 const wxGridCellCoords
& bottomRight
,
1552 bool addToSelected
= false )
1553 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1554 bottomRight
.GetRow(), bottomRight
.GetCol(),
1559 bool IsSelection() const;
1561 // ------ deselect blocks or cells
1563 void DeselectRow( int row
);
1564 void DeselectCol( int col
);
1565 void DeselectCell( int row
, int col
);
1567 void ClearSelection();
1569 bool IsInSelection( int row
, int col
) const;
1571 bool IsInSelection( const wxGridCellCoords
& coords
) const
1572 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1574 wxGridCellCoordsArray
GetSelectedCells() const;
1575 wxGridCellCoordsArray
GetSelectionBlockTopLeft() const;
1576 wxGridCellCoordsArray
GetSelectionBlockBottomRight() const;
1577 wxArrayInt
GetSelectedRows() const;
1578 wxArrayInt
GetSelectedCols() const;
1580 // This function returns the rectangle that encloses the block of cells
1581 // limited by TopLeft and BottomRight cell in device coords and clipped
1582 // to the client size of the grid window.
1584 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1585 const wxGridCellCoords
& bottomRight
) const;
1587 // Access or update the selection fore/back colours
1588 wxColour
GetSelectionBackground() const
1589 { return m_selectionBackground
; }
1590 wxColour
GetSelectionForeground() const
1591 { return m_selectionForeground
; }
1593 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1594 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1597 // Methods for a registry for mapping data types to Renderers/Editors
1598 void RegisterDataType(const wxString
& typeName
,
1599 wxGridCellRenderer
* renderer
,
1600 wxGridCellEditor
* editor
);
1602 virtual wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1603 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1604 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1605 virtual wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1606 virtual wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1607 virtual wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1609 // grid may occupy more space than needed for its rows/columns, this
1610 // function allows to set how big this extra space is
1611 void SetMargins(int extraWidth
, int extraHeight
)
1613 m_extraWidth
= extraWidth
;
1614 m_extraHeight
= extraHeight
;
1619 // Accessors for component windows
1620 wxWindow
* GetGridWindow() const { return (wxWindow
*)m_gridWin
; }
1621 wxWindow
* GetGridRowLabelWindow() const { return (wxWindow
*)m_rowLabelWin
; }
1622 wxWindow
* GetGridColLabelWindow() const { return m_colWindow
; }
1623 wxWindow
* GetGridCornerLabelWindow() const { return (wxWindow
*)m_cornerLabelWin
; }
1625 // This one can only be called if we are using the native header window
1626 wxHeaderCtrl
*GetGridColHeader() const
1628 wxASSERT_MSG( m_useNativeHeader
, "no column header window" );
1630 // static_cast<> doesn't work without the full class declaration in
1631 // view and we prefer to avoid adding more compile-time dependencies
1632 // even at the cost of using reinterpret_cast<>
1633 return reinterpret_cast<wxHeaderCtrl
*>(m_colWindow
);
1636 // Allow adjustment of scroll increment. The default is (15, 15).
1637 void SetScrollLineX(int x
) { m_xScrollPixelsPerLine
= x
; }
1638 void SetScrollLineY(int y
) { m_yScrollPixelsPerLine
= y
; }
1639 int GetScrollLineX() const { return m_xScrollPixelsPerLine
; }
1640 int GetScrollLineY() const { return m_yScrollPixelsPerLine
; }
1642 // ------- drag and drop
1643 #if wxUSE_DRAG_AND_DROP
1644 virtual void SetDropTarget(wxDropTarget
*dropTarget
);
1645 #endif // wxUSE_DRAG_AND_DROP
1648 // ------- sorting support
1650 // wxGrid doesn't support sorting on its own but it can indicate the sort
1651 // order in the column header (currently only if native header control is
1654 // return the column currently displaying the sort indicator or wxNOT_FOUND
1656 int GetSortingColumn() const { return m_sortCol
; }
1658 // return true if this column is currently used for sorting
1659 bool IsSortingBy(int col
) const { return GetSortingColumn() == col
; }
1661 // return the current sorting order (on GetSortingColumn()): true for
1662 // ascending sort and false for descending; it doesn't make sense to call
1663 // it if GetSortingColumn() returns wxNOT_FOUND
1664 bool IsSortOrderAscending() const { return m_sortIsAscending
; }
1666 // set the sorting column (or unsets any existing one if wxNOT_FOUND) and
1667 // the order in which to sort
1668 void SetSortingColumn(int col
, bool ascending
= true);
1670 // unset any existing sorting column
1671 void UnsetSortingColumn() { SetSortingColumn(wxNOT_FOUND
); }
1673 #if WXWIN_COMPATIBILITY_2_8
1674 // ------ For compatibility with previous wxGrid only...
1676 // ************************************************
1677 // ** Don't use these in new code because they **
1678 // ** are liable to disappear in a future **
1680 // ************************************************
1683 wxGrid( wxWindow
*parent
,
1684 int x
, int y
, int w
= wxDefaultCoord
, int h
= wxDefaultCoord
,
1685 long style
= wxWANTS_CHARS
,
1686 const wxString
& name
= wxPanelNameStr
)
1689 Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(w
, h
), style
, name
);
1692 void SetCellValue( const wxString
& val
, int row
, int col
)
1693 { SetCellValue( row
, col
, val
); }
1695 void UpdateDimensions()
1696 { CalcDimensions(); }
1698 int GetRows() const { return GetNumberRows(); }
1699 int GetCols() const { return GetNumberCols(); }
1700 int GetCursorRow() const { return GetGridCursorRow(); }
1701 int GetCursorColumn() const { return GetGridCursorCol(); }
1703 int GetScrollPosX() const { return 0; }
1704 int GetScrollPosY() const { return 0; }
1706 void SetScrollX( int WXUNUSED(x
) ) { }
1707 void SetScrollY( int WXUNUSED(y
) ) { }
1709 void SetColumnWidth( int col
, int width
)
1710 { SetColSize( col
, width
); }
1712 int GetColumnWidth( int col
) const
1713 { return GetColSize( col
); }
1715 void SetRowHeight( int row
, int height
)
1716 { SetRowSize( row
, height
); }
1718 // GetRowHeight() is below
1720 int GetViewHeight() const // returned num whole rows visible
1723 int GetViewWidth() const // returned num whole cols visible
1726 void SetLabelSize( int orientation
, int sz
)
1728 if ( orientation
== wxHORIZONTAL
)
1729 SetColLabelSize( sz
);
1731 SetRowLabelSize( sz
);
1734 int GetLabelSize( int orientation
) const
1736 if ( orientation
== wxHORIZONTAL
)
1737 return GetColLabelSize();
1739 return GetRowLabelSize();
1742 void SetLabelAlignment( int orientation
, int align
)
1744 if ( orientation
== wxHORIZONTAL
)
1745 SetColLabelAlignment( align
, wxALIGN_INVALID
);
1747 SetRowLabelAlignment( align
, wxALIGN_INVALID
);
1750 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) ) const
1753 if ( orientation
== wxHORIZONTAL
)
1755 GetColLabelAlignment( &h
, &v
);
1760 GetRowLabelAlignment( &h
, &v
);
1765 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1767 if ( orientation
== wxHORIZONTAL
)
1768 SetColLabelValue( pos
, val
);
1770 SetRowLabelValue( pos
, val
);
1773 wxString
GetLabelValue( int orientation
, int pos
) const
1775 if ( orientation
== wxHORIZONTAL
)
1776 return GetColLabelValue( pos
);
1778 return GetRowLabelValue( pos
);
1781 wxFont
GetCellTextFont() const
1782 { return m_defaultCellAttr
->GetFont(); }
1784 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1785 { return m_defaultCellAttr
->GetFont(); }
1787 void SetCellTextFont(const wxFont
& fnt
)
1788 { SetDefaultCellFont( fnt
); }
1790 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1791 { SetCellFont( row
, col
, fnt
); }
1793 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1794 { SetCellTextColour( row
, col
, val
); }
1796 void SetCellTextColour(const wxColour
& col
)
1797 { SetDefaultCellTextColour( col
); }
1799 void SetCellBackgroundColour(const wxColour
& col
)
1800 { SetDefaultCellBackgroundColour( col
); }
1802 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1803 { SetCellBackgroundColour( row
, col
, colour
); }
1805 bool GetEditable() const { return IsEditable(); }
1806 void SetEditable( bool edit
= true ) { EnableEditing( edit
); }
1807 bool GetEditInPlace() const { return IsCellEditControlEnabled(); }
1809 void SetEditInPlace(bool WXUNUSED(edit
) = true) { }
1811 void SetCellAlignment( int align
, int row
, int col
)
1812 { SetCellAlignment(row
, col
, align
, wxALIGN_CENTER
); }
1813 void SetCellAlignment( int WXUNUSED(align
) ) {}
1814 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1816 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1817 wxPen
& GetDividerPen() const;
1818 void OnActivate(bool WXUNUSED(active
)) {}
1820 // ******** End of compatibility functions **********
1824 // ------ control IDs
1825 enum { wxGRID_CELLCTRL
= 2000,
1828 // ------ control types
1829 enum { wxGRID_TEXTCTRL
= 2100,
1834 wxDEPRECATED_INLINE(bool CanDragRowSize() const, return m_canDragRowSize
; )
1835 wxDEPRECATED_INLINE(bool CanDragColSize() const, return m_canDragColSize
; )
1836 #endif // WXWIN_COMPATIBILITY_2_8
1839 // override some base class functions
1840 virtual bool Enable(bool enable
= true);
1841 virtual wxWindow
*GetMainWindowOfCompositeControl()
1842 { return (wxWindow
*)m_gridWin
; }
1845 // implementation only
1846 void CancelMouseCapture();
1849 virtual wxSize
DoGetBestSize() const;
1853 wxGridWindow
*m_gridWin
;
1854 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1855 wxGridRowLabelWindow
*m_rowLabelWin
;
1857 // the real type of the column window depends on m_useNativeHeader value:
1858 // if it is true, its dynamic type is wxHeaderCtrl, otherwise it is
1859 // wxGridColLabelWindow, use accessors below when the real type matters
1860 wxWindow
*m_colWindow
;
1862 wxGridColLabelWindow
*GetColLabelWindow() const
1864 wxASSERT_MSG( !m_useNativeHeader
, "no column label window" );
1866 return reinterpret_cast<wxGridColLabelWindow
*>(m_colWindow
);
1869 wxGridTableBase
*m_table
;
1875 wxGridCellCoords m_currentCellCoords
;
1877 // the corners of the block being currently selected or wxGridNoCellCoords
1878 wxGridCellCoords m_selectedBlockTopLeft
;
1879 wxGridCellCoords m_selectedBlockBottomRight
;
1881 // when selecting blocks of cells (either from the keyboard using Shift
1882 // with cursor keys, or by dragging the mouse), the selection is anchored
1883 // at m_currentCellCoords which defines one of the corners of the rectangle
1884 // being selected -- and this variable defines the other corner, i.e. it's
1885 // either m_selectedBlockTopLeft or m_selectedBlockBottomRight depending on
1886 // which of them is not m_currentCellCoords
1888 // if no block selection is in process, it is set to wxGridNoCellCoords
1889 wxGridCellCoords m_selectedBlockCorner
;
1891 wxGridSelection
*m_selection
;
1893 wxColour m_selectionBackground
;
1894 wxColour m_selectionForeground
;
1896 // NB: *never* access m_row/col arrays directly because they are created
1897 // on demand, *always* use accessor functions instead!
1899 // init the m_rowHeights/Bottoms arrays with default values
1900 void InitRowHeights();
1902 int m_defaultRowHeight
;
1903 int m_minAcceptableRowHeight
;
1904 wxArrayInt m_rowHeights
;
1905 wxArrayInt m_rowBottoms
;
1907 // init the m_colWidths/Rights arrays
1908 void InitColWidths();
1910 int m_defaultColWidth
;
1911 int m_minAcceptableColWidth
;
1912 wxArrayInt m_colWidths
;
1913 wxArrayInt m_colRights
;
1916 bool m_sortIsAscending
;
1918 bool m_useNativeHeader
,
1919 m_nativeColumnLabels
;
1921 // get the col/row coords
1922 int GetColWidth(int col
) const;
1923 int GetColLeft(int col
) const;
1924 int GetColRight(int col
) const;
1926 // this function must be public for compatibility...
1928 int GetRowHeight(int row
) const;
1931 int GetRowTop(int row
) const;
1932 int GetRowBottom(int row
) const;
1934 int m_rowLabelWidth
;
1935 int m_colLabelHeight
;
1937 // the size of the margin left to the right and bottom of the cell area
1941 wxColour m_labelBackgroundColour
;
1942 wxColour m_labelTextColour
;
1945 int m_rowLabelHorizAlign
;
1946 int m_rowLabelVertAlign
;
1947 int m_colLabelHorizAlign
;
1948 int m_colLabelVertAlign
;
1949 int m_colLabelTextOrientation
;
1951 bool m_defaultRowLabelValues
;
1952 bool m_defaultColLabelValues
;
1954 wxColour m_gridLineColour
;
1955 bool m_gridLinesEnabled
;
1956 bool m_gridLinesClipHorz
,
1957 m_gridLinesClipVert
;
1958 wxColour m_cellHighlightColour
;
1959 int m_cellHighlightPenWidth
;
1960 int m_cellHighlightROPenWidth
;
1963 // common part of AutoSizeColumn/Row() and GetBestSize()
1964 int SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
= true);
1965 int SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
= true);
1967 // common part of AutoSizeColumn/Row()
1968 void AutoSizeColOrRow(int n
, bool setAsMin
, wxGridDirection direction
);
1970 // Calculate the minimum acceptable size for labels area
1971 wxCoord
CalcColOrRowLabelAreaMinSize(wxGridDirection direction
);
1973 // if a column has a minimal width, it will be the value for it in this
1975 wxLongToLongHashMap m_colMinWidths
,
1978 // get the minimal width of the given column/row
1979 int GetColMinimalWidth(int col
) const;
1980 int GetRowMinimalHeight(int col
) const;
1982 // do we have some place to store attributes in?
1983 bool CanHaveAttributes() const;
1985 // cell attribute cache (currently we only cache 1, may be will do
1986 // more/better later)
1990 wxGridCellAttr
*attr
;
1993 // invalidates the attribute cache
1994 void ClearAttrCache();
1996 // adds an attribute to cache
1997 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
1999 // looks for an attr in cache, returns true if found
2000 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
2002 // looks for the attr in cache, if not found asks the table and caches the
2004 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
2005 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
) const
2006 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
2008 // the default cell attr object for cells that don't have their own
2009 wxGridCellAttr
* m_defaultCellAttr
;
2016 wxGridTypeRegistry
* m_typeRegistry
;
2020 WXGRID_CURSOR_SELECT_CELL
,
2021 WXGRID_CURSOR_RESIZE_ROW
,
2022 WXGRID_CURSOR_RESIZE_COL
,
2023 WXGRID_CURSOR_SELECT_ROW
,
2024 WXGRID_CURSOR_SELECT_COL
,
2025 WXGRID_CURSOR_MOVE_COL
2028 // this method not only sets m_cursorMode but also sets the correct cursor
2029 // for the given mode and, if captureMouse is not false releases the mouse
2030 // if it was captured and captures it if it must be captured
2032 // for this to work, you should always use it and not set m_cursorMode
2034 void ChangeCursorMode(CursorMode mode
,
2035 wxWindow
*win
= NULL
,
2036 bool captureMouse
= true);
2038 wxWindow
*m_winCapture
; // the window which captured the mouse
2040 // this variable is used not for finding the correct current cursor but
2041 // mainly for finding out what is going to happen if the mouse starts being
2042 // dragged right now
2044 // by default it is WXGRID_CURSOR_SELECT_CELL meaning that nothing else is
2045 // going on, and it is set to one of RESIZE/SELECT/MOVE values while the
2046 // corresponding operation will be started if the user starts dragging the
2047 // mouse from the current position
2048 CursorMode m_cursorMode
;
2054 bool m_canDragRowSize
;
2055 bool m_canDragColSize
;
2056 bool m_canDragColMove
;
2057 bool m_canDragGridSize
;
2060 // the last position (horizontal or vertical depending on whether the user
2061 // is resizing a column or a row) where a row or column separator line was
2062 // dragged by the user or -1 of there is no drag operation in progress
2066 // true if a drag operation is in progress; when this is true,
2067 // m_startDragPos is valid, i.e. not wxDefaultPosition
2070 // the position (in physical coordinates) where the user started dragging
2071 // the mouse or wxDefaultPosition if mouse isn't being dragged
2073 // notice that this can be != wxDefaultPosition while m_isDragging is still
2074 // false because we wait until the mouse is moved some distance away before
2075 // setting m_isDragging to true
2076 wxPoint m_startDragPos
;
2078 bool m_waitForSlowClick
;
2080 wxGridCellCoords m_selectionStart
;
2082 wxCursor m_rowResizeCursor
;
2083 wxCursor m_colResizeCursor
;
2085 bool m_editable
; // applies to whole grid
2086 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
2088 TabBehaviour m_tabBehaviour
; // determines how the TAB key behaves
2090 void Init(); // common part of all ctors
2092 void CreateColumnWindow();
2093 void CalcDimensions();
2094 void CalcWindowSizes();
2095 bool Redimension( wxGridTableMessage
& );
2098 // generate the appropriate grid event and return -1 if it was vetoed, 1 if
2099 // it was processed (but not vetoed) and 0 if it wasn't processed
2100 int SendEvent(const wxEventType evtType
,
2102 const wxMouseEvent
& e
);
2103 int SendEvent(const wxEventType evtType
,
2104 const wxGridCellCoords
& coords
,
2105 const wxMouseEvent
& e
)
2106 { return SendEvent(evtType
, coords
.GetRow(), coords
.GetCol(), e
); }
2107 int SendEvent(const wxEventType evtType
,
2109 const wxString
& s
= wxString());
2110 int SendEvent(const wxEventType evtType
,
2111 const wxGridCellCoords
& coords
,
2112 const wxString
& s
= wxString())
2113 { return SendEvent(evtType
, coords
.GetRow(), coords
.GetCol(), s
); }
2114 int SendEvent(const wxEventType evtType
, const wxString
& s
= wxString())
2115 { return SendEvent(evtType
, m_currentCellCoords
, s
); }
2117 // send wxEVT_GRID_{ROW,COL}_SIZE
2118 void SendGridSizeEvent(wxEventType type
,
2120 const wxMouseEvent
& mouseEv
);
2122 void OnPaint( wxPaintEvent
& );
2123 void OnSize( wxSizeEvent
& );
2124 void OnKeyDown( wxKeyEvent
& );
2125 void OnKeyUp( wxKeyEvent
& );
2126 void OnChar( wxKeyEvent
& );
2127 void OnEraseBackground( wxEraseEvent
& );
2130 bool SetCurrentCell( const wxGridCellCoords
& coords
);
2131 bool SetCurrentCell( int row
, int col
)
2132 { return SetCurrentCell( wxGridCellCoords(row
, col
) ); }
2135 // this function is called to extend the block being currently selected
2136 // from mouse and keyboard event handlers
2137 void UpdateBlockBeingSelected(int topRow
, int leftCol
,
2138 int bottomRow
, int rightCol
);
2140 void UpdateBlockBeingSelected(const wxGridCellCoords
& topLeft
,
2141 const wxGridCellCoords
& bottomRight
)
2142 { UpdateBlockBeingSelected(topLeft
.GetRow(), topLeft
.GetCol(),
2143 bottomRight
.GetRow(), bottomRight
.GetCol()); }
2145 // ------ functions to get/send data (see also public functions)
2147 bool GetModelValues();
2148 bool SetModelValues();
2150 friend class WXDLLIMPEXP_FWD_ADV wxGridSelection
;
2151 friend class wxGridRowOperations
;
2152 friend class wxGridColumnOperations
;
2154 // they call our private Process{{Corner,Col,Row}Label,GridCell}MouseEvent()
2155 friend class wxGridCornerLabelWindow
;
2156 friend class wxGridColLabelWindow
;
2157 friend class wxGridRowLabelWindow
;
2158 friend class wxGridWindow
;
2159 friend class wxGridHeaderRenderer
;
2161 friend class wxGridHeaderCtrl
;
2165 // implement wxScrolledWindow method to return m_gridWin size
2166 virtual wxSize
GetSizeAvailableForScrollTarget(const wxSize
& size
);
2168 // redraw the grid lines, should be called after changing their attributes
2169 void RedrawGridLines();
2171 // draw all grid lines in the given cell region (unlike the public
2172 // DrawAllGridLines() which just draws all of them)
2173 void DrawRangeGridLines(wxDC
& dc
, const wxRegion
& reg
,
2174 const wxGridCellCoords
& topLeft
,
2175 const wxGridCellCoords
& bottomRight
);
2177 // draw all lines from top to bottom row and left to right column in the
2178 // rectangle determined by (top, left)-(bottom, right) -- but notice that
2179 // the caller must have set up the clipping correctly, this rectangle is
2180 // only used here for optimization
2181 void DoDrawGridLines(wxDC
& dc
,
2183 int bottom
, int right
,
2184 int topRow
, int leftCol
,
2185 int bottomRight
, int rightCol
);
2187 // common part of Clip{Horz,Vert}GridLines
2188 void DoClipGridLines(bool& var
, bool clip
);
2190 // update the sorting indicator shown in the specified column (whose index
2193 // this will use GetSortingColumn() and IsSortOrderAscending() to determine
2194 // the sorting indicator to effectively show
2195 void UpdateColumnSortingIndicator(int col
);
2197 // update the grid after changing the columns order (common part of
2198 // SetColPos() and ResetColPos())
2199 void RefreshAfterColPosChange();
2202 // return the position (not index) of the column at the given logical pixel
2205 // this always returns a valid position, even if the coordinate is out of
2206 // bounds (in which case first/last column is returned)
2207 int XToPos(int x
) const;
2210 // event handlers and their helpers
2211 // --------------------------------
2213 // process mouse drag event in WXGRID_CURSOR_SELECT_CELL mode
2214 bool DoGridCellDrag(wxMouseEvent
& event
,
2215 const wxGridCellCoords
& coords
,
2218 // process row/column resizing drag event
2219 void DoGridLineDrag(wxMouseEvent
& event
, const wxGridOperations
& oper
);
2221 // process mouse drag event in the grid window
2222 void DoGridDragEvent(wxMouseEvent
& event
, const wxGridCellCoords
& coords
);
2224 // process different clicks on grid cells
2225 void DoGridCellLeftDown(wxMouseEvent
& event
,
2226 const wxGridCellCoords
& coords
,
2227 const wxPoint
& pos
);
2228 void DoGridCellLeftDClick(wxMouseEvent
& event
,
2229 const wxGridCellCoords
& coords
,
2230 const wxPoint
& pos
);
2231 void DoGridCellLeftUp(wxMouseEvent
& event
, const wxGridCellCoords
& coords
);
2233 // process movement (but not dragging) event in the grid cell area
2234 void DoGridMouseMoveEvent(wxMouseEvent
& event
,
2235 const wxGridCellCoords
& coords
,
2236 const wxPoint
& pos
);
2238 // process mouse events in the grid window
2239 void ProcessGridCellMouseEvent(wxMouseEvent
& event
);
2241 // process mouse events in the row/column labels/corner windows
2242 void ProcessRowLabelMouseEvent(wxMouseEvent
& event
);
2243 void ProcessColLabelMouseEvent(wxMouseEvent
& event
);
2244 void ProcessCornerLabelMouseEvent(wxMouseEvent
& event
);
2246 void DoColHeaderClick(int col
);
2248 void DoStartResizeCol(int col
);
2249 void DoUpdateResizeCol(int x
);
2250 void DoUpdateResizeColWidth(int w
);
2251 void DoStartMoveCol(int col
);
2253 void DoEndDragResizeRow(const wxMouseEvent
& event
);
2254 void DoEndDragResizeCol(const wxMouseEvent
& event
);
2255 void DoEndMoveCol(int pos
);
2257 // process a TAB keypress
2258 void DoGridProcessTab(wxKeyboardState
& kbdState
);
2260 // common implementations of methods defined for both rows and columns
2261 void DeselectLine(int line
, const wxGridOperations
& oper
);
2262 bool DoEndDragResizeLine(const wxGridOperations
& oper
);
2263 int PosToLinePos(int pos
, bool clipToMinMax
,
2264 const wxGridOperations
& oper
) const;
2265 int PosToLine(int pos
, bool clipToMinMax
,
2266 const wxGridOperations
& oper
) const;
2267 int PosToEdgeOfLine(int pos
, const wxGridOperations
& oper
) const;
2269 bool DoMoveCursor(bool expandSelection
,
2270 const wxGridDirectionOperations
& diroper
);
2271 bool DoMoveCursorByPage(const wxGridDirectionOperations
& diroper
);
2272 bool DoMoveCursorByBlock(bool expandSelection
,
2273 const wxGridDirectionOperations
& diroper
);
2274 void AdvanceToNextNonEmpty(wxGridCellCoords
& coords
,
2275 const wxGridDirectionOperations
& diroper
);
2277 // common part of {Insert,Delete}{Rows,Cols}
2278 bool DoModifyLines(bool (wxGridTableBase::*funcModify
)(size_t, size_t),
2279 int pos
, int num
, bool updateLabels
);
2280 // Append{Rows,Cols} is a bit different because of one less parameter
2281 bool DoAppendLines(bool (wxGridTableBase::*funcAppend
)(size_t),
2282 int num
, bool updateLabels
);
2284 // common part of Set{Col,Row}Sizes
2285 void DoSetSizes(const wxGridSizesInfo
& sizeInfo
,
2286 const wxGridOperations
& oper
);
2288 // common part of Disable{Row,Col}Resize and CanDrag{Row,Col}Size
2289 void DoDisableLineResize(int line
, wxGridFixedIndicesSet
*& setFixed
);
2290 bool DoCanResizeLine(int line
, const wxGridFixedIndicesSet
*setFixed
) const;
2292 // Helper of Render(): get grid size, origin offset and fill cell arrays
2293 void GetRenderSizes( const wxGridCellCoords
& topLeft
,
2294 const wxGridCellCoords
& bottomRight
,
2295 wxPoint
& pointOffSet
, wxSize
& sizeGrid
,
2296 wxGridCellCoordsArray
& renderCells
,
2297 wxArrayInt
& arrayCols
, wxArrayInt
& arrayRows
);
2299 // Helper of Render(): set the scale to draw the cells at the right size.
2300 void SetRenderScale( wxDC
& dc
, const wxPoint
& pos
, const wxSize
& size
,
2301 const wxSize
& sizeGrid
);
2303 // Helper of Render(): get render start position from passed parameter
2304 wxPoint
GetRenderPosition( wxDC
& dc
, const wxPoint
& position
);
2306 // Helper of Render(): draws a box around the rendered area
2307 void DoRenderBox( wxDC
& dc
, const int& style
,
2308 const wxPoint
& pointOffSet
,
2309 const wxSize
& sizeCellArea
,
2310 const wxGridCellCoords
& topLeft
,
2311 const wxGridCellCoords
& bottomRight
);
2313 // Implementation of public Set{Row,Col}Size() and {Hide,Show}{Row,Col}().
2314 // They interpret their height or width parameter slightly different from
2315 // the public methods where -1 in it means "auto fit to the label" for the
2316 // compatibility reasons. Here it means "show a previously hidden row or
2317 // column" while 0 means "hide it" just as in the public methods. And any
2318 // positive values are handled naturally, i.e. they just specify the size.
2319 void DoSetRowSize( int row
, int height
);
2320 void DoSetColSize( int col
, int width
);
2323 // these sets contain the indices of fixed, i.e. non-resizable
2324 // interactively, grid rows or columns and are NULL if there are no fixed
2325 // elements (which is the default)
2326 wxGridFixedIndicesSet
*m_setFixedRows
,
2329 DECLARE_DYNAMIC_CLASS( wxGrid
)
2330 DECLARE_EVENT_TABLE()
2331 wxDECLARE_NO_COPY_CLASS(wxGrid
);
2334 // ----------------------------------------------------------------------------
2335 // wxGridUpdateLocker prevents updates to a grid during its lifetime
2336 // ----------------------------------------------------------------------------
2338 class WXDLLIMPEXP_ADV wxGridUpdateLocker
2341 // if the pointer is NULL, Create() can be called later
2342 wxGridUpdateLocker(wxGrid
*grid
= NULL
)
2347 // can be called if ctor was used with a NULL pointer, must not be called
2349 void Create(wxGrid
*grid
)
2351 wxASSERT_MSG( !m_grid
, wxT("shouldn't be called more than once") );
2356 ~wxGridUpdateLocker()
2363 void Init(wxGrid
*grid
)
2367 m_grid
->BeginBatch();
2372 wxDECLARE_NO_COPY_CLASS(wxGridUpdateLocker
);
2375 // ----------------------------------------------------------------------------
2376 // Grid event class and event types
2377 // ----------------------------------------------------------------------------
2379 class WXDLLIMPEXP_ADV wxGridEvent
: public wxNotifyEvent
,
2380 public wxKeyboardState
2386 Init(-1, -1, -1, -1, false);
2392 int row
= -1, int col
= -1,
2393 int x
= -1, int y
= -1,
2395 const wxKeyboardState
& kbd
= wxKeyboardState())
2396 : wxNotifyEvent(type
, id
),
2397 wxKeyboardState(kbd
)
2399 Init(row
, col
, x
, y
, sel
);
2400 SetEventObject(obj
);
2403 // explicitly specifying inline allows gcc < 3.4 to
2404 // handle the deprecation attribute even in the constructor.
2405 wxDEPRECATED_CONSTRUCTOR(
2413 bool shift
= false, bool alt
= false, bool meta
= false));
2415 virtual int GetRow() { return m_row
; }
2416 virtual int GetCol() { return m_col
; }
2417 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
2418 bool Selecting() { return m_selecting
; }
2420 virtual wxEvent
*Clone() const { return new wxGridEvent(*this); }
2430 void Init(int row
, int col
, int x
, int y
, bool sel
)
2439 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent
)
2442 class WXDLLIMPEXP_ADV wxGridSizeEvent
: public wxNotifyEvent
,
2443 public wxKeyboardState
2452 wxGridSizeEvent(int id
,
2456 int x
= -1, int y
= -1,
2457 const wxKeyboardState
& kbd
= wxKeyboardState())
2458 : wxNotifyEvent(type
, id
),
2459 wxKeyboardState(kbd
)
2461 Init(rowOrCol
, x
, y
);
2463 SetEventObject(obj
);
2466 wxDEPRECATED_CONSTRUCTOR(
2467 wxGridSizeEvent(int id
,
2475 bool meta
= false) );
2477 int GetRowOrCol() { return m_rowOrCol
; }
2478 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
2480 virtual wxEvent
*Clone() const { return new wxGridSizeEvent(*this); }
2488 void Init(int rowOrCol
, int x
, int y
)
2490 m_rowOrCol
= rowOrCol
;
2495 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent
)
2499 class WXDLLIMPEXP_ADV wxGridRangeSelectEvent
: public wxNotifyEvent
,
2500 public wxKeyboardState
2503 wxGridRangeSelectEvent()
2506 Init(wxGridNoCellCoords
, wxGridNoCellCoords
, false);
2509 wxGridRangeSelectEvent(int id
,
2512 const wxGridCellCoords
& topLeft
,
2513 const wxGridCellCoords
& bottomRight
,
2515 const wxKeyboardState
& kbd
= wxKeyboardState())
2516 : wxNotifyEvent(type
, id
),
2517 wxKeyboardState(kbd
)
2519 Init(topLeft
, bottomRight
, sel
);
2521 SetEventObject(obj
);
2524 wxDEPRECATED_CONSTRUCTOR(
2525 wxGridRangeSelectEvent(int id
,
2528 const wxGridCellCoords
& topLeft
,
2529 const wxGridCellCoords
& bottomRight
,
2534 bool meta
= false) );
2536 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
2537 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
2538 int GetTopRow() { return m_topLeft
.GetRow(); }
2539 int GetBottomRow() { return m_bottomRight
.GetRow(); }
2540 int GetLeftCol() { return m_topLeft
.GetCol(); }
2541 int GetRightCol() { return m_bottomRight
.GetCol(); }
2542 bool Selecting() { return m_selecting
; }
2544 virtual wxEvent
*Clone() const { return new wxGridRangeSelectEvent(*this); }
2547 void Init(const wxGridCellCoords
& topLeft
,
2548 const wxGridCellCoords
& bottomRight
,
2551 m_topLeft
= topLeft
;
2552 m_bottomRight
= bottomRight
;
2553 m_selecting
= selecting
;
2556 wxGridCellCoords m_topLeft
;
2557 wxGridCellCoords m_bottomRight
;
2560 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent
)
2564 class WXDLLIMPEXP_ADV wxGridEditorCreatedEvent
: public wxCommandEvent
2567 wxGridEditorCreatedEvent()
2575 wxGridEditorCreatedEvent(int id
, wxEventType type
, wxObject
* obj
,
2576 int row
, int col
, wxControl
* ctrl
);
2578 int GetRow() { return m_row
; }
2579 int GetCol() { return m_col
; }
2580 wxControl
* GetControl() { return m_ctrl
; }
2581 void SetRow(int row
) { m_row
= row
; }
2582 void SetCol(int col
) { m_col
= col
; }
2583 void SetControl(wxControl
* ctrl
) { m_ctrl
= ctrl
; }
2585 virtual wxEvent
*Clone() const { return new wxGridEditorCreatedEvent(*this); }
2592 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent
)
2596 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_LEFT_CLICK
, wxGridEvent
);
2597 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_RIGHT_CLICK
, wxGridEvent
);
2598 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_LEFT_DCLICK
, wxGridEvent
);
2599 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_RIGHT_DCLICK
, wxGridEvent
);
2600 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_LABEL_LEFT_CLICK
, wxGridEvent
);
2601 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_LABEL_RIGHT_CLICK
, wxGridEvent
);
2602 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_LABEL_LEFT_DCLICK
, wxGridEvent
);
2603 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_LABEL_RIGHT_DCLICK
, wxGridEvent
);
2604 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_ROW_SIZE
, wxGridSizeEvent
);
2605 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_COL_SIZE
, wxGridSizeEvent
);
2606 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_RANGE_SELECT
, wxGridRangeSelectEvent
);
2607 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_CHANGING
, wxGridEvent
);
2608 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_CHANGED
, wxGridEvent
);
2609 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_SELECT_CELL
, wxGridEvent
);
2610 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_EDITOR_SHOWN
, wxGridEvent
);
2611 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_EDITOR_HIDDEN
, wxGridEvent
);
2612 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_EDITOR_CREATED
, wxGridEditorCreatedEvent
);
2613 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_BEGIN_DRAG
, wxGridEvent
);
2614 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_COL_MOVE
, wxGridEvent
);
2615 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_COL_SORT
, wxGridEvent
);
2616 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_TABBING
, wxGridEvent
);
2618 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
2619 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
2620 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
2621 typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction
)(wxGridEditorCreatedEvent
&);
2623 #define wxGridEventHandler(func) \
2624 wxEVENT_HANDLER_CAST(wxGridEventFunction, func)
2626 #define wxGridSizeEventHandler(func) \
2627 wxEVENT_HANDLER_CAST(wxGridSizeEventFunction, func)
2629 #define wxGridRangeSelectEventHandler(func) \
2630 wxEVENT_HANDLER_CAST(wxGridRangeSelectEventFunction, func)
2632 #define wxGridEditorCreatedEventHandler(func) \
2633 wxEVENT_HANDLER_CAST(wxGridEditorCreatedEventFunction, func)
2635 #define wx__DECLARE_GRIDEVT(evt, id, fn) \
2636 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn))
2638 #define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \
2639 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn))
2641 #define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \
2642 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn))
2644 #define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \
2645 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn))
2647 #define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn)
2648 #define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn)
2649 #define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn)
2650 #define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn)
2651 #define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn)
2652 #define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn)
2653 #define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn)
2654 #define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn)
2655 #define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn)
2656 #define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn)
2657 #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn)
2658 #define EVT_GRID_CMD_COL_SORT(id, fn) wx__DECLARE_GRIDEVT(COL_SORT, id, fn)
2659 #define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn)
2660 #define EVT_GRID_CMD_CELL_CHANGING(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGING, id, fn)
2661 #define EVT_GRID_CMD_CELL_CHANGED(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGED, id, fn)
2662 #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn)
2663 #define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn)
2664 #define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn)
2665 #define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn)
2666 #define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn)
2667 #define EVT_GRID_CMD_TABBING(id, fn) wx__DECLARE_GRIDEVT(TABBING, id, fn)
2669 // same as above but for any id (exists mainly for backwards compatibility but
2670 // then it's also true that you rarely have multiple grid in the same window)
2671 #define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn)
2672 #define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn)
2673 #define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn)
2674 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn)
2675 #define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn)
2676 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn)
2677 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn)
2678 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn)
2679 #define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn)
2680 #define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn)
2681 #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn)
2682 #define EVT_GRID_COL_SORT(fn) EVT_GRID_CMD_COL_SORT(wxID_ANY, fn)
2683 #define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn)
2684 #define EVT_GRID_CELL_CHANGING(fn) EVT_GRID_CMD_CELL_CHANGING(wxID_ANY, fn)
2685 #define EVT_GRID_CELL_CHANGED(fn) EVT_GRID_CMD_CELL_CHANGED(wxID_ANY, fn)
2686 #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn)
2687 #define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn)
2688 #define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn)
2689 #define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn)
2690 #define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn)
2691 #define EVT_GRID_TABBING(fn) EVT_GRID_CMD_TABBING(wxID_ANY, fn)
2693 // we used to have a single wxEVT_GRID_CELL_CHANGE event but it was split into
2694 // wxEVT_GRID_CELL_CHANGING and CHANGED ones in wx 2.9.0, however the CHANGED
2695 // is basically the same as the old CHANGE event so we keep the name for
2697 #if WXWIN_COMPATIBILITY_2_8
2698 #define wxEVT_GRID_CELL_CHANGE wxEVT_GRID_CELL_CHANGED
2700 #define EVT_GRID_CMD_CELL_CHANGE EVT_GRID_CMD_CELL_CHANGED
2701 #define EVT_GRID_CELL_CHANGE EVT_GRID_CELL_CHANGED
2702 #endif // WXWIN_COMPATIBILITY_2_8
2704 #if 0 // TODO: implement these ? others ?
2706 extern const int wxEVT_GRID_CREATE_CELL
;
2707 extern const int wxEVT_GRID_CHANGE_LABELS
;
2708 extern const int wxEVT_GRID_CHANGE_SEL_LABEL
;
2710 #define EVT_GRID_CREATE_CELL(fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2711 #define EVT_GRID_CHANGE_LABELS(fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2712 #define EVT_GRID_CHANGE_SEL_LABEL(fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2716 #endif // wxUSE_GRID
2717 #endif // _WX_GENERIC_GRID_H_