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 // virtual dtor for any base class
109 virtual ~wxGridCellRenderer();
112 // the default renderer for the cells containing string data
113 class WXDLLEXPORT wxGridCellStringRenderer
: public wxGridCellRenderer
117 virtual void Draw(wxGrid
& grid
,
118 wxGridCellAttr
& attr
,
125 // set the text colours before drawing
126 void SetTextColoursAndFont(wxGrid
& grid
,
127 wxGridCellAttr
& attr
,
132 // the default renderer for the cells containing numeric (long) data
133 class WXDLLEXPORT wxGridCellNumberRenderer
: public wxGridCellStringRenderer
136 // draw the string right aligned
137 virtual void Draw(wxGrid
& grid
,
138 wxGridCellAttr
& attr
,
145 class WXDLLEXPORT wxGridCellFloatRenderer
: public wxGridCellStringRenderer
148 wxGridCellFloatRenderer(int width
, int precision
);
150 // get/change formatting parameters
151 int GetWidth() const { return m_width
; }
152 void SetWidth(int width
) { m_width
= width
; }
153 int GetPrecision() const { return m_precision
; }
154 void SetPrecision(int precision
) { m_precision
= precision
; }
156 // draw the string right aligned with given width/precision
157 virtual void Draw(wxGrid
& grid
,
158 wxGridCellAttr
& attr
,
165 // formatting parameters
172 // renderer for boolean fields
173 class WXDLLEXPORT wxGridCellBoolRenderer
: public wxGridCellRenderer
176 // draw a check mark or nothing
177 virtual void Draw(wxGrid
& grid
,
178 wxGridCellAttr
& attr
,
185 // ----------------------------------------------------------------------------
186 // wxGridCellEditor: This class is responsible for providing and manipulating
187 // the in-place edit controls for the grid. Instances of wxGridCellEditor
188 // (actually, instances of derived classes since it is an ABC) can be
189 // associated with the cell attributes for individual cells, rows, columns, or
190 // even for the entire grid.
191 // ----------------------------------------------------------------------------
193 class WXDLLEXPORT wxGridCellEditor
197 virtual ~wxGridCellEditor();
199 bool IsCreated() { return m_control
!= NULL
; }
201 // Creates the actual edit control
202 virtual void Create(wxWindow
* parent
,
204 wxEvtHandler
* evtHandler
) = 0;
206 // Size and position the edit control
207 virtual void SetSize(const wxRect
& rect
);
209 // Show or hide the edit control, use the specified attributes to set
210 // colours/fonts for it
211 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
213 // Draws the part of the cell not occupied by the control: the base class
214 // version just fills it with background colour from the attribute
215 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
217 // Fetch the value from the table and prepare the edit control
218 // to begin editing. Set the focus to the edit control.
219 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
221 // Complete the editing of the current cell. If saveValue is
222 // true then send the new value back to the table. Returns true
223 // if the value has changed. If necessary, the control may be
225 virtual bool EndEdit(int row
, int col
, bool saveValue
, wxGrid
* grid
) = 0;
227 // Reset the value in the control back to its starting value
228 virtual void Reset() = 0;
230 // If the editor is enabled by pressing keys on the grid,
231 // this will be called to let the editor do something about
232 // that first key if desired.
233 virtual void StartingKey(wxKeyEvent
& event
);
235 // if the editor is enabled by clicking on the cell, this method will be
237 virtual void StartingClick();
239 // Some types of controls on some platforms may need some help
240 // with the Return key.
241 virtual void HandleReturn(wxKeyEvent
& event
);
244 virtual void Destroy();
247 // the control we show on screen
248 wxControl
* m_control
;
250 // if we change the colours/font of the control from the default ones, we
251 // must restore the default later and we save them here between calls to
252 // Show(TRUE) and Show(FALSE)
258 // the editor for string/text data
259 class WXDLLEXPORT wxGridCellTextEditor
: public wxGridCellEditor
262 wxGridCellTextEditor();
264 virtual void Create(wxWindow
* parent
,
266 wxEvtHandler
* evtHandler
);
267 virtual void SetSize(const wxRect
& rect
);
269 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
271 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
272 virtual bool EndEdit(int row
, int col
, bool saveValue
, wxGrid
* grid
);
274 virtual void Reset();
275 virtual void StartingKey(wxKeyEvent
& event
);
276 virtual void HandleReturn(wxKeyEvent
& event
);
279 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
281 // parts of our virtual functions reused by the derived classes
282 void DoBeginEdit(const wxString
& startValue
);
283 void DoReset(const wxString
& startValue
);
286 wxString m_startValue
;
289 // the editor for numeric (long) data
290 class WXDLLEXPORT wxGridCellNumberEditor
: public wxGridCellTextEditor
293 // allows to specify the range - if min == max == -1, no range checking is
295 wxGridCellNumberEditor(int min
= -1, int max
= -1);
297 virtual void Create(wxWindow
* parent
,
299 wxEvtHandler
* evtHandler
);
301 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
302 virtual bool EndEdit(int row
, int col
, bool saveValue
, wxGrid
* grid
);
304 virtual void Reset();
305 virtual void StartingKey(wxKeyEvent
& event
);
308 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
310 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
311 bool HasRange() const { return m_min
!= m_max
; }
313 // string representation of m_valueOld
314 wxString
GetString() const
315 { return wxString::Format(_T("%ld"), m_valueOld
); }
324 // the editor for floating point numbers (double) data
325 class WXDLLEXPORT wxGridCellFloatEditor
: public wxGridCellTextEditor
328 virtual void Create(wxWindow
* parent
,
330 wxEvtHandler
* evtHandler
);
332 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
333 virtual bool EndEdit(int row
, int col
, bool saveValue
, wxGrid
* grid
);
335 virtual void Reset();
336 virtual void StartingKey(wxKeyEvent
& event
);
339 // string representation of m_valueOld
340 wxString
GetString() const
341 { return wxString::Format(_T("%f"), m_valueOld
); }
347 // the editor for boolean data
348 class WXDLLEXPORT wxGridCellBoolEditor
: public wxGridCellEditor
351 virtual void Create(wxWindow
* parent
,
353 wxEvtHandler
* evtHandler
);
355 virtual void SetSize(const wxRect
& rect
);
356 virtual void Show(bool show
, wxGridCellAttr
*attr
= (wxGridCellAttr
*)NULL
);
358 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
359 virtual bool EndEdit(int row
, int col
, bool saveValue
, wxGrid
* grid
);
361 virtual void Reset();
362 virtual void StartingClick();
365 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
371 // ----------------------------------------------------------------------------
372 // wxGridCellAttr: this class can be used to alter the cells appearance in
373 // the grid by changing their colour/font/... from default. An object of this
374 // class may be returned by wxGridTable::GetAttr().
375 // ----------------------------------------------------------------------------
377 class WXDLLEXPORT wxGridCellAttr
387 // VZ: considering the number of members wxGridCellAttr has now, this ctor
388 // seems to be pretty useless... may be we should just remove it?
389 wxGridCellAttr(const wxColour
& colText
,
390 const wxColour
& colBack
,
394 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
397 SetAlignment(hAlign
, vAlign
);
400 // default copy ctor ok
402 // this class is ref counted: it is created with ref count of 1, so
403 // calling DecRef() once will delete it. Calling IncRef() allows to lock
404 // it until the matching DecRef() is called
405 void IncRef() { m_nRef
++; }
406 void DecRef() { if ( !--m_nRef
) delete this; }
407 void SafeIncRef() { if ( this ) IncRef(); }
408 void SafeDecRef() { if ( this ) DecRef(); }
411 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
412 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
413 void SetFont(const wxFont
& font
) { m_font
= font
; }
414 void SetAlignment(int hAlign
, int vAlign
)
419 void SetReadOnly(bool isReadOnly
= TRUE
) { m_isReadOnly
= isReadOnly
; }
421 // takes ownership of the pointer
422 void SetRenderer(wxGridCellRenderer
*renderer
)
423 { delete m_renderer
; m_renderer
= renderer
; }
424 void SetEditor(wxGridCellEditor
* editor
)
425 { delete m_editor
; m_editor
= editor
; }
428 bool HasTextColour() const { return m_colText
.Ok(); }
429 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
430 bool HasFont() const { return m_font
.Ok(); }
431 bool HasAlignment() const { return m_hAlign
|| m_vAlign
; }
432 bool HasRenderer() const { return m_renderer
!= NULL
; }
433 bool HasEditor() const { return m_editor
!= NULL
; }
435 const wxColour
& GetTextColour() const;
436 const wxColour
& GetBackgroundColour() const;
437 const wxFont
& GetFont() const;
438 void GetAlignment(int *hAlign
, int *vAlign
) const;
439 wxGridCellRenderer
*GetRenderer(wxGridCellRenderer
* def
) const;
440 wxGridCellEditor
*GetEditor(wxGridCellEditor
* def
) const;
442 bool IsReadOnly() const { return m_isReadOnly
; }
444 void SetDefAttr(wxGridCellAttr
* defAttr
) { m_defGridAttr
= defAttr
; }
447 // the common part of all ctors
452 m_isReadOnly
= FALSE
;
458 // the dtor is private because only DecRef() can delete us
459 ~wxGridCellAttr() { delete m_renderer
; delete m_editor
; }
461 // the ref count - when it goes to 0, we die
470 wxGridCellRenderer
* m_renderer
;
471 wxGridCellEditor
* m_editor
;
472 wxGridCellAttr
* m_defGridAttr
;
476 // suppress the stupid gcc warning about the class having private dtor and
478 friend class wxGridCellAttrDummyFriend
;
481 // ----------------------------------------------------------------------------
482 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
484 // ----------------------------------------------------------------------------
486 // implementation note: we separate it from wxGridTableBase because we wish to
487 // avoid deriving a new table class if possible, and sometimes it will be
488 // enough to just derive another wxGridCellAttrProvider instead
490 // the default implementation is reasonably efficient for the generic case,
491 // but you might still wish to implement your own for some specific situations
492 // if you have performance problems with the stock one
493 class WXDLLEXPORT wxGridCellAttrProvider
496 wxGridCellAttrProvider();
497 virtual ~wxGridCellAttrProvider();
499 // DecRef() must be called on the returned pointer
500 virtual wxGridCellAttr
*GetAttr(int row
, int col
) const;
502 // all these functions take ownership of the pointer, don't call DecRef()
504 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
505 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
506 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
508 // these functions must be called whenever some rows/cols are deleted
509 // because the internal data must be updated then
510 void UpdateAttrRows( size_t pos
, int numRows
);
511 void UpdateAttrCols( size_t pos
, int numCols
);
516 wxGridCellAttrProviderData
*m_data
;
519 //////////////////////////////////////////////////////////////////////
521 // Grid table classes
523 //////////////////////////////////////////////////////////////////////
526 class WXDLLEXPORT wxGridTableBase
: public wxObject
530 virtual ~wxGridTableBase();
532 // You must override these functions in a derived table class
534 virtual long GetNumberRows() = 0;
535 virtual long GetNumberCols() = 0;
536 virtual bool IsEmptyCell( int row
, int col
) = 0;
537 virtual wxString
GetValue( int row
, int col
) = 0;
538 virtual void SetValue( int row
, int col
, const wxString
& value
) = 0;
540 // Data type determination and value access
541 virtual wxString
GetTypeName( int row
, int col
);
542 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
543 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
545 virtual long GetValueAsLong( int row
, int col
);
546 virtual double GetValueAsDouble( int row
, int col
);
547 virtual bool GetValueAsBool( int row
, int col
);
549 virtual void SetValueAsLong( int row
, int col
, long value
);
550 virtual void SetValueAsDouble( int row
, int col
, double value
);
551 virtual void SetValueAsBool( int row
, int col
, bool value
);
553 // For user defined types
554 virtual void* GetValueAsCustom( int row
, int col
, const wxString
& typeName
);
555 virtual void SetValueAsCustom( int row
, int col
, const wxString
& typeName
, void* value
);
558 // Overriding these is optional
560 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
561 virtual wxGrid
* GetView() const { return m_view
; }
563 virtual void Clear() {}
564 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
565 virtual bool AppendRows( size_t numRows
= 1 );
566 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
567 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
568 virtual bool AppendCols( size_t numCols
= 1 );
569 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
571 virtual wxString
GetRowLabelValue( int row
);
572 virtual wxString
GetColLabelValue( int col
);
573 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
574 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
576 // Attribute handling
579 // give us the attr provider to use - we take ownership of the pointer
580 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
582 // get the currently used attr provider (may be NULL)
583 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
585 // Does this table allow attributes? Default implementation creates
586 // a wxGridCellAttrProvider if necessary.
587 virtual bool CanHaveAttributes();
590 // change row/col number in attribute if needed
591 virtual void UpdateAttrRows( size_t pos
, int numRows
);
592 virtual void UpdateAttrCols( size_t pos
, int numCols
);
594 // by default forwarded to wxGridCellAttrProvider if any. May be
595 // overridden to handle attributes directly in the table.
596 virtual wxGridCellAttr
*GetAttr( int row
, int col
);
598 // these functions take ownership of the pointer
599 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
600 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
601 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
605 wxGridCellAttrProvider
*m_attrProvider
;
607 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
611 // ----------------------------------------------------------------------------
612 // wxGridTableMessage
613 // ----------------------------------------------------------------------------
615 // IDs for messages sent from grid table to view
617 enum wxGridTableRequest
619 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
620 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
621 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
622 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
623 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
624 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
625 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
626 wxGRIDTABLE_NOTIFY_COLS_DELETED
629 class WXDLLEXPORT wxGridTableMessage
632 wxGridTableMessage();
633 wxGridTableMessage( wxGridTableBase
*table
, int id
,
637 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
638 wxGridTableBase
* GetTableObject() const { return m_table
; }
639 void SetId( int id
) { m_id
= id
; }
640 int GetId() { return m_id
; }
641 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
642 int GetCommandInt() { return m_comInt1
; }
643 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
644 int GetCommandInt2() { return m_comInt2
; }
647 wxGridTableBase
*m_table
;
655 // ------ wxGridStringArray
656 // A 2-dimensional array of strings for data values
659 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
663 // ------ wxGridStringTable
665 // Simplest type of data table for a grid for small tables of strings
666 // that are stored in memory
669 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
673 wxGridStringTable( int numRows
, int numCols
);
674 ~wxGridStringTable();
676 // these are pure virtual in wxGridTableBase
678 long GetNumberRows();
679 long GetNumberCols();
680 wxString
GetValue( int row
, int col
);
681 void SetValue( int row
, int col
, const wxString
& s
);
682 bool IsEmptyCell( int row
, int col
);
684 // overridden functions from wxGridTableBase
687 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
688 bool AppendRows( size_t numRows
= 1 );
689 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
690 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
691 bool AppendCols( size_t numCols
= 1 );
692 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
694 void SetRowLabelValue( int row
, const wxString
& );
695 void SetColLabelValue( int col
, const wxString
& );
696 wxString
GetRowLabelValue( int row
);
697 wxString
GetColLabelValue( int col
);
700 wxGridStringArray m_data
;
702 // These only get used if you set your own labels, otherwise the
703 // GetRow/ColLabelValue functions return wxGridTableBase defaults
705 wxArrayString m_rowLabels
;
706 wxArrayString m_colLabels
;
708 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
713 // ============================================================================
715 // ============================================================================
717 // ----------------------------------------------------------------------------
718 // wxGridCellCoords: location of a cell in the grid
719 // ----------------------------------------------------------------------------
721 class WXDLLEXPORT wxGridCellCoords
724 wxGridCellCoords() { m_row
= m_col
= -1; }
725 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
727 // default copy ctor is ok
729 long GetRow() const { return m_row
; }
730 void SetRow( long n
) { m_row
= n
; }
731 long GetCol() const { return m_col
; }
732 void SetCol( long n
) { m_col
= n
; }
733 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
735 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
737 if ( &other
!= this )
745 bool operator==( const wxGridCellCoords
& other
) const
747 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
750 bool operator!=( const wxGridCellCoords
& other
) const
752 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
755 bool operator!() const
757 return (m_row
== -1 && m_col
== -1 );
766 // For comparisons...
768 extern wxGridCellCoords wxGridNoCellCoords
;
769 extern wxRect wxGridNoCellRect
;
771 // An array of cell coords...
773 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
775 // ----------------------------------------------------------------------------
777 // ----------------------------------------------------------------------------
779 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
787 wxGrid( wxWindow
*parent
,
789 const wxPoint
& pos
= wxDefaultPosition
,
790 const wxSize
& size
= wxDefaultSize
,
792 const wxString
& name
= wxPanelNameStr
);
796 bool CreateGrid( int numRows
, int numCols
);
799 // ------ grid dimensions
801 int GetNumberRows() { return m_numRows
; }
802 int GetNumberCols() { return m_numCols
; }
805 // ------ display update functions
807 void CalcRowLabelsExposed( wxRegion
& reg
);
809 void CalcColLabelsExposed( wxRegion
& reg
);
810 void CalcCellsExposed( wxRegion
& reg
);
813 // ------ event handlers
815 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
816 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
817 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
818 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
819 bool ProcessTableMessage( wxGridTableMessage
& );
821 void DoEndDragResizeRow();
822 void DoEndDragResizeCol();
824 wxGridTableBase
* GetTable() const { return m_table
; }
825 bool SetTable( wxGridTableBase
*table
, bool takeOwnership
=FALSE
);
828 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
829 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
830 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
831 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
832 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
833 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
835 void DrawGridCellArea( wxDC
& dc
);
836 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
837 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
838 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
839 void DrawHighlight(wxDC
& dc
);
841 // this function is called when the current cell highlight must be redrawn
842 // and may be overridden by the user
843 virtual void DrawCellHighlight( wxDC
& dc
, const wxGridCellAttr
*attr
);
845 void DrawRowLabels( wxDC
& dc
);
846 void DrawRowLabel( wxDC
& dc
, int row
);
848 void DrawColLabels( wxDC
& dc
);
849 void DrawColLabel( wxDC
& dc
, int col
);
852 // ------ Cell text drawing functions
854 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
855 int horizontalAlignment
= wxLEFT
,
856 int verticalAlignment
= wxTOP
);
858 // Split a string containing newline chararcters into an array of
859 // strings and return the number of lines
861 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
863 void GetTextBoxSize( wxDC
& dc
,
864 wxArrayString
& lines
,
865 long *width
, long *height
);
869 // Code that does a lot of grid modification can be enclosed
870 // between BeginBatch() and EndBatch() calls to avoid screen
873 void BeginBatch() { m_batchCount
++; }
874 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
875 int GetBatchCount() { return m_batchCount
; }
878 // ------ edit control functions
880 bool IsEditable() { return m_editable
; }
881 void EnableEditing( bool edit
);
883 void EnableCellEditControl( bool enable
= TRUE
);
884 void DisableCellEditControl() { EnableCellEditControl(FALSE
); }
885 bool CanEnableCellControl() const;
886 bool IsCellEditControlEnabled() const;
888 bool IsCurrentCellReadOnly() const;
890 void ShowCellEditControl();
891 void HideCellEditControl();
892 void SetEditControlValue( const wxString
& s
= wxEmptyString
);
893 void SaveEditControlValue();
896 // ------ grid location functions
897 // Note that all of these functions work with the logical coordinates of
898 // grid cells and labels so you will need to convert from device
899 // coordinates for mouse events etc.
901 void XYToCell( int x
, int y
, wxGridCellCoords
& );
905 int YToEdgeOfRow( int y
);
906 int XToEdgeOfCol( int x
);
908 wxRect
CellToRect( int row
, int col
);
909 wxRect
CellToRect( const wxGridCellCoords
& coords
)
910 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
912 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
913 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
915 // check to see if a cell is either wholly visible (the default arg) or
916 // at least partially visible in the grid window
918 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
919 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
920 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
921 void MakeCellVisible( int row
, int col
);
922 void MakeCellVisible( const wxGridCellCoords
& coords
)
923 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
926 // ------ grid cursor movement functions
928 void SetGridCursor( int row
, int col
)
929 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
932 bool MoveCursorDown();
933 bool MoveCursorLeft();
934 bool MoveCursorRight();
937 bool MoveCursorUpBlock();
938 bool MoveCursorDownBlock();
939 bool MoveCursorLeftBlock();
940 bool MoveCursorRightBlock();
943 // ------ label and gridline formatting
945 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
946 int GetRowLabelSize() { return m_rowLabelWidth
; }
947 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
948 int GetColLabelSize() { return m_colLabelHeight
; }
949 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
950 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
951 wxFont
GetLabelFont() { return m_labelFont
; }
952 void GetRowLabelAlignment( int *horiz
, int *vert
);
953 void GetColLabelAlignment( int *horiz
, int *vert
);
954 wxString
GetRowLabelValue( int row
);
955 wxString
GetColLabelValue( int col
);
956 wxColour
GetGridLineColour() { return m_gridLineColour
; }
958 void SetRowLabelSize( int width
);
959 void SetColLabelSize( int height
);
960 void SetLabelBackgroundColour( const wxColour
& );
961 void SetLabelTextColour( const wxColour
& );
962 void SetLabelFont( const wxFont
& );
963 void SetRowLabelAlignment( int horiz
, int vert
);
964 void SetColLabelAlignment( int horiz
, int vert
);
965 void SetRowLabelValue( int row
, const wxString
& );
966 void SetColLabelValue( int col
, const wxString
& );
967 void SetGridLineColour( const wxColour
& );
969 void EnableDragRowSize( bool enable
= TRUE
);
970 void DisableDragRowSize() { EnableDragRowSize( FALSE
); }
971 bool CanDragRowSize() { return m_canDragRowSize
; }
972 void EnableDragColSize( bool enable
= TRUE
);
973 void DisableDragColSize() { EnableDragColSize( FALSE
); }
974 bool CanDragColSize() { return m_canDragColSize
; }
976 // this sets the specified attribute for all cells in this row/col
977 void SetRowAttr(int row
, wxGridCellAttr
*attr
);
978 void SetColAttr(int col
, wxGridCellAttr
*attr
);
980 void EnableGridLines( bool enable
= TRUE
);
981 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
983 // ------ row and col formatting
985 int GetDefaultRowSize();
986 int GetRowSize( int row
);
987 int GetDefaultColSize();
988 int GetColSize( int col
);
989 wxColour
GetDefaultCellBackgroundColour();
990 wxColour
GetCellBackgroundColour( int row
, int col
);
991 wxColour
GetDefaultCellTextColour();
992 wxColour
GetCellTextColour( int row
, int col
);
993 wxFont
GetDefaultCellFont();
994 wxFont
GetCellFont( int row
, int col
);
995 void GetDefaultCellAlignment( int *horiz
, int *vert
);
996 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
998 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
999 void SetRowSize( int row
, int height
);
1000 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
1002 void SetColSize( int col
, int width
);
1004 // column won't be resized to be lesser width - this must be called during
1005 // the grid creation because it won't resize the column if it's already
1006 // narrower than the minimal width
1007 void SetColMinimalWidth( int col
, int width
);
1009 void SetDefaultCellBackgroundColour( const wxColour
& );
1010 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
1011 void SetDefaultCellTextColour( const wxColour
& );
1013 void SetCellTextColour( int row
, int col
, const wxColour
& );
1014 void SetDefaultCellFont( const wxFont
& );
1015 void SetCellFont( int row
, int col
, const wxFont
& );
1016 void SetDefaultCellAlignment( int horiz
, int vert
);
1017 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
1019 // takes ownership of the pointer
1020 void SetDefaultRenderer(wxGridCellRenderer
*renderer
);
1021 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
*renderer
);
1022 wxGridCellRenderer
*GetDefaultRenderer() const;
1023 wxGridCellRenderer
* GetCellRenderer(int row
, int col
);
1025 // takes ownership of the pointer
1026 void SetDefaultEditor(wxGridCellEditor
*editor
);
1027 void SetCellEditor(int row
, int col
, wxGridCellEditor
*editor
);
1028 wxGridCellEditor
*GetDefaultEditor() const;
1029 wxGridCellEditor
* GetCellEditor(int row
, int col
);
1033 // ------ cell value accessors
1035 wxString
GetCellValue( int row
, int col
)
1039 return m_table
->GetValue( row
, col
);
1043 return wxEmptyString
;
1047 wxString
GetCellValue( const wxGridCellCoords
& coords
)
1048 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
1050 void SetCellValue( int row
, int col
, const wxString
& s
);
1051 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
1052 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
1054 // returns TRUE if the cell can't be edited
1055 bool IsReadOnly(int row
, int col
) const;
1057 // make the cell editable/readonly
1058 void SetReadOnly(int row
, int col
, bool isReadOnly
= TRUE
);
1060 // ------ selections of blocks of cells
1062 void SelectRow( int row
, bool addToSelected
= FALSE
);
1063 void SelectCol( int col
, bool addToSelected
= FALSE
);
1065 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
1067 void SelectBlock( const wxGridCellCoords
& topLeft
,
1068 const wxGridCellCoords
& bottomRight
)
1069 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
1070 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
1075 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
1076 m_selectedBottomRight
!= wxGridNoCellCoords
);
1079 void ClearSelection();
1081 bool IsInSelection( int row
, int col
)
1082 { return ( IsSelection() &&
1083 row
>= m_selectedTopLeft
.GetRow() &&
1084 col
>= m_selectedTopLeft
.GetCol() &&
1085 row
<= m_selectedBottomRight
.GetRow() &&
1086 col
<= m_selectedBottomRight
.GetCol() );
1089 bool IsInSelection( const wxGridCellCoords
& coords
)
1090 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
1092 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
1094 // these will all be -1 if there is no selected block
1096 *topRow
= m_selectedTopLeft
.GetRow();
1097 *leftCol
= m_selectedTopLeft
.GetCol();
1098 *bottomRow
= m_selectedBottomRight
.GetRow();
1099 *rightCol
= m_selectedBottomRight
.GetCol();
1103 // This function returns the rectangle that encloses the block of cells
1104 // limited by TopLeft and BottomRight cell in device coords and clipped
1105 // to the client size of the grid window.
1107 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
1108 const wxGridCellCoords
& bottomRight
);
1110 // This function returns the rectangle that encloses the selected cells
1111 // in device coords and clipped to the client size of the grid window.
1113 wxRect
SelectionToDeviceRect()
1115 return BlockToDeviceRect( m_selectedTopLeft
,
1116 m_selectedBottomRight
);
1119 // Access or update the selection fore/back colours
1120 wxColour
GetSelectionBackground() const
1121 { return m_selectionBackground
; }
1122 wxColour
GetSelectionForeground() const
1123 { return m_selectionForeground
; }
1125 void SetSelectionBackground(const wxColour
& c
) { m_selectionBackground
= c
; }
1126 void SetSelectionForeground(const wxColour
& c
) { m_selectionForeground
= c
; }
1129 // Methods for a registry for mapping data types to Renderers/Editors
1130 void RegisterDataType(const wxString
& typeName
,
1131 wxGridCellRenderer
* renderer
,
1132 wxGridCellEditor
* editor
);
1133 wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
1134 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const
1135 { return GetDefaultEditorForCell(c
.GetRow(), c
.GetCol()); }
1136 wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
1137 wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
1138 wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
1142 // ------ For compatibility with previous wxGrid only...
1144 // ************************************************
1145 // ** Don't use these in new code because they **
1146 // ** are liable to disappear in a future **
1148 // ************************************************
1151 wxGrid( wxWindow
*parent
,
1152 int x
, int y
, int w
= -1, int h
= -1,
1154 const wxString
& name
= wxPanelNameStr
)
1155 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
), style
, name
)
1160 void SetCellValue( const wxString
& val
, int row
, int col
)
1161 { SetCellValue( row
, col
, val
); }
1163 void UpdateDimensions()
1164 { CalcDimensions(); }
1166 int GetRows() { return GetNumberRows(); }
1167 int GetCols() { return GetNumberCols(); }
1168 int GetCursorRow() { return GetGridCursorRow(); }
1169 int GetCursorColumn() { return GetGridCursorCol(); }
1171 int GetScrollPosX() { return 0; }
1172 int GetScrollPosY() { return 0; }
1174 void SetScrollX( int x
) { }
1175 void SetScrollY( int y
) { }
1177 void SetColumnWidth( int col
, int width
)
1178 { SetColSize( col
, width
); }
1180 int GetColumnWidth( int col
)
1181 { return GetColSize( col
); }
1183 void SetRowHeight( int row
, int height
)
1184 { SetRowSize( row
, height
); }
1186 // GetRowHeight() is below
1188 int GetViewHeight() // returned num whole rows visible
1191 int GetViewWidth() // returned num whole cols visible
1194 void SetLabelSize( int orientation
, int sz
)
1196 if ( orientation
== wxHORIZONTAL
)
1197 SetColLabelSize( sz
);
1199 SetRowLabelSize( sz
);
1202 int GetLabelSize( int orientation
)
1204 if ( orientation
== wxHORIZONTAL
)
1205 return GetColLabelSize();
1207 return GetRowLabelSize();
1210 void SetLabelAlignment( int orientation
, int align
)
1212 if ( orientation
== wxHORIZONTAL
)
1213 SetColLabelAlignment( align
, -1 );
1215 SetRowLabelAlignment( align
, -1 );
1218 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
1221 if ( orientation
== wxHORIZONTAL
)
1223 GetColLabelAlignment( &h
, &v
);
1228 GetRowLabelAlignment( &h
, &v
);
1233 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
1235 if ( orientation
== wxHORIZONTAL
)
1236 SetColLabelValue( pos
, val
);
1238 SetRowLabelValue( pos
, val
);
1241 wxString
GetLabelValue( int orientation
, int pos
)
1243 if ( orientation
== wxHORIZONTAL
)
1244 return GetColLabelValue( pos
);
1246 return GetRowLabelValue( pos
);
1249 wxFont
GetCellTextFont() const
1250 { return m_defaultCellAttr
->GetFont(); }
1252 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
1253 { return m_defaultCellAttr
->GetFont(); }
1255 void SetCellTextFont(const wxFont
& fnt
)
1256 { SetDefaultCellFont( fnt
); }
1258 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
1259 { SetCellFont( row
, col
, fnt
); }
1261 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
1262 { SetCellTextColour( row
, col
, val
); }
1264 void SetCellTextColour(const wxColour
& col
)
1265 { SetDefaultCellTextColour( col
); }
1267 void SetCellBackgroundColour(const wxColour
& col
)
1268 { SetDefaultCellBackgroundColour( col
); }
1270 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
1271 { SetCellBackgroundColour( row
, col
, colour
); }
1273 bool GetEditable() { return IsEditable(); }
1274 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
1275 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
1277 void SetEditInPlace(bool edit
= TRUE
) { }
1279 void SetCellAlignment( int align
, int row
, int col
)
1280 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
1281 void SetCellAlignment( int WXUNUSED(align
) ) {}
1282 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
1284 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
1285 wxPen
& GetDividerPen() const { return wxNullPen
; }
1286 void OnActivate(bool WXUNUSED(active
)) {}
1288 // ******** End of compatibility functions **********
1292 // ------ control IDs
1293 enum { wxGRID_CELLCTRL
= 2000,
1296 // ------ control types
1297 enum { wxGRID_TEXTCTRL
= 2100,
1306 wxGridWindow
*m_gridWin
;
1307 wxGridRowLabelWindow
*m_rowLabelWin
;
1308 wxGridColLabelWindow
*m_colLabelWin
;
1309 wxGridCornerLabelWindow
*m_cornerLabelWin
;
1311 wxGridTableBase
*m_table
;
1322 wxGridCellCoords m_currentCellCoords
;
1324 wxGridCellCoords m_selectedTopLeft
;
1325 wxGridCellCoords m_selectedBottomRight
;
1326 wxColour m_selectionBackground
;
1327 wxColour m_selectionForeground
;
1329 // NB: *never* access m_row/col arrays directly because they are created
1330 // on demand, *always* use accessor functions instead!
1332 // init the m_rowHeights/Bottoms arrays with default values
1333 void InitRowHeights();
1335 int m_defaultRowHeight
;
1336 wxArrayInt m_rowHeights
;
1337 wxArrayInt m_rowBottoms
;
1339 // init the m_colWidths/Rights arrays
1340 void InitColWidths();
1342 int m_defaultColWidth
;
1343 wxArrayInt m_colWidths
;
1344 wxArrayInt m_colRights
;
1346 // get the col/row coords
1347 int GetColWidth(int col
) const;
1348 int GetColLeft(int col
) const;
1349 int GetColRight(int col
) const;
1351 // this function must be public for compatibility...
1353 int GetRowHeight(int row
) const;
1356 int GetRowTop(int row
) const;
1357 int GetRowBottom(int row
) const;
1359 int m_rowLabelWidth
;
1360 int m_colLabelHeight
;
1362 wxColour m_labelBackgroundColour
;
1363 wxColour m_labelTextColour
;
1366 int m_rowLabelHorizAlign
;
1367 int m_rowLabelVertAlign
;
1368 int m_colLabelHorizAlign
;
1369 int m_colLabelVertAlign
;
1371 bool m_defaultRowLabelValues
;
1372 bool m_defaultColLabelValues
;
1374 wxColour m_gridLineColour
;
1375 bool m_gridLinesEnabled
;
1377 // if a column has a minimal width, it will be the value for it in this
1379 wxHashTable m_colMinWidths
;
1381 // get the minimal width of the given column
1382 int GetColMinimalWidth(int col
) const;
1384 // do we have some place to store attributes in?
1385 bool CanHaveAttributes();
1387 // returns the attribute we may modify in place: a new one if this cell
1388 // doesn't have any yet or the existing one if it does
1390 // DecRef() must be called on the returned pointer, as usual
1391 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
1393 // cell attribute cache (currently we only cache 1, may be will do
1394 // more/better later)
1398 wxGridCellAttr
*attr
;
1401 // invalidates the attribute cache
1402 void ClearAttrCache();
1404 // adds an attribute to cache
1405 void CacheAttr(int row
, int col
, wxGridCellAttr
*attr
) const;
1407 // looks for an attr in cache, returns TRUE if found
1408 bool LookupAttr(int row
, int col
, wxGridCellAttr
**attr
) const;
1410 // looks for the attr in cache, if not found asks the table and caches the
1412 wxGridCellAttr
*GetCellAttr(int row
, int col
) const;
1413 wxGridCellAttr
*GetCellAttr(const wxGridCellCoords
& coords
)
1414 { return GetCellAttr( coords
.GetRow(), coords
.GetCol() ); }
1416 // the default cell attr object for cells that don't have their own
1417 wxGridCellAttr
* m_defaultCellAttr
;
1420 wxGridCellCoordsArray m_cellsExposed
;
1421 wxArrayInt m_rowsExposed
;
1422 wxArrayInt m_colsExposed
;
1423 wxArrayInt m_rowLabelsExposed
;
1424 wxArrayInt m_colLabelsExposed
;
1430 wxGridTypeRegistry
* m_typeRegistry
;
1434 WXGRID_CURSOR_SELECT_CELL
,
1435 WXGRID_CURSOR_RESIZE_ROW
,
1436 WXGRID_CURSOR_RESIZE_COL
,
1437 WXGRID_CURSOR_SELECT_ROW
,
1438 WXGRID_CURSOR_SELECT_COL
1441 // this method not only sets m_cursorMode but also sets the correct cursor
1442 // for the given mode and, if captureMouse is not FALSE releases the mouse
1443 // if it was captured and captures it if it must be captured
1445 // for this to work, you should always use it and not set m_cursorMode
1447 void ChangeCursorMode(CursorMode mode
,
1448 wxWindow
*win
= (wxWindow
*)NULL
,
1449 bool captureMouse
= TRUE
);
1451 wxWindow
*m_winCapture
; // the window which captured the mouse
1452 CursorMode m_cursorMode
;
1454 bool m_canDragRowSize
;
1455 bool m_canDragColSize
;
1459 wxPoint m_startDragPos
;
1461 bool m_waitForSlowClick
;
1463 wxGridCellCoords m_selectionStart
;
1465 wxCursor m_rowResizeCursor
;
1466 wxCursor m_colResizeCursor
;
1468 bool m_editable
; // applies to whole grid
1469 bool m_cellEditCtrlEnabled
; // is in-place edit currently shown?
1474 void CalcDimensions();
1475 void CalcWindowSizes();
1476 bool Redimension( wxGridTableMessage
& );
1479 bool SendEvent( const wxEventType
, int row
, int col
, wxMouseEvent
& );
1480 bool SendEvent( const wxEventType
, int row
, int col
);
1481 bool SendEvent( const wxEventType type
)
1483 return SendEvent(type
,
1484 m_currentCellCoords
.GetRow(),
1485 m_currentCellCoords
.GetCol());
1488 void OnPaint( wxPaintEvent
& );
1489 void OnSize( wxSizeEvent
& );
1490 void OnKeyDown( wxKeyEvent
& );
1491 void OnEraseBackground( wxEraseEvent
& );
1494 void SetCurrentCell( const wxGridCellCoords
& coords
);
1495 void SetCurrentCell( int row
, int col
)
1496 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
1499 // ------ functions to get/send data (see also public functions)
1501 bool GetModelValues();
1502 bool SetModelValues();
1505 DECLARE_DYNAMIC_CLASS( wxGrid
)
1506 DECLARE_EVENT_TABLE()
1511 // ----------------------------------------------------------------------------
1512 // Grid event class and event types
1513 // ----------------------------------------------------------------------------
1515 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
1519 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
1520 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1524 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
1525 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
1526 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1528 virtual int GetRow() { return m_row
; }
1529 virtual int GetCol() { return m_col
; }
1530 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1531 bool ControlDown() { return m_control
; }
1532 bool MetaDown() { return m_meta
; }
1533 bool ShiftDown() { return m_shift
; }
1534 bool AltDown() { return m_alt
; }
1546 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
1549 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1553 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1554 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1558 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1559 int rowOrCol
=-1, int x
=-1, int y
=-1,
1560 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1562 int GetRowOrCol() { return m_rowOrCol
; }
1563 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1564 bool ControlDown() { return m_control
; }
1565 bool MetaDown() { return m_meta
; }
1566 bool ShiftDown() { return m_shift
; }
1567 bool AltDown() { return m_alt
; }
1578 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1582 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1585 wxGridRangeSelectEvent()
1588 m_topLeft
= wxGridNoCellCoords
;
1589 m_bottomRight
= wxGridNoCellCoords
;
1596 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1597 const wxGridCellCoords
& topLeft
,
1598 const wxGridCellCoords
& bottomRight
,
1599 bool control
=FALSE
, bool shift
=FALSE
,
1600 bool alt
=FALSE
, bool meta
=FALSE
);
1602 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1603 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1604 int GetTopRow() { return m_topLeft
.GetRow(); }
1605 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1606 int GetLeftCol() { return m_topLeft
.GetCol(); }
1607 int GetRightCol() { return m_bottomRight
.GetCol(); }
1608 bool ControlDown() { return m_control
; }
1609 bool MetaDown() { return m_meta
; }
1610 bool ShiftDown() { return m_shift
; }
1611 bool AltDown() { return m_alt
; }
1614 wxGridCellCoords m_topLeft
;
1615 wxGridCellCoords m_bottomRight
;
1621 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1624 // TODO move to wx/event.h
1625 const wxEventType wxEVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1626 const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1627 const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1628 const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1629 const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1630 const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1631 const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1632 const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1633 const wxEventType wxEVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1634 const wxEventType wxEVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1635 const wxEventType wxEVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1636 const wxEventType wxEVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1637 const wxEventType wxEVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1638 const wxEventType wxEVT_GRID_EDITOR_SHOWN
= wxEVT_FIRST
+ 1593;
1639 const wxEventType wxEVT_GRID_EDITOR_HIDDEN
= wxEVT_FIRST
+ 1594;
1642 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1643 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1644 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1646 #define EVT_GRID_CELL_LEFT_CLICK(fn) { wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1647 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1648 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1649 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1650 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1651 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1652 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1653 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1654 #define EVT_GRID_ROW_SIZE(fn) { wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1655 #define EVT_GRID_COL_SIZE(fn) { wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1656 #define EVT_GRID_RANGE_SELECT(fn) { wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1657 #define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1658 #define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1659 #define EVT_GRID_EDITOR_SHOWN(fn) { wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1660 #define EVT_GRID_EDITOR_HIDDEN(fn) { wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1663 #if 0 // TODO: implement these ? others ?
1665 const wxEventType wxEVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1666 const wxEventType wxEVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1667 const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1669 #define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1670 #define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1671 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1675 #endif // #ifndef __WXGRID_H__
1677 #endif // ifndef wxUSE_NEW_GRID