1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/grid.h
3 // Purpose: wxGrid and related classes
4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
5 // Modified by: Santiago Palacios
8 // Copyright: (c) Michael Bedward
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_GRID_H_
13 #define _WX_GENERIC_GRID_H_
19 #include "wx/scrolwin.h"
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 extern WXDLLIMPEXP_DATA_ADV(const char) wxGridNameStr
[];
27 // Default parameters for wxGrid
29 #define WXGRID_DEFAULT_NUMBER_ROWS 10
30 #define WXGRID_DEFAULT_NUMBER_COLS 10
31 #if defined(__WXMSW__) || defined(__WXGTK20__)
32 #define WXGRID_DEFAULT_ROW_HEIGHT 25
34 #define WXGRID_DEFAULT_ROW_HEIGHT 30
36 #define WXGRID_DEFAULT_COL_WIDTH 80
37 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
38 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
39 #define WXGRID_LABEL_EDGE_ZONE 2
40 #define WXGRID_MIN_ROW_HEIGHT 15
41 #define WXGRID_MIN_COL_WIDTH 15
42 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
44 // type names for grid table values
45 #define wxGRID_VALUE_STRING _T("string")
46 #define wxGRID_VALUE_BOOL _T("bool")
47 #define wxGRID_VALUE_NUMBER _T("long")
48 #define wxGRID_VALUE_FLOAT _T("double")
49 #define wxGRID_VALUE_CHOICE _T("choice")
51 #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
52 #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
54 // magic constant which tells (to some functions) to automatically calculate
55 // the appropriate size
56 #define wxGRID_AUTOSIZE (-1)
58 // many wxGrid methods work either with columns or rows, this enum is used for
59 // the parameter indicating which one should it be
66 // ----------------------------------------------------------------------------
67 // forward declarations
68 // ----------------------------------------------------------------------------
70 class WXDLLIMPEXP_FWD_ADV wxGrid
;
71 class WXDLLIMPEXP_FWD_ADV wxGridCellAttr
;
72 class WXDLLIMPEXP_FWD_ADV wxGridCellAttrProviderData
;
73 class WXDLLIMPEXP_FWD_ADV wxGridColLabelWindow
;
74 class WXDLLIMPEXP_FWD_ADV wxGridCornerLabelWindow
;
75 class WXDLLIMPEXP_FWD_ADV wxGridRowLabelWindow
;
76 class WXDLLIMPEXP_FWD_ADV wxGridWindow
;
77 class WXDLLIMPEXP_FWD_ADV wxGridTypeRegistry
;
78 class WXDLLIMPEXP_FWD_ADV wxGridSelection
;
80 class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl
;
81 class WXDLLIMPEXP_FWD_CORE wxCheckBox
;
82 class WXDLLIMPEXP_FWD_CORE wxComboBox
;
83 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
85 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl
;
88 class wxGridOperations
;
89 class wxGridRowOperations
;
90 class wxGridColumnOperations
;
91 class wxGridDirectionOperations
;
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
99 #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
101 // ----------------------------------------------------------------------------
102 // wxGridCellWorker: common base class for wxGridCellRenderer and
105 // NB: this is more an implementation convenience than a design issue, so this
106 // class is not documented and is not public at all
107 // ----------------------------------------------------------------------------
109 class WXDLLIMPEXP_ADV wxGridCellWorker
: public wxClientDataContainer
112 wxGridCellWorker() { m_nRef
= 1; }
114 // this class is ref counted: it is created with ref count of 1, so
115 // calling DecRef() once will delete it. Calling IncRef() allows to lock
116 // it until the matching DecRef() is called
117 void IncRef() { m_nRef
++; }
118 void DecRef() { if ( --m_nRef
== 0 ) delete this; }
120 // interpret renderer parameters: arbitrary string whose interpretatin is
121 // left to the derived classes
122 virtual void SetParameters(const wxString
& params
);
125 // virtual dtor for any base class - private because only DecRef() can
127 virtual ~wxGridCellWorker();
132 // suppress the stupid gcc warning about the class having private dtor and
134 friend class wxGridCellWorkerDummyFriend
;
137 // ----------------------------------------------------------------------------
138 // wxGridCellRenderer: this class is responsible for actually drawing the cell
139 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
140 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
141 // view of all cells. This is an ABC, you will normally use one of the
142 // predefined derived classes or derive your own class from it.
143 // ----------------------------------------------------------------------------
145 class WXDLLIMPEXP_ADV wxGridCellRenderer
: public wxGridCellWorker
148 // draw the given cell on the provided DC inside the given rectangle
149 // using the style specified by the attribute and the default or selected
150 // state corresponding to the isSelected value.
152 // this pure virtual function has a default implementation which will
153 // prepare the DC using the given attribute: it will draw the rectangle
154 // with the bg colour from attr and set the text colour and font
155 virtual void Draw(wxGrid
& grid
,
156 wxGridCellAttr
& attr
,
160 bool isSelected
) = 0;
162 // get the preferred size of the cell for its contents
163 virtual wxSize
GetBestSize(wxGrid
& grid
,
164 wxGridCellAttr
& attr
,
166 int row
, int col
) = 0;
168 // create a new object which is the copy of this one
169 virtual wxGridCellRenderer
*Clone() const = 0;
172 // ----------------------------------------------------------------------------
173 // wxGridCellEditor: This class is responsible for providing and manipulating
174 // the in-place edit controls for the grid. Instances of wxGridCellEditor
175 // (actually, instances of derived classes since it is an ABC) can be
176 // associated with the cell attributes for individual cells, rows, columns, or
177 // even for the entire grid.
178 // ----------------------------------------------------------------------------
180 class WXDLLIMPEXP_ADV wxGridCellEditor
: public wxGridCellWorker
185 bool IsCreated() { return m_control
!= NULL
; }
186 wxControl
* GetControl() { return m_control
; }
187 void SetControl(wxControl
* control
) { m_control
= control
; }
189 wxGridCellAttr
* GetCellAttr() { return m_attr
; }
190 void SetCellAttr(wxGridCellAttr
* attr
) { m_attr
= attr
; }
192 // Creates the actual edit control
193 virtual void Create(wxWindow
* parent
,
195 wxEvtHandler
* evtHandler
) = 0;
197 // Size and position the edit control
198 virtual void SetSize(const wxRect
& rect
);
200 // Show or hide the edit control, use the specified attributes to set
201 // colours/fonts for it
202 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
204 // Draws the part of the cell not occupied by the control: the base class
205 // version just fills it with background colour from the attribute
206 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
209 // The methods called by wxGrid when a cell is edited: first BeginEdit() is
210 // called, then EndEdit() is and if it returns true and if the change is
211 // not vetoed by a user-defined event handler, finally ApplyEdit() is called
213 // Fetch the value from the table and prepare the edit control
214 // to begin editing. Set the focus to the edit control.
215 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
217 // Returns false if nothing changed, otherwise returns true and return the
218 // new value in its string form in the newval output parameter.
220 // This should also store the new value in its real type internally so that
221 // it could be used by ApplyEdit() but it must not modify the grid as the
222 // change could still be vetoed.
223 virtual bool EndEdit(int row
, int col
, const wxGrid
*grid
,
224 const wxString
& oldval
, wxString
*newval
) = 0;
226 // Complete the editing of the current cell by storing the value saved by
227 // the previous call to EndEdit() in the grid
228 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
) = 0;
231 // Reset the value in the control back to its starting value
232 virtual void Reset() = 0;
234 // return true to allow the given key to start editing: the base class
235 // version only checks that the event has no modifiers. The derived
236 // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
237 // their IsAcceptedKey() implementation, although, of course, it is not a
238 // mandatory requirment.
240 // NB: if the key is F2 (special), editing will always start and this
241 // method will not be called at all (but StartingKey() will)
242 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
244 // If the editor is enabled by pressing keys on the grid, this will be
245 // called to let the editor do something about that first key if desired
246 virtual void StartingKey(wxKeyEvent
& event
);
248 // if the editor is enabled by clicking on the cell, this method will be
250 virtual void StartingClick();
252 // Some types of controls on some platforms may need some help
253 // with the Return key.
254 virtual void HandleReturn(wxKeyEvent
& event
);
257 virtual void Destroy();
259 // create a new object which is the copy of this one
260 virtual wxGridCellEditor
*Clone() const = 0;
262 // added GetValue so we can get the value which is in the control
263 virtual wxString
GetValue() const = 0;
266 // the dtor is private because only DecRef() can delete us
267 virtual ~wxGridCellEditor();
269 // the control we show on screen
270 wxControl
* m_control
;
272 // a temporary pointer to the attribute being edited
273 wxGridCellAttr
* m_attr
;
275 // if we change the colours/font of the control from the default ones, we
276 // must restore the default later and we save them here between calls to
277 // Show(true) and Show(false)
282 // suppress the stupid gcc warning about the class having private dtor and
284 friend class wxGridCellEditorDummyFriend
;
286 wxDECLARE_NO_COPY_CLASS(wxGridCellEditor
);
290 // ----------------------------------------------------------------------------
291 // wxGridCellAttr: this class can be used to alter the cells appearance in
292 // the grid by changing their colour/font/... from default. An object of this
293 // class may be returned by wxGridTable::GetAttr().
294 // ----------------------------------------------------------------------------
296 class WXDLLIMPEXP_ADV wxGridCellAttr
: public wxClientDataContainer
310 wxGridCellAttr(wxGridCellAttr
*attrDefault
= NULL
)
314 // MB: args used to be 0,0 here but wxALIGN_LEFT is 0
315 SetAlignment(-1, -1);
318 // VZ: considering the number of members wxGridCellAttr has now, this ctor
319 // seems to be pretty useless... may be we should just remove it?
320 wxGridCellAttr(const wxColour
& colText
,
321 const wxColour
& colBack
,
325 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
328 SetAlignment(hAlign
, vAlign
);
331 // creates a new copy of this object
332 wxGridCellAttr
*Clone() const;
333 void MergeWith(wxGridCellAttr
*mergefrom
);
335 // this class is ref counted: it is created with ref count of 1, so
336 // calling DecRef() once will delete it. Calling IncRef() allows to lock
337 // it until the matching DecRef() is called
338 void IncRef() { m_nRef
++; }
339 void DecRef() { if ( --m_nRef
== 0 ) delete this; }
342 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
343 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
344 void SetFont(const wxFont
& font
) { m_font
= font
; }
345 void SetAlignment(int hAlign
, int vAlign
)
350 void SetSize(int num_rows
, int num_cols
);
351 void SetOverflow(bool allow
= true)
352 { m_overflow
= allow
? Overflow
: SingleCell
; }
353 void SetReadOnly(bool isReadOnly
= true)
354 { m_isReadOnly
= isReadOnly
? ReadOnly
: ReadWrite
; }
356 // takes ownership of the pointer
357 void SetRenderer(wxGridCellRenderer
*renderer
)
358 { wxSafeDecRef(m_renderer
); m_renderer
= renderer
; }
359 void SetEditor(wxGridCellEditor
* editor
)
360 { wxSafeDecRef(m_editor
); m_editor
= editor
; }
362 void SetKind(wxAttrKind kind
) { m_attrkind
= kind
; }
365 bool HasTextColour() const { return m_colText
.Ok(); }
366 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
367 bool HasFont() const { return m_font
.Ok(); }
368 bool HasAlignment() const { return (m_hAlign
!= -1 || m_vAlign
!= -1); }
369 bool HasRenderer() const { return m_renderer
!= NULL
; }
370 bool HasEditor() const { return m_editor
!= NULL
; }
371 bool HasReadWriteMode() const { return m_isReadOnly
!= Unset
; }
372 bool HasOverflowMode() const { return m_overflow
!= UnsetOverflow
; }
373 bool HasSize() const { return m_sizeRows
!= 1 || m_sizeCols
!= 1; }
375 const wxColour
& GetTextColour() const;
376 const wxColour
& GetBackgroundColour() const;
377 const wxFont
& GetFont() const;
378 void GetAlignment(int *hAlign
, int *vAlign
) const;
379 void GetSize(int *num_rows
, int *num_cols
) const;
380 bool GetOverflow() const
381 { return m_overflow
!= SingleCell
; }
382 wxGridCellRenderer
*GetRenderer(const wxGrid
* grid
, int row
, int col
) const;
383 wxGridCellEditor
*GetEditor(const wxGrid
* grid
, int row
, int col
) const;
385 bool IsReadOnly() const { return m_isReadOnly
== wxGridCellAttr::ReadOnly
; }
387 wxAttrKind
GetKind() { return m_attrkind
; }
389 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
392 // the dtor is private because only DecRef() can delete us
393 virtual ~wxGridCellAttr()
395 wxSafeDecRef(m_renderer
);
396 wxSafeDecRef(m_editor
);
407 enum wxAttrOverflowMode
414 // the common part of all ctors
415 void Init(wxGridCellAttr
*attrDefault
= NULL
);
418 // the ref count - when it goes to 0, we die
429 wxAttrOverflowMode m_overflow
;
431 wxGridCellRenderer
* m_renderer
;
432 wxGridCellEditor
* m_editor
;
433 wxGridCellAttr
* m_defGridAttr
;
435 wxAttrReadMode m_isReadOnly
;
437 wxAttrKind m_attrkind
;
439 // use Clone() instead
440 wxDECLARE_NO_COPY_CLASS(wxGridCellAttr
);
442 // suppress the stupid gcc warning about the class having private dtor and
444 friend class wxGridCellAttrDummyFriend
;
447 // ----------------------------------------------------------------------------
448 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
450 // ----------------------------------------------------------------------------
452 // implementation note: we separate it from wxGridTableBase because we wish to
453 // avoid deriving a new table class if possible, and sometimes it will be
454 // enough to just derive another wxGridCellAttrProvider instead
456 // the default implementation is reasonably efficient for the generic case,
457 // but you might still wish to implement your own for some specific situations
458 // if you have performance problems with the stock one
459 class WXDLLIMPEXP_ADV wxGridCellAttrProvider
: public wxClientDataContainer
462 wxGridCellAttrProvider();
463 virtual ~wxGridCellAttrProvider();
465 // DecRef() must be called on the returned pointer
466 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
467 wxGridCellAttr::wxAttrKind kind
) const;
469 // all these functions take ownership of the pointer, don't call DecRef()
471 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
472 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
473 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
475 // these functions must be called whenever some rows/cols are deleted
476 // because the internal data must be updated then
477 void UpdateAttrRows( size_t pos
, int numRows
);
478 void UpdateAttrCols( size_t pos
, int numCols
);
483 wxGridCellAttrProviderData
*m_data
;
485 wxDECLARE_NO_COPY_CLASS(wxGridCellAttrProvider
);
488 // ----------------------------------------------------------------------------
489 // wxGridCellCoords: location of a cell in the grid
490 // ----------------------------------------------------------------------------
492 class WXDLLIMPEXP_ADV wxGridCellCoords
495 wxGridCellCoords() { m_row
= m_col
= -1; }
496 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
498 // default copy ctor is ok
500 int GetRow() const { return m_row
; }
501 void SetRow( int n
) { m_row
= n
; }
502 int GetCol() const { return m_col
; }
503 void SetCol( int n
) { m_col
= n
; }
504 void Set( int row
, int col
) { m_row
= row
; m_col
= col
; }
506 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
508 if ( &other
!= this )
516 bool operator==( const wxGridCellCoords
& other
) const
518 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
521 bool operator!=( const wxGridCellCoords
& other
) const
523 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
526 bool operator!() const
528 return (m_row
== -1 && m_col
== -1 );
537 // For comparisons...
539 extern WXDLLIMPEXP_ADV wxGridCellCoords wxGridNoCellCoords
;
540 extern WXDLLIMPEXP_ADV wxRect wxGridNoCellRect
;
542 // An array of cell coords...
544 WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords
, wxGridCellCoordsArray
,
545 class WXDLLIMPEXP_ADV
);
547 // ----------------------------------------------------------------------------
548 // Grid table classes
549 // ----------------------------------------------------------------------------
551 // the abstract base class
552 class WXDLLIMPEXP_ADV wxGridTableBase
: public wxObject
,
553 public wxClientDataContainer
557 virtual ~wxGridTableBase();
559 // You must override these functions in a derived table class
562 // return the number of rows and columns in this table
563 virtual int GetNumberRows() = 0;
564 virtual int GetNumberCols() = 0;
566 // the methods above are unfortunately non-const even though they should
567 // have been const -- but changing it now is not possible any longer as it
568 // would break the existing code overriding them, so instead we provide
569 // these const synonyms which can be used from const-correct code
570 int GetRowsCount() const
571 { return const_cast<wxGridTableBase
*>(this)->GetNumberRows(); }
572 int GetColsCount() const
573 { return const_cast<wxGridTableBase
*>(this)->GetNumberCols(); }
576 virtual bool IsEmptyCell( int row
, int col
)
578 return GetValue(row
, col
).empty();
581 bool IsEmpty(const wxGridCellCoords
& coord
)
583 return IsEmptyCell(coord
.GetRow(), coord
.GetCol());
586 virtual wxString
GetValue( int row
, int col
) = 0;
587 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
589 // Data type determination and value access
590 virtual wxString
GetTypeName( int row
, int col
);
591 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
592 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
594 virtual long GetValueAsLong( int row
, int col
);
595 virtual double GetValueAsDouble( int row
, int col
);
596 virtual bool GetValueAsBool( int row
, int col
);
598 virtual void SetValueAsLong( int row
, int col
, long value
);
599 virtual void SetValueAsDouble( int row
, int col
, double value
);
600 virtual void SetValueAsBool( int row
, int col
, bool value
);
602 // For user defined types
603 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
604 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
607 // Overriding these is optional
609 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
610 virtual wxGrid
* GetView() const { return m_view
; }
612 virtual void Clear() {}
613 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
614 virtual bool AppendRows( size_t numRows
= 1 );
615 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
616 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
617 virtual bool AppendCols( size_t numCols
= 1 );
618 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
620 virtual wxString
GetRowLabelValue( int row
);
621 virtual wxString
GetColLabelValue( int col
);
622 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
623 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
625 // Attribute handling
628 // give us the attr provider to use - we take ownership of the pointer
629 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
631 // get the currently used attr provider (may be NULL)
632 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
634 // Does this table allow attributes? Default implementation creates
635 // a wxGridCellAttrProvider if necessary.
636 virtual bool CanHaveAttributes();
638 // by default forwarded to wxGridCellAttrProvider if any. May be
639 // overridden to handle attributes directly in the table.
640 virtual wxGridCellAttr
*GetAttr( int row
, int col
,
641 wxGridCellAttr::wxAttrKind kind
);
644 // these functions take ownership of the pointer
645 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
646 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
647 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
651 wxGridCellAttrProvider
*m_attrProvider
;
653 DECLARE_ABSTRACT_CLASS(wxGridTableBase
)
654 wxDECLARE_NO_COPY_CLASS(wxGridTableBase
);
658 // ----------------------------------------------------------------------------
659 // wxGridTableMessage
660 // ----------------------------------------------------------------------------
662 // IDs for messages sent from grid table to view
664 enum wxGridTableRequest
666 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
667 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
668 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
669 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
670 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
671 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
672 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
673 wxGRIDTABLE_NOTIFY_COLS_DELETED
676 class WXDLLIMPEXP_ADV wxGridTableMessage
679 wxGridTableMessage();
680 wxGridTableMessage( wxGridTableBase
*table
, int id
,
684 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
685 wxGridTableBase
* GetTableObject() const { return m_table
; }
686 void SetId( int id
) { m_id
= id
; }
687 int GetId() { return m_id
; }
688 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
689 int GetCommandInt() { return m_comInt1
; }
690 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
691 int GetCommandInt2() { return m_comInt2
; }
694 wxGridTableBase
*m_table
;
699 wxDECLARE_NO_COPY_CLASS(wxGridTableMessage
);
704 // ------ wxGridStringArray
705 // A 2-dimensional array of strings for data values
708 WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString
, wxGridStringArray
,
709 class WXDLLIMPEXP_ADV
);
713 // ------ wxGridStringTable
715 // Simplest type of data table for a grid for small tables of strings
716 // that are stored in memory
719 class WXDLLIMPEXP_ADV wxGridStringTable
: public wxGridTableBase
723 wxGridStringTable( int numRows
, int numCols
);
724 virtual ~wxGridStringTable();
726 // these are pure virtual in wxGridTableBase
730 wxString
GetValue( int row
, int col
);
731 void SetValue( int row
, int col
, const wxString
& s
);
733 // overridden functions from wxGridTableBase
736 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
737 bool AppendRows( size_t numRows
= 1 );
738 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
739 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
740 bool AppendCols( size_t numCols
= 1 );
741 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
743 void SetRowLabelValue( int row
, const wxString
& );
744 void SetColLabelValue( int col
, const wxString
& );
745 wxString
GetRowLabelValue( int row
);
746 wxString
GetColLabelValue( int col
);
749 wxGridStringArray m_data
;
751 // These only get used if you set your own labels, otherwise the
752 // GetRow/ColLabelValue functions return wxGridTableBase defaults
754 wxArrayString m_rowLabels
;
755 wxArrayString m_colLabels
;
757 DECLARE_DYNAMIC_CLASS_NO_COPY( wxGridStringTable
)
762 // ============================================================================
764 // ============================================================================
766 // ----------------------------------------------------------------------------
767 // wxGridSizesInfo stores information about sizes of the rows or columns.
769 // It assumes that most of the columns or rows have default size and so stores
770 // the default size separately and uses a hash to map column or row numbers to
771 // their non default size for those which don't have the default size.
772 // ----------------------------------------------------------------------------
774 // Hashmap to store postions as the keys and sizes as the values
775 WX_DECLARE_HASH_MAP_WITH_DECL( unsigned, int, wxIntegerHash
, wxIntegerEqual
,
776 wxUnsignedToIntHashMap
, class WXDLLIMPEXP_ADV
);
778 struct WXDLLIMPEXP_ADV wxGridSizesInfo
780 // default ctor, initialize m_sizeDefault and m_customSizes later
781 wxGridSizesInfo() { }
783 // ctor used by wxGrid::Get{Col,Row}Sizes()
784 wxGridSizesInfo(int defSize
, const wxArrayInt
& allSizes
);
786 // default copy ctor, assignment operator and dtor are ok
788 // Get the size of the element with the given index
789 int GetSize(unsigned pos
) const;
795 // position -> size map containing all elements with non-default size
796 wxUnsignedToIntHashMap m_customSizes
;
799 // ----------------------------------------------------------------------------
801 // ----------------------------------------------------------------------------
803 class WXDLLIMPEXP_ADV wxGrid
: public wxScrolledWindow
806 // possible selection modes
807 enum wxGridSelectionModes
809 wxGridSelectCells
= 0, // allow selecting anything
810 wxGridSelectRows
= 1, // allow selecting only entire rows
811 wxGridSelectColumns
= 2, // allow selecting only entire columns
812 wxGridSelectRowsOrColumns
= wxGridSelectRows
| wxGridSelectColumns
815 // creation and destruction
816 // ------------------------
818 // ctor and Create() create the grid window, as with the other controls
821 wxGrid(wxWindow
*parent
,
823 const wxPoint
& pos
= wxDefaultPosition
,
824 const wxSize
& size
= wxDefaultSize
,
825 long style
= wxWANTS_CHARS
,
826 const wxString
& name
= wxGridNameStr
)
830 Create(parent
, id
, pos
, size
, style
, name
);
833 bool Create(wxWindow
*parent
,
835 const wxPoint
& pos
= wxDefaultPosition
,
836 const wxSize
& size
= wxDefaultSize
,
837 long style
= wxWANTS_CHARS
,
838 const wxString
& name
= wxGridNameStr
);
842 // however to initialize grid data either CreateGrid() or SetTable() must
845 // this is basically equivalent to
847 // SetTable(new wxGridStringTable(numRows, numCols), true, selmode)
849 bool CreateGrid( int numRows
, int numCols
,
850 wxGridSelectionModes selmode
= wxGridSelectCells
);
852 bool SetTable( wxGridTableBase
*table
,
853 bool takeOwnership
= false,
854 wxGridSelectionModes selmode
= wxGridSelectCells
);
856 bool ProcessTableMessage(wxGridTableMessage
&);
858 wxGridTableBase
*GetTable() const { return m_table
; }
861 void SetSelectionMode(wxGridSelectionModes selmode
);
862 wxGridSelectionModes
GetSelectionMode() const;
864 // ------ grid dimensions
866 int GetNumberRows() const { return m_numRows
; }
867 int GetNumberCols() const { return m_numCols
; }
870 // ------ display update functions
872 wxArrayInt
CalcRowLabelsExposed( const wxRegion
& reg
) const;
874 wxArrayInt
CalcColLabelsExposed( const wxRegion
& reg
) const;
875 wxGridCellCoordsArray
CalcCellsExposed( const wxRegion
& reg
) const;
879 bool InsertRows(int pos
= 0, int numRows
= 1, bool updateLabels
= true)
881 return DoModifyLines(&wxGridTableBase::InsertRows
,
882 pos
, numRows
, updateLabels
);
884 bool InsertCols(int pos
= 0, int numCols
= 1, bool updateLabels
= true)
886 return DoModifyLines(&wxGridTableBase::InsertCols
,
887 pos
, numCols
, updateLabels
);
890 bool AppendRows(int numRows
= 1, bool updateLabels
= true)
892 return DoAppendLines(&wxGridTableBase::AppendRows
, numRows
, updateLabels
);
894 bool AppendCols(int numCols
= 1, bool updateLabels
= true)
896 return DoAppendLines(&wxGridTableBase::AppendCols
, numCols
, updateLabels
);
899 bool DeleteRows(int pos
= 0, int numRows
= 1, bool updateLabels
= true)
901 return DoModifyLines(&wxGridTableBase::DeleteRows
,
902 pos
, numRows
, updateLabels
);
904 bool DeleteCols(int pos
= 0, int numCols
= 1, bool updateLabels
= true)
906 return DoModifyLines(&wxGridTableBase::DeleteCols
,
907 pos
, numCols
, updateLabels
);
910 void DrawGridCellArea( wxDC
& dc
, const wxGridCellCoordsArray
& cells
);
911 void DrawGridSpace( wxDC
& dc
);
912 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
913 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
914 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
915 void DrawHighlight(wxDC
& dc
, const wxGridCellCoordsArray
& cells
);
917 // this function is called when the current cell highlight must be redrawn
918 // and may be overridden by the user
919 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
921 virtual void DrawRowLabels( wxDC
& dc
, const wxArrayInt
& rows
);
922 virtual void DrawRowLabel( wxDC
& dc
, int row
);
924 virtual void DrawColLabels( wxDC
& dc
, const wxArrayInt
& cols
);
925 virtual void DrawColLabel( wxDC
& dc
, int col
);
927 virtual void DrawCornerLabel(wxDC
& dc
);
929 // ------ Cell text drawing functions
931 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
932 int horizontalAlignment
= wxALIGN_LEFT
,
933 int verticalAlignment
= wxALIGN_TOP
,
934 int textOrientation
= wxHORIZONTAL
);
936 void DrawTextRectangle( wxDC
& dc
, const wxArrayString
& lines
, const wxRect
&,
937 int horizontalAlignment
= wxALIGN_LEFT
,
938 int verticalAlignment
= wxALIGN_TOP
,
939 int textOrientation
= wxHORIZONTAL
);
942 // Split a string containing newline characters into an array of
943 // strings and return the number of lines
945 void StringToLines( const wxString
& value
, wxArrayString
& lines
) const;
947 void GetTextBoxSize( const wxDC
& dc
,
948 const wxArrayString
& lines
,
949 long *width
, long *height
) const;
953 // Code that does a lot of grid modification can be enclosed
954 // between BeginBatch() and EndBatch() calls to avoid screen
957 void BeginBatch() { m_batchCount
++; }
960 int GetBatchCount() { return m_batchCount
; }
962 virtual void Refresh(bool eraseb
= true, const wxRect
* rect
= NULL
);
964 // Use this, rather than wxWindow::Refresh(), to force an
965 // immediate repainting of the grid. Has no effect if you are
966 // already inside a BeginBatch / EndBatch block.
968 // This function is necessary because wxGrid has a minimal OnPaint()
969 // handler to reduce screen flicker.
974 // ------ edit control functions
976 bool IsEditable() const { return m_editable
; }
977 void EnableEditing( bool edit
);
979 void EnableCellEditControl( bool enable
= true );
980 void DisableCellEditControl() { EnableCellEditControl(false); }
981 bool CanEnableCellControl() const;
982 bool IsCellEditControlEnabled() const;
983 bool IsCellEditControlShown() const;
985 bool IsCurrentCellReadOnly() const;
987 void ShowCellEditControl();
988 void HideCellEditControl();
989 void SaveEditControlValue();
992 // ------ grid location functions
993 // Note that all of these functions work with the logical coordinates of
994 // grid cells and labels so you will need to convert from device
995 // coordinates for mouse events etc.
997 wxGridCellCoords
XYToCell(int x
, int y
) const;
998 void XYToCell(int x
, int y
, wxGridCellCoords
& coords
) const
999 { coords
= XYToCell(x
, y
); }
1000 wxGridCellCoords
XYToCell(const wxPoint
& pos
) const
1001 { return XYToCell(pos
.x
, pos
.y
); }
1003 // these functions return the index of the row/columns corresponding to the
1004 // given logical position in pixels
1006 // if clipToMinMax is false (default, wxNOT_FOUND is returned if the
1007 // position is outside any row/column, otherwise the first/last element is
1008 // returned in this case
1009 int YToRow( int y
, bool clipToMinMax
= false ) const;
1010 int XToCol( int x
, bool clipToMinMax
= false ) const;
1012 int YToEdgeOfRow( int y
) const;
1013 int XToEdgeOfCol( int x
) const;
1015 wxRect
CellToRect( int row
, int col
) const;
1016 wxRect
CellToRect( const wxGridCellCoords
& coords
) const
1017 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
1019 int GetGridCursorRow() const { return m_currentCellCoords
.GetRow(); }
1020 int GetGridCursorCol() const { return m_currentCellCoords
.GetCol(); }
1022 // check to see if a cell is either wholly visible (the default arg) or
1023 // at least partially visible in the grid window
1025 bool IsVisible( int row
, int col
, bool wholeCellVisible
= true ) const;
1026 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= true ) const
1027 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
1028 void MakeCellVisible( int row
, int col
);
1029 void MakeCellVisible( const wxGridCellCoords
& coords
)
1030 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
1033 // ------ grid cursor movement functions
1035 void SetGridCursor(int row
, int col
) { SetCurrentCell(row
, col
); }
1036 void SetGridCursor(const wxGridCellCoords
& c
) { SetCurrentCell(c
); }
1038 void GoToCell(int row
, int col
)
1040 if ( SetCurrentCell(row
, col
) )
1041 MakeCellVisible(row
, col
);
1044 void GoToCell(const wxGridCellCoords
& coords
)
1046 if ( SetCurrentCell(coords
) )
1047 MakeCellVisible(coords
);
1050 bool MoveCursorUp( bool expandSelection
);
1051 bool MoveCursorDown( bool expandSelection
);
1052 bool MoveCursorLeft( bool expandSelection
);
1053 bool MoveCursorRight( bool expandSelection
);
1054 bool MovePageDown();
1056 bool MoveCursorUpBlock( bool expandSelection
);
1057 bool MoveCursorDownBlock( bool expandSelection
);
1058 bool MoveCursorLeftBlock( bool expandSelection
);
1059 bool MoveCursorRightBlock( bool expandSelection
);
1062 // ------ label and gridline formatting
1064 int GetDefaultRowLabelSize() const { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
1065 int GetRowLabelSize() const { return m_rowLabelWidth
; }
1066 int GetDefaultColLabelSize() const { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
1067 int GetColLabelSize() const { return m_colLabelHeight
; }
1068 wxColour
GetLabelBackgroundColour() const { return m_labelBackgroundColour
; }
1069 wxColour
GetLabelTextColour() const { return m_labelTextColour
; }
1070 wxFont
GetLabelFont() const { return m_labelFont
; }
1071 void GetRowLabelAlignment( int *horiz
, int *vert
) const;
1072 void GetColLabelAlignment( int *horiz
, int *vert
) const;
1073 int GetColLabelTextOrientation() const;
1074 wxString
GetRowLabelValue( int row
) const;
1075 wxString
GetColLabelValue( int col
) const;
1077 wxColour
GetCellHighlightColour() const { return m_cellHighlightColour
; }
1078 int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth
; }
1079 int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth
; }
1081 // this one will use wxHeaderCtrl for the column labels
1082 void UseNativeColHeader(bool native
= true);
1084 // this one will still draw them manually but using the native renderer
1085 // instead of using the same appearance as for the row labels
1086 void SetUseNativeColLabels( bool native
= true );
1088 void SetRowLabelSize( int width
);
1089 void SetColLabelSize( int height
);
1090 void HideRowLabels() { SetRowLabelSize( 0 ); }
1091 void HideColLabels() { SetColLabelSize( 0 ); }
1092 void SetLabelBackgroundColour( const wxColour
& );
1093 void SetLabelTextColour( const wxColour
& );
1094 void SetLabelFont( const wxFont
& );
1095 void SetRowLabelAlignment( int horiz
, int vert
);
1096 void SetColLabelAlignment( int horiz
, int vert
);
1097 void SetColLabelTextOrientation( int textOrientation
);
1098 void SetRowLabelValue( int row
, const wxString
& );
1099 void SetColLabelValue( int col
, const wxString
& );
1100 void SetCellHighlightColour( const wxColour
& );
1101 void SetCellHighlightPenWidth(int width
);
1102 void SetCellHighlightROPenWidth(int width
);
1104 void EnableDragRowSize( bool enable
= true );
1105 void DisableDragRowSize() { EnableDragRowSize( false ); }
1106 bool CanDragRowSize() const { return m_canDragRowSize
; }
1107 void EnableDragColSize( bool enable
= true );
1108 void DisableDragColSize() { EnableDragColSize( false ); }
1109 bool CanDragColSize() const { return m_canDragColSize
; }
1110 void EnableDragColMove( bool enable
= true );
1111 void DisableDragColMove() { EnableDragColMove( false ); }
1112 bool CanDragColMove() const { return m_canDragColMove
; }
1113 void EnableDragGridSize(bool enable
= true);
1114 void DisableDragGridSize() { EnableDragGridSize(false); }
1115 bool CanDragGridSize() const { return m_canDragGridSize
; }
1117 void EnableDragCell( bool enable
= true );
1118 void DisableDragCell() { EnableDragCell( false ); }
1119 bool CanDragCell() const { return m_canDragCell
; }
1125 // enable or disable drawing of the lines
1126 void EnableGridLines(bool enable
= true);
1127 bool GridLinesEnabled() const { return m_gridLinesEnabled
; }
1129 // by default grid lines stop at last column/row, but this may be changed
1130 void ClipHorzGridLines(bool clip
)
1131 { DoClipGridLines(m_gridLinesClipHorz
, clip
); }
1132 void ClipVertGridLines(bool clip
)
1133 { DoClipGridLines(m_gridLinesClipVert
, clip
); }
1134 bool AreHorzGridLinesClipped() const { return m_gridLinesClipHorz
; }
1135 bool AreVertGridLinesClipped() const { return m_gridLinesClipVert
; }
1137 // this can be used to change the global grid lines colour
1138 void SetGridLineColour(const wxColour
& col
);
1139 wxColour
GetGridLineColour() const { return m_gridLineColour
; }
1141 // these methods may be overridden to customize individual grid lines
1143 virtual wxPen
GetDefaultGridLinePen();
1144 virtual wxPen
GetRowGridLinePen(int row
);
1145 virtual wxPen
GetColGridLinePen(int col
);
1151 // this sets the specified attribute for this cell or in this row/col
1152 void SetAttr(int row
, int col
, wxGridCellAttr
*attr
);
1153 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
1154 void SetColAttr(int col
, wxGridCellAttr
*attr
);
1156 // returns the attribute we may modify in place: a new one if this cell
1157 // doesn't have any yet or the existing one if it does
1159 // DecRef() must be called on the returned pointer, as usual
1160 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1163 // shortcuts for setting the column parameters
1165 // set the format for the data in the column: default is string
1166 void SetColFormatBool(int col
);
1167 void SetColFormatNumber(int col
);
1168 void SetColFormatFloat(int col
, int width
= -1, int precision
= -1);
1169 void SetColFormatCustom(int col
, const wxString
& typeName
);
1171 // ------ row and col formatting
1173 int GetDefaultRowSize() const;
1174 int GetRowSize( int row
) const;
1175 bool IsRowShown(int row
) const { return GetRowSize(row
) != 0; }
1176 int GetDefaultColSize() const;
1177 int GetColSize( int col
) const;
1178 bool IsColShown(int col
) const { return GetColSize(col
) != 0; }
1179 wxColour
GetDefaultCellBackgroundColour() const;
1180 wxColour
GetCellBackgroundColour( int row
, int col
) const;
1181 wxColour
GetDefaultCellTextColour() const;
1182 wxColour
GetCellTextColour( int row
, int col
) const;
1183 wxFont
GetDefaultCellFont() const;
1184 wxFont
GetCellFont( int row
, int col
) const;
1185 void GetDefaultCellAlignment( int *horiz
, int *vert
) const;
1186 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
) const;
1187 bool GetDefaultCellOverflow() const;
1188 bool GetCellOverflow( int row
, int col
) const;
1189 void GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
) const;
1190 wxSize
GetCellSize(const wxGridCellCoords
& coords
)
1193 GetCellSize(coords
.GetRow(), coords
.GetCol(), &s
.x
, &s
.y
);
1197 // ------ row and col sizes
1198 void SetDefaultRowSize( int height
, bool resizeExistingRows
= false );
1199 void SetRowSize( int row
, int height
);
1200 void HideRow(int row
) { SetRowSize(row
, 0); }
1201 void ShowRow(int row
) { SetRowSize(row
, -1); }
1203 void SetDefaultColSize( int width
, bool resizeExistingCols
= false );
1204 void SetColSize( int col
, int width
);
1205 void HideCol(int col
) { SetColSize(col
, 0); }
1206 void ShowCol(int col
) { SetColSize(col
, -1); }
1208 // the row and column sizes can be also set all at once using
1209 // wxGridSizesInfo which holds all of them at once
1211 wxGridSizesInfo
GetColSizes() const
1212 { return wxGridSizesInfo(GetDefaultColSize(), m_colWidths
); }
1213 wxGridSizesInfo
GetRowSizes() const
1214 { return wxGridSizesInfo(GetDefaultRowSize(), m_rowHeights
); }
1216 void SetColSizes(const wxGridSizesInfo
& sizeInfo
);
1217 void SetRowSizes(const wxGridSizesInfo
& sizeInfo
);
1220 // ------- columns (only, for now) reordering
1222 // columns index <-> positions mapping: by default, the position of the
1223 // column is the same as its index, but the columns can also be reordered
1224 // (either by calling SetColPos() explicitly or by the user dragging the
1225 // columns around) in which case their indices don't correspond to their
1226 // positions on display any longer
1228 // internally we always work with indices except for the functions which
1229 // have "Pos" in their names (and which work with columns, not pixels) and
1230 // only the display and hit testing code really cares about display
1233 // set the positions of all columns at once (this method uses the same
1234 // conventions as wxHeaderCtrl::SetColumnsOrder() for the order array)
1235 void SetColumnsOrder(const wxArrayInt
& order
);
1237 // return the column index corresponding to the given (valid) position
1238 int GetColAt(int pos
) const
1240 return m_colAt
.empty() ? pos
: m_colAt
[pos
];
1243 // reorder the columns so that the column with the given index is now shown
1244 // as the position pos
1245 void SetColPos(int idx
, int pos
);
1247 // return the position at which the column with the given index is
1248 // displayed: notice that this is a slow operation as we don't maintain the
1249 // reverse mapping currently
1250 int GetColPos(int idx
) const
1252 if ( m_colAt
.IsEmpty() )
1255 for ( int i
= 0; i
< m_numCols
; i
++ )
1257 if ( m_colAt
[i
] == idx
)
1261 wxFAIL_MSG( "invalid column index" );
1266 // reset the columns positions to the default order
1270 // automatically size the column or row to fit to its contents, if
1271 // setAsMin is true, this optimal width will also be set as minimal width
1273 void AutoSizeColumn( int col
, bool setAsMin
= true )
1274 { AutoSizeColOrRow(col
, setAsMin
, wxGRID_COLUMN
); }
1275 void AutoSizeRow( int row
, bool setAsMin
= true )
1276 { AutoSizeColOrRow(row
, setAsMin
, wxGRID_ROW
); }
1278 // auto size all columns (very ineffective for big grids!)
1279 void AutoSizeColumns( bool setAsMin
= true )
1280 { (void)SetOrCalcColumnSizes(false, setAsMin
); }
1282 void AutoSizeRows( bool setAsMin
= true )
1283 { (void)SetOrCalcRowSizes(false, setAsMin
); }
1285 // auto size the grid, that is make the columns/rows of the "right" size
1286 // and also set the grid size to just fit its contents
1289 // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize:
1290 // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column
1291 // instead of data column. Note that this operation may be slow for large
1293 // autosize row height depending on label text
1294 void AutoSizeRowLabelSize( int row
);
1296 // autosize column width depending on label text
1297 void AutoSizeColLabelSize( int col
);
1299 // column won't be resized to be lesser width - this must be called during
1300 // the grid creation because it won't resize the column if it's already
1301 // narrower than the minimal width
1302 void SetColMinimalWidth( int col
, int width
);
1303 void SetRowMinimalHeight( int row
, int width
);
1305 /* These members can be used to query and modify the minimal
1306 * acceptable size of grid rows and columns. Call this function in
1307 * your code which creates the grid if you want to display cells
1308 * with a size smaller than the default acceptable minimum size.
1309 * Like the members SetColMinimalWidth and SetRowMinimalWidth,
1310 * the existing rows or columns will not be checked/resized.
1312 void SetColMinimalAcceptableWidth( int width
);
1313 void SetRowMinimalAcceptableHeight( int width
);
1314 int GetColMinimalAcceptableWidth() const;
1315 int GetRowMinimalAcceptableHeight() const;
1317 void SetDefaultCellBackgroundColour( const wxColour
& );
1318 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1319 void SetDefaultCellTextColour( const wxColour
& );
1321 void SetCellTextColour( int row
, int col
, const wxColour
& );
1322 void SetDefaultCellFont( const wxFont
& );
1323 void SetCellFont( int row
, int col
, const wxFont
& );
1324 void SetDefaultCellAlignment( int horiz
, int vert
);
1325 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1326 void SetDefaultCellOverflow( bool allow
);
1327 void SetCellOverflow( int row
, int col
, bool allow
);
1328 void SetCellSize( int row
, int col
, int num_rows
, int num_cols
);
1330 // takes ownership of the pointer
1331 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1332 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1333 wxGridCellRenderer
*GetDefaultRenderer() const;
1334 wxGridCellRenderer
* GetCellRenderer(int row
, int col
) const;
1336 // takes ownership of the pointer
1337 void SetDefaultEditor(wxGridCellEditor
*editor
);
1338 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1339 wxGridCellEditor
*GetDefaultEditor() const;
1340 wxGridCellEditor
* GetCellEditor(int row
, int col
) const;
1344 // ------ cell value accessors
1346 wxString
GetCellValue( int row
, int col
) const
1350 return m_table
->GetValue( row
, col
);
1354 return wxEmptyString
;
1358 wxString
GetCellValue( const wxGridCellCoords
& coords
) const
1359 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1361 void SetCellValue( int row
, int col
, const wxString
& s
);
1362 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1363 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1365 // returns true if the cell can't be edited
1366 bool IsReadOnly(int row
, int col
) const;
1368 // make the cell editable/readonly
1369 void SetReadOnly(int row
, int col
, bool isReadOnly
= true);
1371 // ------ select blocks of cells
1373 void SelectRow( int row
, bool addToSelected
= false );
1374 void SelectCol( int col
, bool addToSelected
= false );
1376 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
1377 bool addToSelected
= false );
1379 void SelectBlock( const wxGridCellCoords
& topLeft
,
1380 const wxGridCellCoords
& bottomRight
,
1381 bool addToSelected
= false )
1382 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1383 bottomRight
.GetRow(), bottomRight
.GetCol(),
1388 bool IsSelection() const;
1390 // ------ deselect blocks or cells
1392 void DeselectRow( int row
);
1393 void DeselectCol( int col
);
1394 void DeselectCell( int row
, int col
);
1396 void ClearSelection();
1398 bool IsInSelection( int row
, int col
) const;
1400 bool IsInSelection( const wxGridCellCoords
& coords
) const
1401 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1403 wxGridCellCoordsArray
GetSelectedCells() const;
1404 wxGridCellCoordsArray
GetSelectionBlockTopLeft() const;
1405 wxGridCellCoordsArray
GetSelectionBlockBottomRight() const;
1406 wxArrayInt
GetSelectedRows() const;
1407 wxArrayInt
GetSelectedCols() const;
1409 // This function returns the rectangle that encloses the block of cells
1410 // limited by TopLeft and BottomRight cell in device coords and clipped
1411 // to the client size of the grid window.
1413 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1414 const wxGridCellCoords
& bottomRight
) const;
1416 // Access or update the selection fore/back colours
1417 wxColour
GetSelectionBackground() const
1418 { return m_selectionBackground
; }
1419 wxColour
GetSelectionForeground() const
1420 { return m_selectionForeground
; }
1422 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1423 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1426 // Methods for a registry for mapping data types to Renderers/Editors
1427 void RegisterDataType(const wxString
& typeName
,
1428 wxGridCellRenderer
* renderer
,
1429 wxGridCellEditor
* editor
);
1431 virtual wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1432 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1433 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1434 virtual wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1435 virtual wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1436 virtual wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1438 // grid may occupy more space than needed for its rows/columns, this
1439 // function allows to set how big this extra space is
1440 void SetMargins(int extraWidth
, int extraHeight
)
1442 m_extraWidth
= extraWidth
;
1443 m_extraHeight
= extraHeight
;
1448 // Accessors for component windows
1449 wxWindow
* GetGridWindow() const { return (wxWindow
*)m_gridWin
; }
1450 wxWindow
* GetGridRowLabelWindow() const { return (wxWindow
*)m_rowLabelWin
; }
1451 wxWindow
* GetGridColLabelWindow() const { return m_colWindow
; }
1452 wxWindow
* GetGridCornerLabelWindow() const { return (wxWindow
*)m_cornerLabelWin
; }
1454 // This one can only be called if we are using the native header window
1455 wxHeaderCtrl
*GetGridColHeader() const
1457 wxASSERT_MSG( m_useNativeHeader
, "no column header window" );
1459 // static_cast<> doesn't work without the full class declaration in
1460 // view and we prefer to avoid adding more compile-time dependencies
1461 // even at the cost of using reinterpret_cast<>
1462 return reinterpret_cast<wxHeaderCtrl
*>(m_colWindow
);
1465 // Allow adjustment of scroll increment. The default is (15, 15).
1466 void SetScrollLineX(int x
) { m_scrollLineX
= x
; }
1467 void SetScrollLineY(int y
) { m_scrollLineY
= y
; }
1468 int GetScrollLineX() const { return m_scrollLineX
; }
1469 int GetScrollLineY() const { return m_scrollLineY
; }
1471 // ------- drag and drop
1472 #if wxUSE_DRAG_AND_DROP
1473 virtual void SetDropTarget(wxDropTarget
*dropTarget
);
1474 #endif // wxUSE_DRAG_AND_DROP
1477 // ------- sorting support
1479 // wxGrid doesn't support sorting on its own but it can indicate the sort
1480 // order in the column header (currently only if native header control is
1483 // return the column currently displaying the sort indicator or wxNOT_FOUND
1485 int GetSortingColumn() const { return m_sortCol
; }
1487 // return true if this column is currently used for sorting
1488 bool IsSortingBy(int col
) const { return GetSortingColumn() == col
; }
1490 // return the current sorting order (on GetSortingColumn()): true for
1491 // ascending sort and false for descending; it doesn't make sense to call
1492 // it if GetSortingColumn() returns wxNOT_FOUND
1493 bool IsSortOrderAscending() const { return m_sortIsAscending
; }
1495 // set the sorting column (or unsets any existing one if wxNOT_FOUND) and
1496 // the order in which to sort
1497 void SetSortingColumn(int col
, bool ascending
= true);
1499 // unset any existing sorting column
1500 void UnsetSortingColumn() { SetSortingColumn(wxNOT_FOUND
); }
1502 #ifdef WXWIN_COMPATIBILITY_2_8
1503 // ------ For compatibility with previous wxGrid only...
1505 // ************************************************
1506 // ** Don't use these in new code because they **
1507 // ** are liable to disappear in a future **
1509 // ************************************************
1512 wxGrid( wxWindow
*parent
,
1513 int x
, int y
, int w
= wxDefaultCoord
, int h
= wxDefaultCoord
,
1514 long style
= wxWANTS_CHARS
,
1515 const wxString
& name
= wxPanelNameStr
)
1518 Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(w
, h
), style
, name
);
1521 void SetCellValue( const wxString
& val
, int row
, int col
)
1522 { SetCellValue( row
, col
, val
); }
1524 void UpdateDimensions()
1525 { CalcDimensions(); }
1527 int GetRows() const { return GetNumberRows(); }
1528 int GetCols() const { return GetNumberCols(); }
1529 int GetCursorRow() const { return GetGridCursorRow(); }
1530 int GetCursorColumn() const { return GetGridCursorCol(); }
1532 int GetScrollPosX() const { return 0; }
1533 int GetScrollPosY() const { return 0; }
1535 void SetScrollX( int WXUNUSED(x
) ) { }
1536 void SetScrollY( int WXUNUSED(y
) ) { }
1538 void SetColumnWidth( int col
, int width
)
1539 { SetColSize( col
, width
); }
1541 int GetColumnWidth( int col
) const
1542 { return GetColSize( col
); }
1544 void SetRowHeight( int row
, int height
)
1545 { SetRowSize( row
, height
); }
1547 // GetRowHeight() is below
1549 int GetViewHeight() const // returned num whole rows visible
1552 int GetViewWidth() const // returned num whole cols visible
1555 void SetLabelSize( int orientation
, int sz
)
1557 if ( orientation
== wxHORIZONTAL
)
1558 SetColLabelSize( sz
);
1560 SetRowLabelSize( sz
);
1563 int GetLabelSize( int orientation
) const
1565 if ( orientation
== wxHORIZONTAL
)
1566 return GetColLabelSize();
1568 return GetRowLabelSize();
1571 void SetLabelAlignment( int orientation
, int align
)
1573 if ( orientation
== wxHORIZONTAL
)
1574 SetColLabelAlignment( align
, -1 );
1576 SetRowLabelAlignment( align
, -1 );
1579 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) ) const
1582 if ( orientation
== wxHORIZONTAL
)
1584 GetColLabelAlignment( &h
, &v
);
1589 GetRowLabelAlignment( &h
, &v
);
1594 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1596 if ( orientation
== wxHORIZONTAL
)
1597 SetColLabelValue( pos
, val
);
1599 SetRowLabelValue( pos
, val
);
1602 wxString
GetLabelValue( int orientation
, int pos
) const
1604 if ( orientation
== wxHORIZONTAL
)
1605 return GetColLabelValue( pos
);
1607 return GetRowLabelValue( pos
);
1610 wxFont
GetCellTextFont() const
1611 { return m_defaultCellAttr
->GetFont(); }
1613 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1614 { return m_defaultCellAttr
->GetFont(); }
1616 void SetCellTextFont(const wxFont
& fnt
)
1617 { SetDefaultCellFont( fnt
); }
1619 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1620 { SetCellFont( row
, col
, fnt
); }
1622 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1623 { SetCellTextColour( row
, col
, val
); }
1625 void SetCellTextColour(const wxColour
& col
)
1626 { SetDefaultCellTextColour( col
); }
1628 void SetCellBackgroundColour(const wxColour
& col
)
1629 { SetDefaultCellBackgroundColour( col
); }
1631 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1632 { SetCellBackgroundColour( row
, col
, colour
); }
1634 bool GetEditable() const { return IsEditable(); }
1635 void SetEditable( bool edit
= true ) { EnableEditing( edit
); }
1636 bool GetEditInPlace() const { return IsCellEditControlEnabled(); }
1638 void SetEditInPlace(bool WXUNUSED(edit
) = true) { }
1640 void SetCellAlignment( int align
, int row
, int col
)
1641 { SetCellAlignment(row
, col
, align
, wxALIGN_CENTER
); }
1642 void SetCellAlignment( int WXUNUSED(align
) ) {}
1643 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1645 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1646 wxPen
& GetDividerPen() const;
1647 void OnActivate(bool WXUNUSED(active
)) {}
1649 // ******** End of compatibility functions **********
1653 // ------ control IDs
1654 enum { wxGRID_CELLCTRL
= 2000,
1657 // ------ control types
1658 enum { wxGRID_TEXTCTRL
= 2100,
1662 #endif // WXWIN_COMPATIBILITY_2_8
1665 // override some base class functions
1666 virtual bool Enable(bool enable
= true);
1667 virtual wxWindow
*GetMainWindowOfCompositeControl()
1668 { return (wxWindow
*)m_gridWin
; }
1671 // implementation only
1672 void CancelMouseCapture();
1675 virtual wxSize
DoGetBestSize() const;
1679 wxGridWindow
*m_gridWin
;
1680 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1681 wxGridRowLabelWindow
*m_rowLabelWin
;
1683 // the real type of the column window depends on m_useNativeHeader value:
1684 // if it is true, its dynamic type is wxHeaderCtrl, otherwise it is
1685 // wxGridColLabelWindow, use accessors below when the real type matters
1686 wxWindow
*m_colWindow
;
1688 wxGridColLabelWindow
*GetColLabelWindow() const
1690 wxASSERT_MSG( !m_useNativeHeader
, "no column label window" );
1692 return reinterpret_cast<wxGridColLabelWindow
*>(m_colWindow
);
1695 wxGridTableBase
*m_table
;
1701 wxGridCellCoords m_currentCellCoords
;
1703 // the corners of the block being currently selected or wxGridNoCellCoords
1704 wxGridCellCoords m_selectedBlockTopLeft
;
1705 wxGridCellCoords m_selectedBlockBottomRight
;
1707 // when selecting blocks of cells (either from the keyboard using Shift
1708 // with cursor keys, or by dragging the mouse), the selection is anchored
1709 // at m_currentCellCoords which defines one of the corners of the rectangle
1710 // being selected -- and this variable defines the other corner, i.e. it's
1711 // either m_selectedBlockTopLeft or m_selectedBlockBottomRight depending on
1712 // which of them is not m_currentCellCoords
1714 // if no block selection is in process, it is set to wxGridNoCellCoords
1715 wxGridCellCoords m_selectedBlockCorner
;
1717 wxGridSelection
*m_selection
;
1719 wxColour m_selectionBackground
;
1720 wxColour m_selectionForeground
;
1722 // NB: *never* access m_row/col arrays directly because they are created
1723 // on demand, *always* use accessor functions instead!
1725 // init the m_rowHeights/Bottoms arrays with default values
1726 void InitRowHeights();
1728 int m_defaultRowHeight
;
1729 int m_minAcceptableRowHeight
;
1730 wxArrayInt m_rowHeights
;
1731 wxArrayInt m_rowBottoms
;
1733 // init the m_colWidths/Rights arrays
1734 void InitColWidths();
1736 int m_defaultColWidth
;
1737 int m_minAcceptableColWidth
;
1738 wxArrayInt m_colWidths
;
1739 wxArrayInt m_colRights
;
1742 bool m_sortIsAscending
;
1744 bool m_useNativeHeader
,
1745 m_nativeColumnLabels
;
1747 // get the col/row coords
1748 int GetColWidth(int col
) const;
1749 int GetColLeft(int col
) const;
1750 int GetColRight(int col
) const;
1752 // this function must be public for compatibility...
1754 int GetRowHeight(int row
) const;
1757 int GetRowTop(int row
) const;
1758 int GetRowBottom(int row
) const;
1760 int m_rowLabelWidth
;
1761 int m_colLabelHeight
;
1763 // the size of the margin left to the right and bottom of the cell area
1767 wxColour m_labelBackgroundColour
;
1768 wxColour m_labelTextColour
;
1771 int m_rowLabelHorizAlign
;
1772 int m_rowLabelVertAlign
;
1773 int m_colLabelHorizAlign
;
1774 int m_colLabelVertAlign
;
1775 int m_colLabelTextOrientation
;
1777 bool m_defaultRowLabelValues
;
1778 bool m_defaultColLabelValues
;
1780 wxColour m_gridLineColour
;
1781 bool m_gridLinesEnabled
;
1782 bool m_gridLinesClipHorz
,
1783 m_gridLinesClipVert
;
1784 wxColour m_cellHighlightColour
;
1785 int m_cellHighlightPenWidth
;
1786 int m_cellHighlightROPenWidth
;
1789 // common part of AutoSizeColumn/Row() and GetBestSize()
1790 int SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
= true);
1791 int SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
= true);
1793 // common part of AutoSizeColumn/Row()
1794 void AutoSizeColOrRow(int n
, bool setAsMin
, wxGridDirection direction
);
1796 // Calculate the minimum acceptable size for labels area
1797 wxCoord
CalcColOrRowLabelAreaMinSize(wxGridDirection direction
);
1799 // if a column has a minimal width, it will be the value for it in this
1801 wxLongToLongHashMap m_colMinWidths
,
1804 // get the minimal width of the given column/row
1805 int GetColMinimalWidth(int col
) const;
1806 int GetRowMinimalHeight(int col
) const;
1808 // do we have some place to store attributes in?
1809 bool CanHaveAttributes() const;
1811 // cell attribute cache (currently we only cache 1, may be will do
1812 // more/better later)
1816 wxGridCellAttr
*attr
;
1819 // invalidates the attribute cache
1820 void ClearAttrCache();
1822 // adds an attribute to cache
1823 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
1825 // looks for an attr in cache, returns true if found
1826 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
1828 // looks for the attr in cache, if not found asks the table and caches the
1830 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
1831 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
) const
1832 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
1834 // the default cell attr object for cells that don't have their own
1835 wxGridCellAttr
* m_defaultCellAttr
;
1842 wxGridTypeRegistry
* m_typeRegistry
;
1846 WXGRID_CURSOR_SELECT_CELL
,
1847 WXGRID_CURSOR_RESIZE_ROW
,
1848 WXGRID_CURSOR_RESIZE_COL
,
1849 WXGRID_CURSOR_SELECT_ROW
,
1850 WXGRID_CURSOR_SELECT_COL
,
1851 WXGRID_CURSOR_MOVE_COL
1854 // this method not only sets m_cursorMode but also sets the correct cursor
1855 // for the given mode and, if captureMouse is not false releases the mouse
1856 // if it was captured and captures it if it must be captured
1858 // for this to work, you should always use it and not set m_cursorMode
1860 void ChangeCursorMode(CursorMode mode
,
1861 wxWindow
*win
= NULL
,
1862 bool captureMouse
= true);
1864 wxWindow
*m_winCapture
; // the window which captured the mouse
1866 // this variable is used not for finding the correct current cursor but
1867 // mainly for finding out what is going to happen if the mouse starts being
1868 // dragged right now
1870 // by default it is WXGRID_CURSOR_SELECT_CELL meaning that nothing else is
1871 // going on, and it is set to one of RESIZE/SELECT/MOVE values while the
1872 // corresponding operation will be started if the user starts dragging the
1873 // mouse from the current position
1874 CursorMode m_cursorMode
;
1880 bool m_canDragRowSize
;
1881 bool m_canDragColSize
;
1882 bool m_canDragColMove
;
1883 bool m_canDragGridSize
;
1886 // the last position (horizontal or vertical depending on whether the user
1887 // is resizing a column or a row) where a row or column separator line was
1888 // dragged by the user or -1 of there is no drag operation in progress
1892 // true if a drag operation is in progress; when this is true,
1893 // m_startDragPos is valid, i.e. not wxDefaultPosition
1896 // the position (in physical coordinates) where the user started dragging
1897 // the mouse or wxDefaultPosition if mouse isn't being dragged
1899 // notice that this can be != wxDefaultPosition while m_isDragging is still
1900 // false because we wait until the mouse is moved some distance away before
1901 // setting m_isDragging to true
1902 wxPoint m_startDragPos
;
1904 bool m_waitForSlowClick
;
1906 wxGridCellCoords m_selectionStart
;
1908 wxCursor m_rowResizeCursor
;
1909 wxCursor m_colResizeCursor
;
1911 bool m_editable
; // applies to whole grid
1912 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
1914 int m_scrollLineX
; // X scroll increment
1915 int m_scrollLineY
; // Y scroll increment
1917 void Init(); // common part of all ctors
1919 void CreateColumnWindow();
1920 void CalcDimensions();
1921 void CalcWindowSizes();
1922 bool Redimension( wxGridTableMessage
& );
1925 // generate the appropriate grid event and return -1 if it was vetoed, 1 if
1926 // it was processed (but not vetoed) and 0 if it wasn't processed
1927 int SendEvent(const wxEventType evtType
,
1930 int SendEvent(const wxEventType evtType
,
1931 const wxGridCellCoords
& coords
,
1933 { return SendEvent(evtType
, coords
.GetRow(), coords
.GetCol(), e
); }
1934 int SendEvent(const wxEventType evtType
,
1936 const wxString
& s
= wxString());
1937 int SendEvent(const wxEventType evtType
,
1938 const wxGridCellCoords
& coords
,
1939 const wxString
& s
= wxString())
1940 { return SendEvent(evtType
, coords
.GetRow(), coords
.GetCol(), s
); }
1941 int SendEvent(const wxEventType evtType
, const wxString
& s
= wxString())
1942 { return SendEvent(evtType
, m_currentCellCoords
, s
); }
1944 void OnPaint( wxPaintEvent
& );
1945 void OnSize( wxSizeEvent
& );
1946 void OnKeyDown( wxKeyEvent
& );
1947 void OnKeyUp( wxKeyEvent
& );
1948 void OnChar( wxKeyEvent
& );
1949 void OnEraseBackground( wxEraseEvent
& );
1952 bool SetCurrentCell( const wxGridCellCoords
& coords
);
1953 bool SetCurrentCell( int row
, int col
)
1954 { return SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1957 // this function is called to extend the block being currently selected
1958 // from mouse and keyboard event handlers
1959 void UpdateBlockBeingSelected(int topRow
, int leftCol
,
1960 int bottomRow
, int rightCol
);
1962 void UpdateBlockBeingSelected(const wxGridCellCoords
& topLeft
,
1963 const wxGridCellCoords
& bottomRight
)
1964 { UpdateBlockBeingSelected(topLeft
.GetRow(), topLeft
.GetCol(),
1965 bottomRight
.GetRow(), bottomRight
.GetCol()); }
1967 // ------ functions to get/send data (see also public functions)
1969 bool GetModelValues();
1970 bool SetModelValues();
1972 friend class WXDLLIMPEXP_FWD_ADV wxGridSelection
;
1973 friend class wxGridRowOperations
;
1974 friend class wxGridColumnOperations
;
1976 // they call our private Process{{Corner,Col,Row}Label,GridCell}MouseEvent()
1977 friend class wxGridCornerLabelWindow
;
1978 friend class wxGridColLabelWindow
;
1979 friend class wxGridRowLabelWindow
;
1980 friend class wxGridWindow
;
1982 friend class wxGridHeaderCtrl
;
1985 // implement wxScrolledWindow method to return m_gridWin size
1986 virtual wxSize
GetSizeAvailableForScrollTarget(const wxSize
& size
);
1988 // redraw the grid lines, should be called after changing their attributes
1989 void RedrawGridLines();
1991 // common part of Clip{Horz,Vert}GridLines
1992 void DoClipGridLines(bool& var
, bool clip
);
1994 // update the sorting indicator shown in the specified column (whose index
1997 // this will use GetSortingColumn() and IsSortOrderAscending() to determine
1998 // the sorting indicator to effectively show
1999 void UpdateColumnSortingIndicator(int col
);
2001 // update the grid after changing the columns order (common part of
2002 // SetColPos() and ResetColPos())
2003 void RefreshAfterColPosChange();
2006 // return the position (not index) of the column at the given logical pixel
2009 // this always returns a valid position, even if the coordinate is out of
2010 // bounds (in which case first/last column is returned)
2011 int XToPos(int x
) const;
2014 // event handlers and their helpers
2015 // --------------------------------
2017 // process mouse drag event in WXGRID_CURSOR_SELECT_CELL mode
2018 void DoGridCellDrag(wxMouseEvent
& event
,
2019 const wxGridCellCoords
& coords
,
2022 // process row/column resizing drag event
2023 void DoGridLineDrag(wxMouseEvent
& event
, const wxGridOperations
& oper
);
2025 // process mouse drag event in the grid window
2026 void DoGridDragEvent(wxMouseEvent
& event
, const wxGridCellCoords
& coords
);
2028 // process different clicks on grid cells
2029 void DoGridCellLeftDown(wxMouseEvent
& event
,
2030 const wxGridCellCoords
& coords
,
2031 const wxPoint
& pos
);
2032 void DoGridCellLeftDClick(wxMouseEvent
& event
,
2033 const wxGridCellCoords
& coords
,
2034 const wxPoint
& pos
);
2035 void DoGridCellLeftUp(wxMouseEvent
& event
, const wxGridCellCoords
& coords
);
2037 // process movement (but not dragging) event in the grid cell area
2038 void DoGridMouseMoveEvent(wxMouseEvent
& event
,
2039 const wxGridCellCoords
& coords
,
2040 const wxPoint
& pos
);
2042 // process mouse events in the grid window
2043 void ProcessGridCellMouseEvent(wxMouseEvent
& event
);
2045 // process mouse events in the row/column labels/corner windows
2046 void ProcessRowLabelMouseEvent(wxMouseEvent
& event
);
2047 void ProcessColLabelMouseEvent(wxMouseEvent
& event
);
2048 void ProcessCornerLabelMouseEvent(wxMouseEvent
& event
);
2050 void DoColHeaderClick(int col
);
2052 void DoStartResizeCol(int col
);
2053 void DoUpdateResizeCol(int x
);
2054 void DoUpdateResizeColWidth(int w
);
2055 void DoStartMoveCol(int col
);
2057 void DoEndDragResizeRow();
2058 void DoEndDragResizeCol(wxMouseEvent
*event
= NULL
);
2059 void DoEndMoveCol(int pos
);
2062 // common implementations of methods defined for both rows and columns
2063 void DeselectLine(int line
, const wxGridOperations
& oper
);
2064 void DoEndDragResizeLine(const wxGridOperations
& oper
);
2065 int PosToLinePos(int pos
, bool clipToMinMax
,
2066 const wxGridOperations
& oper
) const;
2067 int PosToLine(int pos
, bool clipToMinMax
,
2068 const wxGridOperations
& oper
) const;
2069 int PosToEdgeOfLine(int pos
, const wxGridOperations
& oper
) const;
2071 bool DoMoveCursor(bool expandSelection
,
2072 const wxGridDirectionOperations
& diroper
);
2073 bool DoMoveCursorByPage(const wxGridDirectionOperations
& diroper
);
2074 bool DoMoveCursorByBlock(bool expandSelection
,
2075 const wxGridDirectionOperations
& diroper
);
2076 void AdvanceToNextNonEmpty(wxGridCellCoords
& coords
,
2077 const wxGridDirectionOperations
& diroper
);
2079 // common part of {Insert,Delete}{Rows,Cols}
2080 bool DoModifyLines(bool (wxGridTableBase::*funcModify
)(size_t, size_t),
2081 int pos
, int num
, bool updateLabels
);
2082 // Append{Rows,Cols} is a bit different because of one less parameter
2083 bool DoAppendLines(bool (wxGridTableBase::*funcAppend
)(size_t),
2084 int num
, bool updateLabels
);
2086 // Common part of Set{Col,Row}Sizes
2087 void DoSetSizes(const wxGridSizesInfo
& sizeInfo
,
2088 const wxGridOperations
& oper
);
2090 DECLARE_DYNAMIC_CLASS( wxGrid
)
2091 DECLARE_EVENT_TABLE()
2092 wxDECLARE_NO_COPY_CLASS(wxGrid
);
2095 // ----------------------------------------------------------------------------
2096 // wxGridUpdateLocker prevents updates to a grid during its lifetime
2097 // ----------------------------------------------------------------------------
2099 class WXDLLIMPEXP_ADV wxGridUpdateLocker
2102 // if the pointer is NULL, Create() can be called later
2103 wxGridUpdateLocker(wxGrid
*grid
= NULL
)
2108 // can be called if ctor was used with a NULL pointer, must not be called
2110 void Create(wxGrid
*grid
)
2112 wxASSERT_MSG( !m_grid
, _T("shouldn't be called more than once") );
2117 ~wxGridUpdateLocker()
2124 void Init(wxGrid
*grid
)
2128 m_grid
->BeginBatch();
2133 wxDECLARE_NO_COPY_CLASS(wxGridUpdateLocker
);
2136 // ----------------------------------------------------------------------------
2137 // Grid event class and event types
2138 // ----------------------------------------------------------------------------
2140 class WXDLLIMPEXP_ADV wxGridEvent
: public wxNotifyEvent
,
2141 public wxKeyboardState
2147 Init(-1, -1, -1, -1, false);
2153 int row
= -1, int col
= -1,
2154 int x
= -1, int y
= -1,
2156 const wxKeyboardState
& kbd
= wxKeyboardState())
2157 : wxNotifyEvent(type
, id
),
2158 wxKeyboardState(kbd
)
2160 Init(row
, col
, x
, y
, sel
);
2161 SetEventObject(obj
);
2164 // explicitly specifying inline allows gcc < 3.4 to
2165 // handle the deprecation attribute even in the constructor.
2166 wxDEPRECATED_CONSTRUCTOR(
2174 bool shift
= false, bool alt
= false, bool meta
= false));
2176 virtual int GetRow() { return m_row
; }
2177 virtual int GetCol() { return m_col
; }
2178 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
2179 bool Selecting() { return m_selecting
; }
2181 virtual wxEvent
*Clone() const { return new wxGridEvent(*this); }
2191 void Init(int row
, int col
, int x
, int y
, bool sel
)
2200 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent
)
2203 class WXDLLIMPEXP_ADV wxGridSizeEvent
: public wxNotifyEvent
,
2204 public wxKeyboardState
2213 wxGridSizeEvent(int id
,
2217 int x
= -1, int y
= -1,
2218 const wxKeyboardState
& kbd
= wxKeyboardState())
2219 : wxNotifyEvent(type
, id
),
2220 wxKeyboardState(kbd
)
2222 Init(rowOrCol
, x
, y
);
2224 SetEventObject(obj
);
2227 wxDEPRECATED_CONSTRUCTOR(
2228 wxGridSizeEvent(int id
,
2236 bool meta
= false) );
2238 int GetRowOrCol() { return m_rowOrCol
; }
2239 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
2241 virtual wxEvent
*Clone() const { return new wxGridSizeEvent(*this); }
2249 void Init(int rowOrCol
, int x
, int y
)
2251 m_rowOrCol
= rowOrCol
;
2256 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent
)
2260 class WXDLLIMPEXP_ADV wxGridRangeSelectEvent
: public wxNotifyEvent
,
2261 public wxKeyboardState
2264 wxGridRangeSelectEvent()
2267 Init(wxGridNoCellCoords
, wxGridNoCellCoords
, false);
2270 wxGridRangeSelectEvent(int id
,
2273 const wxGridCellCoords
& topLeft
,
2274 const wxGridCellCoords
& bottomRight
,
2276 const wxKeyboardState
& kbd
= wxKeyboardState())
2277 : wxNotifyEvent(type
, id
),
2278 wxKeyboardState(kbd
)
2280 Init(topLeft
, bottomRight
, sel
);
2282 SetEventObject(obj
);
2285 wxDEPRECATED_CONSTRUCTOR(
2286 wxGridRangeSelectEvent(int id
,
2289 const wxGridCellCoords
& topLeft
,
2290 const wxGridCellCoords
& bottomRight
,
2295 bool meta
= false) );
2297 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
2298 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
2299 int GetTopRow() { return m_topLeft
.GetRow(); }
2300 int GetBottomRow() { return m_bottomRight
.GetRow(); }
2301 int GetLeftCol() { return m_topLeft
.GetCol(); }
2302 int GetRightCol() { return m_bottomRight
.GetCol(); }
2303 bool Selecting() { return m_selecting
; }
2305 virtual wxEvent
*Clone() const { return new wxGridRangeSelectEvent(*this); }
2308 void Init(const wxGridCellCoords
& topLeft
,
2309 const wxGridCellCoords
& bottomRight
,
2312 m_topLeft
= topLeft
;
2313 m_bottomRight
= bottomRight
;
2314 m_selecting
= selecting
;
2317 wxGridCellCoords m_topLeft
;
2318 wxGridCellCoords m_bottomRight
;
2321 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent
)
2325 class WXDLLIMPEXP_ADV wxGridEditorCreatedEvent
: public wxCommandEvent
2328 wxGridEditorCreatedEvent()
2336 wxGridEditorCreatedEvent(int id
, wxEventType type
, wxObject
* obj
,
2337 int row
, int col
, wxControl
* ctrl
);
2339 int GetRow() { return m_row
; }
2340 int GetCol() { return m_col
; }
2341 wxControl
* GetControl() { return m_ctrl
; }
2342 void SetRow(int row
) { m_row
= row
; }
2343 void SetCol(int col
) { m_col
= col
; }
2344 void SetControl(wxControl
* ctrl
) { m_ctrl
= ctrl
; }
2346 virtual wxEvent
*Clone() const { return new wxGridEditorCreatedEvent(*this); }
2353 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent
)
2357 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_LEFT_CLICK
, wxGridEvent
);
2358 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_RIGHT_CLICK
, wxGridEvent
);
2359 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_LEFT_DCLICK
, wxGridEvent
);
2360 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_RIGHT_DCLICK
, wxGridEvent
);
2361 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_LABEL_LEFT_CLICK
, wxGridEvent
);
2362 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_LABEL_RIGHT_CLICK
, wxGridEvent
);
2363 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_LABEL_LEFT_DCLICK
, wxGridEvent
);
2364 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_LABEL_RIGHT_DCLICK
, wxGridEvent
);
2365 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_ROW_SIZE
, wxGridSizeEvent
);
2366 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_COL_SIZE
, wxGridSizeEvent
);
2367 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_RANGE_SELECT
, wxGridRangeSelectEvent
);
2368 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_CHANGING
, wxGridEvent
);
2369 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_CHANGED
, wxGridEvent
);
2370 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_SELECT_CELL
, wxGridEvent
);
2371 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_EDITOR_SHOWN
, wxGridEvent
);
2372 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_EDITOR_HIDDEN
, wxGridEvent
);
2373 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_EDITOR_CREATED
, wxGridEditorCreatedEvent
);
2374 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_CELL_BEGIN_DRAG
, wxGridEvent
);
2375 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_COL_MOVE
, wxGridEvent
);
2376 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_GRID_COL_SORT
, wxGridEvent
);
2378 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
2379 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
2380 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
2381 typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction
)(wxGridEditorCreatedEvent
&);
2383 #define wxGridEventHandler(func) \
2384 wxEVENT_HANDLER_CAST(wxGridEventFunction, func)
2386 #define wxGridSizeEventHandler(func) \
2387 wxEVENT_HANDLER_CAST(wxGridSizeEventFunction, func)
2389 #define wxGridRangeSelectEventHandler(func) \
2390 wxEVENT_HANDLER_CAST(wxGridRangeSelectEventFunction, func)
2392 #define wxGridEditorCreatedEventHandler(func) \
2393 wxEVENT_HANDLER_CAST(wxGridEditorCreatedEventFunction, func)
2395 #define wx__DECLARE_GRIDEVT(evt, id, fn) \
2396 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn))
2398 #define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \
2399 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn))
2401 #define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \
2402 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn))
2404 #define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \
2405 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn))
2407 #define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn)
2408 #define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn)
2409 #define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn)
2410 #define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn)
2411 #define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn)
2412 #define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn)
2413 #define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn)
2414 #define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn)
2415 #define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn)
2416 #define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn)
2417 #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn)
2418 #define EVT_GRID_CMD_COL_SORT(id, fn) wx__DECLARE_GRIDEVT(COL_SORT, id, fn)
2419 #define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn)
2420 #define EVT_GRID_CMD_CELL_CHANGING(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGING, id, fn)
2421 #define EVT_GRID_CMD_CELL_CHANGED(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGED, id, fn)
2422 #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn)
2423 #define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn)
2424 #define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn)
2425 #define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn)
2426 #define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn)
2428 // same as above but for any id (exists mainly for backwards compatibility but
2429 // then it's also true that you rarely have multiple grid in the same window)
2430 #define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn)
2431 #define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn)
2432 #define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn)
2433 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn)
2434 #define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn)
2435 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn)
2436 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn)
2437 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn)
2438 #define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn)
2439 #define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn)
2440 #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn)
2441 #define EVT_GRID_COL_SORT(fn) EVT_GRID_CMD_COL_SORT(wxID_ANY, fn)
2442 #define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn)
2443 #define EVT_GRID_CELL_CHANGING(fn) EVT_GRID_CMD_CELL_CHANGING(wxID_ANY, fn)
2444 #define EVT_GRID_CELL_CHANGED(fn) EVT_GRID_CMD_CELL_CHANGED(wxID_ANY, fn)
2445 #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn)
2446 #define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn)
2447 #define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn)
2448 #define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn)
2449 #define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn)
2451 // we used to have a single wxEVT_GRID_CELL_CHANGE event but it was split into
2452 // wxEVT_GRID_CELL_CHANGING and CHANGED ones in wx 2.9.0, however the CHANGED
2453 // is basically the same as the old CHANGE event so we keep the name for
2455 #if WXWIN_COMPATIBILITY_2_8
2456 #define wxEVT_GRID_CELL_CHANGE wxEVT_GRID_CELL_CHANGED
2458 #define EVT_GRID_CMD_CELL_CHANGE EVT_GRID_CMD_CELL_CHANGED
2459 #define EVT_GRID_CELL_CHANGE EVT_GRID_CELL_CHANGED
2460 #endif // WXWIN_COMPATIBILITY_2_8
2462 #if 0 // TODO: implement these ? others ?
2464 extern const int wxEVT_GRID_CREATE_CELL
;
2465 extern const int wxEVT_GRID_CHANGE_LABELS
;
2466 extern const int wxEVT_GRID_CHANGE_SEL_LABEL
;
2468 #define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2469 #define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2470 #define EVT_GRID_CHANGE_SEL_LABEL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2474 #endif // wxUSE_GRID
2475 #endif // _WX_GENERIC_GRID_H_