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
52 #define WXGRID_DEFAULT_TOPEDIT_WIDTH 300
53 #define WXGRID_DEFAULT_TOPEDIT_HEIGHT 60
56 class WXDLLEXPORT wxGrid
;
59 //////////////////////////////////////////////////////////////////////
63 //////////////////////////////////////////////////////////////////////
66 class WXDLLEXPORT wxGridTableBase
: public wxObject
72 virtual ~wxGridTableBase();
74 // You must override these functions in a derived table class
76 virtual long GetNumberRows() = 0;
77 virtual long GetNumberCols() = 0;
78 virtual wxString
GetValue( int row
, int col
) = 0;
79 virtual void SetValue( int row
, int col
, const wxString
& s
) = 0;
80 virtual bool IsEmptyCell( int row
, int col
) = 0;
82 // Overriding these is optional
84 virtual void SetView( wxGrid
*grid
) { m_view
= grid
; }
85 virtual wxGrid
* GetView() const { return m_view
; }
87 virtual void Clear() {}
88 virtual bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
89 virtual bool AppendRows( size_t numRows
= 1 );
90 virtual bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
91 virtual bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
92 virtual bool AppendCols( size_t numCols
= 1 );
93 virtual bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
95 virtual wxString
GetRowLabelValue( int row
);
96 virtual wxString
GetColLabelValue( int col
);
97 virtual void SetRowLabelValue( int WXUNUSED(row
), const wxString
& ) {}
98 virtual void SetColLabelValue( int WXUNUSED(col
), const wxString
& ) {}
100 DECLARE_ABSTRACT_CLASS( wxGridTableBase
);
105 // IDs for messages sent from grid table to view
107 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
120 wxGridTableBase
*m_table
;
126 wxGridTableMessage();
127 wxGridTableMessage( wxGridTableBase
*table
, int id
,
131 void SetTableObject( wxGridTableBase
*table
) { m_table
= table
; }
132 wxGridTableBase
* GetTableObject() const { return m_table
; }
133 void SetId( int id
) { m_id
= id
; }
134 int GetId() { return m_id
; }
135 void SetCommandInt( int comInt1
) { m_comInt1
= comInt1
; }
136 int GetCommandInt() { return m_comInt1
; }
137 void SetCommandInt2( int comInt2
) { m_comInt2
= comInt2
; }
138 int GetCommandInt2() { return m_comInt2
; }
143 // ------ wxGridStringArray
144 // A 2-dimensional array of strings for data values
147 WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString
, wxGridStringArray
);
151 // ------ wxGridStringTable
153 // Simplest type of data table for a grid for small tables of strings
154 // that are stored in memory
157 class WXDLLEXPORT wxGridStringTable
: public wxGridTableBase
159 wxGridStringArray m_data
;
161 // These only get used if you set your own labels, otherwise the
162 // GetRow/ColLabelValue functions return wxGridTableBase defaults
164 wxArrayString m_rowLabels
;
165 wxArrayString m_colLabels
;
169 wxGridStringTable( int numRows
, int numCols
);
170 ~wxGridStringTable();
172 // these are pure virtual in wxGridTableBase
174 long GetNumberRows();
175 long GetNumberCols();
176 wxString
GetValue( int row
, int col
);
177 void SetValue( int row
, int col
, const wxString
& s
);
178 bool IsEmptyCell( int row
, int col
);
180 // overridden functions from wxGridTableBase
183 bool InsertRows( size_t pos
= 0, size_t numRows
= 1 );
184 bool AppendRows( size_t numRows
= 1 );
185 bool DeleteRows( size_t pos
= 0, size_t numRows
= 1 );
186 bool InsertCols( size_t pos
= 0, size_t numCols
= 1 );
187 bool AppendCols( size_t numCols
= 1 );
188 bool DeleteCols( size_t pos
= 0, size_t numCols
= 1 );
190 void SetRowLabelValue( int row
, const wxString
& );
191 void SetColLabelValue( int col
, const wxString
& );
192 wxString
GetRowLabelValue( int row
);
193 wxString
GetColLabelValue( int col
);
195 DECLARE_DYNAMIC_CLASS( wxGridStringTable
)
200 //////////////////////////////////////////////////////////////////////
204 //////////////////////////////////////////////////////////////////////
206 class WXDLLEXPORT wxGridCellCoords
212 wxGridCellCoords() { m_row
= m_col
= -1; }
213 wxGridCellCoords( int r
, int c
) { m_row
= r
; m_col
= c
; }
215 // default copy ctor is ok
217 long GetRow() const { return m_row
; }
218 void SetRow( long n
) { m_row
= n
; }
219 long GetCol() const { return m_col
; }
220 void SetCol( long n
) { m_col
= n
; }
221 void Set( long row
, long col
) { m_row
= row
; m_col
= col
; }
223 wxGridCellCoords
& operator=( const wxGridCellCoords
& other
)
225 if ( &other
!= this )
233 bool operator==( const wxGridCellCoords
& other
)
235 return (m_row
== other
.m_row
&& m_col
== other
.m_col
);
238 bool operator!=( const wxGridCellCoords
& other
)
240 return (m_row
!= other
.m_row
|| m_col
!= other
.m_col
);
245 return (m_row
== -1 && m_col
== -1 );
250 // For comparisons...
252 extern wxGridCellCoords wxGridNoCellCoords
;
253 extern wxRect wxGridNoCellRect
;
255 // An array of cell coords...
257 WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords
, wxGridCellCoordsArray
);
261 // This set of classes is to provide for the use of different types of
262 // cell edit controls in the grid while avoiding the wx class info
263 // system in deference to wxPython
265 class WXDLLEXPORT wxGridTextCtrl
: public wxTextCtrl
269 // TRUE for controls placed over cells,
270 // FALSE for a control on a grid control panel
271 bool m_isCellControl
;
275 void OnKeyDown( wxKeyEvent
& );
279 wxGridTextCtrl( wxWindow
*,
283 const wxString
& value
= wxEmptyString
,
284 const wxPoint
& pos
= wxDefaultPosition
,
285 const wxSize
& size
= wxDefaultSize
,
288 void SetStartValue( const wxString
& );
289 wxString
GetStartValue() { return startValue
; }
291 DECLARE_DYNAMIC_CLASS( wxGridTextCtrl
)
292 DECLARE_EVENT_TABLE()
296 class WXDLLEXPORT wxGridRowLabelWindow
: public wxWindow
300 void OnPaint( wxPaintEvent
& event
);
301 void OnMouseEvent( wxMouseEvent
& event
);
302 void OnKeyDown( wxKeyEvent
& event
);
305 wxGridRowLabelWindow() {}
306 wxGridRowLabelWindow( wxGrid
*parent
, wxWindowID id
,
307 const wxPoint
&pos
, const wxSize
&size
);
309 DECLARE_DYNAMIC_CLASS(wxGridRowLabelWindow
)
310 DECLARE_EVENT_TABLE()
314 class WXDLLEXPORT wxGridColLabelWindow
: public wxWindow
318 void OnPaint( wxPaintEvent
&event
);
319 void OnMouseEvent( wxMouseEvent
& event
);
320 void OnKeyDown( wxKeyEvent
& event
);
323 wxGridColLabelWindow() {}
324 wxGridColLabelWindow( wxGrid
*parent
, wxWindowID id
,
325 const wxPoint
&pos
, const wxSize
&size
);
327 DECLARE_DYNAMIC_CLASS(wxGridColLabelWindow
)
328 DECLARE_EVENT_TABLE()
332 class WXDLLEXPORT wxGridCornerLabelWindow
: public wxWindow
336 void OnMouseEvent( wxMouseEvent
& event
);
337 void OnKeyDown( wxKeyEvent
& event
);
340 wxGridCornerLabelWindow() {}
341 wxGridCornerLabelWindow( wxGrid
*parent
, wxWindowID id
,
342 const wxPoint
&pos
, const wxSize
&size
);
344 DECLARE_DYNAMIC_CLASS(wxGridCornerLabelWindow
)
345 DECLARE_EVENT_TABLE()
350 class WXDLLEXPORT wxGridWindow
: public wxPanel
353 wxGridRowLabelWindow
*m_rowLabelWin
;
354 wxGridColLabelWindow
*m_colLabelWin
;
356 void OnPaint( wxPaintEvent
&event
);
357 void OnMouseEvent( wxMouseEvent
& event
);
358 void OnKeyDown( wxKeyEvent
& );
362 wxGridWindow( wxGrid
*parent
,
363 wxGridRowLabelWindow
*rowLblWin
,
364 wxGridColLabelWindow
*colLblWin
,
365 wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
368 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
370 DECLARE_DYNAMIC_CLASS(wxGridWindow
)
371 DECLARE_EVENT_TABLE()
376 class WXDLLEXPORT wxGrid
: public wxScrolledWindow
381 wxGridWindow
*m_gridWin
;
382 wxGridRowLabelWindow
*m_rowLabelWin
;
383 wxGridColLabelWindow
*m_colLabelWin
;
384 wxGridCornerLabelWindow
*m_cornerLabelWin
;
386 wxBoxSizer
*m_mainSizer
;
387 wxBoxSizer
*m_topSizer
;
388 wxBoxSizer
*m_middleSizer
;
390 wxGridTableBase
*m_table
;
400 wxGridCellCoords m_currentCellCoords
;
401 bool m_currentCellHighlighted
;
403 wxGridCellCoords m_selectedTopLeft
;
404 wxGridCellCoords m_selectedBottomRight
;
406 int m_defaultRowHeight
;
407 wxArrayInt m_rowHeights
;
408 wxArrayInt m_rowBottoms
;
410 int m_defaultColWidth
;
411 wxArrayInt m_colWidths
;
412 wxArrayInt m_colRights
;
415 int m_colLabelHeight
;
417 wxColour m_labelBackgroundColour
;
418 wxColour m_labelTextColour
;
421 int m_rowLabelHorizAlign
;
422 int m_rowLabelVertAlign
;
423 int m_colLabelHorizAlign
;
424 int m_colLabelVertAlign
;
426 bool m_defaultRowLabelValues
;
427 bool m_defaultColLabelValues
;
429 wxColour m_gridLineColour
;
430 bool m_gridLinesEnabled
;
432 wxFont m_defaultCellFont
;
434 wxGridCellCoordsArray m_cellsExposed
;
435 wxArrayInt m_rowsExposed
;
436 wxArrayInt m_colsExposed
;
437 wxArrayInt m_rowLabelsExposed
;
438 wxArrayInt m_colLabelsExposed
;
444 enum { WXGRID_CURSOR_DEFAULT
,
445 WXGRID_CURSOR_SELECT_CELL
,
446 WXGRID_CURSOR_RESIZE_ROW
,
447 WXGRID_CURSOR_RESIZE_COL
,
448 WXGRID_CURSOR_SELECT_ROW
,
449 WXGRID_CURSOR_SELECT_COL
456 wxGridCellCoords m_selectionStart
;
458 wxCursor m_rowResizeCursor
;
459 wxCursor m_colResizeCursor
;
461 bool m_editable
; // applies to whole grid
462 int m_editCtrlType
; // for current cell
463 wxWindow
* m_cellEditCtrl
;
464 bool m_cellEditCtrlEnabled
;
465 wxWindow
* m_topEditCtrl
;
466 bool m_topEditCtrlEnabled
;
471 void CalcDimensions();
472 bool Redimension( wxGridTableMessage
& );
475 bool SendEvent( const wxEventType
,
479 bool SendEvent( const wxEventType
,
483 void OnPaint( wxPaintEvent
& );
484 void OnSize( wxSizeEvent
& );
485 void OnKeyDown( wxKeyEvent
& );
488 void SetCurrentCell( const wxGridCellCoords
& coords
);
489 void SetCurrentCell( int row
, int col
)
490 { SetCurrentCell( wxGridCellCoords(row
, col
) ); }
493 // ------ functions to get/send data (see also public functions)
495 bool GetModelValues();
496 bool SetModelValues();
499 ////////////////////// Public section ////////////////////
505 wxGrid( wxWindow
*parent
,
507 const wxPoint
& pos
= wxDefaultPosition
,
508 const wxSize
& size
= wxDefaultSize
,
510 const wxString
& name
= wxPanelNameStr
);
514 bool CreateGrid( int numRows
, int numCols
);
517 // ------ grid dimensions
519 int GetNumberRows() { return m_numRows
; }
520 int GetNumberCols() { return m_numCols
; }
523 // ------ display update functions
525 void CalcRowLabelsExposed( wxRegion
& reg
);
526 void CalcColLabelsExposed( wxRegion
& reg
);
527 void CalcCellsExposed( wxRegion
& reg
);
530 // ------ event handlers
532 void ProcessRowLabelMouseEvent( wxMouseEvent
& event
);
533 void ProcessColLabelMouseEvent( wxMouseEvent
& event
);
534 void ProcessCornerLabelMouseEvent( wxMouseEvent
& event
);
535 void ProcessGridCellMouseEvent( wxMouseEvent
& event
);
536 bool ProcessTableMessage( wxGridTableMessage
& );
539 wxGridTableBase
* GetTable() const { return m_table
; }
540 void SetTable( wxGridTableBase
*table
) { m_table
= table
; }
543 bool InsertRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
544 bool AppendRows( int numRows
= 1, bool updateLabels
=TRUE
);
545 bool DeleteRows( int pos
= 0, int numRows
= 1, bool updateLabels
=TRUE
);
546 bool InsertCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
547 bool AppendCols( int numCols
= 1, bool updateLabels
=TRUE
);
548 bool DeleteCols( int pos
= 0, int numCols
= 1, bool updateLabels
=TRUE
);
550 void DrawGridCellArea( wxDC
& dc
);
551 void DrawCellBorder( wxDC
& dc
, const wxGridCellCoords
& );
552 void DrawAllGridLines( wxDC
& dc
); // TODO - delete this ?
553 void DrawCell( wxDC
& dc
, const wxGridCellCoords
& );
554 void DrawCellBackground( wxDC
& dc
, const wxGridCellCoords
& );
555 void DrawCellValue( wxDC
& dc
, const wxGridCellCoords
& );
557 void DrawRowLabels( wxDC
& dc
);
558 void DrawRowLabel( wxDC
& dc
, int row
);
559 void DrawColLabels( wxDC
& dc
);
560 void DrawColLabel( wxDC
& dc
, int col
);
563 // ------ Cell text drawing functions
565 void DrawTextRectangle( wxDC
& dc
, const wxString
&, const wxRect
&,
566 int horizontalAlignment
= wxLEFT
,
567 int verticalAlignment
= wxTOP
);
569 // Split a string containing newline chararcters into an array of
570 // strings and return the number of lines
572 void StringToLines( const wxString
& value
, wxArrayString
& lines
);
574 void GetTextBoxSize( wxDC
& dc
,
575 wxArrayString
& lines
,
576 long *width
, long *height
);
580 // Code that does a lot of grid modification can be enclosed
581 // between BeginBatch() and EndBatch() calls to avoid screen
584 void BeginBatch() { m_batchCount
++; }
585 void EndBatch() { if ( m_batchCount
> 0 ) m_batchCount
--; }
586 int GetBatchCount() { return m_batchCount
; }
589 // ------ edit control functions
591 bool IsEditable() { return m_editable
; }
592 void EnableEditing( bool edit
);
594 void EnableCellEditControl( bool enable
);
596 bool IsCellEditControlEnabled()
597 { return (m_cellEditCtrl
&& m_cellEditCtrlEnabled
); }
599 void EnableTopEditControl( bool enable
);
601 bool IsTopEditControlEnabled()
602 { return (m_topEditCtrl
&& m_topEditCtrlEnabled
); }
604 void ShowCellEditControl();
605 void HideCellEditControl();
606 void SetEditControlValue( const wxString
& s
= wxEmptyString
);
607 void SaveEditControlValue();
610 // ------ grid location functions
611 // Note that all of these functions work with the logical coordinates of
612 // grid cells and labels so you will need to convert from device
613 // coordinates for mouse events etc.
615 void XYToCell( int x
, int y
, wxGridCellCoords
& );
619 int YToEdgeOfRow( int y
);
620 int XToEdgeOfCol( int x
);
622 wxRect
CellToRect( int row
, int col
);
623 wxRect
CellToRect( const wxGridCellCoords
& coords
)
624 { return CellToRect( coords
.GetRow(), coords
.GetCol() ); }
626 int GetGridCursorRow() { return m_currentCellCoords
.GetRow(); }
627 int GetGridCursorCol() { return m_currentCellCoords
.GetCol(); }
629 // check to see if a cell is either wholly visible (the default arg) or
630 // at least partially visible in the grid window
632 bool IsVisible( int row
, int col
, bool wholeCellVisible
= TRUE
);
633 bool IsVisible( const wxGridCellCoords
& coords
, bool wholeCellVisible
= TRUE
)
634 { return IsVisible( coords
.GetRow(), coords
.GetCol(), wholeCellVisible
); }
635 void MakeCellVisible( int row
, int col
);
636 void MakeCellVisible( const wxGridCellCoords
& coords
)
637 { MakeCellVisible( coords
.GetRow(), coords
.GetCol() ); }
640 // ------ grid cursor movement functions
643 bool MoveCursorDown();
644 bool MoveCursorLeft();
645 bool MoveCursorRight();
648 bool MoveCursorUpBlock();
649 bool MoveCursorDownBlock();
650 bool MoveCursorLeftBlock();
651 bool MoveCursorRightBlock();
654 // ------ label and gridline formatting
656 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH
; }
657 int GetRowLabelSize() { return m_rowLabelWidth
; }
658 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT
; }
659 int GetColLabelSize() { return m_colLabelHeight
; }
660 wxColour
GetLabelBackgroundColour() { return m_labelBackgroundColour
; }
661 wxColour
GetLabelTextColour() { return m_labelTextColour
; }
662 wxFont
GetLabelFont() { return m_labelFont
; }
663 void GetRowLabelAlignment( int *horiz
, int *vert
);
664 void GetColLabelAlignment( int *horiz
, int *vert
);
665 wxString
GetRowLabelValue( int row
);
666 wxString
GetColLabelValue( int col
);
667 wxColour
GetGridLineColour() { return m_gridLineColour
; }
669 void SetRowLabelSize( int width
);
670 void SetColLabelSize( int height
);
671 void SetLabelBackgroundColour( const wxColour
& );
672 void SetLabelTextColour( const wxColour
& );
673 void SetLabelFont( const wxFont
& );
674 void SetRowLabelAlignment( int horiz
, int vert
);
675 void SetColLabelAlignment( int horiz
, int vert
);
676 void SetRowLabelValue( int row
, const wxString
& );
677 void SetColLabelValue( int col
, const wxString
& );
678 void SetGridLineColour( const wxColour
& );
680 void EnableGridLines( bool enable
= TRUE
);
681 bool GridLinesEnabled() { return m_gridLinesEnabled
; }
684 // ------ row and col formatting
686 int GetDefaultRowSize();
687 int GetRowSize( int row
);
688 int GetDefaultColSize();
689 int GetColSize( int col
);
690 wxColour
GetDefaultCellBackgroundColour();
691 wxColour
GetCellBackgroundColour( int row
, int col
);
692 wxColour
GetDefaultCellTextColour();
693 wxColour
GetCellTextColour( int row
, int col
);
694 wxColour
GetCellHighlightColour();
695 wxFont
GetDefaultCellFont();
696 wxFont
GetCellFont( int row
, int col
);
697 void GetDefaultCellAlignment( int *horiz
, int *vert
);
698 void GetCellAlignment( int row
, int col
, int *horiz
, int *vert
);
700 void SetDefaultRowSize( int height
, bool resizeExistingRows
= FALSE
);
701 void SetRowSize( int row
, int height
);
702 void SetDefaultColSize( int width
, bool resizeExistingCols
= FALSE
);
703 void SetColSize( int col
, int width
);
704 void SetDefaultCellBackgroundColour( const wxColour
& );
705 void SetCellBackgroundColour( int row
, int col
, const wxColour
& );
706 void SetDefaultCellTextColour( const wxColour
& );
707 void SetCellTextColour( int row
, int col
, const wxColour
& );
708 void SetCellHighlightColour( const wxColour
& );
709 void SetDefaultCellFont( const wxFont
& );
710 void SetCellFont( int row
, int col
, const wxFont
& );
711 void SetDefaultCellAlignment( int horiz
, int vert
);
712 void SetCellAlignment( int row
, int col
, int horiz
, int vert
);
715 // ------ cell value accessors
717 wxString
GetCellValue( int row
, int col
)
721 return m_table
->GetValue( row
, col
);
725 return wxEmptyString
;
729 wxString
GetCellValue( const wxGridCellCoords
& coords
)
730 { return GetCellValue( coords
.GetRow(), coords
.GetCol() ); }
732 void SetCellValue( int row
, int col
, const wxString
& s
);
733 void SetCellValue( const wxGridCellCoords
& coords
, const wxString
& s
)
734 { SetCellValue( coords
.GetRow(), coords
.GetCol(), s
); }
738 // ------ selections of blocks of cells
740 void SelectRow( int row
, bool addToSelected
= FALSE
);
741 void SelectCol( int col
, bool addToSelected
= FALSE
);
743 void SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
);
745 void SelectBlock( const wxGridCellCoords
& topLeft
,
746 const wxGridCellCoords
& bottomRight
)
747 { SelectBlock( topLeft
.GetRow(), topLeft
.GetCol(),
748 bottomRight
.GetRow(), bottomRight
.GetCol() ); }
753 { return ( m_selectedTopLeft
!= wxGridNoCellCoords
&&
754 m_selectedBottomRight
!= wxGridNoCellCoords
);
757 void ClearSelection();
759 bool IsInSelection( int row
, int col
)
760 { return ( IsSelection() &&
761 row
>= m_selectedTopLeft
.GetRow() &&
762 col
>= m_selectedTopLeft
.GetCol() &&
763 row
<= m_selectedBottomRight
.GetRow() &&
764 col
<= m_selectedBottomRight
.GetCol() );
767 bool IsInSelection( const wxGridCellCoords
& coords
)
768 { return IsInSelection( coords
.GetRow(), coords
.GetCol() ); }
770 void GetSelection( int* topRow
, int* leftCol
, int* bottomRow
, int* rightCol
)
772 // these will all be -1 if there is no selected block
774 *topRow
= m_selectedTopLeft
.GetRow();
775 *leftCol
= m_selectedTopLeft
.GetCol();
776 *bottomRow
= m_selectedBottomRight
.GetRow();
777 *rightCol
= m_selectedBottomRight
.GetCol();
780 // This function returns the rectangle that encloses the selected cells
781 // in device coords and clipped to the client size of the grid window.
783 wxRect
SelectionToDeviceRect();
787 // ------ For compatibility with previous wxGrid only...
789 // ************************************************
790 // ** Don't use these in new code because they **
791 // ** are liable to disappear in a future **
793 // ************************************************
796 wxGrid( wxWindow
*parent
,
797 int x
= -1, int y
= -1, int w
= -1, int h
= -1,
799 const wxString
& name
= wxPanelNameStr
)
800 : wxScrolledWindow( parent
, -1, wxPoint(x
,y
), wxSize(w
,h
), style
, name
)
805 void SetCellValue( const wxString
& val
, int row
, int col
)
806 { SetCellValue( row
, col
, val
); }
808 void UpdateDimensions()
809 { CalcDimensions(); }
811 int GetRows() { return GetNumberRows(); }
812 int GetCols() { return GetNumberCols(); }
813 int GetCursorRow() { return GetGridCursorRow(); }
814 int GetCursorColumn() { return GetGridCursorCol(); }
816 int GetScrollPosX() { return 0; }
817 int GetScrollPosY() { return 0; }
819 void SetScrollX( int x
) { }
820 void SetScrollY( int y
) { }
822 void SetColumnWidth( int col
, int width
)
823 { SetColSize( col
, width
); }
825 int GetColumnWidth( int col
)
826 { return GetColSize( col
); }
828 void SetRowHeight( int row
, int height
)
829 { SetRowSize( row
, height
); }
831 int GetRowHeight( int row
)
832 { return GetRowSize( row
); }
834 int GetViewHeight() // returned num whole rows visible
837 int GetViewWidth() // returned num whole cols visible
840 void SetLabelSize( int orientation
, int sz
)
842 if ( orientation
== wxHORIZONTAL
)
843 SetColLabelSize( sz
);
845 SetRowLabelSize( sz
);
848 int GetLabelSize( int orientation
)
850 if ( orientation
== wxHORIZONTAL
)
851 return GetColLabelSize();
853 return GetRowLabelSize();
856 void SetLabelAlignment( int orientation
, int align
)
858 if ( orientation
== wxHORIZONTAL
)
859 SetColLabelAlignment( align
, -1 );
861 SetRowLabelAlignment( align
, -1 );
864 int GetLabelAlignment( int orientation
, int WXUNUSED(align
) )
867 if ( orientation
== wxHORIZONTAL
)
869 GetColLabelAlignment( &h
, &v
);
874 GetRowLabelAlignment( &h
, &v
);
879 void SetLabelValue( int orientation
, const wxString
& val
, int pos
)
881 if ( orientation
== wxHORIZONTAL
)
882 SetColLabelValue( pos
, val
);
884 SetRowLabelValue( pos
, val
);
887 wxString
GetLabelValue( int orientation
, int pos
)
889 if ( orientation
== wxHORIZONTAL
)
890 return GetColLabelValue( pos
);
892 return GetRowLabelValue( pos
);
895 wxFont
GetCellTextFont() const
896 { return m_defaultCellFont
; }
898 wxFont
GetCellTextFont(int WXUNUSED(row
), int WXUNUSED(col
)) const
899 { return m_defaultCellFont
; }
901 void SetCellTextFont(const wxFont
& fnt
)
902 { SetDefaultCellFont( fnt
); }
904 void SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
905 { SetCellFont( row
, col
, fnt
); }
907 void SetCellTextColour(const wxColour
& val
, int row
, int col
)
908 { SetCellTextColour( row
, col
, val
); }
910 void SetCellTextColour(const wxColour
& col
)
911 { SetDefaultCellTextColour( col
); }
913 void SetCellBackgroundColour(const wxColour
& col
)
914 { SetDefaultCellBackgroundColour( col
); }
916 void SetCellBackgroundColour(const wxColour
& colour
, int row
, int col
)
917 { SetCellBackgroundColour( row
, col
, colour
); }
919 bool GetEditable() { return IsEditable(); }
920 void SetEditable( bool edit
= TRUE
) { EnableEditing( edit
); }
921 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
922 void SetEditInPlace(bool edit
= TRUE
) { EnableCellEditControl( edit
); }
924 void SetCellAlignment( int align
, int row
, int col
)
925 { SetCellAlignment(row
, col
, align
, wxCENTER
); }
926 void SetCellAlignment( int WXUNUSED(align
) ) {}
927 void SetCellBitmap(wxBitmap
*WXUNUSED(bitmap
), int WXUNUSED(row
), int WXUNUSED(col
))
929 void SetDividerPen(const wxPen
& WXUNUSED(pen
)) { }
930 wxPen
& GetDividerPen() const { return wxNullPen
; }
931 void OnActivate(bool WXUNUSED(active
)) {}
933 // ******** End of compatibility functions **********
937 // ------ control IDs
938 enum { wxGRID_CELLCTRL
= 2000,
941 // ------ control types
942 enum { wxGRID_TEXTCTRL
= 2100,
948 DECLARE_DYNAMIC_CLASS( wxGrid
)
949 DECLARE_EVENT_TABLE()
957 // ------ Grid event class and event types
960 class WXDLLEXPORT wxGridEvent
: public wxNotifyEvent
974 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
975 m_control(0), m_meta(0), m_shift(0), m_alt(0)
979 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
980 int row
=-1, int col
=-1, int x
=-1, int y
=-1,
981 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
983 virtual int GetRow() { return m_row
; }
984 virtual int GetCol() { return m_col
; }
985 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
986 bool ControlDown() { return m_control
; }
987 bool MetaDown() { return m_meta
; }
988 bool ShiftDown() { return m_shift
; }
989 bool AltDown() { return m_alt
; }
991 DECLARE_DYNAMIC_CLASS(wxGridEvent
)
995 class WXDLLEXPORT wxGridSizeEvent
: public wxNotifyEvent
1008 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1009 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1013 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
1014 int rowOrCol
=-1, int x
=-1, int y
=-1,
1015 bool control
=FALSE
, bool shift
=FALSE
, bool alt
=FALSE
, bool meta
=FALSE
);
1017 int GetRowOrCol() { return m_rowOrCol
; }
1018 wxPoint
GetPosition() { return wxPoint( m_x
, m_y
); }
1019 bool ControlDown() { return m_control
; }
1020 bool MetaDown() { return m_meta
; }
1021 bool ShiftDown() { return m_shift
; }
1022 bool AltDown() { return m_alt
; }
1024 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent
)
1028 class WXDLLEXPORT wxGridRangeSelectEvent
: public wxNotifyEvent
1031 wxGridCellCoords m_topLeft
;
1032 wxGridCellCoords m_bottomRight
;
1039 wxGridRangeSelectEvent()
1042 m_topLeft
= wxGridNoCellCoords
;
1043 m_bottomRight
= wxGridNoCellCoords
;
1050 wxGridRangeSelectEvent(int id
, wxEventType type
, wxObject
* obj
,
1051 const wxGridCellCoords
& topLeft
,
1052 const wxGridCellCoords
& bottomRight
,
1053 bool control
=FALSE
, bool shift
=FALSE
,
1054 bool alt
=FALSE
, bool meta
=FALSE
);
1056 wxGridCellCoords
GetTopLeftCoords() { return m_topLeft
; }
1057 wxGridCellCoords
GetBottomRightCoords() { return m_bottomRight
; }
1058 int GetTopRow() { return m_topLeft
.GetRow(); }
1059 int GetBottomRow() { return m_bottomRight
.GetRow(); }
1060 int GetLeftCol() { return m_topLeft
.GetCol(); }
1061 int GetRightCol() { return m_bottomRight
.GetCol(); }
1062 bool ControlDown() { return m_control
; }
1063 bool MetaDown() { return m_meta
; }
1064 bool ShiftDown() { return m_shift
; }
1065 bool AltDown() { return m_alt
; }
1067 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent
)
1071 const wxEventType EVT_GRID_CELL_LEFT_CLICK
= wxEVT_FIRST
+ 1580;
1072 const wxEventType EVT_GRID_CELL_RIGHT_CLICK
= wxEVT_FIRST
+ 1581;
1073 const wxEventType EVT_GRID_CELL_LEFT_DCLICK
= wxEVT_FIRST
+ 1582;
1074 const wxEventType EVT_GRID_CELL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1583;
1075 const wxEventType EVT_GRID_LABEL_LEFT_CLICK
= wxEVT_FIRST
+ 1584;
1076 const wxEventType EVT_GRID_LABEL_RIGHT_CLICK
= wxEVT_FIRST
+ 1585;
1077 const wxEventType EVT_GRID_LABEL_LEFT_DCLICK
= wxEVT_FIRST
+ 1586;
1078 const wxEventType EVT_GRID_LABEL_RIGHT_DCLICK
= wxEVT_FIRST
+ 1587;
1079 const wxEventType EVT_GRID_ROW_SIZE
= wxEVT_FIRST
+ 1588;
1080 const wxEventType EVT_GRID_COL_SIZE
= wxEVT_FIRST
+ 1589;
1081 const wxEventType EVT_GRID_RANGE_SELECT
= wxEVT_FIRST
+ 1590;
1082 const wxEventType EVT_GRID_CELL_CHANGE
= wxEVT_FIRST
+ 1591;
1083 const wxEventType EVT_GRID_SELECT_CELL
= wxEVT_FIRST
+ 1592;
1086 typedef void (wxEvtHandler::*wxGridEventFunction
)(wxGridEvent
&);
1087 typedef void (wxEvtHandler::*wxGridSizeEventFunction
)(wxGridSizeEvent
&);
1088 typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction
)(wxGridRangeSelectEvent
&);
1090 #define EVT_GRID_CELL_LEFT_CLICK(fn) { EVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1091 #define EVT_GRID_CELL_RIGHT_CLICK(fn) { EVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1092 #define EVT_GRID_CELL_LEFT_DCLICK(fn) { EVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1093 #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { EVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1094 #define EVT_GRID_LABEL_LEFT_CLICK(fn) { EVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1095 #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { EVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1096 #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { EVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1097 #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { EVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1098 #define EVT_GRID_ROW_SIZE(fn) { EVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1099 #define EVT_GRID_COL_SIZE(fn) { EVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL },
1100 #define EVT_GRID_RANGE_SELECT(fn) { EVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL },
1101 #define EVT_GRID_CELL_CHANGE(fn) { EVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1102 #define EVT_GRID_SELECT_CELL(fn) { EVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1105 #if 0 // TODO: implement these ? others ?
1107 const wxEventType EVT_GRID_CREATE_CELL
= wxEVT_FIRST
+ 1576;
1108 const wxEventType EVT_GRID_CHANGE_LABELS
= wxEVT_FIRST
+ 1577;
1109 const wxEventType EVT_GRID_CHANGE_SEL_LABEL
= wxEVT_FIRST
+ 1578;
1111 #define EVT_GRID_CREATE_CELL(fn) { EVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1112 #define EVT_GRID_CHANGE_LABELS(fn) { EVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1113 #define EVT_GRID_CHANGE_SEL_LABEL(fn) { EVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL },
1117 #endif // #ifndef __WXGRID_H__
1119 #endif // ifndef wxUSE_NEW_GRID