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
);
135 // virtual dtor for any base class - private because only DecRef() can
137 virtual ~wxGridCellRenderer();
142 // suppress the stupid gcc warning about the class having private dtor and
144 friend class wxGridCellRendererDummyFriend
;
147 // the default renderer for the cells containing string data
148 class WXDLLEXPORT wxGridCellStringRenderer
: public wxGridCellRenderer
152 virtual void Draw(wxGrid
& grid
,
153 wxGridCellAttr
& attr
,
159 // return the string extent
160 virtual wxSize
GetBestSize(wxGrid
& grid
,
161 wxGridCellAttr
& attr
,
166 // set the text colours before drawing
167 void SetTextColoursAndFont(wxGrid
& grid
,
168 wxGridCellAttr
& attr
,
172 // calc the string extent for given string/font
173 wxSize
DoGetBestSize(wxGridCellAttr
& attr
,
175 const wxString
& text
);
178 // the default renderer for the cells containing numeric (long) data
179 class WXDLLEXPORT wxGridCellNumberRenderer
: public wxGridCellStringRenderer
182 // draw the string right aligned
183 virtual void Draw(wxGrid
& grid
,
184 wxGridCellAttr
& attr
,
190 virtual wxSize
GetBestSize(wxGrid
& grid
,
191 wxGridCellAttr
& attr
,
196 wxString
GetString(wxGrid
& grid
, int row
, int col
);
199 class WXDLLEXPORT wxGridCellFloatRenderer
: public wxGridCellStringRenderer
202 wxGridCellFloatRenderer(int width
= -1, int precision
= -1);
204 // get/change formatting parameters
205 int GetWidth() const { return m_width
; }
206 void SetWidth(int width
) { m_width
= width
; m_format
.clear(); }
207 int GetPrecision() const { return m_precision
; }
208 void SetPrecision(int precision
) { m_precision
= precision
; m_format
.clear(); }
210 // draw the string right aligned with given width/precision
211 virtual void Draw(wxGrid
& grid
,
212 wxGridCellAttr
& attr
,
218 virtual wxSize
GetBestSize(wxGrid
& grid
,
219 wxGridCellAttr
& attr
,
223 // parameters string format is "width[,precision]"
224 virtual void SetParameters(const wxString
& params
);
227 wxString
GetString(wxGrid
& grid
, int row
, int col
);
230 // formatting parameters
237 // renderer for boolean fields
238 class WXDLLEXPORT wxGridCellBoolRenderer
: public wxGridCellRenderer
241 // draw a check mark or nothing
242 virtual void Draw(wxGrid
& grid
,
243 wxGridCellAttr
& attr
,
249 // return the checkmark size
250 virtual wxSize
GetBestSize(wxGrid
& grid
,
251 wxGridCellAttr
& attr
,
256 static wxSize ms_sizeCheckMark
;
259 // ----------------------------------------------------------------------------
260 // wxGridCellEditor: This class is responsible for providing and manipulating
261 // the in-place edit controls for the grid. Instances of wxGridCellEditor
262 // (actually, instances of derived classes since it is an ABC) can be
263 // associated with the cell attributes for individual cells, rows, columns, or
264 // even for the entire grid.
265 // ----------------------------------------------------------------------------
267 class WXDLLEXPORT wxGridCellEditor
272 // this class is ref counted: it is created with ref count of 1, so
273 // calling DecRef() once will delete it. Calling IncRef() allows to lock
274 // it until the matching DecRef() is called
275 void IncRef() { m_nRef
++; }
276 void DecRef() { if ( !--m_nRef
) delete this; }
278 bool IsCreated() { return m_control
!= NULL
; }
280 // Creates the actual edit control
281 virtual void Create(wxWindow
* parent
,
283 wxEvtHandler
* evtHandler
) = 0;
285 // Size and position the edit control
286 virtual void SetSize(const wxRect
& rect
);
288 // Show or hide the edit control, use the specified attributes to set
289 // colours/fonts for it
290 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
292 // Draws the part of the cell not occupied by the control: the base class
293 // version just fills it with background colour from the attribute
294 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
296 // Fetch the value from the table and prepare the edit control
297 // to begin editing. Set the focus to the edit control.
298 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
300 // Complete the editing of the current cell. Returns true if the value has
301 // changed. If necessary, the control may be destroyed.
302 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
) = 0;
304 // Reset the value in the control back to its starting value
305 virtual void Reset() = 0;
307 // If the editor is enabled by pressing keys on the grid,
308 // this will be called to let the editor do something about
309 // that first key if desired.
310 virtual void StartingKey(wxKeyEvent
& event
);
312 // if the editor is enabled by clicking on the cell, this method will be
314 virtual void StartingClick();
316 // Some types of controls on some platforms may need some help
317 // with the Return key.
318 virtual void HandleReturn(wxKeyEvent
& event
);
321 virtual void Destroy();
324 // the dtor is private because only DecRef() can delete us
325 virtual ~wxGridCellEditor();
327 // the ref count - when it goes to 0, we die
330 // the control we show on screen
331 wxControl
* m_control
;
333 // if we change the colours/font of the control from the default ones, we
334 // must restore the default later and we save them here between calls to
335 // Show(TRUE) and Show(FALSE)
340 // suppress the stupid gcc warning about the class having private dtor and
342 friend class wxGridCellEditorDummyFriend
;
345 // the editor for string/text data
346 class WXDLLEXPORT wxGridCellTextEditor
: public wxGridCellEditor
349 wxGridCellTextEditor();
351 virtual void Create(wxWindow
* parent
,
353 wxEvtHandler
* evtHandler
);
354 virtual void SetSize(const wxRect
& rect
);
356 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
358 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
359 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
361 virtual void Reset();
362 virtual void StartingKey(wxKeyEvent
& event
);
363 virtual void HandleReturn(wxKeyEvent
& event
);
366 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
368 // parts of our virtual functions reused by the derived classes
369 void DoBeginEdit(const wxString
& startValue
);
370 void DoReset(const wxString
& startValue
);
373 wxString m_startValue
;
376 // the editor for numeric (long) data
377 class WXDLLEXPORT wxGridCellNumberEditor
: public wxGridCellTextEditor
380 // allows to specify the range - if min == max == -1, no range checking is
382 wxGridCellNumberEditor(int min
= -1, int max
= -1);
384 virtual void Create(wxWindow
* parent
,
386 wxEvtHandler
* evtHandler
);
388 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
389 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
391 virtual void Reset();
392 virtual void StartingKey(wxKeyEvent
& event
);
395 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
397 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
398 bool HasRange() const { return m_min
!= m_max
; }
400 // string representation of m_valueOld
401 wxString
GetString() const
402 { return wxString::Format(_T("%ld"), m_valueOld
); }
411 // the editor for floating point numbers (double) data
412 class WXDLLEXPORT wxGridCellFloatEditor
: public wxGridCellTextEditor
415 virtual void Create(wxWindow
* parent
,
417 wxEvtHandler
* evtHandler
);
419 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
420 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
422 virtual void Reset();
423 virtual void StartingKey(wxKeyEvent
& event
);
426 // string representation of m_valueOld
427 wxString
GetString() const
428 { return wxString::Format(_T("%f"), m_valueOld
); }
434 // the editor for boolean data
435 class WXDLLEXPORT wxGridCellBoolEditor
: public wxGridCellEditor
438 virtual void Create(wxWindow
* parent
,
440 wxEvtHandler
* evtHandler
);
442 virtual void SetSize(const wxRect
& rect
);
443 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
445 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
446 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
448 virtual void Reset();
449 virtual void StartingClick();
452 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
458 // the editor for string data allowing to choose from the list of strings
459 class WXDLLEXPORT wxGridCellChoiceEditor
: public wxGridCellEditor
462 // if !allowOthers, user can't type a string not in choices array
463 wxGridCellChoiceEditor(size_t count
, const wxChar
* choices
[],
464 bool allowOthers
= FALSE
);
466 virtual void Create(wxWindow
* parent
,
468 wxEvtHandler
* evtHandler
);
470 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
472 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
473 virtual bool EndEdit(int row
, int col
, wxGrid
* grid
);
475 virtual void Reset();
478 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
481 wxString m_startValue
;
482 wxArrayString m_choices
;
486 // ----------------------------------------------------------------------------
487 // wxGridCellAttr: this class can be used to alter the cells appearance in
488 // the grid by changing their colour/font/... from default. An object of this
489 // class may be returned by wxGridTable::GetAttr().
490 // ----------------------------------------------------------------------------
492 class WXDLLEXPORT wxGridCellAttr
502 // VZ: considering the number of members wxGridCellAttr has now, this ctor
503 // seems to be pretty useless... may be we should just remove it?
504 wxGridCellAttr(const wxColour
& colText
,
505 const wxColour
& colBack
,
509 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
512 SetAlignment(hAlign
, vAlign
);
515 // creates a new copy of this object
516 wxGridCellAttr
*Clone() const;
518 // this class is ref counted: it is created with ref count of 1, so
519 // calling DecRef() once will delete it. Calling IncRef() allows to lock
520 // it until the matching DecRef() is called
521 void IncRef() { m_nRef
++; }
522 void DecRef() { if ( !--m_nRef
) delete this; }
525 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
526 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
527 void SetFont(const wxFont
& font
) { m_font
= font
; }
528 void SetAlignment(int hAlign
, int vAlign
)
533 void SetReadOnly(bool isReadOnly
= TRUE
) { m_isReadOnly
= isReadOnly
; }
535 // takes ownership of the pointer
536 void SetRenderer(wxGridCellRenderer
*renderer
)
537 { wxSafeDecRef(m_renderer
); m_renderer
= renderer
; }
538 void SetEditor(wxGridCellEditor
* editor
)
539 { wxSafeDecRef(m_editor
); m_editor
= editor
; }
542 bool HasTextColour() const { return m_colText
.Ok(); }
543 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
544 bool HasFont() const { return m_font
.Ok(); }
545 bool HasAlignment() const { return m_hAlign
|| m_vAlign
; }
546 bool HasRenderer() const { return m_renderer
!= NULL
; }
547 bool HasEditor() const { return m_editor
!= NULL
; }
549 const wxColour
& GetTextColour() const;
550 const wxColour
& GetBackgroundColour() const;
551 const wxFont
& GetFont() const;
552 void GetAlignment(int *hAlign
, int *vAlign
) const;
553 wxGridCellRenderer
*GetRenderer(wxGrid
* grid
, int row
, int col
) const;
554 wxGridCellEditor
*GetEditor(wxGrid
* grid
, int row
, int col
) const;
556 bool IsReadOnly() const { return m_isReadOnly
; }
558 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
561 // the common part of all ctors
566 m_isReadOnly
= FALSE
;
572 // the dtor is private because only DecRef() can delete us
575 wxSafeDecRef(m_renderer
);
576 wxSafeDecRef(m_editor
);
579 // the ref count - when it goes to 0, we die
588 wxGridCellRenderer
* m_renderer
;
589 wxGridCellEditor
* m_editor
;
590 wxGridCellAttr
* m_defGridAttr
;
594 // use Clone() instead
595 DECLARE_NO_COPY_CLASS(wxGridCellAttr
);
597 // suppress the stupid gcc warning about the class having private dtor and
599 friend class wxGridCellAttrDummyFriend
;
602 // ----------------------------------------------------------------------------
603 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
605 // ----------------------------------------------------------------------------
607 // implementation note: we separate it from wxGridTableBase because we wish to
608 // avoid deriving a new table class if possible, and sometimes it will be
609 // enough to just derive another wxGridCellAttrProvider instead
611 // the default implementation is reasonably efficient for the generic case,
612 // but you might still wish to implement your own for some specific situations
613 // if you have performance problems with the stock one
614 class WXDLLEXPORT wxGridCellAttrProvider
617 wxGridCellAttrProvider();
618 virtual ~wxGridCellAttrProvider();
620 // DecRef() must be called on the returned pointer
621 virtual wxGridCellAttr
*GetAttr(int row
, int col
) const;
623 // all these functions take ownership of the pointer, don't call DecRef()
625 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
626 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
627 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
629 // these functions must be called whenever some rows/cols are deleted
630 // because the internal data must be updated then
631 void UpdateAttrRows( size_t pos
, int numRows
);
632 void UpdateAttrCols( size_t pos
, int numCols
);
637 wxGridCellAttrProviderData
*m_data
;
640 //////////////////////////////////////////////////////////////////////
642 // Grid table classes
644 //////////////////////////////////////////////////////////////////////
647 class WXDLLEXPORT wxGridTableBase
: public wxObject
651 virtual ~wxGridTableBase();
653 // You must override these functions in a derived table class
655 virtual long GetNumberRows() = 0;
656 virtual long GetNumberCols() = 0;
657 virtual bool IsEmptyCell( int row
, int col
) = 0;
658 virtual wxString
GetValue( int row
, int col
) = 0;
659 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
661 // Data type determination and value access
662 virtual wxString
GetTypeName( int row
, int col
);
663 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
664 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
666 virtual long GetValueAsLong( int row
, int col
);
667 virtual double GetValueAsDouble( int row
, int col
);
668 virtual bool GetValueAsBool( int row
, int col
);
670 virtual void SetValueAsLong( int row
, int col
, long value
);
671 virtual void SetValueAsDouble( int row
, int col
, double value
);
672 virtual void SetValueAsBool( int row
, int col
, bool value
);
674 // For user defined types
675 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
676 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
679 // Overriding these is optional
681 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
682 virtual wxGrid
* GetView() const { return m_view
; }
684 virtual void Clear() {}
685 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
686 virtual bool AppendRows( size_t numRows
= 1 );
687 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
688 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
689 virtual bool AppendCols( size_t numCols
= 1 );
690 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
692 virtual wxString
GetRowLabelValue( int row
);
693 virtual wxString
GetColLabelValue( int col
);
694 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
695 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
697 // Attribute handling
700 // give us the attr provider to use - we take ownership of the pointer
701 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
703 // get the currently used attr provider (may be NULL)
704 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
706 // Does this table allow attributes? Default implementation creates
707 // a wxGridCellAttrProvider if necessary.
708 virtual bool CanHaveAttributes();
711 // change row/col number in attribute if needed
712 virtual void UpdateAttrRows( size_t pos
, int numRows
);
713 virtual void UpdateAttrCols( size_t pos
, int numCols
);
715 // by default forwarded to wxGridCellAttrProvider if any. May be
716 // overridden to handle attributes directly in the table.
717 virtual wxGridCellAttr
*GetAttr( int row
, int col
);
719 // these functions take ownership of the pointer
720 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
721 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
722 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
726 wxGridCellAttrProvider
*m_attrProvider
;
728 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
732 // ----------------------------------------------------------------------------
733 // wxGridTableMessage
734 // ----------------------------------------------------------------------------
736 // IDs for messages sent from grid table to view
738 enum wxGridTableRequest
740 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
741 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
742 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
743 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
744 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
745 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
746 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
747 wxGRIDTABLE_NOTIFY_COLS_DELETED
750 class WXDLLEXPORT wxGridTableMessage
753 wxGridTableMessage();
754 wxGridTableMessage( wxGridTableBase
*table
, int id
,
758 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
759 wxGridTableBase
* GetTableObject() const { return m_table
; }
760 void SetId( int id
) { m_id
= id
; }
761 int GetId() { return m_id
; }
762 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
763 int GetCommandInt() { return m_comInt1
; }
764 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
765 int GetCommandInt2() { return m_comInt2
; }
768 wxGridTableBase
*m_table
;
776 // ------ wxGridStringArray
777 // A 2-dimensional array of strings for data values
780 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
784 // ------ wxGridStringTable
786 // Simplest type of data table for a grid for small tables of strings
787 // that are stored in memory
790 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
794 wxGridStringTable( int numRows
, int numCols
);
795 ~wxGridStringTable();
797 // these are pure virtual in wxGridTableBase
799 long GetNumberRows();
800 long GetNumberCols();
801 wxString
GetValue( int row
, int col
);
802 void SetValue( int row
, int col
, const wxString
& s
);
803 bool IsEmptyCell( int row
, int col
);
805 // overridden functions from wxGridTableBase
808 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
809 bool AppendRows( size_t numRows
= 1 );
810 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
811 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
812 bool AppendCols( size_t numCols
= 1 );
813 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
815 void SetRowLabelValue( int row
, const wxString
& );
816 void SetColLabelValue( int col
, const wxString
& );
817 wxString
GetRowLabelValue( int row
);
818 wxString
GetColLabelValue( int col
);
821 wxGridStringArray m_data
;
823 // These only get used if you set your own labels, otherwise the
824 // GetRow/ColLabelValue functions return wxGridTableBase defaults
826 wxArrayString m_rowLabels
;
827 wxArrayString m_colLabels
;
829 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
834 // ============================================================================
836 // ============================================================================
838 // ----------------------------------------------------------------------------
839 // wxGridCellCoords: location of a cell in the grid
840 // ----------------------------------------------------------------------------
842 class WXDLLEXPORT wxGridCellCoords
845 wxGridCellCoords() { m_row
= m_col
= -1; }
846 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
848 // default copy ctor is ok
850 long GetRow() const { return m_row
; }
851 void SetRow( long n
) { m_row
= n
; }
852 long GetCol() const { return m_col
; }
853 void SetCol( long n
) { m_col
= n
; }
854 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
856 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
858 if ( &other
!= this )
866 bool operator==( const wxGridCellCoords
& other
) const
868 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
871 bool operator!=( const wxGridCellCoords
& other
) const
873 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
876 bool operator!() const
878 return (m_row
== -1 && m_col
== -1 );
887 // For comparisons...
889 extern wxGridCellCoords wxGridNoCellCoords
;
890 extern wxRect wxGridNoCellRect
;
892 // An array of cell coords...
894 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
896 // ----------------------------------------------------------------------------
898 // ----------------------------------------------------------------------------
900 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
908 wxGrid( wxWindow
*parent
,
910 const wxPoint
& pos
= wxDefaultPosition
,
911 const wxSize
& size
= wxDefaultSize
,
912 long style
= wxWANTS_CHARS
,
913 const wxString
& name
= wxPanelNameStr
);
917 bool CreateGrid( int numRows
, int numCols
);
920 // ------ grid dimensions
922 int GetNumberRows() { return m_numRows
; }
923 int GetNumberCols() { return m_numCols
; }
926 // ------ display update functions
928 void CalcRowLabelsExposed( wxRegion
& reg
);
930 void CalcColLabelsExposed( wxRegion
& reg
);
931 void CalcCellsExposed( wxRegion
& reg
);
934 // ------ event handlers
936 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
937 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
938 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
939 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
940 bool ProcessTableMessage( wxGridTableMessage
& );
942 void DoEndDragResizeRow();
943 void DoEndDragResizeCol();
945 wxGridTableBase
* GetTable() const { return m_table
; }
946 bool SetTable( wxGridTableBase
*table
, bool takeOwnership
=FALSE
);
949 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
950 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
951 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
952 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
953 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
954 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
956 void DrawGridCellArea( wxDC
& dc
);
957 void DrawGridSpace( wxDC
& dc
);
958 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
959 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
960 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
961 void DrawHighlight(wxDC
& dc
);
963 // this function is called when the current cell highlight must be redrawn
964 // and may be overridden by the user
965 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
967 void DrawRowLabels( wxDC
& dc
);
968 void DrawRowLabel( wxDC
& dc
, int row
);
970 void DrawColLabels( wxDC
& dc
);
971 void DrawColLabel( wxDC
& dc
, int col
);
974 // ------ Cell text drawing functions
976 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
977 int horizontalAlignment
= wxLEFT
,
978 int verticalAlignment
= wxTOP
);
980 // Split a string containing newline chararcters into an array of
981 // strings and return the number of lines
983 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
985 void GetTextBoxSize( wxDC
& dc
,
986 wxArrayString
& lines
,
987 long *width
, long *height
);
991 // Code that does a lot of grid modification can be enclosed
992 // between BeginBatch() and EndBatch() calls to avoid screen
995 void BeginBatch() { m_batchCount
++; }
996 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
997 int GetBatchCount() { return m_batchCount
; }
1000 // ------ edit control functions
1002 bool IsEditable() { return m_editable
; }
1003 void EnableEditing( bool edit
);
1005 void EnableCellEditControl( bool enable
= TRUE
);
1006 void DisableCellEditControl() { EnableCellEditControl(FALSE
); }
1007 bool CanEnableCellControl() const;
1008 bool IsCellEditControlEnabled() const;
1010 bool IsCurrentCellReadOnly() const;
1012 void ShowCellEditControl();
1013 void HideCellEditControl();
1014 void SaveEditControlValue();
1017 // ------ grid location functions
1018 // Note that all of these functions work with the logical coordinates of
1019 // grid cells and labels so you will need to convert from device
1020 // coordinates for mouse events etc.
1022 void XYToCell( int x
, int y
, wxGridCellCoords
& );
1023 int YToRow( int y
);
1024 int XToCol( int x
);
1026 int YToEdgeOfRow( int y
);
1027 int XToEdgeOfCol( int x
);
1029 wxRect
CellToRect( int row
, int col
);
1030 wxRect
CellToRect( const wxGridCellCoords
& coords
)
1031 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
1033 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
1034 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
1036 // check to see if a cell is either wholly visible (the default arg) or
1037 // at least partially visible in the grid window
1039 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
1040 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
1041 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
1042 void MakeCellVisible( int row
, int col
);
1043 void MakeCellVisible( const wxGridCellCoords
& coords
)
1044 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
1047 // ------ grid cursor movement functions
1049 void SetGridCursor( int row
, int col
)
1050 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1052 bool MoveCursorUp();
1053 bool MoveCursorDown();
1054 bool MoveCursorLeft();
1055 bool MoveCursorRight();
1056 bool MovePageDown();
1058 bool MoveCursorUpBlock();
1059 bool MoveCursorDownBlock();
1060 bool MoveCursorLeftBlock();
1061 bool MoveCursorRightBlock();
1064 // ------ label and gridline formatting
1066 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
1067 int GetRowLabelSize() { return m_rowLabelWidth
; }
1068 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
1069 int GetColLabelSize() { return m_colLabelHeight
; }
1070 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
1071 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
1072 wxFont
GetLabelFont() { return m_labelFont
; }
1073 void GetRowLabelAlignment( int *horiz
, int *vert
);
1074 void GetColLabelAlignment( int *horiz
, int *vert
);
1075 wxString
GetRowLabelValue( int row
);
1076 wxString
GetColLabelValue( int col
);
1077 wxColour
GetGridLineColour() { return m_gridLineColour
; }
1079 void SetRowLabelSize( int width
);
1080 void SetColLabelSize( int height
);
1081 void SetLabelBackgroundColour( const wxColour
& );
1082 void SetLabelTextColour( const wxColour
& );
1083 void SetLabelFont( const wxFont
& );
1084 void SetRowLabelAlignment( int horiz
, int vert
);
1085 void SetColLabelAlignment( int horiz
, int vert
);
1086 void SetRowLabelValue( int row
, const wxString
& );
1087 void SetColLabelValue( int col
, const wxString
& );
1088 void SetGridLineColour( const wxColour
& );
1090 void EnableDragRowSize( bool enable
= TRUE
);
1091 void DisableDragRowSize() { EnableDragRowSize( FALSE
); }
1092 bool CanDragRowSize() { return m_canDragRowSize
; }
1093 void EnableDragColSize( bool enable
= TRUE
);
1094 void DisableDragColSize() { EnableDragColSize( FALSE
); }
1095 bool CanDragColSize() { return m_canDragColSize
; }
1096 void EnableDragGridSize(bool enable
= TRUE
);
1097 void DisableDragGridSize() { EnableDragGridSize(FALSE
); }
1098 bool CanDragGridSize() { return m_canDragGridSize
; }
1100 // this sets the specified attribute for all cells in this row/col
1101 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
1102 void SetColAttr(int col
, wxGridCellAttr
*attr
);
1104 // shortcuts for setting the column parameters
1106 // set the format for the data in the column: default is string
1107 void SetColFormatBool(int col
);
1108 void SetColFormatNumber(int col
);
1109 void SetColFormatFloat(int col
, int width
= -1, int precision
= -1);
1110 void SetColFormatCustom(int col
, const wxString
& typeName
);
1112 void EnableGridLines( bool enable
= TRUE
);
1113 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
1115 // ------ row and col formatting
1117 int GetDefaultRowSize();
1118 int GetRowSize( int row
);
1119 int GetDefaultColSize();
1120 int GetColSize( int col
);
1121 wxColour
GetDefaultCellBackgroundColour();
1122 wxColour
GetCellBackgroundColour( int row
, int col
);
1123 wxColour
GetDefaultCellTextColour();
1124 wxColour
GetCellTextColour( int row
, int col
);
1125 wxFont
GetDefaultCellFont();
1126 wxFont
GetCellFont( int row
, int col
);
1127 void GetDefaultCellAlignment( int *horiz
, int *vert
);
1128 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
1130 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
1131 void SetRowSize( int row
, int height
);
1132 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
1134 void SetColSize( int col
, int width
);
1136 // automatically size the column or row to fit to its contents, if
1137 // setAsMin is TRUE, this optimal width will also be set as minimal width
1139 void AutoSizeColumn( int col
, bool setAsMin
= TRUE
)
1140 { AutoSizeColOrRow(col
, setAsMin
, TRUE
); }
1141 void AutoSizeRow( int row
, bool setAsMin
= TRUE
)
1142 { AutoSizeColOrRow(row
, setAsMin
, FALSE
); }
1144 // auto size all columns (very ineffective for big grids!)
1145 void AutoSizeColumns( bool setAsMin
= TRUE
)
1146 { (void)SetOrCalcColumnSizes(FALSE
, setAsMin
); }
1148 void AutoSizeRows( bool setAsMin
= TRUE
)
1149 { (void)SetOrCalcRowSizes(FALSE
, setAsMin
); }
1151 // auto size the grid, that is make the columns/rows of the "right" size
1152 // and also set the grid size to just fit its contents
1155 // column won't be resized to be lesser width - this must be called during
1156 // the grid creation because it won't resize the column if it's already
1157 // narrower than the minimal width
1158 void SetColMinimalWidth( int col
, int width
);
1159 void SetRowMinimalHeight( int row
, int width
);
1161 void SetDefaultCellBackgroundColour( const wxColour
& );
1162 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1163 void SetDefaultCellTextColour( const wxColour
& );
1165 void SetCellTextColour( int row
, int col
, const wxColour
& );
1166 void SetDefaultCellFont( const wxFont
& );
1167 void SetCellFont( int row
, int col
, const wxFont
& );
1168 void SetDefaultCellAlignment( int horiz
, int vert
);
1169 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1171 // takes ownership of the pointer
1172 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1173 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1174 wxGridCellRenderer
*GetDefaultRenderer() const;
1175 wxGridCellRenderer
* GetCellRenderer(int row
, int col
);
1177 // takes ownership of the pointer
1178 void SetDefaultEditor(wxGridCellEditor
*editor
);
1179 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1180 wxGridCellEditor
*GetDefaultEditor() const;
1181 wxGridCellEditor
* GetCellEditor(int row
, int col
);
1185 // ------ cell value accessors
1187 wxString
GetCellValue( int row
, int col
)
1191 return m_table
->GetValue( row
, col
);
1195 return wxEmptyString
;
1199 wxString
GetCellValue( const wxGridCellCoords
& coords
)
1200 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1202 void SetCellValue( int row
, int col
, const wxString
& s
);
1203 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1204 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1206 // returns TRUE if the cell can't be edited
1207 bool IsReadOnly(int row
, int col
) const;
1209 // make the cell editable/readonly
1210 void SetReadOnly(int row
, int col
, bool isReadOnly
= TRUE
);
1212 // ------ selections of blocks of cells
1214 void SelectRow( int row
, bool addToSelected
= FALSE
);
1215 void SelectCol( int col
, bool addToSelected
= FALSE
);
1217 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
1219 void SelectBlock( const wxGridCellCoords
& topLeft
,
1220 const wxGridCellCoords
& bottomRight
)
1221 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1222 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
1227 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
1228 m_selectedBottomRight
!= wxGridNoCellCoords
);
1231 void ClearSelection();
1233 bool IsInSelection( int row
, int col
)
1234 { return ( IsSelection() &&
1235 row
>= m_selectedTopLeft
.GetRow() &&
1236 col
>= m_selectedTopLeft
.GetCol() &&
1237 row
<= m_selectedBottomRight
.GetRow() &&
1238 col
<= m_selectedBottomRight
.GetCol() );
1241 bool IsInSelection( const wxGridCellCoords
& coords
)
1242 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1244 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
1246 // these will all be -1 if there is no selected block
1248 *topRow
= m_selectedTopLeft
.GetRow();
1249 *leftCol
= m_selectedTopLeft
.GetCol();
1250 *bottomRow
= m_selectedBottomRight
.GetRow();
1251 *rightCol
= m_selectedBottomRight
.GetCol();
1255 // This function returns the rectangle that encloses the block of cells
1256 // limited by TopLeft and BottomRight cell in device coords and clipped
1257 // to the client size of the grid window.
1259 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1260 const wxGridCellCoords
& bottomRight
);
1262 // This function returns the rectangle that encloses the selected cells
1263 // in device coords and clipped to the client size of the grid window.
1265 wxRect
SelectionToDeviceRect()
1267 return BlockToDeviceRect( m_selectedTopLeft
,
1268 m_selectedBottomRight
);
1271 // Access or update the selection fore/back colours
1272 wxColour
GetSelectionBackground() const
1273 { return m_selectionBackground
; }
1274 wxColour
GetSelectionForeground() const
1275 { return m_selectionForeground
; }
1277 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1278 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1281 // Methods for a registry for mapping data types to Renderers/Editors
1282 void RegisterDataType(const wxString
& typeName
,
1283 wxGridCellRenderer
* renderer
,
1284 wxGridCellEditor
* editor
);
1285 wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1286 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1287 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1288 wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1289 wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1290 wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1292 // grid may occupy more space than needed for its rows/columns, this
1293 // function allows to set how big this extra space is
1294 void SetMargins(int extraWidth
, int extraHeight
)
1296 m_extraWidth
= extraWidth
;
1297 m_extraHeight
= extraHeight
;
1300 // ------ For compatibility with previous wxGrid only...
1302 // ************************************************
1303 // ** Don't use these in new code because they **
1304 // ** are liable to disappear in a future **
1306 // ************************************************
1309 wxGrid( wxWindow
*parent
,
1310 int x
, int y
, int w
= -1, int h
= -1,
1311 long style
= wxWANTS_CHARS
,
1312 const wxString
& name
= wxPanelNameStr
)
1313 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
),
1314 (style
|wxWANTS_CHARS
), name
)
1319 void SetCellValue( const wxString
& val
, int row
, int col
)
1320 { SetCellValue( row
, col
, val
); }
1322 void UpdateDimensions()
1323 { CalcDimensions(); }
1325 int GetRows() { return GetNumberRows(); }
1326 int GetCols() { return GetNumberCols(); }
1327 int GetCursorRow() { return GetGridCursorRow(); }
1328 int GetCursorColumn() { return GetGridCursorCol(); }
1330 int GetScrollPosX() { return 0; }
1331 int GetScrollPosY() { return 0; }
1333 void SetScrollX( int x
) { }
1334 void SetScrollY( int y
) { }
1336 void SetColumnWidth( int col
, int width
)
1337 { SetColSize( col
, width
); }
1339 int GetColumnWidth( int col
)
1340 { return GetColSize( col
); }
1342 void SetRowHeight( int row
, int height
)
1343 { SetRowSize( row
, height
); }
1345 // GetRowHeight() is below
1347 int GetViewHeight() // returned num whole rows visible
1350 int GetViewWidth() // returned num whole cols visible
1353 void SetLabelSize( int orientation
, int sz
)
1355 if ( orientation
== wxHORIZONTAL
)
1356 SetColLabelSize( sz
);
1358 SetRowLabelSize( sz
);
1361 int GetLabelSize( int orientation
)
1363 if ( orientation
== wxHORIZONTAL
)
1364 return GetColLabelSize();
1366 return GetRowLabelSize();
1369 void SetLabelAlignment( int orientation
, int align
)
1371 if ( orientation
== wxHORIZONTAL
)
1372 SetColLabelAlignment( align
, -1 );
1374 SetRowLabelAlignment( align
, -1 );
1377 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
1380 if ( orientation
== wxHORIZONTAL
)
1382 GetColLabelAlignment( &h
, &v
);
1387 GetRowLabelAlignment( &h
, &v
);
1392 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1394 if ( orientation
== wxHORIZONTAL
)
1395 SetColLabelValue( pos
, val
);
1397 SetRowLabelValue( pos
, val
);
1400 wxString
GetLabelValue( int orientation
, int pos
)
1402 if ( orientation
== wxHORIZONTAL
)
1403 return GetColLabelValue( pos
);
1405 return GetRowLabelValue( pos
);
1408 wxFont
GetCellTextFont() const
1409 { return m_defaultCellAttr
->GetFont(); }
1411 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1412 { return m_defaultCellAttr
->GetFont(); }
1414 void SetCellTextFont(const wxFont
& fnt
)
1415 { SetDefaultCellFont( fnt
); }
1417 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1418 { SetCellFont( row
, col
, fnt
); }
1420 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1421 { SetCellTextColour( row
, col
, val
); }
1423 void SetCellTextColour(const wxColour
& col
)
1424 { SetDefaultCellTextColour( col
); }
1426 void SetCellBackgroundColour(const wxColour
& col
)
1427 { SetDefaultCellBackgroundColour( col
); }
1429 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1430 { SetCellBackgroundColour( row
, col
, colour
); }
1432 bool GetEditable() { return IsEditable(); }
1433 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
1434 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
1436 void SetEditInPlace(bool edit
= TRUE
) { }
1438 void SetCellAlignment( int align
, int row
, int col
)
1439 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
1440 void SetCellAlignment( int WXUNUSED(align
) ) {}
1441 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1443 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1444 wxPen
& GetDividerPen() const { return wxNullPen
; }
1445 void OnActivate(bool WXUNUSED(active
)) {}
1447 // ******** End of compatibility functions **********
1451 // ------ control IDs
1452 enum { wxGRID_CELLCTRL
= 2000,
1455 // ------ control types
1456 enum { wxGRID_TEXTCTRL
= 2100,
1461 // overridden wxWindow methods
1465 virtual wxSize
DoGetBestSize() const;
1470 wxGridWindow
*m_gridWin
;
1471 wxGridRowLabelWindow
*m_rowLabelWin
;
1472 wxGridColLabelWindow
*m_colLabelWin
;
1473 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1475 wxGridTableBase
*m_table
;
1486 wxGridCellCoords m_currentCellCoords
;
1488 wxGridCellCoords m_selectedTopLeft
;
1489 wxGridCellCoords m_selectedBottomRight
;
1490 wxColour m_selectionBackground
;
1491 wxColour m_selectionForeground
;
1493 // NB: *never* access m_row/col arrays directly because they are created
1494 // on demand, *always* use accessor functions instead!
1496 // init the m_rowHeights/Bottoms arrays with default values
1497 void InitRowHeights();
1499 int m_defaultRowHeight
;
1500 wxArrayInt m_rowHeights
;
1501 wxArrayInt m_rowBottoms
;
1503 // init the m_colWidths/Rights arrays
1504 void InitColWidths();
1506 int m_defaultColWidth
;
1507 wxArrayInt m_colWidths
;
1508 wxArrayInt m_colRights
;
1510 // get the col/row coords
1511 int GetColWidth(int col
) const;
1512 int GetColLeft(int col
) const;
1513 int GetColRight(int col
) const;
1515 // this function must be public for compatibility...
1517 int GetRowHeight(int row
) const;
1520 int GetRowTop(int row
) const;
1521 int GetRowBottom(int row
) const;
1523 int m_rowLabelWidth
;
1524 int m_colLabelHeight
;
1526 // the size of the margin left to the right and bottom of the cell area
1530 wxColour m_labelBackgroundColour
;
1531 wxColour m_labelTextColour
;
1534 int m_rowLabelHorizAlign
;
1535 int m_rowLabelVertAlign
;
1536 int m_colLabelHorizAlign
;
1537 int m_colLabelVertAlign
;
1539 bool m_defaultRowLabelValues
;
1540 bool m_defaultColLabelValues
;
1542 wxColour m_gridLineColour
;
1543 bool m_gridLinesEnabled
;
1545 // common part of AutoSizeColumn/Row() and GetBestSize()
1546 int SetOrCalcColumnSizes(bool calcOnly
, bool setAsMin
= TRUE
);
1547 int SetOrCalcRowSizes(bool calcOnly
, bool setAsMin
= TRUE
);
1549 // common part of AutoSizeColumn/Row()
1550 void AutoSizeColOrRow(int n
, bool setAsMin
, bool column
/* or row? */);
1552 // if a column has a minimal width, it will be the value for it in this
1554 wxHashTableLong m_colMinWidths
,
1557 // get the minimal width of the given column/row
1558 int GetColMinimalWidth(int col
) const;
1559 int GetRowMinimalHeight(int col
) const;
1561 // do we have some place to store attributes in?
1562 bool CanHaveAttributes();
1564 // returns the attribute we may modify in place: a new one if this cell
1565 // doesn't have any yet or the existing one if it does
1567 // DecRef() must be called on the returned pointer, as usual
1568 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1570 // cell attribute cache (currently we only cache 1, may be will do
1571 // more/better later)
1575 wxGridCellAttr
*attr
;
1578 // invalidates the attribute cache
1579 void ClearAttrCache();
1581 // adds an attribute to cache
1582 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
1584 // looks for an attr in cache, returns TRUE if found
1585 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
1587 // looks for the attr in cache, if not found asks the table and caches the
1589 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
1590 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
)
1591 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
1593 // the default cell attr object for cells that don't have their own
1594 wxGridCellAttr
* m_defaultCellAttr
;
1597 wxGridCellCoordsArray m_cellsExposed
;
1598 wxArrayInt m_rowsExposed
;
1599 wxArrayInt m_colsExposed
;
1600 wxArrayInt m_rowLabelsExposed
;
1601 wxArrayInt m_colLabelsExposed
;
1607 wxGridTypeRegistry
* m_typeRegistry
;
1611 WXGRID_CURSOR_SELECT_CELL
,
1612 WXGRID_CURSOR_RESIZE_ROW
,
1613 WXGRID_CURSOR_RESIZE_COL
,
1614 WXGRID_CURSOR_SELECT_ROW
,
1615 WXGRID_CURSOR_SELECT_COL
1618 // this method not only sets m_cursorMode but also sets the correct cursor
1619 // for the given mode and, if captureMouse is not FALSE releases the mouse
1620 // if it was captured and captures it if it must be captured
1622 // for this to work, you should always use it and not set m_cursorMode
1624 void ChangeCursorMode(CursorMode mode
,
1625 wxWindow
*win
= (wxWindow
*)NULL
,
1626 bool captureMouse
= TRUE
);
1628 wxWindow
*m_winCapture
; // the window which captured the mouse
1629 CursorMode m_cursorMode
;
1631 bool m_canDragRowSize
;
1632 bool m_canDragColSize
;
1633 bool m_canDragGridSize
;
1637 wxPoint m_startDragPos
;
1639 bool m_waitForSlowClick
;
1641 wxGridCellCoords m_selectionStart
;
1643 wxCursor m_rowResizeCursor
;
1644 wxCursor m_colResizeCursor
;
1646 bool m_editable
; // applies to whole grid
1647 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
1652 void CalcDimensions();
1653 void CalcWindowSizes();
1654 bool Redimension( wxGridTableMessage
& );
1657 bool SendEvent( const wxEventType
, int row
, int col
, wxMouseEvent
& );
1658 bool SendEvent( const wxEventType
, int row
, int col
);
1659 bool SendEvent( const wxEventType type
)
1661 return SendEvent(type
,
1662 m_currentCellCoords
.GetRow(),
1663 m_currentCellCoords
.GetCol());
1666 void OnPaint( wxPaintEvent
& );
1667 void OnSize( wxSizeEvent
& );
1668 void OnKeyDown( wxKeyEvent
& );
1669 void OnEraseBackground( wxEraseEvent
& );
1672 void SetCurrentCell( const wxGridCellCoords
& coords
);
1673 void SetCurrentCell( int row
, int col
)
1674 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1677 // ------ functions to get/send data (see also public functions)
1679 bool GetModelValues();
1680 bool SetModelValues();
1683 DECLARE_DYNAMIC_CLASS( wxGrid
)
1684 DECLARE_EVENT_TABLE()
1687 // ----------------------------------------------------------------------------
1688 // Grid event class and event types
1689 // ----------------------------------------------------------------------------
1691 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
1695 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
1696 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1700 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
1701 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
1702 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1704 virtual int GetRow() { return m_row
; }
1705 virtual int GetCol() { return m_col
; }
1706 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1707 bool ControlDown() { return m_control
; }
1708 bool MetaDown() { return m_meta
; }
1709 bool ShiftDown() { return m_shift
; }
1710 bool AltDown() { return m_alt
; }
1722 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
1725 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1729 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1730 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1734 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1735 int rowOrCol
=-1, int x
=-1, int y
=-1,
1736 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1738 int GetRowOrCol() { return m_rowOrCol
; }
1739 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1740 bool ControlDown() { return m_control
; }
1741 bool MetaDown() { return m_meta
; }
1742 bool ShiftDown() { return m_shift
; }
1743 bool AltDown() { return m_alt
; }
1754 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1758 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1761 wxGridRangeSelectEvent()
1764 m_topLeft
= wxGridNoCellCoords
;
1765 m_bottomRight
= wxGridNoCellCoords
;
1772 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1773 const wxGridCellCoords
& topLeft
,
1774 const wxGridCellCoords
& bottomRight
,
1775 bool control
=FALSE
, bool shift
=FALSE
,
1776 bool alt
=FALSE
, bool meta
=FALSE
);
1778 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1779 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1780 int GetTopRow() { return m_topLeft
.GetRow(); }
1781 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1782 int GetLeftCol() { return m_topLeft
.GetCol(); }
1783 int GetRightCol() { return m_bottomRight
.GetCol(); }
1784 bool ControlDown() { return m_control
; }
1785 bool MetaDown() { return m_meta
; }
1786 bool ShiftDown() { return m_shift
; }
1787 bool AltDown() { return m_alt
; }
1790 wxGridCellCoords m_topLeft
;
1791 wxGridCellCoords m_bottomRight
;
1797 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1800 // TODO move to wx/event.h
1801 const wxEventType wxEVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1802 const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1803 const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1804 const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1805 const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1806 const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1807 const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1808 const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1809 const wxEventType wxEVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1810 const wxEventType wxEVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1811 const wxEventType wxEVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1812 const wxEventType wxEVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1813 const wxEventType wxEVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1814 const wxEventType wxEVT_GRID_EDITOR_SHOWN
= wxEVT_FIRST
+ 1593;
1815 const wxEventType wxEVT_GRID_EDITOR_HIDDEN
= wxEVT_FIRST
+ 1594;
1818 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1819 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1820 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1822 #define EVT_GRID_CELL_LEFT_CLICK(fn) { wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1823 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1824 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1825 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1826 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1827 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1828 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1829 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1830 #define EVT_GRID_ROW_SIZE(fn) { wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1831 #define EVT_GRID_COL_SIZE(fn) { wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1832 #define EVT_GRID_RANGE_SELECT(fn) { wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1833 #define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1834 #define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1835 #define EVT_GRID_EDITOR_SHOWN(fn) { wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1836 #define EVT_GRID_EDITOR_HIDDEN(fn) { wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1839 #if 0 // TODO: implement these ? others ?
1841 const wxEventType wxEVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1842 const wxEventType wxEVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1843 const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1845 #define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1846 #define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1847 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1851 #endif // #ifndef __WXGRID_H__
1853 #endif // ifndef wxUSE_NEW_GRID