1 /////////////////////////////////////////////////////////////////////////////
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 /////////////////////////////////////////////////////////////////////////////
15 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
23 #pragma interface "grid.h"
27 #include "wx/scrolwin.h"
28 #include "wx/string.h"
29 #include "wx/scrolbar.h"
31 #include "wx/textctrl.h"
32 #include "wx/combobox.h"
33 #include "wx/dynarray.h"
36 // Default parameters for wxGrid
38 #define WXGRID_DEFAULT_NUMBER_ROWS 10
39 #define WXGRID_DEFAULT_NUMBER_COLS 10
41 #define WXGRID_DEFAULT_ROW_HEIGHT 25
43 #define WXGRID_DEFAULT_ROW_HEIGHT 30
45 #define WXGRID_DEFAULT_COL_WIDTH 80
46 #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
47 #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
48 #define WXGRID_LABEL_EDGE_ZONE 5
49 #define WXGRID_MIN_ROW_HEIGHT 15
50 #define WXGRID_MIN_COL_WIDTH 15
51 #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
53 // ----------------------------------------------------------------------------
54 // forward declarations
55 // ----------------------------------------------------------------------------
57 class WXDLLEXPORT wxGridCellAttrProviderData
;
58 class WXDLLEXPORT wxGridRowLabelWindow
;
59 class WXDLLEXPORT wxGridColLabelWindow
;
60 class WXDLLEXPORT wxGridCornerLabelWindow
;
61 class WXDLLEXPORT wxGridWindow
;
62 class WXDLLEXPORT wxGrid
;
64 // ----------------------------------------------------------------------------
65 // wxGridCellAttr: this class can be used to alter the cells appearance in
66 // the grid by changing their colour/font/... from default. An object of this
67 // class may be returned by wxGridTable::GetAttr().
68 // ----------------------------------------------------------------------------
70 class WXDLLEXPORT wxGridCellAttr
79 wxGridCellAttr(const wxColour
& colText
,
80 const wxColour
& colBack
,
84 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
86 SetAlignment(hAlign
, vAlign
);
89 // default copy ctor ok
92 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
93 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
94 void SetFont(const wxFont
& font
) { m_font
= font
; }
95 void SetAlignment(int hAlign
, int vAlign
)
102 bool HasTextColour() const { return m_colText
.Ok(); }
103 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
104 bool HasFont() const { return m_font
.Ok(); }
105 bool HasAlignment() const { return m_hAlign
|| m_vAlign
; }
107 const wxColour
& GetTextColour() const { return m_colText
; }
108 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
109 const wxFont
& GetFont() const { return m_font
; }
110 void GetAlignment(int *hAlign
, int *vAlign
)
112 if ( hAlign
) *hAlign
= m_hAlign
;
113 if ( vAlign
) *vAlign
= m_vAlign
;
124 // ----------------------------------------------------------------------------
125 // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
127 // ----------------------------------------------------------------------------
129 // implementation note: we separate it from wxGridTableBase because we wish to
130 // avoid deriving a new table class if possible, and sometimes it will be
131 // enough to just derive another wxGridCellAttrProvider instead
133 class WXDLLEXPORT wxGridCellAttrProvider
136 wxGridCellAttrProvider();
137 virtual ~wxGridCellAttrProvider();
139 virtual wxGridCellAttr
*GetAttr(int row
, int col
) const;
140 virtual void SetAttr(const wxGridCellAttr
*attr
, int row
, int col
);
145 wxGridCellAttrProviderData
*m_data
;
148 //////////////////////////////////////////////////////////////////////
150 // Grid table classes
152 //////////////////////////////////////////////////////////////////////
155 class WXDLLEXPORT wxGridTableBase
: public wxObject
159 virtual ~wxGridTableBase();
161 // You must override these functions in a derived table class
163 virtual long GetNumberRows() = 0;
164 virtual long GetNumberCols() = 0;
165 virtual wxString
GetValue( int row
, int col
) = 0;
166 virtual void SetValue( int row
, int col
, const wxString
& s
) = 0;
167 virtual bool IsEmptyCell( int row
, int col
) = 0;
169 // Overriding these is optional
171 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
172 virtual wxGrid
* GetView() const { return m_view
; }
174 virtual void Clear() {}
175 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
176 virtual bool AppendRows( size_t numRows
= 1 );
177 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
178 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
179 virtual bool AppendCols( size_t numCols
= 1 );
180 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
182 virtual wxString
GetRowLabelValue( int row
);
183 virtual wxString
GetColLabelValue( int col
);
184 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
185 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
187 // Attribute handling
190 // give us the attr provider to use - we take ownership of the pointer
191 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
193 // get the currently used attr provider (may be NULL)
194 wxGridCellAttrProvider
*GetAttrProvider() const { return m_attrProvider
; }
196 // by default forwarded to wxGridCellAttrProvider if any. May be
197 // overridden to handle attributes directly in this class.
198 virtual wxGridCellAttr
*GetAttr( int row
, int col
);
200 // takes ownership of the pointer
201 virtual void SetAttr(const wxGridCellAttr
*attr
, int row
, int col
);
205 wxGridCellAttrProvider
*m_attrProvider
;
207 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
211 // ----------------------------------------------------------------------------
212 // wxGridTableMessage
213 // ----------------------------------------------------------------------------
215 // IDs for messages sent from grid table to view
217 enum wxGridTableRequest
219 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
220 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
221 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
222 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
223 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
224 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
225 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
226 wxGRIDTABLE_NOTIFY_COLS_DELETED
229 class WXDLLEXPORT wxGridTableMessage
232 wxGridTableMessage();
233 wxGridTableMessage( wxGridTableBase
*table
, int id
,
237 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
238 wxGridTableBase
* GetTableObject() const { return m_table
; }
239 void SetId( int id
) { m_id
= id
; }
240 int GetId() { return m_id
; }
241 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
242 int GetCommandInt() { return m_comInt1
; }
243 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
244 int GetCommandInt2() { return m_comInt2
; }
247 wxGridTableBase
*m_table
;
255 // ------ wxGridStringArray
256 // A 2-dimensional array of strings for data values
259 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
263 // ------ wxGridStringTable
265 // Simplest type of data table for a grid for small tables of strings
266 // that are stored in memory
269 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
273 wxGridStringTable( int numRows
, int numCols
);
274 ~wxGridStringTable();
276 // these are pure virtual in wxGridTableBase
278 long GetNumberRows();
279 long GetNumberCols();
280 wxString
GetValue( int row
, int col
);
281 void SetValue( int row
, int col
, const wxString
& s
);
282 bool IsEmptyCell( int row
, int col
);
284 // overridden functions from wxGridTableBase
287 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
288 bool AppendRows( size_t numRows
= 1 );
289 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
290 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
291 bool AppendCols( size_t numCols
= 1 );
292 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
294 void SetRowLabelValue( int row
, const wxString
& );
295 void SetColLabelValue( int col
, const wxString
& );
296 wxString
GetRowLabelValue( int row
);
297 wxString
GetColLabelValue( int col
);
300 wxGridStringArray m_data
;
302 // These only get used if you set your own labels, otherwise the
303 // GetRow/ColLabelValue functions return wxGridTableBase defaults
305 wxArrayString m_rowLabels
;
306 wxArrayString m_colLabels
;
308 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
313 //////////////////////////////////////////////////////////////////////
317 //////////////////////////////////////////////////////////////////////
319 class WXDLLEXPORT wxGridCellCoords
322 wxGridCellCoords() { m_row
= m_col
= -1; }
323 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
325 // default copy ctor is ok
327 long GetRow() const { return m_row
; }
328 void SetRow( long n
) { m_row
= n
; }
329 long GetCol() const { return m_col
; }
330 void SetCol( long n
) { m_col
= n
; }
331 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
333 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
335 if ( &other
!= this )
343 bool operator==( const wxGridCellCoords
& other
)
345 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
348 bool operator!=( const wxGridCellCoords
& other
)
350 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
355 return (m_row
== -1 && m_col
== -1 );
364 // For comparisons...
366 extern wxGridCellCoords wxGridNoCellCoords
;
367 extern wxRect wxGridNoCellRect
;
369 // An array of cell coords...
371 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
375 // This set of classes is to provide for the use of different types of
376 // cell edit controls in the grid while avoiding the wx class info
377 // system in deference to wxPython
379 class WXDLLEXPORT wxGridTextCtrl
: public wxTextCtrl
383 wxGridTextCtrl( wxWindow
*,
387 const wxString
& value
= wxEmptyString
,
388 const wxPoint
& pos
= wxDefaultPosition
,
389 const wxSize
& size
= wxDefaultSize
,
392 void SetStartValue( const wxString
& );
393 wxString
GetStartValue() { return startValue
; }
398 // TRUE for controls placed over cells,
399 // FALSE for a control on a grid control panel
400 bool m_isCellControl
;
404 void OnKeyDown( wxKeyEvent
& );
406 DECLARE_DYNAMIC_CLASS( wxGridTextCtrl
)
407 DECLARE_EVENT_TABLE()
410 // ----------------------------------------------------------------------------
412 // ----------------------------------------------------------------------------
414 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
419 m_table
= (wxGridTableBase
*) NULL
;
420 m_gridWin
= (wxGridWindow
*) NULL
;
421 m_rowLabelWin
= (wxGridRowLabelWindow
*) NULL
;
422 m_colLabelWin
= (wxGridColLabelWindow
*) NULL
;
423 m_cornerLabelWin
= (wxGridCornerLabelWindow
*) NULL
;
424 m_cellEditCtrl
= (wxWindow
*) NULL
;
427 wxGrid( wxWindow
*parent
,
429 const wxPoint
& pos
= wxDefaultPosition
,
430 const wxSize
& size
= wxDefaultSize
,
432 const wxString
& name
= wxPanelNameStr
);
436 bool CreateGrid( int numRows
, int numCols
);
439 // ------ grid dimensions
441 int GetNumberRows() { return m_numRows
; }
442 int GetNumberCols() { return m_numCols
; }
445 // ------ display update functions
447 void CalcRowLabelsExposed( wxRegion
& reg
);
449 void CalcColLabelsExposed( wxRegion
& reg
);
450 void CalcCellsExposed( wxRegion
& reg
);
453 // ------ event handlers
455 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
456 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
457 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
458 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
459 bool ProcessTableMessage( wxGridTableMessage
& );
462 wxGridTableBase
* GetTable() const { return m_table
; }
463 void SetTable( wxGridTableBase
*table
) { m_table
= table
; }
466 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
467 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
468 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
469 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
470 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
471 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
473 void DrawGridCellArea( wxDC
& dc
);
474 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
475 void DrawAllGridLines( wxDC
& dc
, const wxRegion
& reg
);
476 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
477 void DrawCellBackground( wxDC
& dc
, const wxGridCellCoords
& );
478 void DrawCellValue( wxDC
& dc
, const wxGridCellCoords
& );
480 void DrawRowLabels( wxDC
& dc
);
481 void DrawRowLabel( wxDC
& dc
, int row
);
483 void DrawColLabels( wxDC
& dc
);
484 void DrawColLabel( wxDC
& dc
, int col
);
487 // ------ Cell text drawing functions
489 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
490 int horizontalAlignment
= wxLEFT
,
491 int verticalAlignment
= wxTOP
);
493 // Split a string containing newline chararcters into an array of
494 // strings and return the number of lines
496 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
498 void GetTextBoxSize( wxDC
& dc
,
499 wxArrayString
& lines
,
500 long *width
, long *height
);
504 // Code that does a lot of grid modification can be enclosed
505 // between BeginBatch() and EndBatch() calls to avoid screen
508 void BeginBatch() { m_batchCount
++; }
509 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
510 int GetBatchCount() { return m_batchCount
; }
513 // ------ edit control functions
515 bool IsEditable() { return m_editable
; }
516 void EnableEditing( bool edit
);
518 #if 0 // at the moment the cell edit control is always active
519 void EnableCellEditControl( bool enable
);
522 bool IsCellEditControlEnabled()
523 { return (m_cellEditCtrl
&& m_cellEditCtrlEnabled
); }
525 void ShowCellEditControl();
526 void HideCellEditControl();
527 void SetEditControlValue( const wxString
& s
= wxEmptyString
);
528 void SaveEditControlValue();
531 // ------ grid location functions
532 // Note that all of these functions work with the logical coordinates of
533 // grid cells and labels so you will need to convert from device
534 // coordinates for mouse events etc.
536 void XYToCell( int x
, int y
, wxGridCellCoords
& );
540 int YToEdgeOfRow( int y
);
541 int XToEdgeOfCol( int x
);
543 wxRect
CellToRect( int row
, int col
);
544 wxRect
CellToRect( const wxGridCellCoords
& coords
)
545 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
547 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
548 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
550 // check to see if a cell is either wholly visible (the default arg) or
551 // at least partially visible in the grid window
553 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
554 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
555 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
556 void MakeCellVisible( int row
, int col
);
557 void MakeCellVisible( const wxGridCellCoords
& coords
)
558 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
561 // ------ grid cursor movement functions
563 void SetGridCursor( int row
, int col
)
564 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
567 bool MoveCursorDown();
568 bool MoveCursorLeft();
569 bool MoveCursorRight();
572 bool MoveCursorUpBlock();
573 bool MoveCursorDownBlock();
574 bool MoveCursorLeftBlock();
575 bool MoveCursorRightBlock();
578 // ------ label and gridline formatting
580 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
581 int GetRowLabelSize() { return m_rowLabelWidth
; }
582 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
583 int GetColLabelSize() { return m_colLabelHeight
; }
584 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
585 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
586 wxFont
GetLabelFont() { return m_labelFont
; }
587 void GetRowLabelAlignment( int *horiz
, int *vert
);
588 void GetColLabelAlignment( int *horiz
, int *vert
);
589 wxString
GetRowLabelValue( int row
);
590 wxString
GetColLabelValue( int col
);
591 wxColour
GetGridLineColour() { return m_gridLineColour
; }
593 void SetRowLabelSize( int width
);
594 void SetColLabelSize( int height
);
595 void SetLabelBackgroundColour( const wxColour
& );
596 void SetLabelTextColour( const wxColour
& );
597 void SetLabelFont( const wxFont
& );
598 void SetRowLabelAlignment( int horiz
, int vert
);
599 void SetColLabelAlignment( int horiz
, int vert
);
600 void SetRowLabelValue( int row
, const wxString
& );
601 void SetColLabelValue( int col
, const wxString
& );
602 void SetGridLineColour( const wxColour
& );
604 void EnableGridLines( bool enable
= TRUE
);
605 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
608 // ------ row and col formatting
610 int GetDefaultRowSize();
611 int GetRowSize( int row
);
612 int GetDefaultColSize();
613 int GetColSize( int col
);
614 wxColour
GetDefaultCellBackgroundColour();
615 wxColour
GetCellBackgroundColour( int row
, int col
);
616 wxColour
GetDefaultCellTextColour();
617 wxColour
GetCellTextColour( int row
, int col
);
618 wxFont
GetDefaultCellFont();
619 wxFont
GetCellFont( int row
, int col
);
620 void GetDefaultCellAlignment( int *horiz
, int *vert
);
621 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
623 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
624 void SetRowSize( int row
, int height
);
625 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
627 void SetColSize( int col
, int width
);
628 void SetDefaultCellBackgroundColour( const wxColour
& );
629 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
630 void SetDefaultCellTextColour( const wxColour
& );
632 void SetCellTextColour( int row
, int col
, const wxColour
& );
633 void SetDefaultCellFont( const wxFont
& );
634 void SetCellFont( int row
, int col
, const wxFont
& );
635 void SetDefaultCellAlignment( int horiz
, int vert
);
636 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
639 // ------ cell value accessors
641 wxString
GetCellValue( int row
, int col
)
645 return m_table
->GetValue( row
, col
);
649 return wxEmptyString
;
653 wxString
GetCellValue( const wxGridCellCoords
& coords
)
654 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
656 void SetCellValue( int row
, int col
, const wxString
& s
);
657 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
658 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
662 // ------ selections of blocks of cells
664 void SelectRow( int row
, bool addToSelected
= FALSE
);
665 void SelectCol( int col
, bool addToSelected
= FALSE
);
667 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
669 void SelectBlock( const wxGridCellCoords
& topLeft
,
670 const wxGridCellCoords
& bottomRight
)
671 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
672 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
677 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
678 m_selectedBottomRight
!= wxGridNoCellCoords
);
681 void ClearSelection();
683 bool IsInSelection( int row
, int col
)
684 { return ( IsSelection() &&
685 row
>= m_selectedTopLeft
.GetRow() &&
686 col
>= m_selectedTopLeft
.GetCol() &&
687 row
<= m_selectedBottomRight
.GetRow() &&
688 col
<= m_selectedBottomRight
.GetCol() );
691 bool IsInSelection( const wxGridCellCoords
& coords
)
692 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
694 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
696 // these will all be -1 if there is no selected block
698 *topRow
= m_selectedTopLeft
.GetRow();
699 *leftCol
= m_selectedTopLeft
.GetCol();
700 *bottomRow
= m_selectedBottomRight
.GetRow();
701 *rightCol
= m_selectedBottomRight
.GetCol();
705 // This function returns the rectangle that encloses the block of cells
706 // limited by TopLeft and BottomRight cell in device coords and clipped
707 // to the client size of the grid window.
709 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
710 const wxGridCellCoords
& bottomRight
);
712 // This function returns the rectangle that encloses the selected cells
713 // in device coords and clipped to the client size of the grid window.
715 wxRect
SelectionToDeviceRect()
717 return BlockToDeviceRect( m_selectedTopLeft
,
718 m_selectedBottomRight
);
722 // ------ For compatibility with previous wxGrid only...
724 // ************************************************
725 // ** Don't use these in new code because they **
726 // ** are liable to disappear in a future **
728 // ************************************************
731 wxGrid( wxWindow
*parent
,
732 int x
= -1, int y
= -1, int w
= -1, int h
= -1,
734 const wxString
& name
= wxPanelNameStr
)
735 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
), style
, name
)
740 void SetCellValue( const wxString
& val
, int row
, int col
)
741 { SetCellValue( row
, col
, val
); }
743 void UpdateDimensions()
744 { CalcDimensions(); }
746 int GetRows() { return GetNumberRows(); }
747 int GetCols() { return GetNumberCols(); }
748 int GetCursorRow() { return GetGridCursorRow(); }
749 int GetCursorColumn() { return GetGridCursorCol(); }
751 int GetScrollPosX() { return 0; }
752 int GetScrollPosY() { return 0; }
754 void SetScrollX( int x
) { }
755 void SetScrollY( int y
) { }
757 void SetColumnWidth( int col
, int width
)
758 { SetColSize( col
, width
); }
760 int GetColumnWidth( int col
)
761 { return GetColSize( col
); }
763 void SetRowHeight( int row
, int height
)
764 { SetRowSize( row
, height
); }
766 int GetRowHeight( int row
)
767 { return GetRowSize( row
); }
769 int GetViewHeight() // returned num whole rows visible
772 int GetViewWidth() // returned num whole cols visible
775 void SetLabelSize( int orientation
, int sz
)
777 if ( orientation
== wxHORIZONTAL
)
778 SetColLabelSize( sz
);
780 SetRowLabelSize( sz
);
783 int GetLabelSize( int orientation
)
785 if ( orientation
== wxHORIZONTAL
)
786 return GetColLabelSize();
788 return GetRowLabelSize();
791 void SetLabelAlignment( int orientation
, int align
)
793 if ( orientation
== wxHORIZONTAL
)
794 SetColLabelAlignment( align
, -1 );
796 SetRowLabelAlignment( align
, -1 );
799 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
802 if ( orientation
== wxHORIZONTAL
)
804 GetColLabelAlignment( &h
, &v
);
809 GetRowLabelAlignment( &h
, &v
);
814 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
816 if ( orientation
== wxHORIZONTAL
)
817 SetColLabelValue( pos
, val
);
819 SetRowLabelValue( pos
, val
);
822 wxString
GetLabelValue( int orientation
, int pos
)
824 if ( orientation
== wxHORIZONTAL
)
825 return GetColLabelValue( pos
);
827 return GetRowLabelValue( pos
);
830 wxFont
GetCellTextFont() const
831 { return m_defaultCellFont
; }
833 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
834 { return m_defaultCellFont
; }
836 void SetCellTextFont(const wxFont
& fnt
)
837 { SetDefaultCellFont( fnt
); }
839 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
840 { SetCellFont( row
, col
, fnt
); }
842 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
843 { SetCellTextColour( row
, col
, val
); }
845 void SetCellTextColour(const wxColour
& col
)
846 { SetDefaultCellTextColour( col
); }
848 void SetCellBackgroundColour(const wxColour
& col
)
849 { SetDefaultCellBackgroundColour( col
); }
851 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
852 { SetCellBackgroundColour( row
, col
, colour
); }
854 bool GetEditable() { return IsEditable(); }
855 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
856 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
858 void SetEditInPlace(bool edit
= TRUE
) { }
860 void SetCellAlignment( int align
, int row
, int col
)
861 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
862 void SetCellAlignment( int WXUNUSED(align
) ) {}
863 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
865 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
866 wxPen
& GetDividerPen() const { return wxNullPen
; }
867 void OnActivate(bool WXUNUSED(active
)) {}
869 // ******** End of compatibility functions **********
873 // ------ control IDs
874 enum { wxGRID_CELLCTRL
= 2000,
877 // ------ control types
878 enum { wxGRID_TEXTCTRL
= 2100,
887 wxGridWindow
*m_gridWin
;
888 wxGridRowLabelWindow
*m_rowLabelWin
;
889 wxGridColLabelWindow
*m_colLabelWin
;
890 wxGridCornerLabelWindow
*m_cornerLabelWin
;
892 wxGridTableBase
*m_table
;
902 wxGridCellCoords m_currentCellCoords
;
904 wxGridCellCoords m_selectedTopLeft
;
905 wxGridCellCoords m_selectedBottomRight
;
907 int m_defaultRowHeight
;
908 wxArrayInt m_rowHeights
;
909 wxArrayInt m_rowBottoms
;
911 int m_defaultColWidth
;
912 wxArrayInt m_colWidths
;
913 wxArrayInt m_colRights
;
916 int m_colLabelHeight
;
918 wxColour m_labelBackgroundColour
;
919 wxColour m_labelTextColour
;
922 int m_rowLabelHorizAlign
;
923 int m_rowLabelVertAlign
;
924 int m_colLabelHorizAlign
;
925 int m_colLabelVertAlign
;
927 bool m_defaultRowLabelValues
;
928 bool m_defaultColLabelValues
;
930 wxColour m_gridLineColour
;
931 bool m_gridLinesEnabled
;
933 // default cell attributes
934 wxFont m_defaultCellFont
;
935 int m_defaultCellHAlign
,
938 // do we have some place to store attributes in?
939 bool CanHaveAttributes();
941 wxGridCellCoordsArray m_cellsExposed
;
942 wxArrayInt m_rowsExposed
;
943 wxArrayInt m_colsExposed
;
944 wxArrayInt m_rowLabelsExposed
;
945 wxArrayInt m_colLabelsExposed
;
951 enum { WXGRID_CURSOR_SELECT_CELL
,
952 WXGRID_CURSOR_RESIZE_ROW
,
953 WXGRID_CURSOR_RESIZE_COL
,
954 WXGRID_CURSOR_SELECT_ROW
,
955 WXGRID_CURSOR_SELECT_COL
962 wxGridCellCoords m_selectionStart
;
964 wxCursor m_rowResizeCursor
;
965 wxCursor m_colResizeCursor
;
967 bool m_editable
; // applies to whole grid
968 int m_editCtrlType
; // for current cell
969 wxWindow
* m_cellEditCtrl
;
970 bool m_cellEditCtrlEnabled
;
975 void CalcDimensions();
976 void CalcWindowSizes();
977 bool Redimension( wxGridTableMessage
& );
980 bool SendEvent( const wxEventType
,
984 bool SendEvent( const wxEventType
,
988 void OnPaint( wxPaintEvent
& );
989 void OnSize( wxSizeEvent
& );
990 void OnKeyDown( wxKeyEvent
& );
993 void SetCurrentCell( const wxGridCellCoords
& coords
);
994 void SetCurrentCell( int row
, int col
)
995 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
998 // ------ functions to get/send data (see also public functions)
1000 bool GetModelValues();
1001 bool SetModelValues();
1004 DECLARE_DYNAMIC_CLASS( wxGrid
)
1005 DECLARE_EVENT_TABLE()
1013 // ------ Grid event class and event types
1016 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
1020 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
1021 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1025 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
1026 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
1027 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1029 virtual int GetRow() { return m_row
; }
1030 virtual int GetCol() { return m_col
; }
1031 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1032 bool ControlDown() { return m_control
; }
1033 bool MetaDown() { return m_meta
; }
1034 bool ShiftDown() { return m_shift
; }
1035 bool AltDown() { return m_alt
; }
1047 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
1051 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1055 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1056 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1060 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1061 int rowOrCol
=-1, int x
=-1, int y
=-1,
1062 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1064 int GetRowOrCol() { return m_rowOrCol
; }
1065 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1066 bool ControlDown() { return m_control
; }
1067 bool MetaDown() { return m_meta
; }
1068 bool ShiftDown() { return m_shift
; }
1069 bool AltDown() { return m_alt
; }
1080 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1084 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1087 wxGridRangeSelectEvent()
1090 m_topLeft
= wxGridNoCellCoords
;
1091 m_bottomRight
= wxGridNoCellCoords
;
1098 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1099 const wxGridCellCoords
& topLeft
,
1100 const wxGridCellCoords
& bottomRight
,
1101 bool control
=FALSE
, bool shift
=FALSE
,
1102 bool alt
=FALSE
, bool meta
=FALSE
);
1104 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1105 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1106 int GetTopRow() { return m_topLeft
.GetRow(); }
1107 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1108 int GetLeftCol() { return m_topLeft
.GetCol(); }
1109 int GetRightCol() { return m_bottomRight
.GetCol(); }
1110 bool ControlDown() { return m_control
; }
1111 bool MetaDown() { return m_meta
; }
1112 bool ShiftDown() { return m_shift
; }
1113 bool AltDown() { return m_alt
; }
1116 wxGridCellCoords m_topLeft
;
1117 wxGridCellCoords m_bottomRight
;
1123 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1127 const wxEventType EVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1128 const wxEventType EVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1129 const wxEventType EVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1130 const wxEventType EVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1131 const wxEventType EVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1132 const wxEventType EVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1133 const wxEventType EVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1134 const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1135 const wxEventType EVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1136 const wxEventType EVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1137 const wxEventType EVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1138 const wxEventType EVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1139 const wxEventType EVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1142 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1143 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1144 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1146 #define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1147 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1148 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1149 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1150 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1151 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1152 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1153 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1154 #define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1155 #define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1156 #define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1157 #define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1158 #define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1161 #if 0 // TODO: implement these ? others ?
1163 const wxEventType EVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1164 const wxEventType EVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1165 const wxEventType EVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1167 #define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1168 #define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1169 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1173 #endif // #ifndef __WXGRID_H__
1175 #endif // ifndef wxUSE_NEW_GRID