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
54 class WXDLLEXPORT wxGrid
;
57 //////////////////////////////////////////////////////////////////////
61 //////////////////////////////////////////////////////////////////////
64 class WXDLLEXPORT wxGridTableBase
: public wxObject
68 virtual ~wxGridTableBase();
70 // You must override these functions in a derived table class
72 virtual long GetNumberRows() = 0;
73 virtual long GetNumberCols() = 0;
74 virtual wxString
GetValue( int row
, int col
) = 0;
75 virtual void SetValue( int row
, int col
, const wxString
& s
) = 0;
76 virtual bool IsEmptyCell( int row
, int col
) = 0;
78 // Overriding these is optional
80 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
81 virtual wxGrid
* GetView() const { return m_view
; }
83 virtual void Clear() {}
84 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
85 virtual bool AppendRows( size_t numRows
= 1 );
86 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
87 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
88 virtual bool AppendCols( size_t numCols
= 1 );
89 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
91 virtual wxString
GetRowLabelValue( int row
);
92 virtual wxString
GetColLabelValue( int col
);
93 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
94 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
99 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
104 // IDs for messages sent from grid table to view
106 enum wxGridTableRequest
108 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES
= 2000,
109 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES
,
110 wxGRIDTABLE_NOTIFY_ROWS_INSERTED
,
111 wxGRIDTABLE_NOTIFY_ROWS_APPENDED
,
112 wxGRIDTABLE_NOTIFY_ROWS_DELETED
,
113 wxGRIDTABLE_NOTIFY_COLS_INSERTED
,
114 wxGRIDTABLE_NOTIFY_COLS_APPENDED
,
115 wxGRIDTABLE_NOTIFY_COLS_DELETED
118 class WXDLLEXPORT wxGridTableMessage
121 wxGridTableMessage();
122 wxGridTableMessage( wxGridTableBase
*table
, int id
,
126 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
127 wxGridTableBase
* GetTableObject() const { return m_table
; }
128 void SetId( int id
) { m_id
= id
; }
129 int GetId() { return m_id
; }
130 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
131 int GetCommandInt() { return m_comInt1
; }
132 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
133 int GetCommandInt2() { return m_comInt2
; }
136 wxGridTableBase
*m_table
;
144 // ------ wxGridStringArray
145 // A 2-dimensional array of strings for data values
148 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
152 // ------ wxGridStringTable
154 // Simplest type of data table for a grid for small tables of strings
155 // that are stored in memory
158 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
162 wxGridStringTable( int numRows
, int numCols
);
163 ~wxGridStringTable();
165 // these are pure virtual in wxGridTableBase
167 long GetNumberRows();
168 long GetNumberCols();
169 wxString
GetValue( int row
, int col
);
170 void SetValue( int row
, int col
, const wxString
& s
);
171 bool IsEmptyCell( int row
, int col
);
173 // overridden functions from wxGridTableBase
176 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
177 bool AppendRows( size_t numRows
= 1 );
178 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
179 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
180 bool AppendCols( size_t numCols
= 1 );
181 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
183 void SetRowLabelValue( int row
, const wxString
& );
184 void SetColLabelValue( int col
, const wxString
& );
185 wxString
GetRowLabelValue( int row
);
186 wxString
GetColLabelValue( int col
);
189 wxGridStringArray m_data
;
191 // These only get used if you set your own labels, otherwise the
192 // GetRow/ColLabelValue functions return wxGridTableBase defaults
194 wxArrayString m_rowLabels
;
195 wxArrayString m_colLabels
;
197 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
202 //////////////////////////////////////////////////////////////////////
206 //////////////////////////////////////////////////////////////////////
208 class WXDLLEXPORT wxGridCellCoords
211 wxGridCellCoords() { m_row
= m_col
= -1; }
212 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
214 // default copy ctor is ok
216 long GetRow() const { return m_row
; }
217 void SetRow( long n
) { m_row
= n
; }
218 long GetCol() const { return m_col
; }
219 void SetCol( long n
) { m_col
= n
; }
220 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
222 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
224 if ( &other
!= this )
232 bool operator==( const wxGridCellCoords
& other
)
234 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
237 bool operator!=( const wxGridCellCoords
& other
)
239 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
244 return (m_row
== -1 && m_col
== -1 );
253 // For comparisons...
255 extern wxGridCellCoords wxGridNoCellCoords
;
256 extern wxRect wxGridNoCellRect
;
258 // An array of cell coords...
260 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
264 // This set of classes is to provide for the use of different types of
265 // cell edit controls in the grid while avoiding the wx class info
266 // system in deference to wxPython
268 class WXDLLEXPORT wxGridTextCtrl
: public wxTextCtrl
272 wxGridTextCtrl( wxWindow
*,
276 const wxString
& value
= wxEmptyString
,
277 const wxPoint
& pos
= wxDefaultPosition
,
278 const wxSize
& size
= wxDefaultSize
,
281 void SetStartValue( const wxString
& );
282 wxString
GetStartValue() { return startValue
; }
287 // TRUE for controls placed over cells,
288 // FALSE for a control on a grid control panel
289 bool m_isCellControl
;
293 void OnKeyDown( wxKeyEvent
& );
295 DECLARE_DYNAMIC_CLASS( wxGridTextCtrl
)
296 DECLARE_EVENT_TABLE()
300 class WXDLLEXPORT wxGridRowLabelWindow
: public wxWindow
303 wxGridRowLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
304 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
305 const wxPoint
&pos
, const wxSize
&size
);
310 void OnPaint( wxPaintEvent
& event
);
311 void OnMouseEvent( wxMouseEvent
& event
);
312 void OnKeyDown( wxKeyEvent
& event
);
314 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
315 DECLARE_EVENT_TABLE()
319 class WXDLLEXPORT wxGridColLabelWindow
: public wxWindow
322 wxGridColLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
323 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
324 const wxPoint
&pos
, const wxSize
&size
);
329 void OnPaint( wxPaintEvent
&event
);
330 void OnMouseEvent( wxMouseEvent
& event
);
331 void OnKeyDown( wxKeyEvent
& event
);
333 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
334 DECLARE_EVENT_TABLE()
338 class WXDLLEXPORT wxGridCornerLabelWindow
: public wxWindow
341 wxGridCornerLabelWindow() { m_owner
= (wxGrid
*)NULL
; }
342 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
343 const wxPoint
&pos
, const wxSize
&size
);
348 void OnMouseEvent( wxMouseEvent
& event
);
349 void OnKeyDown( wxKeyEvent
& event
);
350 void OnPaint( wxPaintEvent
& event
);
352 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
353 DECLARE_EVENT_TABLE()
358 class WXDLLEXPORT wxGridWindow
: public wxPanel
363 m_owner
= (wxGrid
*)NULL
;
364 m_rowLabelWin
= (wxGridRowLabelWindow
*)NULL
;
365 m_colLabelWin
= (wxGridColLabelWindow
*)NULL
;
368 wxGridWindow( wxGrid
*parent
,
369 wxGridRowLabelWindow
*rowLblWin
,
370 wxGridColLabelWindow
*colLblWin
,
371 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
374 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
378 wxGridRowLabelWindow
*m_rowLabelWin
;
379 wxGridColLabelWindow
*m_colLabelWin
;
381 void OnPaint( wxPaintEvent
&event
);
382 void OnMouseEvent( wxMouseEvent
& event
);
383 void OnKeyDown( wxKeyEvent
& );
385 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
386 DECLARE_EVENT_TABLE()
391 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
396 m_table
= (wxGridTableBase
*) NULL
;
397 m_gridWin
= (wxGridWindow
*) NULL
;
398 m_rowLabelWin
= (wxGridRowLabelWindow
*) NULL
;
399 m_colLabelWin
= (wxGridColLabelWindow
*) NULL
;
400 m_cornerLabelWin
= (wxGridCornerLabelWindow
*) NULL
;
401 m_cellEditCtrl
= (wxWindow
*) NULL
;
404 wxGrid( wxWindow
*parent
,
406 const wxPoint
& pos
= wxDefaultPosition
,
407 const wxSize
& size
= wxDefaultSize
,
409 const wxString
& name
= wxPanelNameStr
);
413 bool CreateGrid( int numRows
, int numCols
);
416 // ------ grid dimensions
418 int GetNumberRows() { return m_numRows
; }
419 int GetNumberCols() { return m_numCols
; }
422 // ------ display update functions
424 void CalcRowLabelsExposed( wxRegion
& reg
);
426 void CalcColLabelsExposed( wxRegion
& reg
);
427 void CalcCellsExposed( wxRegion
& reg
);
430 // ------ event handlers
432 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
433 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
434 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
435 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
436 bool ProcessTableMessage( wxGridTableMessage
& );
439 wxGridTableBase
* GetTable() const { return m_table
; }
440 void SetTable( wxGridTableBase
*table
) { m_table
= table
; }
443 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
444 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
445 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
446 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
447 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
448 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
450 void DrawGridCellArea( wxDC
& dc
);
451 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
452 void DrawAllGridLines( wxDC
& dc
); // TODO - delete this ?
453 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
454 void DrawCellBackground( wxDC
& dc
, const wxGridCellCoords
& );
455 void DrawCellValue( wxDC
& dc
, const wxGridCellCoords
& );
457 void DrawRowLabels( wxDC
& dc
);
458 void DrawRowLabel( wxDC
& dc
, int row
);
460 void DrawColLabels( wxDC
& dc
);
461 void DrawColLabel( wxDC
& dc
, int col
);
464 // ------ Cell text drawing functions
466 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
467 int horizontalAlignment
= wxLEFT
,
468 int verticalAlignment
= wxTOP
);
470 // Split a string containing newline chararcters into an array of
471 // strings and return the number of lines
473 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
475 void GetTextBoxSize( wxDC
& dc
,
476 wxArrayString
& lines
,
477 long *width
, long *height
);
481 // Code that does a lot of grid modification can be enclosed
482 // between BeginBatch() and EndBatch() calls to avoid screen
485 void BeginBatch() { m_batchCount
++; }
486 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
487 int GetBatchCount() { return m_batchCount
; }
490 // ------ edit control functions
492 bool IsEditable() { return m_editable
; }
493 void EnableEditing( bool edit
);
495 #if 0 // at the moment the cell edit control is always active
496 void EnableCellEditControl( bool enable
);
499 bool IsCellEditControlEnabled()
500 { return (m_cellEditCtrl
&& m_cellEditCtrlEnabled
); }
502 void ShowCellEditControl();
503 void HideCellEditControl();
504 void SetEditControlValue( const wxString
& s
= wxEmptyString
);
505 void SaveEditControlValue();
508 // ------ grid location functions
509 // Note that all of these functions work with the logical coordinates of
510 // grid cells and labels so you will need to convert from device
511 // coordinates for mouse events etc.
513 void XYToCell( int x
, int y
, wxGridCellCoords
& );
517 int YToEdgeOfRow( int y
);
518 int XToEdgeOfCol( int x
);
520 wxRect
CellToRect( int row
, int col
);
521 wxRect
CellToRect( const wxGridCellCoords
& coords
)
522 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
524 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
525 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
527 // check to see if a cell is either wholly visible (the default arg) or
528 // at least partially visible in the grid window
530 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
531 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
532 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
533 void MakeCellVisible( int row
, int col
);
534 void MakeCellVisible( const wxGridCellCoords
& coords
)
535 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
538 // ------ grid cursor movement functions
540 void SetGridCursor( int row
, int col
)
541 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
544 bool MoveCursorDown();
545 bool MoveCursorLeft();
546 bool MoveCursorRight();
549 bool MoveCursorUpBlock();
550 bool MoveCursorDownBlock();
551 bool MoveCursorLeftBlock();
552 bool MoveCursorRightBlock();
555 // ------ label and gridline formatting
557 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
558 int GetRowLabelSize() { return m_rowLabelWidth
; }
559 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
560 int GetColLabelSize() { return m_colLabelHeight
; }
561 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
562 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
563 wxFont
GetLabelFont() { return m_labelFont
; }
564 void GetRowLabelAlignment( int *horiz
, int *vert
);
565 void GetColLabelAlignment( int *horiz
, int *vert
);
566 wxString
GetRowLabelValue( int row
);
567 wxString
GetColLabelValue( int col
);
568 wxColour
GetGridLineColour() { return m_gridLineColour
; }
570 void SetRowLabelSize( int width
);
571 void SetColLabelSize( int height
);
572 void SetLabelBackgroundColour( const wxColour
& );
573 void SetLabelTextColour( const wxColour
& );
574 void SetLabelFont( const wxFont
& );
575 void SetRowLabelAlignment( int horiz
, int vert
);
576 void SetColLabelAlignment( int horiz
, int vert
);
577 void SetRowLabelValue( int row
, const wxString
& );
578 void SetColLabelValue( int col
, const wxString
& );
579 void SetGridLineColour( const wxColour
& );
581 void EnableGridLines( bool enable
= TRUE
);
582 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
585 // ------ row and col formatting
587 int GetDefaultRowSize();
588 int GetRowSize( int row
);
589 int GetDefaultColSize();
590 int GetColSize( int col
);
591 wxColour
GetDefaultCellBackgroundColour();
592 wxColour
GetCellBackgroundColour( int row
, int col
);
593 wxColour
GetDefaultCellTextColour();
594 wxColour
GetCellTextColour( int row
, int col
);
595 wxFont
GetDefaultCellFont();
596 wxFont
GetCellFont( int row
, int col
);
597 void GetDefaultCellAlignment( int *horiz
, int *vert
);
598 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
600 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
601 void SetRowSize( int row
, int height
);
602 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
604 void SetColSize( int col
, int width
);
605 void SetDefaultCellBackgroundColour( const wxColour
& );
606 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
607 void SetDefaultCellTextColour( const wxColour
& );
609 void SetCellTextColour( int row
, int col
, const wxColour
& );
610 void SetDefaultCellFont( const wxFont
& );
611 void SetCellFont( int row
, int col
, const wxFont
& );
612 void SetDefaultCellAlignment( int horiz
, int vert
);
613 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
616 // ------ cell value accessors
618 wxString
GetCellValue( int row
, int col
)
622 return m_table
->GetValue( row
, col
);
626 return wxEmptyString
;
630 wxString
GetCellValue( const wxGridCellCoords
& coords
)
631 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
633 void SetCellValue( int row
, int col
, const wxString
& s
);
634 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
635 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
639 // ------ selections of blocks of cells
641 void SelectRow( int row
, bool addToSelected
= FALSE
);
642 void SelectCol( int col
, bool addToSelected
= FALSE
);
644 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
646 void SelectBlock( const wxGridCellCoords
& topLeft
,
647 const wxGridCellCoords
& bottomRight
)
648 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
649 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
654 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
655 m_selectedBottomRight
!= wxGridNoCellCoords
);
658 void ClearSelection();
660 bool IsInSelection( int row
, int col
)
661 { return ( IsSelection() &&
662 row
>= m_selectedTopLeft
.GetRow() &&
663 col
>= m_selectedTopLeft
.GetCol() &&
664 row
<= m_selectedBottomRight
.GetRow() &&
665 col
<= m_selectedBottomRight
.GetCol() );
668 bool IsInSelection( const wxGridCellCoords
& coords
)
669 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
671 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
673 // these will all be -1 if there is no selected block
675 *topRow
= m_selectedTopLeft
.GetRow();
676 *leftCol
= m_selectedTopLeft
.GetCol();
677 *bottomRow
= m_selectedBottomRight
.GetRow();
678 *rightCol
= m_selectedBottomRight
.GetCol();
682 // This function returns the rectangle that encloses the block of cells
683 // limited by TopLeft and BottomRight cell in device coords and clipped
684 // to the client size of the grid window.
686 wxRect
BlockToDeviceRect( const wxGridCellCoords
& topLeft
,
687 const wxGridCellCoords
& bottomRight
);
689 // This function returns the rectangle that encloses the selected cells
690 // in device coords and clipped to the client size of the grid window.
692 wxRect
SelectionToDeviceRect()
694 return BlockToDeviceRect( m_selectedTopLeft
,
695 m_selectedBottomRight
);
699 // ------ For compatibility with previous wxGrid only...
701 // ************************************************
702 // ** Don't use these in new code because they **
703 // ** are liable to disappear in a future **
705 // ************************************************
708 wxGrid( wxWindow
*parent
,
709 int x
= -1, int y
= -1, int w
= -1, int h
= -1,
711 const wxString
& name
= wxPanelNameStr
)
712 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
), style
, name
)
717 void SetCellValue( const wxString
& val
, int row
, int col
)
718 { SetCellValue( row
, col
, val
); }
720 void UpdateDimensions()
721 { CalcDimensions(); }
723 int GetRows() { return GetNumberRows(); }
724 int GetCols() { return GetNumberCols(); }
725 int GetCursorRow() { return GetGridCursorRow(); }
726 int GetCursorColumn() { return GetGridCursorCol(); }
728 int GetScrollPosX() { return 0; }
729 int GetScrollPosY() { return 0; }
731 void SetScrollX( int x
) { }
732 void SetScrollY( int y
) { }
734 void SetColumnWidth( int col
, int width
)
735 { SetColSize( col
, width
); }
737 int GetColumnWidth( int col
)
738 { return GetColSize( col
); }
740 void SetRowHeight( int row
, int height
)
741 { SetRowSize( row
, height
); }
743 int GetRowHeight( int row
)
744 { return GetRowSize( row
); }
746 int GetViewHeight() // returned num whole rows visible
749 int GetViewWidth() // returned num whole cols visible
752 void SetLabelSize( int orientation
, int sz
)
754 if ( orientation
== wxHORIZONTAL
)
755 SetColLabelSize( sz
);
757 SetRowLabelSize( sz
);
760 int GetLabelSize( int orientation
)
762 if ( orientation
== wxHORIZONTAL
)
763 return GetColLabelSize();
765 return GetRowLabelSize();
768 void SetLabelAlignment( int orientation
, int align
)
770 if ( orientation
== wxHORIZONTAL
)
771 SetColLabelAlignment( align
, -1 );
773 SetRowLabelAlignment( align
, -1 );
776 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
779 if ( orientation
== wxHORIZONTAL
)
781 GetColLabelAlignment( &h
, &v
);
786 GetRowLabelAlignment( &h
, &v
);
791 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
793 if ( orientation
== wxHORIZONTAL
)
794 SetColLabelValue( pos
, val
);
796 SetRowLabelValue( pos
, val
);
799 wxString
GetLabelValue( int orientation
, int pos
)
801 if ( orientation
== wxHORIZONTAL
)
802 return GetColLabelValue( pos
);
804 return GetRowLabelValue( pos
);
807 wxFont
GetCellTextFont() const
808 { return m_defaultCellFont
; }
810 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
811 { return m_defaultCellFont
; }
813 void SetCellTextFont(const wxFont
& fnt
)
814 { SetDefaultCellFont( fnt
); }
816 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
817 { SetCellFont( row
, col
, fnt
); }
819 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
820 { SetCellTextColour( row
, col
, val
); }
822 void SetCellTextColour(const wxColour
& col
)
823 { SetDefaultCellTextColour( col
); }
825 void SetCellBackgroundColour(const wxColour
& col
)
826 { SetDefaultCellBackgroundColour( col
); }
828 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
829 { SetCellBackgroundColour( row
, col
, colour
); }
831 bool GetEditable() { return IsEditable(); }
832 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
833 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
835 void SetEditInPlace(bool edit
= TRUE
) { }
837 void SetCellAlignment( int align
, int row
, int col
)
838 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
839 void SetCellAlignment( int WXUNUSED(align
) ) {}
840 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
842 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
843 wxPen
& GetDividerPen() const { return wxNullPen
; }
844 void OnActivate(bool WXUNUSED(active
)) {}
846 // ******** End of compatibility functions **********
850 // ------ control IDs
851 enum { wxGRID_CELLCTRL
= 2000,
854 // ------ control types
855 enum { wxGRID_TEXTCTRL
= 2100,
863 wxGridWindow
*m_gridWin
;
864 wxGridRowLabelWindow
*m_rowLabelWin
;
865 wxGridColLabelWindow
*m_colLabelWin
;
866 wxGridCornerLabelWindow
*m_cornerLabelWin
;
868 wxBoxSizer
*m_mainSizer
;
869 wxBoxSizer
*m_topSizer
;
870 wxBoxSizer
*m_middleSizer
;
872 wxGridTableBase
*m_table
;
882 wxGridCellCoords m_currentCellCoords
;
884 wxGridCellCoords m_selectedTopLeft
;
885 wxGridCellCoords m_selectedBottomRight
;
887 int m_defaultRowHeight
;
888 wxArrayInt m_rowHeights
;
889 wxArrayInt m_rowBottoms
;
891 int m_defaultColWidth
;
892 wxArrayInt m_colWidths
;
893 wxArrayInt m_colRights
;
896 int m_colLabelHeight
;
898 wxColour m_labelBackgroundColour
;
899 wxColour m_labelTextColour
;
902 int m_rowLabelHorizAlign
;
903 int m_rowLabelVertAlign
;
904 int m_colLabelHorizAlign
;
905 int m_colLabelVertAlign
;
907 bool m_defaultRowLabelValues
;
908 bool m_defaultColLabelValues
;
910 wxColour m_gridLineColour
;
911 bool m_gridLinesEnabled
;
913 wxFont m_defaultCellFont
;
915 wxGridCellCoordsArray m_cellsExposed
;
916 wxArrayInt m_rowsExposed
;
917 wxArrayInt m_colsExposed
;
918 wxArrayInt m_rowLabelsExposed
;
919 wxArrayInt m_colLabelsExposed
;
925 enum { WXGRID_CURSOR_DEFAULT
,
926 WXGRID_CURSOR_SELECT_CELL
,
927 WXGRID_CURSOR_RESIZE_ROW
,
928 WXGRID_CURSOR_RESIZE_COL
,
929 WXGRID_CURSOR_SELECT_ROW
,
930 WXGRID_CURSOR_SELECT_COL
937 wxGridCellCoords m_selectionStart
;
939 wxCursor m_rowResizeCursor
;
940 wxCursor m_colResizeCursor
;
942 bool m_editable
; // applies to whole grid
943 int m_editCtrlType
; // for current cell
944 wxWindow
* m_cellEditCtrl
;
945 bool m_cellEditCtrlEnabled
;
950 void CalcDimensions();
951 bool Redimension( wxGridTableMessage
& );
954 bool SendEvent( const wxEventType
,
958 bool SendEvent( const wxEventType
,
962 void OnPaint( wxPaintEvent
& );
963 void OnSize( wxSizeEvent
& );
964 void OnKeyDown( wxKeyEvent
& );
967 void SetCurrentCell( const wxGridCellCoords
& coords
);
968 void SetCurrentCell( int row
, int col
)
969 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
972 // ------ functions to get/send data (see also public functions)
974 bool GetModelValues();
975 bool SetModelValues();
978 DECLARE_DYNAMIC_CLASS( wxGrid
)
979 DECLARE_EVENT_TABLE()
987 // ------ Grid event class and event types
990 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
994 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
995 m_control(0), m_meta(0), m_shift(0), m_alt(0)
999 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
1000 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
1001 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1003 virtual int GetRow() { return m_row
; }
1004 virtual int GetCol() { return m_col
; }
1005 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1006 bool ControlDown() { return m_control
; }
1007 bool MetaDown() { return m_meta
; }
1008 bool ShiftDown() { return m_shift
; }
1009 bool AltDown() { return m_alt
; }
1021 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
1025 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1029 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1030 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1034 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1035 int rowOrCol
=-1, int x
=-1, int y
=-1,
1036 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1038 int GetRowOrCol() { return m_rowOrCol
; }
1039 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1040 bool ControlDown() { return m_control
; }
1041 bool MetaDown() { return m_meta
; }
1042 bool ShiftDown() { return m_shift
; }
1043 bool AltDown() { return m_alt
; }
1054 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1058 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1061 wxGridRangeSelectEvent()
1064 m_topLeft
= wxGridNoCellCoords
;
1065 m_bottomRight
= wxGridNoCellCoords
;
1072 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1073 const wxGridCellCoords
& topLeft
,
1074 const wxGridCellCoords
& bottomRight
,
1075 bool control
=FALSE
, bool shift
=FALSE
,
1076 bool alt
=FALSE
, bool meta
=FALSE
);
1078 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1079 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1080 int GetTopRow() { return m_topLeft
.GetRow(); }
1081 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1082 int GetLeftCol() { return m_topLeft
.GetCol(); }
1083 int GetRightCol() { return m_bottomRight
.GetCol(); }
1084 bool ControlDown() { return m_control
; }
1085 bool MetaDown() { return m_meta
; }
1086 bool ShiftDown() { return m_shift
; }
1087 bool AltDown() { return m_alt
; }
1090 wxGridCellCoords m_topLeft
;
1091 wxGridCellCoords m_bottomRight
;
1097 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1101 const wxEventType EVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1102 const wxEventType EVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1103 const wxEventType EVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1104 const wxEventType EVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1105 const wxEventType EVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1106 const wxEventType EVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1107 const wxEventType EVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1108 const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1109 const wxEventType EVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1110 const wxEventType EVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1111 const wxEventType EVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1112 const wxEventType EVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1113 const wxEventType EVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1116 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1117 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1118 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1120 #define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1121 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1122 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1123 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1124 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1125 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1126 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1127 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1128 #define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1129 #define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1130 #define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1131 #define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1132 #define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1135 #if 0 // TODO: implement these ? others ?
1137 const wxEventType EVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1138 const wxEventType EVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1139 const wxEventType EVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1141 #define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1142 #define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1143 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1147 #endif // #ifndef __WXGRID_H__
1149 #endif // ifndef wxUSE_NEW_GRID