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 2
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
;
79 class WXDLLEXPORT wxGridSelection
;
81 class WXDLLEXPORT wxCheckBox
;
82 class WXDLLEXPORT wxComboBox
;
83 class WXDLLEXPORT wxTextCtrl
;
84 class WXDLLEXPORT wxSpinCtrl
;
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
91 #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
93 // ----------------------------------------------------------------------------
94 // wxGridCellWorker: common base class for wxGridCellRenderer and
97 // NB: this is more an implementation convenience than a design issue, so this
98 // class is not documented and is not public at all
99 // ----------------------------------------------------------------------------
101 class WXDLLEXPORT wxGridCellWorker
104 wxGridCellWorker() { m_nRef
= 1; }
106 // this class is ref counted: it is created with ref count of 1, so
107 // calling DecRef() once will delete it. Calling IncRef() allows to lock
108 // it until the matching DecRef() is called
109 void IncRef() { m_nRef
++; }
110 void DecRef() { if ( !--m_nRef
) delete this; }
112 // interpret renderer parameters: arbitrary string whose interpretatin is
113 // left to the derived classes
114 virtual void SetParameters(const wxString
& params
);
117 // virtual dtor for any base class - private because only DecRef() can
119 virtual ~wxGridCellWorker();
124 // suppress the stupid gcc warning about the class having private dtor and
126 friend class wxGridCellWorkerDummyFriend
;
129 // ----------------------------------------------------------------------------
130 // wxGridCellRenderer: this class is responsible for actually drawing the cell
131 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
132 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
133 // view of all cells. This is an ABC, you will normally use one of the
134 // predefined derived classes or derive your own class from it.
135 // ----------------------------------------------------------------------------
137 class WXDLLEXPORT wxGridCellRenderer
: public wxGridCellWorker
140 // draw the given cell on the provided DC inside the given rectangle
141 // using the style specified by the attribute and the default or selected
142 // state corresponding to the isSelected value.
144 // this pure virtual function has a default implementation which will
145 // prepare the DC using the given attribute: it will draw the rectangle
146 // with the bg colour from attr and set the text colour and font
147 virtual void Draw(wxGrid
& grid
,
148 wxGridCellAttr
& attr
,
152 bool isSelected
) = 0;
154 // get the preferred size of the cell for its contents
155 virtual wxSize
GetBestSize(wxGrid
& grid
,
156 wxGridCellAttr
& attr
,
158 int row
, int col
) = 0;
160 // create a new object which is the copy of this one
161 virtual wxGridCellRenderer
*Clone() const = 0;
164 // the default renderer for the cells containing string data
165 class WXDLLEXPORT wxGridCellStringRenderer
: public wxGridCellRenderer
169 virtual void Draw(wxGrid
& grid
,
170 wxGridCellAttr
& attr
,
176 // return the string extent
177 virtual wxSize
GetBestSize(wxGrid
& grid
,
178 wxGridCellAttr
& attr
,
182 virtual wxGridCellRenderer
*Clone() const
183 { return new wxGridCellStringRenderer
; }
186 // set the text colours before drawing
187 void SetTextColoursAndFont(wxGrid
& grid
,
188 wxGridCellAttr
& attr
,
192 // calc the string extent for given string/font
193 wxSize
DoGetBestSize(wxGridCellAttr
& attr
,
195 const wxString
& text
);
198 // the default renderer for the cells containing numeric (long) data
199 class WXDLLEXPORT wxGridCellNumberRenderer
: public wxGridCellStringRenderer
202 // draw the string right aligned
203 virtual void Draw(wxGrid
& grid
,
204 wxGridCellAttr
& attr
,
210 virtual wxSize
GetBestSize(wxGrid
& grid
,
211 wxGridCellAttr
& attr
,
215 virtual wxGridCellRenderer
*Clone() const
216 { return new wxGridCellNumberRenderer
; }
219 wxString
GetString(wxGrid
& grid
, int row
, int col
);
222 class WXDLLEXPORT wxGridCellFloatRenderer
: public wxGridCellStringRenderer
225 wxGridCellFloatRenderer(int width
= -1, int precision
= -1);
227 // get/change formatting parameters
228 int GetWidth() const { return m_width
; }
229 void SetWidth(int width
) { m_width
= width
; m_format
.clear(); }
230 int GetPrecision() const { return m_precision
; }
231 void SetPrecision(int precision
) { m_precision
= precision
; m_format
.clear(); }
233 // draw the string right aligned with given width/precision
234 virtual void Draw(wxGrid
& grid
,
235 wxGridCellAttr
& attr
,
241 virtual wxSize
GetBestSize(wxGrid
& grid
,
242 wxGridCellAttr
& attr
,
246 // parameters string format is "width[,precision]"
247 virtual void SetParameters(const wxString
& params
);
249 virtual wxGridCellRenderer
*Clone() const;
252 wxString
GetString(wxGrid
& grid
, int row
, int col
);
255 // formatting parameters
262 // renderer for boolean fields
263 class WXDLLEXPORT wxGridCellBoolRenderer
: public wxGridCellRenderer
266 // draw a check mark or nothing
267 virtual void Draw(wxGrid
& grid
,
268 wxGridCellAttr
& attr
,
274 // return the checkmark size
275 virtual wxSize
GetBestSize(wxGrid
& grid
,
276 wxGridCellAttr
& attr
,
280 virtual wxGridCellRenderer
*Clone() const
281 { return new wxGridCellBoolRenderer
; }
284 static wxSize ms_sizeCheckMark
;
287 // ----------------------------------------------------------------------------
288 // wxGridCellEditor: This class is responsible for providing and manipulating
289 // the in-place edit controls for the grid. Instances of wxGridCellEditor
290 // (actually, instances of derived classes since it is an ABC) can be
291 // associated with the cell attributes for individual cells, rows, columns, or
292 // even for the entire grid.
293 // ----------------------------------------------------------------------------
295 class WXDLLEXPORT wxGridCellEditor
: public wxGridCellWorker
300 bool IsCreated() { return m_control
!= NULL
; }
301 wxControl
* GetControl() { return m_control
; }
302 void SetControl(wxControl
* control
) { m_control
= control
; }
304 // Creates the actual edit control
305 virtual void Create(wxWindow
* parent
,
307 wxEvtHandler
* evtHandler
) = 0;
309 // Size and position the edit control
310 virtual void SetSize(const wxRect
& rect
);
312 // Show or hide the edit control, use the specified attributes to set
313 // colours/fonts for it
314 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
316 // Draws the part of the cell not occupied by the control: the base class
317 // version just fills it with background colour from the attribute
318 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
320 // Fetch the value from the table and prepare the edit control
321 // to begin editing. Set the focus to the edit control.
322 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
324 // Complete the editing of the current cell. Returns true if the value has
325 // changed. If necessary, the control may be destroyed.
326 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
) = 0;
328 // Reset the value in the control back to its starting value
329 virtual void Reset() = 0;
331 // return TRUE to allow the given key to start editing: the base class
332 // version only checks that the event has no modifiers. The derived
333 // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
334 // their IsAcceptedKey() implementation, although, of course, it is not a
335 // mandatory requirment.
337 // NB: if the key is F2 (special), editing will always start and this
338 // method will not be called at all (but StartingKey() will)
339 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
341 // If the editor is enabled by pressing keys on the grid, this will be
342 // called to let the editor do something about that first key if desired
343 virtual void StartingKey(wxKeyEvent
& event
);
345 // if the editor is enabled by clicking on the cell, this method will be
347 virtual void StartingClick();
349 // Some types of controls on some platforms may need some help
350 // with the Return key.
351 virtual void HandleReturn(wxKeyEvent
& event
);
354 virtual void Destroy();
356 // create a new object which is the copy of this one
357 virtual wxGridCellEditor
*Clone() const = 0;
360 // the dtor is private because only DecRef() can delete us
361 virtual ~wxGridCellEditor();
363 // the control we show on screen
364 wxControl
* m_control
;
366 // if we change the colours/font of the control from the default ones, we
367 // must restore the default later and we save them here between calls to
368 // Show(TRUE) and Show(FALSE)
373 // suppress the stupid gcc warning about the class having private dtor and
375 friend class wxGridCellEditorDummyFriend
;
378 // the editor for string/text data
379 class WXDLLEXPORT wxGridCellTextEditor
: public wxGridCellEditor
382 wxGridCellTextEditor();
384 virtual void Create(wxWindow
* parent
,
386 wxEvtHandler
* evtHandler
);
387 virtual void SetSize(const wxRect
& rect
);
389 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
391 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
392 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
393 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
395 virtual void Reset();
396 virtual void StartingKey(wxKeyEvent
& event
);
397 virtual void HandleReturn(wxKeyEvent
& event
);
399 // parameters string format is "max_width"
400 virtual void SetParameters(const wxString
& params
);
402 virtual wxGridCellEditor
*Clone() const
403 { return new wxGridCellTextEditor
; }
406 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
408 // parts of our virtual functions reused by the derived classes
409 void DoBeginEdit(const wxString
& startValue
);
410 void DoReset(const wxString
& startValue
);
413 size_t m_maxChars
; // max number of chars allowed
414 wxString m_startValue
;
417 // the editor for numeric (long) data
418 class WXDLLEXPORT wxGridCellNumberEditor
: public wxGridCellTextEditor
421 // allows to specify the range - if min == max == -1, no range checking is
423 wxGridCellNumberEditor(int min
= -1, int max
= -1);
425 virtual void Create(wxWindow
* parent
,
427 wxEvtHandler
* evtHandler
);
429 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
430 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
431 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
433 virtual void Reset();
434 virtual void StartingKey(wxKeyEvent
& event
);
436 // parameters string format is "min,max"
437 virtual void SetParameters(const wxString
& params
);
439 virtual wxGridCellEditor
*Clone() const
440 { return new wxGridCellNumberEditor(m_min
, m_max
); }
443 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
445 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
446 bool HasRange() const { return m_min
!= m_max
; }
448 // string representation of m_valueOld
449 wxString
GetString() const
450 { return wxString::Format(_T("%ld"), m_valueOld
); }
459 // the editor for floating point numbers (double) data
460 class WXDLLEXPORT wxGridCellFloatEditor
: public wxGridCellTextEditor
463 wxGridCellFloatEditor(int width
= -1, int precision
= -1);
465 virtual void Create(wxWindow
* parent
,
467 wxEvtHandler
* evtHandler
);
469 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
470 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
471 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
473 virtual void Reset();
474 virtual void StartingKey(wxKeyEvent
& event
);
476 virtual wxGridCellEditor
*Clone() const
477 { return new wxGridCellFloatEditor
; }
479 // parameters string format is "width,precision"
480 virtual void SetParameters(const wxString
& params
);
483 // string representation of m_valueOld
484 wxString
GetString() const;
492 // the editor for boolean data
493 class WXDLLEXPORT wxGridCellBoolEditor
: public wxGridCellEditor
496 virtual void Create(wxWindow
* parent
,
498 wxEvtHandler
* evtHandler
);
500 virtual void SetSize(const wxRect
& rect
);
501 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
503 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
504 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
505 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
507 virtual void Reset();
508 virtual void StartingClick();
510 virtual wxGridCellEditor
*Clone() const
511 { return new wxGridCellBoolEditor
; }
514 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
520 // the editor for string data allowing to choose from the list of strings
521 class WXDLLEXPORT wxGridCellChoiceEditor
: public wxGridCellEditor
524 // if !allowOthers, user can't type a string not in choices array
525 wxGridCellChoiceEditor(size_t count
= 0,
526 const wxString choices
[] = NULL
,
527 bool allowOthers
= FALSE
);
529 virtual void Create(wxWindow
* parent
,
531 wxEvtHandler
* evtHandler
);
533 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
535 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
536 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
538 virtual void Reset();
540 // parameters string format is "item1[,item2[...,itemN]]"
541 virtual void SetParameters(const wxString
& params
);
543 virtual wxGridCellEditor
*Clone() const;
546 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
549 wxString m_startValue
;
550 wxArrayString m_choices
;
554 // ----------------------------------------------------------------------------
555 // wxGridCellAttr: this class can be used to alter the cells appearance in
556 // the grid by changing their colour/font/... from default. An object of this
557 // class may be returned by wxGridTable::GetAttr().
558 // ----------------------------------------------------------------------------
560 class WXDLLEXPORT wxGridCellAttr
567 // MB: args used to be 0,0 here but wxALIGN_LEFT is 0
568 SetAlignment(-1, -1);
571 // VZ: considering the number of members wxGridCellAttr has now, this ctor
572 // seems to be pretty useless... may be we should just remove it?
573 wxGridCellAttr(const wxColour
& colText
,
574 const wxColour
& colBack
,
578 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
581 SetAlignment(hAlign
, vAlign
);
584 // creates a new copy of this object
585 wxGridCellAttr
*Clone() const;
587 // this class is ref counted: it is created with ref count of 1, so
588 // calling DecRef() once will delete it. Calling IncRef() allows to lock
589 // it until the matching DecRef() is called
590 void IncRef() { m_nRef
++; }
591 void DecRef() { if ( !--m_nRef
) delete this; }
594 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
595 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
596 void SetFont(const wxFont
& font
) { m_font
= font
; }
597 void SetAlignment(int hAlign
, int vAlign
)
602 void SetReadOnly(bool isReadOnly
= TRUE
) { m_isReadOnly
= isReadOnly
; }
604 // takes ownership of the pointer
605 void SetRenderer(wxGridCellRenderer
*renderer
)
606 { wxSafeDecRef(m_renderer
); m_renderer
= renderer
; }
607 void SetEditor(wxGridCellEditor
* editor
)
608 { wxSafeDecRef(m_editor
); m_editor
= editor
; }
611 bool HasTextColour() const { return m_colText
.Ok(); }
612 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
613 bool HasFont() const { return m_font
.Ok(); }
614 bool HasAlignment() const { return (m_hAlign
!= -1 || m_vAlign
!= -1); }
615 bool HasRenderer() const { return m_renderer
!= NULL
; }
616 bool HasEditor() const { return m_editor
!= NULL
; }
618 const wxColour
& GetTextColour() const;
619 const wxColour
& GetBackgroundColour() const;
620 const wxFont
& GetFont() const;
621 void GetAlignment(int *hAlign
, int *vAlign
) const;
622 wxGridCellRenderer
*GetRenderer(wxGrid
* grid
, int row
, int col
) const;
623 wxGridCellEditor
*GetEditor(wxGrid
* grid
, int row
, int col
) const;
625 bool IsReadOnly() const { return m_isReadOnly
; }
627 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
630 // the common part of all ctors
635 m_isReadOnly
= FALSE
;
641 // the dtor is private because only DecRef() can delete us
644 wxSafeDecRef(m_renderer
);
645 wxSafeDecRef(m_editor
);
648 // the ref count - when it goes to 0, we die
657 wxGridCellRenderer
* m_renderer
;
658 wxGridCellEditor
* m_editor
;
659 wxGridCellAttr
* m_defGridAttr
;
663 // use Clone() instead
664 DECLARE_NO_COPY_CLASS(wxGridCellAttr
);
666 // suppress the stupid gcc warning about the class having private dtor and
668 friend class wxGridCellAttrDummyFriend
;
671 // ----------------------------------------------------------------------------
672 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
674 // ----------------------------------------------------------------------------
676 // implementation note: we separate it from wxGridTableBase because we wish to
677 // avoid deriving a new table class if possible, and sometimes it will be
678 // enough to just derive another wxGridCellAttrProvider instead
680 // the default implementation is reasonably efficient for the generic case,
681 // but you might still wish to implement your own for some specific situations
682 // if you have performance problems with the stock one
683 class WXDLLEXPORT wxGridCellAttrProvider
686 wxGridCellAttrProvider();
687 virtual ~wxGridCellAttrProvider();
689 // DecRef() must be called on the returned pointer
690 virtual wxGridCellAttr
*GetAttr(int row
, int col
) const;
692 // all these functions take ownership of the pointer, don't call DecRef()
694 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
695 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
696 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
698 // these functions must be called whenever some rows/cols are deleted
699 // because the internal data must be updated then
700 void UpdateAttrRows( size_t pos
, int numRows
);
701 void UpdateAttrCols( size_t pos
, int numCols
);
706 wxGridCellAttrProviderData
*m_data
;
709 //////////////////////////////////////////////////////////////////////
711 // Grid table classes
713 //////////////////////////////////////////////////////////////////////
716 class WXDLLEXPORT wxGridTableBase
: public wxObject
720 virtual ~wxGridTableBase();
722 // You must override these functions in a derived table class
724 virtual int GetNumberRows() = 0;
725 virtual int GetNumberCols() = 0;
726 virtual bool IsEmptyCell( int row
, int col
) = 0;
727 virtual wxString
GetValue( int row
, int col
) = 0;
728 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
730 // Data type determination and value access
731 virtual wxString
GetTypeName( int row
, int col
);
732 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
733 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
735 virtual long GetValueAsLong( int row
, int col
);
736 virtual double GetValueAsDouble( int row
, int col
);
737 virtual bool GetValueAsBool( int row
, int col
);
739 virtual void SetValueAsLong( int row
, int col
, long value
);
740 virtual void SetValueAsDouble( int row
, int col
, double value
);
741 virtual void SetValueAsBool( int row
, int col
, bool value
);
743 // For user defined types
744 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
745 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
748 // Overriding these is optional
750 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
751 virtual wxGrid
* GetView() const { return m_view
; }
753 virtual void Clear() {}
754 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
755 virtual bool AppendRows( size_t numRows
= 1 );
756 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
757 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
758 virtual bool AppendCols( size_t numCols
= 1 );
759 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
761 virtual wxString
GetRowLabelValue( int row
);
762 virtual wxString
GetColLabelValue( int col
);
763 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
764 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
766 // Attribute handling
769 // give us the attr provider to use - we take ownership of the pointer
770 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
772 // get the currently used attr provider (may be NULL)
773 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
775 // Does this table allow attributes? Default implementation creates
776 // a wxGridCellAttrProvider if necessary.
777 virtual bool CanHaveAttributes();
779 // by default forwarded to wxGridCellAttrProvider if any. May be
780 // overridden to handle attributes directly in the table.
781 virtual wxGridCellAttr
*GetAttr( int row
, int col
);
783 // these functions take ownership of the pointer
784 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
785 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
786 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
790 wxGridCellAttrProvider
*m_attrProvider
;
792 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
796 // ----------------------------------------------------------------------------
797 // wxGridTableMessage
798 // ----------------------------------------------------------------------------
800 // IDs for messages sent from grid table to view
802 enum wxGridTableRequest
804 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
805 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
806 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
807 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
808 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
809 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
810 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
811 wxGRIDTABLE_NOTIFY_COLS_DELETED
814 class WXDLLEXPORT wxGridTableMessage
817 wxGridTableMessage();
818 wxGridTableMessage( wxGridTableBase
*table
, int id
,
822 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
823 wxGridTableBase
* GetTableObject() const { return m_table
; }
824 void SetId( int id
) { m_id
= id
; }
825 int GetId() { return m_id
; }
826 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
827 int GetCommandInt() { return m_comInt1
; }
828 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
829 int GetCommandInt2() { return m_comInt2
; }
832 wxGridTableBase
*m_table
;
840 // ------ wxGridStringArray
841 // A 2-dimensional array of strings for data values
844 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
848 // ------ wxGridStringTable
850 // Simplest type of data table for a grid for small tables of strings
851 // that are stored in memory
854 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
858 wxGridStringTable( int numRows
, int numCols
);
859 ~wxGridStringTable();
861 // these are pure virtual in wxGridTableBase
865 wxString
GetValue( int row
, int col
);
866 void SetValue( int row
, int col
, const wxString
& s
);
867 bool IsEmptyCell( int row
, int col
);
869 // overridden functions from wxGridTableBase
872 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
873 bool AppendRows( size_t numRows
= 1 );
874 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
875 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
876 bool AppendCols( size_t numCols
= 1 );
877 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
879 void SetRowLabelValue( int row
, const wxString
& );
880 void SetColLabelValue( int col
, const wxString
& );
881 wxString
GetRowLabelValue( int row
);
882 wxString
GetColLabelValue( int col
);
885 wxGridStringArray m_data
;
887 // These only get used if you set your own labels, otherwise the
888 // GetRow/ColLabelValue functions return wxGridTableBase defaults
890 wxArrayString m_rowLabels
;
891 wxArrayString m_colLabels
;
893 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
898 // ============================================================================
900 // ============================================================================
902 // ----------------------------------------------------------------------------
903 // wxGridCellCoords: location of a cell in the grid
904 // ----------------------------------------------------------------------------
906 class WXDLLEXPORT wxGridCellCoords
909 wxGridCellCoords() { m_row
= m_col
= -1; }
910 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
912 // default copy ctor is ok
914 int GetRow() const { return m_row
; }
915 void SetRow( int n
) { m_row
= n
; }
916 int GetCol() const { return m_col
; }
917 void SetCol( int n
) { m_col
= n
; }
918 void Set( int row
, int col
) { m_row
= row
; m_col
= col
; }
920 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
922 if ( &other
!= this )
930 bool operator==( const wxGridCellCoords
& other
) const
932 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
935 bool operator!=( const wxGridCellCoords
& other
) const
937 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
940 bool operator!() const
942 return (m_row
== -1 && m_col
== -1 );
951 // For comparisons...
953 extern WXDLLEXPORT wxGridCellCoords wxGridNoCellCoords
;
954 extern WXDLLEXPORT wxRect wxGridNoCellRect
;
956 // An array of cell coords...
958 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
960 // ----------------------------------------------------------------------------
962 // ----------------------------------------------------------------------------
964 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
972 wxGrid( wxWindow
*parent
,
974 const wxPoint
& pos
= wxDefaultPosition
,
975 const wxSize
& size
= wxDefaultSize
,
976 long style
= wxWANTS_CHARS
,
977 const wxString
& name
= wxPanelNameStr
);
981 enum wxGridSelectionModes
{wxGridSelectCells
,
983 wxGridSelectColumns
};
985 bool CreateGrid( int numRows
, int numCols
,
986 wxGrid::wxGridSelectionModes selmode
=
987 wxGrid::wxGridSelectCells
);
989 void SetSelectionMode(wxGrid::wxGridSelectionModes selmode
);
991 // ------ grid dimensions
993 int GetNumberRows() { return m_numRows
; }
994 int GetNumberCols() { return m_numCols
; }
997 // ------ display update functions
999 void CalcRowLabelsExposed( const wxRegion
& reg
);
1001 void CalcColLabelsExposed( const wxRegion
& reg
);
1002 void CalcCellsExposed( const wxRegion
& reg
);
1005 // ------ event handlers
1007 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
1008 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
1009 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
1010 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
1011 bool ProcessTableMessage( wxGridTableMessage
& );
1013 void DoEndDragResizeRow();
1014 void DoEndDragResizeCol();
1016 wxGridTableBase
* GetTable() const { return m_table
; }
1017 bool SetTable( wxGridTableBase
*table
, bool takeOwnership
=FALSE
,
1018 wxGrid::wxGridSelectionModes selmode
=
1019 wxGrid::wxGridSelectCells
);
1022 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
1023 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
1024 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
1025 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
1026 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
1027 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
1029 void DrawGridCellArea( wxDC
& dc
);
1030 void DrawGridSpace( wxDC
& dc
);
1031 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
1032 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
1033 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
1034 void DrawHighlight(wxDC
& dc
);
1036 // this function is called when the current cell highlight must be redrawn
1037 // and may be overridden by the user
1038 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
1040 void DrawRowLabels( wxDC
& dc
);
1041 void DrawRowLabel( wxDC
& dc
, int row
);
1043 void DrawColLabels( wxDC
& dc
);
1044 void DrawColLabel( wxDC
& dc
, int col
);
1047 // ------ Cell text drawing functions
1049 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
1050 int horizontalAlignment
= wxALIGN_LEFT
,
1051 int verticalAlignment
= wxALIGN_TOP
);
1053 // Split a string containing newline chararcters into an array of
1054 // strings and return the number of lines
1056 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
1058 void GetTextBoxSize( wxDC
& dc
,
1059 wxArrayString
& lines
,
1060 long *width
, long *height
);
1064 // Code that does a lot of grid modification can be enclosed
1065 // between BeginBatch() and EndBatch() calls to avoid screen
1068 void BeginBatch() { m_batchCount
++; }
1071 int GetBatchCount() { return m_batchCount
; }
1073 // Use this, rather than wxWindow::Refresh(), to force an
1074 // immediate repainting of the grid. Has no effect if you are
1075 // already inside a BeginBatch / EndBatch block.
1077 // This function is necessary because wxGrid has a minimal OnPaint()
1078 // handler to reduce screen flicker.
1080 void ForceRefresh();
1083 // ------ edit control functions
1085 bool IsEditable() { return m_editable
; }
1086 void EnableEditing( bool edit
);
1088 void EnableCellEditControl( bool enable
= TRUE
);
1089 void DisableCellEditControl() { EnableCellEditControl(FALSE
); }
1090 bool CanEnableCellControl() const;
1091 bool IsCellEditControlEnabled() const;
1092 bool IsCellEditControlShown() const;
1094 bool IsCurrentCellReadOnly() const;
1096 void ShowCellEditControl();
1097 void HideCellEditControl();
1098 void SaveEditControlValue();
1101 // ------ grid location functions
1102 // Note that all of these functions work with the logical coordinates of
1103 // grid cells and labels so you will need to convert from device
1104 // coordinates for mouse events etc.
1106 void XYToCell( int x
, int y
, wxGridCellCoords
& );
1107 int YToRow( int y
);
1108 int XToCol( int x
);
1110 int YToEdgeOfRow( int y
);
1111 int XToEdgeOfCol( int x
);
1113 wxRect
CellToRect( int row
, int col
);
1114 wxRect
CellToRect( const wxGridCellCoords
& coords
)
1115 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
1117 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
1118 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
1120 // check to see if a cell is either wholly visible (the default arg) or
1121 // at least partially visible in the grid window
1123 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
1124 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
1125 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
1126 void MakeCellVisible( int row
, int col
);
1127 void MakeCellVisible( const wxGridCellCoords
& coords
)
1128 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
1131 // ------ grid cursor movement functions
1133 void SetGridCursor( int row
, int col
)
1134 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1136 bool MoveCursorUp( bool expandSelection
);
1137 bool MoveCursorDown( bool expandSelection
);
1138 bool MoveCursorLeft( bool expandSelection
);
1139 bool MoveCursorRight( bool expandSelection
);
1140 bool MovePageDown();
1142 bool MoveCursorUpBlock( bool expandSelection
);
1143 bool MoveCursorDownBlock( bool expandSelection
);
1144 bool MoveCursorLeftBlock( bool expandSelection
);
1145 bool MoveCursorRightBlock( bool expandSelection
);
1148 // ------ label and gridline formatting
1150 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
1151 int GetRowLabelSize() { return m_rowLabelWidth
; }
1152 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
1153 int GetColLabelSize() { return m_colLabelHeight
; }
1154 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
1155 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
1156 wxFont
GetLabelFont() { return m_labelFont
; }
1157 void GetRowLabelAlignment( int *horiz
, int *vert
);
1158 void GetColLabelAlignment( int *horiz
, int *vert
);
1159 wxString
GetRowLabelValue( int row
);
1160 wxString
GetColLabelValue( int col
);
1161 wxColour
GetGridLineColour() { return m_gridLineColour
; }
1162 wxColour
GetCellHighlightColour() { return m_cellHighlightColour
; }
1163 int GetCellHighlightPenWidth() { return m_cellHighlightPenWidth
; }
1164 int GetCellHighlightROPenWidth() { return m_cellHighlightROPenWidth
; }
1166 void SetRowLabelSize( int width
);
1167 void SetColLabelSize( int height
);
1168 void SetLabelBackgroundColour( const wxColour
& );
1169 void SetLabelTextColour( const wxColour
& );
1170 void SetLabelFont( const wxFont
& );
1171 void SetRowLabelAlignment( int horiz
, int vert
);
1172 void SetColLabelAlignment( int horiz
, int vert
);
1173 void SetRowLabelValue( int row
, const wxString
& );
1174 void SetColLabelValue( int col
, const wxString
& );
1175 void SetGridLineColour( const wxColour
& );
1176 void SetCellHighlightColour( const wxColour
& );
1177 void SetCellHighlightPenWidth(int width
);
1178 void SetCellHighlightROPenWidth(int width
);
1180 void EnableDragRowSize( bool enable
= TRUE
);
1181 void DisableDragRowSize() { EnableDragRowSize( FALSE
); }
1182 bool CanDragRowSize() { return m_canDragRowSize
; }
1183 void EnableDragColSize( bool enable
= TRUE
);
1184 void DisableDragColSize() { EnableDragColSize( FALSE
); }
1185 bool CanDragColSize() { return m_canDragColSize
; }
1186 void EnableDragGridSize(bool enable
= TRUE
);
1187 void DisableDragGridSize() { EnableDragGridSize(FALSE
); }
1188 bool CanDragGridSize() { return m_canDragGridSize
; }
1190 // this sets the specified attribute for all cells in this row/col
1191 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
1192 void SetColAttr(int col
, wxGridCellAttr
*attr
);
1194 // shortcuts for setting the column parameters
1196 // set the format for the data in the column: default is string
1197 void SetColFormatBool(int col
);
1198 void SetColFormatNumber(int col
);
1199 void SetColFormatFloat(int col
, int width
= -1, int precision
= -1);
1200 void SetColFormatCustom(int col
, const wxString
& typeName
);
1202 void EnableGridLines( bool enable
= TRUE
);
1203 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
1205 // ------ row and col formatting
1207 int GetDefaultRowSize();
1208 int GetRowSize( int row
);
1209 int GetDefaultColSize();
1210 int GetColSize( int col
);
1211 wxColour
GetDefaultCellBackgroundColour();
1212 wxColour
GetCellBackgroundColour( int row
, int col
);
1213 wxColour
GetDefaultCellTextColour();
1214 wxColour
GetCellTextColour( int row
, int col
);
1215 wxFont
GetDefaultCellFont();
1216 wxFont
GetCellFont( int row
, int col
);
1217 void GetDefaultCellAlignment( int *horiz
, int *vert
);
1218 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
1220 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
1221 void SetRowSize( int row
, int height
);
1222 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
1224 void SetColSize( int col
, int width
);
1226 // automatically size the column or row to fit to its contents, if
1227 // setAsMin is TRUE, this optimal width will also be set as minimal width
1229 void AutoSizeColumn( int col
, bool setAsMin
= TRUE
)
1230 { AutoSizeColOrRow(col
, setAsMin
, TRUE
); }
1231 void AutoSizeRow( int row
, bool setAsMin
= TRUE
)
1232 { AutoSizeColOrRow(row
, setAsMin
, FALSE
); }
1234 // auto size all columns (very ineffective for big grids!)
1235 void AutoSizeColumns( bool setAsMin
= TRUE
)
1236 { (void)SetOrCalcColumnSizes(FALSE
, setAsMin
); }
1238 void AutoSizeRows( bool setAsMin
= TRUE
)
1239 { (void)SetOrCalcRowSizes(FALSE
, setAsMin
); }
1241 // auto size the grid, that is make the columns/rows of the "right" size
1242 // and also set the grid size to just fit its contents
1245 // column won't be resized to be lesser width - this must be called during
1246 // the grid creation because it won't resize the column if it's already
1247 // narrower than the minimal width
1248 void SetColMinimalWidth( int col
, int width
);
1249 void SetRowMinimalHeight( int row
, int width
);
1251 void SetDefaultCellBackgroundColour( const wxColour
& );
1252 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1253 void SetDefaultCellTextColour( const wxColour
& );
1255 void SetCellTextColour( int row
, int col
, const wxColour
& );
1256 void SetDefaultCellFont( const wxFont
& );
1257 void SetCellFont( int row
, int col
, const wxFont
& );
1258 void SetDefaultCellAlignment( int horiz
, int vert
);
1259 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1261 // takes ownership of the pointer
1262 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1263 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1264 wxGridCellRenderer
*GetDefaultRenderer() const;
1265 wxGridCellRenderer
* GetCellRenderer(int row
, int col
);
1267 // takes ownership of the pointer
1268 void SetDefaultEditor(wxGridCellEditor
*editor
);
1269 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1270 wxGridCellEditor
*GetDefaultEditor() const;
1271 wxGridCellEditor
* GetCellEditor(int row
, int col
);
1275 // ------ cell value accessors
1277 wxString
GetCellValue( int row
, int col
)
1281 return m_table
->GetValue( row
, col
);
1285 return wxEmptyString
;
1289 wxString
GetCellValue( const wxGridCellCoords
& coords
)
1290 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1292 void SetCellValue( int row
, int col
, const wxString
& s
);
1293 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1294 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1296 // returns TRUE if the cell can't be edited
1297 bool IsReadOnly(int row
, int col
) const;
1299 // make the cell editable/readonly
1300 void SetReadOnly(int row
, int col
, bool isReadOnly
= TRUE
);
1302 // ------ selections of blocks of cells
1304 void SelectRow( int row
, bool addToSelected
= FALSE
);
1305 void SelectCol( int col
, bool addToSelected
= FALSE
);
1307 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
,
1308 bool addToSelected
= FALSE
);
1310 void SelectBlock( const wxGridCellCoords
& topLeft
,
1311 const wxGridCellCoords
& bottomRight
,
1312 bool addToSelected
= FALSE
)
1313 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1314 bottomRight
.GetRow(), bottomRight
.GetCol(),
1321 // ------ deselection
1323 void DeselectRow( int row
);
1324 void DeselectCol( int col
);
1325 void DeselectCell( int row
, int col
);
1327 void ClearSelection();
1329 bool IsInSelection( int row
, int col
);
1331 bool IsInSelection( const wxGridCellCoords
& coords
)
1332 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1335 // This function returns the rectangle that encloses the block of cells
1336 // limited by TopLeft and BottomRight cell in device coords and clipped
1337 // to the client size of the grid window.
1339 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1340 const wxGridCellCoords
& bottomRight
);
1342 // Access or update the selection fore/back colours
1343 wxColour
GetSelectionBackground() const
1344 { return m_selectionBackground
; }
1345 wxColour
GetSelectionForeground() const
1346 { return m_selectionForeground
; }
1348 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1349 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1352 // Methods for a registry for mapping data types to Renderers/Editors
1353 void RegisterDataType(const wxString
& typeName
,
1354 wxGridCellRenderer
* renderer
,
1355 wxGridCellEditor
* editor
);
1356 wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1357 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1358 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1359 wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1360 wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1361 wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1363 // grid may occupy more space than needed for its rows/columns, this
1364 // function allows to set how big this extra space is
1365 void SetMargins(int extraWidth
, int extraHeight
)
1367 m_extraWidth
= extraWidth
;
1368 m_extraHeight
= extraHeight
;
1371 // Accessors for component windows
1372 wxWindow
* GetGridWindow() { return (wxWindow
*)m_gridWin
; }
1373 wxWindow
* GetGridRowLabelWindow() { return (wxWindow
*)m_rowLabelWin
; }
1374 wxWindow
* GetGridColLabelWindow() { return (wxWindow
*)m_colLabelWin
; }
1375 wxWindow
* GetGridCornerLabelWindow() { return (wxWindow
*)m_cornerLabelWin
; }
1379 // ------ For compatibility with previous wxGrid only...
1381 // ************************************************
1382 // ** Don't use these in new code because they **
1383 // ** are liable to disappear in a future **
1385 // ************************************************
1388 wxGrid( wxWindow
*parent
,
1389 int x
, int y
, int w
= -1, int h
= -1,
1390 long style
= wxWANTS_CHARS
,
1391 const wxString
& name
= wxPanelNameStr
)
1392 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
),
1393 (style
|wxWANTS_CHARS
), name
)
1398 void SetCellValue( const wxString
& val
, int row
, int col
)
1399 { SetCellValue( row
, col
, val
); }
1401 void UpdateDimensions()
1402 { CalcDimensions(); }
1404 int GetRows() { return GetNumberRows(); }
1405 int GetCols() { return GetNumberCols(); }
1406 int GetCursorRow() { return GetGridCursorRow(); }
1407 int GetCursorColumn() { return GetGridCursorCol(); }
1409 int GetScrollPosX() { return 0; }
1410 int GetScrollPosY() { return 0; }
1412 void SetScrollX( int WXUNUSED(x
) ) { }
1413 void SetScrollY( int WXUNUSED(y
) ) { }
1415 void SetColumnWidth( int col
, int width
)
1416 { SetColSize( col
, width
); }
1418 int GetColumnWidth( int col
)
1419 { return GetColSize( col
); }
1421 void SetRowHeight( int row
, int height
)
1422 { SetRowSize( row
, height
); }
1424 // GetRowHeight() is below
1426 int GetViewHeight() // returned num whole rows visible
1429 int GetViewWidth() // returned num whole cols visible
1432 void SetLabelSize( int orientation
, int sz
)
1434 if ( orientation
== wxHORIZONTAL
)
1435 SetColLabelSize( sz
);
1437 SetRowLabelSize( sz
);
1440 int GetLabelSize( int orientation
)
1442 if ( orientation
== wxHORIZONTAL
)
1443 return GetColLabelSize();
1445 return GetRowLabelSize();
1448 void SetLabelAlignment( int orientation
, int align
)
1450 if ( orientation
== wxHORIZONTAL
)
1451 SetColLabelAlignment( align
, -1 );
1453 SetRowLabelAlignment( align
, -1 );
1456 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
1459 if ( orientation
== wxHORIZONTAL
)
1461 GetColLabelAlignment( &h
, &v
);
1466 GetRowLabelAlignment( &h
, &v
);
1471 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1473 if ( orientation
== wxHORIZONTAL
)
1474 SetColLabelValue( pos
, val
);
1476 SetRowLabelValue( pos
, val
);
1479 wxString
GetLabelValue( int orientation
, int pos
)
1481 if ( orientation
== wxHORIZONTAL
)
1482 return GetColLabelValue( pos
);
1484 return GetRowLabelValue( pos
);
1487 wxFont
GetCellTextFont() const
1488 { return m_defaultCellAttr
->GetFont(); }
1490 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1491 { return m_defaultCellAttr
->GetFont(); }
1493 void SetCellTextFont(const wxFont
& fnt
)
1494 { SetDefaultCellFont( fnt
); }
1496 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1497 { SetCellFont( row
, col
, fnt
); }
1499 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1500 { SetCellTextColour( row
, col
, val
); }
1502 void SetCellTextColour(const wxColour
& col
)
1503 { SetDefaultCellTextColour( col
); }
1505 void SetCellBackgroundColour(const wxColour
& col
)
1506 { SetDefaultCellBackgroundColour( col
); }
1508 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1509 { SetCellBackgroundColour( row
, col
, colour
); }
1511 bool GetEditable() { return IsEditable(); }
1512 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
1513 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
1515 void SetEditInPlace(bool WXUNUSED(edit
) = TRUE
) { }
1517 void SetCellAlignment( int align
, int row
, int col
)
1518 { SetCellAlignment(row
, col
, align
, wxALIGN_CENTER
); }
1519 void SetCellAlignment( int WXUNUSED(align
) ) {}
1520 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1522 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1523 wxPen
& GetDividerPen() const;
1524 void OnActivate(bool WXUNUSED(active
)) {}
1526 // ******** End of compatibility functions **********
1530 // ------ control IDs
1531 enum { wxGRID_CELLCTRL
= 2000,
1534 // ------ control types
1535 enum { wxGRID_TEXTCTRL
= 2100,
1540 // overridden wxWindow methods
1544 virtual wxSize
DoGetBestSize() const;
1548 wxGridWindow
*m_gridWin
;
1549 wxGridRowLabelWindow
*m_rowLabelWin
;
1550 wxGridColLabelWindow
*m_colLabelWin
;
1551 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1553 wxGridTableBase
*m_table
;
1559 wxGridCellCoords m_currentCellCoords
;
1561 wxGridCellCoords m_selectingTopLeft
;
1562 wxGridCellCoords m_selectingBottomRight
;
1563 wxGridCellCoords m_selectingKeyboard
;
1564 wxGridSelection
*m_selection
;
1565 wxColour m_selectionBackground
;
1566 wxColour m_selectionForeground
;
1568 // NB: *never* access m_row/col arrays directly because they are created
1569 // on demand, *always* use accessor functions instead!
1571 // init the m_rowHeights/Bottoms arrays with default values
1572 void InitRowHeights();
1574 int m_defaultRowHeight
;
1575 wxArrayInt m_rowHeights
;
1576 wxArrayInt m_rowBottoms
;
1578 // init the m_colWidths/Rights arrays
1579 void InitColWidths();
1581 int m_defaultColWidth
;
1582 wxArrayInt m_colWidths
;
1583 wxArrayInt m_colRights
;
1585 // get the col/row coords
1586 int GetColWidth(int col
) const;
1587 int GetColLeft(int col
) const;
1588 int GetColRight(int col
) const;
1590 // this function must be public for compatibility...
1592 int GetRowHeight(int row
) const;
1595 int GetRowTop(int row
) const;
1596 int GetRowBottom(int row
) const;
1598 int m_rowLabelWidth
;
1599 int m_colLabelHeight
;
1601 // the size of the margin left to the right and bottom of the cell area
1605 wxColour m_labelBackgroundColour
;
1606 wxColour m_labelTextColour
;
1609 int m_rowLabelHorizAlign
;
1610 int m_rowLabelVertAlign
;
1611 int m_colLabelHorizAlign
;
1612 int m_colLabelVertAlign
;
1614 bool m_defaultRowLabelValues
;
1615 bool m_defaultColLabelValues
;
1617 wxColour m_gridLineColour
;
1618 bool m_gridLinesEnabled
;
1619 wxColour m_cellHighlightColour
;
1620 int m_cellHighlightPenWidth
;
1621 int m_cellHighlightROPenWidth
;
1624 // common part of AutoSizeColumn/Row() and GetBestSize()
1625 int SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
= TRUE
);
1626 int SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
= TRUE
);
1628 // common part of AutoSizeColumn/Row()
1629 void AutoSizeColOrRow(int n
, bool setAsMin
, bool column
/* or row? */);
1631 // if a column has a minimal width, it will be the value for it in this
1633 wxHashTableLong m_colMinWidths
,
1636 // get the minimal width of the given column/row
1637 int GetColMinimalWidth(int col
) const;
1638 int GetRowMinimalHeight(int col
) const;
1640 // do we have some place to store attributes in?
1641 bool CanHaveAttributes();
1643 // returns the attribute we may modify in place: a new one if this cell
1644 // doesn't have any yet or the existing one if it does
1646 // DecRef() must be called on the returned pointer, as usual
1647 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1649 // cell attribute cache (currently we only cache 1, may be will do
1650 // more/better later)
1654 wxGridCellAttr
*attr
;
1657 // invalidates the attribute cache
1658 void ClearAttrCache();
1660 // adds an attribute to cache
1661 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
1663 // looks for an attr in cache, returns TRUE if found
1664 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
1666 // looks for the attr in cache, if not found asks the table and caches the
1668 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
1669 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
)
1670 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
1672 // the default cell attr object for cells that don't have their own
1673 wxGridCellAttr
* m_defaultCellAttr
;
1676 wxGridCellCoordsArray m_cellsExposed
;
1677 wxArrayInt m_rowsExposed
;
1678 wxArrayInt m_colsExposed
;
1679 wxArrayInt m_rowLabelsExposed
;
1680 wxArrayInt m_colLabelsExposed
;
1686 wxGridTypeRegistry
* m_typeRegistry
;
1690 WXGRID_CURSOR_SELECT_CELL
,
1691 WXGRID_CURSOR_RESIZE_ROW
,
1692 WXGRID_CURSOR_RESIZE_COL
,
1693 WXGRID_CURSOR_SELECT_ROW
,
1694 WXGRID_CURSOR_SELECT_COL
1697 // this method not only sets m_cursorMode but also sets the correct cursor
1698 // for the given mode and, if captureMouse is not FALSE releases the mouse
1699 // if it was captured and captures it if it must be captured
1701 // for this to work, you should always use it and not set m_cursorMode
1703 void ChangeCursorMode(CursorMode mode
,
1704 wxWindow
*win
= (wxWindow
*)NULL
,
1705 bool captureMouse
= TRUE
);
1707 wxWindow
*m_winCapture
; // the window which captured the mouse
1708 CursorMode m_cursorMode
;
1710 bool m_canDragRowSize
;
1711 bool m_canDragColSize
;
1712 bool m_canDragGridSize
;
1716 wxPoint m_startDragPos
;
1718 bool m_waitForSlowClick
;
1720 wxGridCellCoords m_selectionStart
;
1722 wxCursor m_rowResizeCursor
;
1723 wxCursor m_colResizeCursor
;
1725 bool m_editable
; // applies to whole grid
1726 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
1731 void CalcDimensions();
1732 void CalcWindowSizes();
1733 bool Redimension( wxGridTableMessage
& );
1736 bool SendEvent( const wxEventType
, int row
, int col
, wxMouseEvent
& );
1737 bool SendEvent( const wxEventType
, int row
, int col
);
1738 bool SendEvent( const wxEventType type
)
1740 return SendEvent(type
,
1741 m_currentCellCoords
.GetRow(),
1742 m_currentCellCoords
.GetCol());
1745 void OnPaint( wxPaintEvent
& );
1746 void OnSize( wxSizeEvent
& );
1747 void OnKeyDown( wxKeyEvent
& );
1748 void OnKeyUp( wxKeyEvent
& );
1749 void OnEraseBackground( wxEraseEvent
& );
1752 void SetCurrentCell( const wxGridCellCoords
& coords
);
1753 void SetCurrentCell( int row
, int col
)
1754 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1756 void HighlightBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
1758 void HighlightBlock( const wxGridCellCoords
& topLeft
,
1759 const wxGridCellCoords
& bottomRight
)
1760 { HighlightBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1761 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
1763 // ------ functions to get/send data (see also public functions)
1765 bool GetModelValues();
1766 bool SetModelValues();
1768 friend class wxGridSelection
;
1770 DECLARE_DYNAMIC_CLASS( wxGrid
)
1771 DECLARE_EVENT_TABLE()
1774 // ----------------------------------------------------------------------------
1775 // Grid event class and event types
1776 // ----------------------------------------------------------------------------
1778 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
1782 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
1783 m_selecting(0), m_control(0), m_meta(0), m_shift(0), m_alt(0)
1787 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
1788 int row
=-1, int col
=-1, int x
=-1, int y
=-1, bool sel
= TRUE
,
1789 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1791 virtual int GetRow() { return m_row
; }
1792 virtual int GetCol() { return m_col
; }
1793 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1794 bool Selecting() { return m_selecting
; }
1795 bool ControlDown() { return m_control
; }
1796 bool MetaDown() { return m_meta
; }
1797 bool ShiftDown() { return m_shift
; }
1798 bool AltDown() { return m_alt
; }
1811 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
1814 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1818 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1819 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1823 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1824 int rowOrCol
=-1, int x
=-1, int y
=-1,
1825 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1827 int GetRowOrCol() { return m_rowOrCol
; }
1828 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1829 bool ControlDown() { return m_control
; }
1830 bool MetaDown() { return m_meta
; }
1831 bool ShiftDown() { return m_shift
; }
1832 bool AltDown() { return m_alt
; }
1843 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1847 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1850 wxGridRangeSelectEvent()
1853 m_topLeft
= wxGridNoCellCoords
;
1854 m_bottomRight
= wxGridNoCellCoords
;
1855 m_selecting
= FALSE
;
1862 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1863 const wxGridCellCoords
& topLeft
,
1864 const wxGridCellCoords
& bottomRight
,
1866 bool control
=FALSE
, bool shift
=FALSE
,
1867 bool alt
=FALSE
, bool meta
=FALSE
);
1869 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1870 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1871 int GetTopRow() { return m_topLeft
.GetRow(); }
1872 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1873 int GetLeftCol() { return m_topLeft
.GetCol(); }
1874 int GetRightCol() { return m_bottomRight
.GetCol(); }
1875 bool Selecting() { return m_selecting
; }
1876 bool ControlDown() { return m_control
; }
1877 bool MetaDown() { return m_meta
; }
1878 bool ShiftDown() { return m_shift
; }
1879 bool AltDown() { return m_alt
; }
1882 wxGridCellCoords m_topLeft
;
1883 wxGridCellCoords m_bottomRight
;
1890 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1893 BEGIN_DECLARE_EVENT_TYPES()
1894 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_CLICK
, 1580)
1895 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_CLICK
, 1581)
1896 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_DCLICK
, 1582)
1897 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_DCLICK
, 1583)
1898 DECLARE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_CLICK
, 1584)
1899 DECLARE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_CLICK
, 1585)
1900 DECLARE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_DCLICK
, 1586)
1901 DECLARE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_DCLICK
, 1587)
1902 DECLARE_EVENT_TYPE(wxEVT_GRID_ROW_SIZE
, 1588)
1903 DECLARE_EVENT_TYPE(wxEVT_GRID_COL_SIZE
, 1589)
1904 DECLARE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT
, 1590)
1905 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGE
, 1591)
1906 DECLARE_EVENT_TYPE(wxEVT_GRID_SELECT_CELL
, 1592)
1907 DECLARE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN
, 1593)
1908 DECLARE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN
, 1594)
1909 END_DECLARE_EVENT_TYPES()
1912 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1913 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1914 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1916 #define EVT_GRID_CELL_LEFT_CLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1917 #define EVT_GRID_CELL_RIGHT_CLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1918 #define EVT_GRID_CELL_LEFT_DCLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1919 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1920 #define EVT_GRID_LABEL_LEFT_CLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1921 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1922 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1923 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1924 #define EVT_GRID_ROW_SIZE(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL ),
1925 #define EVT_GRID_COL_SIZE(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL ),
1926 #define EVT_GRID_RANGE_SELECT(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL ),
1927 #define EVT_GRID_CELL_CHANGE(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1928 #define EVT_GRID_SELECT_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1929 #define EVT_GRID_EDITOR_SHOWN(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1930 #define EVT_GRID_EDITOR_HIDDEN(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1933 #if 0 // TODO: implement these ? others ?
1935 extern const int wxEVT_GRID_CREATE_CELL
;
1936 extern const int wxEVT_GRID_CHANGE_LABELS
;
1937 extern const int wxEVT_GRID_CHANGE_SEL_LABEL
;
1939 #define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1940 #define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1941 #define EVT_GRID_CHANGE_SEL_LABEL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
1945 #endif // #ifndef __WXGRID_H__
1947 #endif // ifndef wxUSE_NEW_GRID