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 wxTextCtrl
;
81 class WXDLLEXPORT wxSpinCtrl
;
83 // ----------------------------------------------------------------------------
84 // wxGridCellRenderer: this class is responsible for actually drawing the cell
85 // in the grid. You may pass it to the wxGridCellAttr (below) to change the
86 // format of one given cell or to wxGrid::SetDefaultRenderer() to change the
87 // view of all cells. This is an ABC, you will normally use one of the
88 // predefined derived classes or derive oyur own class from it.
89 // ----------------------------------------------------------------------------
91 class WXDLLEXPORT wxGridCellRenderer
94 // draw the given cell on the provided DC inside the given rectangle
95 // using the style specified by the attribute and the default or selected
96 // state corresponding to the isSelected value.
98 // this pure virtual function has a default implementation which will
99 // prepare the DC using the given attribute: it will draw the rectangle
100 // with the bg colour from attr and set the text colour and font
101 virtual void Draw(wxGrid
& grid
,
102 wxGridCellAttr
& attr
,
106 bool isSelected
) = 0;
108 // get the preferred size of the cell for its contents
109 virtual wxSize
GetBestSize(wxGrid
& grid
,
110 wxGridCellAttr
& attr
,
112 int row
, int col
) = 0;
114 // virtual dtor for any base class
115 virtual ~wxGridCellRenderer();
118 // the default renderer for the cells containing string data
119 class WXDLLEXPORT wxGridCellStringRenderer
: public wxGridCellRenderer
123 virtual void Draw(wxGrid
& grid
,
124 wxGridCellAttr
& attr
,
130 // return the string extent
131 virtual wxSize
GetBestSize(wxGrid
& grid
,
132 wxGridCellAttr
& attr
,
137 // set the text colours before drawing
138 void SetTextColoursAndFont(wxGrid
& grid
,
139 wxGridCellAttr
& attr
,
143 // calc the string extent for given string/font
144 wxSize
DoGetBestSize(wxGridCellAttr
& attr
,
146 const wxString
& text
);
149 // the default renderer for the cells containing numeric (long) data
150 class WXDLLEXPORT wxGridCellNumberRenderer
: public wxGridCellStringRenderer
153 // draw the string right aligned
154 virtual void Draw(wxGrid
& grid
,
155 wxGridCellAttr
& attr
,
161 virtual wxSize
GetBestSize(wxGrid
& grid
,
162 wxGridCellAttr
& attr
,
167 wxString
GetString(wxGrid
& grid
, int row
, int col
);
170 class WXDLLEXPORT wxGridCellFloatRenderer
: public wxGridCellStringRenderer
173 wxGridCellFloatRenderer(int width
, int precision
);
175 // get/change formatting parameters
176 int GetWidth() const { return m_width
; }
177 void SetWidth(int width
) { m_width
= width
; }
178 int GetPrecision() const { return m_precision
; }
179 void SetPrecision(int precision
) { m_precision
= precision
; }
181 // draw the string right aligned with given width/precision
182 virtual void Draw(wxGrid
& grid
,
183 wxGridCellAttr
& attr
,
189 virtual wxSize
GetBestSize(wxGrid
& grid
,
190 wxGridCellAttr
& attr
,
194 wxString
GetString(wxGrid
& grid
, int row
, int col
);
197 // formatting parameters
204 // renderer for boolean fields
205 class WXDLLEXPORT wxGridCellBoolRenderer
: public wxGridCellRenderer
208 // draw a check mark or nothing
209 virtual void Draw(wxGrid
& grid
,
210 wxGridCellAttr
& attr
,
216 // return the checkmark size
217 virtual wxSize
GetBestSize(wxGrid
& grid
,
218 wxGridCellAttr
& attr
,
223 static wxSize ms_sizeCheckMark
;
226 // ----------------------------------------------------------------------------
227 // wxGridCellEditor: This class is responsible for providing and manipulating
228 // the in-place edit controls for the grid. Instances of wxGridCellEditor
229 // (actually, instances of derived classes since it is an ABC) can be
230 // associated with the cell attributes for individual cells, rows, columns, or
231 // even for the entire grid.
232 // ----------------------------------------------------------------------------
234 class WXDLLEXPORT wxGridCellEditor
238 virtual ~wxGridCellEditor();
240 bool IsCreated() { return m_control
!= NULL
; }
242 // Creates the actual edit control
243 virtual void Create(wxWindow
* parent
,
245 wxEvtHandler
* evtHandler
) = 0;
247 // Size and position the edit control
248 virtual void SetSize(const wxRect
& rect
);
250 // Show or hide the edit control, use the specified attributes to set
251 // colours/fonts for it
252 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
254 // Draws the part of the cell not occupied by the control: the base class
255 // version just fills it with background colour from the attribute
256 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
258 // Fetch the value from the table and prepare the edit control
259 // to begin editing. Set the focus to the edit control.
260 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
262 // Complete the editing of the current cell. If saveValue is
263 // true then send the new value back to the table. Returns true
264 // if the value has changed. If necessary, the control may be
266 virtual bool EndEdit(int row
, int col
, bool saveValue
, wxGrid
* grid
) = 0;
268 // Reset the value in the control back to its starting value
269 virtual void Reset() = 0;
271 // If the editor is enabled by pressing keys on the grid,
272 // this will be called to let the editor do something about
273 // that first key if desired.
274 virtual void StartingKey(wxKeyEvent
& event
);
276 // if the editor is enabled by clicking on the cell, this method will be
278 virtual void StartingClick();
280 // Some types of controls on some platforms may need some help
281 // with the Return key.
282 virtual void HandleReturn(wxKeyEvent
& event
);
285 virtual void Destroy();
288 // the control we show on screen
289 wxControl
* m_control
;
291 // if we change the colours/font of the control from the default ones, we
292 // must restore the default later and we save them here between calls to
293 // Show(TRUE) and Show(FALSE)
299 // the editor for string/text data
300 class WXDLLEXPORT wxGridCellTextEditor
: public wxGridCellEditor
303 wxGridCellTextEditor();
305 virtual void Create(wxWindow
* parent
,
307 wxEvtHandler
* evtHandler
);
308 virtual void SetSize(const wxRect
& rect
);
310 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
312 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
313 virtual bool EndEdit(int row
, int col
, bool saveValue
, wxGrid
* grid
);
315 virtual void Reset();
316 virtual void StartingKey(wxKeyEvent
& event
);
317 virtual void HandleReturn(wxKeyEvent
& event
);
320 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
322 // parts of our virtual functions reused by the derived classes
323 void DoBeginEdit(const wxString
& startValue
);
324 void DoReset(const wxString
& startValue
);
327 wxString m_startValue
;
330 // the editor for numeric (long) data
331 class WXDLLEXPORT wxGridCellNumberEditor
: public wxGridCellTextEditor
334 // allows to specify the range - if min == max == -1, no range checking is
336 wxGridCellNumberEditor(int min
= -1, int max
= -1);
338 virtual void Create(wxWindow
* parent
,
340 wxEvtHandler
* evtHandler
);
342 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
343 virtual bool EndEdit(int row
, int col
, bool saveValue
, wxGrid
* grid
);
345 virtual void Reset();
346 virtual void StartingKey(wxKeyEvent
& event
);
349 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
351 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
352 bool HasRange() const { return m_min
!= m_max
; }
354 // string representation of m_valueOld
355 wxString
GetString() const
356 { return wxString
::Format(_T("%ld"), m_valueOld
); }
365 // the editor for floating point numbers (double) data
366 class WXDLLEXPORT wxGridCellFloatEditor
: public wxGridCellTextEditor
369 virtual void Create(wxWindow
* parent
,
371 wxEvtHandler
* evtHandler
);
373 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
374 virtual bool EndEdit(int row
, int col
, bool saveValue
, wxGrid
* grid
);
376 virtual void Reset();
377 virtual void StartingKey(wxKeyEvent
& event
);
380 // string representation of m_valueOld
381 wxString
GetString() const
382 { return wxString
::Format(_T("%f"), m_valueOld
); }
388 // the editor for boolean data
389 class WXDLLEXPORT wxGridCellBoolEditor
: public wxGridCellEditor
392 virtual void Create(wxWindow
* parent
,
394 wxEvtHandler
* evtHandler
);
396 virtual void SetSize(const wxRect
& rect
);
397 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
399 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
400 virtual bool EndEdit(int row
, int col
, bool saveValue
, wxGrid
* grid
);
402 virtual void Reset();
403 virtual void StartingClick();
406 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
412 // ----------------------------------------------------------------------------
413 // wxGridCellAttr: this class can be used to alter the cells appearance in
414 // the grid by changing their colour/font/... from default. An object of this
415 // class may be returned by wxGridTable::GetAttr().
416 // ----------------------------------------------------------------------------
418 class WXDLLEXPORT wxGridCellAttr
428 // VZ: considering the number of members wxGridCellAttr has now, this ctor
429 // seems to be pretty useless... may be we should just remove it?
430 wxGridCellAttr(const wxColour
& colText
,
431 const wxColour
& colBack
,
435 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
438 SetAlignment(hAlign
, vAlign
);
441 // default copy ctor ok
443 // this class is ref counted: it is created with ref count of 1, so
444 // calling DecRef() once will delete it. Calling IncRef() allows to lock
445 // it until the matching DecRef() is called
446 void IncRef() { m_nRef
++; }
447 void DecRef() { if ( !--m_nRef
) delete this; }
448 void SafeIncRef() { if ( this ) IncRef(); }
449 void SafeDecRef() { if ( this ) DecRef(); }
452 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
453 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
454 void SetFont(const wxFont
& font
) { m_font
= font
; }
455 void SetAlignment(int hAlign
, int vAlign
)
460 void SetReadOnly(bool isReadOnly
= TRUE
) { m_isReadOnly
= isReadOnly
; }
462 // takes ownership of the pointer
463 void SetRenderer(wxGridCellRenderer
*renderer
)
464 { delete m_renderer
; m_renderer
= renderer
; }
465 void SetEditor(wxGridCellEditor
* editor
)
466 { delete m_editor
; m_editor
= editor
; }
469 bool HasTextColour() const { return m_colText
.Ok(); }
470 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
471 bool HasFont() const { return m_font
.Ok(); }
472 bool HasAlignment() const { return m_hAlign
|| m_vAlign
; }
473 bool HasRenderer() const { return m_renderer
!= NULL
; }
474 bool HasEditor() const { return m_editor
!= NULL
; }
476 const wxColour
& GetTextColour() const;
477 const wxColour
& GetBackgroundColour() const;
478 const wxFont
& GetFont() const;
479 void GetAlignment(int *hAlign
, int *vAlign
) const;
480 wxGridCellRenderer
*GetRenderer(wxGridCellRenderer
* def
) const;
481 wxGridCellEditor
*GetEditor(wxGridCellEditor
* def
) const;
483 bool IsReadOnly() const { return m_isReadOnly
; }
485 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
488 // the common part of all ctors
493 m_isReadOnly
= FALSE
;
499 // the dtor is private because only DecRef() can delete us
500 ~wxGridCellAttr() { delete m_renderer
; delete m_editor
; }
502 // the ref count - when it goes to 0, we die
511 wxGridCellRenderer
* m_renderer
;
512 wxGridCellEditor
* m_editor
;
513 wxGridCellAttr
* m_defGridAttr
;
517 // suppress the stupid gcc warning about the class having private dtor and
519 friend class wxGridCellAttrDummyFriend
;
522 // ----------------------------------------------------------------------------
523 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
525 // ----------------------------------------------------------------------------
527 // implementation note: we separate it from wxGridTableBase because we wish to
528 // avoid deriving a new table class if possible, and sometimes it will be
529 // enough to just derive another wxGridCellAttrProvider instead
531 // the default implementation is reasonably efficient for the generic case,
532 // but you might still wish to implement your own for some specific situations
533 // if you have performance problems with the stock one
534 class WXDLLEXPORT wxGridCellAttrProvider
537 wxGridCellAttrProvider();
538 virtual ~wxGridCellAttrProvider();
540 // DecRef() must be called on the returned pointer
541 virtual wxGridCellAttr
*GetAttr(int row
, int col
) const;
543 // all these functions take ownership of the pointer, don't call DecRef()
545 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
546 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
547 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
549 // these functions must be called whenever some rows/cols are deleted
550 // because the internal data must be updated then
551 void UpdateAttrRows( size_t pos
, int numRows
);
552 void UpdateAttrCols( size_t pos
, int numCols
);
557 wxGridCellAttrProviderData
*m_data
;
560 //////////////////////////////////////////////////////////////////////
562 // Grid table classes
564 //////////////////////////////////////////////////////////////////////
567 class WXDLLEXPORT wxGridTableBase
: public wxObject
571 virtual ~wxGridTableBase();
573 // You must override these functions in a derived table class
575 virtual long GetNumberRows() = 0;
576 virtual long GetNumberCols() = 0;
577 virtual bool IsEmptyCell( int row
, int col
) = 0;
578 virtual wxString
GetValue( int row
, int col
) = 0;
579 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
581 // Data type determination and value access
582 virtual wxString
GetTypeName( int row
, int col
);
583 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
584 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
586 virtual long GetValueAsLong( int row
, int col
);
587 virtual double GetValueAsDouble( int row
, int col
);
588 virtual bool GetValueAsBool( int row
, int col
);
590 virtual void SetValueAsLong( int row
, int col
, long value
);
591 virtual void SetValueAsDouble( int row
, int col
, double value
);
592 virtual void SetValueAsBool( int row
, int col
, bool value
);
594 // For user defined types
595 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
596 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
599 // Overriding these is optional
601 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
602 virtual wxGrid
* GetView() const { return m_view
; }
604 virtual void Clear() {}
605 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
606 virtual bool AppendRows( size_t numRows
= 1 );
607 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
608 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
609 virtual bool AppendCols( size_t numCols
= 1 );
610 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
612 virtual wxString
GetRowLabelValue( int row
);
613 virtual wxString
GetColLabelValue( int col
);
614 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
615 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
617 // Attribute handling
620 // give us the attr provider to use - we take ownership of the pointer
621 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
623 // get the currently used attr provider (may be NULL)
624 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
626 // Does this table allow attributes? Default implementation creates
627 // a wxGridCellAttrProvider if necessary.
628 virtual bool CanHaveAttributes();
631 // change row/col number in attribute if needed
632 virtual void UpdateAttrRows( size_t pos
, int numRows
);
633 virtual void UpdateAttrCols( size_t pos
, int numCols
);
635 // by default forwarded to wxGridCellAttrProvider if any. May be
636 // overridden to handle attributes directly in the table.
637 virtual wxGridCellAttr
*GetAttr( int row
, int col
);
639 // these functions take ownership of the pointer
640 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
641 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
642 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
646 wxGridCellAttrProvider
*m_attrProvider
;
648 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
652 // ----------------------------------------------------------------------------
653 // wxGridTableMessage
654 // ----------------------------------------------------------------------------
656 // IDs for messages sent from grid table to view
658 enum wxGridTableRequest
660 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
661 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
662 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
663 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
664 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
665 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
666 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
667 wxGRIDTABLE_NOTIFY_COLS_DELETED
670 class WXDLLEXPORT wxGridTableMessage
673 wxGridTableMessage();
674 wxGridTableMessage( wxGridTableBase
*table
, int id
,
678 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
679 wxGridTableBase
* GetTableObject() const { return m_table
; }
680 void SetId( int id
) { m_id
= id
; }
681 int GetId() { return m_id
; }
682 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
683 int GetCommandInt() { return m_comInt1
; }
684 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
685 int GetCommandInt2() { return m_comInt2
; }
688 wxGridTableBase
*m_table
;
696 // ------ wxGridStringArray
697 // A 2-dimensional array of strings for data values
700 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
704 // ------ wxGridStringTable
706 // Simplest type of data table for a grid for small tables of strings
707 // that are stored in memory
710 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
714 wxGridStringTable( int numRows
, int numCols
);
715 ~wxGridStringTable();
717 // these are pure virtual in wxGridTableBase
719 long GetNumberRows();
720 long GetNumberCols();
721 wxString
GetValue( int row
, int col
);
722 void SetValue( int row
, int col
, const wxString
& s
);
723 bool IsEmptyCell( int row
, int col
);
725 // overridden functions from wxGridTableBase
728 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
729 bool AppendRows( size_t numRows
= 1 );
730 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
731 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
732 bool AppendCols( size_t numCols
= 1 );
733 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
735 void SetRowLabelValue( int row
, const wxString
& );
736 void SetColLabelValue( int col
, const wxString
& );
737 wxString
GetRowLabelValue( int row
);
738 wxString
GetColLabelValue( int col
);
741 wxGridStringArray m_data
;
743 // These only get used if you set your own labels, otherwise the
744 // GetRow/ColLabelValue functions return wxGridTableBase defaults
746 wxArrayString m_rowLabels
;
747 wxArrayString m_colLabels
;
749 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
754 // ============================================================================
756 // ============================================================================
758 // ----------------------------------------------------------------------------
759 // wxGridCellCoords: location of a cell in the grid
760 // ----------------------------------------------------------------------------
762 class WXDLLEXPORT wxGridCellCoords
765 wxGridCellCoords() { m_row
= m_col
= -1; }
766 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
768 // default copy ctor is ok
770 long GetRow() const { return m_row
; }
771 void SetRow( long n
) { m_row
= n
; }
772 long GetCol() const { return m_col
; }
773 void SetCol( long n
) { m_col
= n
; }
774 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
776 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
778 if ( &other
!= this )
786 bool operator==( const wxGridCellCoords
& other
) const
788 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
791 bool operator!=( const wxGridCellCoords
& other
) const
793 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
796 bool operator!() const
798 return (m_row
== -1 && m_col
== -1 );
807 // For comparisons...
809 extern wxGridCellCoords wxGridNoCellCoords
;
810 extern wxRect wxGridNoCellRect
;
812 // An array of cell coords...
814 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
816 // ----------------------------------------------------------------------------
818 // ----------------------------------------------------------------------------
820 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
828 wxGrid( wxWindow
*parent
,
830 const wxPoint
& pos
= wxDefaultPosition
,
831 const wxSize
& size
= wxDefaultSize
,
833 const wxString
& name
= wxPanelNameStr
);
837 bool CreateGrid( int numRows
, int numCols
);
840 // ------ grid dimensions
842 int GetNumberRows() { return m_numRows
; }
843 int GetNumberCols() { return m_numCols
; }
846 // ------ display update functions
848 void CalcRowLabelsExposed( wxRegion
& reg
);
850 void CalcColLabelsExposed( wxRegion
& reg
);
851 void CalcCellsExposed( wxRegion
& reg
);
854 // ------ event handlers
856 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
857 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
858 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
859 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
860 bool ProcessTableMessage( wxGridTableMessage
& );
862 void DoEndDragResizeRow();
863 void DoEndDragResizeCol();
865 wxGridTableBase
* GetTable() const { return m_table
; }
866 bool SetTable( wxGridTableBase
*table
, bool takeOwnership
=FALSE
);
869 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
870 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
871 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
872 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
873 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
874 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
876 void DrawGridCellArea( wxDC
& dc
);
877 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
878 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
879 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
880 void DrawHighlight(wxDC
& dc
);
882 // this function is called when the current cell highlight must be redrawn
883 // and may be overridden by the user
884 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
886 void DrawRowLabels( wxDC
& dc
);
887 void DrawRowLabel( wxDC
& dc
, int row
);
889 void DrawColLabels( wxDC
& dc
);
890 void DrawColLabel( wxDC
& dc
, int col
);
893 // ------ Cell text drawing functions
895 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
896 int horizontalAlignment
= wxLEFT
,
897 int verticalAlignment
= wxTOP
);
899 // Split a string containing newline chararcters into an array of
900 // strings and return the number of lines
902 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
904 void GetTextBoxSize( wxDC
& dc
,
905 wxArrayString
& lines
,
906 long *width
, long *height
);
910 // Code that does a lot of grid modification can be enclosed
911 // between BeginBatch() and EndBatch() calls to avoid screen
914 void BeginBatch() { m_batchCount
++; }
915 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
916 int GetBatchCount() { return m_batchCount
; }
919 // ------ edit control functions
921 bool IsEditable() { return m_editable
; }
922 void EnableEditing( bool edit
);
924 void EnableCellEditControl( bool enable
= TRUE
);
925 void DisableCellEditControl() { EnableCellEditControl(FALSE
); }
926 bool CanEnableCellControl() const;
927 bool IsCellEditControlEnabled() const;
929 bool IsCurrentCellReadOnly() const;
931 void ShowCellEditControl();
932 void HideCellEditControl();
933 void SetEditControlValue( const wxString
& s
= wxEmptyString
);
934 void SaveEditControlValue();
937 // ------ grid location functions
938 // Note that all of these functions work with the logical coordinates of
939 // grid cells and labels so you will need to convert from device
940 // coordinates for mouse events etc.
942 void XYToCell( int x
, int y
, wxGridCellCoords
& );
946 int YToEdgeOfRow( int y
);
947 int XToEdgeOfCol( int x
);
949 wxRect
CellToRect( int row
, int col
);
950 wxRect
CellToRect( const wxGridCellCoords
& coords
)
951 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
953 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
954 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
956 // check to see if a cell is either wholly visible (the default arg) or
957 // at least partially visible in the grid window
959 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
960 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
961 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
962 void MakeCellVisible( int row
, int col
);
963 void MakeCellVisible( const wxGridCellCoords
& coords
)
964 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
967 // ------ grid cursor movement functions
969 void SetGridCursor( int row
, int col
)
970 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
973 bool MoveCursorDown();
974 bool MoveCursorLeft();
975 bool MoveCursorRight();
978 bool MoveCursorUpBlock();
979 bool MoveCursorDownBlock();
980 bool MoveCursorLeftBlock();
981 bool MoveCursorRightBlock();
984 // ------ label and gridline formatting
986 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
987 int GetRowLabelSize() { return m_rowLabelWidth
; }
988 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
989 int GetColLabelSize() { return m_colLabelHeight
; }
990 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
991 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
992 wxFont
GetLabelFont() { return m_labelFont
; }
993 void GetRowLabelAlignment( int *horiz
, int *vert
);
994 void GetColLabelAlignment( int *horiz
, int *vert
);
995 wxString
GetRowLabelValue( int row
);
996 wxString
GetColLabelValue( int col
);
997 wxColour
GetGridLineColour() { return m_gridLineColour
; }
999 void SetRowLabelSize( int width
);
1000 void SetColLabelSize( int height
);
1001 void SetLabelBackgroundColour( const wxColour
& );
1002 void SetLabelTextColour( const wxColour
& );
1003 void SetLabelFont( const wxFont
& );
1004 void SetRowLabelAlignment( int horiz
, int vert
);
1005 void SetColLabelAlignment( int horiz
, int vert
);
1006 void SetRowLabelValue( int row
, const wxString
& );
1007 void SetColLabelValue( int col
, const wxString
& );
1008 void SetGridLineColour( const wxColour
& );
1010 void EnableDragRowSize( bool enable
= TRUE
);
1011 void DisableDragRowSize() { EnableDragRowSize( FALSE
); }
1012 bool CanDragRowSize() { return m_canDragRowSize
; }
1013 void EnableDragColSize( bool enable
= TRUE
);
1014 void DisableDragColSize() { EnableDragColSize( FALSE
); }
1015 bool CanDragColSize() { return m_canDragColSize
; }
1017 // this sets the specified attribute for all cells in this row/col
1018 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
1019 void SetColAttr(int col
, wxGridCellAttr
*attr
);
1021 void EnableGridLines( bool enable
= TRUE
);
1022 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
1024 // ------ row and col formatting
1026 int GetDefaultRowSize();
1027 int GetRowSize( int row
);
1028 int GetDefaultColSize();
1029 int GetColSize( int col
);
1030 wxColour
GetDefaultCellBackgroundColour();
1031 wxColour
GetCellBackgroundColour( int row
, int col
);
1032 wxColour
GetDefaultCellTextColour();
1033 wxColour
GetCellTextColour( int row
, int col
);
1034 wxFont
GetDefaultCellFont();
1035 wxFont
GetCellFont( int row
, int col
);
1036 void GetDefaultCellAlignment( int *horiz
, int *vert
);
1037 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
1039 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
1040 void SetRowSize( int row
, int height
);
1041 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
1043 void SetColSize( int col
, int width
);
1045 // automatically size the column to fit to its contents, if setAsMin is
1046 // TRUE, this optimal width will also be set as minimal width for this
1048 void AutoSizeColumn( int col
, bool setAsMin
= TRUE
);
1050 // auto size all columns (very ineffective for big grids!)
1051 void AutoSizeColumns( bool setAsMin
= TRUE
);
1053 // column won't be resized to be lesser width - this must be called during
1054 // the grid creation because it won't resize the column if it's already
1055 // narrower than the minimal width
1056 void SetColMinimalWidth( int col
, int width
);
1058 void SetDefaultCellBackgroundColour( const wxColour
& );
1059 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1060 void SetDefaultCellTextColour( const wxColour
& );
1062 void SetCellTextColour( int row
, int col
, const wxColour
& );
1063 void SetDefaultCellFont( const wxFont
& );
1064 void SetCellFont( int row
, int col
, const wxFont
& );
1065 void SetDefaultCellAlignment( int horiz
, int vert
);
1066 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1068 // takes ownership of the pointer
1069 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1070 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1071 wxGridCellRenderer
*GetDefaultRenderer() const;
1072 wxGridCellRenderer
* GetCellRenderer(int row
, int col
);
1074 // takes ownership of the pointer
1075 void SetDefaultEditor(wxGridCellEditor
*editor
);
1076 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1077 wxGridCellEditor
*GetDefaultEditor() const;
1078 wxGridCellEditor
* GetCellEditor(int row
, int col
);
1082 // ------ cell value accessors
1084 wxString
GetCellValue( int row
, int col
)
1088 return m_table
->GetValue( row
, col
);
1092 return wxEmptyString
;
1096 wxString
GetCellValue( const wxGridCellCoords
& coords
)
1097 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1099 void SetCellValue( int row
, int col
, const wxString
& s
);
1100 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1101 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1103 // returns TRUE if the cell can't be edited
1104 bool IsReadOnly(int row
, int col
) const;
1106 // make the cell editable/readonly
1107 void SetReadOnly(int row
, int col
, bool isReadOnly
= TRUE
);
1109 // ------ selections of blocks of cells
1111 void SelectRow( int row
, bool addToSelected
= FALSE
);
1112 void SelectCol( int col
, bool addToSelected
= FALSE
);
1114 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
1116 void SelectBlock( const wxGridCellCoords
& topLeft
,
1117 const wxGridCellCoords
& bottomRight
)
1118 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1119 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
1124 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
1125 m_selectedBottomRight
!= wxGridNoCellCoords
);
1128 void ClearSelection();
1130 bool IsInSelection( int row
, int col
)
1131 { return ( IsSelection() &&
1132 row
>= m_selectedTopLeft
.GetRow() &&
1133 col
>= m_selectedTopLeft
.GetCol() &&
1134 row
<= m_selectedBottomRight
.GetRow() &&
1135 col
<= m_selectedBottomRight
.GetCol() );
1138 bool IsInSelection( const wxGridCellCoords
& coords
)
1139 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1141 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
1143 // these will all be -1 if there is no selected block
1145 *topRow
= m_selectedTopLeft
.GetRow();
1146 *leftCol
= m_selectedTopLeft
.GetCol();
1147 *bottomRow
= m_selectedBottomRight
.GetRow();
1148 *rightCol
= m_selectedBottomRight
.GetCol();
1152 // This function returns the rectangle that encloses the block of cells
1153 // limited by TopLeft and BottomRight cell in device coords and clipped
1154 // to the client size of the grid window.
1156 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1157 const wxGridCellCoords
& bottomRight
);
1159 // This function returns the rectangle that encloses the selected cells
1160 // in device coords and clipped to the client size of the grid window.
1162 wxRect
SelectionToDeviceRect()
1164 return BlockToDeviceRect( m_selectedTopLeft
,
1165 m_selectedBottomRight
);
1168 // Access or update the selection fore/back colours
1169 wxColour
GetSelectionBackground() const
1170 { return m_selectionBackground
; }
1171 wxColour
GetSelectionForeground() const
1172 { return m_selectionForeground
; }
1174 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1175 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1178 // Methods for a registry for mapping data types to Renderers/Editors
1179 void RegisterDataType(const wxString
& typeName
,
1180 wxGridCellRenderer
* renderer
,
1181 wxGridCellEditor
* editor
);
1182 wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1183 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1184 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1185 wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1186 wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1187 wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1191 // ------ For compatibility with previous wxGrid only...
1193 // ************************************************
1194 // ** Don't use these in new code because they **
1195 // ** are liable to disappear in a future **
1197 // ************************************************
1200 wxGrid( wxWindow
*parent
,
1201 int x
, int y
, int w
= -1, int h
= -1,
1203 const wxString
& name
= wxPanelNameStr
)
1204 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
), style
, name
)
1209 void SetCellValue( const wxString
& val
, int row
, int col
)
1210 { SetCellValue( row
, col
, val
); }
1212 void UpdateDimensions()
1213 { CalcDimensions(); }
1215 int GetRows() { return GetNumberRows(); }
1216 int GetCols() { return GetNumberCols(); }
1217 int GetCursorRow() { return GetGridCursorRow(); }
1218 int GetCursorColumn() { return GetGridCursorCol(); }
1220 int GetScrollPosX() { return 0; }
1221 int GetScrollPosY() { return 0; }
1223 void SetScrollX( int x
) { }
1224 void SetScrollY( int y
) { }
1226 void SetColumnWidth( int col
, int width
)
1227 { SetColSize( col
, width
); }
1229 int GetColumnWidth( int col
)
1230 { return GetColSize( col
); }
1232 void SetRowHeight( int row
, int height
)
1233 { SetRowSize( row
, height
); }
1235 // GetRowHeight() is below
1237 int GetViewHeight() // returned num whole rows visible
1240 int GetViewWidth() // returned num whole cols visible
1243 void SetLabelSize( int orientation
, int sz
)
1245 if ( orientation
== wxHORIZONTAL
)
1246 SetColLabelSize( sz
);
1248 SetRowLabelSize( sz
);
1251 int GetLabelSize( int orientation
)
1253 if ( orientation
== wxHORIZONTAL
)
1254 return GetColLabelSize();
1256 return GetRowLabelSize();
1259 void SetLabelAlignment( int orientation
, int align
)
1261 if ( orientation
== wxHORIZONTAL
)
1262 SetColLabelAlignment( align
, -1 );
1264 SetRowLabelAlignment( align
, -1 );
1267 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
1270 if ( orientation
== wxHORIZONTAL
)
1272 GetColLabelAlignment( &h
, &v
);
1277 GetRowLabelAlignment( &h
, &v
);
1282 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1284 if ( orientation
== wxHORIZONTAL
)
1285 SetColLabelValue( pos
, val
);
1287 SetRowLabelValue( pos
, val
);
1290 wxString
GetLabelValue( int orientation
, int pos
)
1292 if ( orientation
== wxHORIZONTAL
)
1293 return GetColLabelValue( pos
);
1295 return GetRowLabelValue( pos
);
1298 wxFont
GetCellTextFont() const
1299 { return m_defaultCellAttr
->GetFont(); }
1301 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1302 { return m_defaultCellAttr
->GetFont(); }
1304 void SetCellTextFont(const wxFont
& fnt
)
1305 { SetDefaultCellFont( fnt
); }
1307 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1308 { SetCellFont( row
, col
, fnt
); }
1310 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1311 { SetCellTextColour( row
, col
, val
); }
1313 void SetCellTextColour(const wxColour
& col
)
1314 { SetDefaultCellTextColour( col
); }
1316 void SetCellBackgroundColour(const wxColour
& col
)
1317 { SetDefaultCellBackgroundColour( col
); }
1319 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1320 { SetCellBackgroundColour( row
, col
, colour
); }
1322 bool GetEditable() { return IsEditable(); }
1323 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
1324 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
1326 void SetEditInPlace(bool edit
= TRUE
) { }
1328 void SetCellAlignment( int align
, int row
, int col
)
1329 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
1330 void SetCellAlignment( int WXUNUSED(align
) ) {}
1331 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1333 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1334 wxPen
& GetDividerPen() const { return wxNullPen
; }
1335 void OnActivate(bool WXUNUSED(active
)) {}
1337 // ******** End of compatibility functions **********
1341 // ------ control IDs
1342 enum { wxGRID_CELLCTRL
= 2000,
1345 // ------ control types
1346 enum { wxGRID_TEXTCTRL
= 2100,
1355 wxGridWindow
*m_gridWin
;
1356 wxGridRowLabelWindow
*m_rowLabelWin
;
1357 wxGridColLabelWindow
*m_colLabelWin
;
1358 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1360 wxGridTableBase
*m_table
;
1371 wxGridCellCoords m_currentCellCoords
;
1373 wxGridCellCoords m_selectedTopLeft
;
1374 wxGridCellCoords m_selectedBottomRight
;
1375 wxColour m_selectionBackground
;
1376 wxColour m_selectionForeground
;
1378 // NB: *never* access m_row/col arrays directly because they are created
1379 // on demand, *always* use accessor functions instead!
1381 // init the m_rowHeights/Bottoms arrays with default values
1382 void InitRowHeights();
1384 int m_defaultRowHeight
;
1385 wxArrayInt m_rowHeights
;
1386 wxArrayInt m_rowBottoms
;
1388 // init the m_colWidths/Rights arrays
1389 void InitColWidths();
1391 int m_defaultColWidth
;
1392 wxArrayInt m_colWidths
;
1393 wxArrayInt m_colRights
;
1395 // get the col/row coords
1396 int GetColWidth(int col
) const;
1397 int GetColLeft(int col
) const;
1398 int GetColRight(int col
) const;
1400 // this function must be public for compatibility...
1402 int GetRowHeight(int row
) const;
1405 int GetRowTop(int row
) const;
1406 int GetRowBottom(int row
) const;
1408 int m_rowLabelWidth
;
1409 int m_colLabelHeight
;
1411 wxColour m_labelBackgroundColour
;
1412 wxColour m_labelTextColour
;
1415 int m_rowLabelHorizAlign
;
1416 int m_rowLabelVertAlign
;
1417 int m_colLabelHorizAlign
;
1418 int m_colLabelVertAlign
;
1420 bool m_defaultRowLabelValues
;
1421 bool m_defaultColLabelValues
;
1423 wxColour m_gridLineColour
;
1424 bool m_gridLinesEnabled
;
1426 // if a column has a minimal width, it will be the value for it in this
1428 wxHashTable m_colMinWidths
;
1430 // get the minimal width of the given column
1431 int GetColMinimalWidth(int col
) const;
1433 // do we have some place to store attributes in?
1434 bool CanHaveAttributes();
1436 // returns the attribute we may modify in place: a new one if this cell
1437 // doesn't have any yet or the existing one if it does
1439 // DecRef() must be called on the returned pointer, as usual
1440 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1442 // cell attribute cache (currently we only cache 1, may be will do
1443 // more/better later)
1447 wxGridCellAttr
*attr
;
1450 // invalidates the attribute cache
1451 void ClearAttrCache();
1453 // adds an attribute to cache
1454 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
1456 // looks for an attr in cache, returns TRUE if found
1457 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
1459 // looks for the attr in cache, if not found asks the table and caches the
1461 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
1462 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
)
1463 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
1465 // the default cell attr object for cells that don't have their own
1466 wxGridCellAttr
* m_defaultCellAttr
;
1469 wxGridCellCoordsArray m_cellsExposed
;
1470 wxArrayInt m_rowsExposed
;
1471 wxArrayInt m_colsExposed
;
1472 wxArrayInt m_rowLabelsExposed
;
1473 wxArrayInt m_colLabelsExposed
;
1479 wxGridTypeRegistry
* m_typeRegistry
;
1483 WXGRID_CURSOR_SELECT_CELL
,
1484 WXGRID_CURSOR_RESIZE_ROW
,
1485 WXGRID_CURSOR_RESIZE_COL
,
1486 WXGRID_CURSOR_SELECT_ROW
,
1487 WXGRID_CURSOR_SELECT_COL
1490 // this method not only sets m_cursorMode but also sets the correct cursor
1491 // for the given mode and, if captureMouse is not FALSE releases the mouse
1492 // if it was captured and captures it if it must be captured
1494 // for this to work, you should always use it and not set m_cursorMode
1496 void ChangeCursorMode(CursorMode mode
,
1497 wxWindow
*win
= (wxWindow
*)NULL
,
1498 bool captureMouse
= TRUE
);
1500 wxWindow
*m_winCapture
; // the window which captured the mouse
1501 CursorMode m_cursorMode
;
1503 bool m_canDragRowSize
;
1504 bool m_canDragColSize
;
1508 wxPoint m_startDragPos
;
1510 bool m_waitForSlowClick
;
1512 wxGridCellCoords m_selectionStart
;
1514 wxCursor m_rowResizeCursor
;
1515 wxCursor m_colResizeCursor
;
1517 bool m_editable
; // applies to whole grid
1518 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
1523 void CalcDimensions();
1524 void CalcWindowSizes();
1525 bool Redimension( wxGridTableMessage
& );
1528 bool SendEvent( const wxEventType
, int row
, int col
, wxMouseEvent
& );
1529 bool SendEvent( const wxEventType
, int row
, int col
);
1530 bool SendEvent( const wxEventType type
)
1532 return SendEvent(type
,
1533 m_currentCellCoords
.GetRow(),
1534 m_currentCellCoords
.GetCol());
1537 void OnPaint( wxPaintEvent
& );
1538 void OnSize( wxSizeEvent
& );
1539 void OnKeyDown( wxKeyEvent
& );
1540 void OnEraseBackground( wxEraseEvent
& );
1543 void SetCurrentCell( const wxGridCellCoords
& coords
);
1544 void SetCurrentCell( int row
, int col
)
1545 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1548 // ------ functions to get/send data (see also public functions)
1550 bool GetModelValues();
1551 bool SetModelValues();
1554 DECLARE_DYNAMIC_CLASS( wxGrid
)
1555 DECLARE_EVENT_TABLE()
1558 // ----------------------------------------------------------------------------
1559 // Grid event class and event types
1560 // ----------------------------------------------------------------------------
1562 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
1566 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
1567 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1571 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
1572 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
1573 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1575 virtual int GetRow() { return m_row
; }
1576 virtual int GetCol() { return m_col
; }
1577 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1578 bool ControlDown() { return m_control
; }
1579 bool MetaDown() { return m_meta
; }
1580 bool ShiftDown() { return m_shift
; }
1581 bool AltDown() { return m_alt
; }
1593 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
1596 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1600 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1601 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1605 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1606 int rowOrCol
=-1, int x
=-1, int y
=-1,
1607 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1609 int GetRowOrCol() { return m_rowOrCol
; }
1610 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1611 bool ControlDown() { return m_control
; }
1612 bool MetaDown() { return m_meta
; }
1613 bool ShiftDown() { return m_shift
; }
1614 bool AltDown() { return m_alt
; }
1625 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1629 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1632 wxGridRangeSelectEvent()
1635 m_topLeft
= wxGridNoCellCoords
;
1636 m_bottomRight
= wxGridNoCellCoords
;
1643 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1644 const wxGridCellCoords
& topLeft
,
1645 const wxGridCellCoords
& bottomRight
,
1646 bool control
=FALSE
, bool shift
=FALSE
,
1647 bool alt
=FALSE
, bool meta
=FALSE
);
1649 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1650 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1651 int GetTopRow() { return m_topLeft
.GetRow(); }
1652 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1653 int GetLeftCol() { return m_topLeft
.GetCol(); }
1654 int GetRightCol() { return m_bottomRight
.GetCol(); }
1655 bool ControlDown() { return m_control
; }
1656 bool MetaDown() { return m_meta
; }
1657 bool ShiftDown() { return m_shift
; }
1658 bool AltDown() { return m_alt
; }
1661 wxGridCellCoords m_topLeft
;
1662 wxGridCellCoords m_bottomRight
;
1668 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1671 // TODO move to wx/event.h
1672 const wxEventType wxEVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1673 const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1674 const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1675 const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1676 const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1677 const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1678 const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1679 const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1680 const wxEventType wxEVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1681 const wxEventType wxEVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1682 const wxEventType wxEVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1683 const wxEventType wxEVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1684 const wxEventType wxEVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1685 const wxEventType wxEVT_GRID_EDITOR_SHOWN
= wxEVT_FIRST
+ 1593;
1686 const wxEventType wxEVT_GRID_EDITOR_HIDDEN
= wxEVT_FIRST
+ 1594;
1689 typedef void (wxEvtHandler
::*wxGridEventFunction
)(wxGridEvent
&);
1690 typedef void (wxEvtHandler
::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1691 typedef void (wxEvtHandler
::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1693 #define EVT_GRID_CELL_LEFT_CLICK(fn) { wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1694 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1695 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1696 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1697 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1698 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1699 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1700 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1701 #define EVT_GRID_ROW_SIZE(fn) { wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1702 #define EVT_GRID_COL_SIZE(fn) { wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1703 #define EVT_GRID_RANGE_SELECT(fn) { wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1704 #define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1705 #define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1706 #define EVT_GRID_EDITOR_SHOWN(fn) { wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1707 #define EVT_GRID_EDITOR_HIDDEN(fn) { wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1710 #if 0 // TODO: implement these ? others ?
1712 const wxEventType wxEVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1713 const wxEventType wxEVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1714 const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1716 #define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1717 #define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1718 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1722 #endif // #ifndef __WXGRID_H__
1724 #endif // ifndef wxUSE_NEW_GRID