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")
61 #define wxGRID_VALUE_CHOICE _T("choice")
63 #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
64 #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
66 // ----------------------------------------------------------------------------
67 // forward declarations
68 // ----------------------------------------------------------------------------
70 class WXDLLEXPORT wxGrid
;
71 class WXDLLEXPORT wxGridCellAttr
;
72 class WXDLLEXPORT wxGridCellAttrProviderData
;
73 class WXDLLEXPORT wxGridColLabelWindow
;
74 class WXDLLEXPORT wxGridCornerLabelWindow
;
75 class WXDLLEXPORT wxGridRowLabelWindow
;
76 class WXDLLEXPORT wxGridTableBase
;
77 class WXDLLEXPORT wxGridWindow
;
78 class WXDLLEXPORT wxGridTypeRegistry
;
80 class WXDLLEXPORT wxCheckBox
;
81 class WXDLLEXPORT wxComboBox
;
82 class WXDLLEXPORT wxTextCtrl
;
83 class WXDLLEXPORT wxSpinCtrl
;
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
90 #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
92 // ----------------------------------------------------------------------------
93 // wxGridCellWorker: common base class for wxGridCellRenderer and
96 // NB: this is more an implementation convenience than a design issue, so this
97 // class is not documented and is not public at all
98 // ----------------------------------------------------------------------------
100 class WXDLLEXPORT wxGridCellWorker
103 wxGridCellWorker() { m_nRef
= 1; }
105 // this class is ref counted: it is created with ref count of 1, so
106 // calling DecRef() once will delete it. Calling IncRef() allows to lock
107 // it until the matching DecRef() is called
108 void IncRef() { m_nRef
++; }
109 void DecRef() { if ( !--m_nRef
) delete this; }
111 // interpret renderer parameters: arbitrary string whose interpretatin is
112 // left to the derived classes
113 virtual void SetParameters(const wxString
& params
);
116 // virtual dtor for any base class - private because only DecRef() can
118 virtual ~wxGridCellWorker();
123 // suppress the stupid gcc warning about the class having private dtor and
125 friend class wxGridCellWorkerDummyFriend
;
128 // ----------------------------------------------------------------------------
129 // wxGridCellRenderer: this class is responsible for actually drawing the cell
130 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
131 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
132 // view of all cells. This is an ABC, you will normally use one of the
133 // predefined derived classes or derive your own class from it.
134 // ----------------------------------------------------------------------------
136 class WXDLLEXPORT wxGridCellRenderer
: public wxGridCellWorker
139 // draw the given cell on the provided DC inside the given rectangle
140 // using the style specified by the attribute and the default or selected
141 // state corresponding to the isSelected value.
143 // this pure virtual function has a default implementation which will
144 // prepare the DC using the given attribute: it will draw the rectangle
145 // with the bg colour from attr and set the text colour and font
146 virtual void Draw(wxGrid
& grid
,
147 wxGridCellAttr
& attr
,
151 bool isSelected
) = 0;
153 // get the preferred size of the cell for its contents
154 virtual wxSize
GetBestSize(wxGrid
& grid
,
155 wxGridCellAttr
& attr
,
157 int row
, int col
) = 0;
159 // create a new object which is the copy of this one
160 virtual wxGridCellRenderer
*Clone() const = 0;
163 // the default renderer for the cells containing string data
164 class WXDLLEXPORT wxGridCellStringRenderer
: public wxGridCellRenderer
168 virtual void Draw(wxGrid
& grid
,
169 wxGridCellAttr
& attr
,
175 // return the string extent
176 virtual wxSize
GetBestSize(wxGrid
& grid
,
177 wxGridCellAttr
& attr
,
181 virtual wxGridCellRenderer
*Clone() const
182 { return new wxGridCellStringRenderer
; }
185 // set the text colours before drawing
186 void SetTextColoursAndFont(wxGrid
& grid
,
187 wxGridCellAttr
& attr
,
191 // calc the string extent for given string/font
192 wxSize
DoGetBestSize(wxGridCellAttr
& attr
,
194 const wxString
& text
);
197 // the default renderer for the cells containing numeric (long) data
198 class WXDLLEXPORT wxGridCellNumberRenderer
: public wxGridCellStringRenderer
201 // draw the string right aligned
202 virtual void Draw(wxGrid
& grid
,
203 wxGridCellAttr
& attr
,
209 virtual wxSize
GetBestSize(wxGrid
& grid
,
210 wxGridCellAttr
& attr
,
214 virtual wxGridCellRenderer
*Clone() const
215 { return new wxGridCellNumberRenderer
; }
218 wxString
GetString(wxGrid
& grid
, int row
, int col
);
221 class WXDLLEXPORT wxGridCellFloatRenderer
: public wxGridCellStringRenderer
224 wxGridCellFloatRenderer(int width
= -1, int precision
= -1);
226 // get/change formatting parameters
227 int GetWidth() const { return m_width
; }
228 void SetWidth(int width
) { m_width
= width
; m_format
.clear(); }
229 int GetPrecision() const { return m_precision
; }
230 void SetPrecision(int precision
) { m_precision
= precision
; m_format
.clear(); }
232 // draw the string right aligned with given width/precision
233 virtual void Draw(wxGrid
& grid
,
234 wxGridCellAttr
& attr
,
240 virtual wxSize
GetBestSize(wxGrid
& grid
,
241 wxGridCellAttr
& attr
,
245 // parameters string format is "width[,precision]"
246 virtual void SetParameters(const wxString
& params
);
248 virtual wxGridCellRenderer
*Clone() const;
251 wxString
GetString(wxGrid
& grid
, int row
, int col
);
254 // formatting parameters
261 // renderer for boolean fields
262 class WXDLLEXPORT wxGridCellBoolRenderer
: public wxGridCellRenderer
265 // draw a check mark or nothing
266 virtual void Draw(wxGrid
& grid
,
267 wxGridCellAttr
& attr
,
273 // return the checkmark size
274 virtual wxSize
GetBestSize(wxGrid
& grid
,
275 wxGridCellAttr
& attr
,
279 virtual wxGridCellRenderer
*Clone() const
280 { return new wxGridCellBoolRenderer
; }
283 static wxSize ms_sizeCheckMark
;
286 // ----------------------------------------------------------------------------
287 // wxGridCellEditor: This class is responsible for providing and manipulating
288 // the in-place edit controls for the grid. Instances of wxGridCellEditor
289 // (actually, instances of derived classes since it is an ABC) can be
290 // associated with the cell attributes for individual cells, rows, columns, or
291 // even for the entire grid.
292 // ----------------------------------------------------------------------------
294 class WXDLLEXPORT wxGridCellEditor
: public wxGridCellWorker
299 bool IsCreated() { return m_control
!= NULL
; }
301 // Creates the actual edit control
302 virtual void Create(wxWindow
* parent
,
304 wxEvtHandler
* evtHandler
) = 0;
306 // Size and position the edit control
307 virtual void SetSize(const wxRect
& rect
);
309 // Show or hide the edit control, use the specified attributes to set
310 // colours/fonts for it
311 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
313 // Draws the part of the cell not occupied by the control: the base class
314 // version just fills it with background colour from the attribute
315 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
317 // Fetch the value from the table and prepare the edit control
318 // to begin editing. Set the focus to the edit control.
319 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
321 // Complete the editing of the current cell. Returns true if the value has
322 // changed. If necessary, the control may be destroyed.
323 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
) = 0;
325 // Reset the value in the control back to its starting value
326 virtual void Reset() = 0;
328 // If the editor is enabled by pressing keys on the grid,
329 // this will be called to let the editor do something about
330 // that first key if desired.
331 virtual void StartingKey(wxKeyEvent
& event
);
333 // if the editor is enabled by clicking on the cell, this method will be
335 virtual void StartingClick();
337 // Some types of controls on some platforms may need some help
338 // with the Return key.
339 virtual void HandleReturn(wxKeyEvent
& event
);
342 virtual void Destroy();
344 // create a new object which is the copy of this one
345 virtual wxGridCellEditor
*Clone() const = 0;
348 // the dtor is private because only DecRef() can delete us
349 virtual ~wxGridCellEditor();
351 // the control we show on screen
352 wxControl
* m_control
;
354 // if we change the colours/font of the control from the default ones, we
355 // must restore the default later and we save them here between calls to
356 // Show(TRUE) and Show(FALSE)
361 // suppress the stupid gcc warning about the class having private dtor and
363 friend class wxGridCellEditorDummyFriend
;
366 // the editor for string/text data
367 class WXDLLEXPORT wxGridCellTextEditor
: public wxGridCellEditor
370 wxGridCellTextEditor();
372 virtual void Create(wxWindow
* parent
,
374 wxEvtHandler
* evtHandler
);
375 virtual void SetSize(const wxRect
& rect
);
377 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
379 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
380 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
382 virtual void Reset();
383 virtual void StartingKey(wxKeyEvent
& event
);
384 virtual void HandleReturn(wxKeyEvent
& event
);
386 // parameters string format is "max_width"
387 virtual void SetParameters(const wxString
& params
);
389 virtual wxGridCellEditor
*Clone() const
390 { return new wxGridCellTextEditor
; }
393 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
395 // parts of our virtual functions reused by the derived classes
396 void DoBeginEdit(const wxString
& startValue
);
397 void DoReset(const wxString
& startValue
);
400 size_t m_maxChars
; // max number of chars allowed
401 wxString m_startValue
;
404 // the editor for numeric (long) data
405 class WXDLLEXPORT wxGridCellNumberEditor
: public wxGridCellTextEditor
408 // allows to specify the range - if min == max == -1, no range checking is
410 wxGridCellNumberEditor(int min
= -1, int max
= -1);
412 virtual void Create(wxWindow
* parent
,
414 wxEvtHandler
* evtHandler
);
416 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
417 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
419 virtual void Reset();
420 virtual void StartingKey(wxKeyEvent
& event
);
422 // parameters string format is "min,max"
423 virtual void SetParameters(const wxString
& params
);
425 virtual wxGridCellEditor
*Clone() const
426 { return new wxGridCellNumberEditor(m_min
, m_max
); }
429 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
431 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
432 bool HasRange() const { return m_min
!= m_max
; }
434 // string representation of m_valueOld
435 wxString
GetString() const
436 { return wxString::Format(_T("%ld"), m_valueOld
); }
445 // the editor for floating point numbers (double) data
446 class WXDLLEXPORT wxGridCellFloatEditor
: public wxGridCellTextEditor
449 virtual void Create(wxWindow
* parent
,
451 wxEvtHandler
* evtHandler
);
453 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
454 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
456 virtual void Reset();
457 virtual void StartingKey(wxKeyEvent
& event
);
459 virtual wxGridCellEditor
*Clone() const
460 { return new wxGridCellFloatEditor
; }
463 // string representation of m_valueOld
464 wxString
GetString() const
465 { return wxString::Format(_T("%f"), m_valueOld
); }
471 // the editor for boolean data
472 class WXDLLEXPORT wxGridCellBoolEditor
: public wxGridCellEditor
475 virtual void Create(wxWindow
* parent
,
477 wxEvtHandler
* evtHandler
);
479 virtual void SetSize(const wxRect
& rect
);
480 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
482 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
483 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
485 virtual void Reset();
486 virtual void StartingClick();
488 virtual wxGridCellEditor
*Clone() const
489 { return new wxGridCellBoolEditor
; }
492 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
498 // the editor for string data allowing to choose from the list of strings
499 class WXDLLEXPORT wxGridCellChoiceEditor
: public wxGridCellEditor
502 // if !allowOthers, user can't type a string not in choices array
503 wxGridCellChoiceEditor(size_t count
= 0,
504 const wxChar
* choices
[] = NULL
,
505 bool allowOthers
= FALSE
);
507 virtual void Create(wxWindow
* parent
,
509 wxEvtHandler
* evtHandler
);
511 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
513 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
514 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
516 virtual void Reset();
518 // parameters string format is "item1[,item2[...,itemN]]"
519 virtual void SetParameters(const wxString
& params
);
521 virtual wxGridCellEditor
*Clone() const;
524 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
527 wxString m_startValue
;
528 wxArrayString m_choices
;
532 // ----------------------------------------------------------------------------
533 // wxGridCellAttr: this class can be used to alter the cells appearance in
534 // the grid by changing their colour/font/... from default. An object of this
535 // class may be returned by wxGridTable::GetAttr().
536 // ----------------------------------------------------------------------------
538 class WXDLLEXPORT wxGridCellAttr
548 // VZ: considering the number of members wxGridCellAttr has now, this ctor
549 // seems to be pretty useless... may be we should just remove it?
550 wxGridCellAttr(const wxColour
& colText
,
551 const wxColour
& colBack
,
555 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
558 SetAlignment(hAlign
, vAlign
);
561 // creates a new copy of this object
562 wxGridCellAttr
*Clone() const;
564 // this class is ref counted: it is created with ref count of 1, so
565 // calling DecRef() once will delete it. Calling IncRef() allows to lock
566 // it until the matching DecRef() is called
567 void IncRef() { m_nRef
++; }
568 void DecRef() { if ( !--m_nRef
) delete this; }
571 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
572 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
573 void SetFont(const wxFont
& font
) { m_font
= font
; }
574 void SetAlignment(int hAlign
, int vAlign
)
579 void SetReadOnly(bool isReadOnly
= TRUE
) { m_isReadOnly
= isReadOnly
; }
581 // takes ownership of the pointer
582 void SetRenderer(wxGridCellRenderer
*renderer
)
583 { wxSafeDecRef(m_renderer
); m_renderer
= renderer
; }
584 void SetEditor(wxGridCellEditor
* editor
)
585 { wxSafeDecRef(m_editor
); m_editor
= editor
; }
588 bool HasTextColour() const { return m_colText
.Ok(); }
589 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
590 bool HasFont() const { return m_font
.Ok(); }
591 bool HasAlignment() const { return m_hAlign
|| m_vAlign
; }
592 bool HasRenderer() const { return m_renderer
!= NULL
; }
593 bool HasEditor() const { return m_editor
!= NULL
; }
595 const wxColour
& GetTextColour() const;
596 const wxColour
& GetBackgroundColour() const;
597 const wxFont
& GetFont() const;
598 void GetAlignment(int *hAlign
, int *vAlign
) const;
599 wxGridCellRenderer
*GetRenderer(wxGrid
* grid
, int row
, int col
) const;
600 wxGridCellEditor
*GetEditor(wxGrid
* grid
, int row
, int col
) const;
602 bool IsReadOnly() const { return m_isReadOnly
; }
604 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
607 // the common part of all ctors
612 m_isReadOnly
= FALSE
;
618 // the dtor is private because only DecRef() can delete us
621 wxSafeDecRef(m_renderer
);
622 wxSafeDecRef(m_editor
);
625 // the ref count - when it goes to 0, we die
634 wxGridCellRenderer
* m_renderer
;
635 wxGridCellEditor
* m_editor
;
636 wxGridCellAttr
* m_defGridAttr
;
640 // use Clone() instead
641 DECLARE_NO_COPY_CLASS(wxGridCellAttr
);
643 // suppress the stupid gcc warning about the class having private dtor and
645 friend class wxGridCellAttrDummyFriend
;
648 // ----------------------------------------------------------------------------
649 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
651 // ----------------------------------------------------------------------------
653 // implementation note: we separate it from wxGridTableBase because we wish to
654 // avoid deriving a new table class if possible, and sometimes it will be
655 // enough to just derive another wxGridCellAttrProvider instead
657 // the default implementation is reasonably efficient for the generic case,
658 // but you might still wish to implement your own for some specific situations
659 // if you have performance problems with the stock one
660 class WXDLLEXPORT wxGridCellAttrProvider
663 wxGridCellAttrProvider();
664 virtual ~wxGridCellAttrProvider();
666 // DecRef() must be called on the returned pointer
667 virtual wxGridCellAttr
*GetAttr(int row
, int col
) const;
669 // all these functions take ownership of the pointer, don't call DecRef()
671 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
672 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
673 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
675 // these functions must be called whenever some rows/cols are deleted
676 // because the internal data must be updated then
677 void UpdateAttrRows( size_t pos
, int numRows
);
678 void UpdateAttrCols( size_t pos
, int numCols
);
683 wxGridCellAttrProviderData
*m_data
;
686 //////////////////////////////////////////////////////////////////////
688 // Grid table classes
690 //////////////////////////////////////////////////////////////////////
693 class WXDLLEXPORT wxGridTableBase
: public wxObject
697 virtual ~wxGridTableBase();
699 // You must override these functions in a derived table class
701 virtual long GetNumberRows() = 0;
702 virtual long GetNumberCols() = 0;
703 virtual bool IsEmptyCell( int row
, int col
) = 0;
704 virtual wxString
GetValue( int row
, int col
) = 0;
705 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
707 // Data type determination and value access
708 virtual wxString
GetTypeName( int row
, int col
);
709 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
710 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
712 virtual long GetValueAsLong( int row
, int col
);
713 virtual double GetValueAsDouble( int row
, int col
);
714 virtual bool GetValueAsBool( int row
, int col
);
716 virtual void SetValueAsLong( int row
, int col
, long value
);
717 virtual void SetValueAsDouble( int row
, int col
, double value
);
718 virtual void SetValueAsBool( int row
, int col
, bool value
);
720 // For user defined types
721 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
722 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
725 // Overriding these is optional
727 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
728 virtual wxGrid
* GetView() const { return m_view
; }
730 virtual void Clear() {}
731 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
732 virtual bool AppendRows( size_t numRows
= 1 );
733 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
734 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
735 virtual bool AppendCols( size_t numCols
= 1 );
736 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
738 virtual wxString
GetRowLabelValue( int row
);
739 virtual wxString
GetColLabelValue( int col
);
740 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
741 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
743 // Attribute handling
746 // give us the attr provider to use - we take ownership of the pointer
747 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
749 // get the currently used attr provider (may be NULL)
750 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
752 // Does this table allow attributes? Default implementation creates
753 // a wxGridCellAttrProvider if necessary.
754 virtual bool CanHaveAttributes();
757 // change row/col number in attribute if needed
758 virtual void UpdateAttrRows( size_t pos
, int numRows
);
759 virtual void UpdateAttrCols( size_t pos
, int numCols
);
761 // by default forwarded to wxGridCellAttrProvider if any. May be
762 // overridden to handle attributes directly in the table.
763 virtual wxGridCellAttr
*GetAttr( int row
, int col
);
765 // these functions take ownership of the pointer
766 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
767 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
768 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
772 wxGridCellAttrProvider
*m_attrProvider
;
774 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
778 // ----------------------------------------------------------------------------
779 // wxGridTableMessage
780 // ----------------------------------------------------------------------------
782 // IDs for messages sent from grid table to view
784 enum wxGridTableRequest
786 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
787 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
788 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
789 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
790 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
791 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
792 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
793 wxGRIDTABLE_NOTIFY_COLS_DELETED
796 class WXDLLEXPORT wxGridTableMessage
799 wxGridTableMessage();
800 wxGridTableMessage( wxGridTableBase
*table
, int id
,
804 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
805 wxGridTableBase
* GetTableObject() const { return m_table
; }
806 void SetId( int id
) { m_id
= id
; }
807 int GetId() { return m_id
; }
808 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
809 int GetCommandInt() { return m_comInt1
; }
810 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
811 int GetCommandInt2() { return m_comInt2
; }
814 wxGridTableBase
*m_table
;
822 // ------ wxGridStringArray
823 // A 2-dimensional array of strings for data values
826 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
830 // ------ wxGridStringTable
832 // Simplest type of data table for a grid for small tables of strings
833 // that are stored in memory
836 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
840 wxGridStringTable( int numRows
, int numCols
);
841 ~wxGridStringTable();
843 // these are pure virtual in wxGridTableBase
845 long GetNumberRows();
846 long GetNumberCols();
847 wxString
GetValue( int row
, int col
);
848 void SetValue( int row
, int col
, const wxString
& s
);
849 bool IsEmptyCell( int row
, int col
);
851 // overridden functions from wxGridTableBase
854 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
855 bool AppendRows( size_t numRows
= 1 );
856 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
857 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
858 bool AppendCols( size_t numCols
= 1 );
859 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
861 void SetRowLabelValue( int row
, const wxString
& );
862 void SetColLabelValue( int col
, const wxString
& );
863 wxString
GetRowLabelValue( int row
);
864 wxString
GetColLabelValue( int col
);
867 wxGridStringArray m_data
;
869 // These only get used if you set your own labels, otherwise the
870 // GetRow/ColLabelValue functions return wxGridTableBase defaults
872 wxArrayString m_rowLabels
;
873 wxArrayString m_colLabels
;
875 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
880 // ============================================================================
882 // ============================================================================
884 // ----------------------------------------------------------------------------
885 // wxGridCellCoords: location of a cell in the grid
886 // ----------------------------------------------------------------------------
888 class WXDLLEXPORT wxGridCellCoords
891 wxGridCellCoords() { m_row
= m_col
= -1; }
892 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
894 // default copy ctor is ok
896 long GetRow() const { return m_row
; }
897 void SetRow( long n
) { m_row
= n
; }
898 long GetCol() const { return m_col
; }
899 void SetCol( long n
) { m_col
= n
; }
900 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
902 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
904 if ( &other
!= this )
912 bool operator==( const wxGridCellCoords
& other
) const
914 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
917 bool operator!=( const wxGridCellCoords
& other
) const
919 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
922 bool operator!() const
924 return (m_row
== -1 && m_col
== -1 );
933 // For comparisons...
935 extern wxGridCellCoords wxGridNoCellCoords
;
936 extern wxRect wxGridNoCellRect
;
938 // An array of cell coords...
940 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
942 // ----------------------------------------------------------------------------
944 // ----------------------------------------------------------------------------
946 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
954 wxGrid( wxWindow
*parent
,
956 const wxPoint
& pos
= wxDefaultPosition
,
957 const wxSize
& size
= wxDefaultSize
,
958 long style
= wxWANTS_CHARS
,
959 const wxString
& name
= wxPanelNameStr
);
963 bool CreateGrid( int numRows
, int numCols
);
966 // ------ grid dimensions
968 int GetNumberRows() { return m_numRows
; }
969 int GetNumberCols() { return m_numCols
; }
972 // ------ display update functions
974 void CalcRowLabelsExposed( wxRegion
& reg
);
976 void CalcColLabelsExposed( wxRegion
& reg
);
977 void CalcCellsExposed( wxRegion
& reg
);
980 // ------ event handlers
982 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
983 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
984 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
985 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
986 bool ProcessTableMessage( wxGridTableMessage
& );
988 void DoEndDragResizeRow();
989 void DoEndDragResizeCol();
991 wxGridTableBase
* GetTable() const { return m_table
; }
992 bool SetTable( wxGridTableBase
*table
, bool takeOwnership
=FALSE
);
995 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
996 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
997 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
998 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
999 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
1000 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
1002 void DrawGridCellArea( wxDC
& dc
);
1003 void DrawGridSpace( wxDC
& dc
);
1004 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
1005 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
1006 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
1007 void DrawHighlight(wxDC
& dc
);
1009 // this function is called when the current cell highlight must be redrawn
1010 // and may be overridden by the user
1011 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
1013 void DrawRowLabels( wxDC
& dc
);
1014 void DrawRowLabel( wxDC
& dc
, int row
);
1016 void DrawColLabels( wxDC
& dc
);
1017 void DrawColLabel( wxDC
& dc
, int col
);
1020 // ------ Cell text drawing functions
1022 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
1023 int horizontalAlignment
= wxLEFT
,
1024 int verticalAlignment
= wxTOP
);
1026 // Split a string containing newline chararcters into an array of
1027 // strings and return the number of lines
1029 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
1031 void GetTextBoxSize( wxDC
& dc
,
1032 wxArrayString
& lines
,
1033 long *width
, long *height
);
1037 // Code that does a lot of grid modification can be enclosed
1038 // between BeginBatch() and EndBatch() calls to avoid screen
1041 void BeginBatch() { m_batchCount
++; }
1042 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
1043 int GetBatchCount() { return m_batchCount
; }
1046 // ------ edit control functions
1048 bool IsEditable() { return m_editable
; }
1049 void EnableEditing( bool edit
);
1051 void EnableCellEditControl( bool enable
= TRUE
);
1052 void DisableCellEditControl() { EnableCellEditControl(FALSE
); }
1053 bool CanEnableCellControl() const;
1054 bool IsCellEditControlEnabled() const;
1056 bool IsCurrentCellReadOnly() const;
1058 void ShowCellEditControl();
1059 void HideCellEditControl();
1060 void SaveEditControlValue();
1063 // ------ grid location functions
1064 // Note that all of these functions work with the logical coordinates of
1065 // grid cells and labels so you will need to convert from device
1066 // coordinates for mouse events etc.
1068 void XYToCell( int x
, int y
, wxGridCellCoords
& );
1069 int YToRow( int y
);
1070 int XToCol( int x
);
1072 int YToEdgeOfRow( int y
);
1073 int XToEdgeOfCol( int x
);
1075 wxRect
CellToRect( int row
, int col
);
1076 wxRect
CellToRect( const wxGridCellCoords
& coords
)
1077 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
1079 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
1080 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
1082 // check to see if a cell is either wholly visible (the default arg) or
1083 // at least partially visible in the grid window
1085 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
1086 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
1087 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
1088 void MakeCellVisible( int row
, int col
);
1089 void MakeCellVisible( const wxGridCellCoords
& coords
)
1090 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
1093 // ------ grid cursor movement functions
1095 void SetGridCursor( int row
, int col
)
1096 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1098 bool MoveCursorUp();
1099 bool MoveCursorDown();
1100 bool MoveCursorLeft();
1101 bool MoveCursorRight();
1102 bool MovePageDown();
1104 bool MoveCursorUpBlock();
1105 bool MoveCursorDownBlock();
1106 bool MoveCursorLeftBlock();
1107 bool MoveCursorRightBlock();
1110 // ------ label and gridline formatting
1112 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
1113 int GetRowLabelSize() { return m_rowLabelWidth
; }
1114 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
1115 int GetColLabelSize() { return m_colLabelHeight
; }
1116 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
1117 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
1118 wxFont
GetLabelFont() { return m_labelFont
; }
1119 void GetRowLabelAlignment( int *horiz
, int *vert
);
1120 void GetColLabelAlignment( int *horiz
, int *vert
);
1121 wxString
GetRowLabelValue( int row
);
1122 wxString
GetColLabelValue( int col
);
1123 wxColour
GetGridLineColour() { return m_gridLineColour
; }
1125 void SetRowLabelSize( int width
);
1126 void SetColLabelSize( int height
);
1127 void SetLabelBackgroundColour( const wxColour
& );
1128 void SetLabelTextColour( const wxColour
& );
1129 void SetLabelFont( const wxFont
& );
1130 void SetRowLabelAlignment( int horiz
, int vert
);
1131 void SetColLabelAlignment( int horiz
, int vert
);
1132 void SetRowLabelValue( int row
, const wxString
& );
1133 void SetColLabelValue( int col
, const wxString
& );
1134 void SetGridLineColour( const wxColour
& );
1136 void EnableDragRowSize( bool enable
= TRUE
);
1137 void DisableDragRowSize() { EnableDragRowSize( FALSE
); }
1138 bool CanDragRowSize() { return m_canDragRowSize
; }
1139 void EnableDragColSize( bool enable
= TRUE
);
1140 void DisableDragColSize() { EnableDragColSize( FALSE
); }
1141 bool CanDragColSize() { return m_canDragColSize
; }
1142 void EnableDragGridSize(bool enable
= TRUE
);
1143 void DisableDragGridSize() { EnableDragGridSize(FALSE
); }
1144 bool CanDragGridSize() { return m_canDragGridSize
; }
1146 // this sets the specified attribute for all cells in this row/col
1147 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
1148 void SetColAttr(int col
, wxGridCellAttr
*attr
);
1150 // shortcuts for setting the column parameters
1152 // set the format for the data in the column: default is string
1153 void SetColFormatBool(int col
);
1154 void SetColFormatNumber(int col
);
1155 void SetColFormatFloat(int col
, int width
= -1, int precision
= -1);
1156 void SetColFormatCustom(int col
, const wxString
& typeName
);
1158 void EnableGridLines( bool enable
= TRUE
);
1159 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
1161 // ------ row and col formatting
1163 int GetDefaultRowSize();
1164 int GetRowSize( int row
);
1165 int GetDefaultColSize();
1166 int GetColSize( int col
);
1167 wxColour
GetDefaultCellBackgroundColour();
1168 wxColour
GetCellBackgroundColour( int row
, int col
);
1169 wxColour
GetDefaultCellTextColour();
1170 wxColour
GetCellTextColour( int row
, int col
);
1171 wxFont
GetDefaultCellFont();
1172 wxFont
GetCellFont( int row
, int col
);
1173 void GetDefaultCellAlignment( int *horiz
, int *vert
);
1174 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
1176 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
1177 void SetRowSize( int row
, int height
);
1178 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
1180 void SetColSize( int col
, int width
);
1182 // automatically size the column or row to fit to its contents, if
1183 // setAsMin is TRUE, this optimal width will also be set as minimal width
1185 void AutoSizeColumn( int col
, bool setAsMin
= TRUE
)
1186 { AutoSizeColOrRow(col
, setAsMin
, TRUE
); }
1187 void AutoSizeRow( int row
, bool setAsMin
= TRUE
)
1188 { AutoSizeColOrRow(row
, setAsMin
, FALSE
); }
1190 // auto size all columns (very ineffective for big grids!)
1191 void AutoSizeColumns( bool setAsMin
= TRUE
)
1192 { (void)SetOrCalcColumnSizes(FALSE
, setAsMin
); }
1194 void AutoSizeRows( bool setAsMin
= TRUE
)
1195 { (void)SetOrCalcRowSizes(FALSE
, setAsMin
); }
1197 // auto size the grid, that is make the columns/rows of the "right" size
1198 // and also set the grid size to just fit its contents
1201 // column won't be resized to be lesser width - this must be called during
1202 // the grid creation because it won't resize the column if it's already
1203 // narrower than the minimal width
1204 void SetColMinimalWidth( int col
, int width
);
1205 void SetRowMinimalHeight( int row
, int width
);
1207 void SetDefaultCellBackgroundColour( const wxColour
& );
1208 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1209 void SetDefaultCellTextColour( const wxColour
& );
1211 void SetCellTextColour( int row
, int col
, const wxColour
& );
1212 void SetDefaultCellFont( const wxFont
& );
1213 void SetCellFont( int row
, int col
, const wxFont
& );
1214 void SetDefaultCellAlignment( int horiz
, int vert
);
1215 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1217 // takes ownership of the pointer
1218 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1219 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1220 wxGridCellRenderer
*GetDefaultRenderer() const;
1221 wxGridCellRenderer
* GetCellRenderer(int row
, int col
);
1223 // takes ownership of the pointer
1224 void SetDefaultEditor(wxGridCellEditor
*editor
);
1225 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1226 wxGridCellEditor
*GetDefaultEditor() const;
1227 wxGridCellEditor
* GetCellEditor(int row
, int col
);
1231 // ------ cell value accessors
1233 wxString
GetCellValue( int row
, int col
)
1237 return m_table
->GetValue( row
, col
);
1241 return wxEmptyString
;
1245 wxString
GetCellValue( const wxGridCellCoords
& coords
)
1246 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1248 void SetCellValue( int row
, int col
, const wxString
& s
);
1249 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1250 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1252 // returns TRUE if the cell can't be edited
1253 bool IsReadOnly(int row
, int col
) const;
1255 // make the cell editable/readonly
1256 void SetReadOnly(int row
, int col
, bool isReadOnly
= TRUE
);
1258 // ------ selections of blocks of cells
1260 void SelectRow( int row
, bool addToSelected
= FALSE
);
1261 void SelectCol( int col
, bool addToSelected
= FALSE
);
1263 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
1265 void SelectBlock( const wxGridCellCoords
& topLeft
,
1266 const wxGridCellCoords
& bottomRight
)
1267 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1268 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
1273 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
1274 m_selectedBottomRight
!= wxGridNoCellCoords
);
1277 void ClearSelection();
1279 bool IsInSelection( int row
, int col
)
1280 { return ( IsSelection() &&
1281 row
>= m_selectedTopLeft
.GetRow() &&
1282 col
>= m_selectedTopLeft
.GetCol() &&
1283 row
<= m_selectedBottomRight
.GetRow() &&
1284 col
<= m_selectedBottomRight
.GetCol() );
1287 bool IsInSelection( const wxGridCellCoords
& coords
)
1288 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1290 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
1292 // these will all be -1 if there is no selected block
1294 *topRow
= m_selectedTopLeft
.GetRow();
1295 *leftCol
= m_selectedTopLeft
.GetCol();
1296 *bottomRow
= m_selectedBottomRight
.GetRow();
1297 *rightCol
= m_selectedBottomRight
.GetCol();
1301 // This function returns the rectangle that encloses the block of cells
1302 // limited by TopLeft and BottomRight cell in device coords and clipped
1303 // to the client size of the grid window.
1305 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1306 const wxGridCellCoords
& bottomRight
);
1308 // This function returns the rectangle that encloses the selected cells
1309 // in device coords and clipped to the client size of the grid window.
1311 wxRect
SelectionToDeviceRect()
1313 return BlockToDeviceRect( m_selectedTopLeft
,
1314 m_selectedBottomRight
);
1317 // Access or update the selection fore/back colours
1318 wxColour
GetSelectionBackground() const
1319 { return m_selectionBackground
; }
1320 wxColour
GetSelectionForeground() const
1321 { return m_selectionForeground
; }
1323 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1324 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1327 // Methods for a registry for mapping data types to Renderers/Editors
1328 void RegisterDataType(const wxString
& typeName
,
1329 wxGridCellRenderer
* renderer
,
1330 wxGridCellEditor
* editor
);
1331 wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1332 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1333 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1334 wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1335 wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1336 wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1338 // grid may occupy more space than needed for its rows/columns, this
1339 // function allows to set how big this extra space is
1340 void SetMargins(int extraWidth
, int extraHeight
)
1342 m_extraWidth
= extraWidth
;
1343 m_extraHeight
= extraHeight
;
1346 // ------ For compatibility with previous wxGrid only...
1348 // ************************************************
1349 // ** Don't use these in new code because they **
1350 // ** are liable to disappear in a future **
1352 // ************************************************
1355 wxGrid( wxWindow
*parent
,
1356 int x
, int y
, int w
= -1, int h
= -1,
1357 long style
= wxWANTS_CHARS
,
1358 const wxString
& name
= wxPanelNameStr
)
1359 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
),
1360 (style
|wxWANTS_CHARS
), name
)
1365 void SetCellValue( const wxString
& val
, int row
, int col
)
1366 { SetCellValue( row
, col
, val
); }
1368 void UpdateDimensions()
1369 { CalcDimensions(); }
1371 int GetRows() { return GetNumberRows(); }
1372 int GetCols() { return GetNumberCols(); }
1373 int GetCursorRow() { return GetGridCursorRow(); }
1374 int GetCursorColumn() { return GetGridCursorCol(); }
1376 int GetScrollPosX() { return 0; }
1377 int GetScrollPosY() { return 0; }
1379 void SetScrollX( int x
) { }
1380 void SetScrollY( int y
) { }
1382 void SetColumnWidth( int col
, int width
)
1383 { SetColSize( col
, width
); }
1385 int GetColumnWidth( int col
)
1386 { return GetColSize( col
); }
1388 void SetRowHeight( int row
, int height
)
1389 { SetRowSize( row
, height
); }
1391 // GetRowHeight() is below
1393 int GetViewHeight() // returned num whole rows visible
1396 int GetViewWidth() // returned num whole cols visible
1399 void SetLabelSize( int orientation
, int sz
)
1401 if ( orientation
== wxHORIZONTAL
)
1402 SetColLabelSize( sz
);
1404 SetRowLabelSize( sz
);
1407 int GetLabelSize( int orientation
)
1409 if ( orientation
== wxHORIZONTAL
)
1410 return GetColLabelSize();
1412 return GetRowLabelSize();
1415 void SetLabelAlignment( int orientation
, int align
)
1417 if ( orientation
== wxHORIZONTAL
)
1418 SetColLabelAlignment( align
, -1 );
1420 SetRowLabelAlignment( align
, -1 );
1423 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
1426 if ( orientation
== wxHORIZONTAL
)
1428 GetColLabelAlignment( &h
, &v
);
1433 GetRowLabelAlignment( &h
, &v
);
1438 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1440 if ( orientation
== wxHORIZONTAL
)
1441 SetColLabelValue( pos
, val
);
1443 SetRowLabelValue( pos
, val
);
1446 wxString
GetLabelValue( int orientation
, int pos
)
1448 if ( orientation
== wxHORIZONTAL
)
1449 return GetColLabelValue( pos
);
1451 return GetRowLabelValue( pos
);
1454 wxFont
GetCellTextFont() const
1455 { return m_defaultCellAttr
->GetFont(); }
1457 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1458 { return m_defaultCellAttr
->GetFont(); }
1460 void SetCellTextFont(const wxFont
& fnt
)
1461 { SetDefaultCellFont( fnt
); }
1463 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1464 { SetCellFont( row
, col
, fnt
); }
1466 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1467 { SetCellTextColour( row
, col
, val
); }
1469 void SetCellTextColour(const wxColour
& col
)
1470 { SetDefaultCellTextColour( col
); }
1472 void SetCellBackgroundColour(const wxColour
& col
)
1473 { SetDefaultCellBackgroundColour( col
); }
1475 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1476 { SetCellBackgroundColour( row
, col
, colour
); }
1478 bool GetEditable() { return IsEditable(); }
1479 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
1480 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
1482 void SetEditInPlace(bool edit
= TRUE
) { }
1484 void SetCellAlignment( int align
, int row
, int col
)
1485 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
1486 void SetCellAlignment( int WXUNUSED(align
) ) {}
1487 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1489 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1490 wxPen
& GetDividerPen() const { return wxNullPen
; }
1491 void OnActivate(bool WXUNUSED(active
)) {}
1493 // ******** End of compatibility functions **********
1497 // ------ control IDs
1498 enum { wxGRID_CELLCTRL
= 2000,
1501 // ------ control types
1502 enum { wxGRID_TEXTCTRL
= 2100,
1507 // overridden wxWindow methods
1511 virtual wxSize
DoGetBestSize() const;
1516 wxGridWindow
*m_gridWin
;
1517 wxGridRowLabelWindow
*m_rowLabelWin
;
1518 wxGridColLabelWindow
*m_colLabelWin
;
1519 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1521 wxGridTableBase
*m_table
;
1532 wxGridCellCoords m_currentCellCoords
;
1534 wxGridCellCoords m_selectedTopLeft
;
1535 wxGridCellCoords m_selectedBottomRight
;
1536 wxColour m_selectionBackground
;
1537 wxColour m_selectionForeground
;
1539 // NB: *never* access m_row/col arrays directly because they are created
1540 // on demand, *always* use accessor functions instead!
1542 // init the m_rowHeights/Bottoms arrays with default values
1543 void InitRowHeights();
1545 int m_defaultRowHeight
;
1546 wxArrayInt m_rowHeights
;
1547 wxArrayInt m_rowBottoms
;
1549 // init the m_colWidths/Rights arrays
1550 void InitColWidths();
1552 int m_defaultColWidth
;
1553 wxArrayInt m_colWidths
;
1554 wxArrayInt m_colRights
;
1556 // get the col/row coords
1557 int GetColWidth(int col
) const;
1558 int GetColLeft(int col
) const;
1559 int GetColRight(int col
) const;
1561 // this function must be public for compatibility...
1563 int GetRowHeight(int row
) const;
1566 int GetRowTop(int row
) const;
1567 int GetRowBottom(int row
) const;
1569 int m_rowLabelWidth
;
1570 int m_colLabelHeight
;
1572 // the size of the margin left to the right and bottom of the cell area
1576 wxColour m_labelBackgroundColour
;
1577 wxColour m_labelTextColour
;
1580 int m_rowLabelHorizAlign
;
1581 int m_rowLabelVertAlign
;
1582 int m_colLabelHorizAlign
;
1583 int m_colLabelVertAlign
;
1585 bool m_defaultRowLabelValues
;
1586 bool m_defaultColLabelValues
;
1588 wxColour m_gridLineColour
;
1589 bool m_gridLinesEnabled
;
1591 // common part of AutoSizeColumn/Row() and GetBestSize()
1592 int SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
= TRUE
);
1593 int SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
= TRUE
);
1595 // common part of AutoSizeColumn/Row()
1596 void AutoSizeColOrRow(int n
, bool setAsMin
, bool column
/* or row? */);
1598 // if a column has a minimal width, it will be the value for it in this
1600 wxHashTableLong m_colMinWidths
,
1603 // get the minimal width of the given column/row
1604 int GetColMinimalWidth(int col
) const;
1605 int GetRowMinimalHeight(int col
) const;
1607 // do we have some place to store attributes in?
1608 bool CanHaveAttributes();
1610 // returns the attribute we may modify in place: a new one if this cell
1611 // doesn't have any yet or the existing one if it does
1613 // DecRef() must be called on the returned pointer, as usual
1614 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1616 // cell attribute cache (currently we only cache 1, may be will do
1617 // more/better later)
1621 wxGridCellAttr
*attr
;
1624 // invalidates the attribute cache
1625 void ClearAttrCache();
1627 // adds an attribute to cache
1628 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
1630 // looks for an attr in cache, returns TRUE if found
1631 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
1633 // looks for the attr in cache, if not found asks the table and caches the
1635 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
1636 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
)
1637 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
1639 // the default cell attr object for cells that don't have their own
1640 wxGridCellAttr
* m_defaultCellAttr
;
1643 wxGridCellCoordsArray m_cellsExposed
;
1644 wxArrayInt m_rowsExposed
;
1645 wxArrayInt m_colsExposed
;
1646 wxArrayInt m_rowLabelsExposed
;
1647 wxArrayInt m_colLabelsExposed
;
1653 wxGridTypeRegistry
* m_typeRegistry
;
1657 WXGRID_CURSOR_SELECT_CELL
,
1658 WXGRID_CURSOR_RESIZE_ROW
,
1659 WXGRID_CURSOR_RESIZE_COL
,
1660 WXGRID_CURSOR_SELECT_ROW
,
1661 WXGRID_CURSOR_SELECT_COL
1664 // this method not only sets m_cursorMode but also sets the correct cursor
1665 // for the given mode and, if captureMouse is not FALSE releases the mouse
1666 // if it was captured and captures it if it must be captured
1668 // for this to work, you should always use it and not set m_cursorMode
1670 void ChangeCursorMode(CursorMode mode
,
1671 wxWindow
*win
= (wxWindow
*)NULL
,
1672 bool captureMouse
= TRUE
);
1674 wxWindow
*m_winCapture
; // the window which captured the mouse
1675 CursorMode m_cursorMode
;
1677 bool m_canDragRowSize
;
1678 bool m_canDragColSize
;
1679 bool m_canDragGridSize
;
1683 wxPoint m_startDragPos
;
1685 bool m_waitForSlowClick
;
1687 wxGridCellCoords m_selectionStart
;
1689 wxCursor m_rowResizeCursor
;
1690 wxCursor m_colResizeCursor
;
1692 bool m_editable
; // applies to whole grid
1693 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
1698 void CalcDimensions();
1699 void CalcWindowSizes();
1700 bool Redimension( wxGridTableMessage
& );
1703 bool SendEvent( const wxEventType
, int row
, int col
, wxMouseEvent
& );
1704 bool SendEvent( const wxEventType
, int row
, int col
);
1705 bool SendEvent( const wxEventType type
)
1707 return SendEvent(type
,
1708 m_currentCellCoords
.GetRow(),
1709 m_currentCellCoords
.GetCol());
1712 void OnPaint( wxPaintEvent
& );
1713 void OnSize( wxSizeEvent
& );
1714 void OnKeyDown( wxKeyEvent
& );
1715 void OnEraseBackground( wxEraseEvent
& );
1718 void SetCurrentCell( const wxGridCellCoords
& coords
);
1719 void SetCurrentCell( int row
, int col
)
1720 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1723 // ------ functions to get/send data (see also public functions)
1725 bool GetModelValues();
1726 bool SetModelValues();
1728 friend class wxGridSelection
;
1730 DECLARE_DYNAMIC_CLASS( wxGrid
)
1731 DECLARE_EVENT_TABLE()
1734 // ----------------------------------------------------------------------------
1735 // Grid event class and event types
1736 // ----------------------------------------------------------------------------
1738 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
1742 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
1743 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1747 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
1748 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
1749 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1751 virtual int GetRow() { return m_row
; }
1752 virtual int GetCol() { return m_col
; }
1753 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1754 bool ControlDown() { return m_control
; }
1755 bool MetaDown() { return m_meta
; }
1756 bool ShiftDown() { return m_shift
; }
1757 bool AltDown() { return m_alt
; }
1769 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
1772 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1776 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1777 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1781 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1782 int rowOrCol
=-1, int x
=-1, int y
=-1,
1783 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1785 int GetRowOrCol() { return m_rowOrCol
; }
1786 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1787 bool ControlDown() { return m_control
; }
1788 bool MetaDown() { return m_meta
; }
1789 bool ShiftDown() { return m_shift
; }
1790 bool AltDown() { return m_alt
; }
1801 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1805 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1808 wxGridRangeSelectEvent()
1811 m_topLeft
= wxGridNoCellCoords
;
1812 m_bottomRight
= wxGridNoCellCoords
;
1819 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1820 const wxGridCellCoords
& topLeft
,
1821 const wxGridCellCoords
& bottomRight
,
1822 bool control
=FALSE
, bool shift
=FALSE
,
1823 bool alt
=FALSE
, bool meta
=FALSE
);
1825 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1826 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1827 int GetTopRow() { return m_topLeft
.GetRow(); }
1828 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1829 int GetLeftCol() { return m_topLeft
.GetCol(); }
1830 int GetRightCol() { return m_bottomRight
.GetCol(); }
1831 bool ControlDown() { return m_control
; }
1832 bool MetaDown() { return m_meta
; }
1833 bool ShiftDown() { return m_shift
; }
1834 bool AltDown() { return m_alt
; }
1837 wxGridCellCoords m_topLeft
;
1838 wxGridCellCoords m_bottomRight
;
1844 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1847 // TODO move to wx/event.h
1848 const wxEventType wxEVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1849 const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1850 const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1851 const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1852 const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1853 const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1854 const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1855 const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1856 const wxEventType wxEVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1857 const wxEventType wxEVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1858 const wxEventType wxEVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1859 const wxEventType wxEVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1860 const wxEventType wxEVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1861 const wxEventType wxEVT_GRID_EDITOR_SHOWN
= wxEVT_FIRST
+ 1593;
1862 const wxEventType wxEVT_GRID_EDITOR_HIDDEN
= wxEVT_FIRST
+ 1594;
1865 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1866 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1867 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1869 #define EVT_GRID_CELL_LEFT_CLICK(fn) { wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1870 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1871 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1872 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1873 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1874 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1875 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1876 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1877 #define EVT_GRID_ROW_SIZE(fn) { wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1878 #define EVT_GRID_COL_SIZE(fn) { wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1879 #define EVT_GRID_RANGE_SELECT(fn) { wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1880 #define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1881 #define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1882 #define EVT_GRID_EDITOR_SHOWN(fn) { wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1883 #define EVT_GRID_EDITOR_HIDDEN(fn) { wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1886 #if 0 // TODO: implement these ? others ?
1888 const wxEventType wxEVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1889 const wxEventType wxEVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1890 const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1892 #define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1893 #define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1894 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1898 #endif // #ifndef __WXGRID_H__
1900 #endif // ifndef wxUSE_NEW_GRID