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
7 // Copyright: (c) Michael Bedward
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GENERIC_GRID_H_
12 #define _WX_GENERIC_GRID_H_
18 #include "wx/hashmap.h"
20 #include "wx/scrolwin.h"
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
26 extern WXDLLIMPEXP_DATA_ADV(const char) wxGridNameStr
[];
28 // Default parameters for wxGrid
30 #define WXGRID_DEFAULT_NUMBER_ROWS 10
31 #define WXGRID_DEFAULT_NUMBER_COLS 10
32 #if defined(__WXMSW__) || defined(__WXGTK20__)
33 #define WXGRID_DEFAULT_ROW_HEIGHT 25
35 #define WXGRID_DEFAULT_ROW_HEIGHT 30
37 #define WXGRID_DEFAULT_COL_WIDTH 80
38 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
39 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
40 #define WXGRID_LABEL_EDGE_ZONE 2
41 #define WXGRID_MIN_ROW_HEIGHT 15
42 #define WXGRID_MIN_COL_WIDTH 15
43 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
45 // type names for grid table values
46 #define wxGRID_VALUE_STRING wxT("string")
47 #define wxGRID_VALUE_BOOL wxT("bool")
48 #define wxGRID_VALUE_NUMBER wxT("long")
49 #define wxGRID_VALUE_FLOAT wxT("double")
50 #define wxGRID_VALUE_CHOICE wxT("choice")
52 #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
53 #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
55 // magic constant which tells (to some functions) to automatically calculate
56 // the appropriate size
57 #define wxGRID_AUTOSIZE (-1)
59 // many wxGrid methods work either with columns or rows, this enum is used for
60 // the parameter indicating which one should it be
67 // Flags used with wxGrid::Render() to select parts of the grid to draw.
68 enum wxGridRenderStyle
70 wxGRID_DRAW_ROWS_HEADER
= 0x001,
71 wxGRID_DRAW_COLS_HEADER
= 0x002,
72 wxGRID_DRAW_CELL_LINES
= 0x004,
73 wxGRID_DRAW_BOX_RECT
= 0x008,
74 wxGRID_DRAW_SELECTION
= 0x010,
75 wxGRID_DRAW_DEFAULT
= wxGRID_DRAW_ROWS_HEADER
|
76 wxGRID_DRAW_COLS_HEADER
|
77 wxGRID_DRAW_CELL_LINES
|
81 // ----------------------------------------------------------------------------
82 // forward declarations
83 // ----------------------------------------------------------------------------
85 class WXDLLIMPEXP_FWD_ADV wxGrid
;
86 class WXDLLIMPEXP_FWD_ADV wxGridCellAttr
;
87 class WXDLLIMPEXP_FWD_ADV wxGridCellAttrProviderData
;
88 class WXDLLIMPEXP_FWD_ADV wxGridColLabelWindow
;
89 class WXDLLIMPEXP_FWD_ADV wxGridCornerLabelWindow
;
90 class WXDLLIMPEXP_FWD_ADV wxGridRowLabelWindow
;
91 class WXDLLIMPEXP_FWD_ADV wxGridWindow
;
92 class WXDLLIMPEXP_FWD_ADV wxGridTypeRegistry
;
93 class WXDLLIMPEXP_FWD_ADV wxGridSelection
;
95 class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl
;
96 class WXDLLIMPEXP_FWD_CORE wxCheckBox
;
97 class WXDLLIMPEXP_FWD_CORE wxComboBox
;
98 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
100 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl
;
103 class wxGridFixedIndicesSet
;
105 class wxGridOperations
;
106 class wxGridRowOperations
;
107 class wxGridColumnOperations
;
108 class wxGridDirectionOperations
;
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
116 #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
118 // ----------------------------------------------------------------------------
119 // wxGridCellWorker: common base class for wxGridCellRenderer and
122 // NB: this is more an implementation convenience than a design issue, so this
123 // class is not documented and is not public at all
124 // ----------------------------------------------------------------------------
126 class WXDLLIMPEXP_ADV wxGridCellWorker
: public wxClientDataContainer
, public wxRefCounter
129 wxGridCellWorker() { }
131 // interpret renderer parameters: arbitrary string whose interpretation is
132 // left to the derived classes
133 virtual void SetParameters(const wxString
& params
);
136 // virtual dtor for any base class - private because only DecRef() can
138 virtual ~wxGridCellWorker();
141 // suppress the stupid gcc warning about the class having private dtor and
143 friend class wxGridCellWorkerDummyFriend
;
146 // ----------------------------------------------------------------------------
147 // wxGridCellRenderer: this class is responsible for actually drawing the cell
148 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
149 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
150 // view of all cells. This is an ABC, you will normally use one of the
151 // predefined derived classes or derive your own class from it.
152 // ----------------------------------------------------------------------------
154 class WXDLLIMPEXP_ADV wxGridCellRenderer
: public wxGridCellWorker
157 // draw the given cell on the provided DC inside the given rectangle
158 // using the style specified by the attribute and the default or selected
159 // state corresponding to the isSelected value.
161 // this pure virtual function has a default implementation which will
162 // prepare the DC using the given attribute: it will draw the rectangle
163 // with the bg colour from attr and set the text colour and font
164 virtual void Draw(wxGrid
& grid
,
165 wxGridCellAttr
& attr
,
169 bool isSelected
) = 0;
171 // get the preferred size of the cell for its contents
172 virtual wxSize
GetBestSize(wxGrid
& grid
,
173 wxGridCellAttr
& attr
,
175 int row
, int col
) = 0;
177 // create a new object which is the copy of this one
178 virtual wxGridCellRenderer
*Clone() const = 0;
181 // ----------------------------------------------------------------------------
182 // wxGridCellEditor: This class is responsible for providing and manipulating
183 // the in-place edit controls for the grid. Instances of wxGridCellEditor
184 // (actually, instances of derived classes since it is an ABC) can be
185 // associated with the cell attributes for individual cells, rows, columns, or
186 // even for the entire grid.
187 // ----------------------------------------------------------------------------
189 class WXDLLIMPEXP_ADV wxGridCellEditor
: public wxGridCellWorker
194 bool IsCreated() const { return m_control
!= NULL
; }
195 wxControl
* GetControl() const { return m_control
; }
196 void SetControl(wxControl
* control
) { m_control
= control
; }
198 wxGridCellAttr
* GetCellAttr() const { return m_attr
; }
199 void SetCellAttr(wxGridCellAttr
* attr
) { m_attr
= attr
; }
201 // Creates the actual edit control
202 virtual void Create(wxWindow
* parent
,
204 wxEvtHandler
* evtHandler
) = 0;
206 // Size and position the edit control
207 virtual void SetSize(const wxRect
& rect
);
209 // Show or hide the edit control, use the specified attributes to set
210 // colours/fonts for it
211 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
213 // Draws the part of the cell not occupied by the control: the base class
214 // version just fills it with background colour from the attribute
215 virtual void PaintBackground(wxDC
& dc
,
216 const wxRect
& rectCell
,
217 const wxGridCellAttr
& attr
);
220 // The methods called by wxGrid when a cell is edited: first BeginEdit() is
221 // called, then EndEdit() is and if it returns true and if the change is
222 // not vetoed by a user-defined event handler, finally ApplyEdit() is called
224 // Fetch the value from the table and prepare the edit control
225 // to begin editing. Set the focus to the edit control.
226 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
228 // Returns false if nothing changed, otherwise returns true and return the
229 // new value in its string form in the newval output parameter.
231 // This should also store the new value in its real type internally so that
232 // it could be used by ApplyEdit() but it must not modify the grid as the
233 // change could still be vetoed.
234 virtual bool EndEdit(int row
, int col
, const wxGrid
*grid
,
235 const wxString
& oldval
, wxString
*newval
) = 0;
237 // Complete the editing of the current cell by storing the value saved by
238 // the previous call to EndEdit() in the grid
239 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
) = 0;
242 // Reset the value in the control back to its starting value
243 virtual void Reset() = 0;
245 // return true to allow the given key to start editing: the base class
246 // version only checks that the event has no modifiers. The derived
247 // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
248 // their IsAcceptedKey() implementation, although, of course, it is not a
249 // mandatory requirment.
251 // NB: if the key is F2 (special), editing will always start and this
252 // method will not be called at all (but StartingKey() will)
253 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
255 // If the editor is enabled by pressing keys on the grid, this will be
256 // called to let the editor do something about that first key if desired
257 virtual void StartingKey(wxKeyEvent
& event
);
259 // if the editor is enabled by clicking on the cell, this method will be
261 virtual void StartingClick();
263 // Some types of controls on some platforms may need some help
264 // with the Return key.
265 virtual void HandleReturn(wxKeyEvent
& event
);
268 virtual void Destroy();
270 // create a new object which is the copy of this one
271 virtual wxGridCellEditor
*Clone() const = 0;
273 // added GetValue so we can get the value which is in the control
274 virtual wxString
GetValue() const = 0;
277 // the dtor is private because only DecRef() can delete us
278 virtual ~wxGridCellEditor();
280 // the control we show on screen
281 wxControl
* m_control
;
283 // a temporary pointer to the attribute being edited
284 wxGridCellAttr
* m_attr
;
286 // if we change the colours/font of the control from the default ones, we
287 // must restore the default later and we save them here between calls to
288 // Show(true) and Show(false)
293 // suppress the stupid gcc warning about the class having private dtor and
295 friend class wxGridCellEditorDummyFriend
;
297 wxDECLARE_NO_COPY_CLASS(wxGridCellEditor
);
300 // ----------------------------------------------------------------------------
301 // wxGridHeaderRenderer and company: like wxGridCellRenderer but for headers
302 // ----------------------------------------------------------------------------
304 // Base class for corner window renderer: it is the simplest of all renderers
305 // and only has a single function
306 class WXDLLIMPEXP_ADV wxGridCornerHeaderRenderer
309 // Draw the border around the corner window.
310 virtual void DrawBorder(const wxGrid
& grid
,
312 wxRect
& rect
) const = 0;
314 // make the dtor of a class with virtual functions virtual to avoid g++
315 // warnings, even though this class is not supposed to be used
317 virtual ~wxGridCornerHeaderRenderer() { }
321 // Base class for the row/column header cells renderers
322 class WXDLLIMPEXP_ADV wxGridHeaderLabelsRenderer
323 : public wxGridCornerHeaderRenderer
326 // Draw header cell label
327 virtual void DrawLabel(const wxGrid
& grid
,
329 const wxString
& value
,
333 int textOrientation
) const;
336 // Currently the row/column/corner renders don't need any methods other than
337 // those already in wxGridHeaderLabelsRenderer but still define separate classes
338 // for them for future extensions and also for better type safety (i.e. to
339 // avoid inadvertently using a column header renderer for the row headers)
340 class WXDLLIMPEXP_ADV wxGridRowHeaderRenderer
341 : public wxGridHeaderLabelsRenderer
345 class WXDLLIMPEXP_ADV wxGridColumnHeaderRenderer
346 : public wxGridHeaderLabelsRenderer
350 // Also define the default renderers which are used by wxGridCellAttrProvider
352 class WXDLLIMPEXP_ADV wxGridRowHeaderRendererDefault
353 : public wxGridRowHeaderRenderer
356 virtual void DrawBorder(const wxGrid
& grid
,
361 // Column header cells renderers
362 class WXDLLIMPEXP_ADV wxGridColumnHeaderRendererDefault
363 : public wxGridColumnHeaderRenderer
366 virtual void DrawBorder(const wxGrid
& grid
,
371 // Header corner renderer
372 class WXDLLIMPEXP_ADV wxGridCornerHeaderRendererDefault
373 : public wxGridCornerHeaderRenderer
376 virtual void DrawBorder(const wxGrid
& grid
,
382 // ----------------------------------------------------------------------------
383 // wxGridCellAttr: this class can be used to alter the cells appearance in
384 // the grid by changing their colour/font/... from default. An object of this
385 // class may be returned by wxGridTable::GetAttr().
386 // ----------------------------------------------------------------------------
388 class WXDLLIMPEXP_ADV wxGridCellAttr
: public wxClientDataContainer
, public wxRefCounter
402 wxGridCellAttr(wxGridCellAttr
*attrDefault
= NULL
)
406 SetAlignment(wxALIGN_INVALID
, wxALIGN_INVALID
);
409 // VZ: considering the number of members wxGridCellAttr has now, this ctor
410 // seems to be pretty useless... may be we should just remove it?
411 wxGridCellAttr(const wxColour
& colText
,
412 const wxColour
& colBack
,
416 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
419 SetAlignment(hAlign
, vAlign
);
422 // creates a new copy of this object
423 wxGridCellAttr
*Clone() const;
424 void MergeWith(wxGridCellAttr
*mergefrom
);
427 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
428 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
429 void SetFont(const wxFont
& font
) { m_font
= font
; }
430 void SetAlignment(int hAlign
, int vAlign
)
435 void SetSize(int num_rows
, int num_cols
);
436 void SetOverflow(bool allow
= true)
437 { m_overflow
= allow
? Overflow
: SingleCell
; }
438 void SetReadOnly(bool isReadOnly
= true)
439 { m_isReadOnly
= isReadOnly
? ReadOnly
: ReadWrite
; }
441 // takes ownership of the pointer
442 void SetRenderer(wxGridCellRenderer
*renderer
)
443 { wxSafeDecRef(m_renderer
); m_renderer
= renderer
; }
444 void SetEditor(wxGridCellEditor
* editor
)
445 { wxSafeDecRef(m_editor
); m_editor
= editor
; }
447 void SetKind(wxAttrKind kind
) { m_attrkind
= kind
; }
450 bool HasTextColour() const { return m_colText
.IsOk(); }
451 bool HasBackgroundColour() const { return m_colBack
.IsOk(); }
452 bool HasFont() const { return m_font
.IsOk(); }
453 bool HasAlignment() const
455 return m_hAlign
!= wxALIGN_INVALID
|| m_vAlign
!= wxALIGN_INVALID
;
457 bool HasRenderer() const { return m_renderer
!= NULL
; }
458 bool HasEditor() const { return m_editor
!= NULL
; }
459 bool HasReadWriteMode() const { return m_isReadOnly
!= Unset
; }
460 bool HasOverflowMode() const { return m_overflow
!= UnsetOverflow
; }
461 bool HasSize() const { return m_sizeRows
!= 1 || m_sizeCols
!= 1; }
463 const wxColour
& GetTextColour() const;
464 const wxColour
& GetBackgroundColour() const;
465 const wxFont
& GetFont() const;
466 void GetAlignment(int *hAlign
, int *vAlign
) const;
468 // unlike GetAlignment() which always overwrites its output arguments with
469 // the alignment values to use, falling back on default alignment if this
470 // attribute doesn't have any, this function will preserve the values of
471 // parameters on entry if the corresponding alignment is not set in this
472 // attribute meaning that they can be initialized to default alignment (and
473 // also that they must be initialized, unlike with GetAlignment())
474 void GetNonDefaultAlignment(int *hAlign
, int *vAlign
) const;
476 void GetSize(int *num_rows
, int *num_cols
) const;
477 bool GetOverflow() const
478 { return m_overflow
!= SingleCell
; }
479 wxGridCellRenderer
*GetRenderer(const wxGrid
* grid
, int row
, int col
) const;
480 wxGridCellEditor
*GetEditor(const wxGrid
* grid
, int row
, int col
) const;
482 bool IsReadOnly() const { return m_isReadOnly
== wxGridCellAttr::ReadOnly
; }
484 wxAttrKind
GetKind() { return m_attrkind
; }
486 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
489 // the dtor is private because only DecRef() can delete us
490 virtual ~wxGridCellAttr()
492 wxSafeDecRef(m_renderer
);
493 wxSafeDecRef(m_editor
);
504 enum wxAttrOverflowMode
511 // the common part of all ctors
512 void Init(wxGridCellAttr
*attrDefault
= NULL
);
523 wxAttrOverflowMode m_overflow
;
525 wxGridCellRenderer
* m_renderer
;
526 wxGridCellEditor
* m_editor
;
527 wxGridCellAttr
* m_defGridAttr
;
529 wxAttrReadMode m_isReadOnly
;
531 wxAttrKind m_attrkind
;
533 // use Clone() instead
534 wxDECLARE_NO_COPY_CLASS(wxGridCellAttr
);
536 // suppress the stupid gcc warning about the class having private dtor and
538 friend class wxGridCellAttrDummyFriend
;
541 // ----------------------------------------------------------------------------
542 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
544 // ----------------------------------------------------------------------------
546 // implementation note: we separate it from wxGridTableBase because we wish to
547 // avoid deriving a new table class if possible, and sometimes it will be
548 // enough to just derive another wxGridCellAttrProvider instead
550 // the default implementation is reasonably efficient for the generic case,
551 // but you might still wish to implement your own for some specific situations
552 // if you have performance problems with the stock one
553 class WXDLLIMPEXP_ADV wxGridCellAttrProvider
: public wxClientDataContainer
556 wxGridCellAttrProvider();
557 virtual ~wxGridCellAttrProvider();
559 // DecRef() must be called on the returned pointer
560 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
561 wxGridCellAttr::wxAttrKind kind
) const;
563 // all these functions take ownership of the pointer, don't call DecRef()
565 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
566 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
567 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
569 // these functions must be called whenever some rows/cols are deleted
570 // because the internal data must be updated then
571 void UpdateAttrRows( size_t pos
, int numRows
);
572 void UpdateAttrCols( size_t pos
, int numCols
);
575 // get renderers for the given row/column header label and the corner
576 // window: unlike cell renderers, these objects are not reference counted
577 // and are never NULL so they are returned by reference
578 virtual const wxGridColumnHeaderRenderer
& GetColumnHeaderRenderer(int col
);
579 virtual const wxGridRowHeaderRenderer
& GetRowHeaderRenderer(int row
);
580 virtual const wxGridCornerHeaderRenderer
& GetCornerRenderer();
585 wxGridCellAttrProviderData
*m_data
;
587 wxDECLARE_NO_COPY_CLASS(wxGridCellAttrProvider
);
590 // ----------------------------------------------------------------------------
591 // wxGridCellCoords: location of a cell in the grid
592 // ----------------------------------------------------------------------------
594 class WXDLLIMPEXP_ADV wxGridCellCoords
597 wxGridCellCoords() { m_row
= m_col
= -1; }
598 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
600 // default copy ctor is ok
602 int GetRow() const { return m_row
; }
603 void SetRow( int n
) { m_row
= n
; }
604 int GetCol() const { return m_col
; }
605 void SetCol( int n
) { m_col
= n
; }
606 void Set( int row
, int col
) { m_row
= row
; m_col
= col
; }
608 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
610 if ( &other
!= this )
618 bool operator==( const wxGridCellCoords
& other
) const
620 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
623 bool operator!=( const wxGridCellCoords
& other
) const
625 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
628 bool operator!() const
630 return (m_row
== -1 && m_col
== -1 );
639 // For comparisons...
641 extern WXDLLIMPEXP_ADV wxGridCellCoords wxGridNoCellCoords
;
642 extern WXDLLIMPEXP_ADV wxRect wxGridNoCellRect
;
644 // An array of cell coords...
646 WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords
, wxGridCellCoordsArray
,
647 class WXDLLIMPEXP_ADV
);
649 // ----------------------------------------------------------------------------
650 // Grid table classes
651 // ----------------------------------------------------------------------------
653 // the abstract base class
654 class WXDLLIMPEXP_ADV wxGridTableBase
: public wxObject
,
655 public wxClientDataContainer
659 virtual ~wxGridTableBase();
661 // You must override these functions in a derived table class
664 // return the number of rows and columns in this table
665 virtual int GetNumberRows() = 0;
666 virtual int GetNumberCols() = 0;
668 // the methods above are unfortunately non-const even though they should
669 // have been const -- but changing it now is not possible any longer as it
670 // would break the existing code overriding them, so instead we provide
671 // these const synonyms which can be used from const-correct code
672 int GetRowsCount() const
673 { return const_cast<wxGridTableBase
*>(this)->GetNumberRows(); }
674 int GetColsCount() const
675 { return const_cast<wxGridTableBase
*>(this)->GetNumberCols(); }
678 virtual bool IsEmptyCell( int row
, int col
)
680 return GetValue(row
, col
).empty();
683 bool IsEmpty(const wxGridCellCoords
& coord
)
685 return IsEmptyCell(coord
.GetRow(), coord
.GetCol());
688 virtual wxString
GetValue( int row
, int col
) = 0;
689 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
691 // Data type determination and value access
692 virtual wxString
GetTypeName( int row
, int col
);
693 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
694 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
696 virtual long GetValueAsLong( int row
, int col
);
697 virtual double GetValueAsDouble( int row
, int col
);
698 virtual bool GetValueAsBool( int row
, int col
);
700 virtual void SetValueAsLong( int row
, int col
, long value
);
701 virtual void SetValueAsDouble( int row
, int col
, double value
);
702 virtual void SetValueAsBool( int row
, int col
, bool value
);
704 // For user defined types
705 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
706 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
709 // Overriding these is optional
711 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
712 virtual wxGrid
* GetView() const { return m_view
; }
714 virtual void Clear() {}
715 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
716 virtual bool AppendRows( size_t numRows
= 1 );
717 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
718 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
719 virtual bool AppendCols( size_t numCols
= 1 );
720 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
722 virtual wxString
GetRowLabelValue( int row
);
723 virtual wxString
GetColLabelValue( int col
);
724 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
725 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
727 // Attribute handling
730 // give us the attr provider to use - we take ownership of the pointer
731 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
733 // get the currently used attr provider (may be NULL)
734 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
736 // Does this table allow attributes? Default implementation creates
737 // a wxGridCellAttrProvider if necessary.
738 virtual bool CanHaveAttributes();
740 // by default forwarded to wxGridCellAttrProvider if any. May be
741 // overridden to handle attributes directly in the table.
742 virtual wxGridCellAttr
*GetAttr( int row
, int col
,
743 wxGridCellAttr::wxAttrKind kind
);
746 // these functions take ownership of the pointer
747 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
748 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
749 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
753 wxGridCellAttrProvider
*m_attrProvider
;
755 DECLARE_ABSTRACT_CLASS(wxGridTableBase
)
756 wxDECLARE_NO_COPY_CLASS(wxGridTableBase
);
760 // ----------------------------------------------------------------------------
761 // wxGridTableMessage
762 // ----------------------------------------------------------------------------
764 // IDs for messages sent from grid table to view
766 enum wxGridTableRequest
768 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
769 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
770 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
771 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
772 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
773 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
774 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
775 wxGRIDTABLE_NOTIFY_COLS_DELETED
778 class WXDLLIMPEXP_ADV wxGridTableMessage
781 wxGridTableMessage();
782 wxGridTableMessage( wxGridTableBase
*table
, int id
,
786 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
787 wxGridTableBase
* GetTableObject() const { return m_table
; }
788 void SetId( int id
) { m_id
= id
; }
789 int GetId() { return m_id
; }
790 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
791 int GetCommandInt() { return m_comInt1
; }
792 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
793 int GetCommandInt2() { return m_comInt2
; }
796 wxGridTableBase
*m_table
;
801 wxDECLARE_NO_COPY_CLASS(wxGridTableMessage
);
806 // ------ wxGridStringArray
807 // A 2-dimensional array of strings for data values
810 WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString
, wxGridStringArray
,
811 class WXDLLIMPEXP_ADV
);
815 // ------ wxGridStringTable
817 // Simplest type of data table for a grid for small tables of strings
818 // that are stored in memory
821 class WXDLLIMPEXP_ADV wxGridStringTable
: public wxGridTableBase
825 wxGridStringTable( int numRows
, int numCols
);
827 // these are pure virtual in wxGridTableBase
829 virtual int GetNumberRows() { return static_cast<int>(m_data
.size()); }
830 virtual int GetNumberCols() { return m_numCols
; }
831 virtual wxString
GetValue( int row
, int col
);
832 virtual void SetValue( int row
, int col
, const wxString
& s
);
834 // overridden functions from wxGridTableBase
837 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
838 bool AppendRows( size_t numRows
= 1 );
839 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
840 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
841 bool AppendCols( size_t numCols
= 1 );
842 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
844 void SetRowLabelValue( int row
, const wxString
& );
845 void SetColLabelValue( int col
, const wxString
& );
846 wxString
GetRowLabelValue( int row
);
847 wxString
GetColLabelValue( int col
);
850 wxGridStringArray m_data
;
852 // notice that while we don't need to store the number of our rows as it's
853 // always equal to the size of m_data array, we do need to store the number
854 // of our columns as we can't retrieve it from m_data when the number of
855 // rows is 0 (see #10818)
858 // These only get used if you set your own labels, otherwise the
859 // GetRow/ColLabelValue functions return wxGridTableBase defaults
861 wxArrayString m_rowLabels
;
862 wxArrayString m_colLabels
;
864 DECLARE_DYNAMIC_CLASS_NO_COPY( wxGridStringTable
)
869 // ============================================================================
871 // ============================================================================
873 // ----------------------------------------------------------------------------
874 // wxGridSizesInfo stores information about sizes of the rows or columns.
876 // It assumes that most of the columns or rows have default size and so stores
877 // the default size separately and uses a hash to map column or row numbers to
878 // their non default size for those which don't have the default size.
879 // ----------------------------------------------------------------------------
881 // hash map to store positions as the keys and sizes as the values
882 WX_DECLARE_HASH_MAP_WITH_DECL( unsigned, int, wxIntegerHash
, wxIntegerEqual
,
883 wxUnsignedToIntHashMap
, class WXDLLIMPEXP_ADV
);
885 struct WXDLLIMPEXP_ADV wxGridSizesInfo
887 // default ctor, initialize m_sizeDefault and m_customSizes later
888 wxGridSizesInfo() { }
890 // ctor used by wxGrid::Get{Col,Row}Sizes()
891 wxGridSizesInfo(int defSize
, const wxArrayInt
& allSizes
);
893 // default copy ctor, assignment operator and dtor are ok
895 // Get the size of the element with the given index
896 int GetSize(unsigned pos
) const;
902 // position -> size map containing all elements with non-default size
903 wxUnsignedToIntHashMap m_customSizes
;
906 // ----------------------------------------------------------------------------
908 // ----------------------------------------------------------------------------
910 class WXDLLIMPEXP_ADV wxGrid
: public wxScrolledWindow
913 // possible selection modes
914 enum wxGridSelectionModes
916 wxGridSelectCells
= 0, // allow selecting anything
917 wxGridSelectRows
= 1, // allow selecting only entire rows
918 wxGridSelectColumns
= 2, // allow selecting only entire columns
919 wxGridSelectRowsOrColumns
= wxGridSelectRows
| wxGridSelectColumns
922 // Different behaviour of the TAB key when the end (or the beginning, for
923 // Shift-TAB) of the current row is reached:
926 Tab_Stop
, // Do nothing, this is default.
927 Tab_Wrap
, // Move to the next (or previous) row.
928 Tab_Leave
// Move to the next (or previous) control.
931 // creation and destruction
932 // ------------------------
934 // ctor and Create() create the grid window, as with the other controls
937 wxGrid(wxWindow
*parent
,
939 const wxPoint
& pos
= wxDefaultPosition
,
940 const wxSize
& size
= wxDefaultSize
,
941 long style
= wxWANTS_CHARS
,
942 const wxString
& name
= wxGridNameStr
)
946 Create(parent
, id
, pos
, size
, style
, name
);
949 bool Create(wxWindow
*parent
,
951 const wxPoint
& pos
= wxDefaultPosition
,
952 const wxSize
& size
= wxDefaultSize
,
953 long style
= wxWANTS_CHARS
,
954 const wxString
& name
= wxGridNameStr
);
958 // however to initialize grid data either CreateGrid() or SetTable() must
961 // this is basically equivalent to
963 // SetTable(new wxGridStringTable(numRows, numCols), true, selmode)
965 bool CreateGrid( int numRows
, int numCols
,
966 wxGridSelectionModes selmode
= wxGridSelectCells
);
968 bool SetTable( wxGridTableBase
*table
,
969 bool takeOwnership
= false,
970 wxGridSelectionModes selmode
= wxGridSelectCells
);
972 bool ProcessTableMessage(wxGridTableMessage
&);
974 wxGridTableBase
*GetTable() const { return m_table
; }
977 void SetSelectionMode(wxGridSelectionModes selmode
);
978 wxGridSelectionModes
GetSelectionMode() const;
980 // ------ grid dimensions
982 int GetNumberRows() const { return m_numRows
; }
983 int GetNumberCols() const { return m_numCols
; }
986 // ------ display update functions
988 wxArrayInt
CalcRowLabelsExposed( const wxRegion
& reg
) const;
990 wxArrayInt
CalcColLabelsExposed( const wxRegion
& reg
) const;
991 wxGridCellCoordsArray
CalcCellsExposed( const wxRegion
& reg
) const;
995 bool InsertRows(int pos
= 0, int numRows
= 1, bool updateLabels
= true)
997 return DoModifyLines(&wxGridTableBase::InsertRows
,
998 pos
, numRows
, updateLabels
);
1000 bool InsertCols(int pos
= 0, int numCols
= 1, bool updateLabels
= true)
1002 return DoModifyLines(&wxGridTableBase::InsertCols
,
1003 pos
, numCols
, updateLabels
);
1006 bool AppendRows(int numRows
= 1, bool updateLabels
= true)
1008 return DoAppendLines(&wxGridTableBase::AppendRows
, numRows
, updateLabels
);
1010 bool AppendCols(int numCols
= 1, bool updateLabels
= true)
1012 return DoAppendLines(&wxGridTableBase::AppendCols
, numCols
, updateLabels
);
1015 bool DeleteRows(int pos
= 0, int numRows
= 1, bool updateLabels
= true)
1017 return DoModifyLines(&wxGridTableBase::DeleteRows
,
1018 pos
, numRows
, updateLabels
);
1020 bool DeleteCols(int pos
= 0, int numCols
= 1, bool updateLabels
= true)
1022 return DoModifyLines(&wxGridTableBase::DeleteCols
,
1023 pos
, numCols
, updateLabels
);
1026 void DrawGridCellArea( wxDC
& dc
, const wxGridCellCoordsArray
& cells
);
1027 void DrawGridSpace( wxDC
& dc
);
1028 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
1029 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
1030 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
1031 void DrawHighlight(wxDC
& dc
, const wxGridCellCoordsArray
& cells
);
1033 // this function is called when the current cell highlight must be redrawn
1034 // and may be overridden by the user
1035 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
1037 virtual void DrawRowLabels( wxDC
& dc
, const wxArrayInt
& rows
);
1038 virtual void DrawRowLabel( wxDC
& dc
, int row
);
1040 virtual void DrawColLabels( wxDC
& dc
, const wxArrayInt
& cols
);
1041 virtual void DrawColLabel( wxDC
& dc
, int col
);
1043 virtual void DrawCornerLabel(wxDC
& dc
);
1045 // ------ Cell text drawing functions
1047 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
1048 int horizontalAlignment
= wxALIGN_LEFT
,
1049 int verticalAlignment
= wxALIGN_TOP
,
1050 int textOrientation
= wxHORIZONTAL
) const;
1052 void DrawTextRectangle( wxDC
& dc
, const wxArrayString
& lines
, const wxRect
&,
1053 int horizontalAlignment
= wxALIGN_LEFT
,
1054 int verticalAlignment
= wxALIGN_TOP
,
1055 int textOrientation
= wxHORIZONTAL
) const;
1057 // ------ grid render function for printing
1059 void Render( wxDC
& dc
,
1060 const wxPoint
& pos
= wxDefaultPosition
,
1061 const wxSize
& size
= wxDefaultSize
,
1062 const wxGridCellCoords
& topLeft
= wxGridCellCoords(-1, -1),
1063 const wxGridCellCoords
& bottomRight
= wxGridCellCoords(-1, -1),
1064 int style
= wxGRID_DRAW_DEFAULT
);
1066 // Split a string containing newline characters into an array of
1067 // strings and return the number of lines
1069 void StringToLines( const wxString
& value
, wxArrayString
& lines
) const;
1071 void GetTextBoxSize( const wxDC
& dc
,
1072 const wxArrayString
& lines
,
1073 long *width
, long *height
) const;
1077 // Code that does a lot of grid modification can be enclosed
1078 // between BeginBatch() and EndBatch() calls to avoid screen
1081 void BeginBatch() { m_batchCount
++; }
1084 int GetBatchCount() { return m_batchCount
; }
1086 virtual void Refresh(bool eraseb
= true, const wxRect
* rect
= NULL
);
1088 // Use this, rather than wxWindow::Refresh(), to force an
1089 // immediate repainting of the grid. Has no effect if you are
1090 // already inside a BeginBatch / EndBatch block.
1092 // This function is necessary because wxGrid has a minimal OnPaint()
1093 // handler to reduce screen flicker.
1095 void ForceRefresh();
1098 // ------ edit control functions
1100 bool IsEditable() const { return m_editable
; }
1101 void EnableEditing( bool edit
);
1103 void EnableCellEditControl( bool enable
= true );
1104 void DisableCellEditControl() { EnableCellEditControl(false); }
1105 bool CanEnableCellControl() const;
1106 bool IsCellEditControlEnabled() const;
1107 bool IsCellEditControlShown() const;
1109 bool IsCurrentCellReadOnly() const;
1111 void ShowCellEditControl();
1112 void HideCellEditControl();
1113 void SaveEditControlValue();
1116 // ------ grid location functions
1117 // Note that all of these functions work with the logical coordinates of
1118 // grid cells and labels so you will need to convert from device
1119 // coordinates for mouse events etc.
1121 wxGridCellCoords
XYToCell(int x
, int y
) const;
1122 void XYToCell(int x
, int y
, wxGridCellCoords
& coords
) const
1123 { coords
= XYToCell(x
, y
); }
1124 wxGridCellCoords
XYToCell(const wxPoint
& pos
) const
1125 { return XYToCell(pos
.x
, pos
.y
); }
1127 // these functions return the index of the row/columns corresponding to the
1128 // given logical position in pixels
1130 // if clipToMinMax is false (default, wxNOT_FOUND is returned if the
1131 // position is outside any row/column, otherwise the first/last element is
1132 // returned in this case
1133 int YToRow( int y
, bool clipToMinMax
= false ) const;
1134 int XToCol( int x
, bool clipToMinMax
= false ) const;
1136 int YToEdgeOfRow( int y
) const;
1137 int XToEdgeOfCol( int x
) const;
1139 wxRect
CellToRect( int row
, int col
) const;
1140 wxRect
CellToRect( const wxGridCellCoords
& coords
) const
1141 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
1143 int GetGridCursorRow() const { return m_currentCellCoords
.GetRow(); }
1144 int GetGridCursorCol() const { return m_currentCellCoords
.GetCol(); }
1146 // check to see if a cell is either wholly visible (the default arg) or
1147 // at least partially visible in the grid window
1149 bool IsVisible( int row
, int col
, bool wholeCellVisible
= true ) const;
1150 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= true ) const
1151 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
1152 void MakeCellVisible( int row
, int col
);
1153 void MakeCellVisible( const wxGridCellCoords
& coords
)
1154 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
1157 // ------ grid cursor movement functions
1159 void SetGridCursor(int row
, int col
) { SetCurrentCell(row
, col
); }
1160 void SetGridCursor(const wxGridCellCoords
& c
) { SetCurrentCell(c
); }
1162 void GoToCell(int row
, int col
)
1164 if ( SetCurrentCell(row
, col
) )
1165 MakeCellVisible(row
, col
);
1168 void GoToCell(const wxGridCellCoords
& coords
)
1170 if ( SetCurrentCell(coords
) )
1171 MakeCellVisible(coords
);
1174 bool MoveCursorUp( bool expandSelection
);
1175 bool MoveCursorDown( bool expandSelection
);
1176 bool MoveCursorLeft( bool expandSelection
);
1177 bool MoveCursorRight( bool expandSelection
);
1178 bool MovePageDown();
1180 bool MoveCursorUpBlock( bool expandSelection
);
1181 bool MoveCursorDownBlock( bool expandSelection
);
1182 bool MoveCursorLeftBlock( bool expandSelection
);
1183 bool MoveCursorRightBlock( bool expandSelection
);
1185 void SetTabBehaviour(TabBehaviour behaviour
) { m_tabBehaviour
= behaviour
; }
1188 // ------ label and gridline formatting
1190 int GetDefaultRowLabelSize() const { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
1191 int GetRowLabelSize() const { return m_rowLabelWidth
; }
1192 int GetDefaultColLabelSize() const { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
1193 int GetColLabelSize() const { return m_colLabelHeight
; }
1194 wxColour
GetLabelBackgroundColour() const { return m_labelBackgroundColour
; }
1195 wxColour
GetLabelTextColour() const { return m_labelTextColour
; }
1196 wxFont
GetLabelFont() const { return m_labelFont
; }
1197 void GetRowLabelAlignment( int *horiz
, int *vert
) const;
1198 void GetColLabelAlignment( int *horiz
, int *vert
) const;
1199 int GetColLabelTextOrientation() const;
1200 wxString
GetRowLabelValue( int row
) const;
1201 wxString
GetColLabelValue( int col
) const;
1203 wxColour
GetCellHighlightColour() const { return m_cellHighlightColour
; }
1204 int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth
; }
1205 int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth
; }
1207 // this one will use wxHeaderCtrl for the column labels
1208 void UseNativeColHeader(bool native
= true);
1210 // this one will still draw them manually but using the native renderer
1211 // instead of using the same appearance as for the row labels
1212 void SetUseNativeColLabels( bool native
= true );
1214 void SetRowLabelSize( int width
);
1215 void SetColLabelSize( int height
);
1216 void HideRowLabels() { SetRowLabelSize( 0 ); }
1217 void HideColLabels() { SetColLabelSize( 0 ); }
1218 void SetLabelBackgroundColour( const wxColour
& );
1219 void SetLabelTextColour( const wxColour
& );
1220 void SetLabelFont( const wxFont
& );
1221 void SetRowLabelAlignment( int horiz
, int vert
);
1222 void SetColLabelAlignment( int horiz
, int vert
);
1223 void SetColLabelTextOrientation( int textOrientation
);
1224 void SetRowLabelValue( int row
, const wxString
& );
1225 void SetColLabelValue( int col
, const wxString
& );
1226 void SetCellHighlightColour( const wxColour
& );
1227 void SetCellHighlightPenWidth(int width
);
1228 void SetCellHighlightROPenWidth(int width
);
1231 // interactive grid mouse operations control
1232 // -----------------------------------------
1234 // functions globally enabling row/column interactive resizing (enabled by
1236 void EnableDragRowSize( bool enable
= true );
1237 void DisableDragRowSize() { EnableDragRowSize( false ); }
1239 void EnableDragColSize( bool enable
= true );
1240 void DisableDragColSize() { EnableDragColSize( false ); }
1242 // if interactive resizing is enabled, some rows/columns can still have
1244 void DisableRowResize(int row
) { DoDisableLineResize(row
, m_setFixedRows
); }
1245 void DisableColResize(int col
) { DoDisableLineResize(col
, m_setFixedCols
); }
1247 // these functions return whether the given row/column can be
1248 // effectively resized: for this interactive resizing must be enabled
1249 // and this index must not have been passed to DisableRow/ColResize()
1250 bool CanDragRowSize(int row
) const
1251 { return m_canDragRowSize
&& DoCanResizeLine(row
, m_setFixedRows
); }
1252 bool CanDragColSize(int col
) const
1253 { return m_canDragColSize
&& DoCanResizeLine(col
, m_setFixedCols
); }
1255 // interactive column reordering (disabled by default)
1256 void EnableDragColMove( bool enable
= true );
1257 void DisableDragColMove() { EnableDragColMove( false ); }
1258 bool CanDragColMove() const { return m_canDragColMove
; }
1260 // interactive resizing of grid cells (enabled by default)
1261 void EnableDragGridSize(bool enable
= true);
1262 void DisableDragGridSize() { EnableDragGridSize(false); }
1263 bool CanDragGridSize() const { return m_canDragGridSize
; }
1265 // interactive dragging of cells (disabled by default)
1266 void EnableDragCell( bool enable
= true );
1267 void DisableDragCell() { EnableDragCell( false ); }
1268 bool CanDragCell() const { return m_canDragCell
; }
1274 // enable or disable drawing of the lines
1275 void EnableGridLines(bool enable
= true);
1276 bool GridLinesEnabled() const { return m_gridLinesEnabled
; }
1278 // by default grid lines stop at last column/row, but this may be changed
1279 void ClipHorzGridLines(bool clip
)
1280 { DoClipGridLines(m_gridLinesClipHorz
, clip
); }
1281 void ClipVertGridLines(bool clip
)
1282 { DoClipGridLines(m_gridLinesClipVert
, clip
); }
1283 bool AreHorzGridLinesClipped() const { return m_gridLinesClipHorz
; }
1284 bool AreVertGridLinesClipped() const { return m_gridLinesClipVert
; }
1286 // this can be used to change the global grid lines colour
1287 void SetGridLineColour(const wxColour
& col
);
1288 wxColour
GetGridLineColour() const { return m_gridLineColour
; }
1290 // these methods may be overridden to customize individual grid lines
1292 virtual wxPen
GetDefaultGridLinePen();
1293 virtual wxPen
GetRowGridLinePen(int row
);
1294 virtual wxPen
GetColGridLinePen(int col
);
1300 // this sets the specified attribute for this cell or in this row/col
1301 void SetAttr(int row
, int col
, wxGridCellAttr
*attr
);
1302 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
1303 void SetColAttr(int col
, wxGridCellAttr
*attr
);
1305 // the grid can cache attributes for the recently used cells (currently it
1306 // only caches one attribute for the most recently used one) and might
1307 // notice that its value in the attribute provider has changed -- if this
1308 // happens, call this function to force it
1309 void RefreshAttr(int row
, int col
);
1311 // returns the attribute we may modify in place: a new one if this cell
1312 // doesn't have any yet or the existing one if it does
1314 // DecRef() must be called on the returned pointer, as usual
1315 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1318 // shortcuts for setting the column parameters
1320 // set the format for the data in the column: default is string
1321 void SetColFormatBool(int col
);
1322 void SetColFormatNumber(int col
);
1323 void SetColFormatFloat(int col
, int width
= -1, int precision
= -1);
1324 void SetColFormatCustom(int col
, const wxString
& typeName
);
1326 // ------ row and col formatting
1328 int GetDefaultRowSize() const;
1329 int GetRowSize( int row
) const;
1330 bool IsRowShown(int row
) const { return GetRowSize(row
) != 0; }
1331 int GetDefaultColSize() const;
1332 int GetColSize( int col
) const;
1333 bool IsColShown(int col
) const { return GetColSize(col
) != 0; }
1334 wxColour
GetDefaultCellBackgroundColour() const;
1335 wxColour
GetCellBackgroundColour( int row
, int col
) const;
1336 wxColour
GetDefaultCellTextColour() const;
1337 wxColour
GetCellTextColour( int row
, int col
) const;
1338 wxFont
GetDefaultCellFont() const;
1339 wxFont
GetCellFont( int row
, int col
) const;
1340 void GetDefaultCellAlignment( int *horiz
, int *vert
) const;
1341 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
) const;
1342 bool GetDefaultCellOverflow() const;
1343 bool GetCellOverflow( int row
, int col
) const;
1345 // this function returns 1 in num_rows and num_cols for normal cells,
1346 // positive numbers for a cell spanning multiple columns/rows (as set with
1347 // SetCellSize()) and _negative_ numbers corresponding to the offset of the
1348 // top left cell of the span from this one for the other cells covered by
1351 // the return value is CellSpan_None, CellSpan_Main or CellSpan_Inside for
1352 // each of these cases respectively
1355 CellSpan_Inside
= -1,
1360 CellSpan
GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
) const;
1362 wxSize
GetCellSize(const wxGridCellCoords
& coords
)
1365 GetCellSize(coords
.GetRow(), coords
.GetCol(), &s
.x
, &s
.y
);
1369 // ------ row and col sizes
1370 void SetDefaultRowSize( int height
, bool resizeExistingRows
= false );
1371 void SetRowSize( int row
, int height
);
1372 void HideRow(int row
) { DoSetRowSize(row
, 0); }
1373 void ShowRow(int row
) { DoSetRowSize(row
, -1); }
1375 void SetDefaultColSize( int width
, bool resizeExistingCols
= false );
1376 void SetColSize( int col
, int width
);
1377 void HideCol(int col
) { DoSetColSize(col
, 0); }
1378 void ShowCol(int col
) { DoSetColSize(col
, -1); }
1380 // the row and column sizes can be also set all at once using
1381 // wxGridSizesInfo which holds all of them at once
1383 wxGridSizesInfo
GetColSizes() const
1384 { return wxGridSizesInfo(GetDefaultColSize(), m_colWidths
); }
1385 wxGridSizesInfo
GetRowSizes() const
1386 { return wxGridSizesInfo(GetDefaultRowSize(), m_rowHeights
); }
1388 void SetColSizes(const wxGridSizesInfo
& sizeInfo
);
1389 void SetRowSizes(const wxGridSizesInfo
& sizeInfo
);
1392 // ------- columns (only, for now) reordering
1394 // columns index <-> positions mapping: by default, the position of the
1395 // column is the same as its index, but the columns can also be reordered
1396 // (either by calling SetColPos() explicitly or by the user dragging the
1397 // columns around) in which case their indices don't correspond to their
1398 // positions on display any longer
1400 // internally we always work with indices except for the functions which
1401 // have "Pos" in their names (and which work with columns, not pixels) and
1402 // only the display and hit testing code really cares about display
1405 // set the positions of all columns at once (this method uses the same
1406 // conventions as wxHeaderCtrl::SetColumnsOrder() for the order array)
1407 void SetColumnsOrder(const wxArrayInt
& order
);
1409 // return the column index corresponding to the given (valid) position
1410 int GetColAt(int pos
) const
1412 return m_colAt
.empty() ? pos
: m_colAt
[pos
];
1415 // reorder the columns so that the column with the given index is now shown
1416 // as the position pos
1417 void SetColPos(int idx
, int pos
);
1419 // return the position at which the column with the given index is
1420 // displayed: notice that this is a slow operation as we don't maintain the
1421 // reverse mapping currently
1422 int GetColPos(int idx
) const
1424 if ( m_colAt
.IsEmpty() )
1427 for ( int i
= 0; i
< m_numCols
; i
++ )
1429 if ( m_colAt
[i
] == idx
)
1433 wxFAIL_MSG( "invalid column index" );
1438 // reset the columns positions to the default order
1442 // automatically size the column or row to fit to its contents, if
1443 // setAsMin is true, this optimal width will also be set as minimal width
1445 void AutoSizeColumn( int col
, bool setAsMin
= true )
1446 { AutoSizeColOrRow(col
, setAsMin
, wxGRID_COLUMN
); }
1447 void AutoSizeRow( int row
, bool setAsMin
= true )
1448 { AutoSizeColOrRow(row
, setAsMin
, wxGRID_ROW
); }
1450 // auto size all columns (very ineffective for big grids!)
1451 void AutoSizeColumns( bool setAsMin
= true )
1452 { (void)SetOrCalcColumnSizes(false, setAsMin
); }
1454 void AutoSizeRows( bool setAsMin
= true )
1455 { (void)SetOrCalcRowSizes(false, setAsMin
); }
1457 // auto size the grid, that is make the columns/rows of the "right" size
1458 // and also set the grid size to just fit its contents
1461 // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize:
1462 // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column
1463 // instead of data column. Note that this operation may be slow for large
1465 // autosize row height depending on label text
1466 void AutoSizeRowLabelSize( int row
);
1468 // autosize column width depending on label text
1469 void AutoSizeColLabelSize( int col
);
1471 // column won't be resized to be lesser width - this must be called during
1472 // the grid creation because it won't resize the column if it's already
1473 // narrower than the minimal width
1474 void SetColMinimalWidth( int col
, int width
);
1475 void SetRowMinimalHeight( int row
, int width
);
1477 /* These members can be used to query and modify the minimal
1478 * acceptable size of grid rows and columns. Call this function in
1479 * your code which creates the grid if you want to display cells
1480 * with a size smaller than the default acceptable minimum size.
1481 * Like the members SetColMinimalWidth and SetRowMinimalWidth,
1482 * the existing rows or columns will not be checked/resized.
1484 void SetColMinimalAcceptableWidth( int width
);
1485 void SetRowMinimalAcceptableHeight( int width
);
1486 int GetColMinimalAcceptableWidth() const;
1487 int GetRowMinimalAcceptableHeight() const;
1489 void SetDefaultCellBackgroundColour( const wxColour
& );
1490 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1491 void SetDefaultCellTextColour( const wxColour
& );
1493 void SetCellTextColour( int row
, int col
, const wxColour
& );
1494 void SetDefaultCellFont( const wxFont
& );
1495 void SetCellFont( int row
, int col
, const wxFont
& );
1496 void SetDefaultCellAlignment( int horiz
, int vert
);
1497 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1498 void SetDefaultCellOverflow( bool allow
);
1499 void SetCellOverflow( int row
, int col
, bool allow
);
1500 void SetCellSize( int row
, int col
, int num_rows
, int num_cols
);
1502 // takes ownership of the pointer
1503 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1504 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1505 wxGridCellRenderer
*GetDefaultRenderer() const;
1506 wxGridCellRenderer
* GetCellRenderer(int row
, int col
) const;
1508 // takes ownership of the pointer
1509 void SetDefaultEditor(wxGridCellEditor
*editor
);
1510 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1511 wxGridCellEditor
*GetDefaultEditor() const;
1512 wxGridCellEditor
* GetCellEditor(int row
, int col
) const;
1516 // ------ cell value accessors
1518 wxString
GetCellValue( int row
, int col
) const
1522 return m_table
->GetValue( row
, col
);
1526 return wxEmptyString
;
1530 wxString
GetCellValue( const wxGridCellCoords
& coords
) const
1531 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1533 void SetCellValue( int row
, int col
, const wxString
& s
);
1534 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1535 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1537 // returns true if the cell can't be edited
1538 bool IsReadOnly(int row
, int col
) const;
1540 // make the cell editable/readonly
1541 void SetReadOnly(int row
, int col
, bool isReadOnly
= true);
1543 // ------ select blocks of cells
1545 void SelectRow( int row
, bool addToSelected
= false );
1546 void SelectCol( int col
, bool addToSelected
= false );
1548 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
1549 bool addToSelected
= false );
1551 void SelectBlock( const wxGridCellCoords
& topLeft
,
1552 const wxGridCellCoords
& bottomRight
,
1553 bool addToSelected
= false )
1554 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1555 bottomRight
.GetRow(), bottomRight
.GetCol(),
1560 bool IsSelection() const;
1562 // ------ deselect blocks or cells
1564 void DeselectRow( int row
);
1565 void DeselectCol( int col
);
1566 void DeselectCell( int row
, int col
);
1568 void ClearSelection();
1570 bool IsInSelection( int row
, int col
) const;
1572 bool IsInSelection( const wxGridCellCoords
& coords
) const
1573 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1575 wxGridCellCoordsArray
GetSelectedCells() const;
1576 wxGridCellCoordsArray
GetSelectionBlockTopLeft() const;
1577 wxGridCellCoordsArray
GetSelectionBlockBottomRight() const;
1578 wxArrayInt
GetSelectedRows() const;
1579 wxArrayInt
GetSelectedCols() const;
1581 // This function returns the rectangle that encloses the block of cells
1582 // limited by TopLeft and BottomRight cell in device coords and clipped
1583 // to the client size of the grid window.
1585 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1586 const wxGridCellCoords
& bottomRight
) const;
1588 // Access or update the selection fore/back colours
1589 wxColour
GetSelectionBackground() const
1590 { return m_selectionBackground
; }
1591 wxColour
GetSelectionForeground() const
1592 { return m_selectionForeground
; }
1594 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1595 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1598 // Methods for a registry for mapping data types to Renderers/Editors
1599 void RegisterDataType(const wxString
& typeName
,
1600 wxGridCellRenderer
* renderer
,
1601 wxGridCellEditor
* editor
);
1603 virtual wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1604 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1605 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1606 virtual wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1607 virtual wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1608 virtual wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1610 // grid may occupy more space than needed for its rows/columns, this
1611 // function allows to set how big this extra space is
1612 void SetMargins(int extraWidth
, int extraHeight
)
1614 m_extraWidth
= extraWidth
;
1615 m_extraHeight
= extraHeight
;
1620 // Accessors for component windows
1621 wxWindow
* GetGridWindow() const { return (wxWindow
*)m_gridWin
; }
1622 wxWindow
* GetGridRowLabelWindow() const { return (wxWindow
*)m_rowLabelWin
; }
1623 wxWindow
* GetGridColLabelWindow() const { return m_colWindow
; }
1624 wxWindow
* GetGridCornerLabelWindow() const { return (wxWindow
*)m_cornerLabelWin
; }
1626 // This one can only be called if we are using the native header window
1627 wxHeaderCtrl
*GetGridColHeader() const
1629 wxASSERT_MSG( m_useNativeHeader
, "no column header window" );
1631 // static_cast<> doesn't work without the full class declaration in
1632 // view and we prefer to avoid adding more compile-time dependencies
1633 // even at the cost of using reinterpret_cast<>
1634 return reinterpret_cast<wxHeaderCtrl
*>(m_colWindow
);
1637 // Allow adjustment of scroll increment. The default is (15, 15).
1638 void SetScrollLineX(int x
) { m_xScrollPixelsPerLine
= x
; }
1639 void SetScrollLineY(int y
) { m_yScrollPixelsPerLine
= y
; }
1640 int GetScrollLineX() const { return m_xScrollPixelsPerLine
; }
1641 int GetScrollLineY() const { return m_yScrollPixelsPerLine
; }
1643 // ------- drag and drop
1644 #if wxUSE_DRAG_AND_DROP
1645 virtual void SetDropTarget(wxDropTarget
*dropTarget
);
1646 #endif // wxUSE_DRAG_AND_DROP
1649 // ------- sorting support
1651 // wxGrid doesn't support sorting on its own but it can indicate the sort
1652 // order in the column header (currently only if native header control is
1655 // return the column currently displaying the sort indicator or wxNOT_FOUND
1657 int GetSortingColumn() const { return m_sortCol
; }
1659 // return true if this column is currently used for sorting
1660 bool IsSortingBy(int col
) const { return GetSortingColumn() == col
; }
1662 // return the current sorting order (on GetSortingColumn()): true for
1663 // ascending sort and false for descending; it doesn't make sense to call
1664 // it if GetSortingColumn() returns wxNOT_FOUND
1665 bool IsSortOrderAscending() const { return m_sortIsAscending
; }
1667 // set the sorting column (or unsets any existing one if wxNOT_FOUND) and
1668 // the order in which to sort
1669 void SetSortingColumn(int col
, bool ascending
= true);
1671 // unset any existing sorting column
1672 void UnsetSortingColumn() { SetSortingColumn(wxNOT_FOUND
); }
1674 #if WXWIN_COMPATIBILITY_2_8
1675 // ------ For compatibility with previous wxGrid only...
1677 // ************************************************
1678 // ** Don't use these in new code because they **
1679 // ** are liable to disappear in a future **
1681 // ************************************************
1684 wxGrid( wxWindow
*parent
,
1685 int x
, int y
, int w
= wxDefaultCoord
, int h
= wxDefaultCoord
,
1686 long style
= wxWANTS_CHARS
,
1687 const wxString
& name
= wxPanelNameStr
)
1690 Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(w
, h
), style
, name
);
1693 void SetCellValue( const wxString
& val
, int row
, int col
)
1694 { SetCellValue( row
, col
, val
); }
1696 void UpdateDimensions()
1697 { CalcDimensions(); }
1699 int GetRows() const { return GetNumberRows(); }
1700 int GetCols() const { return GetNumberCols(); }
1701 int GetCursorRow() const { return GetGridCursorRow(); }
1702 int GetCursorColumn() const { return GetGridCursorCol(); }
1704 int GetScrollPosX() const { return 0; }
1705 int GetScrollPosY() const { return 0; }
1707 void SetScrollX( int WXUNUSED(x
) ) { }
1708 void SetScrollY( int WXUNUSED(y
) ) { }
1710 void SetColumnWidth( int col
, int width
)
1711 { SetColSize( col
, width
); }
1713 int GetColumnWidth( int col
) const
1714 { return GetColSize( col
); }
1716 void SetRowHeight( int row
, int height
)
1717 { SetRowSize( row
, height
); }
1719 // GetRowHeight() is below
1721 int GetViewHeight() const // returned num whole rows visible
1724 int GetViewWidth() const // returned num whole cols visible
1727 void SetLabelSize( int orientation
, int sz
)
1729 if ( orientation
== wxHORIZONTAL
)
1730 SetColLabelSize( sz
);
1732 SetRowLabelSize( sz
);
1735 int GetLabelSize( int orientation
) const
1737 if ( orientation
== wxHORIZONTAL
)
1738 return GetColLabelSize();
1740 return GetRowLabelSize();
1743 void SetLabelAlignment( int orientation
, int align
)
1745 if ( orientation
== wxHORIZONTAL
)
1746 SetColLabelAlignment( align
, wxALIGN_INVALID
);
1748 SetRowLabelAlignment( align
, wxALIGN_INVALID
);
1751 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) ) const
1754 if ( orientation
== wxHORIZONTAL
)
1756 GetColLabelAlignment( &h
, &v
);
1761 GetRowLabelAlignment( &h
, &v
);
1766 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1768 if ( orientation
== wxHORIZONTAL
)
1769 SetColLabelValue( pos
, val
);
1771 SetRowLabelValue( pos
, val
);
1774 wxString
GetLabelValue( int orientation
, int pos
) const
1776 if ( orientation
== wxHORIZONTAL
)
1777 return GetColLabelValue( pos
);
1779 return GetRowLabelValue( pos
);
1782 wxFont
GetCellTextFont() const
1783 { return m_defaultCellAttr
->GetFont(); }
1785 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1786 { return m_defaultCellAttr
->GetFont(); }
1788 void SetCellTextFont(const wxFont
& fnt
)
1789 { SetDefaultCellFont( fnt
); }
1791 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1792 { SetCellFont( row
, col
, fnt
); }
1794 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1795 { SetCellTextColour( row
, col
, val
); }
1797 void SetCellTextColour(const wxColour
& col
)
1798 { SetDefaultCellTextColour( col
); }
1800 void SetCellBackgroundColour(const wxColour
& col
)
1801 { SetDefaultCellBackgroundColour( col
); }
1803 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1804 { SetCellBackgroundColour( row
, col
, colour
); }
1806 bool GetEditable() const { return IsEditable(); }
1807 void SetEditable( bool edit
= true ) { EnableEditing( edit
); }
1808 bool GetEditInPlace() const { return IsCellEditControlEnabled(); }
1810 void SetEditInPlace(bool WXUNUSED(edit
) = true) { }
1812 void SetCellAlignment( int align
, int row
, int col
)
1813 { SetCellAlignment(row
, col
, align
, wxALIGN_CENTER
); }
1814 void SetCellAlignment( int WXUNUSED(align
) ) {}
1815 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1817 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1818 wxPen
& GetDividerPen() const;
1819 void OnActivate(bool WXUNUSED(active
)) {}
1821 // ******** End of compatibility functions **********
1825 // ------ control IDs
1826 enum { wxGRID_CELLCTRL
= 2000,
1829 // ------ control types
1830 enum { wxGRID_TEXTCTRL
= 2100,
1835 wxDEPRECATED_INLINE(bool CanDragRowSize() const, return m_canDragRowSize
; )
1836 wxDEPRECATED_INLINE(bool CanDragColSize() const, return m_canDragColSize
; )
1837 #endif // WXWIN_COMPATIBILITY_2_8
1840 // override some base class functions
1841 virtual bool Enable(bool enable
= true);
1842 virtual wxWindow
*GetMainWindowOfCompositeControl()
1843 { return (wxWindow
*)m_gridWin
; }
1846 // implementation only
1847 void CancelMouseCapture();
1850 virtual wxSize
DoGetBestSize() const;
1854 wxGridWindow
*m_gridWin
;
1855 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1856 wxGridRowLabelWindow
*m_rowLabelWin
;
1858 // the real type of the column window depends on m_useNativeHeader value:
1859 // if it is true, its dynamic type is wxHeaderCtrl, otherwise it is
1860 // wxGridColLabelWindow, use accessors below when the real type matters
1861 wxWindow
*m_colWindow
;
1863 wxGridColLabelWindow
*GetColLabelWindow() const
1865 wxASSERT_MSG( !m_useNativeHeader
, "no column label window" );
1867 return reinterpret_cast<wxGridColLabelWindow
*>(m_colWindow
);
1870 wxGridTableBase
*m_table
;
1876 wxGridCellCoords m_currentCellCoords
;
1878 // the corners of the block being currently selected or wxGridNoCellCoords
1879 wxGridCellCoords m_selectedBlockTopLeft
;
1880 wxGridCellCoords m_selectedBlockBottomRight
;
1882 // when selecting blocks of cells (either from the keyboard using Shift
1883 // with cursor keys, or by dragging the mouse), the selection is anchored
1884 // at m_currentCellCoords which defines one of the corners of the rectangle
1885 // being selected -- and this variable defines the other corner, i.e. it's
1886 // either m_selectedBlockTopLeft or m_selectedBlockBottomRight depending on
1887 // which of them is not m_currentCellCoords
1889 // if no block selection is in process, it is set to wxGridNoCellCoords
1890 wxGridCellCoords m_selectedBlockCorner
;
1892 wxGridSelection
*m_selection
;
1894 wxColour m_selectionBackground
;
1895 wxColour m_selectionForeground
;
1897 // NB: *never* access m_row/col arrays directly because they are created
1898 // on demand, *always* use accessor functions instead!
1900 // init the m_rowHeights/Bottoms arrays with default values
1901 void InitRowHeights();
1903 int m_defaultRowHeight
;
1904 int m_minAcceptableRowHeight
;
1905 wxArrayInt m_rowHeights
;
1906 wxArrayInt m_rowBottoms
;
1908 // init the m_colWidths/Rights arrays
1909 void InitColWidths();
1911 int m_defaultColWidth
;
1912 int m_minAcceptableColWidth
;
1913 wxArrayInt m_colWidths
;
1914 wxArrayInt m_colRights
;
1917 bool m_sortIsAscending
;
1919 bool m_useNativeHeader
,
1920 m_nativeColumnLabels
;
1922 // get the col/row coords
1923 int GetColWidth(int col
) const;
1924 int GetColLeft(int col
) const;
1925 int GetColRight(int col
) const;
1927 // this function must be public for compatibility...
1929 int GetRowHeight(int row
) const;
1932 int GetRowTop(int row
) const;
1933 int GetRowBottom(int row
) const;
1935 int m_rowLabelWidth
;
1936 int m_colLabelHeight
;
1938 // the size of the margin left to the right and bottom of the cell area
1942 wxColour m_labelBackgroundColour
;
1943 wxColour m_labelTextColour
;
1946 int m_rowLabelHorizAlign
;
1947 int m_rowLabelVertAlign
;
1948 int m_colLabelHorizAlign
;
1949 int m_colLabelVertAlign
;
1950 int m_colLabelTextOrientation
;
1952 bool m_defaultRowLabelValues
;
1953 bool m_defaultColLabelValues
;
1955 wxColour m_gridLineColour
;
1956 bool m_gridLinesEnabled
;
1957 bool m_gridLinesClipHorz
,
1958 m_gridLinesClipVert
;
1959 wxColour m_cellHighlightColour
;
1960 int m_cellHighlightPenWidth
;
1961 int m_cellHighlightROPenWidth
;
1964 // common part of AutoSizeColumn/Row() and GetBestSize()
1965 int SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
= true);
1966 int SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
= true);
1968 // common part of AutoSizeColumn/Row()
1969 void AutoSizeColOrRow(int n
, bool setAsMin
, wxGridDirection direction
);
1971 // Calculate the minimum acceptable size for labels area
1972 wxCoord
CalcColOrRowLabelAreaMinSize(wxGridDirection direction
);
1974 // if a column has a minimal width, it will be the value for it in this
1976 wxLongToLongHashMap m_colMinWidths
,
1979 // get the minimal width of the given column/row
1980 int GetColMinimalWidth(int col
) const;
1981 int GetRowMinimalHeight(int col
) const;
1983 // do we have some place to store attributes in?
1984 bool CanHaveAttributes() const;
1986 // cell attribute cache (currently we only cache 1, may be will do
1987 // more/better later)
1991 wxGridCellAttr
*attr
;
1994 // invalidates the attribute cache
1995 void ClearAttrCache();
1997 // adds an attribute to cache
1998 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
2000 // looks for an attr in cache, returns true if found
2001 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
2003 // looks for the attr in cache, if not found asks the table and caches the
2005 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
2006 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
) const
2007 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
2009 // the default cell attr object for cells that don't have their own
2010 wxGridCellAttr
* m_defaultCellAttr
;
2017 wxGridTypeRegistry
* m_typeRegistry
;
2021 WXGRID_CURSOR_SELECT_CELL
,
2022 WXGRID_CURSOR_RESIZE_ROW
,
2023 WXGRID_CURSOR_RESIZE_COL
,
2024 WXGRID_CURSOR_SELECT_ROW
,
2025 WXGRID_CURSOR_SELECT_COL
,
2026 WXGRID_CURSOR_MOVE_COL
2029 // this method not only sets m_cursorMode but also sets the correct cursor
2030 // for the given mode and, if captureMouse is not false releases the mouse
2031 // if it was captured and captures it if it must be captured
2033 // for this to work, you should always use it and not set m_cursorMode
2035 void ChangeCursorMode(CursorMode mode
,
2036 wxWindow
*win
= NULL
,
2037 bool captureMouse
= true);
2039 wxWindow
*m_winCapture
; // the window which captured the mouse
2041 // this variable is used not for finding the correct current cursor but
2042 // mainly for finding out what is going to happen if the mouse starts being
2043 // dragged right now
2045 // by default it is WXGRID_CURSOR_SELECT_CELL meaning that nothing else is
2046 // going on, and it is set to one of RESIZE/SELECT/MOVE values while the
2047 // corresponding operation will be started if the user starts dragging the
2048 // mouse from the current position
2049 CursorMode m_cursorMode
;
2055 bool m_canDragRowSize
;
2056 bool m_canDragColSize
;
2057 bool m_canDragColMove
;
2058 bool m_canDragGridSize
;
2061 // the last position (horizontal or vertical depending on whether the user
2062 // is resizing a column or a row) where a row or column separator line was
2063 // dragged by the user or -1 of there is no drag operation in progress
2067 // true if a drag operation is in progress; when this is true,
2068 // m_startDragPos is valid, i.e. not wxDefaultPosition
2071 // the position (in physical coordinates) where the user started dragging
2072 // the mouse or wxDefaultPosition if mouse isn't being dragged
2074 // notice that this can be != wxDefaultPosition while m_isDragging is still
2075 // false because we wait until the mouse is moved some distance away before
2076 // setting m_isDragging to true
2077 wxPoint m_startDragPos
;
2079 bool m_waitForSlowClick
;
2081 wxGridCellCoords m_selectionStart
;
2083 wxCursor m_rowResizeCursor
;
2084 wxCursor m_colResizeCursor
;
2086 bool m_editable
; // applies to whole grid
2087 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
2089 TabBehaviour m_tabBehaviour
; // determines how the TAB key behaves
2091 void Init(); // common part of all ctors
2093 void CreateColumnWindow();
2094 void CalcDimensions();
2095 void CalcWindowSizes();
2096 bool Redimension( wxGridTableMessage
& );
2099 // generate the appropriate grid event and return -1 if it was vetoed, 1 if
2100 // it was processed (but not vetoed) and 0 if it wasn't processed
2101 int SendEvent(const wxEventType evtType
,
2103 const wxMouseEvent
& e
);
2104 int SendEvent(const wxEventType evtType
,
2105 const wxGridCellCoords
& coords
,
2106 const wxMouseEvent
& e
)
2107 { return SendEvent(evtType
, coords
.GetRow(), coords
.GetCol(), e
); }
2108 int SendEvent(const wxEventType evtType
,
2110 const wxString
& s
= wxString());
2111 int SendEvent(const wxEventType evtType
,
2112 const wxGridCellCoords
& coords
,
2113 const wxString
& s
= wxString())
2114 { return SendEvent(evtType
, coords
.GetRow(), coords
.GetCol(), s
); }
2115 int SendEvent(const wxEventType evtType
, const wxString
& s
= wxString())
2116 { return SendEvent(evtType
, m_currentCellCoords
, s
); }
2118 // send wxEVT_GRID_{ROW,COL}_SIZE or wxEVT_GRID_COL_AUTO_SIZE, return true
2119 // if the event was processed, false otherwise
2120 bool SendGridSizeEvent(wxEventType type
,
2122 const wxMouseEvent
& mouseEv
);
2124 void OnPaint( wxPaintEvent
& );
2125 void OnSize( wxSizeEvent
& );
2126 void OnKeyDown( wxKeyEvent
& );
2127 void OnKeyUp( wxKeyEvent
& );
2128 void OnChar( wxKeyEvent
& );
2129 void OnEraseBackground( wxEraseEvent
& );
2130 void OnHideEditor( wxCommandEvent
& );
2133 bool SetCurrentCell( const wxGridCellCoords
& coords
);
2134 bool SetCurrentCell( int row
, int col
)
2135 { return SetCurrentCell( wxGridCellCoords(row
, col
) ); }
2138 // this function is called to extend the block being currently selected
2139 // from mouse and keyboard event handlers
2140 void UpdateBlockBeingSelected(int topRow
, int leftCol
,
2141 int bottomRow
, int rightCol
);
2143 void UpdateBlockBeingSelected(const wxGridCellCoords
& topLeft
,
2144 const wxGridCellCoords
& bottomRight
)
2145 { UpdateBlockBeingSelected(topLeft
.GetRow(), topLeft
.GetCol(),
2146 bottomRight
.GetRow(), bottomRight
.GetCol()); }
2148 // ------ functions to get/send data (see also public functions)
2150 bool GetModelValues();
2151 bool SetModelValues();
2153 friend class WXDLLIMPEXP_FWD_ADV wxGridSelection
;
2154 friend class wxGridRowOperations
;
2155 friend class wxGridColumnOperations
;
2157 // they call our private Process{{Corner,Col,Row}Label,GridCell}MouseEvent()
2158 friend class wxGridCornerLabelWindow
;
2159 friend class wxGridColLabelWindow
;
2160 friend class wxGridRowLabelWindow
;
2161 friend class wxGridWindow
;
2162 friend class wxGridHeaderRenderer
;
2164 friend class wxGridHeaderCtrl
;
2168 // implement wxScrolledWindow method to return m_gridWin size
2169 virtual wxSize
GetSizeAvailableForScrollTarget(const wxSize
& size
);
2171 // redraw the grid lines, should be called after changing their attributes
2172 void RedrawGridLines();
2174 // draw all grid lines in the given cell region (unlike the public
2175 // DrawAllGridLines() which just draws all of them)
2176 void DrawRangeGridLines(wxDC
& dc
, const wxRegion
& reg
,
2177 const wxGridCellCoords
& topLeft
,
2178 const wxGridCellCoords
& bottomRight
);
2180 // draw all lines from top to bottom row and left to right column in the
2181 // rectangle determined by (top, left)-(bottom, right) -- but notice that
2182 // the caller must have set up the clipping correctly, this rectangle is
2183 // only used here for optimization
2184 void DoDrawGridLines(wxDC
& dc
,
2186 int bottom
, int right
,
2187 int topRow
, int leftCol
,
2188 int bottomRight
, int rightCol
);
2190 // common part of Clip{Horz,Vert}GridLines
2191 void DoClipGridLines(bool& var
, bool clip
);
2193 // update the sorting indicator shown in the specified column (whose index
2196 // this will use GetSortingColumn() and IsSortOrderAscending() to determine
2197 // the sorting indicator to effectively show
2198 void UpdateColumnSortingIndicator(int col
);
2200 // update the grid after changing the columns order (common part of
2201 // SetColPos() and ResetColPos())
2202 void RefreshAfterColPosChange();
2205 // return the position (not index) of the column at the given logical pixel
2208 // this always returns a valid position, even if the coordinate is out of
2209 // bounds (in which case first/last column is returned)
2210 int XToPos(int x
) const;
2213 // event handlers and their helpers
2214 // --------------------------------
2216 // process mouse drag event in WXGRID_CURSOR_SELECT_CELL mode
2217 bool DoGridCellDrag(wxMouseEvent
& event
,
2218 const wxGridCellCoords
& coords
,
2221 // process row/column resizing drag event
2222 void DoGridLineDrag(wxMouseEvent
& event
, const wxGridOperations
& oper
);
2224 // process mouse drag event in the grid window
2225 void DoGridDragEvent(wxMouseEvent
& event
, const wxGridCellCoords
& coords
);
2227 // process different clicks on grid cells
2228 void DoGridCellLeftDown(wxMouseEvent
& event
,
2229 const wxGridCellCoords
& coords
,
2230 const wxPoint
& pos
);
2231 void DoGridCellLeftDClick(wxMouseEvent
& event
,
2232 const wxGridCellCoords
& coords
,
2233 const wxPoint
& pos
);
2234 void DoGridCellLeftUp(wxMouseEvent
& event
, const wxGridCellCoords
& coords
);
2236 // process movement (but not dragging) event in the grid cell area
2237 void DoGridMouseMoveEvent(wxMouseEvent
& event
,
2238 const wxGridCellCoords
& coords
,
2239 const wxPoint
& pos
);
2241 // process mouse events in the grid window
2242 void ProcessGridCellMouseEvent(wxMouseEvent
& event
);
2244 // process mouse events in the row/column labels/corner windows
2245 void ProcessRowLabelMouseEvent(wxMouseEvent
& event
);
2246 void ProcessColLabelMouseEvent(wxMouseEvent
& event
);
2247 void ProcessCornerLabelMouseEvent(wxMouseEvent
& event
);
2249 void DoColHeaderClick(int col
);
2251 void DoStartResizeCol(int col
);
2252 void DoUpdateResizeCol(int x
);
2253 void DoUpdateResizeColWidth(int w
);
2254 void DoStartMoveCol(int col
);
2256 void DoEndDragResizeRow(const wxMouseEvent
& event
);
2257 void DoEndDragResizeCol(const wxMouseEvent
& event
);
2258 void DoEndMoveCol(int pos
);
2260 // process a TAB keypress
2261 void DoGridProcessTab(wxKeyboardState
& kbdState
);
2263 // common implementations of methods defined for both rows and columns
2264 void DeselectLine(int line
, const wxGridOperations
& oper
);
2265 bool DoEndDragResizeLine(const wxGridOperations
& oper
);
2266 int PosToLinePos(int pos
, bool clipToMinMax
,
2267 const wxGridOperations
& oper
) const;
2268 int PosToLine(int pos
, bool clipToMinMax
,
2269 const wxGridOperations
& oper
) const;
2270 int PosToEdgeOfLine(int pos
, const wxGridOperations
& oper
) const;
2272 bool DoMoveCursor(bool expandSelection
,
2273 const wxGridDirectionOperations
& diroper
);
2274 bool DoMoveCursorByPage(const wxGridDirectionOperations
& diroper
);
2275 bool DoMoveCursorByBlock(bool expandSelection
,
2276 const wxGridDirectionOperations
& diroper
);
2277 void AdvanceToNextNonEmpty(wxGridCellCoords
& coords
,
2278 const wxGridDirectionOperations
& diroper
);
2280 // common part of {Insert,Delete}{Rows,Cols}
2281 bool DoModifyLines(bool (wxGridTableBase::*funcModify
)(size_t, size_t),
2282 int pos
, int num
, bool updateLabels
);
2283 // Append{Rows,Cols} is a bit different because of one less parameter
2284 bool DoAppendLines(bool (wxGridTableBase::*funcAppend
)(size_t),
2285 int num
, bool updateLabels
);
2287 // common part of Set{Col,Row}Sizes
2288 void DoSetSizes(const wxGridSizesInfo
& sizeInfo
,
2289 const wxGridOperations
& oper
);
2291 // common part of Disable{Row,Col}Resize and CanDrag{Row,Col}Size
2292 void DoDisableLineResize(int line
, wxGridFixedIndicesSet
*& setFixed
);
2293 bool DoCanResizeLine(int line
, const wxGridFixedIndicesSet
*setFixed
) const;
2295 // Helper of Render(): get grid size, origin offset and fill cell arrays
2296 void GetRenderSizes( const wxGridCellCoords
& topLeft
,
2297 const wxGridCellCoords
& bottomRight
,
2298 wxPoint
& pointOffSet
, wxSize
& sizeGrid
,
2299 wxGridCellCoordsArray
& renderCells
,
2300 wxArrayInt
& arrayCols
, wxArrayInt
& arrayRows
);
2302 // Helper of Render(): set the scale to draw the cells at the right size.
2303 void SetRenderScale( wxDC
& dc
, const wxPoint
& pos
, const wxSize
& size
,
2304 const wxSize
& sizeGrid
);
2306 // Helper of Render(): get render start position from passed parameter
2307 wxPoint
GetRenderPosition( wxDC
& dc
, const wxPoint
& position
);
2309 // Helper of Render(): draws a box around the rendered area
2310 void DoRenderBox( wxDC
& dc
, const int& style
,
2311 const wxPoint
& pointOffSet
,
2312 const wxSize
& sizeCellArea
,
2313 const wxGridCellCoords
& topLeft
,
2314 const wxGridCellCoords
& bottomRight
);
2316 // Implementation of public Set{Row,Col}Size() and {Hide,Show}{Row,Col}().
2317 // They interpret their height or width parameter slightly different from
2318 // the public methods where -1 in it means "auto fit to the label" for the
2319 // compatibility reasons. Here it means "show a previously hidden row or
2320 // column" while 0 means "hide it" just as in the public methods. And any
2321 // positive values are handled naturally, i.e. they just specify the size.
2322 void DoSetRowSize( int row
, int height
);
2323 void DoSetColSize( int col
, int width
);
2326 // these sets contain the indices of fixed, i.e. non-resizable
2327 // interactively, grid rows or columns and are NULL if there are no fixed
2328 // elements (which is the default)
2329 wxGridFixedIndicesSet
*m_setFixedRows
,
2332 DECLARE_DYNAMIC_CLASS( wxGrid
)
2333 DECLARE_EVENT_TABLE()
2334 wxDECLARE_NO_COPY_CLASS(wxGrid
);
2337 // ----------------------------------------------------------------------------
2338 // wxGridUpdateLocker prevents updates to a grid during its lifetime
2339 // ----------------------------------------------------------------------------
2341 class WXDLLIMPEXP_ADV wxGridUpdateLocker
2344 // if the pointer is NULL, Create() can be called later
2345 wxGridUpdateLocker(wxGrid
*grid
= NULL
)
2350 // can be called if ctor was used with a NULL pointer, must not be called
2352 void Create(wxGrid
*grid
)
2354 wxASSERT_MSG( !m_grid
, wxT("shouldn't be called more than once") );
2359 ~wxGridUpdateLocker()
2366 void Init(wxGrid
*grid
)
2370 m_grid
->BeginBatch();
2375 wxDECLARE_NO_COPY_CLASS(wxGridUpdateLocker
);
2378 // ----------------------------------------------------------------------------
2379 // Grid event class and event types
2380 // ----------------------------------------------------------------------------
2382 class WXDLLIMPEXP_ADV wxGridEvent
: public wxNotifyEvent
,
2383 public wxKeyboardState
2389 Init(-1, -1, -1, -1, false);
2395 int row
= -1, int col
= -1,
2396 int x
= -1, int y
= -1,
2398 const wxKeyboardState
& kbd
= wxKeyboardState())
2399 : wxNotifyEvent(type
, id
),
2400 wxKeyboardState(kbd
)
2402 Init(row
, col
, x
, y
, sel
);
2403 SetEventObject(obj
);
2406 // explicitly specifying inline allows gcc < 3.4 to
2407 // handle the deprecation attribute even in the constructor.
2408 wxDEPRECATED_CONSTRUCTOR(
2416 bool shift
= false, bool alt
= false, bool meta
= false));
2418 virtual int GetRow() { return m_row
; }
2419 virtual int GetCol() { return m_col
; }
2420 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
2421 bool Selecting() { return m_selecting
; }
2423 virtual wxEvent
*Clone() const { return new wxGridEvent(*this); }
2433 void Init(int row
, int col
, int x
, int y
, bool sel
)
2442 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent
)
2445 class WXDLLIMPEXP_ADV wxGridSizeEvent
: public wxNotifyEvent
,
2446 public wxKeyboardState
2455 wxGridSizeEvent(int id
,
2459 int x
= -1, int y
= -1,
2460 const wxKeyboardState
& kbd
= wxKeyboardState())
2461 : wxNotifyEvent(type
, id
),
2462 wxKeyboardState(kbd
)
2464 Init(rowOrCol
, x
, y
);
2466 SetEventObject(obj
);
2469 wxDEPRECATED_CONSTRUCTOR(
2470 wxGridSizeEvent(int id
,
2478 bool meta
= false) );
2480 int GetRowOrCol() { return m_rowOrCol
; }
2481 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
2483 virtual wxEvent
*Clone() const { return new wxGridSizeEvent(*this); }
2491 void Init(int rowOrCol
, int x
, int y
)
2493 m_rowOrCol
= rowOrCol
;
2498 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent
)
2502 class WXDLLIMPEXP_ADV wxGridRangeSelectEvent
: public wxNotifyEvent
,
2503 public wxKeyboardState
2506 wxGridRangeSelectEvent()
2509 Init(wxGridNoCellCoords
, wxGridNoCellCoords
, false);
2512 wxGridRangeSelectEvent(int id
,
2515 const wxGridCellCoords
& topLeft
,
2516 const wxGridCellCoords
& bottomRight
,
2518 const wxKeyboardState
& kbd
= wxKeyboardState())
2519 : wxNotifyEvent(type
, id
),
2520 wxKeyboardState(kbd
)
2522 Init(topLeft
, bottomRight
, sel
);
2524 SetEventObject(obj
);
2527 wxDEPRECATED_CONSTRUCTOR(
2528 wxGridRangeSelectEvent(int id
,
2531 const wxGridCellCoords
& topLeft
,
2532 const wxGridCellCoords
& bottomRight
,
2537 bool meta
= false) );
2539 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
2540 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
2541 int GetTopRow() { return m_topLeft
.GetRow(); }
2542 int GetBottomRow() { return m_bottomRight
.GetRow(); }
2543 int GetLeftCol() { return m_topLeft
.GetCol(); }
2544 int GetRightCol() { return m_bottomRight
.GetCol(); }
2545 bool Selecting() { return m_selecting
; }
2547 virtual wxEvent
*Clone() const { return new wxGridRangeSelectEvent(*this); }
2550 void Init(const wxGridCellCoords
& topLeft
,
2551 const wxGridCellCoords
& bottomRight
,
2554 m_topLeft
= topLeft
;
2555 m_bottomRight
= bottomRight
;
2556 m_selecting
= selecting
;
2559 wxGridCellCoords m_topLeft
;
2560 wxGridCellCoords m_bottomRight
;
2563 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent
)
2567 class WXDLLIMPEXP_ADV wxGridEditorCreatedEvent
: public wxCommandEvent
2570 wxGridEditorCreatedEvent()
2578 wxGridEditorCreatedEvent(int id
, wxEventType type
, wxObject
* obj
,
2579 int row
, int col
, wxControl
* ctrl
);
2581 int GetRow() { return m_row
; }
2582 int GetCol() { return m_col
; }
2583 wxControl
* GetControl() { return m_ctrl
; }
2584 void SetRow(int row
) { m_row
= row
; }
2585 void SetCol(int col
) { m_col
= col
; }
2586 void SetControl(wxControl
* ctrl
) { m_ctrl
= ctrl
; }
2588 virtual wxEvent
*Clone() const { return new wxGridEditorCreatedEvent(*this); }
2595 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent
)
2599 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_LEFT_CLICK
, wxGridEvent
);
2600 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_RIGHT_CLICK
, wxGridEvent
);
2601 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_LEFT_DCLICK
, wxGridEvent
);
2602 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_RIGHT_DCLICK
, wxGridEvent
);
2603 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_LABEL_LEFT_CLICK
, wxGridEvent
);
2604 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_LABEL_RIGHT_CLICK
, wxGridEvent
);
2605 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_LABEL_LEFT_DCLICK
, wxGridEvent
);
2606 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_LABEL_RIGHT_DCLICK
, wxGridEvent
);
2607 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_ROW_SIZE
, wxGridSizeEvent
);
2608 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_COL_SIZE
, wxGridSizeEvent
);
2609 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_COL_AUTO_SIZE
, wxGridSizeEvent
);
2610 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_RANGE_SELECT
, wxGridRangeSelectEvent
);
2611 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_CHANGING
, wxGridEvent
);
2612 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_CHANGED
, wxGridEvent
);
2613 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_SELECT_CELL
, wxGridEvent
);
2614 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_EDITOR_SHOWN
, wxGridEvent
);
2615 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_EDITOR_HIDDEN
, wxGridEvent
);
2616 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_EDITOR_CREATED
, wxGridEditorCreatedEvent
);
2617 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_BEGIN_DRAG
, wxGridEvent
);
2618 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_COL_MOVE
, wxGridEvent
);
2619 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_COL_SORT
, wxGridEvent
);
2620 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_TABBING
, wxGridEvent
);
2622 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
2623 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
2624 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
2625 typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction
)(wxGridEditorCreatedEvent
&);
2627 #define wxGridEventHandler(func) \
2628 wxEVENT_HANDLER_CAST(wxGridEventFunction, func)
2630 #define wxGridSizeEventHandler(func) \
2631 wxEVENT_HANDLER_CAST(wxGridSizeEventFunction, func)
2633 #define wxGridRangeSelectEventHandler(func) \
2634 wxEVENT_HANDLER_CAST(wxGridRangeSelectEventFunction, func)
2636 #define wxGridEditorCreatedEventHandler(func) \
2637 wxEVENT_HANDLER_CAST(wxGridEditorCreatedEventFunction, func)
2639 #define wx__DECLARE_GRIDEVT(evt, id, fn) \
2640 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn))
2642 #define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \
2643 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn))
2645 #define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \
2646 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn))
2648 #define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \
2649 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn))
2651 #define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn)
2652 #define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn)
2653 #define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn)
2654 #define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn)
2655 #define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn)
2656 #define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn)
2657 #define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn)
2658 #define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn)
2659 #define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn)
2660 #define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn)
2661 #define EVT_GRID_CMD_COL_AUTO_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_AUTO_SIZE, id, fn)
2662 #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn)
2663 #define EVT_GRID_CMD_COL_SORT(id, fn) wx__DECLARE_GRIDEVT(COL_SORT, id, fn)
2664 #define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn)
2665 #define EVT_GRID_CMD_CELL_CHANGING(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGING, id, fn)
2666 #define EVT_GRID_CMD_CELL_CHANGED(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGED, id, fn)
2667 #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn)
2668 #define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn)
2669 #define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn)
2670 #define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn)
2671 #define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn)
2672 #define EVT_GRID_CMD_TABBING(id, fn) wx__DECLARE_GRIDEVT(TABBING, id, fn)
2674 // same as above but for any id (exists mainly for backwards compatibility but
2675 // then it's also true that you rarely have multiple grid in the same window)
2676 #define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn)
2677 #define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn)
2678 #define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn)
2679 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn)
2680 #define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn)
2681 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn)
2682 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn)
2683 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn)
2684 #define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn)
2685 #define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn)
2686 #define EVT_GRID_COL_AUTO_SIZE(fn) EVT_GRID_CMD_COL_AUTO_SIZE(wxID_ANY, fn)
2687 #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn)
2688 #define EVT_GRID_COL_SORT(fn) EVT_GRID_CMD_COL_SORT(wxID_ANY, fn)
2689 #define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn)
2690 #define EVT_GRID_CELL_CHANGING(fn) EVT_GRID_CMD_CELL_CHANGING(wxID_ANY, fn)
2691 #define EVT_GRID_CELL_CHANGED(fn) EVT_GRID_CMD_CELL_CHANGED(wxID_ANY, fn)
2692 #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn)
2693 #define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn)
2694 #define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn)
2695 #define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn)
2696 #define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn)
2697 #define EVT_GRID_TABBING(fn) EVT_GRID_CMD_TABBING(wxID_ANY, fn)
2699 // we used to have a single wxEVT_GRID_CELL_CHANGE event but it was split into
2700 // wxEVT_GRID_CELL_CHANGING and CHANGED ones in wx 2.9.0, however the CHANGED
2701 // is basically the same as the old CHANGE event so we keep the name for
2703 #if WXWIN_COMPATIBILITY_2_8
2704 #define wxEVT_GRID_CELL_CHANGE wxEVT_GRID_CELL_CHANGED
2706 #define EVT_GRID_CMD_CELL_CHANGE EVT_GRID_CMD_CELL_CHANGED
2707 #define EVT_GRID_CELL_CHANGE EVT_GRID_CELL_CHANGED
2708 #endif // WXWIN_COMPATIBILITY_2_8
2710 #if 0 // TODO: implement these ? others ?
2712 extern const int wxEVT_GRID_CREATE_CELL
;
2713 extern const int wxEVT_GRID_CHANGE_LABELS
;
2714 extern const int wxEVT_GRID_CHANGE_SEL_LABEL
;
2716 #define EVT_GRID_CREATE_CELL(fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2717 #define EVT_GRID_CHANGE_LABELS(fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2718 #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 ),
2722 #endif // wxUSE_GRID
2723 #endif // _WX_GENERIC_GRID_H_