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)
8 // Copyright: (c) Michael Bedward
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
14 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
22 #pragma interface "grid.h"
27 #include "wx/scrolwin.h"
28 #include "wx/string.h"
29 #include "wx/scrolbar.h"
31 #include "wx/combobox.h"
32 #include "wx/dynarray.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // Default parameters for wxGrid
41 #define WXGRID_DEFAULT_NUMBER_ROWS 10
42 #define WXGRID_DEFAULT_NUMBER_COLS 10
44 #define WXGRID_DEFAULT_ROW_HEIGHT 25
46 #define WXGRID_DEFAULT_ROW_HEIGHT 30
48 #define WXGRID_DEFAULT_COL_WIDTH 80
49 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
50 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
51 #define WXGRID_LABEL_EDGE_ZONE 5
52 #define WXGRID_MIN_ROW_HEIGHT 15
53 #define WXGRID_MIN_COL_WIDTH 15
54 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
56 // type names for grid table values
57 #define wxGRID_VALUE_STRING _T("string")
58 #define wxGRID_VALUE_BOOL _T("bool")
59 #define wxGRID_VALUE_NUMBER _T("long")
60 #define wxGRID_VALUE_FLOAT _T("double")
62 #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
63 #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
65 // ----------------------------------------------------------------------------
66 // forward declarations
67 // ----------------------------------------------------------------------------
69 class WXDLLEXPORT wxGrid
;
70 class WXDLLEXPORT wxGridCellAttr
;
71 class WXDLLEXPORT wxGridCellAttrProviderData
;
72 class WXDLLEXPORT wxGridColLabelWindow
;
73 class WXDLLEXPORT wxGridCornerLabelWindow
;
74 class WXDLLEXPORT wxGridRowLabelWindow
;
75 class WXDLLEXPORT wxGridTableBase
;
76 class WXDLLEXPORT wxGridWindow
;
77 class WXDLLEXPORT wxGridTypeRegistry
;
79 class WXDLLEXPORT wxCheckBox
;
80 class WXDLLEXPORT wxComboBox
;
81 class WXDLLEXPORT wxTextCtrl
;
82 class WXDLLEXPORT wxSpinCtrl
;
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
89 #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
91 // ----------------------------------------------------------------------------
92 // wxGridCellRenderer: this class is responsible for actually drawing the cell
93 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
94 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
95 // view of all cells. This is an ABC, you will normally use one of the
96 // predefined derived classes or derive your own class from it.
97 // ----------------------------------------------------------------------------
99 class WXDLLEXPORT wxGridCellRenderer
102 wxGridCellRenderer() { m_nRef
= 1; }
104 // this class is ref counted: it is created with ref count of 1, so
105 // calling DecRef() once will delete it. Calling IncRef() allows to lock
106 // it until the matching DecRef() is called
107 void IncRef() { m_nRef
++; }
108 void DecRef() { if ( !--m_nRef
) delete this; }
110 // draw the given cell on the provided DC inside the given rectangle
111 // using the style specified by the attribute and the default or selected
112 // state corresponding to the isSelected value.
114 // this pure virtual function has a default implementation which will
115 // prepare the DC using the given attribute: it will draw the rectangle
116 // with the bg colour from attr and set the text colour and font
117 virtual void Draw(wxGrid
& grid
,
118 wxGridCellAttr
& attr
,
122 bool isSelected
) = 0;
124 // get the preferred size of the cell for its contents
125 virtual wxSize
GetBestSize(wxGrid
& grid
,
126 wxGridCellAttr
& attr
,
128 int row
, int col
) = 0;
131 // virtual dtor for any base class - private because only DecRef() can
133 virtual ~wxGridCellRenderer();
138 // suppress the stupid gcc warning about the class having private dtor and
140 friend class wxGridCellRendererDummyFriend
;
143 // the default renderer for the cells containing string data
144 class WXDLLEXPORT wxGridCellStringRenderer
: public wxGridCellRenderer
148 virtual void Draw(wxGrid
& grid
,
149 wxGridCellAttr
& attr
,
155 // return the string extent
156 virtual wxSize
GetBestSize(wxGrid
& grid
,
157 wxGridCellAttr
& attr
,
162 // set the text colours before drawing
163 void SetTextColoursAndFont(wxGrid
& grid
,
164 wxGridCellAttr
& attr
,
168 // calc the string extent for given string/font
169 wxSize
DoGetBestSize(wxGridCellAttr
& attr
,
171 const wxString
& text
);
174 // the default renderer for the cells containing numeric (long) data
175 class WXDLLEXPORT wxGridCellNumberRenderer
: public wxGridCellStringRenderer
178 // draw the string right aligned
179 virtual void Draw(wxGrid
& grid
,
180 wxGridCellAttr
& attr
,
186 virtual wxSize
GetBestSize(wxGrid
& grid
,
187 wxGridCellAttr
& attr
,
192 wxString
GetString(wxGrid
& grid
, int row
, int col
);
195 class WXDLLEXPORT wxGridCellFloatRenderer
: public wxGridCellStringRenderer
198 wxGridCellFloatRenderer(int width
, int precision
);
200 // get/change formatting parameters
201 int GetWidth() const { return m_width
; }
202 void SetWidth(int width
) { m_width
= width
; }
203 int GetPrecision() const { return m_precision
; }
204 void SetPrecision(int precision
) { m_precision
= precision
; }
206 // draw the string right aligned with given width/precision
207 virtual void Draw(wxGrid
& grid
,
208 wxGridCellAttr
& attr
,
214 virtual wxSize
GetBestSize(wxGrid
& grid
,
215 wxGridCellAttr
& attr
,
219 wxString
GetString(wxGrid
& grid
, int row
, int col
);
222 // formatting parameters
229 // renderer for boolean fields
230 class WXDLLEXPORT wxGridCellBoolRenderer
: public wxGridCellRenderer
233 // draw a check mark or nothing
234 virtual void Draw(wxGrid
& grid
,
235 wxGridCellAttr
& attr
,
241 // return the checkmark size
242 virtual wxSize
GetBestSize(wxGrid
& grid
,
243 wxGridCellAttr
& attr
,
248 static wxSize ms_sizeCheckMark
;
251 // ----------------------------------------------------------------------------
252 // wxGridCellEditor: This class is responsible for providing and manipulating
253 // the in-place edit controls for the grid. Instances of wxGridCellEditor
254 // (actually, instances of derived classes since it is an ABC) can be
255 // associated with the cell attributes for individual cells, rows, columns, or
256 // even for the entire grid.
257 // ----------------------------------------------------------------------------
259 class WXDLLEXPORT wxGridCellEditor
264 // this class is ref counted: it is created with ref count of 1, so
265 // calling DecRef() once will delete it. Calling IncRef() allows to lock
266 // it until the matching DecRef() is called
267 void IncRef() { m_nRef
++; }
268 void DecRef() { if ( !--m_nRef
) delete this; }
270 bool IsCreated() { return m_control
!= NULL
; }
272 // Creates the actual edit control
273 virtual void Create(wxWindow
* parent
,
275 wxEvtHandler
* evtHandler
) = 0;
277 // Size and position the edit control
278 virtual void SetSize(const wxRect
& rect
);
280 // Show or hide the edit control, use the specified attributes to set
281 // colours/fonts for it
282 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
284 // Draws the part of the cell not occupied by the control: the base class
285 // version just fills it with background colour from the attribute
286 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
288 // Fetch the value from the table and prepare the edit control
289 // to begin editing. Set the focus to the edit control.
290 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
292 // Complete the editing of the current cell. Returns true if the value has
293 // changed. If necessary, the control may be destroyed.
294 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
) = 0;
296 // Reset the value in the control back to its starting value
297 virtual void Reset() = 0;
299 // If the editor is enabled by pressing keys on the grid,
300 // this will be called to let the editor do something about
301 // that first key if desired.
302 virtual void StartingKey(wxKeyEvent
& event
);
304 // if the editor is enabled by clicking on the cell, this method will be
306 virtual void StartingClick();
308 // Some types of controls on some platforms may need some help
309 // with the Return key.
310 virtual void HandleReturn(wxKeyEvent
& event
);
313 virtual void Destroy();
316 // the dtor is private because only DecRef() can delete us
317 virtual ~wxGridCellEditor();
319 // the ref count - when it goes to 0, we die
322 // the control we show on screen
323 wxControl
* m_control
;
325 // if we change the colours/font of the control from the default ones, we
326 // must restore the default later and we save them here between calls to
327 // Show(TRUE) and Show(FALSE)
332 // suppress the stupid gcc warning about the class having private dtor and
334 friend class wxGridCellEditorDummyFriend
;
337 // the editor for string/text data
338 class WXDLLEXPORT wxGridCellTextEditor
: public wxGridCellEditor
341 wxGridCellTextEditor();
343 virtual void Create(wxWindow
* parent
,
345 wxEvtHandler
* evtHandler
);
346 virtual void SetSize(const wxRect
& rect
);
348 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
350 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
351 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
353 virtual void Reset();
354 virtual void StartingKey(wxKeyEvent
& event
);
355 virtual void HandleReturn(wxKeyEvent
& event
);
358 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
360 // parts of our virtual functions reused by the derived classes
361 void DoBeginEdit(const wxString
& startValue
);
362 void DoReset(const wxString
& startValue
);
365 wxString m_startValue
;
368 // the editor for numeric (long) data
369 class WXDLLEXPORT wxGridCellNumberEditor
: public wxGridCellTextEditor
372 // allows to specify the range - if min == max == -1, no range checking is
374 wxGridCellNumberEditor(int min
= -1, int max
= -1);
376 virtual void Create(wxWindow
* parent
,
378 wxEvtHandler
* evtHandler
);
380 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
381 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
383 virtual void Reset();
384 virtual void StartingKey(wxKeyEvent
& event
);
387 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
389 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
390 bool HasRange() const { return m_min
!= m_max
; }
392 // string representation of m_valueOld
393 wxString
GetString() const
394 { return wxString::Format(_T("%ld"), m_valueOld
); }
403 // the editor for floating point numbers (double) data
404 class WXDLLEXPORT wxGridCellFloatEditor
: public wxGridCellTextEditor
407 virtual void Create(wxWindow
* parent
,
409 wxEvtHandler
* evtHandler
);
411 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
412 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
414 virtual void Reset();
415 virtual void StartingKey(wxKeyEvent
& event
);
418 // string representation of m_valueOld
419 wxString
GetString() const
420 { return wxString::Format(_T("%f"), m_valueOld
); }
426 // the editor for boolean data
427 class WXDLLEXPORT wxGridCellBoolEditor
: public wxGridCellEditor
430 virtual void Create(wxWindow
* parent
,
432 wxEvtHandler
* evtHandler
);
434 virtual void SetSize(const wxRect
& rect
);
435 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
437 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
438 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
440 virtual void Reset();
441 virtual void StartingClick();
444 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
450 // the editor for string data allowing to choose from the list of strings
451 class WXDLLEXPORT wxGridCellChoiceEditor
: public wxGridCellEditor
454 // if !allowOthers, user can't type a string not in choices array
455 wxGridCellChoiceEditor(size_t count
, const wxChar
* choices
[],
456 bool allowOthers
= FALSE
);
458 virtual void Create(wxWindow
* parent
,
460 wxEvtHandler
* evtHandler
);
462 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
464 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
465 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
467 virtual void Reset();
470 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
473 wxString m_startValue
;
474 wxArrayString m_choices
;
478 // ----------------------------------------------------------------------------
479 // wxGridCellAttr: this class can be used to alter the cells appearance in
480 // the grid by changing their colour/font/... from default. An object of this
481 // class may be returned by wxGridTable::GetAttr().
482 // ----------------------------------------------------------------------------
484 class WXDLLEXPORT wxGridCellAttr
494 // VZ: considering the number of members wxGridCellAttr has now, this ctor
495 // seems to be pretty useless... may be we should just remove it?
496 wxGridCellAttr(const wxColour
& colText
,
497 const wxColour
& colBack
,
501 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
504 SetAlignment(hAlign
, vAlign
);
507 // creates a new copy of this object
508 wxGridCellAttr
*Clone() const;
510 // this class is ref counted: it is created with ref count of 1, so
511 // calling DecRef() once will delete it. Calling IncRef() allows to lock
512 // it until the matching DecRef() is called
513 void IncRef() { m_nRef
++; }
514 void DecRef() { if ( !--m_nRef
) delete this; }
517 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
518 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
519 void SetFont(const wxFont
& font
) { m_font
= font
; }
520 void SetAlignment(int hAlign
, int vAlign
)
525 void SetReadOnly(bool isReadOnly
= TRUE
) { m_isReadOnly
= isReadOnly
; }
527 // takes ownership of the pointer
528 void SetRenderer(wxGridCellRenderer
*renderer
)
529 { wxSafeDecRef(m_renderer
); m_renderer
= renderer
; }
530 void SetEditor(wxGridCellEditor
* editor
)
531 { wxSafeDecRef(m_editor
); m_editor
= editor
; }
534 bool HasTextColour() const { return m_colText
.Ok(); }
535 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
536 bool HasFont() const { return m_font
.Ok(); }
537 bool HasAlignment() const { return m_hAlign
|| m_vAlign
; }
538 bool HasRenderer() const { return m_renderer
!= NULL
; }
539 bool HasEditor() const { return m_editor
!= NULL
; }
541 const wxColour
& GetTextColour() const;
542 const wxColour
& GetBackgroundColour() const;
543 const wxFont
& GetFont() const;
544 void GetAlignment(int *hAlign
, int *vAlign
) const;
545 wxGridCellRenderer
*GetRenderer(wxGrid
* grid
, int row
, int col
) const;
546 wxGridCellEditor
*GetEditor(wxGrid
* grid
, int row
, int col
) const;
548 bool IsReadOnly() const { return m_isReadOnly
; }
550 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
553 // the common part of all ctors
558 m_isReadOnly
= FALSE
;
564 // the dtor is private because only DecRef() can delete us
567 wxSafeDecRef(m_renderer
);
568 wxSafeDecRef(m_editor
);
571 // the ref count - when it goes to 0, we die
580 wxGridCellRenderer
* m_renderer
;
581 wxGridCellEditor
* m_editor
;
582 wxGridCellAttr
* m_defGridAttr
;
586 // use Clone() instead
587 DECLARE_NO_COPY_CLASS(wxGridCellAttr
);
589 // suppress the stupid gcc warning about the class having private dtor and
591 friend class wxGridCellAttrDummyFriend
;
594 // ----------------------------------------------------------------------------
595 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
597 // ----------------------------------------------------------------------------
599 // implementation note: we separate it from wxGridTableBase because we wish to
600 // avoid deriving a new table class if possible, and sometimes it will be
601 // enough to just derive another wxGridCellAttrProvider instead
603 // the default implementation is reasonably efficient for the generic case,
604 // but you might still wish to implement your own for some specific situations
605 // if you have performance problems with the stock one
606 class WXDLLEXPORT wxGridCellAttrProvider
609 wxGridCellAttrProvider();
610 virtual ~wxGridCellAttrProvider();
612 // DecRef() must be called on the returned pointer
613 virtual wxGridCellAttr
*GetAttr(int row
, int col
) const;
615 // all these functions take ownership of the pointer, don't call DecRef()
617 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
618 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
619 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
621 // these functions must be called whenever some rows/cols are deleted
622 // because the internal data must be updated then
623 void UpdateAttrRows( size_t pos
, int numRows
);
624 void UpdateAttrCols( size_t pos
, int numCols
);
629 wxGridCellAttrProviderData
*m_data
;
632 //////////////////////////////////////////////////////////////////////
634 // Grid table classes
636 //////////////////////////////////////////////////////////////////////
639 class WXDLLEXPORT wxGridTableBase
: public wxObject
643 virtual ~wxGridTableBase();
645 // You must override these functions in a derived table class
647 virtual long GetNumberRows() = 0;
648 virtual long GetNumberCols() = 0;
649 virtual bool IsEmptyCell( int row
, int col
) = 0;
650 virtual wxString
GetValue( int row
, int col
) = 0;
651 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
653 // Data type determination and value access
654 virtual wxString
GetTypeName( int row
, int col
);
655 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
656 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
658 virtual long GetValueAsLong( int row
, int col
);
659 virtual double GetValueAsDouble( int row
, int col
);
660 virtual bool GetValueAsBool( int row
, int col
);
662 virtual void SetValueAsLong( int row
, int col
, long value
);
663 virtual void SetValueAsDouble( int row
, int col
, double value
);
664 virtual void SetValueAsBool( int row
, int col
, bool value
);
666 // For user defined types
667 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
668 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
671 // Overriding these is optional
673 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
674 virtual wxGrid
* GetView() const { return m_view
; }
676 virtual void Clear() {}
677 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
678 virtual bool AppendRows( size_t numRows
= 1 );
679 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
680 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
681 virtual bool AppendCols( size_t numCols
= 1 );
682 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
684 virtual wxString
GetRowLabelValue( int row
);
685 virtual wxString
GetColLabelValue( int col
);
686 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
687 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
689 // Attribute handling
692 // give us the attr provider to use - we take ownership of the pointer
693 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
695 // get the currently used attr provider (may be NULL)
696 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
698 // Does this table allow attributes? Default implementation creates
699 // a wxGridCellAttrProvider if necessary.
700 virtual bool CanHaveAttributes();
703 // change row/col number in attribute if needed
704 virtual void UpdateAttrRows( size_t pos
, int numRows
);
705 virtual void UpdateAttrCols( size_t pos
, int numCols
);
707 // by default forwarded to wxGridCellAttrProvider if any. May be
708 // overridden to handle attributes directly in the table.
709 virtual wxGridCellAttr
*GetAttr( int row
, int col
);
711 // these functions take ownership of the pointer
712 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
713 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
714 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
718 wxGridCellAttrProvider
*m_attrProvider
;
720 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
724 // ----------------------------------------------------------------------------
725 // wxGridTableMessage
726 // ----------------------------------------------------------------------------
728 // IDs for messages sent from grid table to view
730 enum wxGridTableRequest
732 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
733 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
734 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
735 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
736 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
737 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
738 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
739 wxGRIDTABLE_NOTIFY_COLS_DELETED
742 class WXDLLEXPORT wxGridTableMessage
745 wxGridTableMessage();
746 wxGridTableMessage( wxGridTableBase
*table
, int id
,
750 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
751 wxGridTableBase
* GetTableObject() const { return m_table
; }
752 void SetId( int id
) { m_id
= id
; }
753 int GetId() { return m_id
; }
754 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
755 int GetCommandInt() { return m_comInt1
; }
756 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
757 int GetCommandInt2() { return m_comInt2
; }
760 wxGridTableBase
*m_table
;
768 // ------ wxGridStringArray
769 // A 2-dimensional array of strings for data values
772 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
776 // ------ wxGridStringTable
778 // Simplest type of data table for a grid for small tables of strings
779 // that are stored in memory
782 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
786 wxGridStringTable( int numRows
, int numCols
);
787 ~wxGridStringTable();
789 // these are pure virtual in wxGridTableBase
791 long GetNumberRows();
792 long GetNumberCols();
793 wxString
GetValue( int row
, int col
);
794 void SetValue( int row
, int col
, const wxString
& s
);
795 bool IsEmptyCell( int row
, int col
);
797 // overridden functions from wxGridTableBase
800 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
801 bool AppendRows( size_t numRows
= 1 );
802 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
803 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
804 bool AppendCols( size_t numCols
= 1 );
805 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
807 void SetRowLabelValue( int row
, const wxString
& );
808 void SetColLabelValue( int col
, const wxString
& );
809 wxString
GetRowLabelValue( int row
);
810 wxString
GetColLabelValue( int col
);
813 wxGridStringArray m_data
;
815 // These only get used if you set your own labels, otherwise the
816 // GetRow/ColLabelValue functions return wxGridTableBase defaults
818 wxArrayString m_rowLabels
;
819 wxArrayString m_colLabels
;
821 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
826 // ============================================================================
828 // ============================================================================
830 // ----------------------------------------------------------------------------
831 // wxGridCellCoords: location of a cell in the grid
832 // ----------------------------------------------------------------------------
834 class WXDLLEXPORT wxGridCellCoords
837 wxGridCellCoords() { m_row
= m_col
= -1; }
838 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
840 // default copy ctor is ok
842 long GetRow() const { return m_row
; }
843 void SetRow( long n
) { m_row
= n
; }
844 long GetCol() const { return m_col
; }
845 void SetCol( long n
) { m_col
= n
; }
846 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
848 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
850 if ( &other
!= this )
858 bool operator==( const wxGridCellCoords
& other
) const
860 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
863 bool operator!=( const wxGridCellCoords
& other
) const
865 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
868 bool operator!() const
870 return (m_row
== -1 && m_col
== -1 );
879 // For comparisons...
881 extern wxGridCellCoords wxGridNoCellCoords
;
882 extern wxRect wxGridNoCellRect
;
884 // An array of cell coords...
886 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
888 // ----------------------------------------------------------------------------
890 // ----------------------------------------------------------------------------
892 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
900 wxGrid( wxWindow
*parent
,
902 const wxPoint
& pos
= wxDefaultPosition
,
903 const wxSize
& size
= wxDefaultSize
,
904 long style
= wxWANTS_CHARS
,
905 const wxString
& name
= wxPanelNameStr
);
909 bool CreateGrid( int numRows
, int numCols
);
912 // ------ grid dimensions
914 int GetNumberRows() { return m_numRows
; }
915 int GetNumberCols() { return m_numCols
; }
918 // ------ display update functions
920 void CalcRowLabelsExposed( wxRegion
& reg
);
922 void CalcColLabelsExposed( wxRegion
& reg
);
923 void CalcCellsExposed( wxRegion
& reg
);
926 // ------ event handlers
928 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
929 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
930 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
931 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
932 bool ProcessTableMessage( wxGridTableMessage
& );
934 void DoEndDragResizeRow();
935 void DoEndDragResizeCol();
937 wxGridTableBase
* GetTable() const { return m_table
; }
938 bool SetTable( wxGridTableBase
*table
, bool takeOwnership
=FALSE
);
941 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
942 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
943 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
944 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
945 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
946 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
948 void DrawGridCellArea( wxDC
& dc
);
949 void DrawGridSpace( wxDC
& dc
);
950 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
951 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
952 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
953 void DrawHighlight(wxDC
& dc
);
955 // this function is called when the current cell highlight must be redrawn
956 // and may be overridden by the user
957 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
959 void DrawRowLabels( wxDC
& dc
);
960 void DrawRowLabel( wxDC
& dc
, int row
);
962 void DrawColLabels( wxDC
& dc
);
963 void DrawColLabel( wxDC
& dc
, int col
);
966 // ------ Cell text drawing functions
968 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
969 int horizontalAlignment
= wxLEFT
,
970 int verticalAlignment
= wxTOP
);
972 // Split a string containing newline chararcters into an array of
973 // strings and return the number of lines
975 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
977 void GetTextBoxSize( wxDC
& dc
,
978 wxArrayString
& lines
,
979 long *width
, long *height
);
983 // Code that does a lot of grid modification can be enclosed
984 // between BeginBatch() and EndBatch() calls to avoid screen
987 void BeginBatch() { m_batchCount
++; }
988 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
989 int GetBatchCount() { return m_batchCount
; }
992 // ------ edit control functions
994 bool IsEditable() { return m_editable
; }
995 void EnableEditing( bool edit
);
997 void EnableCellEditControl( bool enable
= TRUE
);
998 void DisableCellEditControl() { EnableCellEditControl(FALSE
); }
999 bool CanEnableCellControl() const;
1000 bool IsCellEditControlEnabled() const;
1002 bool IsCurrentCellReadOnly() const;
1004 void ShowCellEditControl();
1005 void HideCellEditControl();
1006 void SaveEditControlValue();
1009 // ------ grid location functions
1010 // Note that all of these functions work with the logical coordinates of
1011 // grid cells and labels so you will need to convert from device
1012 // coordinates for mouse events etc.
1014 void XYToCell( int x
, int y
, wxGridCellCoords
& );
1015 int YToRow( int y
);
1016 int XToCol( int x
);
1018 int YToEdgeOfRow( int y
);
1019 int XToEdgeOfCol( int x
);
1021 wxRect
CellToRect( int row
, int col
);
1022 wxRect
CellToRect( const wxGridCellCoords
& coords
)
1023 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
1025 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
1026 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
1028 // check to see if a cell is either wholly visible (the default arg) or
1029 // at least partially visible in the grid window
1031 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
1032 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
1033 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
1034 void MakeCellVisible( int row
, int col
);
1035 void MakeCellVisible( const wxGridCellCoords
& coords
)
1036 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
1039 // ------ grid cursor movement functions
1041 void SetGridCursor( int row
, int col
)
1042 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1044 bool MoveCursorUp();
1045 bool MoveCursorDown();
1046 bool MoveCursorLeft();
1047 bool MoveCursorRight();
1048 bool MovePageDown();
1050 bool MoveCursorUpBlock();
1051 bool MoveCursorDownBlock();
1052 bool MoveCursorLeftBlock();
1053 bool MoveCursorRightBlock();
1056 // ------ label and gridline formatting
1058 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
1059 int GetRowLabelSize() { return m_rowLabelWidth
; }
1060 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
1061 int GetColLabelSize() { return m_colLabelHeight
; }
1062 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
1063 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
1064 wxFont
GetLabelFont() { return m_labelFont
; }
1065 void GetRowLabelAlignment( int *horiz
, int *vert
);
1066 void GetColLabelAlignment( int *horiz
, int *vert
);
1067 wxString
GetRowLabelValue( int row
);
1068 wxString
GetColLabelValue( int col
);
1069 wxColour
GetGridLineColour() { return m_gridLineColour
; }
1071 void SetRowLabelSize( int width
);
1072 void SetColLabelSize( int height
);
1073 void SetLabelBackgroundColour( const wxColour
& );
1074 void SetLabelTextColour( const wxColour
& );
1075 void SetLabelFont( const wxFont
& );
1076 void SetRowLabelAlignment( int horiz
, int vert
);
1077 void SetColLabelAlignment( int horiz
, int vert
);
1078 void SetRowLabelValue( int row
, const wxString
& );
1079 void SetColLabelValue( int col
, const wxString
& );
1080 void SetGridLineColour( const wxColour
& );
1082 void EnableDragRowSize( bool enable
= TRUE
);
1083 void DisableDragRowSize() { EnableDragRowSize( FALSE
); }
1084 bool CanDragRowSize() { return m_canDragRowSize
; }
1085 void EnableDragColSize( bool enable
= TRUE
);
1086 void DisableDragColSize() { EnableDragColSize( FALSE
); }
1087 bool CanDragColSize() { return m_canDragColSize
; }
1088 void EnableDragGridSize(bool enable
= TRUE
);
1089 void DisableDragGridSize() { EnableDragGridSize(FALSE
); }
1090 bool CanDragGridSize() { return m_canDragGridSize
; }
1093 // this sets the specified attribute for all cells in this row/col
1094 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
1095 void SetColAttr(int col
, wxGridCellAttr
*attr
);
1097 void EnableGridLines( bool enable
= TRUE
);
1098 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
1100 // ------ row and col formatting
1102 int GetDefaultRowSize();
1103 int GetRowSize( int row
);
1104 int GetDefaultColSize();
1105 int GetColSize( int col
);
1106 wxColour
GetDefaultCellBackgroundColour();
1107 wxColour
GetCellBackgroundColour( int row
, int col
);
1108 wxColour
GetDefaultCellTextColour();
1109 wxColour
GetCellTextColour( int row
, int col
);
1110 wxFont
GetDefaultCellFont();
1111 wxFont
GetCellFont( int row
, int col
);
1112 void GetDefaultCellAlignment( int *horiz
, int *vert
);
1113 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
1115 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
1116 void SetRowSize( int row
, int height
);
1117 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
1119 void SetColSize( int col
, int width
);
1121 // automatically size the column or row to fit to its contents, if
1122 // setAsMin is TRUE, this optimal width will also be set as minimal width
1124 void AutoSizeColumn( int col
, bool setAsMin
= TRUE
)
1125 { AutoSizeColOrRow(col
, setAsMin
, TRUE
); }
1126 void AutoSizeRow( int row
, bool setAsMin
= TRUE
)
1127 { AutoSizeColOrRow(row
, setAsMin
, FALSE
); }
1129 // auto size all columns (very ineffective for big grids!)
1130 void AutoSizeColumns( bool setAsMin
= TRUE
)
1131 { (void)SetOrCalcColumnSizes(FALSE
, setAsMin
); }
1133 void AutoSizeRows( bool setAsMin
= TRUE
)
1134 { (void)SetOrCalcRowSizes(FALSE
, setAsMin
); }
1136 // auto size the grid, that is make the columns/rows of the "right" size
1137 // and also set the grid size to just fit its contents
1140 // column won't be resized to be lesser width - this must be called during
1141 // the grid creation because it won't resize the column if it's already
1142 // narrower than the minimal width
1143 void SetColMinimalWidth( int col
, int width
);
1144 void SetRowMinimalHeight( int row
, int width
);
1146 void SetDefaultCellBackgroundColour( const wxColour
& );
1147 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1148 void SetDefaultCellTextColour( const wxColour
& );
1150 void SetCellTextColour( int row
, int col
, const wxColour
& );
1151 void SetDefaultCellFont( const wxFont
& );
1152 void SetCellFont( int row
, int col
, const wxFont
& );
1153 void SetDefaultCellAlignment( int horiz
, int vert
);
1154 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1156 // takes ownership of the pointer
1157 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1158 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1159 wxGridCellRenderer
*GetDefaultRenderer() const;
1160 wxGridCellRenderer
* GetCellRenderer(int row
, int col
);
1162 // takes ownership of the pointer
1163 void SetDefaultEditor(wxGridCellEditor
*editor
);
1164 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1165 wxGridCellEditor
*GetDefaultEditor() const;
1166 wxGridCellEditor
* GetCellEditor(int row
, int col
);
1170 // ------ cell value accessors
1172 wxString
GetCellValue( int row
, int col
)
1176 return m_table
->GetValue( row
, col
);
1180 return wxEmptyString
;
1184 wxString
GetCellValue( const wxGridCellCoords
& coords
)
1185 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1187 void SetCellValue( int row
, int col
, const wxString
& s
);
1188 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1189 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1191 // returns TRUE if the cell can't be edited
1192 bool IsReadOnly(int row
, int col
) const;
1194 // make the cell editable/readonly
1195 void SetReadOnly(int row
, int col
, bool isReadOnly
= TRUE
);
1197 // ------ selections of blocks of cells
1199 void SelectRow( int row
, bool addToSelected
= FALSE
);
1200 void SelectCol( int col
, bool addToSelected
= FALSE
);
1202 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
1204 void SelectBlock( const wxGridCellCoords
& topLeft
,
1205 const wxGridCellCoords
& bottomRight
)
1206 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1207 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
1212 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
1213 m_selectedBottomRight
!= wxGridNoCellCoords
);
1216 void ClearSelection();
1218 bool IsInSelection( int row
, int col
)
1219 { return ( IsSelection() &&
1220 row
>= m_selectedTopLeft
.GetRow() &&
1221 col
>= m_selectedTopLeft
.GetCol() &&
1222 row
<= m_selectedBottomRight
.GetRow() &&
1223 col
<= m_selectedBottomRight
.GetCol() );
1226 bool IsInSelection( const wxGridCellCoords
& coords
)
1227 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1229 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
1231 // these will all be -1 if there is no selected block
1233 *topRow
= m_selectedTopLeft
.GetRow();
1234 *leftCol
= m_selectedTopLeft
.GetCol();
1235 *bottomRow
= m_selectedBottomRight
.GetRow();
1236 *rightCol
= m_selectedBottomRight
.GetCol();
1240 // This function returns the rectangle that encloses the block of cells
1241 // limited by TopLeft and BottomRight cell in device coords and clipped
1242 // to the client size of the grid window.
1244 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1245 const wxGridCellCoords
& bottomRight
);
1247 // This function returns the rectangle that encloses the selected cells
1248 // in device coords and clipped to the client size of the grid window.
1250 wxRect
SelectionToDeviceRect()
1252 return BlockToDeviceRect( m_selectedTopLeft
,
1253 m_selectedBottomRight
);
1256 // Access or update the selection fore/back colours
1257 wxColour
GetSelectionBackground() const
1258 { return m_selectionBackground
; }
1259 wxColour
GetSelectionForeground() const
1260 { return m_selectionForeground
; }
1262 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1263 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1266 // Methods for a registry for mapping data types to Renderers/Editors
1267 void RegisterDataType(const wxString
& typeName
,
1268 wxGridCellRenderer
* renderer
,
1269 wxGridCellEditor
* editor
);
1270 wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1271 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1272 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1273 wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1274 wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1275 wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1277 // grid may occupy more space than needed for its rows/columns, this
1278 // function allows to set how big this extra space is
1279 void SetMargins(int extraWidth
, int extraHeight
)
1281 m_extraWidth
= extraWidth
;
1282 m_extraHeight
= extraHeight
;
1285 // ------ For compatibility with previous wxGrid only...
1287 // ************************************************
1288 // ** Don't use these in new code because they **
1289 // ** are liable to disappear in a future **
1291 // ************************************************
1294 wxGrid( wxWindow
*parent
,
1295 int x
, int y
, int w
= -1, int h
= -1,
1296 long style
= wxWANTS_CHARS
,
1297 const wxString
& name
= wxPanelNameStr
)
1298 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
),
1299 (style
|wxWANTS_CHARS
), name
)
1304 void SetCellValue( const wxString
& val
, int row
, int col
)
1305 { SetCellValue( row
, col
, val
); }
1307 void UpdateDimensions()
1308 { CalcDimensions(); }
1310 int GetRows() { return GetNumberRows(); }
1311 int GetCols() { return GetNumberCols(); }
1312 int GetCursorRow() { return GetGridCursorRow(); }
1313 int GetCursorColumn() { return GetGridCursorCol(); }
1315 int GetScrollPosX() { return 0; }
1316 int GetScrollPosY() { return 0; }
1318 void SetScrollX( int x
) { }
1319 void SetScrollY( int y
) { }
1321 void SetColumnWidth( int col
, int width
)
1322 { SetColSize( col
, width
); }
1324 int GetColumnWidth( int col
)
1325 { return GetColSize( col
); }
1327 void SetRowHeight( int row
, int height
)
1328 { SetRowSize( row
, height
); }
1330 // GetRowHeight() is below
1332 int GetViewHeight() // returned num whole rows visible
1335 int GetViewWidth() // returned num whole cols visible
1338 void SetLabelSize( int orientation
, int sz
)
1340 if ( orientation
== wxHORIZONTAL
)
1341 SetColLabelSize( sz
);
1343 SetRowLabelSize( sz
);
1346 int GetLabelSize( int orientation
)
1348 if ( orientation
== wxHORIZONTAL
)
1349 return GetColLabelSize();
1351 return GetRowLabelSize();
1354 void SetLabelAlignment( int orientation
, int align
)
1356 if ( orientation
== wxHORIZONTAL
)
1357 SetColLabelAlignment( align
, -1 );
1359 SetRowLabelAlignment( align
, -1 );
1362 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
1365 if ( orientation
== wxHORIZONTAL
)
1367 GetColLabelAlignment( &h
, &v
);
1372 GetRowLabelAlignment( &h
, &v
);
1377 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1379 if ( orientation
== wxHORIZONTAL
)
1380 SetColLabelValue( pos
, val
);
1382 SetRowLabelValue( pos
, val
);
1385 wxString
GetLabelValue( int orientation
, int pos
)
1387 if ( orientation
== wxHORIZONTAL
)
1388 return GetColLabelValue( pos
);
1390 return GetRowLabelValue( pos
);
1393 wxFont
GetCellTextFont() const
1394 { return m_defaultCellAttr
->GetFont(); }
1396 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1397 { return m_defaultCellAttr
->GetFont(); }
1399 void SetCellTextFont(const wxFont
& fnt
)
1400 { SetDefaultCellFont( fnt
); }
1402 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1403 { SetCellFont( row
, col
, fnt
); }
1405 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1406 { SetCellTextColour( row
, col
, val
); }
1408 void SetCellTextColour(const wxColour
& col
)
1409 { SetDefaultCellTextColour( col
); }
1411 void SetCellBackgroundColour(const wxColour
& col
)
1412 { SetDefaultCellBackgroundColour( col
); }
1414 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1415 { SetCellBackgroundColour( row
, col
, colour
); }
1417 bool GetEditable() { return IsEditable(); }
1418 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
1419 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
1421 void SetEditInPlace(bool edit
= TRUE
) { }
1423 void SetCellAlignment( int align
, int row
, int col
)
1424 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
1425 void SetCellAlignment( int WXUNUSED(align
) ) {}
1426 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1428 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1429 wxPen
& GetDividerPen() const { return wxNullPen
; }
1430 void OnActivate(bool WXUNUSED(active
)) {}
1432 // ******** End of compatibility functions **********
1436 // ------ control IDs
1437 enum { wxGRID_CELLCTRL
= 2000,
1440 // ------ control types
1441 enum { wxGRID_TEXTCTRL
= 2100,
1446 // overridden wxWindow methods
1450 virtual wxSize
DoGetBestSize() const;
1455 wxGridWindow
*m_gridWin
;
1456 wxGridRowLabelWindow
*m_rowLabelWin
;
1457 wxGridColLabelWindow
*m_colLabelWin
;
1458 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1460 wxGridTableBase
*m_table
;
1471 wxGridCellCoords m_currentCellCoords
;
1473 wxGridCellCoords m_selectedTopLeft
;
1474 wxGridCellCoords m_selectedBottomRight
;
1475 wxColour m_selectionBackground
;
1476 wxColour m_selectionForeground
;
1478 // NB: *never* access m_row/col arrays directly because they are created
1479 // on demand, *always* use accessor functions instead!
1481 // init the m_rowHeights/Bottoms arrays with default values
1482 void InitRowHeights();
1484 int m_defaultRowHeight
;
1485 wxArrayInt m_rowHeights
;
1486 wxArrayInt m_rowBottoms
;
1488 // init the m_colWidths/Rights arrays
1489 void InitColWidths();
1491 int m_defaultColWidth
;
1492 wxArrayInt m_colWidths
;
1493 wxArrayInt m_colRights
;
1495 // get the col/row coords
1496 int GetColWidth(int col
) const;
1497 int GetColLeft(int col
) const;
1498 int GetColRight(int col
) const;
1500 // this function must be public for compatibility...
1502 int GetRowHeight(int row
) const;
1505 int GetRowTop(int row
) const;
1506 int GetRowBottom(int row
) const;
1508 int m_rowLabelWidth
;
1509 int m_colLabelHeight
;
1511 // the size of the margin left to the right and bottom of the cell area
1515 wxColour m_labelBackgroundColour
;
1516 wxColour m_labelTextColour
;
1519 int m_rowLabelHorizAlign
;
1520 int m_rowLabelVertAlign
;
1521 int m_colLabelHorizAlign
;
1522 int m_colLabelVertAlign
;
1524 bool m_defaultRowLabelValues
;
1525 bool m_defaultColLabelValues
;
1527 wxColour m_gridLineColour
;
1528 bool m_gridLinesEnabled
;
1530 // common part of AutoSizeColumn/Row() and GetBestSize()
1531 int SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
= TRUE
);
1532 int SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
= TRUE
);
1534 // common part of AutoSizeColumn/Row()
1535 void AutoSizeColOrRow(int n
, bool setAsMin
, bool column
/* or row? */);
1537 // if a column has a minimal width, it will be the value for it in this
1539 wxHashTableLong m_colMinWidths
,
1542 // get the minimal width of the given column/row
1543 int GetColMinimalWidth(int col
) const;
1544 int GetRowMinimalHeight(int col
) const;
1546 // do we have some place to store attributes in?
1547 bool CanHaveAttributes();
1549 // returns the attribute we may modify in place: a new one if this cell
1550 // doesn't have any yet or the existing one if it does
1552 // DecRef() must be called on the returned pointer, as usual
1553 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1555 // cell attribute cache (currently we only cache 1, may be will do
1556 // more/better later)
1560 wxGridCellAttr
*attr
;
1563 // invalidates the attribute cache
1564 void ClearAttrCache();
1566 // adds an attribute to cache
1567 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
1569 // looks for an attr in cache, returns TRUE if found
1570 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
1572 // looks for the attr in cache, if not found asks the table and caches the
1574 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
1575 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
)
1576 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
1578 // the default cell attr object for cells that don't have their own
1579 wxGridCellAttr
* m_defaultCellAttr
;
1582 wxGridCellCoordsArray m_cellsExposed
;
1583 wxArrayInt m_rowsExposed
;
1584 wxArrayInt m_colsExposed
;
1585 wxArrayInt m_rowLabelsExposed
;
1586 wxArrayInt m_colLabelsExposed
;
1592 wxGridTypeRegistry
* m_typeRegistry
;
1596 WXGRID_CURSOR_SELECT_CELL
,
1597 WXGRID_CURSOR_RESIZE_ROW
,
1598 WXGRID_CURSOR_RESIZE_COL
,
1599 WXGRID_CURSOR_SELECT_ROW
,
1600 WXGRID_CURSOR_SELECT_COL
1603 // this method not only sets m_cursorMode but also sets the correct cursor
1604 // for the given mode and, if captureMouse is not FALSE releases the mouse
1605 // if it was captured and captures it if it must be captured
1607 // for this to work, you should always use it and not set m_cursorMode
1609 void ChangeCursorMode(CursorMode mode
,
1610 wxWindow
*win
= (wxWindow
*)NULL
,
1611 bool captureMouse
= TRUE
);
1613 wxWindow
*m_winCapture
; // the window which captured the mouse
1614 CursorMode m_cursorMode
;
1616 bool m_canDragRowSize
;
1617 bool m_canDragColSize
;
1618 bool m_canDragGridSize
;
1622 wxPoint m_startDragPos
;
1624 bool m_waitForSlowClick
;
1626 wxGridCellCoords m_selectionStart
;
1628 wxCursor m_rowResizeCursor
;
1629 wxCursor m_colResizeCursor
;
1631 bool m_editable
; // applies to whole grid
1632 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
1637 void CalcDimensions();
1638 void CalcWindowSizes();
1639 bool Redimension( wxGridTableMessage
& );
1642 bool SendEvent( const wxEventType
, int row
, int col
, wxMouseEvent
& );
1643 bool SendEvent( const wxEventType
, int row
, int col
);
1644 bool SendEvent( const wxEventType type
)
1646 return SendEvent(type
,
1647 m_currentCellCoords
.GetRow(),
1648 m_currentCellCoords
.GetCol());
1651 void OnPaint( wxPaintEvent
& );
1652 void OnSize( wxSizeEvent
& );
1653 void OnKeyDown( wxKeyEvent
& );
1654 void OnEraseBackground( wxEraseEvent
& );
1657 void SetCurrentCell( const wxGridCellCoords
& coords
);
1658 void SetCurrentCell( int row
, int col
)
1659 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1662 // ------ functions to get/send data (see also public functions)
1664 bool GetModelValues();
1665 bool SetModelValues();
1668 DECLARE_DYNAMIC_CLASS( wxGrid
)
1669 DECLARE_EVENT_TABLE()
1672 // ----------------------------------------------------------------------------
1673 // Grid event class and event types
1674 // ----------------------------------------------------------------------------
1676 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
1680 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
1681 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1685 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
1686 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
1687 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1689 virtual int GetRow() { return m_row
; }
1690 virtual int GetCol() { return m_col
; }
1691 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1692 bool ControlDown() { return m_control
; }
1693 bool MetaDown() { return m_meta
; }
1694 bool ShiftDown() { return m_shift
; }
1695 bool AltDown() { return m_alt
; }
1707 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
1710 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1714 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1715 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1719 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1720 int rowOrCol
=-1, int x
=-1, int y
=-1,
1721 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1723 int GetRowOrCol() { return m_rowOrCol
; }
1724 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1725 bool ControlDown() { return m_control
; }
1726 bool MetaDown() { return m_meta
; }
1727 bool ShiftDown() { return m_shift
; }
1728 bool AltDown() { return m_alt
; }
1739 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1743 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1746 wxGridRangeSelectEvent()
1749 m_topLeft
= wxGridNoCellCoords
;
1750 m_bottomRight
= wxGridNoCellCoords
;
1757 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1758 const wxGridCellCoords
& topLeft
,
1759 const wxGridCellCoords
& bottomRight
,
1760 bool control
=FALSE
, bool shift
=FALSE
,
1761 bool alt
=FALSE
, bool meta
=FALSE
);
1763 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1764 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1765 int GetTopRow() { return m_topLeft
.GetRow(); }
1766 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1767 int GetLeftCol() { return m_topLeft
.GetCol(); }
1768 int GetRightCol() { return m_bottomRight
.GetCol(); }
1769 bool ControlDown() { return m_control
; }
1770 bool MetaDown() { return m_meta
; }
1771 bool ShiftDown() { return m_shift
; }
1772 bool AltDown() { return m_alt
; }
1775 wxGridCellCoords m_topLeft
;
1776 wxGridCellCoords m_bottomRight
;
1782 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1785 // TODO move to wx/event.h
1786 const wxEventType wxEVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1787 const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1788 const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1789 const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1790 const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1791 const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1792 const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1793 const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1794 const wxEventType wxEVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1795 const wxEventType wxEVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1796 const wxEventType wxEVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1797 const wxEventType wxEVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1798 const wxEventType wxEVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1799 const wxEventType wxEVT_GRID_EDITOR_SHOWN
= wxEVT_FIRST
+ 1593;
1800 const wxEventType wxEVT_GRID_EDITOR_HIDDEN
= wxEVT_FIRST
+ 1594;
1803 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1804 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1805 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1807 #define EVT_GRID_CELL_LEFT_CLICK(fn) { wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1808 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1809 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1810 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1811 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1812 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1813 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1814 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1815 #define EVT_GRID_ROW_SIZE(fn) { wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1816 #define EVT_GRID_COL_SIZE(fn) { wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1817 #define EVT_GRID_RANGE_SELECT(fn) { wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1818 #define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1819 #define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1820 #define EVT_GRID_EDITOR_SHOWN(fn) { wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1821 #define EVT_GRID_EDITOR_HIDDEN(fn) { wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1824 #if 0 // TODO: implement these ? others ?
1826 const wxEventType wxEVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1827 const wxEventType wxEVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1828 const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1830 #define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1831 #define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1832 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1836 #endif // #ifndef __WXGRID_H__
1838 #endif // ifndef wxUSE_NEW_GRID