1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/grid.h
3 // Purpose: wxGrid and related classes
4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
8 // Copyright: (c) Michael Bedward
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
14 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
22 #pragma interface "grid.h"
27 #include "wx/scrolwin.h"
28 #include "wx/string.h"
29 #include "wx/scrolbar.h"
31 #include "wx/combobox.h"
32 #include "wx/dynarray.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // Default parameters for wxGrid
41 #define WXGRID_DEFAULT_NUMBER_ROWS 10
42 #define WXGRID_DEFAULT_NUMBER_COLS 10
44 #define WXGRID_DEFAULT_ROW_HEIGHT 25
46 #define WXGRID_DEFAULT_ROW_HEIGHT 30
48 #define WXGRID_DEFAULT_COL_WIDTH 80
49 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
50 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
51 #define WXGRID_LABEL_EDGE_ZONE 5
52 #define WXGRID_MIN_ROW_HEIGHT 15
53 #define WXGRID_MIN_COL_WIDTH 15
54 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
56 // type names for grid table values
57 #define wxGRID_VALUE_STRING _T("string")
58 #define wxGRID_VALUE_BOOL _T("bool")
59 #define wxGRID_VALUE_NUMBER _T("long")
60 #define wxGRID_VALUE_FLOAT _T("double")
62 #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
63 #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
65 // ----------------------------------------------------------------------------
66 // forward declarations
67 // ----------------------------------------------------------------------------
69 class WXDLLEXPORT wxGrid
;
70 class WXDLLEXPORT wxGridCellAttr
;
71 class WXDLLEXPORT wxGridCellAttrProviderData
;
72 class WXDLLEXPORT wxGridColLabelWindow
;
73 class WXDLLEXPORT wxGridCornerLabelWindow
;
74 class WXDLLEXPORT wxGridRowLabelWindow
;
75 class WXDLLEXPORT wxGridTableBase
;
76 class WXDLLEXPORT wxGridWindow
;
77 class WXDLLEXPORT wxGridTypeRegistry
;
79 class WXDLLEXPORT wxCheckBox
;
80 class WXDLLEXPORT wxComboBox
;
81 class WXDLLEXPORT wxTextCtrl
;
82 class WXDLLEXPORT wxSpinCtrl
;
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 #define wxSafeIncRef(p) if ( p ) (p)->IncRef()
89 #define wxSafeDecRef(p) if ( p ) (p)->DecRef()
91 // ----------------------------------------------------------------------------
92 // wxGridCellRenderer: this class is responsible for actually drawing the cell
93 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
94 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
95 // view of all cells. This is an ABC, you will normally use one of the
96 // predefined derived classes or derive your own class from it.
97 // ----------------------------------------------------------------------------
99 class WXDLLEXPORT wxGridCellRenderer
102 wxGridCellRenderer() { m_nRef
= 1; }
104 // this class is ref counted: it is created with ref count of 1, so
105 // calling DecRef() once will delete it. Calling IncRef() allows to lock
106 // it until the matching DecRef() is called
107 void IncRef() { m_nRef
++; }
108 void DecRef() { if ( !--m_nRef
) delete this; }
110 // draw the given cell on the provided DC inside the given rectangle
111 // using the style specified by the attribute and the default or selected
112 // state corresponding to the isSelected value.
114 // this pure virtual function has a default implementation which will
115 // prepare the DC using the given attribute: it will draw the rectangle
116 // with the bg colour from attr and set the text colour and font
117 virtual void Draw(wxGrid
& grid
,
118 wxGridCellAttr
& attr
,
122 bool isSelected
) = 0;
124 // get the preferred size of the cell for its contents
125 virtual wxSize
GetBestSize(wxGrid
& grid
,
126 wxGridCellAttr
& attr
,
128 int row
, int col
) = 0;
130 // interpret renderer parameters: arbitrary string whose interpretatin is
131 // left to the derived classes
132 virtual void SetParameters(const wxString
& params
);
134 // create a new object which is the copy of this one
135 virtual wxGridCellRenderer
*Clone() const = 0;
138 // virtual dtor for any base class - private because only DecRef() can
140 virtual ~wxGridCellRenderer();
145 // suppress the stupid gcc warning about the class having private dtor and
147 friend class wxGridCellRendererDummyFriend
;
150 // the default renderer for the cells containing string data
151 class WXDLLEXPORT wxGridCellStringRenderer
: public wxGridCellRenderer
155 virtual void Draw(wxGrid
& grid
,
156 wxGridCellAttr
& attr
,
162 // return the string extent
163 virtual wxSize
GetBestSize(wxGrid
& grid
,
164 wxGridCellAttr
& attr
,
168 virtual wxGridCellRenderer
*Clone() const
169 { return new wxGridCellStringRenderer
; }
172 // set the text colours before drawing
173 void SetTextColoursAndFont(wxGrid
& grid
,
174 wxGridCellAttr
& attr
,
178 // calc the string extent for given string/font
179 wxSize
DoGetBestSize(wxGridCellAttr
& attr
,
181 const wxString
& text
);
184 // the default renderer for the cells containing numeric (long) data
185 class WXDLLEXPORT wxGridCellNumberRenderer
: public wxGridCellStringRenderer
188 // draw the string right aligned
189 virtual void Draw(wxGrid
& grid
,
190 wxGridCellAttr
& attr
,
196 virtual wxSize
GetBestSize(wxGrid
& grid
,
197 wxGridCellAttr
& attr
,
201 virtual wxGridCellRenderer
*Clone() const
202 { return new wxGridCellNumberRenderer
; }
205 wxString
GetString(wxGrid
& grid
, int row
, int col
);
208 class WXDLLEXPORT wxGridCellFloatRenderer
: public wxGridCellStringRenderer
211 wxGridCellFloatRenderer(int width
= -1, int precision
= -1);
213 // get/change formatting parameters
214 int GetWidth() const { return m_width
; }
215 void SetWidth(int width
) { m_width
= width
; m_format
.clear(); }
216 int GetPrecision() const { return m_precision
; }
217 void SetPrecision(int precision
) { m_precision
= precision
; m_format
.clear(); }
219 // draw the string right aligned with given width/precision
220 virtual void Draw(wxGrid
& grid
,
221 wxGridCellAttr
& attr
,
227 virtual wxSize
GetBestSize(wxGrid
& grid
,
228 wxGridCellAttr
& attr
,
232 // parameters string format is "width[,precision]"
233 virtual void SetParameters(const wxString
& params
);
235 virtual wxGridCellRenderer
*Clone() const;
238 wxString
GetString(wxGrid
& grid
, int row
, int col
);
241 // formatting parameters
248 // renderer for boolean fields
249 class WXDLLEXPORT wxGridCellBoolRenderer
: public wxGridCellRenderer
252 // draw a check mark or nothing
253 virtual void Draw(wxGrid
& grid
,
254 wxGridCellAttr
& attr
,
260 // return the checkmark size
261 virtual wxSize
GetBestSize(wxGrid
& grid
,
262 wxGridCellAttr
& attr
,
266 virtual wxGridCellRenderer
*Clone() const
267 { return new wxGridCellBoolRenderer
; }
270 static wxSize ms_sizeCheckMark
;
273 // ----------------------------------------------------------------------------
274 // wxGridCellEditor: This class is responsible for providing and manipulating
275 // the in-place edit controls for the grid. Instances of wxGridCellEditor
276 // (actually, instances of derived classes since it is an ABC) can be
277 // associated with the cell attributes for individual cells, rows, columns, or
278 // even for the entire grid.
279 // ----------------------------------------------------------------------------
281 class WXDLLEXPORT wxGridCellEditor
286 // this class is ref counted: it is created with ref count of 1, so
287 // calling DecRef() once will delete it. Calling IncRef() allows to lock
288 // it until the matching DecRef() is called
289 void IncRef() { m_nRef
++; }
290 void DecRef() { if ( !--m_nRef
) delete this; }
292 bool IsCreated() { return m_control
!= NULL
; }
294 // Creates the actual edit control
295 virtual void Create(wxWindow
* parent
,
297 wxEvtHandler
* evtHandler
) = 0;
299 // Size and position the edit control
300 virtual void SetSize(const wxRect
& rect
);
302 // Show or hide the edit control, use the specified attributes to set
303 // colours/fonts for it
304 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
306 // Draws the part of the cell not occupied by the control: the base class
307 // version just fills it with background colour from the attribute
308 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
310 // Fetch the value from the table and prepare the edit control
311 // to begin editing. Set the focus to the edit control.
312 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
314 // Complete the editing of the current cell. Returns true if the value has
315 // changed. If necessary, the control may be destroyed.
316 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
) = 0;
318 // Reset the value in the control back to its starting value
319 virtual void Reset() = 0;
321 // If the editor is enabled by pressing keys on the grid,
322 // this will be called to let the editor do something about
323 // that first key if desired.
324 virtual void StartingKey(wxKeyEvent
& event
);
326 // if the editor is enabled by clicking on the cell, this method will be
328 virtual void StartingClick();
330 // Some types of controls on some platforms may need some help
331 // with the Return key.
332 virtual void HandleReturn(wxKeyEvent
& event
);
335 virtual void Destroy();
338 // the dtor is private because only DecRef() can delete us
339 virtual ~wxGridCellEditor();
341 // the ref count - when it goes to 0, we die
344 // the control we show on screen
345 wxControl
* m_control
;
347 // if we change the colours/font of the control from the default ones, we
348 // must restore the default later and we save them here between calls to
349 // Show(TRUE) and Show(FALSE)
354 // suppress the stupid gcc warning about the class having private dtor and
356 friend class wxGridCellEditorDummyFriend
;
359 // the editor for string/text data
360 class WXDLLEXPORT wxGridCellTextEditor
: public wxGridCellEditor
363 wxGridCellTextEditor();
365 virtual void Create(wxWindow
* parent
,
367 wxEvtHandler
* evtHandler
);
368 virtual void SetSize(const wxRect
& rect
);
370 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
372 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
373 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
375 virtual void Reset();
376 virtual void StartingKey(wxKeyEvent
& event
);
377 virtual void HandleReturn(wxKeyEvent
& event
);
380 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
382 // parts of our virtual functions reused by the derived classes
383 void DoBeginEdit(const wxString
& startValue
);
384 void DoReset(const wxString
& startValue
);
387 wxString m_startValue
;
390 // the editor for numeric (long) data
391 class WXDLLEXPORT wxGridCellNumberEditor
: public wxGridCellTextEditor
394 // allows to specify the range - if min == max == -1, no range checking is
396 wxGridCellNumberEditor(int min
= -1, int max
= -1);
398 virtual void Create(wxWindow
* parent
,
400 wxEvtHandler
* evtHandler
);
402 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
403 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
405 virtual void Reset();
406 virtual void StartingKey(wxKeyEvent
& event
);
409 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
411 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
412 bool HasRange() const { return m_min
!= m_max
; }
414 // string representation of m_valueOld
415 wxString
GetString() const
416 { return wxString::Format(_T("%ld"), m_valueOld
); }
425 // the editor for floating point numbers (double) data
426 class WXDLLEXPORT wxGridCellFloatEditor
: public wxGridCellTextEditor
429 virtual void Create(wxWindow
* parent
,
431 wxEvtHandler
* evtHandler
);
433 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
434 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
436 virtual void Reset();
437 virtual void StartingKey(wxKeyEvent
& event
);
440 // string representation of m_valueOld
441 wxString
GetString() const
442 { return wxString::Format(_T("%f"), m_valueOld
); }
448 // the editor for boolean data
449 class WXDLLEXPORT wxGridCellBoolEditor
: public wxGridCellEditor
452 virtual void Create(wxWindow
* parent
,
454 wxEvtHandler
* evtHandler
);
456 virtual void SetSize(const wxRect
& rect
);
457 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
459 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
460 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
462 virtual void Reset();
463 virtual void StartingClick();
466 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
472 // the editor for string data allowing to choose from the list of strings
473 class WXDLLEXPORT wxGridCellChoiceEditor
: public wxGridCellEditor
476 // if !allowOthers, user can't type a string not in choices array
477 wxGridCellChoiceEditor(size_t count
, const wxChar
* choices
[],
478 bool allowOthers
= FALSE
);
480 virtual void Create(wxWindow
* parent
,
482 wxEvtHandler
* evtHandler
);
484 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
486 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
487 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
489 virtual void Reset();
492 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
495 wxString m_startValue
;
496 wxArrayString m_choices
;
500 // ----------------------------------------------------------------------------
501 // wxGridCellAttr: this class can be used to alter the cells appearance in
502 // the grid by changing their colour/font/... from default. An object of this
503 // class may be returned by wxGridTable::GetAttr().
504 // ----------------------------------------------------------------------------
506 class WXDLLEXPORT wxGridCellAttr
516 // VZ: considering the number of members wxGridCellAttr has now, this ctor
517 // seems to be pretty useless... may be we should just remove it?
518 wxGridCellAttr(const wxColour
& colText
,
519 const wxColour
& colBack
,
523 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
526 SetAlignment(hAlign
, vAlign
);
529 // creates a new copy of this object
530 wxGridCellAttr
*Clone() const;
532 // this class is ref counted: it is created with ref count of 1, so
533 // calling DecRef() once will delete it. Calling IncRef() allows to lock
534 // it until the matching DecRef() is called
535 void IncRef() { m_nRef
++; }
536 void DecRef() { if ( !--m_nRef
) delete this; }
539 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
540 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
541 void SetFont(const wxFont
& font
) { m_font
= font
; }
542 void SetAlignment(int hAlign
, int vAlign
)
547 void SetReadOnly(bool isReadOnly
= TRUE
) { m_isReadOnly
= isReadOnly
; }
549 // takes ownership of the pointer
550 void SetRenderer(wxGridCellRenderer
*renderer
)
551 { wxSafeDecRef(m_renderer
); m_renderer
= renderer
; }
552 void SetEditor(wxGridCellEditor
* editor
)
553 { wxSafeDecRef(m_editor
); m_editor
= editor
; }
556 bool HasTextColour() const { return m_colText
.Ok(); }
557 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
558 bool HasFont() const { return m_font
.Ok(); }
559 bool HasAlignment() const { return m_hAlign
|| m_vAlign
; }
560 bool HasRenderer() const { return m_renderer
!= NULL
; }
561 bool HasEditor() const { return m_editor
!= NULL
; }
563 const wxColour
& GetTextColour() const;
564 const wxColour
& GetBackgroundColour() const;
565 const wxFont
& GetFont() const;
566 void GetAlignment(int *hAlign
, int *vAlign
) const;
567 wxGridCellRenderer
*GetRenderer(wxGrid
* grid
, int row
, int col
) const;
568 wxGridCellEditor
*GetEditor(wxGrid
* grid
, int row
, int col
) const;
570 bool IsReadOnly() const { return m_isReadOnly
; }
572 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
575 // the common part of all ctors
580 m_isReadOnly
= FALSE
;
586 // the dtor is private because only DecRef() can delete us
589 wxSafeDecRef(m_renderer
);
590 wxSafeDecRef(m_editor
);
593 // the ref count - when it goes to 0, we die
602 wxGridCellRenderer
* m_renderer
;
603 wxGridCellEditor
* m_editor
;
604 wxGridCellAttr
* m_defGridAttr
;
608 // use Clone() instead
609 DECLARE_NO_COPY_CLASS(wxGridCellAttr
);
611 // suppress the stupid gcc warning about the class having private dtor and
613 friend class wxGridCellAttrDummyFriend
;
616 // ----------------------------------------------------------------------------
617 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
619 // ----------------------------------------------------------------------------
621 // implementation note: we separate it from wxGridTableBase because we wish to
622 // avoid deriving a new table class if possible, and sometimes it will be
623 // enough to just derive another wxGridCellAttrProvider instead
625 // the default implementation is reasonably efficient for the generic case,
626 // but you might still wish to implement your own for some specific situations
627 // if you have performance problems with the stock one
628 class WXDLLEXPORT wxGridCellAttrProvider
631 wxGridCellAttrProvider();
632 virtual ~wxGridCellAttrProvider();
634 // DecRef() must be called on the returned pointer
635 virtual wxGridCellAttr
*GetAttr(int row
, int col
) const;
637 // all these functions take ownership of the pointer, don't call DecRef()
639 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
640 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
641 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
643 // these functions must be called whenever some rows/cols are deleted
644 // because the internal data must be updated then
645 void UpdateAttrRows( size_t pos
, int numRows
);
646 void UpdateAttrCols( size_t pos
, int numCols
);
651 wxGridCellAttrProviderData
*m_data
;
654 //////////////////////////////////////////////////////////////////////
656 // Grid table classes
658 //////////////////////////////////////////////////////////////////////
661 class WXDLLEXPORT wxGridTableBase
: public wxObject
665 virtual ~wxGridTableBase();
667 // You must override these functions in a derived table class
669 virtual long GetNumberRows() = 0;
670 virtual long GetNumberCols() = 0;
671 virtual bool IsEmptyCell( int row
, int col
) = 0;
672 virtual wxString
GetValue( int row
, int col
) = 0;
673 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
675 // Data type determination and value access
676 virtual wxString
GetTypeName( int row
, int col
);
677 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
678 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
680 virtual long GetValueAsLong( int row
, int col
);
681 virtual double GetValueAsDouble( int row
, int col
);
682 virtual bool GetValueAsBool( int row
, int col
);
684 virtual void SetValueAsLong( int row
, int col
, long value
);
685 virtual void SetValueAsDouble( int row
, int col
, double value
);
686 virtual void SetValueAsBool( int row
, int col
, bool value
);
688 // For user defined types
689 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
690 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
693 // Overriding these is optional
695 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
696 virtual wxGrid
* GetView() const { return m_view
; }
698 virtual void Clear() {}
699 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
700 virtual bool AppendRows( size_t numRows
= 1 );
701 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
702 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
703 virtual bool AppendCols( size_t numCols
= 1 );
704 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
706 virtual wxString
GetRowLabelValue( int row
);
707 virtual wxString
GetColLabelValue( int col
);
708 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
709 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
711 // Attribute handling
714 // give us the attr provider to use - we take ownership of the pointer
715 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
717 // get the currently used attr provider (may be NULL)
718 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
720 // Does this table allow attributes? Default implementation creates
721 // a wxGridCellAttrProvider if necessary.
722 virtual bool CanHaveAttributes();
725 // change row/col number in attribute if needed
726 virtual void UpdateAttrRows( size_t pos
, int numRows
);
727 virtual void UpdateAttrCols( size_t pos
, int numCols
);
729 // by default forwarded to wxGridCellAttrProvider if any. May be
730 // overridden to handle attributes directly in the table.
731 virtual wxGridCellAttr
*GetAttr( int row
, int col
);
733 // these functions take ownership of the pointer
734 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
735 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
736 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
740 wxGridCellAttrProvider
*m_attrProvider
;
742 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
746 // ----------------------------------------------------------------------------
747 // wxGridTableMessage
748 // ----------------------------------------------------------------------------
750 // IDs for messages sent from grid table to view
752 enum wxGridTableRequest
754 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
755 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
756 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
757 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
758 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
759 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
760 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
761 wxGRIDTABLE_NOTIFY_COLS_DELETED
764 class WXDLLEXPORT wxGridTableMessage
767 wxGridTableMessage();
768 wxGridTableMessage( wxGridTableBase
*table
, int id
,
772 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
773 wxGridTableBase
* GetTableObject() const { return m_table
; }
774 void SetId( int id
) { m_id
= id
; }
775 int GetId() { return m_id
; }
776 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
777 int GetCommandInt() { return m_comInt1
; }
778 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
779 int GetCommandInt2() { return m_comInt2
; }
782 wxGridTableBase
*m_table
;
790 // ------ wxGridStringArray
791 // A 2-dimensional array of strings for data values
794 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
798 // ------ wxGridStringTable
800 // Simplest type of data table for a grid for small tables of strings
801 // that are stored in memory
804 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
808 wxGridStringTable( int numRows
, int numCols
);
809 ~wxGridStringTable();
811 // these are pure virtual in wxGridTableBase
813 long GetNumberRows();
814 long GetNumberCols();
815 wxString
GetValue( int row
, int col
);
816 void SetValue( int row
, int col
, const wxString
& s
);
817 bool IsEmptyCell( int row
, int col
);
819 // overridden functions from wxGridTableBase
822 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
823 bool AppendRows( size_t numRows
= 1 );
824 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
825 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
826 bool AppendCols( size_t numCols
= 1 );
827 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
829 void SetRowLabelValue( int row
, const wxString
& );
830 void SetColLabelValue( int col
, const wxString
& );
831 wxString
GetRowLabelValue( int row
);
832 wxString
GetColLabelValue( int col
);
835 wxGridStringArray m_data
;
837 // These only get used if you set your own labels, otherwise the
838 // GetRow/ColLabelValue functions return wxGridTableBase defaults
840 wxArrayString m_rowLabels
;
841 wxArrayString m_colLabels
;
843 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
848 // ============================================================================
850 // ============================================================================
852 // ----------------------------------------------------------------------------
853 // wxGridCellCoords: location of a cell in the grid
854 // ----------------------------------------------------------------------------
856 class WXDLLEXPORT wxGridCellCoords
859 wxGridCellCoords() { m_row
= m_col
= -1; }
860 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
862 // default copy ctor is ok
864 long GetRow() const { return m_row
; }
865 void SetRow( long n
) { m_row
= n
; }
866 long GetCol() const { return m_col
; }
867 void SetCol( long n
) { m_col
= n
; }
868 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
870 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
872 if ( &other
!= this )
880 bool operator==( const wxGridCellCoords
& other
) const
882 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
885 bool operator!=( const wxGridCellCoords
& other
) const
887 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
890 bool operator!() const
892 return (m_row
== -1 && m_col
== -1 );
901 // For comparisons...
903 extern wxGridCellCoords wxGridNoCellCoords
;
904 extern wxRect wxGridNoCellRect
;
906 // An array of cell coords...
908 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
910 // ----------------------------------------------------------------------------
912 // ----------------------------------------------------------------------------
914 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
922 wxGrid( wxWindow
*parent
,
924 const wxPoint
& pos
= wxDefaultPosition
,
925 const wxSize
& size
= wxDefaultSize
,
926 long style
= wxWANTS_CHARS
,
927 const wxString
& name
= wxPanelNameStr
);
931 bool CreateGrid( int numRows
, int numCols
);
934 // ------ grid dimensions
936 int GetNumberRows() { return m_numRows
; }
937 int GetNumberCols() { return m_numCols
; }
940 // ------ display update functions
942 void CalcRowLabelsExposed( wxRegion
& reg
);
944 void CalcColLabelsExposed( wxRegion
& reg
);
945 void CalcCellsExposed( wxRegion
& reg
);
948 // ------ event handlers
950 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
951 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
952 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
953 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
954 bool ProcessTableMessage( wxGridTableMessage
& );
956 void DoEndDragResizeRow();
957 void DoEndDragResizeCol();
959 wxGridTableBase
* GetTable() const { return m_table
; }
960 bool SetTable( wxGridTableBase
*table
, bool takeOwnership
=FALSE
);
963 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
964 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
965 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
966 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
967 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
968 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
970 void DrawGridCellArea( wxDC
& dc
);
971 void DrawGridSpace( wxDC
& dc
);
972 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
973 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
974 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
975 void DrawHighlight(wxDC
& dc
);
977 // this function is called when the current cell highlight must be redrawn
978 // and may be overridden by the user
979 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
981 void DrawRowLabels( wxDC
& dc
);
982 void DrawRowLabel( wxDC
& dc
, int row
);
984 void DrawColLabels( wxDC
& dc
);
985 void DrawColLabel( wxDC
& dc
, int col
);
988 // ------ Cell text drawing functions
990 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
991 int horizontalAlignment
= wxLEFT
,
992 int verticalAlignment
= wxTOP
);
994 // Split a string containing newline chararcters into an array of
995 // strings and return the number of lines
997 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
999 void GetTextBoxSize( wxDC
& dc
,
1000 wxArrayString
& lines
,
1001 long *width
, long *height
);
1005 // Code that does a lot of grid modification can be enclosed
1006 // between BeginBatch() and EndBatch() calls to avoid screen
1009 void BeginBatch() { m_batchCount
++; }
1010 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
1011 int GetBatchCount() { return m_batchCount
; }
1014 // ------ edit control functions
1016 bool IsEditable() { return m_editable
; }
1017 void EnableEditing( bool edit
);
1019 void EnableCellEditControl( bool enable
= TRUE
);
1020 void DisableCellEditControl() { EnableCellEditControl(FALSE
); }
1021 bool CanEnableCellControl() const;
1022 bool IsCellEditControlEnabled() const;
1024 bool IsCurrentCellReadOnly() const;
1026 void ShowCellEditControl();
1027 void HideCellEditControl();
1028 void SaveEditControlValue();
1031 // ------ grid location functions
1032 // Note that all of these functions work with the logical coordinates of
1033 // grid cells and labels so you will need to convert from device
1034 // coordinates for mouse events etc.
1036 void XYToCell( int x
, int y
, wxGridCellCoords
& );
1037 int YToRow( int y
);
1038 int XToCol( int x
);
1040 int YToEdgeOfRow( int y
);
1041 int XToEdgeOfCol( int x
);
1043 wxRect
CellToRect( int row
, int col
);
1044 wxRect
CellToRect( const wxGridCellCoords
& coords
)
1045 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
1047 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
1048 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
1050 // check to see if a cell is either wholly visible (the default arg) or
1051 // at least partially visible in the grid window
1053 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
1054 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
1055 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
1056 void MakeCellVisible( int row
, int col
);
1057 void MakeCellVisible( const wxGridCellCoords
& coords
)
1058 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
1061 // ------ grid cursor movement functions
1063 void SetGridCursor( int row
, int col
)
1064 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1066 bool MoveCursorUp();
1067 bool MoveCursorDown();
1068 bool MoveCursorLeft();
1069 bool MoveCursorRight();
1070 bool MovePageDown();
1072 bool MoveCursorUpBlock();
1073 bool MoveCursorDownBlock();
1074 bool MoveCursorLeftBlock();
1075 bool MoveCursorRightBlock();
1078 // ------ label and gridline formatting
1080 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
1081 int GetRowLabelSize() { return m_rowLabelWidth
; }
1082 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
1083 int GetColLabelSize() { return m_colLabelHeight
; }
1084 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
1085 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
1086 wxFont
GetLabelFont() { return m_labelFont
; }
1087 void GetRowLabelAlignment( int *horiz
, int *vert
);
1088 void GetColLabelAlignment( int *horiz
, int *vert
);
1089 wxString
GetRowLabelValue( int row
);
1090 wxString
GetColLabelValue( int col
);
1091 wxColour
GetGridLineColour() { return m_gridLineColour
; }
1093 void SetRowLabelSize( int width
);
1094 void SetColLabelSize( int height
);
1095 void SetLabelBackgroundColour( const wxColour
& );
1096 void SetLabelTextColour( const wxColour
& );
1097 void SetLabelFont( const wxFont
& );
1098 void SetRowLabelAlignment( int horiz
, int vert
);
1099 void SetColLabelAlignment( int horiz
, int vert
);
1100 void SetRowLabelValue( int row
, const wxString
& );
1101 void SetColLabelValue( int col
, const wxString
& );
1102 void SetGridLineColour( const wxColour
& );
1104 void EnableDragRowSize( bool enable
= TRUE
);
1105 void DisableDragRowSize() { EnableDragRowSize( FALSE
); }
1106 bool CanDragRowSize() { return m_canDragRowSize
; }
1107 void EnableDragColSize( bool enable
= TRUE
);
1108 void DisableDragColSize() { EnableDragColSize( FALSE
); }
1109 bool CanDragColSize() { return m_canDragColSize
; }
1110 void EnableDragGridSize(bool enable
= TRUE
);
1111 void DisableDragGridSize() { EnableDragGridSize(FALSE
); }
1112 bool CanDragGridSize() { return m_canDragGridSize
; }
1114 // this sets the specified attribute for all cells in this row/col
1115 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
1116 void SetColAttr(int col
, wxGridCellAttr
*attr
);
1118 // shortcuts for setting the column parameters
1120 // set the format for the data in the column: default is string
1121 void SetColFormatBool(int col
);
1122 void SetColFormatNumber(int col
);
1123 void SetColFormatFloat(int col
, int width
= -1, int precision
= -1);
1124 void SetColFormatCustom(int col
, const wxString
& typeName
);
1126 void EnableGridLines( bool enable
= TRUE
);
1127 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
1129 // ------ row and col formatting
1131 int GetDefaultRowSize();
1132 int GetRowSize( int row
);
1133 int GetDefaultColSize();
1134 int GetColSize( int col
);
1135 wxColour
GetDefaultCellBackgroundColour();
1136 wxColour
GetCellBackgroundColour( int row
, int col
);
1137 wxColour
GetDefaultCellTextColour();
1138 wxColour
GetCellTextColour( int row
, int col
);
1139 wxFont
GetDefaultCellFont();
1140 wxFont
GetCellFont( int row
, int col
);
1141 void GetDefaultCellAlignment( int *horiz
, int *vert
);
1142 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
1144 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
1145 void SetRowSize( int row
, int height
);
1146 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
1148 void SetColSize( int col
, int width
);
1150 // automatically size the column or row to fit to its contents, if
1151 // setAsMin is TRUE, this optimal width will also be set as minimal width
1153 void AutoSizeColumn( int col
, bool setAsMin
= TRUE
)
1154 { AutoSizeColOrRow(col
, setAsMin
, TRUE
); }
1155 void AutoSizeRow( int row
, bool setAsMin
= TRUE
)
1156 { AutoSizeColOrRow(row
, setAsMin
, FALSE
); }
1158 // auto size all columns (very ineffective for big grids!)
1159 void AutoSizeColumns( bool setAsMin
= TRUE
)
1160 { (void)SetOrCalcColumnSizes(FALSE
, setAsMin
); }
1162 void AutoSizeRows( bool setAsMin
= TRUE
)
1163 { (void)SetOrCalcRowSizes(FALSE
, setAsMin
); }
1165 // auto size the grid, that is make the columns/rows of the "right" size
1166 // and also set the grid size to just fit its contents
1169 // column won't be resized to be lesser width - this must be called during
1170 // the grid creation because it won't resize the column if it's already
1171 // narrower than the minimal width
1172 void SetColMinimalWidth( int col
, int width
);
1173 void SetRowMinimalHeight( int row
, int width
);
1175 void SetDefaultCellBackgroundColour( const wxColour
& );
1176 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1177 void SetDefaultCellTextColour( const wxColour
& );
1179 void SetCellTextColour( int row
, int col
, const wxColour
& );
1180 void SetDefaultCellFont( const wxFont
& );
1181 void SetCellFont( int row
, int col
, const wxFont
& );
1182 void SetDefaultCellAlignment( int horiz
, int vert
);
1183 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1185 // takes ownership of the pointer
1186 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1187 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1188 wxGridCellRenderer
*GetDefaultRenderer() const;
1189 wxGridCellRenderer
* GetCellRenderer(int row
, int col
);
1191 // takes ownership of the pointer
1192 void SetDefaultEditor(wxGridCellEditor
*editor
);
1193 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1194 wxGridCellEditor
*GetDefaultEditor() const;
1195 wxGridCellEditor
* GetCellEditor(int row
, int col
);
1199 // ------ cell value accessors
1201 wxString
GetCellValue( int row
, int col
)
1205 return m_table
->GetValue( row
, col
);
1209 return wxEmptyString
;
1213 wxString
GetCellValue( const wxGridCellCoords
& coords
)
1214 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1216 void SetCellValue( int row
, int col
, const wxString
& s
);
1217 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1218 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1220 // returns TRUE if the cell can't be edited
1221 bool IsReadOnly(int row
, int col
) const;
1223 // make the cell editable/readonly
1224 void SetReadOnly(int row
, int col
, bool isReadOnly
= TRUE
);
1226 // ------ selections of blocks of cells
1228 void SelectRow( int row
, bool addToSelected
= FALSE
);
1229 void SelectCol( int col
, bool addToSelected
= FALSE
);
1231 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
1233 void SelectBlock( const wxGridCellCoords
& topLeft
,
1234 const wxGridCellCoords
& bottomRight
)
1235 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1236 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
1241 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
1242 m_selectedBottomRight
!= wxGridNoCellCoords
);
1245 void ClearSelection();
1247 bool IsInSelection( int row
, int col
)
1248 { return ( IsSelection() &&
1249 row
>= m_selectedTopLeft
.GetRow() &&
1250 col
>= m_selectedTopLeft
.GetCol() &&
1251 row
<= m_selectedBottomRight
.GetRow() &&
1252 col
<= m_selectedBottomRight
.GetCol() );
1255 bool IsInSelection( const wxGridCellCoords
& coords
)
1256 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1258 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
1260 // these will all be -1 if there is no selected block
1262 *topRow
= m_selectedTopLeft
.GetRow();
1263 *leftCol
= m_selectedTopLeft
.GetCol();
1264 *bottomRow
= m_selectedBottomRight
.GetRow();
1265 *rightCol
= m_selectedBottomRight
.GetCol();
1269 // This function returns the rectangle that encloses the block of cells
1270 // limited by TopLeft and BottomRight cell in device coords and clipped
1271 // to the client size of the grid window.
1273 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1274 const wxGridCellCoords
& bottomRight
);
1276 // This function returns the rectangle that encloses the selected cells
1277 // in device coords and clipped to the client size of the grid window.
1279 wxRect
SelectionToDeviceRect()
1281 return BlockToDeviceRect( m_selectedTopLeft
,
1282 m_selectedBottomRight
);
1285 // Access or update the selection fore/back colours
1286 wxColour
GetSelectionBackground() const
1287 { return m_selectionBackground
; }
1288 wxColour
GetSelectionForeground() const
1289 { return m_selectionForeground
; }
1291 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1292 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1295 // Methods for a registry for mapping data types to Renderers/Editors
1296 void RegisterDataType(const wxString
& typeName
,
1297 wxGridCellRenderer
* renderer
,
1298 wxGridCellEditor
* editor
);
1299 wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1300 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1301 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1302 wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1303 wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1304 wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1306 // grid may occupy more space than needed for its rows/columns, this
1307 // function allows to set how big this extra space is
1308 void SetMargins(int extraWidth
, int extraHeight
)
1310 m_extraWidth
= extraWidth
;
1311 m_extraHeight
= extraHeight
;
1314 // ------ For compatibility with previous wxGrid only...
1316 // ************************************************
1317 // ** Don't use these in new code because they **
1318 // ** are liable to disappear in a future **
1320 // ************************************************
1323 wxGrid( wxWindow
*parent
,
1324 int x
, int y
, int w
= -1, int h
= -1,
1325 long style
= wxWANTS_CHARS
,
1326 const wxString
& name
= wxPanelNameStr
)
1327 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
),
1328 (style
|wxWANTS_CHARS
), name
)
1333 void SetCellValue( const wxString
& val
, int row
, int col
)
1334 { SetCellValue( row
, col
, val
); }
1336 void UpdateDimensions()
1337 { CalcDimensions(); }
1339 int GetRows() { return GetNumberRows(); }
1340 int GetCols() { return GetNumberCols(); }
1341 int GetCursorRow() { return GetGridCursorRow(); }
1342 int GetCursorColumn() { return GetGridCursorCol(); }
1344 int GetScrollPosX() { return 0; }
1345 int GetScrollPosY() { return 0; }
1347 void SetScrollX( int x
) { }
1348 void SetScrollY( int y
) { }
1350 void SetColumnWidth( int col
, int width
)
1351 { SetColSize( col
, width
); }
1353 int GetColumnWidth( int col
)
1354 { return GetColSize( col
); }
1356 void SetRowHeight( int row
, int height
)
1357 { SetRowSize( row
, height
); }
1359 // GetRowHeight() is below
1361 int GetViewHeight() // returned num whole rows visible
1364 int GetViewWidth() // returned num whole cols visible
1367 void SetLabelSize( int orientation
, int sz
)
1369 if ( orientation
== wxHORIZONTAL
)
1370 SetColLabelSize( sz
);
1372 SetRowLabelSize( sz
);
1375 int GetLabelSize( int orientation
)
1377 if ( orientation
== wxHORIZONTAL
)
1378 return GetColLabelSize();
1380 return GetRowLabelSize();
1383 void SetLabelAlignment( int orientation
, int align
)
1385 if ( orientation
== wxHORIZONTAL
)
1386 SetColLabelAlignment( align
, -1 );
1388 SetRowLabelAlignment( align
, -1 );
1391 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
1394 if ( orientation
== wxHORIZONTAL
)
1396 GetColLabelAlignment( &h
, &v
);
1401 GetRowLabelAlignment( &h
, &v
);
1406 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1408 if ( orientation
== wxHORIZONTAL
)
1409 SetColLabelValue( pos
, val
);
1411 SetRowLabelValue( pos
, val
);
1414 wxString
GetLabelValue( int orientation
, int pos
)
1416 if ( orientation
== wxHORIZONTAL
)
1417 return GetColLabelValue( pos
);
1419 return GetRowLabelValue( pos
);
1422 wxFont
GetCellTextFont() const
1423 { return m_defaultCellAttr
->GetFont(); }
1425 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1426 { return m_defaultCellAttr
->GetFont(); }
1428 void SetCellTextFont(const wxFont
& fnt
)
1429 { SetDefaultCellFont( fnt
); }
1431 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1432 { SetCellFont( row
, col
, fnt
); }
1434 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1435 { SetCellTextColour( row
, col
, val
); }
1437 void SetCellTextColour(const wxColour
& col
)
1438 { SetDefaultCellTextColour( col
); }
1440 void SetCellBackgroundColour(const wxColour
& col
)
1441 { SetDefaultCellBackgroundColour( col
); }
1443 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1444 { SetCellBackgroundColour( row
, col
, colour
); }
1446 bool GetEditable() { return IsEditable(); }
1447 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
1448 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
1450 void SetEditInPlace(bool edit
= TRUE
) { }
1452 void SetCellAlignment( int align
, int row
, int col
)
1453 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
1454 void SetCellAlignment( int WXUNUSED(align
) ) {}
1455 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1457 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1458 wxPen
& GetDividerPen() const { return wxNullPen
; }
1459 void OnActivate(bool WXUNUSED(active
)) {}
1461 // ******** End of compatibility functions **********
1465 // ------ control IDs
1466 enum { wxGRID_CELLCTRL
= 2000,
1469 // ------ control types
1470 enum { wxGRID_TEXTCTRL
= 2100,
1475 // overridden wxWindow methods
1479 virtual wxSize
DoGetBestSize() const;
1484 wxGridWindow
*m_gridWin
;
1485 wxGridRowLabelWindow
*m_rowLabelWin
;
1486 wxGridColLabelWindow
*m_colLabelWin
;
1487 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1489 wxGridTableBase
*m_table
;
1500 wxGridCellCoords m_currentCellCoords
;
1502 wxGridCellCoords m_selectedTopLeft
;
1503 wxGridCellCoords m_selectedBottomRight
;
1504 wxColour m_selectionBackground
;
1505 wxColour m_selectionForeground
;
1507 // NB: *never* access m_row/col arrays directly because they are created
1508 // on demand, *always* use accessor functions instead!
1510 // init the m_rowHeights/Bottoms arrays with default values
1511 void InitRowHeights();
1513 int m_defaultRowHeight
;
1514 wxArrayInt m_rowHeights
;
1515 wxArrayInt m_rowBottoms
;
1517 // init the m_colWidths/Rights arrays
1518 void InitColWidths();
1520 int m_defaultColWidth
;
1521 wxArrayInt m_colWidths
;
1522 wxArrayInt m_colRights
;
1524 // get the col/row coords
1525 int GetColWidth(int col
) const;
1526 int GetColLeft(int col
) const;
1527 int GetColRight(int col
) const;
1529 // this function must be public for compatibility...
1531 int GetRowHeight(int row
) const;
1534 int GetRowTop(int row
) const;
1535 int GetRowBottom(int row
) const;
1537 int m_rowLabelWidth
;
1538 int m_colLabelHeight
;
1540 // the size of the margin left to the right and bottom of the cell area
1544 wxColour m_labelBackgroundColour
;
1545 wxColour m_labelTextColour
;
1548 int m_rowLabelHorizAlign
;
1549 int m_rowLabelVertAlign
;
1550 int m_colLabelHorizAlign
;
1551 int m_colLabelVertAlign
;
1553 bool m_defaultRowLabelValues
;
1554 bool m_defaultColLabelValues
;
1556 wxColour m_gridLineColour
;
1557 bool m_gridLinesEnabled
;
1559 // common part of AutoSizeColumn/Row() and GetBestSize()
1560 int SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
= TRUE
);
1561 int SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
= TRUE
);
1563 // common part of AutoSizeColumn/Row()
1564 void AutoSizeColOrRow(int n
, bool setAsMin
, bool column
/* or row? */);
1566 // if a column has a minimal width, it will be the value for it in this
1568 wxHashTableLong m_colMinWidths
,
1571 // get the minimal width of the given column/row
1572 int GetColMinimalWidth(int col
) const;
1573 int GetRowMinimalHeight(int col
) const;
1575 // do we have some place to store attributes in?
1576 bool CanHaveAttributes();
1578 // returns the attribute we may modify in place: a new one if this cell
1579 // doesn't have any yet or the existing one if it does
1581 // DecRef() must be called on the returned pointer, as usual
1582 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1584 // cell attribute cache (currently we only cache 1, may be will do
1585 // more/better later)
1589 wxGridCellAttr
*attr
;
1592 // invalidates the attribute cache
1593 void ClearAttrCache();
1595 // adds an attribute to cache
1596 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
1598 // looks for an attr in cache, returns TRUE if found
1599 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
1601 // looks for the attr in cache, if not found asks the table and caches the
1603 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
1604 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
)
1605 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
1607 // the default cell attr object for cells that don't have their own
1608 wxGridCellAttr
* m_defaultCellAttr
;
1611 wxGridCellCoordsArray m_cellsExposed
;
1612 wxArrayInt m_rowsExposed
;
1613 wxArrayInt m_colsExposed
;
1614 wxArrayInt m_rowLabelsExposed
;
1615 wxArrayInt m_colLabelsExposed
;
1621 wxGridTypeRegistry
* m_typeRegistry
;
1625 WXGRID_CURSOR_SELECT_CELL
,
1626 WXGRID_CURSOR_RESIZE_ROW
,
1627 WXGRID_CURSOR_RESIZE_COL
,
1628 WXGRID_CURSOR_SELECT_ROW
,
1629 WXGRID_CURSOR_SELECT_COL
1632 // this method not only sets m_cursorMode but also sets the correct cursor
1633 // for the given mode and, if captureMouse is not FALSE releases the mouse
1634 // if it was captured and captures it if it must be captured
1636 // for this to work, you should always use it and not set m_cursorMode
1638 void ChangeCursorMode(CursorMode mode
,
1639 wxWindow
*win
= (wxWindow
*)NULL
,
1640 bool captureMouse
= TRUE
);
1642 wxWindow
*m_winCapture
; // the window which captured the mouse
1643 CursorMode m_cursorMode
;
1645 bool m_canDragRowSize
;
1646 bool m_canDragColSize
;
1647 bool m_canDragGridSize
;
1651 wxPoint m_startDragPos
;
1653 bool m_waitForSlowClick
;
1655 wxGridCellCoords m_selectionStart
;
1657 wxCursor m_rowResizeCursor
;
1658 wxCursor m_colResizeCursor
;
1660 bool m_editable
; // applies to whole grid
1661 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
1666 void CalcDimensions();
1667 void CalcWindowSizes();
1668 bool Redimension( wxGridTableMessage
& );
1671 bool SendEvent( const wxEventType
, int row
, int col
, wxMouseEvent
& );
1672 bool SendEvent( const wxEventType
, int row
, int col
);
1673 bool SendEvent( const wxEventType type
)
1675 return SendEvent(type
,
1676 m_currentCellCoords
.GetRow(),
1677 m_currentCellCoords
.GetCol());
1680 void OnPaint( wxPaintEvent
& );
1681 void OnSize( wxSizeEvent
& );
1682 void OnKeyDown( wxKeyEvent
& );
1683 void OnEraseBackground( wxEraseEvent
& );
1686 void SetCurrentCell( const wxGridCellCoords
& coords
);
1687 void SetCurrentCell( int row
, int col
)
1688 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1691 // ------ functions to get/send data (see also public functions)
1693 bool GetModelValues();
1694 bool SetModelValues();
1697 DECLARE_DYNAMIC_CLASS( wxGrid
)
1698 DECLARE_EVENT_TABLE()
1701 // ----------------------------------------------------------------------------
1702 // Grid event class and event types
1703 // ----------------------------------------------------------------------------
1705 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
1709 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
1710 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1714 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
1715 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
1716 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1718 virtual int GetRow() { return m_row
; }
1719 virtual int GetCol() { return m_col
; }
1720 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1721 bool ControlDown() { return m_control
; }
1722 bool MetaDown() { return m_meta
; }
1723 bool ShiftDown() { return m_shift
; }
1724 bool AltDown() { return m_alt
; }
1736 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
1739 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1743 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1744 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1748 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1749 int rowOrCol
=-1, int x
=-1, int y
=-1,
1750 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1752 int GetRowOrCol() { return m_rowOrCol
; }
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
; }
1768 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1772 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1775 wxGridRangeSelectEvent()
1778 m_topLeft
= wxGridNoCellCoords
;
1779 m_bottomRight
= wxGridNoCellCoords
;
1786 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1787 const wxGridCellCoords
& topLeft
,
1788 const wxGridCellCoords
& bottomRight
,
1789 bool control
=FALSE
, bool shift
=FALSE
,
1790 bool alt
=FALSE
, bool meta
=FALSE
);
1792 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1793 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1794 int GetTopRow() { return m_topLeft
.GetRow(); }
1795 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1796 int GetLeftCol() { return m_topLeft
.GetCol(); }
1797 int GetRightCol() { return m_bottomRight
.GetCol(); }
1798 bool ControlDown() { return m_control
; }
1799 bool MetaDown() { return m_meta
; }
1800 bool ShiftDown() { return m_shift
; }
1801 bool AltDown() { return m_alt
; }
1804 wxGridCellCoords m_topLeft
;
1805 wxGridCellCoords m_bottomRight
;
1811 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1814 // TODO move to wx/event.h
1815 const wxEventType wxEVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1816 const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1817 const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1818 const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1819 const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1820 const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1821 const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1822 const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1823 const wxEventType wxEVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1824 const wxEventType wxEVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1825 const wxEventType wxEVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1826 const wxEventType wxEVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1827 const wxEventType wxEVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1828 const wxEventType wxEVT_GRID_EDITOR_SHOWN
= wxEVT_FIRST
+ 1593;
1829 const wxEventType wxEVT_GRID_EDITOR_HIDDEN
= wxEVT_FIRST
+ 1594;
1832 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1833 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1834 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1836 #define EVT_GRID_CELL_LEFT_CLICK(fn) { wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1837 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1838 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1839 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1840 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1841 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1842 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1843 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1844 #define EVT_GRID_ROW_SIZE(fn) { wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1845 #define EVT_GRID_COL_SIZE(fn) { wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1846 #define EVT_GRID_RANGE_SELECT(fn) { wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1847 #define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1848 #define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1849 #define EVT_GRID_EDITOR_SHOWN(fn) { wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1850 #define EVT_GRID_EDITOR_HIDDEN(fn) { wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1853 #if 0 // TODO: implement these ? others ?
1855 const wxEventType wxEVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1856 const wxEventType wxEVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1857 const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1859 #define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1860 #define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1861 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1865 #endif // #ifndef __WXGRID_H__
1867 #endif // ifndef wxUSE_NEW_GRID